-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
80 lines (63 loc) · 1.79 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
# Makefile
CC := gcc
AR := ar
LDFLAGS := $(LDFLAGS)
LDFLAGS_SHARED := -shared
CFLAGS := -std=c99 -DCTC_DISABLE_GNUC=1 -I./include -Wall -Wextra -Wpedantic \
-Wno-cast-function-type $(CFLAGS)
CFLAGS_SHARED := -fPIC
CFLAGS_DEBUG =
shared_object := libctc.so
static_library := libctc.a
objects := sorter.o binary-searcher.o prepare.o object.o
objects_static := $(patsubst %.o,%_static.o,$(objects))
headers := $(wildcard *.h include/ctc/*.h)
examples := example/hello example/lists
ifneq (,$(findstring debug,$(MAKECMDGOALS)))
debug: $(filter-out debug,$(MAKECMDGOALS))
endif
.PHONY: all default debug
default: shared ;
all: shared static examples ;
debug: ;
.PHONY: shared static examples
shared: $(shared_object) ;
static: $(static_library) ;
examples: $(examples) ;
.PHONY: clean
clean: clean-shared clean-static clean-objects clean-examples ;
debug: CFLAGS_DEBUG += -ggdb -O0 -Wcast-function-type \
-Wno-error=cast-function-type
$(shared_object): $(objects)
$(CC) $^ $(LDFLAGS) $(LDFLAGS_SHARED) -o $@
$(static_library): $(objects_static)
$(AR) -rc $@ $^
$(objects):%.o:%.c $(headers)
$(CC) -c $(CFLAGS) $(CFLAGS_SHARED) $(CFLAGS_DEBUG) $< -o $@
$(objects_static):%_static.o:%.c $(headers)
$(CC) -c $(CFLAGS) $(CFLAGS_DEBUG) $< -o $@
.PHONY: $(examples)
$(examples):%:%/Makefile $(static_library) $(headers)
make -C $@
.PHONY: clean-shared
clean-shared:
if [ -f $(shared_object) ]; then \
rm -f -- $(shared_object); \
fi
.PHONY: clean-static
clean-static:
if [ -f $(static_library) ]; then \
rm -f -- $(static_library); \
fi
.PHONY: clean-objects
clean-objects:
for object in $(objects) $(objects_static); do \
if [ -f $$object ]; then \
rm -f -- $$object; \
fi; \
done
.PHONY: clean-examples
clean-examples:
for example in $(examples); do \
make -C "$$example" clean; \
done