-
Notifications
You must be signed in to change notification settings - Fork 0
/
GNUmakefile
159 lines (128 loc) · 4.46 KB
/
GNUmakefile
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
ifeq ($(BUILD),release)
CFLAGS += -Os -s -D_FORTIFY_SOURCE=2 -DNDEBUG -march=native
else ifeq ($(BUILD),musl)
CFLAGS += -Os -s -D_FORTIFY_SOURCE=2 -DNDEBUG -march=native -static
LDFLAGS += -static
CC = musl-gcc
else ifeq ($(BUILD),musldebug)
CFLAGS += -Og -g
CC = musl-gcc
else ifeq ($(BUILD),valgrind)
CFLAGS += -Og -g
else ifeq ($(BUILD),sanitise)
CFLAGS += -Og -g -fsanitize=address -fsanitize=undefined
LDFLAGS += -lasan -lubsan
else ifeq ($(BUILD),gdb)
CFLAGS += -O0 -g
else
BUILD = debug
CFLAGS += -Og -g
endif
ifneq ($(BUILD),release)
ifneq ($(BUILD),musl)
#CFLAGS += -Werror
endif
endif
V := 0
AT_0 := @
AT_1 :=
AT := $(AT_$(V))
CFLAGS += -DBUILD_$(shell echo '$(BUILD)' | tr '[:lower:]' '[:upper:]')
TARGET := aether
#PC_DEPS :=
#CFLAGS += $(shell pkg-config --cflags $(PC_DEPS))
#LDLIBS += $(shell pkg-config --static --libs $(PC_DEPS))
SRCS := $(shell find src -name *.c -or -name *.S)
OBJS := $(SRCS:%=build/$(BUILD)/%.o)
DEPS := $(OBJS:%.o=%.d)
INCS := -iquote./include
WARNINGS += -pedantic -pedantic-errors -Wno-overlength-strings
WARNINGS += -fmax-errors=20 -Wall -Wextra -Wdouble-promotion -Wformat=2
WARNINGS += -Wformat-signedness -Wvla -Wformat-truncation=2 -Wformat-overflow=2
WARNINGS += -Wnull-dereference -Winit-self -Wuninitialized
WARNINGS += -Wimplicit-fallthrough=4 -Wstack-protector -Wmissing-include-dirs
WARNINGS += -Wshift-overflow=2 -Wswitch-default -Wswitch-enum
WARNINGS += -Wunused-parameter -Wunused-const-variable=2 -Wstrict-overflow=5
WARNINGS += -Wstringop-overflow=4 -Wstringop-truncation -Walloc-zero -Walloca
WARNINGS += -Warray-bounds=2 -Wattribute-alias=2 -Wlogical-op
WARNINGS += -Wduplicated-branches -Wduplicated-cond -Wtrampolines -Wfloat-equal
WARNINGS += -Wunsafe-loop-optimizations -Wbad-function-cast #-Wshadow
WARNINGS += -Wcast-qual -Wcast-align -Wwrite-strings #-Wconversion
WARNINGS += -Wpacked -Wdangling-else -Wno-parentheses #-Wsign-conversion
WARNINGS += -Wdate-time -Wjump-misses-init -Wreturn-local-addr -Wno-pointer-sign
WARNINGS += -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes
WARNINGS += -Wmissing-declarations -Wnormalized=nfkc -Wredundant-decls
WARNINGS += -Wnested-externs -Wno-missing-field-initializers -fanalyzer
CFLAGS += -D_GNU_SOURCE $(INCS) -MMD -MP -std=c99 -fPIE -fstack-protector
CFLAGS += -ftrapv -fno-strict-aliasing -fno-delete-null-pointer-checks
CFLAGSNW := $(CFLAGS)
CFLAGS += $(WARNINGS)
LDFLAGS += -pie -fPIE -flto
LDLIBS += -lm
VALGRIND_FLAGS += -s --show-leak-kinds=all --leak-check=full --track-origins=yes
.PHONY: $(TARGET)
$(TARGET): build/$(BUILD)/$(TARGET)
$(AT)echo ' SYMLINK ' $(TARGET) "->" build/$(BUILD)/$(TARGET)
$(AT)ln -sf build/$(BUILD)/$(TARGET) $(TARGET)
build/$(BUILD)/$(TARGET): $(OBJS)
$(AT)echo ' LD ' $@
$(AT)$(CC) $(OBJS) -o $@ $(LDFLAGS) $(LDLIBS)
build/$(BUILD)/src/monocypher.c.o: src/monocypher.c
$(AT)mkdir -p $(dir $@)
$(AT)echo ' CC ' $<.o
$(AT)$(CC) -c $(CFLAGSNW) $< -o $@
build/$(BUILD)/src/stb_ds.c.o: src/stb_ds.c
$(AT)mkdir -p $(dir $@)
$(AT)echo ' CC ' $<.o
$(AT)$(CC) -c $(CFLAGSNW) $< -o $@
build/$(BUILD)/src/optparse.c.o: src/optparse.c
$(AT)mkdir -p $(dir $@)
$(AT)echo ' CC ' $<.o
$(AT)$(CC) -c $(CFLAGSNW) $< -o $@
build/$(BUILD)/%.c.o: %.c
$(AT)mkdir -p $(dir $@)
$(AT)echo ' CC ' $<.o
$(AT)$(CC) -c $(CFLAGS) $< -o $@
build/$(BUILD)/%.S.o: %.S
$(AT)mkdir -p $(dir $@)
$(AT)echo ' AS ' $<.o
$(AT)$(AS) $(ASFLAGS) $< -o $@
tags: $(SRCS)
gcc -M $(INCS) $(SRCS) | sed -e 's/[\ ]/\n/g' | \
sed -e '/^$$/d' -e '/\.o:[ \t]*$$/d' | \
ctags -L - $(CTAGS_FLAGS)
.PHONY: clean cleanall syntastic debug release valgrind sanitise
clean:
$(RM) -r build/$(BUILD)/*
cleanall: clean
$(RM) -r build/*/*
syntastic:
echo $(CFLAGS) | tr ' ' '\n' | sort | grep -v "MMD\|MP" | \
grep -v "BUILD_$(shell echo '$(BUILD)' | tr '[:lower:]' '[:upper:]')" \
> .syntastic_c_config
release:
-$(MAKE) "BUILD=release"
./build/release/$(TARGET) $(args)
musl:
-$(MAKE) "BUILD=musl"
./build/musl/$(TARGET) $(args)
musldebug:
-$(MAKE) "BUILD=musldebug"
./build/musldebug/$(TARGET) $(args)
valgrind:
-$(MAKE) "BUILD=valgrind"
valgrind $(VALGRIND_FLAGS) ./build/valgrind/$(TARGET) $(args)
sanitise:
-$(MAKE) "BUILD=sanitise"
./build/sanitise/$(TARGET) $(args)
gdb:
-$(MAKE) "BUILD=gdb"
gdb ./build/gdb/$(TARGET) $(args)
debug:
-$(MAKE)
./build/debug/$(TARGET) $(args)
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),cleanall)
-include $(DEPS)
endif
endif