forked from ngolovchenko/codegen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.rules
101 lines (74 loc) · 2.38 KB
/
Makefile.rules
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
#
# This file is included in a Makefile after definition of
#
# 1) SOURCES: list of source files
# 2a) to build a library:
# LIBRARY: name of the library
# 2b) to build a cgi-bin application
# CGI_BIN: name of application
# LIBS: list of standard libraries (such as -lstdc++)
# MYLIBS: list of local libraries (such as ../cgihtml/cgihtml.a)
# 3) to build a static HTML with embedded WebAssembly application
# WASM_HTML: name of the html output
ifeq ("$(findstring wasm,$(MAKECMDGOALS))","")
PLATF ?=native
else
PLAT ?=wasm
endif
ifeq ($(PLATF),native)
CC = gcc
CXX = g++
AR = ar
CFLAGS = -fexpensive-optimizations -O3 -Wno-write-strings -Wno-parenteses -fPIE
else
# WebAssembly compiler: https://emscripten.org/docs/getting_started/downloads.html
CC = emcc
CXX = emcc
AR = emar
CFLAGS = -Os -Wno-write-strings -Wno-parentheses -ffast-math
endif
CXXFLAGS = $(CFLAGS)
ARFLAGS = crs
INCS =
CLEAN_FILES = *.o $(LIBRARY) $(CGI_BIN) Makefile.depends \
$(WASM_HTML) $(WASM_HTML:.html=.wasm.txt) $(WASM_HTML:.html=.wasm)
OBJS = $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCES)))
##################################################
#
# targets
#
# all -- compile library
# clean -- remove object files
# depend -- build dependency file
#
##################################################
all: $(LIBRARY) $(CGI_BIN)
wasm: $(WASM_HTML)
clean:
-rm -f $(CLEAN_FILES)
depend:
$(CC) -MM $(INCS) $(CFLAGS) $(SOURCES) > Makefile.depends
.PHONY: all clean depend test install
##################################################
%.o: %.c
$(CC) $(INCS) $(CFLAGS) -c $<
%.o: %.cpp
$(CXX) $(INCS) $(CXXFLAGS) -c $<
%.a:
make -C $(dir $@) PLATF=$(PLATF)
$(LIBRARY): $(OBJS)
$(AR) $(ARFLAGS) $(LIBRARY) $(OBJS)
$(CGI_BIN): $(OBJS) $(MYLIBS)
$(CC) $(OBJS) $(MYLIBS) $(LIBS) -o $(CGI_BIN)
$(WASM_HTML): $(WASM_HTML:.html=.wasm.txt) template.html
sed '/const wasm=/ r $<' template.html > $@
.SECONDARY: $(WASM_HTML:.html=.wasm)
%.wasm.txt: %.wasm
# convert binary to base64-encoded JS text string
openssl base64 -in $(WASM_HTML:.html=.wasm) | sed 's/.*/"\0"+/' > $@
$(WASM_HTML:.html=.wasm): $(LIBRARY) $(CGI_BIN)
Makefile.depends: depend
ifneq ($(MAKECMDGOALS),clean)
include Makefile.depends
endif
.PHONY: all wasm clean depend