Makefile: don't separate all modules with external dependencies.
[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         array_size \
12         asearch \
13         build_assert \
14         bytestring \
15         cast \
16         check_type \
17         compiler \
18         container_of \
19         darray \
20         endian \
21         objset \
22         short_types \
23         tcon \
24         tlist \
25         typesafe_cb \
26         version
27
28 # No external dependencies, with C code:
29 MODS_WITH_SRC := antithread \
30         antithread/alloc \
31         asort \
32         asprintf \
33         autodata \
34         avl \
35         bdelta \
36         block_pool \
37         btree \
38         ccan_tokenizer \
39         charset \
40         ciniparser \
41         crc \
42         crcsync \
43         daemonize \
44         daemon_with_notify \
45         dgraph \
46         err \
47         failtest \
48         foreach \
49         grab_file \
50         hash \
51         htable \
52         idtree \
53         ilog \
54         isaac \
55         iscsi \
56         jmap \
57         json \
58         jset \
59         lbalance \
60         likely \
61         list \
62         md4 \
63         net \
64         nfs \
65         noerr \
66         ogg_to_pcm \
67         opt \
68         ptr_valid \
69         rbtree \
70         rbuf \
71         read_write_all \
72         rfc822 \
73         siphash \
74         sparse_bsearch \
75         str \
76         stringmap \
77         strmap \
78         strset \
79         str_talloc \
80         take \
81         tal \
82         tal/link \
83         tal/path \
84         tal/str \
85         tal/talloc \
86         talloc \
87         talloc_link \
88         tally \
89         tap \
90         time \
91         ttxml \
92         wwviaudio
93
94 MODS:=$(MODS_WITH_SRC) $(MODS_NO_SRC)
95
96 default: libccan.a
97
98 # Automatic dependency generation: makes ccan/*/*.d files.
99 DEPGEN=-MD
100 -include ccan/*/*.d
101
102 # Anything with C files needs building; dir leaves / on, sort uniquifies
103 DIRS=$(patsubst %/, %, $(sort $(foreach m, $(filter-out $(MODS_EXCLUDE), $(MODS_WITH_SRC)), $(dir $(wildcard ccan/$m/*.c)))))
104
105 # Generate everyone's separate Makefiles.
106 -include $(foreach dir, $(DIRS), $(dir)-Makefile)
107
108 ccan/%-Makefile:
109         @echo $@: $(wildcard ccan/$*/*.[ch]) ccan/$*/_info > $@
110         @echo ccan/$*.o: $(patsubst %.c, %.o, $(wildcard ccan/$*/*.c)) >> $@
111
112 # We compile all the ccan/foo/*.o files together into ccan/foo.o
113 OBJFILES=$(DIRS:=.o)
114
115 # We create all the .o files and link them together.
116 $(OBJFILES): %.o:
117         $(LD) -r -o $@ $^
118
119 libccan.a: $(OBJFILES)
120         $(AR) r $@ $(OBJFILES)