-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
101 lines (77 loc) · 2.51 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
__LIBFLAT_VERSION__:=$(shell grep "Libflat, version " libflat.h | python -c "import sys; print sys.stdin.read().split(\"\\n\")[0].split()[-1]")
CC = gcc
AR = ar
LIBS =
INCDIRS =
CFLAGS = -Wno-address -Wno-missing-field-initializers
ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
CFLAGS += -Wall -Wextra
CFLAGS += -O2 -ggdb3
CFLAGS += -MD
CFLAGS += -D__LIBFLAT_VERSION__=\"$(__LIBFLAT_VERSION__)\"
LIB_CFLAGS += -fPIC
EXE_LDFLAGS +=
LIB_SRC := libflat.c rbtree.c interval_tree.c
TEST_SRC := main.c
EXAMPLE_DIR := examples
EXAMPLE_SRC := $(wildcard $(EXAMPLE_DIR)/*.c)
EXAMPLE_OUT := $(basename $(EXAMPLE_SRC))
EXAMPLE_DEP := $(EXAMPLE_SRC:.c=.d)
LIB_OBJ := $(LIB_SRC:.c=.lib.o)
LIB_DEP := $(LIB_SRC:.c=.lib.d)
OBJ := $(LIB_SRC:.c=.o)
DEP := $(LIB_SRC:.c=.d)
TEST_OBJ := $(TEST_SRC:.c=.o)
TEST_DEP := $(TEST_SRC:.c=.d)
OUTLIB = libflat.a
OUTDYN = libflat.so
OUTTEST = flattest
MAKEFILE = Makefile
OUT := $(OUTLIB) $(OUTDYN) $(OUTTEST)
all: $(OUT)
@echo "Built version $(__LIBFLAT_VERSION__)"
static: $(OUTLIB)
shared: $(OUTDYN)
test: $(OUTTEST)
@python flattest.py flattest
examples: $(EXAMPLE_OUT)
define compile_example
$(1): LDFLAGS += $(EXE_LDFLAGS) -lm
$(1): CFLAGS += -I$(ROOT_DIR) -Wno-unused-local-typedefs -Wno-unused-function
$(1): $(addsuffix .c,$(1)) $(OUTDYN)
@echo " [LD] $$@"
$$(CC) $$(CFLAGS) $$^ $$(LDFLAGS) -o $$@
endef
$(foreach example,$(EXAMPLE_OUT),$(eval $(call compile_example,$(example))))
$(OUTLIB): $(OBJ) $(LIBS)
@echo " [AR] $@"
$(AR) rcs $@ $^
$(OUTDYN): LDFLAGS += --shared $(LIB_LDFLAGS)
$(OUTDYN): $(LIB_OBJ) $(LIBS)
@echo " [LD] $@"
$(CC) $(LDFLAGS) -o $@ $^
$(OUTTEST): LDFLAGS += $(EXE_LDFLAGS)
$(OUTTEST): $(TEST_OBJ) $(OUTDYN)
@echo " [LD] $@"
$(CC) $(LDFLAGS) -o $@ $^
$(LIB_OBJ): CFLAGS += $(LIB_CFLAGS)
$(LIB_OBJ): %.lib.o : %.c $(MAKEFILE)
@echo " [CC (pic)] $@"
$(CC) $(CFLAGS) -c $< -o $@
$(OBJ) $(TEST_OBJ): %.o : %.c $(MAKEFILE)
@echo " [CC] $@"
$(CC) $(CFLAGS) -c $< -o $@
clean:
@echo "Cleaning up..."
$(RM) $(OBJ) $(LIB_OBJ) $(TEST_OBJ) $(LIB_DEP) $(DEP) $(TEST_DEP) $(OUT) $(EXAMPLE_OUT) $(EXAMPLE_DEP)
OUTHDR := $(OUTDYN:.so=.h)
install:
@cp -f $(OUTHDR) /usr/local/include
@cp -f $(OUTDYN) /usr/local/lib/$(OUTDYN).$(__LIBFLAT_VERSION__)
@rm -f /usr/local/lib/$(OUTDYN)
@ln -s /usr/local/lib/$(OUTDYN).$(__LIBFLAT_VERSION__) /usr/local/lib/$(OUTDYN)
@echo "Libflat successfully installed"
.PHONY : all clean install static shared test examples
.SILENT :
-include $(LIB_DEP) $(DEP) $(TEST_DEP)
-include $($(EXAMPLE_SRC):.c=.d)