1 # These variables are specifically meant to be overridable via the make
4 NM ?
= $(patsubst %clang
,%llvm-nm
,$(filter-out ccache sccache
,$(CC
)))
5 AR ?
= $(patsubst %clang
,%llvm-ar
,$(filter-out ccache sccache
,$(CC
)))
6 EXTRA_CFLAGS ?
= -O2
-DNDEBUG
7 # The directory where we build the sysroot.
8 SYSROOT ?
= $(CURDIR
)/sysroot
9 # A directory to install to for "make install".
10 INSTALL_DIR ?
= /usr
/local
12 THREAD_MODEL ?
= single
14 MALLOC_IMPL ?
= dlmalloc
16 BUILD_LIBC_TOP_HALF ?
= yes
17 # The directory where we're store intermediate artifacts.
18 OBJDIR ?
= $(CURDIR
)/build
20 # Variables from this point on are not meant to be overridable via the
23 # Set the target variables. Multiarch triples notably omit the vendor field,
24 # which happens to be what we do for the main target triple too.
25 TARGET_TRIPLE
= wasm32-wasi
26 MULTIARCH_TRIPLE
= wasm32-wasi
28 # These variables describe the locations of various files and directories in
30 DLMALLOC_DIR
= $(CURDIR
)/dlmalloc
31 DLMALLOC_SRC_DIR
= $(DLMALLOC_DIR
)/src
32 DLMALLOC_SOURCES
= $(DLMALLOC_SRC_DIR
)/dlmalloc.c
33 DLMALLOC_INC
= $(DLMALLOC_DIR
)/include
34 LIBC_BOTTOM_HALF_DIR
= $(CURDIR
)/libc-bottom-half
35 LIBC_BOTTOM_HALF_CLOUDLIBC_SRC
= $(LIBC_BOTTOM_HALF_DIR
)/cloudlibc
/src
36 LIBC_BOTTOM_HALF_CLOUDLIBC_SRC_INC
= $(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC
)/include
37 LIBC_BOTTOM_HALF_HEADERS_PUBLIC
= $(LIBC_BOTTOM_HALF_DIR
)/headers
/public
38 LIBC_BOTTOM_HALF_HEADERS_PRIVATE
= $(LIBC_BOTTOM_HALF_DIR
)/headers
/private
39 LIBC_BOTTOM_HALF_SOURCES
= $(LIBC_BOTTOM_HALF_DIR
)/sources
40 LIBC_BOTTOM_HALF_ALL_SOURCES
= \
41 $(shell find
$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC
) -name \
*.c
) \
42 $(shell find
$(LIBC_BOTTOM_HALF_SOURCES
) -name \
*.c
)
44 # FIXME(https://reviews.llvm.org/D85567) - due to a bug in LLD the weak
45 # references to a function defined in `chdir.c` only work if `chdir.c` is at the
46 # end of the archive, but once that LLD review lands and propagates into LLVM
47 # then we don't have to do this.
48 LIBC_BOTTOM_HALF_ALL_SOURCES
:= $(filter-out $(LIBC_BOTTOM_HALF_SOURCES
)/chdir.c
,$(LIBC_BOTTOM_HALF_ALL_SOURCES
))
49 LIBC_BOTTOM_HALF_ALL_SOURCES
:= $(LIBC_BOTTOM_HALF_ALL_SOURCES
) $(LIBC_BOTTOM_HALF_SOURCES
)/chdir.c
51 LIBWASI_EMULATED_MMAN_SOURCES
= \
52 $(shell find
$(LIBC_BOTTOM_HALF_DIR
)/mman
-name \
*.c
)
53 LIBWASI_EMULATED_PROCESS_CLOCKS_SOURCES
= \
54 $(shell find
$(LIBC_BOTTOM_HALF_DIR
)/clocks
-name \
*.c
)
55 LIBWASI_EMULATED_GETPID_SOURCES
= \
56 $(shell find
$(LIBC_BOTTOM_HALF_DIR
)/getpid
-name \
*.c
)
57 LIBWASI_EMULATED_SIGNAL_SOURCES
= \
58 $(shell find
$(LIBC_BOTTOM_HALF_DIR
)/signal
-name \
*.c
)
59 LIBWASI_EMULATED_SIGNAL_MUSL_SOURCES
= \
60 $(LIBC_TOP_HALF_MUSL_SRC_DIR
)/signal
/psignal.c \
61 $(LIBC_TOP_HALF_MUSL_SRC_DIR
)/string
/strsignal.c
62 LIBC_BOTTOM_HALF_CRT_SOURCES
= $(wildcard $(LIBC_BOTTOM_HALF_DIR
)/crt
/*.c
)
63 LIBC_TOP_HALF_DIR
= $(CURDIR
)/libc-top-half
64 LIBC_TOP_HALF_MUSL_DIR
= $(LIBC_TOP_HALF_DIR
)/musl
65 LIBC_TOP_HALF_MUSL_SRC_DIR
= $(LIBC_TOP_HALF_MUSL_DIR
)/src
66 LIBC_TOP_HALF_MUSL_INC
= $(LIBC_TOP_HALF_MUSL_DIR
)/include
67 LIBC_TOP_HALF_MUSL_SOURCES
= \
68 $(addprefix $(LIBC_TOP_HALF_MUSL_SRC_DIR
)/, \
76 misc
/getdomainname.c \
91 network
/in6addr_any.c \
92 network
/in6addr_loopback.c \
96 fenv
/fesetexceptflag.c \
97 fenv
/fegetexceptflag.c \
103 exit
/at_quick_exit.c \
116 time
/timespec_get.c \
121 time
/__tm_to_secs.c \
122 time
/__month_to_secs.c \
123 time
/__secs_to_tm.c \
124 time
/__year_to_secs.c \
128 dirent
/versionsort.c \
134 unistd
/posix_close.c \
137 $(filter-out %/procfdname.c
%/syscall.c
%/syscall_ret.c
%/vdso.c
%/version.c
, \
138 $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR
)/internal
/*.c
)) \
139 $(filter-out %/flockfile.c
%/funlockfile.c
%/__lockfile.c
%/ftrylockfile.c \
141 %/tmpnam.c
%/tmpfile.c
%/tempnam.c \
142 %/popen.c
%/pclose.c \
145 $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR
)/stdio
/*.c
)) \
146 $(filter-out %/strsignal.c
, \
147 $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR
)/string
/*.c
)) \
148 $(filter-out %/dcngettext.c
%/textdomain.c
%/bind_textdomain_codeset.c
, \
149 $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR
)/locale
/*.c
)) \
150 $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR
)/stdlib
/*.c
) \
151 $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR
)/search
/*.c
) \
152 $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR
)/multibyte
/*.c
) \
153 $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR
)/regex
/*.c
) \
154 $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR
)/prng
/*.c
) \
155 $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR
)/conf
/*.c
) \
156 $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR
)/ctype
/*.c
) \
157 $(filter-out %/__signbit.c
%/__signbitf.c
%/__signbitl.c \
158 %/__fpclassify.c
%/__fpclassifyf.c
%/__fpclassifyl.c \
160 %/floorf.c
%/floor.c \
161 %/truncf.c
%/trunc.c \
163 %/nearbyintf.c
%/nearbyint.c \
166 %/copysignf.c
%/copysign.c \
167 %/fminf.c
%/fmaxf.c \
169 $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR
)/math
/*.c
)) \
170 $(filter-out %/crealf.c
%/creal.c
%creall.c \
171 %/cimagf.c
%/cimag.c
%cimagl.c
, \
172 $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR
)/complex
/*.c
)) \
173 $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR
)/crypt
/*.c
)
174 MUSL_PRINTSCAN_SOURCES
= \
175 $(LIBC_TOP_HALF_MUSL_SRC_DIR
)/internal
/floatscan.c \
176 $(LIBC_TOP_HALF_MUSL_SRC_DIR
)/stdio
/vfprintf.c \
177 $(LIBC_TOP_HALF_MUSL_SRC_DIR
)/stdio
/vfwprintf.c \
178 $(LIBC_TOP_HALF_MUSL_SRC_DIR
)/stdio
/vfscanf.c \
179 $(LIBC_TOP_HALF_MUSL_SRC_DIR
)/stdlib
/strtod.c \
180 $(LIBC_TOP_HALF_MUSL_SRC_DIR
)/stdlib
/wcstod.c
181 LIBC_TOP_HALF_HEADERS_PRIVATE
= $(LIBC_TOP_HALF_DIR
)/headers
/private
182 LIBC_TOP_HALF_SOURCES
= $(LIBC_TOP_HALF_DIR
)/sources
183 LIBC_TOP_HALF_ALL_SOURCES
= \
184 $(LIBC_TOP_HALF_MUSL_SOURCES
) \
185 $(shell find
$(LIBC_TOP_HALF_SOURCES
) -name \
*.c
)
187 # Add any extra flags
188 CFLAGS
= $(EXTRA_CFLAGS
)
190 CFLAGS
+= --target
=$(TARGET_TRIPLE
)
191 # WebAssembly floating-point match doesn't trap.
192 # TODO: Add -fno-signaling-nans when the compiler supports it.
193 CFLAGS
+= -fno-trapping-math
194 # Add all warnings, but disable a few which occur in third-party code.
195 CFLAGS
+= -Wall
-Wextra
-Werror \
196 -Wno-null-pointer-arithmetic \
197 -Wno-unused-parameter \
199 -Wno-unused-variable \
200 -Wno-unused-function \
201 -Wno-ignored-attributes \
202 -Wno-missing-braces \
203 -Wno-ignored-pragmas \
204 -Wno-unused-but-set-variable \
205 -Wno-unknown-warning-option
207 # Configure support for threads.
208 ifeq ($(THREAD_MODEL
), single
)
209 CFLAGS
+= -mthread-model single
211 ifeq ($(THREAD_MODEL
), posix
)
212 CFLAGS
+= -mthread-model posix
-pthread
215 # Expose the public headers to the implementation. We use `-isystem` for
216 # purpose for two reasons:
218 # 1. It only does `<...>` not `"...."` lookup. We are making a libc,
219 # which is a system library, so all public headers should be
220 # accessible via `<...>` and never also need `"..."`. `-isystem` main
221 # purpose is to only effect `<...>` lookup.
223 # 2. The `-I` for private headers added for specific C files below
224 # should come earlier in the search path, so they can "override"
225 # and/or `#include_next` the public headers. `-isystem` (like
226 # `-idirafter`) comes later in the search path than `-I`.
227 CFLAGS
+= -isystem
"$(SYSROOT_INC)"
229 # These variables describe the locations of various files and directories in
231 objs
= $(patsubst $(CURDIR
)/%.c
,$(OBJDIR
)/%.o
,$(1))
232 DLMALLOC_OBJS
= $(call objs
,$(DLMALLOC_SOURCES
))
233 LIBC_BOTTOM_HALF_ALL_OBJS
= $(call objs
,$(LIBC_BOTTOM_HALF_ALL_SOURCES
))
234 LIBC_TOP_HALF_ALL_OBJS
= $(call objs
,$(LIBC_TOP_HALF_ALL_SOURCES
))
235 ifeq ($(MALLOC_IMPL
),dlmalloc
)
236 LIBC_OBJS
+= $(DLMALLOC_OBJS
)
237 else ifeq ($(MALLOC_IMPL
),none
)
238 # No object files to add.
240 $(error unknown malloc implementation
$(MALLOC_IMPL
))
242 # Add libc-bottom-half's objects.
243 LIBC_OBJS
+= $(LIBC_BOTTOM_HALF_ALL_OBJS
)
244 ifeq ($(BUILD_LIBC_TOP_HALF
),yes
)
245 # libc-top-half is musl.
246 LIBC_OBJS
+= $(LIBC_TOP_HALF_ALL_OBJS
)
248 MUSL_PRINTSCAN_OBJS
= $(call objs
,$(MUSL_PRINTSCAN_SOURCES
))
249 MUSL_PRINTSCAN_LONG_DOUBLE_OBJS
= $(patsubst %.o
,%.long-double.o
,$(MUSL_PRINTSCAN_OBJS
))
250 MUSL_PRINTSCAN_NO_FLOATING_POINT_OBJS
= $(patsubst %.o
,%.no-floating-point.o
,$(MUSL_PRINTSCAN_OBJS
))
251 LIBWASI_EMULATED_MMAN_OBJS
= $(call objs
,$(LIBWASI_EMULATED_MMAN_SOURCES
))
252 LIBWASI_EMULATED_PROCESS_CLOCKS_OBJS
= $(call objs
,$(LIBWASI_EMULATED_PROCESS_CLOCKS_SOURCES
))
253 LIBWASI_EMULATED_GETPID_OBJS
= $(call objs
,$(LIBWASI_EMULATED_GETPID_SOURCES
))
254 LIBWASI_EMULATED_SIGNAL_OBJS
= $(call objs
,$(LIBWASI_EMULATED_SIGNAL_SOURCES
))
255 LIBWASI_EMULATED_SIGNAL_MUSL_OBJS
= $(call objs
,$(LIBWASI_EMULATED_SIGNAL_MUSL_SOURCES
))
257 # These variables describe the locations of various files and
258 # directories in the generated sysroot tree.
259 SYSROOT_LIB
:= $(SYSROOT
)/lib
/$(MULTIARCH_TRIPLE
)
260 SYSROOT_INC
= $(SYSROOT
)/include
261 SYSROOT_SHARE
= $(SYSROOT
)/share
/$(MULTIARCH_TRIPLE
)
263 # Files from musl's include directory that we don't want to install in the
264 # sysroot's include directory.
267 # Remove files which aren't headers (we generate alltypes.h below).
268 MUSL_OMIT_HEADERS
+= \
269 "bits/syscall.h.in" \
270 "bits/alltypes.h.in" \
273 # Use the compiler's version of these headers.
274 MUSL_OMIT_HEADERS
+= \
278 # Use the WASI errno definitions.
279 MUSL_OMIT_HEADERS
+= \
282 # Remove headers that aren't supported yet or that aren't relevant for WASI.
283 MUSL_OMIT_HEADERS
+= \
286 "sys/kd.h" "sys/vt.h" "sys/soundcard.h" "sys/sem.h" \
287 "sys/shm.h" "sys/msg.h" "sys/ipc.h" "sys/ptrace.h" \
289 "bits/kd.h" "bits/vt.h" "bits/soundcard.h" "bits/sem.h" \
290 "bits/shm.h" "bits/msg.h" "bits/ipc.h" "bits/ptrace.h" \
294 "syslog.h" "sys/syslog.h" \
295 "wait.h" "sys/wait.h" \
296 "ucontext.h" "sys/ucontext.h" \
302 "sys/epoll.h" "sys/reboot.h" "sys/swap.h" \
303 "sys/sendfile.h" "sys/inotify.h" \
312 "sys/personality.h" \
313 "elf.h" "link.h" "bits/link.h" \
314 "scsi/scsi.h" "scsi/scsi_ioctl.h" "scsi/sg.h" \
316 "pwd.h" "shadow.h" "grp.h" \
336 "netinet/if_ether.h" \
342 ifeq ($(THREAD_MODEL
), single
)
343 # Remove headers not supported in single-threaded mode.
344 MUSL_OMIT_HEADERS
+= "aio.h" "pthread.h"
349 $(SYSROOT_LIB
)/libc.a
: $(LIBC_OBJS
)
351 $(SYSROOT_LIB
)/libc-printscan-long-double.a
: $(MUSL_PRINTSCAN_LONG_DOUBLE_OBJS
)
353 $(SYSROOT_LIB
)/libc-printscan-no-floating-point.a
: $(MUSL_PRINTSCAN_NO_FLOATING_POINT_OBJS
)
355 $(SYSROOT_LIB
)/libwasi-emulated-mman.a
: $(LIBWASI_EMULATED_MMAN_OBJS
)
357 $(SYSROOT_LIB
)/libwasi-emulated-process-clocks.a
: $(LIBWASI_EMULATED_PROCESS_CLOCKS_OBJS
)
359 $(SYSROOT_LIB
)/libwasi-emulated-getpid.a
: $(LIBWASI_EMULATED_GETPID_OBJS
)
361 $(SYSROOT_LIB
)/libwasi-emulated-signal.a
: $(LIBWASI_EMULATED_SIGNAL_OBJS
) $(LIBWASI_EMULATED_SIGNAL_MUSL_OBJS
)
365 # On Windows, the commandline for the ar invocation got too long, so it needs to be split up.
366 $(AR
) crs
$@
$(wordlist
1, 199, $^
)
367 $(AR
) crs
$@
$(wordlist
200, 399, $^
)
368 $(AR
) crs
$@
$(wordlist
400, 599, $^
)
369 $(AR
) crs
$@
$(wordlist
600, 799, $^
)
370 # This might eventually overflow again, but at least it'll do so in a loud way instead of
371 # silently dropping the tail.
372 $(AR
) crs
$@
$(wordlist
800, 100000, $^
)
374 $(MUSL_PRINTSCAN_OBJS
): CFLAGS
+= \
375 -D__wasilibc_printscan_no_long_double \
376 -D__wasilibc_printscan_full_support_option
="\"add -lc-printscan-long-double to the link command\""
378 $(MUSL_PRINTSCAN_NO_FLOATING_POINT_OBJS
): CFLAGS
+= \
379 -D__wasilibc_printscan_no_floating_point \
380 -D__wasilibc_printscan_floating_point_support_option
="\"remove -lc-printscan-no-floating-point from the link command\""
382 $(LIBWASI_EMULATED_SIGNAL_MUSL_OBJS
): CFLAGS
+= \
383 -D_WASI_EMULATED_SIGNAL
385 $(OBJDIR
)/%.long-double.o
: $(CURDIR
)/%.c include_dirs
387 $(CC
) $(CFLAGS
) -MD
-MP
-o
$@
-c
$<
389 $(OBJDIR
)/%.no-floating-point.o
: $(CURDIR
)/%.c include_dirs
391 $(CC
) $(CFLAGS
) -MD
-MP
-o
$@
-c
$<
393 $(OBJDIR
)/%.o
: $(CURDIR
)/%.c include_dirs
395 $(CC
) $(CFLAGS
) -MD
-MP
-o
$@
-c
$<
397 -include $(shell find
$(OBJDIR
) -name \
*.d
)
399 $(DLMALLOC_OBJS
): CFLAGS
+= \
402 startup_files
$(LIBC_BOTTOM_HALF_ALL_OBJS
): CFLAGS
+= \
403 -I
$(LIBC_BOTTOM_HALF_HEADERS_PRIVATE
) \
404 -I
$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC_INC
) \
405 -I
$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC
)
407 $(LIBC_TOP_HALF_ALL_OBJS
) $(MUSL_PRINTSCAN_LONG_DOUBLE_OBJS
) $(MUSL_PRINTSCAN_NO_FLOATING_POINT_OBJS
) $(LIBWASI_EMULATED_SIGNAL_MUSL_OBJS
): CFLAGS
+= \
408 -I
$(LIBC_TOP_HALF_MUSL_SRC_DIR
)/include \
409 -I
$(LIBC_TOP_HALF_MUSL_SRC_DIR
)/internal \
410 -I
$(LIBC_TOP_HALF_MUSL_DIR
)/arch
/wasm32 \
411 -I
$(LIBC_TOP_HALF_MUSL_DIR
)/arch
/generic \
412 -I
$(LIBC_TOP_HALF_HEADERS_PRIVATE
) \
414 -Wno-shift-op-parentheses \
415 -Wno-bitwise-op-parentheses \
416 -Wno-logical-op-parentheses \
417 -Wno-string-plus-int \
421 $(LIBWASI_EMULATED_PROCESS_CLOCKS_OBJS
): CFLAGS
+= \
422 -I
$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC
)
426 # Install the include files.
428 mkdir
-p
"$(SYSROOT_INC)"
429 cp
-r
"$(LIBC_BOTTOM_HALF_HEADERS_PUBLIC)"/* "$(SYSROOT_INC)"
431 # Generate musl's bits/alltypes.h header.
432 mkdir
-p
"$(SYSROOT_INC)/bits"
433 sed
-f
$(LIBC_TOP_HALF_MUSL_DIR
)/tools
/mkalltypes.sed \
434 $(LIBC_TOP_HALF_MUSL_DIR
)/arch
/wasm32
/bits
/alltypes.h.in \
435 $(LIBC_TOP_HALF_MUSL_DIR
)/include/alltypes.h.in \
436 > "$(SYSROOT_INC)/bits/alltypes.h"
438 # Copy in the bulk of musl's public header files.
439 cp
-r
"$(LIBC_TOP_HALF_MUSL_INC)"/* "$(SYSROOT_INC)"
440 # Copy in the musl's "bits" header files.
441 cp
-r
"$(LIBC_TOP_HALF_MUSL_DIR)"/arch
/generic
/bits
/* "$(SYSROOT_INC)/bits"
442 cp
-r
"$(LIBC_TOP_HALF_MUSL_DIR)"/arch
/wasm32
/bits
/* "$(SYSROOT_INC)/bits"
444 # Remove selected header files.
445 $(RM
) $(patsubst %,$(SYSROOT_INC
)/%,$(MUSL_OMIT_HEADERS
))
447 startup_files
: include_dirs
449 # Build the startup files.
451 @mkdir
-p
"$(OBJDIR)"
453 $(CC
) $(CFLAGS
) -c
$(LIBC_BOTTOM_HALF_CRT_SOURCES
) -MD
-MP
&& \
454 mkdir
-p
"$(SYSROOT_LIB)" && \
455 mv
*.o
"$(SYSROOT_LIB)"
458 $(SYSROOT_LIB
)/libc.a \
459 $(SYSROOT_LIB
)/libc-printscan-long-double.a \
460 $(SYSROOT_LIB
)/libc-printscan-no-floating-point.a \
461 $(SYSROOT_LIB
)/libwasi-emulated-mman.a \
462 $(SYSROOT_LIB
)/libwasi-emulated-process-clocks.a \
463 $(SYSROOT_LIB
)/libwasi-emulated-getpid.a \
464 $(SYSROOT_LIB
)/libwasi-emulated-signal.a
466 finish
: startup_files libc
468 # Create empty placeholder libraries.
470 for name in m rt pthread crypt util xnet resolv dl
; do \
471 $(AR
) crs
"$(SYSROOT_LIB)/lib$${name}.a"; \
475 # The build succeeded! The generated sysroot is in $(SYSROOT).
478 # The check for defined and undefined symbols expects there to be a heap
479 # alloctor (providing malloc, calloc, free, etc). Skip this step if the build
480 # is done without a malloc implementation.
481 ifneq ($(MALLOC_IMPL
),none
)
482 finish
: check-symbols
485 DEFINED_SYMBOLS
= $(SYSROOT_SHARE
)/defined-symbols.txt
486 UNDEFINED_SYMBOLS
= $(SYSROOT_SHARE
)/undefined-symbols.txt
488 check-symbols
: startup_files libc
490 # Collect metadata on the sysroot and perform sanity checks.
492 mkdir
-p
"$(SYSROOT_SHARE)"
495 # Collect symbol information.
497 @
# TODO: Use llvm-nm --extern-only instead of grep. This is blocked on
498 @
# LLVM PR40497, which is fixed in 9.0, but not in 8.0.
499 @
# Ignore certain llvm builtin symbols such as those starting with __mul
500 @
# since these dependencies can vary between llvm versions.
501 "$(NM)" --defined-only
"$(SYSROOT_LIB)"/libc.a
"$(SYSROOT_LIB)"/libwasi-emulated-
*.a
"$(SYSROOT_LIB)"/*.o \
502 |grep
' [[:upper:]] ' |sed
's/.* [[:upper:]] //' |LC_ALL
=C
sort > "$(DEFINED_SYMBOLS)"
503 for undef_sym in
$$("$(NM)" --undefined-only
"$(SYSROOT_LIB)"/libc.a
"$(SYSROOT_LIB)"/libc-
*.a
"$(SYSROOT_LIB)"/*.o \
504 |grep
' U ' |sed
's/.* U //' |LC_ALL
=C
sort |uniq
); do \
505 grep
-q
'\<'$$undef_sym'\>' "$(DEFINED_SYMBOLS)" || echo
$$undef_sym; \
506 done | grep
-v
"^__mul" > "$(UNDEFINED_SYMBOLS)"
507 grep
'^_*imported_wasi_' "$(UNDEFINED_SYMBOLS)" \
508 > "$(SYSROOT_LIB)/libc.imports"
511 # Generate a test file that includes all public header files.
513 cd
"$(SYSROOT_INC)" && \
514 for header in
$$(find .
-type f
-not
-name mman.h
-not
-name signal.h
-not
-name times.h
-not
-name resource.h |grep
-v
/bits
/); do \
515 echo
'#include <'$$header'>' | sed
's/\.\///' ; \
516 done |LC_ALL
=C
sort >$(SYSROOT_SHARE
)/include-all.c
; \
520 # Test that it compiles.
522 $(CC
) $(CFLAGS
) -fsyntax-only
"$(SYSROOT_SHARE)/include-all.c" -Wno-\
#warnings
525 # Collect all the predefined macros, except for compiler version macros
526 # which we don't need to track here.
529 @
# For the __*_ATOMIC_*_LOCK_FREE macros, squash individual compiler names
530 @
# to attempt, toward keeping these files compiler-independent.
532 @
# We have to add `-isystem $(SYSROOT_INC)` because otherwise clang puts
533 @
# its builtin include path first, which produces compiler-specific
536 @
# TODO: Undefine __FLOAT128__ for now since it's not in clang 8.0.
537 @
# TODO: Filter out __FLT16_* for now, as not all versions of clang have these.
538 @
# TODO: Filter out __NO_MATH_ERRNO_ and a few __*WIDTH__ that are new to clang 14.
539 @
# TODO: clang defined __FLT_EVAL_METHOD__ until clang 15, so we force-undefine it
540 @
# for older versions.
541 $(CC
) $(CFLAGS
) "$(SYSROOT_SHARE)/include-all.c" \
542 -isystem
$(SYSROOT_INC
) \
544 -E
-dM
-Wno-\
#warnings \
550 -U__clang_patchlevel__ \
551 -U__clang_version__ \
552 -U__clang_literal_encoding__ \
553 -U__clang_wide_literal_encoding__ \
556 -U__GNUC_PATCHLEVEL__ \
559 -U__NO_MATH_ERRNO__ \
560 -U__BITINT_MAXWIDTH__ \
561 -U__FLT_EVAL_METHOD__
-Wno-builtin-macro-redefined \
562 | sed
-e
's/__[[:upper:][:digit:]]*_ATOMIC_\([[:upper:][:digit:]_]*\)_LOCK_FREE/__compiler_ATOMIC_\1_LOCK_FREE/' \
563 | grep
-v
'^#define __FLT16_' \
564 | grep
-v
'^#define __\(BOOL\|INT_\(LEAST\|FAST\)\(8\|16\|32\|64\)\|INT\|LONG\|LLONG\|SHRT\)_WIDTH__' \
565 > "$(SYSROOT_SHARE)/predefined-macros.txt"
567 # Check that the computed metadata matches the expected metadata.
568 # This ignores whitespace because on Windows the output has CRLF line endings.
569 diff
-wur
"$(CURDIR)/expected/$(MULTIARCH_TRIPLE)" "$(SYSROOT_SHARE)"
572 mkdir
-p
"$(INSTALL_DIR)"
573 cp
-r
"$(SYSROOT)/lib" "$(SYSROOT)/share" "$(SYSROOT)/include" "$(INSTALL_DIR)"
577 $(RM
) -r
"$(SYSROOT)"
579 .PHONY
: default startup_files libc finish
install include_dirs
clean