-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
134 lines (98 loc) · 3.14 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
128
129
130
131
132
133
################################################################
#
# $Id:$
#
# $Log:$
#
ifeq ($(V),1)
VB=''
else
VB=@
endif
CC=clang
CFLAGS+=-O3 -nostdlib -target wasm32 -I./newlib-cygwin/newlib/libc/include -I./include -D__IEEE_LITTLE_ENDIAN -DMINECRAFT=1
CFLAGS+=-Dmalloc_getpagesize="(65536)" -D_GNU_SOURCE=1 -DNO_FLOATING_POINT=1
CFLAGS+=-ggdb3 -Wall # -DNORMALUNIX -DLINUX -DSNDSERV # -DUSEASM
# Normally, Wasmcraft programs that need external files will include the files in the binary in the form of a C array.
# This means that we can "mmap" it in as a no-op to be more efficient.
# However, we don't *really* have mmap, so we only define HAVE_MMAP when compiling user functions.
CFLAGS_N = $(CFLAGS) -DHAVE_MMAP=0
CFLAGS_M = $(CFLAGS) -DHAVE_MMAP=1
LDFLAGS+=-Wl,--lto-O3,--gc-sections,--import-undefined
LIBS+=
# subdirectory for objects
OBJDIR=build
OBJDIR2=build2
OUTPUT=build/newlib_example.wasm
OBJS_NEWLIB+=errno.o sysfstat.o
include Makefile.string.inc
include Makefile.stdlib.inc
include Makefile.stdio.inc
include Makefile.reent.inc
include Makefile.ctype.inc
include Makefile.posix.inc
include Makefile.locale.inc
include Makefile.libmcommon.inc
OBJS2 += $(addprefix $(OBJDIR2)/, $(OBJS_NEWLIB))
LIBC_DIR = ./newlib-cygwin/newlib/libc
LIBM_DIR = ./newlib-cygwin/newlib/libm
#SRC_NEWLIB_RAW = stdio/printf.c stdio/fprintf.c
#SRC_NEWLIB += $(addprefix ./newlib-cygwin/newlib/libc/, $(SRC_NEWLIB_RAW))
SRC_USER = main.o stubs.o
OBJS += $(addprefix $(OBJDIR)/, $(SRC_USER))
all: $(OUTPUT) build/newlib_example.wat
clean:
rm -rf $(OBJDIR)
rm -rf $(OBJDIR2)
rm -f $(OUTPUT)
rm -f $(OUTPUT).gdb
rm -f $(OUTPUT).map
build/newlib_example.wat: $(OUTPUT)
wasm2wat $(OUTPUT) -o build/newlib_example.wat
$(OUTPUT): $(OBJS) $(OBJS2)
@echo [Linking $@]
$(VB)$(CC) $(CFLAGS_M) $(LDFLAGS) $(OBJS) $(OBJS2) \
-o $(OUTPUT) $(LIBS) -Wl
# @echo [Size]
# -$(CROSS_COMPILE)size $(OUTPUT)
$(OBJS): | $(OBJDIR)
$(OBJS2): | $(OBJDIR2)
$(OBJDIR):
mkdir -p $(OBJDIR)
$(OBJDIR2):
mkdir -p $(OBJDIR2)
$(OBJDIR)/%.o: %.c
@echo [Compiling $<]
$(VB)$(CC) $(CFLAGS_M) -Werror-implicit-function-declaration -c $< -o $@
$(OBJDIR2)/%.o: $(LIBC_DIR)/stdio/%.c
@echo [Compiling newlib $<]
$(VB)$(CC) $(CFLAGS_N) -c $< -o $@
$(OBJDIR2)/%.o: $(LIBC_DIR)/string/%.c
@echo [Compiling newlib $<]
$(VB)$(CC) $(CFLAGS_N) -c $< -o $@
$(OBJDIR2)/%.o: $(LIBC_DIR)/stdlib/%.c
@echo [Compiling newlib $<]
$(VB)$(CC) $(CFLAGS_N) -c $< -o $@
$(OBJDIR2)/%.o: $(LIBC_DIR)/reent/%.c
@echo [Compiling newlib $<]
$(VB)$(CC) $(CFLAGS_N) -c $< -o $@
$(OBJDIR2)/%.o: $(LIBC_DIR)/ctype/%.c
@echo [Compiling newlib $<]
$(VB)$(CC) $(CFLAGS_N) -c $< -o $@
$(OBJDIR2)/%.o: $(LIBC_DIR)/posix/%.c
@echo [Compiling newlib $<]
$(VB)$(CC) $(CFLAGS_N) -c $< -o $@
$(OBJDIR2)/%.o: $(LIBC_DIR)/locale/%.c
@echo [Compiling newlib $<]
$(VB)$(CC) $(CFLAGS_N) -c $< -o $@
$(OBJDIR2)/%.o: $(LIBC_DIR)/errno/%.c
@echo [Compiling newlib $<]
$(VB)$(CC) $(CFLAGS_N) -c $< -o $@
$(OBJDIR2)/%.o: $(LIBC_DIR)/syscalls/%.c
@echo [Compiling newlib $<]
$(VB)$(CC) $(CFLAGS_N) -c $< -o $@
$(OBJDIR2)/%.o: $(LIBM_DIR)/common/%.c
@echo [Compiling newlib $<]
$(VB)$(CC) $(CFLAGS_N) -c $< -o $@
print:
@echo OBJS: $(OBJS)