-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMakefile
More file actions
180 lines (117 loc) · 5.26 KB
/
Copy pathMakefile
File metadata and controls
180 lines (117 loc) · 5.26 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# Compiler configuration
.DEFAULT_GOAL := main
CC = g++
# CC = g++-15
WEBCC = emcc
VER = -std=c++23
OPT = -O2
ARGS = -Wall -Wextra -Wpedantic -Wno-missing-braces #-Wnrvo
# -sENVIRONMENT=node -sNODERAWFS=1
WEB_ARGS = -sWASM=1 -sFORCE_FILESYSTEM -sEXPORTED_RUNTIME_METHODS='["callMain", "ccall"]' \
-sASSERTIONS -sENVIRONMENT=web -sSTACK_SIZE=8388608 -INVOKE_RUN_AT_START=0 -sEXIT_RUNTIME=0 -sNO_DISABLE_EXCEPTION_CATCHING
SRC_DIRS = src/Lex src/Parser src/Analysis src/Interp src/Utils src/CLI src/Preprocessor src/Type src/Value
SRC = $(wildcard $(SRC_DIRS:=/*.cxx))
SAN = -fsanitize=undefined -fsanitize=address # -g3
OUTPUT_NAME = Pie
DEBUG_OUTPUT_NAME = Pie_debug
WEB_OUTPUT_NAME = Pie.js
## Library directories
# Pulled from GitHub
REMOTE_INCLUDE_DIR = remote_includes
MP11_DIR = $(REMOTE_INCLUDE_DIR)/mp11
CPP_STD_EXT_DIR = $(REMOTE_INCLUDE_DIR)/cpp-std-extensions
# LIB_FFI_DIR = $(REMOTE_INCLUDE_DIR)/libffi
# Saved locally
LOCAL_INCLUDE_DIR = includes
# Include paths (compile-time only)
INCLUDE = \
-Isrc \
-I$(MP11_DIR)/include/ \
-I$(CPP_STD_EXT_DIR)/include/ \
-I$(LIB_FFI_DIR)/include/ \
# Link-time only
LIBS = -lffi
# ============================================================
define BUILD_CONFIG
$(1)_OBJ_DIR := build/$(1)
$(1)_OBJS := $$(SRC:src/%.cxx=$$($(1)_OBJ_DIR)/%.o)
$$($(1)_OBJ_DIR)/%.o: src/%.cxx
@mkdir -p $$(dir $$@)
$$(CC) $$(ARGS) $$(VER) $$(INCLUDE) $(2) -MMD -MP -c $$< -o $$@
-include $$($(1)_OBJS:.o=.d)
endef
$(eval $(call BUILD_CONFIG,release,$(OPT) -DNO_ERR_LOC))
$(eval $(call BUILD_CONFIG,debug,-O0 $(SAN)))
$(eval $(call BUILD_CONFIG,test,-O0 $(SAN)))
$(eval $(call BUILD_CONFIG,gh-actions,-O0))
$(eval $(call BUILD_CONFIG,web,$(OPT) -DWEB_PIE))
# ============================== Main target ==============================
$(release_OBJ_DIR)/main.o: src/main.cc
@mkdir -p $(dir $@)
$(CC) $(ARGS) $(VER) $(INCLUDE) $(OPT) -DNO_ERR_LOC -MMD -MP -c $< -o $@
-include $(release_OBJ_DIR)/main.d
$(OUTPUT_NAME): $(release_OBJS) $(release_OBJ_DIR)/main.o
$(CC) $(VER) $(release_OBJS) $(release_OBJ_DIR)/main.o $(INCLUDE) $(LIBS) $(OPT) -o $(OUTPUT_NAME)
main: checklibs $(OUTPUT_NAME)
# ============================== Debug target ==============================
$(debug_OBJ_DIR)/main.o: src/main.cc
@mkdir -p $(dir $@)
$(CC) $(ARGS) $(VER) $(INCLUDE) -O0 -MMD -MP -c $< -o $@
-include $(debug_OBJ_DIR)/main.d
$(DEBUG_OUTPUT_NAME): $(debug_OBJS) $(debug_OBJ_DIR)/main.o
$(CC) $(VER) $(debug_OBJS) $(debug_OBJ_DIR)/main.o $(INCLUDE) $(LIBS) -O0 -o $(DEBUG_OUTPUT_NAME) $(SAN)
debug: checklibs $(DEBUG_OUTPUT_NAME)
# ============================== Test target ==============================
$(test_OBJ_DIR)/Test.o: Tests/Test.cc
@mkdir -p $(dir $@)
$(CC) $(ARGS) $(VER) $(INCLUDE) -O0 -MMD -MP -c $< -o $@
$(test_OBJ_DIR)/catch.o: Tests/catch.cpp
@mkdir -p $(dir $@)
$(CC) $(ARGS) $(VER) $(INCLUDE) -O0 -MMD -MP -c $< -o $@
-include $(test_OBJ_DIR)/Test.d $(test_OBJ_DIR)/catch.d
run_tests: $(test_OBJS) $(test_OBJ_DIR)/Test.o $(test_OBJ_DIR)/catch.o
$(CC) $(VER) $(test_OBJS) $(test_OBJ_DIR)/Test.o $(test_OBJ_DIR)/catch.o $(INCLUDE) $(LIBS) -O0 -o run_tests $(SAN)
test: checklibs run_tests
./run_tests && rm run_tests
# ============================== Web target ==============================
web: checklibs
$(WEBCC) $(WEB_ARGS) $(VER) $(INCLUDE) $(OPT) src/main.cc $(SRC) -o $(WEB_OUTPUT_NAME) -DWEB_PIE
# $(web_OBJ_DIR)/main.o: src/main.cc
# @mkdir -p $(dir $@)
# $(WEBCC) $(ARGS) $(VER) $(INCLUDE) $(OPT) -DWEB_PIE -MMD -MP -c $< -o $@
# -include $(web_OBJ_DIR)/main.d
# $(WEB_OUTPUT_NAME): $(web_OBJS) $(web_OBJ_DIR)/main.o
# $(WEBCC) $(VER) $(web_OBJS) $(web_OBJ_DIR)/main.o $(WEB_ARGS) $(INCLUDE) $(LIBS) $(OPT) -o $(WEB_OUTPUT_NAME)
# web: checklibs $(WEB_OUTPUT_NAME)
# ============================== GH Actions ==============================
test_dylib_mac:
$(CC) $(VER) -dynamiclib -arch arm64 -arch x86_64 Tests/ffi_test.cpp -o Tests/dylib
test_dylib_lnx:
$(CC) $(VER) -fPIC -shared Tests/ffi_test.cpp -o Tests/dylib
gh-actions: checklibs test_dylib_lnx run_tests_gh
$(gh-actions_OBJ_DIR)/Test.o: Tests/Test.cc
@mkdir -p $(dir $@)
$(CC) $(ARGS) $(VER) $(INCLUDE) -O0 -MMD -MP -c $< -o $@
$(gh-actions_OBJ_DIR)/catch.o: Tests/catch.cpp
@mkdir -p $(dir $@)
$(CC) $(ARGS) $(VER) $(INCLUDE) -O0 -MMD -MP -c $< -o $@
-include $(gh-actions_OBJ_DIR)/Test.d $(gh-actions_OBJ_DIR)/catch.d
run_tests_gh: $(gh-actions_OBJS) $(gh-actions_OBJ_DIR)/Test.o $(gh-actions_OBJ_DIR)/catch.o
$(CC) $(VER) $(gh-actions_OBJS) $(gh-actions_OBJ_DIR)/Test.o $(gh-actions_OBJ_DIR)/catch.o $(INCLUDE) $(LIBS) -O0 -o run_tests_gh
./run_tests_gh
# ============================== Misc ==============================
checklibs:
@mkdir -p $(REMOTE_INCLUDE_DIR)
@if [ ! -d "$(MP11_DIR)" ]; then \
echo "Cloning Boost.MP11..."; \
git clone https://github.com/boostorg/mp11 $(MP11_DIR); \
fi
@if [ ! -d "$(CPP_STD_EXT_DIR)" ]; then \
echo "Cloning cpp-std-extensions...";\
git clone https://github.com/intel/cpp-std-extensions $(CPP_STD_EXT_DIR); \
fi
clean:
rm -f $(OUTPUT_NAME) $(DEBUG_OUTPUT_NAME) run_tests run_tests_gh $(WEB_OUTPUT_NAME) Pie.wasm
rm -rf build
rm -rf remote_includes/*
.PHONY: checklibs clean main debug test web gh-actions test_dylib_lnx