This repository has been archived by the owner on Aug 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMakefile
63 lines (56 loc) · 1.67 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# These variables are specifically meant to be overridable via
# the make command-line.
WASM_CC = clang
WASM_CFLAGS = -O2
WASM_TARGET_FLAGS = --target=wasm32
SYSROOT = sysroot
# single or posix
THREAD_MODEL = single
# These variables describe the locations of various files and
# directories in the source tree.
BASICS_DIR = basics
BASICS_INC = $(BASICS_DIR)/include
BASICS_LIBC_DIR = $(BASICS_DIR)/libc
BASICS_LIBC_SOURCES = $(BASICS_LIBC_DIR)/string.c
DLMALLOC_DIR = dlmalloc
DLMALLOC_SRC_DIR = $(DLMALLOC_DIR)/src
DLMALLOC_SOURCES = $(DLMALLOC_SRC_DIR)/wrapper.c
DLMALLOC_INC = $(DLMALLOC_DIR)/include
# Configure support for threads.
ifeq ($(THREADS), single)
WASM_CFLAGS += -mthread-model single -DWASM_THREAD_MODEL_SINGLE
endif
ifeq ($(THREADS), posix)
WASM_CFLAGS += -mthread-model posix -DWASM_THREAD_MODEL_POSIX
endif
.PHONY: $(SYSROOT)
$(SYSROOT):
$(RM) -r "$(SYSROOT)"
mkdir -p "$(SYSROOT)/usr"
#
# Install the include files.
#
cp -r "$(BASICS_INC)" "$(SYSROOT)/usr"
#
# Build the C startup files.
#
$(RM) *.o
"$(WASM_CC)" $(WASM_CFLAGS) $(WASM_TARGET_FLAGS) --sysroot="$(SYSROOT)" -c $(BASICS_LIBC_DIR)/crt*.s
mkdir -p "$(SYSROOT)/lib"
mv *.o "$(SYSROOT)/lib"
#
# Compile and install the libc-subset source files.
#
$(RM) *.o
"$(WASM_CC)" $(WASM_CFLAGS) $(WASM_TARGET_FLAGS) --sysroot="$(SYSROOT)" -c $(BASICS_LIBC_SOURCES)
mkdir -p "$(SYSROOT)/lib"
$(AR) crs "$(SYSROOT)/lib/libc-basics.a" *.o
$(RM) *.o
#
# Compile and install the dlmalloc source files.
#
$(RM) *.o
"$(WASM_CC)" $(WASM_CFLAGS) $(WASM_TARGET_FLAGS) --sysroot="$(SYSROOT)" -c $(DLMALLOC_SOURCES) -I $(DLMALLOC_INC)
mkdir -p "$(SYSROOT)/lib"
$(AR) crs "$(SYSROOT)/lib/libc-dlmalloc.a" *.o
$(RM) *.o