Artifact
19f6186e5280c287f7576ca7a9dfcbd5677586f4e77c54a354359490cd5b5552 :
File
tools/emcc.sh.in
— part of check-in
[98dd262675]
at
2022-06-08 12:19:29
on branch pikchrshow-wasm
— Refactored the configure script's emsdk detection in the hopes that this reformulation will work on systems where emcc is installed via a package manager.
(user:
stephan
size: 1938)
[more...]
0000: 23 21 2f 75 73 72 2f 62 69 6e 2f 62 61 73 68 0a #!/usr/bin/bash.
0010: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 ################
0020: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 ################
0030: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 ################
0040: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 ################
0050: 23 23 23 23 23 23 23 23 0a 23 20 57 41 52 4e 49 ########.# WARNI
0060: 4e 47 3a 20 65 6d 63 63 2e 73 68 20 69 73 20 67 NG: emcc.sh is g
0070: 65 6e 65 72 61 74 65 64 20 66 72 6f 6d 20 65 6d enerated from em
0080: 63 63 2e 73 68 2e 69 6e 20 62 79 20 74 68 65 20 cc.sh.in by the
0090: 63 6f 6e 66 69 67 75 72 65 0a 23 20 70 72 6f 63 configure.# proc
00a0: 65 73 73 2e 20 44 6f 20 6e 6f 74 20 65 64 69 74 ess. Do not edit
00b0: 20 65 6d 63 63 2e 73 68 20 64 69 72 65 63 74 6c emcc.sh directl
00c0: 79 2c 20 61 73 20 69 74 20 6d 61 79 20 62 65 20 y, as it may be
00d0: 64 65 6c 65 74 65 64 20 6f 72 0a 23 20 6f 76 65 deleted or.# ove
00e0: 72 77 72 69 74 74 65 6e 20 62 79 20 74 68 65 20 rwritten by the
00f0: 63 6f 6e 66 69 67 75 72 65 20 73 63 72 69 70 74 configure script
0100: 2e 0a 23 0a 23 20 41 20 77 72 61 70 70 65 72 20 ..#.# A wrapper
0110: 61 72 6f 75 6e 64 20 74 68 65 20 65 6d 63 63 20 around the emcc
0120: 63 6f 6d 70 69 6c 65 72 20 77 68 69 63 68 20 75 compiler which u
0130: 73 65 73 20 63 6f 6e 66 69 67 75 72 65 2d 74 69 ses configure-ti
0140: 6d 65 20 73 74 61 74 65 0a 23 20 74 6f 20 6c 6f me state.# to lo
0150: 63 61 74 65 20 74 68 65 20 45 6d 73 63 72 69 70 cate the Emscrip
0160: 74 65 6e 20 53 44 4b 20 61 6e 64 20 69 6d 70 6f ten SDK and impo
0170: 72 74 20 74 68 65 20 53 44 4b 27 73 20 65 6e 76 rt the SDK's env
0180: 69 72 6f 6e 6d 65 6e 74 0a 23 20 73 63 72 69 70 ironment.# scrip
0190: 74 2c 20 69 66 20 6e 65 65 64 65 64 2e 0a 23 23 t, if needed..##
01a0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 ################
01b0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 ################
01c0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 ################
01d0: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 ################
01e0: 23 23 23 23 23 23 0a 23 20 45 4d 53 44 4b 5f 48 ######.# EMSDK_H
01f0: 4f 4d 45 20 63 6f 6d 65 73 20 66 72 6f 6d 20 74 OME comes from t
0200: 68 65 20 63 6f 6e 66 69 67 75 72 65 20 2d 2d 77 he configure --w
0210: 69 74 68 2d 65 6d 73 64 6b 3d 2f 64 69 72 20 66 ith-emsdk=/dir f
0220: 6c 61 67 2e 0a 23 20 45 4d 53 44 4b 5f 45 4e 56 lag..# EMSDK_ENV
0230: 20 69 73 20 24 7b 74 68 61 74 44 69 72 7d 2f 65 is ${thatDir}/e
0240: 6d 73 64 6b 5f 65 6e 76 2e 73 68 20 61 6e 64 20 msdk_env.sh and
0250: 69 73 20 61 6c 73 6f 20 73 65 74 20 62 79 20 74 is also set by t
0260: 68 65 0a 23 20 63 6f 6e 66 69 67 75 72 65 20 70 he.# configure p
0270: 72 6f 63 65 73 73 2e 0a 45 4d 53 44 4b 5f 48 4f rocess..EMSDK_HO
0280: 4d 45 3d 22 40 45 4d 53 44 4b 5f 48 4f 4d 45 40 ME="@EMSDK_HOME@
0290: 22 0a 45 4d 53 44 4b 5f 45 4e 56 3d 22 40 45 4d ".EMSDK_ENV="@EM
02a0: 53 44 4b 5f 45 4e 56 40 22 0a 0a 65 6d 63 63 3d SDK_ENV@"..emcc=
02b0: 24 28 77 68 69 63 68 20 65 6d 63 63 20 32 3e 2f $(which emcc 2>/
02c0: 64 65 76 2f 6e 75 6c 6c 29 0a 0a 69 66 20 5b 20 dev/null)..if [
02d0: 78 20 3d 20 22 78 24 7b 65 6d 63 63 7d 22 20 5d x = "x${emcc}" ]
02e0: 3b 20 74 68 65 6e 0a 20 20 23 20 49 66 20 65 6d ; then. # If em
02f0: 63 63 20 69 73 20 6e 6f 74 20 66 6f 75 6e 64 20 cc is not found
0300: 69 6e 20 74 68 65 20 70 61 74 68 2c 20 74 72 79 in the path, try
0310: 20 74 6f 20 66 69 6e 64 20 69 74 20 76 69 61 20 to find it via
0320: 61 6e 20 65 6d 73 64 6b 0a 20 20 23 20 69 6e 73 an emsdk. # ins
0330: 74 61 6c 6c 61 74 69 6f 6e 2e 20 54 68 65 20 53 tallation. The S
0340: 44 4b 20 76 61 72 69 61 6e 74 20 69 73 20 74 68 DK variant is th
0350: 65 20 6f 66 66 69 63 69 61 6c 20 69 6e 73 74 61 e official insta
0360: 6c 6c 61 74 69 6f 6e 0a 20 20 23 20 73 74 79 6c llation. # styl
0370: 65 20 73 75 70 70 6f 72 74 65 64 20 62 79 20 74 e supported by t
0380: 68 65 20 45 6d 73 63 72 69 70 74 65 6e 20 66 6f he Emscripten fo
0390: 6c 6b 73 2c 20 62 75 74 20 65 6d 63 63 20 69 73 lks, but emcc is
03a0: 20 61 6c 73 6f 0a 20 20 23 20 61 76 61 69 6c 61 also. # availa
03b0: 62 6c 65 20 76 69 61 20 70 61 63 6b 61 67 65 20 ble via package
03c0: 6d 61 6e 61 67 65 72 73 20 6f 6e 20 73 6f 6d 65 managers on some
03d0: 20 4f 53 65 73 2e 0a 20 20 69 66 20 5b 20 78 20 OSes.. if [ x
03e0: 3d 20 22 78 24 7b 45 4d 53 44 4b 5f 48 4f 4d 45 = "x${EMSDK_HOME
03f0: 7d 22 20 5d 3b 20 74 68 65 6e 0a 20 20 20 20 65 }" ]; then. e
0400: 63 68 6f 20 22 45 4d 53 44 4b 5f 48 4f 4d 45 20 cho "EMSDK_HOME
0410: 69 73 20 6e 6f 74 20 73 65 74 2e 20 50 61 73 73 is not set. Pass
0420: 20 2d 2d 77 69 74 68 2d 65 6d 73 64 6b 3d 2f 70 --with-emsdk=/p
0430: 61 74 68 2f 74 6f 2f 65 6d 73 64 6b 22 20 5c 0a ath/to/emsdk" \.
0440: 20 20 20 20 20 20 20 20 20 22 74 6f 20 74 68 65 "to the
0450: 20 63 6f 6e 66 69 67 75 72 65 20 73 63 72 69 70 configure scrip
0460: 74 2e 22 20 31 3e 26 32 0a 20 20 20 20 65 78 69 t." 1>&2. exi
0470: 74 20 31 0a 20 20 66 69 0a 0a 20 20 69 66 20 5b t 1. fi.. if [
0480: 20 78 20 3d 20 22 78 24 7b 45 4d 53 44 4b 5f 45 x = "x${EMSDK_E
0490: 4e 56 7d 22 20 5d 3b 20 74 68 65 6e 0a 20 20 20 NV}" ]; then.
04a0: 20 69 66 20 5b 20 2d 66 20 22 24 7b 45 4d 53 44 if [ -f "${EMSD
04b0: 4b 5f 48 4f 4d 45 7d 2f 65 6d 73 64 6b 5f 65 6e K_HOME}/emsdk_en
04c0: 76 2e 73 68 22 20 5d 3b 20 74 68 65 6e 0a 20 20 v.sh" ]; then.
04d0: 20 20 20 20 45 4d 53 44 4b 5f 45 4e 56 3d 22 24 EMSDK_ENV="$
04e0: 7b 45 4d 53 44 4b 5f 48 4f 4d 45 7d 2f 65 6d 73 {EMSDK_HOME}/ems
04f0: 64 6b 5f 65 6e 76 2e 73 68 22 0a 20 20 20 20 65 dk_env.sh". e
0500: 6c 73 65 0a 20 20 20 20 20 20 65 63 68 6f 20 22 lse. echo "
0510: 45 4d 53 44 4b 5f 45 4e 56 20 69 73 20 6e 6f 74 EMSDK_ENV is not
0520: 20 73 65 74 2e 20 45 78 70 65 63 74 69 6e 67 20 set. Expecting
0530: 63 6f 6e 66 69 67 75 72 65 20 73 63 72 69 70 74 configure script
0540: 20 74 6f 20 73 65 74 20 69 74 2e 22 20 31 3e 26 to set it." 1>&
0550: 32 0a 20 20 20 20 20 20 65 78 69 74 20 32 0a 20 2. exit 2.
0560: 20 20 20 66 69 0a 20 20 66 69 0a 0a 20 20 69 66 fi. fi.. if
0570: 20 5b 20 21 20 2d 66 20 22 24 7b 45 4d 53 44 4b [ ! -f "${EMSDK
0580: 5f 45 4e 56 7d 22 20 5d 3b 20 74 68 65 6e 0a 20 _ENV}" ]; then.
0590: 20 20 20 65 63 68 6f 20 22 65 6d 73 64 6b 5f 65 echo "emsdk_e
05a0: 6e 76 20 73 63 72 69 70 74 20 6e 6f 74 20 66 6f nv script not fo
05b0: 75 6e 64 3a 20 24 45 4d 53 44 4b 5f 45 4e 56 22 und: $EMSDK_ENV"
05c0: 20 31 3e 26 32 0a 20 20 20 20 65 78 69 74 20 33 1>&2. exit 3
05d0: 0a 20 20 66 69 0a 0a 20 20 23 20 24 45 4d 53 44 . fi.. # $EMSD
05e0: 4b 20 69 73 20 70 61 72 74 20 6f 66 20 74 68 65 K is part of the
05f0: 20 73 74 61 74 65 20 73 65 74 20 62 79 20 65 6d state set by em
0600: 73 64 6b 5f 65 6e 76 2e 73 68 2e 0a 20 20 69 66 sdk_env.sh.. if
0610: 20 5b 20 78 20 3d 20 22 78 24 7b 45 4d 53 44 4b [ x = "x${EMSDK
0620: 7d 22 20 5d 3b 20 74 68 65 6e 0a 20 20 20 20 73 }" ]; then. s
0630: 6f 75 72 63 65 20 22 24 7b 45 4d 53 44 4b 5f 45 ource "${EMSDK_E
0640: 4e 56 7d 22 20 3e 2f 64 65 76 2f 6e 75 6c 6c 20 NV}" >/dev/null
0650: 32 3e 26 31 20 7c 7c 20 7b 0a 20 20 20 20 20 20 2>&1 || {.
0660: 23 20 5e 5e 5e 20 75 6e 66 6f 72 74 75 6e 61 74 # ^^^ unfortunat
0670: 65 6c 79 20 6f 75 74 70 75 74 73 20 6c 6f 74 73 ely outputs lots
0680: 20 6f 66 20 6e 6f 69 73 65 20 74 6f 20 73 74 64 of noise to std
0690: 65 72 72 0a 20 20 20 20 20 20 72 63 3d 24 3f 0a err. rc=$?.
06a0: 20 20 20 20 20 20 65 63 68 6f 20 22 45 72 72 6f echo "Erro
06b0: 72 20 73 6f 75 72 63 69 6e 67 20 24 7b 45 4d 53 r sourcing ${EMS
06c0: 44 4b 5f 45 4e 56 7d 22 0a 20 20 20 20 20 20 65 DK_ENV}". e
06d0: 78 69 74 20 24 72 63 0a 20 20 20 20 7d 0a 20 20 xit $rc. }.
06e0: 66 69 0a 20 20 65 6d 63 63 3d 24 28 77 68 69 63 fi. emcc=$(whic
06f0: 68 20 65 6d 63 63 20 32 3e 2f 64 65 76 2f 6e 75 h emcc 2>/dev/nu
0700: 6c 6c 29 0a 20 20 69 66 20 5b 20 78 20 3d 20 22 ll). if [ x = "
0710: 78 24 7b 65 6d 63 63 7d 22 20 5d 3b 20 74 68 65 x${emcc}" ]; the
0720: 6e 0a 20 20 20 20 65 63 68 6f 20 22 65 6d 63 63 n. echo "emcc
0730: 20 6e 6f 74 20 66 6f 75 6e 64 20 69 6e 20 50 41 not found in PA
0740: 54 48 2e 20 4e 6f 72 6d 61 6c 6c 79 20 74 68 61 TH. Normally tha
0750: 74 27 73 20 73 65 74 20 75 70 20 62 79 20 45 4d t's set up by EM
0760: 53 44 4b 5f 45 4e 56 2e 22 20 31 3e 26 32 0a 20 SDK_ENV." 1>&2.
0770: 20 20 20 65 78 69 74 20 34 0a 20 20 66 69 0a 66 exit 4. fi.f
0780: 69 0a 0a 65 78 65 63 20 65 6d 63 63 20 22 24 40 i..exec emcc "$@
0790: 22 0a ".