Debian Codegraph @

Makefile

raw
1 PROJECT = heatshrink
2 OPTIMIZE = -O3
3 WARN = -Wall -Wextra -pedantic #-Werror
4 WARN += -Wmissing-prototypes
5 WARN += -Wstrict-prototypes
6 WARN += -Wmissing-declarations
7
8 # If libtheft is available, build additional property-based tests.
9 # Uncomment these to use it in test_heatshrink_dynamic.
10 #CFLAGS += -DHEATSHRINK_HAS_THEFT
11 #THEFT_PATH= /usr/local/
12 #THEFT_INC= -I${THEFT_PATH}/include/
13 #LDFLAGS += -L${THEFT_PATH}/lib -ltheft
14
15 CFLAGS += -std=c99 -g ${WARN} ${THEFT_INC} ${OPTIMIZE}
16
17 all: heatshrink test_runners libraries
18
19 libraries: libheatshrink_static.a libheatshrink_dynamic.a
20
21 test_runners: test_heatshrink_static test_heatshrink_dynamic
22 test: test_runners
23 ./test_heatshrink_static
24 ./test_heatshrink_dynamic
25 ci: test
26
27 clean:
28 rm -f heatshrink test_heatshrink_{dynamic,static} \
29 *.o *.os *.od *.core *.a {dec,enc}_sm.png TAGS
30 rm -rf ${BENCHMARK_OUT}
31
32 TAGS:
33 etags *.[ch]
34
35 diagrams: dec_sm.png enc_sm.png
36
37 dec_sm.png: dec_sm.dot
38 dot -o $@ -Tpng $<
39
40 enc_sm.png: enc_sm.dot
41 dot -o $@ -Tpng $<
42
43 # Benchmarking
44 CORPUS_ARCHIVE= cantrbry.tar.gz
45 CORPUS_URL= http://corpus.canterbury.ac.nz/resources/${CORPUS_ARCHIVE}
46 BENCHMARK_OUT= benchmark_out
47
48 ## Uncomment one of these.
49 DL= curl -o ${CORPUS_ARCHIVE}
50 #DL= wget -O ${CORPUS_ARCHIVE}
51
52 bench: heatshrink corpus
53 mkdir -p ${BENCHMARK_OUT}
54 cd ${BENCHMARK_OUT} && tar vzxf ../${CORPUS_ARCHIVE}
55 time ./benchmark
56
57 corpus: ${CORPUS_ARCHIVE}
58
59 ${CORPUS_ARCHIVE}:
60 ${DL} ${CORPUS_URL}
61
62 # Installation
63 PREFIX ?= /usr/local
64 INSTALL ?= install
65 RM ?= rm
66
67 install: libraries heatshrink
68 ${INSTALL} -c heatshrink ${PREFIX}/bin/
69 ${INSTALL} -c libheatshrink_static.a ${PREFIX}/lib/
70 ${INSTALL} -c libheatshrink_dynamic.a ${PREFIX}/lib/
71 ${INSTALL} -c heatshrink_common.h ${PREFIX}/include/
72 ${INSTALL} -c heatshrink_config.h ${PREFIX}/include/
73 ${INSTALL} -c heatshrink_encoder.h ${PREFIX}/include/
74 ${INSTALL} -c heatshrink_decoder.h ${PREFIX}/include/
75
76 uninstall:
77 ${RM} -f ${PREFIX}/lib/libheatshrink_static.a
78 ${RM} -f ${PREFIX}/lib/libheatshrink_dynamic.a
79 ${RM} -f ${PREFIX}/include/heatshrink_common.h
80 ${RM} -f ${PREFIX}/include/heatshrink_config.h
81 ${RM} -f ${PREFIX}/include/heatshrink_encoder.h
82 ${RM} -f ${PREFIX}/include/heatshrink_decoder.h
83
84 # Internal targets and rules
85
86 OBJS = heatshrink_encoder.o heatshrink_decoder.o
87
88 DYNAMIC_OBJS= $(OBJS:.o=.od)
89 STATIC_OBJS= $(OBJS:.o=.os)
90
91 DYNAMIC_LDFLAGS= ${LDFLAGS} -L. -lheatshrink_dynamic
92 STATIC_LDFLAGS= ${LDFLAGS} -L. -lheatshrink_static
93
94 # Libraries should be built separately for versions
95 # with and without dynamic allocation.
96 CFLAGS_STATIC = ${CFLAGS} -DHEATSHRINK_DYNAMIC_ALLOC=0
97 CFLAGS_DYNAMIC = ${CFLAGS} -DHEATSHRINK_DYNAMIC_ALLOC=1
98
99 heatshrink: heatshrink.od libheatshrink_dynamic.a
100 ${CC} -o $@ $^ ${CFLAGS_DYNAMIC} -L. -lheatshrink_dynamic
101
102 test_heatshrink_dynamic: test_heatshrink_dynamic.od test_heatshrink_dynamic_theft.od libheatshrink_dynamic.a
103 ${CC} -o $@ $< ${CFLAGS_DYNAMIC} test_heatshrink_dynamic_theft.od ${DYNAMIC_LDFLAGS}
104
105 test_heatshrink_static: test_heatshrink_static.os libheatshrink_static.a
106 ${CC} -o $@ $< ${CFLAGS_STATIC} ${STATIC_LDFLAGS}
107
108 libheatshrink_static.a: ${STATIC_OBJS}
109 ar -rcs $@ $^
110
111 libheatshrink_dynamic.a: ${DYNAMIC_OBJS}
112 ar -rcs $@ $^
113
114 %.od: %.c
115 ${CC} -c -o $@ $< ${CFLAGS_DYNAMIC}
116
117 %.os: %.c
118 ${CC} -c -o $@ $< ${CFLAGS_STATIC}
119
120 *.os: Makefile *.h
121 *.od: Makefile *.h
122