-
Notifications
You must be signed in to change notification settings - Fork 20
/
Makefile
156 lines (124 loc) · 3.03 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
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
# OS = [ linux | windows ]
OS ?= linux
ifeq ($(OS),windows)
OS_ = osWindows
else
OS_ = osLinux
endif
# ARCH = [ 32 | 64 ]
ARCH ?= 32
ifeq ($(ARCH),64)
WORDSIZE = 8
else
WORDSIZE = 4
endif
# CONFIG = [ debug | release | profiling ]
CONFIG ?= release
CC ?= gcc
CFLAGS ?= -std=c11
CFLAGS += -Werror -Wall -Wextra -Wvla -Wstrict-aliasing -Wstrict-overflow=5 -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wmissing-field-initializers -g
CFLAGS += -include defaults.h
ifeq ($(STRICT),yes)
CFLAGS += -Wformat=2 -Wmissing-include-dirs -Wconversion -pedantic
CFLAGS += -Wno-format-nonliteral -Wno-sign-conversion
endif
ifeq ($(CONFIG),debug)
CFLAGS += -DFCC_DEBUGMODE -g
LDFLAGS += -g
endif
ifeq ($(CONFIG),release)
CFLAGS += -O3
LDFLAGS += -O3
endif
ifeq ($(CONFIG),profiling)
CFLAGS += -O3 -pg
LDFLAGS += -O3 -pg
endif
ifeq ($(CONFIG),coverage)
CFLAGS += --coverage
LDFLAGS += --coverage
endif
BINNAME = fcc
FCC ?= bin/$(CONFIG)/$(BINNAME)
SILENT = >/dev/null
POSTBUILD = @[ -e $@ ] && du -hs $@; echo
#
# Build
#
HEADERS = $(wildcard inc/*.h) defaults.h
OBJS = $(patsubst src/%.c, obj/$(CONFIG)/%.o, $(filter-out src/lexerself.c, $(filter-out src/regself.c, $(wildcard src/*.c))))
OBJ = obj/$(CONFIG)
BIN = bin/$(CONFIG)
OUT = $(BIN)/$(BINNAME)
all: $(OUT)
defaults.h: defaults.in.h
@echo " [makedefaults.sh] $@"
@OS=$(OS_) WORDSIZE=$(WORDSIZE) bash makedefaults.sh $< >$@
$(OBJ)/%.o: src/%.c $(HEADERS)
@mkdir -p $(OBJ)
@echo " [CC] $@"
@$(CC) $(CFLAGS) -c $< -o $@
$(OUT): $(OBJS)
@mkdir -p $(BIN)
@echo " [LD] $@"
@$(CC) $(LDFLAGS) $(OBJS) -o $@
$(POSTBUILD)
clean:
rm -f defaults.h
rm -f obj/*/*.o
rm -f bin/*/$(BINNAME)*
rm -f bin/tests/*
print:
@echo "===================="
@echo " OS : $(OS)"
@echo " ARCH : $(ARCH)"
@echo " CONFIG : $(CONFIG)"
@echo " CC : $(CC)"
@echo " CLFAGS : $(CFLAGS)"
@echo " HEADERS: $(HEADERS)"
@echo " OBJS : $(OBJS)"
@echo " OUT : $(OUT)"
@echo "===================="
#
# Tests
#
TFLAGS = -I tests/include -s
TOUT = xor-list hashset xor-list-error.txt
TESTS = $(patsubst %, bin/tests/%, $(TOUT))
ifneq ($(shell command -v valgrind; echo $?),)
VFLAGS = -q --leak-check=full --workaround-gcc296-bugs=yes --error-exitcode=1
VALGRIND ?= valgrind $(VFLAGS)
endif
tests: $(TESTS)
bin/tests/%-error.txt: tests/%-error.c $(FCC)
@mkdir -p bin/tests
@echo " [$(FCC)] $@"
@$(VALGRIND) $(FCC) $(TFLAGS) $< >$@; [ $$? -eq 1 ]
$(POSTBUILD)
bin/tests/%: tests/%.c $(FCC)
@mkdir -p bin/tests
@echo " [$(FCC)] $@"
@$(VALGRIND) $(FCC) $(TFLAGS) $< -o $@
@echo " [$@]"
@$@ $(SILENT)
$(POSTBUILD)
print-tests:
@echo "===================="
@echo " FCC : $(FCC)"
@echo " TFLAGS : $(TFLAGS)"
@echo " TESTS : $(TESTS)"
@echo " VALGRIND: $(VALGRIND)"
@echo "===================="
#
# Selfhost
#
selfhost: bin/self/fcc
bin/self/%: $(FCC) src/lexerself.c src/regself.c
@echo " [$(FCC)] $@"
@$(VALGRIND) $(FCC) -I tests/include `find src/*.[c] | egrep -v "lexer.c|reg.c"` -o $@
$(POSTBUILD)
#
#
#
.PHONY: all clean print print-tests tests selfhost
.SUFFIXES: