]>
Commit | Line | Data |
---|---|---|
41af0db3 DG |
1 | # These variables are specifically meant to be overridable via the make |
2 | # command-line. | |
255e6f7c | 3 | WASM_CC ?= clang |
90a62361 VL |
4 | WASM_NM ?= $(patsubst %clang,%llvm-nm,$(filter-out ccache sccache,$(WASM_CC))) |
5 | WASM_AR ?= $(patsubst %clang,%llvm-ar,$(filter-out ccache sccache,$(WASM_CC))) | |
7fcc4f29 | 6 | WASM_CFLAGS ?= -O2 -DNDEBUG |
320054e8 | 7 | # The directory where we build the sysroot. |
255e6f7c | 8 | SYSROOT ?= $(CURDIR)/sysroot |
320054e8 | 9 | # A directory to install to for "make install". |
255e6f7c | 10 | INSTALL_DIR ?= /usr/local |
dbfccac2 | 11 | # single or posix |
41af0db3 | 12 | THREAD_MODEL ?= single |
c7465d22 AL |
13 | # dlmalloc or none |
14 | MALLOC_IMPL ?= dlmalloc | |
320054e8 | 15 | # yes or no |
41af0db3 | 16 | BUILD_LIBC_TOP_HALF ?= yes |
320054e8 | 17 | # The directory where we're store intermediate artifacts. |
41af0db3 | 18 | OBJDIR ?= $(CURDIR)/build |
320054e8 | 19 | |
41af0db3 DG |
20 | # Variables from this point on are not meant to be overridable via the |
21 | # make command-line. | |
22 | ||
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 | |
27 | ||
28 | # These variables describe the locations of various files and directories in | |
29 | # the source tree. | |
320054e8 | 30 | DLMALLOC_DIR = $(CURDIR)/dlmalloc |
dbfccac2 | 31 | DLMALLOC_SRC_DIR = $(DLMALLOC_DIR)/src |
320054e8 | 32 | DLMALLOC_SOURCES = $(DLMALLOC_SRC_DIR)/dlmalloc.c |
dbfccac2 | 33 | DLMALLOC_INC = $(DLMALLOC_DIR)/include |
320054e8 DG |
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 | |
320054e8 DG |
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) \ | |
320054e8 | 42 | $(shell find $(LIBC_BOTTOM_HALF_SOURCES) -name \*.c) |
5b148b61 AC |
43 | |
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 | |
50 | ||
320054e8 DG |
51 | LIBWASI_EMULATED_MMAN_SOURCES = \ |
52 | $(shell find $(LIBC_BOTTOM_HALF_DIR)/mman -name \*.c) | |
b9b64a69 DG |
53 | LIBWASI_EMULATED_PROCESS_CLOCKS_SOURCES = \ |
54 | $(shell find $(LIBC_BOTTOM_HALF_DIR)/clocks -name \*.c) | |
659ff414 DG |
55 | LIBWASI_EMULATED_GETPID_SOURCES = \ |
56 | $(shell find $(LIBC_BOTTOM_HALF_DIR)/getpid -name \*.c) | |
d1cd4f48 DG |
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 | |
320054e8 DG |
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 = \ | |
41af0db3 DG |
68 | $(addprefix $(LIBC_TOP_HALF_MUSL_SRC_DIR)/, \ |
69 | misc/a64l.c \ | |
70 | misc/basename.c \ | |
71 | misc/dirname.c \ | |
72 | misc/ffs.c \ | |
73 | misc/ffsl.c \ | |
74 | misc/ffsll.c \ | |
75 | misc/fmtmsg.c \ | |
76 | misc/getdomainname.c \ | |
77 | misc/gethostid.c \ | |
78 | misc/getopt.c \ | |
79 | misc/getopt_long.c \ | |
80 | misc/getsubopt.c \ | |
81 | misc/uname.c \ | |
82 | misc/nftw.c \ | |
83 | errno/strerror.c \ | |
84 | network/htonl.c \ | |
85 | network/htons.c \ | |
86 | network/ntohl.c \ | |
87 | network/ntohs.c \ | |
88 | network/inet_ntop.c \ | |
89 | network/inet_pton.c \ | |
90 | network/inet_aton.c \ | |
91 | network/in6addr_any.c \ | |
92 | network/in6addr_loopback.c \ | |
93 | fenv/fenv.c \ | |
94 | fenv/fesetround.c \ | |
95 | fenv/feupdateenv.c \ | |
96 | fenv/fesetexceptflag.c \ | |
97 | fenv/fegetexceptflag.c \ | |
98 | fenv/feholdexcept.c \ | |
99 | exit/exit.c \ | |
100 | exit/atexit.c \ | |
101 | exit/assert.c \ | |
102 | exit/quick_exit.c \ | |
103 | exit/at_quick_exit.c \ | |
104 | time/strftime.c \ | |
105 | time/asctime.c \ | |
106 | time/asctime_r.c \ | |
107 | time/ctime.c \ | |
108 | time/ctime_r.c \ | |
109 | time/wcsftime.c \ | |
110 | time/strptime.c \ | |
111 | time/difftime.c \ | |
112 | time/timegm.c \ | |
113 | time/ftime.c \ | |
114 | time/gmtime.c \ | |
115 | time/gmtime_r.c \ | |
116 | time/timespec_get.c \ | |
117 | time/getdate.c \ | |
118 | time/localtime.c \ | |
119 | time/localtime_r.c \ | |
120 | time/mktime.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 \ | |
125 | time/__tz.c \ | |
126 | fcntl/creat.c \ | |
127 | dirent/alphasort.c \ | |
128 | dirent/versionsort.c \ | |
129 | env/clearenv.c \ | |
130 | env/getenv.c \ | |
131 | env/putenv.c \ | |
132 | env/setenv.c \ | |
133 | env/unsetenv.c \ | |
134 | unistd/posix_close.c \ | |
135 | ) \ | |
320054e8 DG |
136 | $(filter-out %/procfdname.c %/syscall.c %/syscall_ret.c %/vdso.c %/version.c, \ |
137 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/internal/*.c)) \ | |
138 | $(filter-out %/flockfile.c %/funlockfile.c %/__lockfile.c %/ftrylockfile.c \ | |
139 | %/rename.c \ | |
140 | %/tmpnam.c %/tmpfile.c %/tempnam.c \ | |
141 | %/popen.c %/pclose.c \ | |
142 | %/remove.c \ | |
143 | %/gets.c, \ | |
144 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdio/*.c)) \ | |
145 | $(filter-out %/strsignal.c, \ | |
146 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/string/*.c)) \ | |
8048aeb5 | 147 | $(filter-out %/dcngettext.c %/textdomain.c %/bind_textdomain_codeset.c, \ |
320054e8 DG |
148 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/locale/*.c)) \ |
149 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdlib/*.c) \ | |
150 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/search/*.c) \ | |
151 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/multibyte/*.c) \ | |
152 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/regex/*.c) \ | |
320054e8 DG |
153 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/prng/*.c) \ |
154 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/conf/*.c) \ | |
155 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/ctype/*.c) \ | |
900b8032 | 156 | $(filter-out %/__signbit.c %/__signbitf.c %/__signbitl.c \ |
16450763 DG |
157 | %/__fpclassify.c %/__fpclassifyf.c %/__fpclassifyl.c \ |
158 | %/ceilf.c %/ceil.c \ | |
159 | %/floorf.c %/floor.c \ | |
160 | %/truncf.c %/trunc.c \ | |
161 | %/rintf.c %/rint.c \ | |
162 | %/nearbyintf.c %/nearbyint.c \ | |
163 | %/sqrtf.c %/sqrt.c \ | |
164 | %/fabsf.c %/fabs.c \ | |
cf81683e DG |
165 | %/copysignf.c %/copysign.c \ |
166 | %/fminf.c %/fmaxf.c \ | |
167 | %/fmin.c %/fmax.c, \ | |
900b8032 | 168 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/math/*.c)) \ |
5ccebd31 DG |
169 | $(filter-out %/crealf.c %/creal.c %creall.c \ |
170 | %/cimagf.c %/cimag.c %cimagl.c, \ | |
7d5074ff | 171 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/complex/*.c)) \ |
320054e8 DG |
172 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/crypt/*.c) |
173 | MUSL_PRINTSCAN_SOURCES = \ | |
174 | $(LIBC_TOP_HALF_MUSL_SRC_DIR)/internal/floatscan.c \ | |
175 | $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdio/vfprintf.c \ | |
2201343c | 176 | $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdio/vfwprintf.c \ |
320054e8 DG |
177 | $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdio/vfscanf.c \ |
178 | $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdlib/strtod.c \ | |
179 | $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdlib/wcstod.c | |
180 | LIBC_TOP_HALF_HEADERS_PRIVATE = $(LIBC_TOP_HALF_DIR)/headers/private | |
181 | LIBC_TOP_HALF_SOURCES = $(LIBC_TOP_HALF_DIR)/sources | |
182 | LIBC_TOP_HALF_ALL_SOURCES = \ | |
183 | $(LIBC_TOP_HALF_MUSL_SOURCES) \ | |
184 | $(shell find $(LIBC_TOP_HALF_SOURCES) -name \*.c) | |
185 | ||
320054e8 | 186 | # Set the target. |
5ccfab77 | 187 | CFLAGS = $(WASM_CFLAGS) --target=$(TARGET_TRIPLE) |
320054e8 DG |
188 | # WebAssembly floating-point match doesn't trap. |
189 | # TODO: Add -fno-signaling-nans when the compiler supports it. | |
5ccfab77 | 190 | CFLAGS += -fno-trapping-math |
63f0f3c5 DG |
191 | # Add all warnings, but disable a few which occur in third-party code. |
192 | CFLAGS += -Wall -Wextra -Werror \ | |
193 | -Wno-null-pointer-arithmetic \ | |
9520010f | 194 | -Wno-unused-parameter \ |
e69430a9 | 195 | -Wno-sign-compare \ |
6273a5ff | 196 | -Wno-unused-variable \ |
ed6e0ba9 | 197 | -Wno-unused-function \ |
e8270d1b | 198 | -Wno-ignored-attributes \ |
b77dcff6 | 199 | -Wno-missing-braces \ |
9cbfeaaa | 200 | -Wno-ignored-pragmas \ |
a78cd329 DG |
201 | -Wno-unused-but-set-variable \ |
202 | -Wno-unknown-warning-option | |
dbfccac2 DG |
203 | |
204 | # Configure support for threads. | |
320054e8 | 205 | ifeq ($(THREAD_MODEL), single) |
5ccfab77 | 206 | CFLAGS += -mthread-model single |
dbfccac2 | 207 | endif |
320054e8 | 208 | ifeq ($(THREAD_MODEL), posix) |
5ccfab77 | 209 | CFLAGS += -mthread-model posix -pthread |
320054e8 DG |
210 | endif |
211 | ||
212 | # Set the sysroot. | |
5ccfab77 | 213 | CFLAGS += --sysroot="$(SYSROOT)" |
320054e8 | 214 | |
41af0db3 DG |
215 | # These variables describe the locations of various files and directories in |
216 | # the build tree. | |
320054e8 | 217 | objs = $(patsubst $(CURDIR)/%.c,$(OBJDIR)/%.o,$(1)) |
41af0db3 DG |
218 | DLMALLOC_OBJS = $(call objs,$(DLMALLOC_SOURCES)) |
219 | LIBC_BOTTOM_HALF_ALL_OBJS = $(call objs,$(LIBC_BOTTOM_HALF_ALL_SOURCES)) | |
220 | LIBC_TOP_HALF_ALL_OBJS = $(call objs,$(LIBC_TOP_HALF_ALL_SOURCES)) | |
c7465d22 | 221 | ifeq ($(MALLOC_IMPL),dlmalloc) |
41af0db3 | 222 | LIBC_OBJS += $(DLMALLOC_OBJS) |
c7465d22 AL |
223 | else ifeq ($(MALLOC_IMPL),none) |
224 | # No object files to add. | |
225 | else | |
226 | $(error unknown malloc implementation $(MALLOC_IMPL)) | |
dbfccac2 | 227 | endif |
320054e8 | 228 | # Add libc-bottom-half's objects. |
41af0db3 | 229 | LIBC_OBJS += $(LIBC_BOTTOM_HALF_ALL_OBJS) |
320054e8 | 230 | ifeq ($(BUILD_LIBC_TOP_HALF),yes) |
320054e8 | 231 | # libc-top-half is musl. |
41af0db3 | 232 | LIBC_OBJS += $(LIBC_TOP_HALF_ALL_OBJS) |
320054e8 | 233 | endif |
41af0db3 DG |
234 | MUSL_PRINTSCAN_OBJS = $(call objs,$(MUSL_PRINTSCAN_SOURCES)) |
235 | MUSL_PRINTSCAN_LONG_DOUBLE_OBJS = $(patsubst %.o,%.long-double.o,$(MUSL_PRINTSCAN_OBJS)) | |
236 | MUSL_PRINTSCAN_NO_FLOATING_POINT_OBJS = $(patsubst %.o,%.no-floating-point.o,$(MUSL_PRINTSCAN_OBJS)) | |
237 | LIBWASI_EMULATED_MMAN_OBJS = $(call objs,$(LIBWASI_EMULATED_MMAN_SOURCES)) | |
b9b64a69 | 238 | LIBWASI_EMULATED_PROCESS_CLOCKS_OBJS = $(call objs,$(LIBWASI_EMULATED_PROCESS_CLOCKS_SOURCES)) |
659ff414 | 239 | LIBWASI_EMULATED_GETPID_OBJS = $(call objs,$(LIBWASI_EMULATED_GETPID_SOURCES)) |
d1cd4f48 DG |
240 | LIBWASI_EMULATED_SIGNAL_OBJS = $(call objs,$(LIBWASI_EMULATED_SIGNAL_SOURCES)) |
241 | LIBWASI_EMULATED_SIGNAL_MUSL_OBJS = $(call objs,$(LIBWASI_EMULATED_SIGNAL_MUSL_SOURCES)) | |
41af0db3 DG |
242 | |
243 | # These variables describe the locations of various files and | |
244 | # directories in the generated sysroot tree. | |
245 | SYSROOT_LIB := $(SYSROOT)/lib/$(MULTIARCH_TRIPLE) | |
246 | SYSROOT_INC = $(SYSROOT)/include | |
247 | SYSROOT_SHARE = $(SYSROOT)/share/$(MULTIARCH_TRIPLE) | |
320054e8 | 248 | |
1f409842 DG |
249 | # Files from musl's include directory that we don't want to install in the |
250 | # sysroot's include directory. | |
41af0db3 | 251 | MUSL_OMIT_HEADERS := |
1f409842 DG |
252 | |
253 | # Remove files which aren't headers (we generate alltypes.h below). | |
41af0db3 | 254 | MUSL_OMIT_HEADERS += \ |
1f409842 DG |
255 | "bits/syscall.h.in" \ |
256 | "bits/alltypes.h.in" \ | |
257 | "alltypes.h.in" | |
258 | ||
33e8b518 | 259 | # Use the compiler's version of these headers. |
41af0db3 | 260 | MUSL_OMIT_HEADERS += \ |
33e8b518 DG |
261 | "stdarg.h" \ |
262 | "stddef.h" | |
263 | ||
1f409842 | 264 | # Use the WASI errno definitions. |
41af0db3 | 265 | MUSL_OMIT_HEADERS += \ |
1f409842 DG |
266 | "bits/errno.h" |
267 | ||
268 | # Remove headers that aren't supported yet or that aren't relevant for WASI. | |
41af0db3 | 269 | MUSL_OMIT_HEADERS += \ |
1f409842 DG |
270 | "sys/procfs.h" \ |
271 | "sys/user.h" \ | |
272 | "sys/kd.h" "sys/vt.h" "sys/soundcard.h" "sys/sem.h" \ | |
273 | "sys/shm.h" "sys/msg.h" "sys/ipc.h" "sys/ptrace.h" \ | |
274 | "sys/statfs.h" \ | |
275 | "bits/kd.h" "bits/vt.h" "bits/soundcard.h" "bits/sem.h" \ | |
276 | "bits/shm.h" "bits/msg.h" "bits/ipc.h" "bits/ptrace.h" \ | |
277 | "bits/statfs.h" \ | |
278 | "sys/vfs.h" \ | |
279 | "sys/statvfs.h" \ | |
280 | "syslog.h" "sys/syslog.h" \ | |
281 | "wait.h" "sys/wait.h" \ | |
282 | "ucontext.h" "sys/ucontext.h" \ | |
283 | "paths.h" \ | |
284 | "utmp.h" "utmpx.h" \ | |
285 | "lastlog.h" \ | |
286 | "sys/acct.h" \ | |
287 | "sys/cachectl.h" \ | |
288 | "sys/epoll.h" "sys/reboot.h" "sys/swap.h" \ | |
289 | "sys/sendfile.h" "sys/inotify.h" \ | |
290 | "sys/quota.h" \ | |
291 | "sys/klog.h" \ | |
292 | "sys/fsuid.h" \ | |
293 | "sys/io.h" \ | |
294 | "sys/prctl.h" \ | |
295 | "sys/mtio.h" \ | |
296 | "sys/mount.h" \ | |
297 | "sys/fanotify.h" \ | |
298 | "sys/personality.h" \ | |
299 | "elf.h" "link.h" "bits/link.h" \ | |
300 | "scsi/scsi.h" "scsi/scsi_ioctl.h" "scsi/sg.h" \ | |
301 | "sys/auxv.h" \ | |
302 | "pwd.h" "shadow.h" "grp.h" \ | |
303 | "mntent.h" \ | |
304 | "netdb.h" \ | |
305 | "resolv.h" \ | |
306 | "pty.h" \ | |
307 | "dlfcn.h" \ | |
308 | "setjmp.h" \ | |
309 | "ulimit.h" \ | |
310 | "sys/xattr.h" \ | |
311 | "wordexp.h" \ | |
312 | "spawn.h" \ | |
313 | "sys/membarrier.h" \ | |
314 | "sys/signalfd.h" \ | |
315 | "termios.h" \ | |
316 | "sys/termios.h" \ | |
317 | "bits/termios.h" \ | |
318 | "net/if.h" \ | |
319 | "net/if_arp.h" \ | |
320 | "net/ethernet.h" \ | |
321 | "net/route.h" \ | |
322 | "netinet/if_ether.h" \ | |
323 | "netinet/ether.h" \ | |
eb7230cf DG |
324 | "sys/timerfd.h" \ |
325 | "libintl.h" \ | |
7b92f334 | 326 | "sys/sysmacros.h" |
1f409842 DG |
327 | |
328 | ifeq ($(THREAD_MODEL), single) | |
329 | # Remove headers not supported in single-threaded mode. | |
41af0db3 | 330 | MUSL_OMIT_HEADERS += "aio.h" "pthread.h" |
1f409842 DG |
331 | endif |
332 | ||
41af0db3 | 333 | default: finish |
320054e8 DG |
334 | |
335 | $(SYSROOT_LIB)/libc.a: $(LIBC_OBJS) | |
336 | ||
337 | $(SYSROOT_LIB)/libc-printscan-long-double.a: $(MUSL_PRINTSCAN_LONG_DOUBLE_OBJS) | |
338 | ||
339 | $(SYSROOT_LIB)/libc-printscan-no-floating-point.a: $(MUSL_PRINTSCAN_NO_FLOATING_POINT_OBJS) | |
340 | ||
341 | $(SYSROOT_LIB)/libwasi-emulated-mman.a: $(LIBWASI_EMULATED_MMAN_OBJS) | |
342 | ||
b9b64a69 DG |
343 | $(SYSROOT_LIB)/libwasi-emulated-process-clocks.a: $(LIBWASI_EMULATED_PROCESS_CLOCKS_OBJS) |
344 | ||
659ff414 DG |
345 | $(SYSROOT_LIB)/libwasi-emulated-getpid.a: $(LIBWASI_EMULATED_GETPID_OBJS) |
346 | ||
d1cd4f48 DG |
347 | $(SYSROOT_LIB)/libwasi-emulated-signal.a: $(LIBWASI_EMULATED_SIGNAL_OBJS) $(LIBWASI_EMULATED_SIGNAL_MUSL_OBJS) |
348 | ||
320054e8 DG |
349 | %.a: |
350 | @mkdir -p "$(@D)" | |
255e6f7c TS |
351 | # On Windows, the commandline for the ar invocation got too long, so it needs to be split up. |
352 | $(WASM_AR) crs $@ $(wordlist 1, 199, $^) | |
353 | $(WASM_AR) crs $@ $(wordlist 200, 399, $^) | |
354 | $(WASM_AR) crs $@ $(wordlist 400, 599, $^) | |
355 | $(WASM_AR) crs $@ $(wordlist 600, 799, $^) | |
356 | # This might eventually overflow again, but at least it'll do so in a loud way instead of | |
357 | # silently dropping the tail. | |
358 | $(WASM_AR) crs $@ $(wordlist 800, 100000, $^) | |
320054e8 | 359 | |
5ccfab77 | 360 | $(MUSL_PRINTSCAN_OBJS): CFLAGS += \ |
320054e8 DG |
361 | -D__wasilibc_printscan_no_long_double \ |
362 | -D__wasilibc_printscan_full_support_option="\"add -lc-printscan-long-double to the link command\"" | |
363 | ||
5ccfab77 | 364 | $(MUSL_PRINTSCAN_NO_FLOATING_POINT_OBJS): CFLAGS += \ |
320054e8 DG |
365 | -D__wasilibc_printscan_no_floating_point \ |
366 | -D__wasilibc_printscan_floating_point_support_option="\"remove -lc-printscan-no-floating-point from the link command\"" | |
367 | ||
5ccfab77 | 368 | $(LIBWASI_EMULATED_SIGNAL_MUSL_OBJS): CFLAGS += \ |
d1cd4f48 DG |
369 | -D_WASI_EMULATED_SIGNAL |
370 | ||
8e8cc34a | 371 | $(OBJDIR)/%.long-double.o: $(CURDIR)/%.c include_dirs |
320054e8 | 372 | @mkdir -p "$(@D)" |
90a62361 | 373 | $(WASM_CC) $(CFLAGS) -MD -MP -o $@ -c $< |
dcf13b6f | 374 | |
8e8cc34a | 375 | $(OBJDIR)/%.no-floating-point.o: $(CURDIR)/%.c include_dirs |
320054e8 | 376 | @mkdir -p "$(@D)" |
90a62361 | 377 | $(WASM_CC) $(CFLAGS) -MD -MP -o $@ -c $< |
320054e8 | 378 | |
8e8cc34a | 379 | $(OBJDIR)/%.o: $(CURDIR)/%.c include_dirs |
320054e8 | 380 | @mkdir -p "$(@D)" |
90a62361 | 381 | $(WASM_CC) $(CFLAGS) -MD -MP -o $@ -c $< |
320054e8 | 382 | |
255e6f7c | 383 | -include $(shell find $(OBJDIR) -name \*.d) |
320054e8 | 384 | |
5ccfab77 | 385 | $(DLMALLOC_OBJS): CFLAGS += \ |
320054e8 DG |
386 | -I$(DLMALLOC_INC) |
387 | ||
5ccfab77 | 388 | startup_files $(LIBC_BOTTOM_HALF_ALL_OBJS): CFLAGS += \ |
320054e8 DG |
389 | -I$(LIBC_BOTTOM_HALF_HEADERS_PRIVATE) \ |
390 | -I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC_INC) \ | |
7fcc4f29 | 391 | -I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC) |
320054e8 | 392 | |
5ccfab77 | 393 | $(LIBC_TOP_HALF_ALL_OBJS) $(MUSL_PRINTSCAN_LONG_DOUBLE_OBJS) $(MUSL_PRINTSCAN_NO_FLOATING_POINT_OBJS) $(LIBWASI_EMULATED_SIGNAL_MUSL_OBJS): CFLAGS += \ |
320054e8 DG |
394 | -I$(LIBC_TOP_HALF_MUSL_SRC_DIR)/include \ |
395 | -I$(LIBC_TOP_HALF_MUSL_SRC_DIR)/internal \ | |
396 | -I$(LIBC_TOP_HALF_MUSL_DIR)/arch/wasm32 \ | |
397 | -I$(LIBC_TOP_HALF_MUSL_DIR)/arch/generic \ | |
398 | -I$(LIBC_TOP_HALF_HEADERS_PRIVATE) \ | |
399 | -Wno-parentheses \ | |
400 | -Wno-shift-op-parentheses \ | |
401 | -Wno-bitwise-op-parentheses \ | |
402 | -Wno-logical-op-parentheses \ | |
403 | -Wno-string-plus-int \ | |
404 | -Wno-dangling-else \ | |
405 | -Wno-unknown-pragmas | |
406 | ||
b9b64a69 DG |
407 | $(LIBWASI_EMULATED_PROCESS_CLOCKS_OBJS): CFLAGS += \ |
408 | -I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC) | |
409 | ||
8e8cc34a | 410 | include_dirs: |
dcf13b6f | 411 | $(RM) -r "$(SYSROOT)" |
dcf13b6f DG |
412 | |
413 | # | |
414 | # Install the include files. | |
415 | # | |
320054e8 | 416 | mkdir -p "$(SYSROOT_INC)" |
320054e8 DG |
417 | cp -r "$(LIBC_BOTTOM_HALF_HEADERS_PUBLIC)"/* "$(SYSROOT_INC)" |
418 | ||
419 | # Generate musl's bits/alltypes.h header. | |
420 | mkdir -p "$(SYSROOT_INC)/bits" | |
421 | sed -f $(LIBC_TOP_HALF_MUSL_DIR)/tools/mkalltypes.sed \ | |
422 | $(LIBC_TOP_HALF_MUSL_DIR)/arch/wasm32/bits/alltypes.h.in \ | |
423 | $(LIBC_TOP_HALF_MUSL_DIR)/include/alltypes.h.in \ | |
424 | > "$(SYSROOT_INC)/bits/alltypes.h" | |
425 | ||
426 | # Copy in the bulk of musl's public header files. | |
427 | cp -r "$(LIBC_TOP_HALF_MUSL_INC)"/* "$(SYSROOT_INC)" | |
428 | # Copy in the musl's "bits" header files. | |
429 | cp -r "$(LIBC_TOP_HALF_MUSL_DIR)"/arch/generic/bits/* "$(SYSROOT_INC)/bits" | |
430 | cp -r "$(LIBC_TOP_HALF_MUSL_DIR)"/arch/wasm32/bits/* "$(SYSROOT_INC)/bits" | |
431 | ||
1f409842 DG |
432 | # Remove selected header files. |
433 | $(RM) $(patsubst %,$(SYSROOT_INC)/%,$(MUSL_OMIT_HEADERS)) | |
320054e8 | 434 | |
8e8cc34a | 435 | startup_files: include_dirs |
dcf13b6f | 436 | # |
320054e8 | 437 | # Build the startup files. |
dcf13b6f | 438 | # |
320054e8 DG |
439 | @mkdir -p "$(OBJDIR)" |
440 | cd "$(OBJDIR)" && \ | |
90a62361 | 441 | $(WASM_CC) $(CFLAGS) -c $(LIBC_BOTTOM_HALF_CRT_SOURCES) -MD -MP && \ |
320054e8 DG |
442 | mkdir -p "$(SYSROOT_LIB)" && \ |
443 | mv *.o "$(SYSROOT_LIB)" | |
dcf13b6f | 444 | |
8e8cc34a | 445 | libc: include_dirs \ |
320054e8 DG |
446 | $(SYSROOT_LIB)/libc.a \ |
447 | $(SYSROOT_LIB)/libc-printscan-long-double.a \ | |
448 | $(SYSROOT_LIB)/libc-printscan-no-floating-point.a \ | |
d1cd4f48 | 449 | $(SYSROOT_LIB)/libwasi-emulated-mman.a \ |
b9b64a69 | 450 | $(SYSROOT_LIB)/libwasi-emulated-process-clocks.a \ |
659ff414 | 451 | $(SYSROOT_LIB)/libwasi-emulated-getpid.a \ |
d1cd4f48 | 452 | $(SYSROOT_LIB)/libwasi-emulated-signal.a |
320054e8 | 453 | |
8e8cc34a | 454 | finish: startup_files libc |
dcf13b6f | 455 | # |
320054e8 | 456 | # Create empty placeholder libraries. |
dcf13b6f | 457 | # |
1f7d798a | 458 | for name in m rt pthread crypt util xnet resolv dl; do \ |
320054e8 DG |
459 | $(WASM_AR) crs "$(SYSROOT_LIB)/lib$${name}.a"; \ |
460 | done | |
dbfccac2 | 461 | |
c7465d22 AL |
462 | # |
463 | # The build succeeded! The generated sysroot is in $(SYSROOT). | |
464 | # | |
465 | ||
466 | # The check for defined and undefined symbols expects there to be a heap | |
467 | # alloctor (providing malloc, calloc, free, etc). Skip this step if the build | |
468 | # is done without a malloc implementation. | |
469 | ifneq ($(MALLOC_IMPL),none) | |
470 | finish: check-symbols | |
471 | endif | |
472 | ||
473 | check-symbols: startup_files libc | |
dbfccac2 | 474 | # |
320054e8 | 475 | # Collect metadata on the sysroot and perform sanity checks. |
dbfccac2 | 476 | # |
320054e8 DG |
477 | mkdir -p "$(SYSROOT_SHARE)" |
478 | ||
41af0db3 | 479 | # |
320054e8 | 480 | # Collect symbol information. |
41af0db3 DG |
481 | # |
482 | @# TODO: Use llvm-nm --extern-only instead of grep. This is blocked on | |
483 | @# LLVM PR40497, which is fixed in 9.0, but not in 8.0. | |
484 | @# Ignore certain llvm builtin symbols such as those starting with __mul | |
485 | @# since these dependencies can vary between llvm versions. | |
549b32be | 486 | "$(WASM_NM)" --defined-only "$(SYSROOT_LIB)"/libc.a "$(SYSROOT_LIB)"/libwasi-emulated-*.a "$(SYSROOT_LIB)"/*.o \ |
fad009dc | 487 | |grep ' [[:upper:]] ' |sed 's/.* [[:upper:]] //' |LC_ALL=C sort > "$(SYSROOT_SHARE)/defined-symbols.txt" |
d1cd4f48 | 488 | for undef_sym in $$("$(WASM_NM)" --undefined-only "$(SYSROOT_LIB)"/libc.a "$(SYSROOT_LIB)"/libc-*.a "$(SYSROOT_LIB)"/*.o \ |
fad009dc | 489 | |grep ' U ' |sed 's/.* U //' |LC_ALL=C sort |uniq); do \ |
320054e8 | 490 | grep -q '\<'$$undef_sym'\>' "$(SYSROOT_SHARE)/defined-symbols.txt" || echo $$undef_sym; \ |
c35f0f5d | 491 | done | grep -v "^__mul" > "$(SYSROOT_SHARE)/undefined-symbols.txt" |
2b7e73ae | 492 | grep '^_*imported_wasi_' "$(SYSROOT_SHARE)/undefined-symbols.txt" \ |
320054e8 DG |
493 | > "$(SYSROOT_LIB)/libc.imports" |
494 | ||
41af0db3 | 495 | # |
320054e8 | 496 | # Generate a test file that includes all public header files. |
41af0db3 | 497 | # |
320054e8 | 498 | cd "$(SYSROOT)" && \ |
b9b64a69 | 499 | for header in $$(find include -type f -not -name mman.h -not -name signal.h -not -name times.h -not -name resource.h |grep -v /bits/); do \ |
41af0db3 | 500 | echo '#include <'$$header'>' | sed 's/include\///' ; \ |
fad009dc | 501 | done |LC_ALL=C sort >share/$(MULTIARCH_TRIPLE)/include-all.c ; \ |
320054e8 DG |
502 | cd - >/dev/null |
503 | ||
41af0db3 | 504 | # |
320054e8 | 505 | # Test that it compiles. |
41af0db3 | 506 | # |
90a62361 | 507 | $(WASM_CC) $(CFLAGS) -fsyntax-only "$(SYSROOT_SHARE)/include-all.c" -Wno-\#warnings |
320054e8 | 508 | |
8df0d4cd | 509 | # |
41af0db3 DG |
510 | # Collect all the predefined macros, except for compiler version macros |
511 | # which we don't need to track here. | |
8df0d4cd | 512 | # |
41af0db3 DG |
513 | @# |
514 | @# For the __*_ATOMIC_*_LOCK_FREE macros, squash individual compiler names | |
515 | @# to attempt, toward keeping these files compiler-independent. | |
516 | @# | |
517 | @# We have to add `-isystem $(SYSROOT_INC)` because otherwise clang puts | |
518 | @# its builtin include path first, which produces compiler-specific | |
519 | @# output. | |
520 | @# | |
521 | @# TODO: Undefine __FLOAT128__ for now since it's not in clang 8.0. | |
522 | @# TODO: Filter out __FLT16_* for now, as not all versions of clang have these. | |
90a62361 | 523 | $(WASM_CC) $(CFLAGS) "$(SYSROOT_SHARE)/include-all.c" \ |
8df0d4cd | 524 | -isystem $(SYSROOT_INC) \ |
38b930a2 | 525 | -std=gnu17 \ |
320054e8 | 526 | -E -dM -Wno-\#warnings \ |
9f0d8e85 | 527 | -D_ALL_SOURCE \ |
320054e8 DG |
528 | -U__llvm__ \ |
529 | -U__clang__ \ | |
530 | -U__clang_major__ \ | |
531 | -U__clang_minor__ \ | |
532 | -U__clang_patchlevel__ \ | |
533 | -U__clang_version__ \ | |
534 | -U__GNUC__ \ | |
535 | -U__GNUC_MINOR__ \ | |
536 | -U__GNUC_PATCHLEVEL__ \ | |
537 | -U__VERSION__ \ | |
538 | -U__FLOAT128__ \ | |
539 | | sed -e 's/__[[:upper:][:digit:]]*_ATOMIC_\([[:upper:][:digit:]_]*\)_LOCK_FREE/__compiler_ATOMIC_\1_LOCK_FREE/' \ | |
f74124a6 | 540 | | grep -v '^#define __FLT16_' \ |
320054e8 DG |
541 | > "$(SYSROOT_SHARE)/predefined-macros.txt" |
542 | ||
320054e8 | 543 | # Check that the computed metadata matches the expected metadata. |
255e6f7c TS |
544 | # This ignores whitespace because on Windows the output has CRLF line endings. |
545 | diff -wur "$(CURDIR)/expected/$(MULTIARCH_TRIPLE)" "$(SYSROOT_SHARE)" | |
320054e8 | 546 | |
8e8cc34a | 547 | install: finish |
320054e8 DG |
548 | mkdir -p "$(INSTALL_DIR)" |
549 | cp -r "$(SYSROOT)/lib" "$(SYSROOT)/share" "$(SYSROOT)/include" "$(INSTALL_DIR)" | |
550 | ||
41af0db3 | 551 | .PHONY: default startup_files libc finish install include_dirs |