]>
Commit | Line | Data |
---|---|---|
41af0db3 DG |
1 | # These variables are specifically meant to be overridable via the make |
2 | # command-line. | |
255e6f7c TS |
3 | WASM_CC ?= clang |
4 | WASM_NM ?= $(patsubst %clang,%llvm-nm,$(WASM_CC)) | |
5 | WASM_AR ?= $(patsubst %clang,%llvm-ar,$(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 |
320054e8 | 13 | # yes or no |
41af0db3 DG |
14 | BUILD_DLMALLOC ?= yes |
15 | BUILD_LIBC_BOTTOM_HALF ?= yes | |
16 | BUILD_LIBC_TOP_HALF ?= yes | |
320054e8 | 17 | # The directory where we're store intermediate artifacts. |
41af0db3 | 18 | OBJDIR ?= $(CURDIR)/build |
320054e8 DG |
19 | |
20 | # Check dependencies. | |
21 | ifeq ($(BUILD_LIBC_TOP_HALF),yes) | |
22 | ifneq ($(BUILD_LIBC_BOTTOM_HALF),yes) | |
23 | $(error BUILD_LIBC_TOP_HALF=yes depends on BUILD_LIBC_BOTTOM_HALF=yes) | |
24 | endif | |
25 | endif | |
26 | ifeq ($(BUILD_LIBC_BOTTOM_HALF),yes) | |
27 | ifneq ($(BUILD_DLMALLOC),yes) | |
28 | $(error BUILD_LIBC_BOTTOM_HALF=yes depends on BUILD_DLMALLOC=yes) | |
29 | endif | |
30 | endif | |
dcf13b6f | 31 | |
41af0db3 DG |
32 | # Variables from this point on are not meant to be overridable via the |
33 | # make command-line. | |
34 | ||
35 | # Set the target variables. Multiarch triples notably omit the vendor field, | |
36 | # which happens to be what we do for the main target triple too. | |
37 | TARGET_TRIPLE = wasm32-wasi | |
38 | MULTIARCH_TRIPLE = wasm32-wasi | |
39 | ||
40 | # These variables describe the locations of various files and directories in | |
41 | # the source tree. | |
320054e8 | 42 | BASICS_DIR = $(CURDIR)/basics |
dbfccac2 | 43 | BASICS_INC = $(BASICS_DIR)/include |
ad03c82d | 44 | BASICS_CRT_SOURCES = $(wildcard $(BASICS_DIR)/crt/*.c) |
a280fead DG |
45 | BASICS_SOURCES = \ |
46 | $(wildcard $(BASICS_DIR)/sources/*.c) \ | |
47 | $(wildcard $(BASICS_DIR)/sources/math/*.c) | |
320054e8 | 48 | DLMALLOC_DIR = $(CURDIR)/dlmalloc |
dbfccac2 | 49 | DLMALLOC_SRC_DIR = $(DLMALLOC_DIR)/src |
320054e8 | 50 | DLMALLOC_SOURCES = $(DLMALLOC_SRC_DIR)/dlmalloc.c |
dbfccac2 | 51 | DLMALLOC_INC = $(DLMALLOC_DIR)/include |
320054e8 DG |
52 | LIBC_BOTTOM_HALF_DIR = $(CURDIR)/libc-bottom-half |
53 | LIBC_BOTTOM_HALF_CLOUDLIBC_SRC = $(LIBC_BOTTOM_HALF_DIR)/cloudlibc/src | |
54 | LIBC_BOTTOM_HALF_CLOUDLIBC_SRC_INC = $(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC)/include | |
55 | LIBC_BOTTOM_HALF_HEADERS_PUBLIC = $(LIBC_BOTTOM_HALF_DIR)/headers/public | |
56 | LIBC_BOTTOM_HALF_HEADERS_PRIVATE = $(LIBC_BOTTOM_HALF_DIR)/headers/private | |
57 | LIBC_BOTTOM_HALF_LIBPREOPEN_DIR = $(LIBC_BOTTOM_HALF_DIR)/libpreopen | |
320054e8 DG |
58 | LIBC_BOTTOM_HALF_SOURCES = $(LIBC_BOTTOM_HALF_DIR)/sources |
59 | LIBC_BOTTOM_HALF_ALL_SOURCES = \ | |
60 | $(shell find $(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC) -name \*.c) \ | |
7fcc4f29 | 61 | $(LIBC_BOTTOM_HALF_LIBPREOPEN_DIR)/libpreopen.c \ |
320054e8 DG |
62 | $(shell find $(LIBC_BOTTOM_HALF_SOURCES) -name \*.c) |
63 | LIBWASI_EMULATED_MMAN_SOURCES = \ | |
64 | $(shell find $(LIBC_BOTTOM_HALF_DIR)/mman -name \*.c) | |
d1cd4f48 DG |
65 | LIBWASI_EMULATED_SIGNAL_SOURCES = \ |
66 | $(shell find $(LIBC_BOTTOM_HALF_DIR)/signal -name \*.c) | |
67 | LIBWASI_EMULATED_SIGNAL_MUSL_SOURCES = \ | |
68 | $(LIBC_TOP_HALF_MUSL_SRC_DIR)/signal/psignal.c \ | |
69 | $(LIBC_TOP_HALF_MUSL_SRC_DIR)/string/strsignal.c | |
320054e8 DG |
70 | LIBC_BOTTOM_HALF_CRT_SOURCES = $(wildcard $(LIBC_BOTTOM_HALF_DIR)/crt/*.c) |
71 | LIBC_TOP_HALF_DIR = $(CURDIR)/libc-top-half | |
72 | LIBC_TOP_HALF_MUSL_DIR = $(LIBC_TOP_HALF_DIR)/musl | |
73 | LIBC_TOP_HALF_MUSL_SRC_DIR = $(LIBC_TOP_HALF_MUSL_DIR)/src | |
74 | LIBC_TOP_HALF_MUSL_INC = $(LIBC_TOP_HALF_MUSL_DIR)/include | |
75 | LIBC_TOP_HALF_MUSL_SOURCES = \ | |
41af0db3 DG |
76 | $(addprefix $(LIBC_TOP_HALF_MUSL_SRC_DIR)/, \ |
77 | misc/a64l.c \ | |
78 | misc/basename.c \ | |
79 | misc/dirname.c \ | |
80 | misc/ffs.c \ | |
81 | misc/ffsl.c \ | |
82 | misc/ffsll.c \ | |
83 | misc/fmtmsg.c \ | |
84 | misc/getdomainname.c \ | |
85 | misc/gethostid.c \ | |
86 | misc/getopt.c \ | |
87 | misc/getopt_long.c \ | |
88 | misc/getsubopt.c \ | |
89 | misc/uname.c \ | |
90 | misc/nftw.c \ | |
91 | errno/strerror.c \ | |
92 | network/htonl.c \ | |
93 | network/htons.c \ | |
94 | network/ntohl.c \ | |
95 | network/ntohs.c \ | |
96 | network/inet_ntop.c \ | |
97 | network/inet_pton.c \ | |
98 | network/inet_aton.c \ | |
99 | network/in6addr_any.c \ | |
100 | network/in6addr_loopback.c \ | |
101 | fenv/fenv.c \ | |
102 | fenv/fesetround.c \ | |
103 | fenv/feupdateenv.c \ | |
104 | fenv/fesetexceptflag.c \ | |
105 | fenv/fegetexceptflag.c \ | |
106 | fenv/feholdexcept.c \ | |
107 | exit/exit.c \ | |
108 | exit/atexit.c \ | |
109 | exit/assert.c \ | |
110 | exit/quick_exit.c \ | |
111 | exit/at_quick_exit.c \ | |
112 | time/strftime.c \ | |
113 | time/asctime.c \ | |
114 | time/asctime_r.c \ | |
115 | time/ctime.c \ | |
116 | time/ctime_r.c \ | |
117 | time/wcsftime.c \ | |
118 | time/strptime.c \ | |
119 | time/difftime.c \ | |
120 | time/timegm.c \ | |
121 | time/ftime.c \ | |
122 | time/gmtime.c \ | |
123 | time/gmtime_r.c \ | |
124 | time/timespec_get.c \ | |
125 | time/getdate.c \ | |
126 | time/localtime.c \ | |
127 | time/localtime_r.c \ | |
128 | time/mktime.c \ | |
129 | time/__tm_to_secs.c \ | |
130 | time/__month_to_secs.c \ | |
131 | time/__secs_to_tm.c \ | |
132 | time/__year_to_secs.c \ | |
133 | time/__tz.c \ | |
134 | fcntl/creat.c \ | |
135 | dirent/alphasort.c \ | |
136 | dirent/versionsort.c \ | |
137 | env/clearenv.c \ | |
138 | env/getenv.c \ | |
139 | env/putenv.c \ | |
140 | env/setenv.c \ | |
141 | env/unsetenv.c \ | |
142 | unistd/posix_close.c \ | |
143 | ) \ | |
320054e8 DG |
144 | $(filter-out %/procfdname.c %/syscall.c %/syscall_ret.c %/vdso.c %/version.c, \ |
145 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/internal/*.c)) \ | |
146 | $(filter-out %/flockfile.c %/funlockfile.c %/__lockfile.c %/ftrylockfile.c \ | |
147 | %/rename.c \ | |
148 | %/tmpnam.c %/tmpfile.c %/tempnam.c \ | |
149 | %/popen.c %/pclose.c \ | |
150 | %/remove.c \ | |
151 | %/gets.c, \ | |
152 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdio/*.c)) \ | |
153 | $(filter-out %/strsignal.c, \ | |
154 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/string/*.c)) \ | |
8048aeb5 | 155 | $(filter-out %/dcngettext.c %/textdomain.c %/bind_textdomain_codeset.c, \ |
320054e8 DG |
156 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/locale/*.c)) \ |
157 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdlib/*.c) \ | |
158 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/search/*.c) \ | |
159 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/multibyte/*.c) \ | |
160 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/regex/*.c) \ | |
320054e8 DG |
161 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/prng/*.c) \ |
162 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/conf/*.c) \ | |
163 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/ctype/*.c) \ | |
900b8032 | 164 | $(filter-out %/__signbit.c %/__signbitf.c %/__signbitl.c \ |
16450763 DG |
165 | %/__fpclassify.c %/__fpclassifyf.c %/__fpclassifyl.c \ |
166 | %/ceilf.c %/ceil.c \ | |
167 | %/floorf.c %/floor.c \ | |
168 | %/truncf.c %/trunc.c \ | |
169 | %/rintf.c %/rint.c \ | |
170 | %/nearbyintf.c %/nearbyint.c \ | |
171 | %/sqrtf.c %/sqrt.c \ | |
172 | %/fabsf.c %/fabs.c \ | |
cf81683e DG |
173 | %/copysignf.c %/copysign.c \ |
174 | %/fminf.c %/fmaxf.c \ | |
175 | %/fmin.c %/fmax.c, \ | |
900b8032 | 176 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/math/*.c)) \ |
7d5074ff DG |
177 | $(filter-out %/crealf.c %/creal.c \ |
178 | %/cimagf.c %/cimag.c, \ | |
179 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/complex/*.c)) \ | |
320054e8 DG |
180 | $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/crypt/*.c) |
181 | MUSL_PRINTSCAN_SOURCES = \ | |
182 | $(LIBC_TOP_HALF_MUSL_SRC_DIR)/internal/floatscan.c \ | |
183 | $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdio/vfprintf.c \ | |
2201343c | 184 | $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdio/vfwprintf.c \ |
320054e8 DG |
185 | $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdio/vfscanf.c \ |
186 | $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdlib/strtod.c \ | |
187 | $(LIBC_TOP_HALF_MUSL_SRC_DIR)/stdlib/wcstod.c | |
188 | LIBC_TOP_HALF_HEADERS_PRIVATE = $(LIBC_TOP_HALF_DIR)/headers/private | |
189 | LIBC_TOP_HALF_SOURCES = $(LIBC_TOP_HALF_DIR)/sources | |
190 | LIBC_TOP_HALF_ALL_SOURCES = \ | |
191 | $(LIBC_TOP_HALF_MUSL_SOURCES) \ | |
192 | $(shell find $(LIBC_TOP_HALF_SOURCES) -name \*.c) | |
193 | ||
320054e8 | 194 | # Set the target. |
41af0db3 | 195 | WASM_CFLAGS += --target=$(TARGET_TRIPLE) |
320054e8 DG |
196 | # WebAssembly floating-point match doesn't trap. |
197 | # TODO: Add -fno-signaling-nans when the compiler supports it. | |
41af0db3 | 198 | WASM_CFLAGS += -fno-trapping-math |
dbfccac2 DG |
199 | |
200 | # Configure support for threads. | |
320054e8 | 201 | ifeq ($(THREAD_MODEL), single) |
41af0db3 | 202 | WASM_CFLAGS += -mthread-model single |
dbfccac2 | 203 | endif |
320054e8 | 204 | ifeq ($(THREAD_MODEL), posix) |
41af0db3 | 205 | WASM_CFLAGS += -mthread-model posix -pthread |
320054e8 DG |
206 | endif |
207 | ||
208 | # Set the sysroot. | |
41af0db3 | 209 | WASM_CFLAGS += --sysroot="$(SYSROOT)" |
320054e8 | 210 | |
41af0db3 DG |
211 | # These variables describe the locations of various files and directories in |
212 | # the build tree. | |
320054e8 | 213 | objs = $(patsubst $(CURDIR)/%.c,$(OBJDIR)/%.o,$(1)) |
41af0db3 DG |
214 | BASICS_OBJS = $(call objs,$(BASICS_SOURCES)) |
215 | DLMALLOC_OBJS = $(call objs,$(DLMALLOC_SOURCES)) | |
216 | LIBC_BOTTOM_HALF_ALL_OBJS = $(call objs,$(LIBC_BOTTOM_HALF_ALL_SOURCES)) | |
217 | LIBC_TOP_HALF_ALL_OBJS = $(call objs,$(LIBC_TOP_HALF_ALL_SOURCES)) | |
218 | LIBC_OBJS := $(BASICS_OBJS) | |
320054e8 | 219 | ifeq ($(BUILD_DLMALLOC),yes) |
41af0db3 | 220 | LIBC_OBJS += $(DLMALLOC_OBJS) |
dbfccac2 | 221 | endif |
320054e8 DG |
222 | ifeq ($(BUILD_LIBC_BOTTOM_HALF),yes) |
223 | # Override basics' string.o with libc-bottom-half's. | |
41af0db3 | 224 | LIBC_OBJS := $(filter-out %/string.o,$(LIBC_OBJS)) |
320054e8 | 225 | # Add libc-bottom-half's objects. |
41af0db3 | 226 | LIBC_OBJS += $(LIBC_BOTTOM_HALF_ALL_OBJS) |
320054e8 DG |
227 | endif |
228 | ifeq ($(BUILD_LIBC_TOP_HALF),yes) | |
229 | # Override libc-bottom-half's string.o with libc-top-half's. | |
41af0db3 | 230 | LIBC_OBJS := $(filter-out %/string.o,$(LIBC_OBJS)) |
320054e8 | 231 | # Override libc-bottom-half's qsort.o with libc-top-half's. |
41af0db3 | 232 | LIBC_OBJS := $(filter-out %/qsort.o,$(LIBC_OBJS)) |
320054e8 | 233 | # libc-top-half is musl. |
41af0db3 | 234 | LIBC_OBJS += $(LIBC_TOP_HALF_ALL_OBJS) |
320054e8 | 235 | endif |
41af0db3 DG |
236 | MUSL_PRINTSCAN_OBJS = $(call objs,$(MUSL_PRINTSCAN_SOURCES)) |
237 | MUSL_PRINTSCAN_LONG_DOUBLE_OBJS = $(patsubst %.o,%.long-double.o,$(MUSL_PRINTSCAN_OBJS)) | |
238 | MUSL_PRINTSCAN_NO_FLOATING_POINT_OBJS = $(patsubst %.o,%.no-floating-point.o,$(MUSL_PRINTSCAN_OBJS)) | |
239 | LIBWASI_EMULATED_MMAN_OBJS = $(call objs,$(LIBWASI_EMULATED_MMAN_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 | ||
d1cd4f48 DG |
343 | $(SYSROOT_LIB)/libwasi-emulated-signal.a: $(LIBWASI_EMULATED_SIGNAL_OBJS) $(LIBWASI_EMULATED_SIGNAL_MUSL_OBJS) |
344 | ||
320054e8 DG |
345 | %.a: |
346 | @mkdir -p "$(@D)" | |
255e6f7c TS |
347 | # On Windows, the commandline for the ar invocation got too long, so it needs to be split up. |
348 | $(WASM_AR) crs $@ $(wordlist 1, 199, $^) | |
349 | $(WASM_AR) crs $@ $(wordlist 200, 399, $^) | |
350 | $(WASM_AR) crs $@ $(wordlist 400, 599, $^) | |
351 | $(WASM_AR) crs $@ $(wordlist 600, 799, $^) | |
352 | # This might eventually overflow again, but at least it'll do so in a loud way instead of | |
353 | # silently dropping the tail. | |
354 | $(WASM_AR) crs $@ $(wordlist 800, 100000, $^) | |
320054e8 | 355 | |
41af0db3 | 356 | $(MUSL_PRINTSCAN_OBJS): WASM_CFLAGS += \ |
320054e8 DG |
357 | -D__wasilibc_printscan_no_long_double \ |
358 | -D__wasilibc_printscan_full_support_option="\"add -lc-printscan-long-double to the link command\"" | |
359 | ||
41af0db3 | 360 | $(MUSL_PRINTSCAN_NO_FLOATING_POINT_OBJS): WASM_CFLAGS += \ |
320054e8 DG |
361 | -D__wasilibc_printscan_no_floating_point \ |
362 | -D__wasilibc_printscan_floating_point_support_option="\"remove -lc-printscan-no-floating-point from the link command\"" | |
363 | ||
d1cd4f48 DG |
364 | $(LIBWASI_EMULATED_SIGNAL_MUSL_OBJS): WASM_CFLAGS += \ |
365 | -D_WASI_EMULATED_SIGNAL | |
366 | ||
8e8cc34a | 367 | $(OBJDIR)/%.long-double.o: $(CURDIR)/%.c include_dirs |
320054e8 DG |
368 | @mkdir -p "$(@D)" |
369 | "$(WASM_CC)" $(WASM_CFLAGS) -MD -MP -o $@ -c $< | |
dcf13b6f | 370 | |
8e8cc34a | 371 | $(OBJDIR)/%.no-floating-point.o: $(CURDIR)/%.c include_dirs |
320054e8 DG |
372 | @mkdir -p "$(@D)" |
373 | "$(WASM_CC)" $(WASM_CFLAGS) -MD -MP -o $@ -c $< | |
374 | ||
8e8cc34a | 375 | $(OBJDIR)/%.o: $(CURDIR)/%.c include_dirs |
320054e8 DG |
376 | @mkdir -p "$(@D)" |
377 | "$(WASM_CC)" $(WASM_CFLAGS) -MD -MP -o $@ -c $< | |
378 | ||
255e6f7c | 379 | -include $(shell find $(OBJDIR) -name \*.d) |
320054e8 | 380 | |
41af0db3 | 381 | $(DLMALLOC_OBJS): WASM_CFLAGS += \ |
320054e8 DG |
382 | -I$(DLMALLOC_INC) |
383 | ||
41af0db3 | 384 | startup_files $(LIBC_BOTTOM_HALF_ALL_OBJS): WASM_CFLAGS += \ |
320054e8 DG |
385 | -I$(LIBC_BOTTOM_HALF_HEADERS_PRIVATE) \ |
386 | -I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC_INC) \ | |
7fcc4f29 | 387 | -I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC) |
320054e8 | 388 | |
d1cd4f48 | 389 | $(LIBC_TOP_HALF_ALL_OBJS) $(MUSL_PRINTSCAN_LONG_DOUBLE_OBJS) $(MUSL_PRINTSCAN_NO_FLOATING_POINT_OBJS) $(LIBWASI_EMULATED_SIGNAL_MUSL_OBJS): WASM_CFLAGS += \ |
320054e8 DG |
390 | -I$(LIBC_TOP_HALF_MUSL_SRC_DIR)/include \ |
391 | -I$(LIBC_TOP_HALF_MUSL_SRC_DIR)/internal \ | |
392 | -I$(LIBC_TOP_HALF_MUSL_DIR)/arch/wasm32 \ | |
393 | -I$(LIBC_TOP_HALF_MUSL_DIR)/arch/generic \ | |
394 | -I$(LIBC_TOP_HALF_HEADERS_PRIVATE) \ | |
395 | -Wno-parentheses \ | |
396 | -Wno-shift-op-parentheses \ | |
397 | -Wno-bitwise-op-parentheses \ | |
398 | -Wno-logical-op-parentheses \ | |
399 | -Wno-string-plus-int \ | |
400 | -Wno-dangling-else \ | |
401 | -Wno-unknown-pragmas | |
402 | ||
8e8cc34a | 403 | include_dirs: |
dcf13b6f | 404 | $(RM) -r "$(SYSROOT)" |
dcf13b6f DG |
405 | |
406 | # | |
407 | # Install the include files. | |
408 | # | |
320054e8 DG |
409 | mkdir -p "$(SYSROOT_INC)" |
410 | cp -r "$(BASICS_INC)" "$(SYSROOT)" | |
411 | cp -r "$(LIBC_BOTTOM_HALF_HEADERS_PUBLIC)"/* "$(SYSROOT_INC)" | |
412 | ||
413 | # Generate musl's bits/alltypes.h header. | |
414 | mkdir -p "$(SYSROOT_INC)/bits" | |
415 | sed -f $(LIBC_TOP_HALF_MUSL_DIR)/tools/mkalltypes.sed \ | |
416 | $(LIBC_TOP_HALF_MUSL_DIR)/arch/wasm32/bits/alltypes.h.in \ | |
417 | $(LIBC_TOP_HALF_MUSL_DIR)/include/alltypes.h.in \ | |
418 | > "$(SYSROOT_INC)/bits/alltypes.h" | |
419 | ||
420 | # Copy in the bulk of musl's public header files. | |
421 | cp -r "$(LIBC_TOP_HALF_MUSL_INC)"/* "$(SYSROOT_INC)" | |
422 | # Copy in the musl's "bits" header files. | |
423 | cp -r "$(LIBC_TOP_HALF_MUSL_DIR)"/arch/generic/bits/* "$(SYSROOT_INC)/bits" | |
424 | cp -r "$(LIBC_TOP_HALF_MUSL_DIR)"/arch/wasm32/bits/* "$(SYSROOT_INC)/bits" | |
425 | ||
1f409842 DG |
426 | # Remove selected header files. |
427 | $(RM) $(patsubst %,$(SYSROOT_INC)/%,$(MUSL_OMIT_HEADERS)) | |
320054e8 DG |
428 | |
429 | ifeq ($(BUILD_LIBC_BOTTOM_HALF),no) | |
41af0db3 | 430 | CRT_SOURCES = $(BASICS_CRT_SOURCES) |
320054e8 | 431 | else |
41af0db3 | 432 | CRT_SOURCES = $(LIBC_BOTTOM_HALF_CRT_SOURCES) |
320054e8 | 433 | endif |
dcf13b6f | 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)" && \ | |
441 | "$(WASM_CC)" $(WASM_CFLAGS) -c $(CRT_SOURCES) -MD -MP && \ | |
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 DG |
449 | $(SYSROOT_LIB)/libwasi-emulated-mman.a \ |
450 | $(SYSROOT_LIB)/libwasi-emulated-signal.a | |
320054e8 | 451 | |
8e8cc34a | 452 | finish: startup_files libc |
dcf13b6f | 453 | # |
320054e8 | 454 | # Create empty placeholder libraries. |
dcf13b6f | 455 | # |
1f7d798a | 456 | for name in m rt pthread crypt util xnet resolv dl; do \ |
320054e8 DG |
457 | $(WASM_AR) crs "$(SYSROOT_LIB)/lib$${name}.a"; \ |
458 | done | |
dbfccac2 DG |
459 | |
460 | # | |
320054e8 | 461 | # Collect metadata on the sysroot and perform sanity checks. |
dbfccac2 | 462 | # |
320054e8 DG |
463 | mkdir -p "$(SYSROOT_SHARE)" |
464 | ||
41af0db3 | 465 | # |
320054e8 | 466 | # Collect symbol information. |
41af0db3 DG |
467 | # |
468 | @# TODO: Use llvm-nm --extern-only instead of grep. This is blocked on | |
469 | @# LLVM PR40497, which is fixed in 9.0, but not in 8.0. | |
470 | @# Ignore certain llvm builtin symbols such as those starting with __mul | |
471 | @# since these dependencies can vary between llvm versions. | |
255e6f7c | 472 | "$(WASM_NM)" --defined-only "$(SYSROOT_LIB)"/libc.a "$(SYSROOT_LIB)"/*.o \ |
fad009dc | 473 | |grep ' [[:upper:]] ' |sed 's/.* [[:upper:]] //' |LC_ALL=C sort > "$(SYSROOT_SHARE)/defined-symbols.txt" |
d1cd4f48 | 474 | for undef_sym in $$("$(WASM_NM)" --undefined-only "$(SYSROOT_LIB)"/libc.a "$(SYSROOT_LIB)"/libc-*.a "$(SYSROOT_LIB)"/*.o \ |
fad009dc | 475 | |grep ' U ' |sed 's/.* U //' |LC_ALL=C sort |uniq); do \ |
320054e8 | 476 | grep -q '\<'$$undef_sym'\>' "$(SYSROOT_SHARE)/defined-symbols.txt" || echo $$undef_sym; \ |
c35f0f5d | 477 | done | grep -v "^__mul" > "$(SYSROOT_SHARE)/undefined-symbols.txt" |
320054e8 DG |
478 | grep '^_*wasi_' "$(SYSROOT_SHARE)/undefined-symbols.txt" \ |
479 | > "$(SYSROOT_LIB)/libc.imports" | |
480 | ||
41af0db3 | 481 | # |
320054e8 | 482 | # Generate a test file that includes all public header files. |
41af0db3 | 483 | # |
320054e8 | 484 | cd "$(SYSROOT)" && \ |
d1cd4f48 | 485 | for header in $$(find include -type f -not -name mman.h -not -name signal.h |grep -v /bits/); do \ |
41af0db3 | 486 | echo '#include <'$$header'>' | sed 's/include\///' ; \ |
fad009dc | 487 | done |LC_ALL=C sort >share/$(MULTIARCH_TRIPLE)/include-all.c ; \ |
320054e8 DG |
488 | cd - >/dev/null |
489 | ||
41af0db3 | 490 | # |
320054e8 | 491 | # Test that it compiles. |
41af0db3 | 492 | # |
320054e8 DG |
493 | "$(WASM_CC)" $(WASM_CFLAGS) -fsyntax-only "$(SYSROOT_SHARE)/include-all.c" -Wno-\#warnings |
494 | ||
8df0d4cd | 495 | # |
41af0db3 DG |
496 | # Collect all the predefined macros, except for compiler version macros |
497 | # which we don't need to track here. | |
8df0d4cd | 498 | # |
41af0db3 DG |
499 | @# |
500 | @# For the __*_ATOMIC_*_LOCK_FREE macros, squash individual compiler names | |
501 | @# to attempt, toward keeping these files compiler-independent. | |
502 | @# | |
503 | @# We have to add `-isystem $(SYSROOT_INC)` because otherwise clang puts | |
504 | @# its builtin include path first, which produces compiler-specific | |
505 | @# output. | |
506 | @# | |
507 | @# TODO: Undefine __FLOAT128__ for now since it's not in clang 8.0. | |
508 | @# TODO: Filter out __FLT16_* for now, as not all versions of clang have these. | |
320054e8 | 509 | "$(WASM_CC)" $(WASM_CFLAGS) "$(SYSROOT_SHARE)/include-all.c" \ |
8df0d4cd | 510 | -isystem $(SYSROOT_INC) \ |
38b930a2 | 511 | -std=gnu17 \ |
320054e8 | 512 | -E -dM -Wno-\#warnings \ |
9f0d8e85 | 513 | -D_ALL_SOURCE \ |
320054e8 DG |
514 | -U__llvm__ \ |
515 | -U__clang__ \ | |
516 | -U__clang_major__ \ | |
517 | -U__clang_minor__ \ | |
518 | -U__clang_patchlevel__ \ | |
519 | -U__clang_version__ \ | |
520 | -U__GNUC__ \ | |
521 | -U__GNUC_MINOR__ \ | |
522 | -U__GNUC_PATCHLEVEL__ \ | |
523 | -U__VERSION__ \ | |
524 | -U__FLOAT128__ \ | |
525 | | sed -e 's/__[[:upper:][:digit:]]*_ATOMIC_\([[:upper:][:digit:]_]*\)_LOCK_FREE/__compiler_ATOMIC_\1_LOCK_FREE/' \ | |
f74124a6 | 526 | | grep -v '^#define __FLT16_' \ |
320054e8 DG |
527 | > "$(SYSROOT_SHARE)/predefined-macros.txt" |
528 | ||
320054e8 | 529 | # Check that the computed metadata matches the expected metadata. |
255e6f7c TS |
530 | # This ignores whitespace because on Windows the output has CRLF line endings. |
531 | diff -wur "$(CURDIR)/expected/$(MULTIARCH_TRIPLE)" "$(SYSROOT_SHARE)" | |
320054e8 | 532 | |
41af0db3 DG |
533 | # |
534 | # The build succeeded! The generated sysroot is in $(SYSROOT). | |
535 | # | |
536 | ||
8e8cc34a | 537 | install: finish |
320054e8 DG |
538 | mkdir -p "$(INSTALL_DIR)" |
539 | cp -r "$(SYSROOT)/lib" "$(SYSROOT)/share" "$(SYSROOT)/include" "$(INSTALL_DIR)" | |
540 | ||
41af0db3 | 541 | .PHONY: default startup_files libc finish install include_dirs |