11# These variables are specifically meant to be overridable via
22# the make command-line.
3- WASM_CC = clang
4- WASM_NM = $(patsubst % clang,% llvm-nm,$(WASM_CC ) )
5- WASM_AR = $(patsubst % clang,% llvm-ar,$(WASM_CC ) )
6- WASM_CFLAGS = -O2
3+ WASM_CC ? = clang
4+ WASM_NM ? = $(patsubst % clang,% llvm-nm,$(WASM_CC ) )
5+ WASM_AR ? = $(patsubst % clang,% llvm-ar,$(WASM_CC ) )
6+ WASM_CFLAGS ? = -O2
77# The directory where we build the sysroot.
8- SYSROOT = $(CURDIR ) /sysroot
8+ SYSROOT ? = $(CURDIR ) /sysroot
99# A directory to install to for "make install".
10- INSTALL_DIR = /usr/local
10+ INSTALL_DIR ? = /usr/local
1111# single or posix
1212THREAD_MODEL = single
1313# yes or no
@@ -245,7 +245,14 @@ $(SYSROOT_LIB)/libwasi-emulated-mman.a: $(LIBWASI_EMULATED_MMAN_OBJS)
245245
246246% .a :
247247 @mkdir -p " $( @D) "
248- $(WASM_AR ) crs $@ $^
248+ # On Windows, the commandline for the ar invocation got too long, so it needs to be split up.
249+ $(WASM_AR ) crs $@ $(wordlist 1, 199, $^ )
250+ $(WASM_AR ) crs $@ $(wordlist 200, 399, $^ )
251+ $(WASM_AR ) crs $@ $(wordlist 400, 599, $^ )
252+ $(WASM_AR ) crs $@ $(wordlist 600, 799, $^ )
253+ # This might eventually overflow again, but at least it'll do so in a loud way instead of
254+ # silently dropping the tail.
255+ $(WASM_AR ) crs $@ $(wordlist 800, 100000, $^ )
249256
250257$(MUSL_PRINTSCAN_OBJS ) : override WASM_CFLAGS += \
251258 -D__wasilibc_printscan_no_long_double \
@@ -267,7 +274,7 @@ $(OBJDIR)/%.o: $(CURDIR)/%.c include_dirs
267274 @mkdir -p " $( @D) "
268275 " $( WASM_CC) " $(WASM_CFLAGS ) -MD -MP -o $@ -c $<
269276
270- include $(shell find $(OBJDIR ) -name \* .d) /dev/null
277+ - include $(shell find $(OBJDIR ) -name \* .d)
271278
272279$(DLMALLOC_OBJS ) : override WASM_CFLAGS += \
273280 -I$(DLMALLOC_INC)
@@ -444,9 +451,9 @@ finish: startup_files libc
444451 # Collect symbol information.
445452 # TODO: Use llvm-nm --extern-only instead of grep. This is blocked on
446453 # LLVM PR40497, which is fixed in 9.0, but not in 8.0.
447- $(WASM_NM) --defined-only "$(SYSROOT_LIB)"/libc.a "$(SYSROOT_LIB)"/*.o \
454+ " $(WASM_NM)" --defined-only "$(SYSROOT_LIB)"/libc.a "$(SYSROOT_LIB)"/*.o \
448455 |grep ' [[:upper:]] ' |sed 's/.* [[:upper:]] //' |LC_ALL=C sort > "$(SYSROOT_SHARE)/defined-symbols.txt"
449- for undef_sym in $$($(WASM_NM) --undefined-only "$(SYSROOT_LIB)"/*.a "$(SYSROOT_LIB)"/*.o \
456+ for undef_sym in $$(" $(WASM_NM)" --undefined-only "$(SYSROOT_LIB)"/*.a "$(SYSROOT_LIB)"/*.o \
450457 |grep ' U ' |sed 's/.* U //' |LC_ALL=C sort |uniq); do \
451458 grep -q '\<'$$undef_sym'\>' "$(SYSROOT_SHARE)/defined-symbols.txt" || echo $$undef_sym; \
452459 done > "$(SYSROOT_SHARE)/undefined-symbols.txt"
@@ -499,7 +506,8 @@ finish: startup_files libc
499506
500507check : finish
501508 # Check that the computed metadata matches the expected metadata.
502- diff -ur " $( CURDIR) /expected/$( MULTIARCH_TRIPLE) " " $( SYSROOT_SHARE) "
509+ # This ignores whitespace because on Windows the output has CRLF line endings.
510+ diff -wur " $( CURDIR) /expected/$( MULTIARCH_TRIPLE) " " $( SYSROOT_SHARE) "
503511
504512install : finish
505513 mkdir -p " $( INSTALL_DIR) "
0 commit comments