-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
79 lines (55 loc) · 1.81 KB
/
Copy pathMakefile
File metadata and controls
79 lines (55 loc) · 1.81 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Usage:
# make # same as `make compile`
# make compile # compile all binaries
# make check # builds tests and runs them
# make test # runs all built tests from bin/tests
# make clean # remove ALL binaries and object files
.PHONY = compile clean
CC = clang
GLIB_CCFLAGS := $(shell pkg-config --cflags glib-2.0)
GLIB_LLFLAGS := $(shell pkg-config --libs glib-2.0)
CHECK_CCFLAGS := $(shell pkg-config --cflags check)
CHECK_LLFLAGS := $(shell pkg-config --libs check)
CCFLAGS = -I include ${GLIB_CCFLAGS}
SO_CCFLAGS = ${CCFLAGS} -shared -fPIC -c
TESTS_CCFLAGS = ${CCFLAGS} ${CHECK_CCFLAGS}
LLFLAGS = -pthread -lm -L lib $(LIBS:lib/lib%.so=-l%) ${GLIB_LLFLAGS}
TESTS_LLFLAGS = ${LLFLAGS} ${CHECK_LLFLAGS}
SLIBS := $(wildcard slib/*.c)
LIBS := $(SLIBS:slib/%.c=lib/lib%.so)
SRCS := $(wildcard src/*.c)
BINS := $(SRCS:src/%.c=bin/%)
TESTS := $(wildcard tests/*.c)
TESTS_BINS := $(TESTS:tests/%.c=bin/tests/%)
lib/lib%.so: slib/%.c --dir-lib
${CC} ${SO_CCFLAGS} -o $@ $<
bin/%: src/%.c --dir-bin
${CC} ${CCFLAGS} ${LLFLAGS} -o $@ $<
bin/tests/%: tests/%.c --dir-bin-tests
${CC} ${TESTS_CCFLAGS} ${TESTS_LLFLAGS} -o $@ $<
compile: --compile-libs --compile-bins
check: --remove-old-tests --compile-tests --run-tests
test: --run-tests
clean:
rm -rf lib/*.so
rm -rf bin/*
@echo "Cleaned Library Files and Binaries\n"
docs: --force
doxygen
@echo "Documentation built\n"
--compile-libs: ${LIBS}
@echo "Compiled Library Files\n"
--compile-bins: ${BINS}
@echo "Compiled Binaries\n"
--remove-old-tests:
rm -rf bin/tests/*
--compile-tests: ${TESTS_BINS}
@echo "Compiled Tests\n"
--run-tests: ${TESTS_BINS}
@echo "Starting Tests\n"
@for file in $^ ; do $${file}; echo ""; done
@echo "Tests Done\n"
--dir-%:
mkdir -p $(subst -,/,$(@:--dir-%=%))
@echo "Created Dir: $(subst -,/,$(@:--dir-%=%))\n"
--force: ;