2014-05-06 14:43:46 -07:00
|
|
|
#! /bin/sh
|
|
|
|
|
2014-11-25 10:51:39 -07:00
|
|
|
export MAKE_FLAGS='-j4'
|
2024-03-24 02:39:43 -07:00
|
|
|
export EXPORTED_FUNCTIONS_STANDARD='["_malloc","_free","_crypto_aead_aegis128l_abytes","_crypto_aead_aegis128l_decrypt","_crypto_aead_aegis128l_decrypt_detached","_crypto_aead_aegis128l_encrypt","_crypto_aead_aegis128l_encrypt_detached","_crypto_aead_aegis128l_keybytes","_crypto_aead_aegis128l_keygen","_crypto_aead_aegis128l_messagebytes_max","_crypto_aead_aegis128l_npubbytes","_crypto_aead_aegis128l_nsecbytes","_crypto_aead_aegis256_abytes","_crypto_aead_aegis256_decrypt","_crypto_aead_aegis256_decrypt_detached","_crypto_aead_aegis256_encrypt","_crypto_aead_aegis256_encrypt_detached","_crypto_aead_aegis256_keybytes","_crypto_aead_aegis256_keygen","_crypto_aead_aegis256_messagebytes_max","_crypto_aead_aegis256_npubbytes","_crypto_aead_aegis256_nsecbytes","_crypto_aead_chacha20poly1305_abytes","_crypto_aead_chacha20poly1305_decrypt","_crypto_aead_chacha20poly1305_decrypt_detached","_crypto_aead_chacha20poly1305_encrypt","_crypto_aead_chacha20poly1305_encrypt_detached","_crypto_aead_chacha20poly1305_ietf_abytes","_crypto_aead_chacha20poly1305_ietf_decrypt","_crypto_aead_chacha20poly1305_ietf_decrypt_detached","_crypto_aead_chacha20poly1305_ietf_encrypt","_crypto_aead_chacha20poly1305_ietf_encrypt_detached","_crypto_aead_chacha20poly1305_ietf_keybytes","_crypto_aead_chacha20poly1305_ietf_keygen","_crypto_aead_chacha20poly1305_ietf_messagebytes_max","_crypto_aead_chacha20poly1305_ietf_npubbytes","_crypto_aead_chacha20poly1305_ietf_nsecbytes","_crypto_aead_chacha20poly1305_keybytes","_crypto_aead_chacha20poly1305_keygen","_crypto_aead_chacha20poly1305_messagebytes_max","_crypto_aead_chacha20poly1305_npubbytes","_crypto_aead_chacha20poly1305_nsecbytes","_crypto_aead_xchacha20poly1305_ietf_abytes","_crypto_aead_xchacha20poly1305_ietf_decrypt","_crypto_aead_xchacha20poly1305_ietf_decrypt_detached","_crypto_aead_xchacha20poly1305_ietf_encrypt","_crypto_aead_xchacha20poly1305_ietf_encrypt_detached","_crypto_aead_xchacha20poly1305_ietf_keybytes","_crypto_aead_xchacha20poly1305_ietf_keygen","_crypto_aead_xchacha20poly1305_ietf_messagebytes_max","_crypto_aead_xchacha20poly1305_ietf_npubbytes","_crypto_aead_xchacha20poly1305_ietf_nsecbytes","_crypto_auth","_crypto_auth_bytes","_crypto_auth_keybytes","_crypto_auth_keygen","_crypto_auth_verify","_crypto_box_beforenm","_crypto_box_beforenmbytes","_crypto_box_detached","_crypto_box_detached_afternm","_crypto_box_easy","_crypto_box_easy_afternm","_crypto_box_keypair","_crypto_box_macbytes","_crypto_box_messagebytes_max","_crypto_box_noncebytes","_crypto_box_open_detached","_crypto_box_open_detached_afternm","_crypto_box_open_easy","_crypto_box_open_easy_afternm","_crypto_box_publickeybytes","_crypto_box_seal","_crypto_box_seal_open","_crypto_box_sealbytes","_crypto_box_secretkeybytes","_crypto_box_seed_keypair","_crypto_box_seedbytes","_crypto_generichash","_crypto_generichash_bytes","_crypto_generichash_bytes_max","_crypto_generichash_bytes_min","_crypto_generichash_final","_crypto_generichash_init","_crypto_generichash_keybytes","_crypto_generichash_keybytes_max","_crypto_generichash_keybytes_min","_crypto_generichash_keygen","_crypto_generichash_statebytes","_crypto_generichash_update","_crypto_hash","_crypto_hash_bytes","_crypto_kdf_bytes_max","_crypto_kdf_bytes_min","_crypto_kdf_contextbytes","_crypto_kdf_derive_from_key","_crypto_kdf_hkdf_sha256_bytes_max","_crypto_kdf_hkdf_sha256_bytes_min","_crypto_kdf_hkdf_sha256_expand","_crypto_kdf_hkdf_sha256_extract","_crypto_kdf_hkdf_sha256_extract_final","_crypto_kdf_hkdf_sha256_extract_init","_crypto_kdf_hkdf_sha256_extract_update","_crypto_kdf_hkdf_sha256_keybytes","_crypto_kdf_hkdf_sha256_keygen","_crypto_kdf_hkdf_sha256_statebytes","_crypto_kdf_hkdf_sha512_bytes_max","_crypto_kdf_hkdf_sha512_bytes_min","_crypto_kdf_hkdf_sha512_expand","_crypto_kdf_hkdf_sha512_extract","_crypto_kdf_hkdf_sha512_extract_final","_crypto_kdf_hkdf_sha512_extract_init","_crypto_kdf_hkdf_sha512_extract_update","_crypto_kdf_hkdf_sha512_keybytes","_crypto_kdf_hkdf_sha512_keygen","_crypto_kdf_hkdf_sha512_statebytes","_crypto_kdf_keybytes","_crypto_kdf_keygen","_cr
|
2023-11-30 07:44:36 -07:00
|
|
|
export EXPORTED_FUNCTIONS_SUMO='["_malloc","_free","_crypto_aead_aegis128l_abytes","_crypto_aead_aegis128l_decrypt","_crypto_aead_aegis128l_decrypt_detached","_crypto_aead_aegis128l_encrypt","_crypto_aead_aegis128l_encrypt_detached","_crypto_aead_aegis128l_keybytes","_crypto_aead_aegis128l_keygen","_crypto_aead_aegis128l_messagebytes_max","_crypto_aead_aegis128l_npubbytes","_crypto_aead_aegis128l_nsecbytes","_crypto_aead_aegis256_abytes","_crypto_aead_aegis256_decrypt","_crypto_aead_aegis256_decrypt_detached","_crypto_aead_aegis256_encrypt","_crypto_aead_aegis256_encrypt_detached","_crypto_aead_aegis256_keybytes","_crypto_aead_aegis256_keygen","_crypto_aead_aegis256_messagebytes_max","_crypto_aead_aegis256_npubbytes","_crypto_aead_aegis256_nsecbytes","_crypto_aead_chacha20poly1305_abytes","_crypto_aead_chacha20poly1305_decrypt","_crypto_aead_chacha20poly1305_decrypt_detached","_crypto_aead_chacha20poly1305_encrypt","_crypto_aead_chacha20poly1305_encrypt_detached","_crypto_aead_chacha20poly1305_ietf_abytes","_crypto_aead_chacha20poly1305_ietf_decrypt","_crypto_aead_chacha20poly1305_ietf_decrypt_detached","_crypto_aead_chacha20poly1305_ietf_encrypt","_crypto_aead_chacha20poly1305_ietf_encrypt_detached","_crypto_aead_chacha20poly1305_ietf_keybytes","_crypto_aead_chacha20poly1305_ietf_keygen","_crypto_aead_chacha20poly1305_ietf_messagebytes_max","_crypto_aead_chacha20poly1305_ietf_npubbytes","_crypto_aead_chacha20poly1305_ietf_nsecbytes","_crypto_aead_chacha20poly1305_keybytes","_crypto_aead_chacha20poly1305_keygen","_crypto_aead_chacha20poly1305_messagebytes_max","_crypto_aead_chacha20poly1305_npubbytes","_crypto_aead_chacha20poly1305_nsecbytes","_crypto_aead_xchacha20poly1305_ietf_abytes","_crypto_aead_xchacha20poly1305_ietf_decrypt","_crypto_aead_xchacha20poly1305_ietf_decrypt_detached","_crypto_aead_xchacha20poly1305_ietf_encrypt","_crypto_aead_xchacha20poly1305_ietf_encrypt_detached","_crypto_aead_xchacha20poly1305_ietf_keybytes","_crypto_aead_xchacha20poly1305_ietf_keygen","_crypto_aead_xchacha20poly1305_ietf_messagebytes_max","_crypto_aead_xchacha20poly1305_ietf_npubbytes","_crypto_aead_xchacha20poly1305_ietf_nsecbytes","_crypto_auth","_crypto_auth_bytes","_crypto_auth_hmacsha256","_crypto_auth_hmacsha256_bytes","_crypto_auth_hmacsha256_final","_crypto_auth_hmacsha256_init","_crypto_auth_hmacsha256_keybytes","_crypto_auth_hmacsha256_keygen","_crypto_auth_hmacsha256_statebytes","_crypto_auth_hmacsha256_update","_crypto_auth_hmacsha256_verify","_crypto_auth_hmacsha512","_crypto_auth_hmacsha512256","_crypto_auth_hmacsha512256_bytes","_crypto_auth_hmacsha512256_final","_crypto_auth_hmacsha512256_init","_crypto_auth_hmacsha512256_keybytes","_crypto_auth_hmacsha512256_keygen","_crypto_auth_hmacsha512256_statebytes","_crypto_auth_hmacsha512256_update","_crypto_auth_hmacsha512256_verify","_crypto_auth_hmacsha512_bytes","_crypto_auth_hmacsha512_final","_crypto_auth_hmacsha512_init","_crypto_auth_hmacsha512_keybytes","_crypto_auth_hmacsha512_keygen","_crypto_auth_hmacsha512_statebytes","_crypto_auth_hmacsha512_update","_crypto_auth_hmacsha512_verify","_crypto_auth_keybytes","_crypto_auth_keygen","_crypto_auth_primitive","_crypto_auth_verify","_crypto_box","_crypto_box_afternm","_crypto_box_beforenm","_crypto_box_beforenmbytes","_crypto_box_boxzerobytes","_crypto_box_curve25519xchacha20poly1305_beforenm","_crypto_box_curve25519xchacha20poly1305_beforenmbytes","_crypto_box_curve25519xchacha20poly1305_detached","_crypto_box_curve25519xchacha20poly1305_detached_afternm","_crypto_box_curve25519xchacha20poly1305_easy","_crypto_box_curve25519xchacha20poly1305_easy_afternm","_crypto_box_curve25519xchacha20poly1305_keypair","_crypto_box_curve25519xchacha20poly1305_macbytes","_crypto_box_curve25519xchacha20poly1305_messagebytes_max","_crypto_box_curve25519xchacha20poly1305_noncebytes","_crypto_box_curve25519xchacha20poly1305_open_detached","_crypto_box_curve25519xchacha20poly1305_open_detached_afternm","_crypto_box_curve25519xchacha20poly1305_open_easy","_crypto_box_curve25519xchacha20poly1305_open_easy_afternm","_crypto_box_curve25519x
|
2019-05-30 07:04:55 -07:00
|
|
|
export EXPORTED_RUNTIME_METHODS='["UTF8ToString","getValue","setValue"]'
|
2023-02-16 12:08:23 -07:00
|
|
|
export JS_RESERVED_MEMORY_STANDARD=16MB
|
|
|
|
export JS_RESERVED_MEMORY_SUMO=48MB
|
|
|
|
export JS_RESERVED_MEMORY_TESTS=16MB
|
|
|
|
export WASM_INITIAL_MEMORY=4MB
|
2016-04-17 13:45:37 -07:00
|
|
|
export LDFLAGS="-s RESERVED_FUNCTION_POINTERS=8"
|
2018-12-30 06:57:06 -07:00
|
|
|
export LDFLAGS="${LDFLAGS} -s ALLOW_MEMORY_GROWTH=1"
|
2017-09-28 23:22:01 -07:00
|
|
|
export LDFLAGS="${LDFLAGS} -s SINGLE_FILE=1"
|
2017-12-26 20:05:08 -07:00
|
|
|
export LDFLAGS="${LDFLAGS} -s ASSERTIONS=0"
|
2016-04-14 14:13:40 -07:00
|
|
|
export LDFLAGS="${LDFLAGS} -s AGGRESSIVE_VARIABLE_ELIMINATION=1 -s ALIASING_FUNCTION_POINTERS=1"
|
2018-03-02 03:18:38 -07:00
|
|
|
export LDFLAGS="${LDFLAGS} -s DISABLE_EXCEPTION_CATCHING=1"
|
2016-04-14 14:13:40 -07:00
|
|
|
export LDFLAGS="${LDFLAGS} -s ELIMINATE_DUPLICATE_FUNCTIONS=1"
|
2019-08-01 03:49:02 -07:00
|
|
|
export LDFLAGS="${LDFLAGS} -s NODEJS_CATCH_EXIT=0"
|
2021-01-28 08:27:36 -07:00
|
|
|
export LDFLAGS="${LDFLAGS} -s NODEJS_CATCH_REJECTION=0"
|
2014-05-06 14:43:46 -07:00
|
|
|
|
2016-04-17 13:45:37 -07:00
|
|
|
echo
|
2023-02-16 12:08:23 -07:00
|
|
|
if [ "$1" = "--standard" ]; then
|
2016-04-17 13:45:37 -07:00
|
|
|
export EXPORTED_FUNCTIONS="$EXPORTED_FUNCTIONS_STANDARD"
|
2023-02-16 12:08:23 -07:00
|
|
|
export LDFLAGS="${LDFLAGS} ${LDFLAGS_DIST}"
|
|
|
|
export LDFLAGS_JS="-s TOTAL_MEMORY=${JS_RESERVED_MEMORY_STANDARD}"
|
2016-04-17 13:45:37 -07:00
|
|
|
export PREFIX="$(pwd)/libsodium-js"
|
|
|
|
export DONE_FILE="$(pwd)/js.done"
|
2017-03-17 08:56:20 -07:00
|
|
|
export CONFIG_EXTRA="--enable-minimal"
|
2016-04-17 13:45:37 -07:00
|
|
|
export DIST='yes'
|
2017-10-18 04:11:15 -07:00
|
|
|
echo "Building a standard distribution in [${PREFIX}]"
|
2023-02-16 12:08:23 -07:00
|
|
|
elif [ "$1" = "--sumo" ]; then
|
2016-03-21 12:59:18 -07:00
|
|
|
export EXPORTED_FUNCTIONS="$EXPORTED_FUNCTIONS_SUMO"
|
2023-02-16 12:08:23 -07:00
|
|
|
export LDFLAGS="${LDFLAGS} ${LDFLAGS_DIST}"
|
|
|
|
export LDFLAGS_JS="-s TOTAL_MEMORY=${JS_RESERVED_MEMORY_SUMO}"
|
2016-04-06 05:53:33 -07:00
|
|
|
export PREFIX="$(pwd)/libsodium-js-sumo"
|
2016-04-17 13:45:37 -07:00
|
|
|
export DONE_FILE="$(pwd)/js-sumo.done"
|
|
|
|
export DIST='yes'
|
2017-10-18 04:11:15 -07:00
|
|
|
echo "Building a sumo distribution in [${PREFIX}]"
|
2023-02-16 12:08:23 -07:00
|
|
|
elif [ "$1" = "--browser-tests" ]; then
|
2016-04-17 13:45:37 -07:00
|
|
|
export EXPORTED_FUNCTIONS="$EXPORTED_FUNCTIONS_SUMO"
|
2020-05-26 08:32:22 -07:00
|
|
|
export CPPFLAGS="${CPPFLAGS} -s FORCE_FILESYSTEM=1"
|
2023-02-16 12:08:23 -07:00
|
|
|
export LDFLAGS="${LDFLAGS}"
|
|
|
|
export LDFLAGS_JS="-s TOTAL_MEMORY=${JS_RESERVED_MEMORY_TESTS}"
|
2016-04-17 13:45:37 -07:00
|
|
|
export PREFIX="$(pwd)/libsodium-js-tests"
|
|
|
|
export DONE_FILE="$(pwd)/js-tests-browser.done"
|
|
|
|
export BROWSER_TESTS='yes'
|
|
|
|
export DIST='no'
|
2017-10-18 04:11:15 -07:00
|
|
|
echo "Building tests for web browsers in [${PREFIX}]"
|
2023-02-16 12:08:23 -07:00
|
|
|
elif [ "$1" = "--tests" ]; then
|
2016-04-17 13:45:37 -07:00
|
|
|
echo "Building for testing"
|
|
|
|
export EXPORTED_FUNCTIONS="$EXPORTED_FUNCTIONS_SUMO"
|
2020-05-26 08:32:22 -07:00
|
|
|
export CPPFLAGS="${CPPFLAGS} -s FORCE_FILESYSTEM=1 -DBENCHMARKS -DITERATIONS=10"
|
2023-02-16 12:08:23 -07:00
|
|
|
export LDFLAGS="${LDFLAGS}"
|
|
|
|
export LDFLAGS_JS="-s TOTAL_MEMORY=${JS_RESERVED_MEMORY_TESTS}"
|
2016-04-17 13:45:37 -07:00
|
|
|
export PREFIX="$(pwd)/libsodium-js-tests"
|
|
|
|
export DONE_FILE="$(pwd)/js-tests.done"
|
|
|
|
export DIST='no'
|
2017-10-18 04:11:15 -07:00
|
|
|
echo "Building for testing in [${PREFIX}]"
|
2016-04-06 05:53:33 -07:00
|
|
|
else
|
2016-04-17 13:45:37 -07:00
|
|
|
echo "Usage: $0 <build_type>"
|
|
|
|
echo "<build_type> := --standard | --sumo | --browser-tests | --tests"
|
|
|
|
echo
|
|
|
|
exit 1
|
2016-03-21 12:59:18 -07:00
|
|
|
fi
|
2021-06-17 12:58:25 -07:00
|
|
|
export JS_EXPORTS_FLAGS="-s EXPORTED_FUNCTIONS=${EXPORTED_FUNCTIONS} -s EXPORTED_RUNTIME_METHODS=${EXPORTED_RUNTIME_METHODS}"
|
2016-03-21 12:59:18 -07:00
|
|
|
|
2016-04-06 06:05:59 -07:00
|
|
|
rm -f "$DONE_FILE"
|
2015-12-06 17:44:33 -07:00
|
|
|
|
2016-04-17 13:45:37 -07:00
|
|
|
echo
|
2017-03-17 08:56:20 -07:00
|
|
|
|
|
|
|
emconfigure ./configure $CONFIG_EXTRA --disable-shared --prefix="$PREFIX" \
|
2023-02-16 11:36:15 -07:00
|
|
|
--without-pthreads \
|
2023-02-16 12:08:23 -07:00
|
|
|
--disable-ssp --disable-asm --disable-pie &&
|
2023-02-16 11:36:15 -07:00
|
|
|
emmake make clean
|
2016-04-17 13:45:37 -07:00
|
|
|
[ $? = 0 ] || exit 1
|
|
|
|
|
|
|
|
if [ "$DIST" = yes ]; then
|
2023-02-16 11:36:15 -07:00
|
|
|
emccLibsodium() {
|
2017-09-28 23:22:01 -07:00
|
|
|
outFile="${1}"
|
|
|
|
shift
|
2023-02-16 12:08:23 -07:00
|
|
|
emcc "$CFLAGS" --llvm-lto 1 $CPPFLAGS $LDFLAGS $JS_EXPORTS_FLAGS "${@}" \
|
2017-09-28 23:22:01 -07:00
|
|
|
"${PREFIX}/lib/libsodium.a" -o "${outFile}" || exit 1
|
|
|
|
}
|
|
|
|
emmake make $MAKE_FLAGS install || exit 1
|
2023-02-16 12:08:23 -07:00
|
|
|
emccLibsodium "${PREFIX}/lib/libsodium.asm.tmp.js" -Oz -s WASM=0 $LDFLAGS_JS
|
|
|
|
emccLibsodium "${PREFIX}/lib/libsodium.wasm.tmp.js" -O3 -s WASM=1 -s EVAL_CTORS=1 -s INITIAL_MEMORY=${WASM_INITIAL_MEMORY}
|
2017-09-28 23:22:01 -07:00
|
|
|
|
2023-02-16 11:36:15 -07:00
|
|
|
cat >"${PREFIX}/lib/libsodium.js" <<-EOM
|
2017-10-04 23:12:05 -07:00
|
|
|
var Module;
|
2017-09-28 23:22:01 -07:00
|
|
|
if (typeof Module === 'undefined') {
|
2017-10-04 23:12:05 -07:00
|
|
|
Module = {};
|
|
|
|
}
|
2017-10-04 23:31:07 -07:00
|
|
|
var root = Module;
|
2017-10-05 01:45:31 -07:00
|
|
|
if (typeof root['sodium'] !== 'object') {
|
2017-10-04 23:31:07 -07:00
|
|
|
if (typeof global === 'object') {
|
|
|
|
root = global;
|
|
|
|
} else if (typeof window === 'object') {
|
|
|
|
root = window;
|
|
|
|
}
|
2017-10-04 23:12:05 -07:00
|
|
|
}
|
2017-09-29 10:31:42 -07:00
|
|
|
var _Module = Module;
|
2018-08-30 13:54:15 -07:00
|
|
|
Module.ready = new Promise(function(resolve, reject) {
|
2017-09-29 10:31:42 -07:00
|
|
|
var Module = _Module;
|
2017-09-28 23:22:01 -07:00
|
|
|
Module.onAbort = reject;
|
2019-05-12 04:04:11 -07:00
|
|
|
Module.print = function(what) {
|
2019-05-12 04:51:41 -07:00
|
|
|
typeof(console) !== 'undefined' && console.log(what);
|
2019-05-12 04:04:11 -07:00
|
|
|
}
|
|
|
|
Module.printErr = function(what) {
|
2019-05-12 04:51:41 -07:00
|
|
|
typeof(console) !== 'undefined' && console.warn(what);
|
2019-05-12 04:04:11 -07:00
|
|
|
}
|
2018-08-30 13:54:15 -07:00
|
|
|
Module.onRuntimeInitialized = function() {
|
2018-03-05 23:48:25 -07:00
|
|
|
try {
|
|
|
|
/* Test arbitrary wasm function */
|
2018-03-06 02:56:05 -07:00
|
|
|
Module._crypto_secretbox_keybytes();
|
2018-03-05 23:48:25 -07:00
|
|
|
resolve();
|
|
|
|
} catch (err) {
|
|
|
|
reject(err);
|
|
|
|
}
|
|
|
|
};
|
2018-08-30 13:54:15 -07:00
|
|
|
Module.useBackupModule = function() {
|
2019-09-11 07:49:46 -07:00
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
var Module = {};
|
|
|
|
Module.onAbort = reject;
|
|
|
|
|
|
|
|
Module.onRuntimeInitialized = function() {
|
|
|
|
Object.keys(_Module).forEach(function(k) {
|
|
|
|
if (k !== 'getRandomValue') {
|
|
|
|
delete _Module[k];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Object.keys(Module).forEach(function(k) {
|
|
|
|
_Module[k] = Module[k];
|
|
|
|
});
|
|
|
|
resolve();
|
|
|
|
};
|
|
|
|
|
2023-02-16 12:08:23 -07:00
|
|
|
$(sed "s|use asm||g" "${PREFIX}/lib/libsodium.asm.tmp.js")
|
2019-09-08 18:41:24 -07:00
|
|
|
});
|
2018-08-22 17:06:32 -07:00
|
|
|
};
|
2017-09-28 23:22:01 -07:00
|
|
|
$(cat "${PREFIX}/lib/libsodium.wasm.tmp.js")
|
2018-08-30 13:54:15 -07:00
|
|
|
}).catch(function() {
|
2019-09-11 07:49:46 -07:00
|
|
|
return _Module.useBackupModule();
|
2017-09-28 23:22:01 -07:00
|
|
|
});
|
|
|
|
EOM
|
|
|
|
|
|
|
|
rm "${PREFIX}/lib/libsodium.asm.tmp.js" "${PREFIX}/lib/libsodium.wasm.tmp.js"
|
2016-04-17 13:45:37 -07:00
|
|
|
touch -r "${PREFIX}/lib/libsodium.js" "$DONE_FILE"
|
|
|
|
ls -l "${PREFIX}/lib/libsodium.js"
|
|
|
|
exit 0
|
|
|
|
fi
|
2014-12-04 11:28:49 -07:00
|
|
|
|
2023-02-16 12:08:23 -07:00
|
|
|
if test "$NODE" = ""; then
|
2017-12-20 14:51:58 -07:00
|
|
|
for candidate in /usr/local/bin/node /usr/local/bin/nodejs /usr/bin/node /usr/bin/nodejs node nodejs; do
|
2014-12-04 11:28:49 -07:00
|
|
|
case $($candidate --version 2>&1) in #(
|
2023-02-16 11:36:15 -07:00
|
|
|
v*)
|
|
|
|
NODE=$candidate
|
|
|
|
break
|
|
|
|
;;
|
2014-12-04 11:28:49 -07:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2015-12-06 17:44:33 -07:00
|
|
|
if [ "x$BROWSER_TESTS" != "x" ]; then
|
2023-02-16 11:36:15 -07:00
|
|
|
echo 'Compiling the test suite for web browsers...' &&
|
|
|
|
emmake make $MAKE_FLAGS CPPFLAGS="$CPPFLAGS -DBROWSER_TESTS=1" check >/dev/null 2>&1
|
2015-12-06 17:44:33 -07:00
|
|
|
else
|
2023-02-16 12:08:23 -07:00
|
|
|
if test "$NODE" = ""; then
|
2016-04-17 13:45:37 -07:00
|
|
|
echo 'node.js not found - test suite skipped' >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "Using [${NODE}] as a Javascript runtime"
|
2023-02-16 11:36:15 -07:00
|
|
|
echo 'Compiling the test suite...' &&
|
|
|
|
emmake make $MAKE_FLAGS check >/dev/null 2>&1
|
2015-12-06 17:44:33 -07:00
|
|
|
fi
|
2014-12-04 11:28:49 -07:00
|
|
|
|
2015-12-06 17:44:33 -07:00
|
|
|
if [ "x$BROWSER_TESTS" != "x" ]; then
|
2015-12-06 18:01:39 -07:00
|
|
|
echo 'Creating the test suite for web browsers'
|
2015-12-06 17:44:33 -07:00
|
|
|
(
|
2023-02-16 11:36:15 -07:00
|
|
|
cd test/default &&
|
|
|
|
mkdir -p browser &&
|
|
|
|
rm -f browser/tests.txt &&
|
|
|
|
for file in *.js; do
|
2023-02-16 12:08:23 -07:00
|
|
|
grep -Fv "#! /usr/bin/env ${NODE}" "$file" >"browser/${file}"
|
2023-02-16 11:36:15 -07:00
|
|
|
tname=$(echo "$file" | sed 's/.js$//')
|
|
|
|
cp -f "${tname}.exp" "browser/${tname}.exp"
|
|
|
|
sed "s/{{tname}}/${tname}/" index.html.tpl >"browser/${tname}.html"
|
|
|
|
echo "${tname}.html" >>"browser/tests.txt"
|
|
|
|
done
|
2016-04-17 13:45:37 -07:00
|
|
|
touch "$DONE_FILE"
|
2015-12-06 17:44:33 -07:00
|
|
|
)
|
|
|
|
else
|
|
|
|
echo 'Running the test suite'
|
|
|
|
(
|
2023-02-16 11:36:15 -07:00
|
|
|
cd test/default &&
|
|
|
|
for file in *.js; do
|
|
|
|
echo "#! /usr/bin/env ${NODE}" >"${file}.tmp"
|
2023-02-16 12:08:23 -07:00
|
|
|
grep -Fv "#! /usr/bin/env ${NODE}" "$file" >>"${file}.tmp"
|
2023-02-16 11:36:15 -07:00
|
|
|
chmod +x "${file}.tmp"
|
|
|
|
mv -f "${file}.tmp" "$file"
|
|
|
|
done
|
2015-12-06 17:44:33 -07:00
|
|
|
)
|
2016-10-29 16:25:32 -07:00
|
|
|
make $MAKE_FLAGS check || exit 1
|
2016-04-17 13:45:37 -07:00
|
|
|
touch "$DONE_FILE"
|
2015-12-06 17:44:33 -07:00
|
|
|
fi
|
2014-11-25 10:51:39 -07:00
|
|
|
|
2015-01-15 02:59:06 -07:00
|
|
|
echo 'Done.'
|