-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMakefile
128 lines (93 loc) · 3.73 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
CC = clang
CFLAGS = -fsanitize=address -g -Werror -Wall -Wextra -pedantic-errors -Wno-gnu-designator -std=gnu11
CPPFLAGS = -MMD -I$(SOURCE_DIR) -I$(DEP)/linenoise -I$(DEP)/hashmap.c
LDFLAGS = -ldwarf -lchicken -lzstd -lz
BUILD_DIR = build
SOURCE_DIR = src
DEP = dependencies
SOURCES = $(wildcard $(SOURCE_DIR)/*.c)
OBJECTS = $(patsubst $(SOURCE_DIR)/%.c, $(BUILD_DIR)/%.o, $(SOURCES))
OBJECTS += $(BUILD_DIR)/hashmap.o $(BUILD_DIR)/linenoise.o $(BUILD_DIR)/print-source.o $(BUILD_DIR)/tokenize.o $(BUILD_DIR)/c-syntax.o
BINARY = $(BUILD_DIR)/spray
DEPS = $(OBJECTS:%.o=%.d)
.PHONY = all bin clean run test unit integration assets install docker
# === SPRAY ===
all: $(BINARY) assets
@echo Build successful 👍️
run: all
./$(BINARY) $(args)
install: $(BINARY)
cp $(BINARY) $$HOME/.local/bin/
docker: $(BINARY)
docker create -i ubuntu
docker cp $(BINARY) `docker ps -q -l`:/opt/spray
docker start `docker ps -q -l`
docker exec -i `docker ps -q -l` bash
$(BINARY): $(OBJECTS)
$(CC) $(CFLAGS) $(OBJECTS) -o $(BINARY) $(LDFLAGS)
-include $(DEPS)
# Wow, seems like CHICKEN is quite strict ...
$(BUILD_DIR)/print_source.o: CFLAGS += -Wno-unused-parameter -Wno-strict-prototypes -Wno-pedantic -Wno-unused-but-set-variable -Wno-unused-variable
$(BUILD_DIR)/print_source.o: CPPFLAGS += -I/usr/include/chicken
$(BUILD_DIR)/print_source.o: $(SOURCE_DIR)/print_source.c | $(BUILD_DIR)
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
$(BUILD_DIR)/print-source.o: $(SOURCE_DIR)/print-source.scm $(BUILD_DIR)/tokenize.o | $(BUILD_DIR)
csc -uses tokenizer -c -embedded $(SOURCE_DIR)/print-source.scm -o $@
$(BUILD_DIR)/tokenize.o: $(SOURCE_DIR)/tokenize.scm $(BUILD_DIR)/c-syntax.o | $(BUILD_DIR)
csc -uses c-syntax -unit tokenizer -c -J $(SOURCE_DIR)/tokenize.scm -o $@
$(BUILD_DIR)/c-syntax.o: $(SOURCE_DIR)/c-syntax.scm | $(BUILD_DIR)
csc -unit c-syntax -c -J $(SOURCE_DIR)/c-syntax.scm -o $@
$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.c | $(BUILD_DIR)
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
$(BUILD_DIR)/hashmap.o: $(DEP)/hashmap.c/hashmap.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
$(BUILD_DIR)/linenoise.o: CFLAGS += -Wno-gnu-zero-variadic-macro-arguments
$(BUILD_DIR)/linenoise.o: $(DEP)/linenoise/linenoise.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
$(BUILD_DIR):
mkdir $(BUILD_DIR)
# Clang's JSON compilation database.
compile_commands.json:
ifeq (, $(shell which bear))
$(error "Bear is required to generate `compile_commands.json`. You can get it here: https://github.com/rizsotto/Bear.git.")
else
make clean
bear -- make all
endif
# === TESTS ===
TEST_SOURCE_DIR = tests
TEST_BUILD_DIR = tests/build
TEST_SOURCES = $(wildcard $(TEST_SOURCE_DIR)/*.c)
TEST_OBJECTS = $(filter-out $(BUILD_DIR)/spray.o, $(OBJECTS))
TEST_OBJECTS += $(patsubst $(TEST_SOURCE_DIR)/%.c, $(TEST_BUILD_DIR)/%.o, $(TEST_SOURCES))
TEST_OBJECTS += $(TEST_BUILD_DIR)/munit.o
TEST_DEPS = $(TEST_OBJECTS:%.o=%.d)
TEST_BINARY = $(TEST_BUILD_DIR)/test
# Run all tests.
test: unit integration
# Run C and Scheme unit tests.
unit: cunit schemeunit
cunit: CPPFLAGS += -I$(TEST_SOURCE_DIR) -I$(DEP)/munit
cunit: $(TEST_BINARY) assets
./$(TEST_BINARY) $(args)
schemeunit: assets
csi -s tests/tokenize.scm
csi -s tests/c-types.scm
# Run integration tests.
integration: $(BINARY) assets
python -m pytest
$(TEST_BINARY): $(TEST_OBJECTS)
$(CC) $(CFLAGS) $(LDFLAGS) $(TEST_OBJECTS) -o $(TEST_BINARY)
-include $(TEST_DEPS)
$(TEST_BUILD_DIR)/%.o: $(TEST_SOURCE_DIR)/%.c | $(TEST_BUILD_DIR)
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
$(TEST_BUILD_DIR)/munit.o: $(DEP)/munit/munit.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
$(TEST_BUILD_DIR):
mkdir $(TEST_BUILD_DIR)
assets:
$(MAKE) -C tests/assets all
clean:
$(RM) *.import.scm
$(RM) -r $(BUILD_DIR) $(TEST_BUILD_DIR) compile_commands.json
$(MAKE) -C tests/assets clean