forked from spevnev/uprintf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
96 lines (73 loc) · 2.85 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
CC := gcc
CFLAGS := -O2 -g2 -std=c99 -Wall -Wextra -pedantic -I . -fsanitize=undefined,address,leak -DUPRINTF_TEST
BUILD_DIR := build
LIB_DIR := libs
EXAMPLE_DIR := examples
TEST_DIR := tests
BASELINE_DIR := tests/baselines
COMPILERS := clang gcc
O_LEVELS := O0 O2 O3 Os
G_LEVELS := g2 g3
EXAMPLES := $(patsubst $(EXAMPLE_DIR)/%.c, %, $(shell find $(EXAMPLE_DIR) -type f -name '*.c'))
TESTS := $(patsubst $(TEST_DIR)/%.c, %, $(shell find $(TEST_DIR) -type f -name '*.c'))
.PHONY: all
all: examples
.PHONY: clean
clean:
rm -rf $(BUILD_DIR) $(LIB_DIR)
.PHONY: install
install:
cp uprintf.h /usr/local/include/uprintf.h
chmod 644 /usr/local/include/uprintf.h
.PHONY: uninstall
uninstall:
rm /usr/local/include/uprintf.h
.PHONY: examples
examples: $(patsubst %, $(BUILD_DIR)/$(EXAMPLE_DIR)/%, $(EXAMPLES))
$(BUILD_DIR)/$(EXAMPLE_DIR)/vorbis: $(EXAMPLE_DIR)/vorbis.c $(LIB_DIR)/stb_vorbis.c uprintf.h Makefile
@mkdir -p $(@D)
$(CC) $(CFLAGS) -I $(LIB_DIR) -o $@ $< -lm
$(LIB_DIR)/stb_vorbis.c:
@mkdir -p $(@D)
wget https://raw.githubusercontent.com/nothings/stb/master/stb_vorbis.c -O $@
$(BUILD_DIR)/$(EXAMPLE_DIR)/avl: $(EXAMPLE_DIR)/avl.c $(LIB_DIR)/avl uprintf.h Makefile
@mkdir -p $(@D)
$(CC) $(CFLAGS) -I $(LIB_DIR)/avl -o $@ $< $(LIB_DIR)/avl/avl.c
$(LIB_DIR)/avl:
@mkdir -p $(@D)
git clone --depth 1 https://github.com/etherealvisage/avl $(LIB_DIR)/avl_src
mv $(LIB_DIR)/avl_src/src $@
rm -rf $(LIB_DIR)/avl_src
$(BUILD_DIR)/$(EXAMPLE_DIR)/sqlite: $(EXAMPLE_DIR)/sqlite.c $(LIB_DIR)/sqlite/sqlite3.c uprintf.h Makefile
@mkdir -p $(@D)
$(CC) $(CFLAGS) -I $(LIB_DIR)/sqlite -o $@ $<
$(LIB_DIR)/sqlite/sqlite3.c:
mkdir -p $(LIB_DIR)
wget https://www.sqlite.org/2024/sqlite-amalgamation-3460100.zip -O $(LIB_DIR)/sqlite.zip
cd $(LIB_DIR) && unzip sqlite.zip && mv sqlite-amalgamation-3460100 sqlite
rm $(LIB_DIR)/sqlite.zip
.PHONY: test
test: tests
.PHONY: tests
tests: $(foreach C,$(COMPILERS),$(foreach O,$(O_LEVELS),$(foreach G,$(G_LEVELS),$(foreach T,$(TESTS),$(BUILD_DIR)/test/$T/$T-$C-$O-$G))))
# Export all variables to subprocesses, i.e. test.sh
export
define TEST_TEMPLATE
$(BUILD_DIR)/test/$1/$1-$2-$3-$4: $(BUILD_DIR)/impl/$2.o $(TEST_DIR)/$1.c uprintf.h Makefile test.sh
@./test.sh $1 $2 $3 $4
endef
$(foreach C,$(COMPILERS), \
$(foreach O,$(O_LEVELS), \
$(foreach G,$(G_LEVELS), \
$(foreach T,$(TESTS), \
$(eval $(call TEST_TEMPLATE,$T,$C,$O,$G)) \
) \
) \
) \
)
define IMPL_TEMPLATE
$(BUILD_DIR)/impl/$1.o: uprintf.h Makefile
@mkdir -p $$(@D)
$1 $(CFLAGS) -DUPRINTF_IMPLEMENTATION -x c -c $$< -o $$@
endef
$(foreach C,$(COMPILERS),$(eval $(call IMPL_TEMPLATE,$C)))