diff --git a/src/Makefile b/src/Makefile index c83abfa0..0276f9e3 100644 --- a/src/Makefile +++ b/src/Makefile @@ -26,7 +26,7 @@ NODOTABIVER= 51 DEFAULT_CC = gcc # # LuaJIT builds as a native 32 or 64 bit binary by default. -CC= $(DEFAULT_CC) +CC ?= $(DEFAULT_CC) # # Use this if you want to force a 32 bit build on a 64 bit multilib OS. #CC= $(DEFAULT_CC) -m32 @@ -70,10 +70,10 @@ CCWARN= -Wall # as dynamic mode. # # Mixed mode creates a static + dynamic library and a statically linked luajit. -BUILDMODE= mixed +#BUILDMODE= mixed # # Static mode creates a static library and a statically linked luajit. -#BUILDMODE= static +BUILDMODE= static # # Dynamic mode creates a dynamic library and a dynamically linked luajit. # Note: this executable will only run when the library is installed! @@ -98,7 +98,7 @@ XCFLAGS= # enabled by default. Some other features that *might* break some existing # code (e.g. __pairs or os.execute() return values) can be enabled here. # Note: this does not provide full compatibility with Lua 5.2 at this time. -#XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT +XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT # # Disable the JIT compiler, i.e. turn LuaJIT into a pure interpreter. #XCFLAGS+= -DLUAJIT_DISABLE_JIT @@ -211,7 +211,7 @@ TARGET_STCC= $(STATIC_CC) TARGET_DYNCC= $(DYNAMIC_CC) TARGET_LD= $(CROSS)$(CC) TARGET_AR= $(CROSS)ar rcus -TARGET_STRIP= $(CROSS)strip +TARGET_STRIP?= $(CROSS)strip TARGET_LIBPATH= $(or $(PREFIX),/usr/local)/$(or $(MULTILIB),lib) TARGET_SONAME= libluajit-$(ABIVER).so.$(MAJVER) @@ -616,7 +616,7 @@ endif Q= @ E= @echo -#Q= +Q= #E= @: ############################################################################## diff --git a/luajit_build.sh b/luajit_build.sh new file mode 100755 index 00000000..3b4f8eca --- /dev/null +++ b/luajit_build.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash + +set -e + +PREFIX="" +while [[ $# -gt 0 ]]; do + case $1 in + --prefix=*) + PREFIX="${1#*=}" + shift + ;; + --prefix) + PREFIX="$2" + shift 2 + ;; + *) + shift + ;; + esac +done + +# Copy source tree to a build directory +SRC_DIR="$(dirname "$(realpath "$0")")" +BUILD_DIR="$(basename "$SRC_DIR")" +cp -r "$SRC_DIR" "$BUILD_DIR" +cd "$BUILD_DIR" + +# Set environment variables +export MACOSX_DEPLOYMENT_TARGET="10.8" +export DEFAULT_CC="${CC:-}" +export TARGET_CFLAGS="${CFLAGS:-} -fno-function-sections -fno-data-sections" +EXTRA_MAKE_ARGS=() +FUSE_LD_FLAG=$(echo "$LDFLAGS" | grep -o -- '-fuse-ld=[^ ]*' | tail -1 || :) +SYSROOT_FLAG=$(echo "$LDFLAGS" | grep -o -- '--sysroot=[^ ]*' || :) +if [[ "$(uname -s)" == "Linux" ]]; then + SAN_LDFLAGS="${FUSE_LD_FLAG} ${SYSROOT_FLAG}" + EXTRA_MAKE_ARGS+=("TARGET_AR=${AR} ${ARFLAGS:-rcus}") + export TARGET_LDFLAGS="${LDFLAGS:-} -fno-function-sections -fno-data-sections" + export CFLAGS="" +elif [[ "$(uname -s)" == "FreeBSD" ]]; then + EXTRA_MAKE_ARGS+=("TARGET_AR=${AR} ${ARFLAGS:-rcus}") + export TARGET_CFLAGS="${TARGET_CFLAGS} -fno-stack-protector -U_FORTIFY_SOURCE" + export TARGET_LDFLAGS="${LDFLAGS:-} -fno-function-sections -fno-data-sections" + export CFLAGS="" +else + # macOS: extract sysroot from CFLAGS and pass to HOST_CFLAGS/HOST_LDFLAGS for building host tools + SYSROOT_FLAG=$(echo "$CFLAGS" | grep -o -- '--sysroot=[^ ]*' || :) + if [[ -n "${SYSROOT_FLAG}" ]]; then + export HOST_CFLAGS="${SYSROOT_FLAG}" + export HOST_LDFLAGS="${SYSROOT_FLAG}" + EXTRA_MAKE_ARGS+=("HOST_CFLAGS=${HOST_CFLAGS}" "HOST_LDFLAGS=${HOST_LDFLAGS}") + fi + export TARGET_LDFLAGS="${CFLAGS:-} -fno-function-sections -fno-data-sections" + export CFLAGS="" + export LDFLAGS="" +fi + +# Don't strip the binary - it doesn't work when cross-compiling +export TARGET_STRIP="@echo" + +# Remove LuaJIT from ASAN/MSAN for now +# TODO(htuch): Remove this when https://github.com/envoyproxy/envoy/issues/6084 is resolved +if [[ -n "${ENVOY_CONFIG_ASAN}" ]] || [[ -n "${ENVOY_CONFIG_MSAN}" ]]; then + export LDFLAGS="$SAN_LDFLAGS" + BLOCK_PATH=$(realpath clang-asan-blocklist.txt) + export TARGET_CFLAGS="${TARGET_CFLAGS} -fsanitize-blacklist=${BLOCK_PATH}" + echo "fun:*" > clang-asan-blocklist.txt +fi + +# Run make with all available cores +NPROC=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 1) +"${MAKE:-make}" -j${NPROC} V=1 PREFIX="$PREFIX" \ + "${EXTRA_MAKE_ARGS[@]}" \ + install