-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
119 lines (98 loc) · 2.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
#
# Project configuration
#
CFGFLAGS := -DWITH_TABLE_CACHE -DWITH_TABLE_CACHE_STATS
#
# Project structure
#
SRCDIRS = src test include
INCDIRS := $(shell find $(SRCDIRS) -type d)
INCFLAGS := $(addprefix -I,$(INCDIRS))
SRCS := src/cache.c \
src/hamt.c \
src/murmur3.c \
src/uh.c
OBJS := $(SRCS:.c=.o)
#
# System info
#
ARCH := $(shell uname)
ifeq ($(ARCH),Darwin)
LIB := libhamt.dylib
LDFLAGS = -dynamiclib
else ifeq ($(ARCH),Linux)
LIB := libhamt.so
LDFLAGS = -shared
endif
#
# Compiler flags
#
CC := gcc
CFLAGS := -std=c11 -pedantic -Wall -Werror -Wextra $(INCFLAGS)
#
# Debug build settings
#
DBGDIR = build/debug
DBGTREE = $(addprefix $(DBGDIR)/, $(SRCDIRS))
DBGLIB = $(DBGDIR)/$(LIB)
DBGOBJS = $(addprefix $(DBGDIR)/, $(OBJS))
DBGCFLAGS = -g -O0 -DDEBUG $(CFGFLAGS)
DBGLDFLAGS := $(LDFLAGS)
#
# Release build settings
#
RELDIR = build/release
RELTREE = $(addprefix $(RELDIR)/, $(SRCDIRS))
RELLIB = $(RELDIR)/$(LIB)
RELOBJS = $(addprefix $(RELDIR)/, $(OBJS))
RELCFLAGS = -O3 -DNDEBUG $(CFGFLAGS)
RELLDFLAGS := $(LDFLAGS)
#
# Test build settings
#
TESTDIR = build/debug
TESTSRCS := src/uh.c \
test/test_hamt.c \
test/utils.c \
test/words.c
TESTOBJS := $(TESTSRCS:.c=.o)
TESTOBJS := $(addprefix $(TESTDIR)/, $(TESTOBJS))
TESTEXE := $(addprefix $(TESTDIR)/test/,test_hamt)
.PHONY: all clean debug prep release remake
# Default build to debug
all: prep debug
#
# Debug rules
#
debug: $(DBGLIB)
$(DBGLIB): $(DBGOBJS)
$(CC) $(DBGLDFLAGS) -o $(DBGLIB) $^
$(DBGDIR)/%.o: %.c
$(CC) -c $(CFLAGS) $(DBGCFLAGS) -o $@ $<
#
# Release rules
#
release: $(RELLIB)
$(RELLIB): $(RELOBJS)
$(CC) $(RELLDFLAGS) -o $(RELLIB) $^
$(RELDIR)/%.o: %.c
$(CC) -c $(CFLAGS) $(RELCFLAGS) -o $@ $<
#
# Test rules
#
runtest: test
$(TESTEXE)
test: $(TESTEXE)
$(TESTEXE): $(TESTOBJS)
echo ${TESTOBJS}
$(CC) -o $(TESTEXE) $^
#
# Other rules
#
prep:
@mkdir -p $(DBGTREE) $(RELTREE)
remake: clean all
clean:
rm -f $(RELLIB) $(RELOBJS) $(DBGLIB) $(DBGOBJS) $(TESTEXE) $(TESTOBJS)
distclean:
rm -r -f build