]> git.proxmox.com Git - wasi-libc.git/blob - Makefile
Merge pull request #9 from WebAssembly/dlmalloc
[wasi-libc.git] / Makefile
1 # These variables are specifically meant to be overridable via
2 # the make command-line.
3 WASM_CC = clang
4 WASM_CFLAGS = -O2
5 WASM_TARGET_FLAGS = --target=wasm32
6 SYSROOT = sysroot
7 # single or posix
8 THREAD_MODEL = single
9
10 # These variables describe the locations of various files and
11 # directories in the source tree.
12 BASICS_DIR = basics
13 BASICS_INC = $(BASICS_DIR)/include
14 BASICS_LIBC_DIR = $(BASICS_DIR)/libc
15 BASICS_LIBC_SOURCES = $(BASICS_LIBC_DIR)/string.c
16 DLMALLOC_DIR = dlmalloc
17 DLMALLOC_SRC_DIR = $(DLMALLOC_DIR)/src
18 DLMALLOC_SOURCES = $(DLMALLOC_SRC_DIR)/wrapper.c
19 DLMALLOC_INC = $(DLMALLOC_DIR)/include
20
21 # Configure support for threads.
22 ifeq ($(THREADS), single)
23 WASM_CFLAGS += -mthread-model single -DWASM_THREAD_MODEL_SINGLE
24 endif
25 ifeq ($(THREADS), posix)
26 WASM_CFLAGS += -mthread-model posix -DWASM_THREAD_MODEL_POSIX
27 endif
28
29 .PHONY: $(SYSROOT)
30 $(SYSROOT):
31 $(RM) -r "$(SYSROOT)"
32 mkdir -p "$(SYSROOT)/usr"
33
34 #
35 # Install the include files.
36 #
37 cp -r "$(BASICS_INC)" "$(SYSROOT)/usr"
38
39 #
40 # Build the C startup files.
41 #
42 $(RM) *.o
43 "$(WASM_CC)" $(WASM_CFLAGS) $(WASM_TARGET_FLAGS) --sysroot="$(SYSROOT)" -c $(BASICS_LIBC_DIR)/crt*.s
44 mkdir -p "$(SYSROOT)/lib"
45 mv *.o "$(SYSROOT)/lib"
46
47 #
48 # Compile and install the libc-subset source files.
49 #
50 $(RM) *.o
51 "$(WASM_CC)" $(WASM_CFLAGS) $(WASM_TARGET_FLAGS) --sysroot="$(SYSROOT)" -c $(BASICS_LIBC_SOURCES)
52 mkdir -p "$(SYSROOT)/lib"
53 $(AR) crs "$(SYSROOT)/lib/libc-basics.a" *.o
54 $(RM) *.o
55
56 #
57 # Compile and install the dlmalloc source files.
58 #
59 $(RM) *.o
60 "$(WASM_CC)" $(WASM_CFLAGS) $(WASM_TARGET_FLAGS) --sysroot="$(SYSROOT)" -c $(DLMALLOC_SOURCES) -I $(DLMALLOC_INC)
61 mkdir -p "$(SYSROOT)/lib"
62 $(AR) crs "$(SYSROOT)/lib/libc-dlmalloc.a" *.o
63 $(RM) *.o