# These variables are specifically meant to be overridable via the make
# command-line.
CC ?= clang
-WASM_NM ?= $(patsubst %clang,%llvm-nm,$(filter-out ccache sccache,$(WASM_CC)))
-WASM_AR ?= $(patsubst %clang,%llvm-ar,$(filter-out ccache sccache,$(WASM_CC)))
-WASM_CFLAGS ?= -O2 -DNDEBUG
+NM ?= $(patsubst %clang,%llvm-nm,$(filter-out ccache sccache,$(CC)))
+AR ?= $(patsubst %clang,%llvm-ar,$(filter-out ccache sccache,$(CC)))
+EXTRA_CFLAGS ?= -O2 -DNDEBUG
# The directory where we build the sysroot.
SYSROOT ?= $(CURDIR)/sysroot
# A directory to install to for "make install".
$(LIBC_TOP_HALF_MUSL_SOURCES) \
$(shell find $(LIBC_TOP_HALF_SOURCES) -name \*.c)
+# Add any extra flags
+CFLAGS = $(EXTRA_CFLAGS)
# Set the target.
-CFLAGS = $(WASM_CFLAGS) --target=$(TARGET_TRIPLE)
+CFLAGS += --target=$(TARGET_TRIPLE)
# WebAssembly floating-point match doesn't trap.
# TODO: Add -fno-signaling-nans when the compiler supports it.
CFLAGS += -fno-trapping-math
%.a:
@mkdir -p "$(@D)"
# On Windows, the commandline for the ar invocation got too long, so it needs to be split up.
- $(WASM_AR) crs $@ $(wordlist 1, 199, $^)
- $(WASM_AR) crs $@ $(wordlist 200, 399, $^)
- $(WASM_AR) crs $@ $(wordlist 400, 599, $^)
- $(WASM_AR) crs $@ $(wordlist 600, 799, $^)
+ $(AR) crs $@ $(wordlist 1, 199, $^)
+ $(AR) crs $@ $(wordlist 200, 399, $^)
+ $(AR) crs $@ $(wordlist 400, 599, $^)
+ $(AR) crs $@ $(wordlist 600, 799, $^)
# This might eventually overflow again, but at least it'll do so in a loud way instead of
# silently dropping the tail.
- $(WASM_AR) crs $@ $(wordlist 800, 100000, $^)
+ $(AR) crs $@ $(wordlist 800, 100000, $^)
$(MUSL_PRINTSCAN_OBJS): CFLAGS += \
-D__wasilibc_printscan_no_long_double \
# Create empty placeholder libraries.
#
for name in m rt pthread crypt util xnet resolv dl; do \
- $(WASM_AR) crs "$(SYSROOT_LIB)/lib$${name}.a"; \
+ $(AR) crs "$(SYSROOT_LIB)/lib$${name}.a"; \
done
#
@# LLVM PR40497, which is fixed in 9.0, but not in 8.0.
@# Ignore certain llvm builtin symbols such as those starting with __mul
@# since these dependencies can vary between llvm versions.
- "$(WASM_NM)" --defined-only "$(SYSROOT_LIB)"/libc.a "$(SYSROOT_LIB)"/libwasi-emulated-*.a "$(SYSROOT_LIB)"/*.o \
+ "$(NM)" --defined-only "$(SYSROOT_LIB)"/libc.a "$(SYSROOT_LIB)"/libwasi-emulated-*.a "$(SYSROOT_LIB)"/*.o \
|grep ' [[:upper:]] ' |sed 's/.* [[:upper:]] //' |LC_ALL=C sort > "$(DEFINED_SYMBOLS)"
- for undef_sym in $$("$(WASM_NM)" --undefined-only "$(SYSROOT_LIB)"/libc.a "$(SYSROOT_LIB)"/libc-*.a "$(SYSROOT_LIB)"/*.o \
+ for undef_sym in $$("$(NM)" --undefined-only "$(SYSROOT_LIB)"/libc.a "$(SYSROOT_LIB)"/libc-*.a "$(SYSROOT_LIB)"/*.o \
|grep ' U ' |sed 's/.* U //' |LC_ALL=C sort |uniq); do \
grep -q '\<'$$undef_sym'\>' "$(DEFINED_SYMBOLS)" || echo $$undef_sym; \
done | grep -v "^__mul" > "$(UNDEFINED_SYMBOLS)"
@#
@# TODO: Undefine __FLOAT128__ for now since it's not in clang 8.0.
@# TODO: Filter out __FLT16_* for now, as not all versions of clang have these.
+ @# TODO: Filter out __NO_MATH_ERRNO_ and a few __*WIDTH__ that are new to clang 14.
+ @# TODO: clang defined __FLT_EVAL_METHOD__ until clang 15, so we force-undefine it
+ @# for older versions.
$(CC) $(CFLAGS) "$(SYSROOT_SHARE)/include-all.c" \
-isystem $(SYSROOT_INC) \
-std=gnu17 \
-U__GNUC_PATCHLEVEL__ \
-U__VERSION__ \
-U__FLOAT128__ \
+ -U__NO_MATH_ERRNO__ \
+ -U__BITINT_MAXWIDTH__ \
+ -U__FLT_EVAL_METHOD__ -Wno-builtin-macro-redefined \
| sed -e 's/__[[:upper:][:digit:]]*_ATOMIC_\([[:upper:][:digit:]_]*\)_LOCK_FREE/__compiler_ATOMIC_\1_LOCK_FREE/' \
| grep -v '^#define __FLT16_' \
+ | grep -v '^#define __\(BOOL\|INT_\(LEAST\|FAST\)\(8\|16\|32\|64\)\|INT\|LONG\|LLONG\|SHRT\)_WIDTH__' \
> "$(SYSROOT_SHARE)/predefined-macros.txt"
# Check that the computed metadata matches the expected metadata.