This repository has been archived by the owner on Apr 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
130 lines (109 loc) · 2.59 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
.POSIX:
.PHONY: clean check install
SRC = main.c
HEADERS := $(wildcard *.h)
DESTDIR ?= /usr/local/
WITH_ASAN = 0
WITH_LOGS=0
WITH_OPTIMIZE = 0
WITH_DTRACE=1
OS = $(shell uname)
ARCH = $(shell uname -m)
ifeq "$(strip $(OS))" "Darwin"
ASAN_DIR=$(shell $(CC) -print-search-dirs | awk -F '=' '/libraries/{print $$2}')/lib/darwin/
else ifeq "$(strip $(OS))" "Linux"
ASAN_DIR=$(shell $(CC) -print-search-dirs | awk -F '=' '/libraries/{split($$2, libs, ":"); printf("%s/lib/linux", libs[1])}')
endif
CFLAGS_COMMON := \
-Wall \
-Wextra \
-Wimplicit-fallthrough \
-Walloca \
-Wparentheses \
-Wignored-qualifiers \
-Wunused-function \
-Wunused \
-Wunused-parameter \
-Wuninitialized \
-Wunreachable-code \
-Wno-missing-field-initializers \
-Wunused-const-variable \
-Wno-dollar-in-identifier-extension \
-g \
-std=c99 \
-march=native \
-fno-omit-frame-pointer \
-fstrict-aliasing \
-fPIC \
-D_POSIX_C_SOURCE=200809L
# If clang: more warnings
ifneq "$(findstring clang,$(shell $(CC) --version))" ""
CFLAGS_COMMON += \
-Wunused-member-function \
-Wloop-analysis \
-Wkeyword-macro \
-Wcomma \
-Wstring-conversion \
-Wunused-member-function \
-Wcomma \
-Wimplicit \
-Wlogical-op-parentheses \
-Widiomatic-parentheses \
-Wheader-hygiene \
-Wconditional-uninitialized \
-Wthread-safety \
-Wmove \
-Wno-c++98-compat
endif
CFLAGS = $(CFLAGS_COMMON) -DLD='"$(CC)"' -DAS='"$(AS)"'
CFLAGS_STDLIB = $(CFLAGS_COMMON) -fno-stack-protector
ifeq "$(WITH_DTRACE)" "0"
CFLAGS_STDLIB += -DDTRACE_PROBES_DISABLED
endif
ifeq "$(WITH_ASAN)" "1"
CFLAGS += -fsanitize=address -DASAN_DIR='"$(ASAN_DIR)"' -DWITH_ASAN=1
CFLAGS_STDLIB += -shared-libasan
else
CFLAGS += -DWITH_ASAN=0
CFLAGS_STDLIB += -DWITH_ASAN=0
endif
ifeq "$(WITH_LOGS)" "1"
CFLAGS += -DWITH_LOGS=1
else
CFLAGS += -DWITH_LOGS=0
endif
ifeq "$(WITH_OPTIMIZE)" "0"
CFLAGS += -O0
CFLAGS_STDLIB += -O0
else
CFLAGS += -O2
CFLAGS_STDLIB += -O2
endif
TESTS_SRC := $(wildcard tests/*.kt)
TESTS_O := $(TESTS_SRC:.kt=.o)
TESTS_ASM := $(TESTS_SRC:.kt=.s)
TESTS_EXE := $(TESTS_SRC:.kt=.exe)
.DEFAULT:
mktc: $(SRC) $(HEADERS) mkt_stdlib.o
$(CC) $(CFLAGS) $(SRC) -o $@
mkt_stdlib.o: mkt_stdlib.c probes.h
$(CC) $(CFLAGS_STDLIB) $< -c
test: test.c
$(CC) $(CFLAGS) $< -o $@
probes.h: probes.d
ifeq "$(WITH_DTRACE)" "1"
dtrace -o $@ -h -s $<
endif
%.exe: %.kt mktc
./mktc $<
check: mktc $(TESTS_EXE) test
@./test
clean:
find . -name '*.s' -or -name '*.o' -or -name '*.exe' -type f | xargs $(RM)
$(RM) mktc
$(RM) -r ./*.dSYM
install: mktc
mkdir -p $(DESTDIR)/lib/
mkdir -p $(DESTDIR)/bin/
cp mkt_stdlib.o $(DESTDIR)/lib/mkt_stdlib.o
cp mktc $(DESTDIR)/bin/mktc