forked from rsms/jsont
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
57 lines (44 loc) · 1.34 KB
/
Copy pathMakefile
File metadata and controls
57 lines (44 loc) · 1.34 KB
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
c_sources := jsont.c
all: example1 example2 test
object_dir = .objs
objects = $(patsubst %,$(object_dir)/%,${c_sources:.c=.o})
object_dirs = $(sort $(foreach fn,$(objects),$(dir $(fn))))
-include ${objects:.o=.d}
test_dir = test
test_sources := $(wildcard test/test*.c)
test_object_dir = $(test_dir)/.objs
test_build_dir = $(test_dir)/build
test_objects = $(patsubst test/%,$(test_object_dir)/%,${test_sources:.c=.o})
test_programs = $(patsubst test/%.c,$(test_build_dir)/%,$(test_sources))
test_object_dirs = $(sort $(foreach fn,$(test_objects),$(dir $(fn))))
CC = clang
LD = clang
CFLAGS += -Wall -g -MMD -std=c99 -I.
TEST_CFLAGS := $(CFLAGS) -O0
#LDFLAGS +=
ifneq ($(DEBUG),)
CFLAGS += -O0 -DDEBUG=1
else
CFLAGS += -O3 -DNDEBUG
endif
clean:
rm -f jsont example1 example2
rm -rf $(object_dir)
rm -rf $(test_object_dir)
rm -rf $(test_build_dir)
example1: $(objects) $(object_dir)/example1.o
$(LD) $(LDFLAGS) -o $@ $^
example2: $(objects) $(object_dir)/example2.o
$(LD) $(LDFLAGS) -o $@ $^
test: $(objects) $(test_programs)
$(test_programs)
$(test_build_dir)/%: $(objects) $(test_object_dir)/%.o
@mkdir -p `dirname $@`
$(LD) $(LDFLAGS) -o $@ $^
$(test_object_dir)/%.o: $(test_dir)/%.c
@mkdir -p `dirname $@`
$(CC) $(TEST_CFLAGS) -c -o $@ $<
$(object_dir)/%.o: %.c
@mkdir -p `dirname $@`
$(CC) $(CFLAGS) -c -o $@ $<
.PHONY: clean all test