-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathMakefile
128 lines (99 loc) · 2.92 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
##########################################################
# User configurable build options
# libc or fooboot
PLATFORM = libc
# WARNING: GPL license implications from using READLINE
USE_READLINE ?=
USE_SDL ?= 1
#CFLAGS ?= -O2 -Wall -Werror -Wextra -MMD -MP
CFLAGS ?= -O2 -Wall -Werror -MMD -MP
EXTRA_WAC_LIBS ?=
EXTRA_WACE_LIBS ?=
##########################################################
CC = gcc $(CFLAGS) -std=gnu99 -m32 -g
EMCC = emcc $(CFLAGS) -s WASM=1 -s SIDE_MODULE=1 -s LEGALIZE_JS_FFI=0
WA_DEPS = util.o thunk.o
ifeq (libc,$(PLATFORM))
CFLAGS += -DPLATFORM=1
ifeq (,$(strip $(USE_READLINE)))
RL_LIBRARY ?= edit
else
RL_LIBRARY ?= readline
CFLAGS += -DUSE_READLINE=1
endif
WAC_LIBS = m dl $(RL_LIBRARY)
WAX_LIBS = m dl
WACE_LIBS = m dl $(RL_LIBRARY)
ifneq (,$(strip $(USE_SDL)))
WACE_LIBS += SDL2 SDL2_image GL glut
endif
else
ifeq (fooboot,$(PLATFORM))
CFLAGS += -DPLATFORM=2
else
$(error unknown PLATFORM: $(PLATFORM))
endif
endif
WAC_LIBS += $(EXTRA_WAC_LIBS)
WAX_LIBS += $(EXTRA_WAX_LIBS)
WACE_LIBS += $(EXTRA_WACE_LIBS)
# Basic build rules
.PHONY:
all: wac wax wace
%.a: %.o
ar rcs $@ $^
%.o: %.c
$(CC) -c $(filter %.c,$^) -o $@
# Additional dependencies
util.o: util.h
wa.o: wa.h util.h platform.h
thunk.o: wa.h thunk.h
wa.a: util.o thunk.o platform_$(PLATFORM).o
wac: wa.a wac.o
wax: wa.a wasi.o wax.o
wace: wa.a wace.o
#
# Platform
#
ifeq (libc,$(PLATFORM)) # libc Platform
wac: platform_readline.o
$(CC) -rdynamic -Wl,--no-as-needed -o $@ \
-Wl,--start-group $^ -Wl,--end-group $(foreach l,$(WAC_LIBS),-l$(l)) \
-Wl,--wrap=readline
wax:
$(CC) -rdynamic -Wl,--no-as-needed -o $@ \
-Wl,--start-group $^ -Wl,--end-group $(foreach l,$(WAX_LIBS),-l$(l))
wace: wace_emscripten.o platform_readline.o
$(CC) -rdynamic -Wl,--no-as-needed -o $@ \
-Wl,--start-group $^ -Wl,--end-group $(foreach l,$(WACE_LIBS),-l$(l)) \
-Wl,--wrap=readline
else # fooboot OS platform
FOO_TARGETS = wac wax wace
include fooboot/Makefile
wace: wace_fooboot.o
endif
.PHONY:
clean::
rm -f *.o *.a *.d wac wax wace wace-sdl.c \
lib/*.o lib/*.d kernel/*.o kernel/*.d \
examples_c/*.js examples_c/*.html \
examples_c/*.wasm examples_c/*.wat \
examples_wat/*.wasm
##########################################################
# Wat example build rules
examples_wam/%.wasm: examples_wam/printnum.wam examples_wam/%.wam
wamp $^ > $(subst .wasm,.wat,$@)
wasm-as $(subst .wasm,.wat,$@) -o $@
examples_wam/hello.wasm: examples_wam/console_curses.wam
examples_wam/colors.wasm: examples_wam/console_curses.wam
examples_wam/snake.wasm: examples_wam/console_curses.wam
examples_wat/%.wasm: examples_wat/%.wat
wasm-as $< -o $@
# General C example build rules
examples_c/%.wasm: examples_c/%.c
$(EMCC) -I examples_c/include -s USE_SDL=2 $< -o $@
.SECONDARY:
examples_c/%.wat: examples_c/%.wasm
wasm-dis $< -o $@
examples_c/%: examples_c/%.c
$(CC) $< -o $@ -lSDL2 -lSDL2_image -lGL -lglut