blob: 848cdc219034fbdd982680b8a4dbf8f1d13d2450 [file] [log] [blame]
Austin Schuhf417eaf2019-09-16 21:58:36 -07001c_sources := jsont.c
2
3all: example1 example2 test
4
5object_dir = .objs
6objects = $(patsubst %,$(object_dir)/%,${c_sources:.c=.o})
7object_dirs = $(sort $(foreach fn,$(objects),$(dir $(fn))))
8-include ${objects:.o=.d}
9
10test_dir = test
11test_sources := $(wildcard test/test*.c)
12test_object_dir = $(test_dir)/.objs
13test_build_dir = $(test_dir)/build
14test_objects = $(patsubst test/%,$(test_object_dir)/%,${test_sources:.c=.o})
15test_programs = $(patsubst test/%.c,$(test_build_dir)/%,$(test_sources))
16test_object_dirs = $(sort $(foreach fn,$(test_objects),$(dir $(fn))))
17
18CC = clang
19LD = clang
20
21CFLAGS += -Wall -g -MMD -std=c99 -I.
22TEST_CFLAGS := $(CFLAGS) -O0
23#LDFLAGS +=
24ifneq ($(DEBUG),)
25 CFLAGS += -O0 -DDEBUG=1
26else
27 CFLAGS += -O3 -DNDEBUG
28endif
29
30clean:
31 rm -f jsont example1 example2
32 rm -rf $(object_dir)
33 rm -rf $(test_object_dir)
34 rm -rf $(test_build_dir)
35
36example1: $(objects) $(object_dir)/example1.o
37 $(LD) $(LDFLAGS) -o $@ $^
38
39example2: $(objects) $(object_dir)/example2.o
40 $(LD) $(LDFLAGS) -o $@ $^
41
42test: $(objects) $(test_programs)
43 $(test_programs)
44
45$(test_build_dir)/%: $(objects) $(test_object_dir)/%.o
46 @mkdir -p `dirname $@`
47 $(LD) $(LDFLAGS) -o $@ $^
48
49$(test_object_dir)/%.o: $(test_dir)/%.c
50 @mkdir -p `dirname $@`
51 $(CC) $(TEST_CFLAGS) -c -o $@ $<
52
53$(object_dir)/%.o: %.c
54 @mkdir -p `dirname $@`
55 $(CC) $(CFLAGS) -c -o $@ $<
56
57.PHONY: clean all test