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