bd6af5ca35274bf411369b47b34bc56afa71260e
[ccan] / Makefile-ccan
1 # Example makefile which makes a "libccan.a" of everything under ccan/.
2 # For simple projects you could just do:
3 #       SRCFILES += $(wildcard ccan/*/*.c)
4
5 #CCAN_CFLAGS=-g -O3 -Wall -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wwrite-strings -Wundef -DCCAN_STR_DEBUG=1
6 CCAN_CFLAGS=-g3 -ggdb -Wall -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wwrite-strings -Wundef -DCCAN_STR_DEBUG=1
7 CFLAGS = $(CCAN_CFLAGS) -I. $(DEPGEN)
8
9 # Modules which are just a header:
10 MODS_NO_SRC := alignof \
11         argcheck \
12         array_size \
13         asearch \
14         bitmap \
15         build_assert \
16         cast \
17         check_type \
18         compiler \
19         container_of \
20         cppmagic \
21         darray \
22         endian \
23         lqueue \
24         lstack \
25         minmax \
26         objset \
27         short_types \
28         structeq \
29         tcon \
30         tlist \
31         typesafe_cb \
32         version
33
34 # No external dependencies, with C code:
35 MODS_WITH_SRC := aga \
36         agar \
37         altstack \
38         antithread \
39         antithread/alloc \
40         asort \
41         asprintf \
42         autodata \
43         avl \
44         base64 \
45         bdelta \
46         block_pool \
47         breakpoint \
48         btree \
49         bytestring \
50         ccan_tokenizer \
51         cdump \
52         charset \
53         ciniparser \
54         crc \
55         crcsync \
56         cpuid \
57         crypto/ripemd160 \
58         crypto/sha256 \
59         crypto/shachain \
60         daemonize \
61         daemon_with_notify \
62         deque \
63         dgraph \
64         eratosthenes \
65         err \
66         failtest \
67         foreach \
68         generator \
69         grab_file \
70         hash \
71         heap \
72         htable \
73         idtree \
74         ilog \
75         invbloom \
76         io \
77         isaac \
78         iscsi \
79         jacobson_karels \
80         jmap \
81         json \
82         jset \
83         lbalance \
84         likely \
85         list \
86         lpq \
87         md4 \
88         mem \
89         net \
90         nfs \
91         noerr \
92         ntdb \
93         ogg_to_pcm \
94         opt \
95         order \
96         permutation \
97         pipecmd \
98         pr_log \
99         ptrint \
100         ptr_valid \
101         pushpull \
102         rbtree \
103         rbuf \
104         read_write_all \
105         rfc822 \
106         rszshm \
107         siphash \
108         sparse_bsearch \
109         str \
110         str/hex \
111         stringbuilder \
112         stringmap \
113         strgrp \
114         strmap \
115         strset \
116         take \
117         tal \
118         tal/grab_file \
119         tal/link \
120         tal/path \
121         tal/stack \
122         tal/str \
123         tal/talloc \
124         talloc \
125         tally \
126         tap \
127         time \
128         timer \
129         ttxml \
130         wwviaudio \
131         xstring
132
133 MODS:=$(MODS_WITH_SRC) $(MODS_NO_SRC)
134
135 default: libccan.a
136
137 # Automatic dependency generation: makes ccan/*/*.d files.
138 DEPGEN=-MMD
139 -include $(foreach m, $(MODS), ccan/$(m)/*.d)
140
141 # Anything with C files needs building; dir leaves / on, sort uniquifies
142 DIRS=$(patsubst %/, %, $(sort $(foreach m, $(filter-out $(MODS_EXCLUDE), $(MODS_WITH_SRC)), $(dir $(wildcard ccan/$m/*.c)))))
143
144 # Generate everyone's separate Makefiles.
145 -include $(foreach dir, $(DIRS), $(dir)-Makefile)
146
147 ccan/%-Makefile:
148         @echo $@: $(wildcard ccan/$*/*.[ch]) ccan/$*/_info > $@
149         @echo ccan/$*.o: $(patsubst %.c, %.o, $(wildcard ccan/$*/*.c)) >> $@
150
151 # We compile all the ccan/foo/*.o files together into ccan/foo.o
152 OBJFILES=$(DIRS:=.o)
153
154 # We create all the .o files and link them together.
155 $(OBJFILES): %.o:
156         $(LD) -r -o $@ $^
157
158 libccan.a: $(OBJFILES)
159         $(AR) r $@ $(OBJFILES)