]> git.ozlabs.org Git - ccan/blob - Makefile-ccan
list: new list_for_each{, _safe}_off_dir_ macros
[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         darray \
21         endian \
22         minmax \
23         objset \
24         short_types \
25         structeq \
26         tcon \
27         tlist \
28         typesafe_cb \
29         version
30
31 # No external dependencies, with C code:
32 MODS_WITH_SRC := antithread \
33         antithread/alloc \
34         asort \
35         asprintf \
36         autodata \
37         avl \
38         bdelta \
39         block_pool \
40         breakpoint \
41         btree \
42         bytestring \
43         ccan_tokenizer \
44         cdump \
45         charset \
46         ciniparser \
47         crc \
48         crcsync \
49         cpuid \
50         daemonize \
51         daemon_with_notify \
52         dgraph \
53         eratosthenes \
54         err \
55         failtest \
56         foreach \
57         grab_file \
58         hash \
59         heap \
60         htable \
61         idtree \
62         ilog \
63         invbloom \
64         io \
65         isaac \
66         iscsi \
67         jacobson_karels \
68         jmap \
69         json \
70         jset \
71         lbalance \
72         likely \
73         list \
74         lqueue \
75         lstack \
76         md4 \
77         mem \
78         net \
79         nfs \
80         noerr \
81         ntdb \
82         ogg_to_pcm \
83         opt \
84         ptr_valid \
85         pushpull \
86         rbtree \
87         rbuf \
88         read_write_all \
89         rfc822 \
90         siphash \
91         sparse_bsearch \
92         str \
93         stringbuilder \
94         stringmap \
95         strmap \
96         strset \
97         take \
98         tal \
99         tal/grab_file \
100         tal/link \
101         tal/path \
102         tal/str \
103         tal/talloc \
104         talloc \
105         tally \
106         tap \
107         time \
108         timer \
109         ttxml \
110         wwviaudio
111
112 MODS:=$(MODS_WITH_SRC) $(MODS_NO_SRC)
113
114 default: libccan.a
115
116 # Automatic dependency generation: makes ccan/*/*.d files.
117 DEPGEN=-MD
118 -include ccan/*/*.d
119
120 # Anything with C files needs building; dir leaves / on, sort uniquifies
121 DIRS=$(patsubst %/, %, $(sort $(foreach m, $(filter-out $(MODS_EXCLUDE), $(MODS_WITH_SRC)), $(dir $(wildcard ccan/$m/*.c)))))
122
123 # Generate everyone's separate Makefiles.
124 -include $(foreach dir, $(DIRS), $(dir)-Makefile)
125
126 ccan/%-Makefile:
127         @echo $@: $(wildcard ccan/$*/*.[ch]) ccan/$*/_info > $@
128         @echo ccan/$*.o: $(patsubst %.c, %.o, $(wildcard ccan/$*/*.c)) >> $@
129
130 # We compile all the ccan/foo/*.o files together into ccan/foo.o
131 OBJFILES=$(DIRS:=.o)
132
133 # We create all the .o files and link them together.
134 $(OBJFILES): %.o:
135         $(LD) -r -o $@ $^
136
137 libccan.a: $(OBJFILES)
138         $(AR) r $@ $(OBJFILES)