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