]> git.ozlabs.org Git - ccan/blob - Makefile-ccan
tal: simplify.
[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 # Normal modules: no external dependencies, just a header:
10 MODS_NORMAL_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
27 # No external dependencies, with C code:
28 MODS_NORMAL_WITH_SRC := antithread \
29         antithread/alloc \
30         asort \
31         asprintf \
32         autodata \
33         avl \
34         bdelta \
35         block_pool \
36         btree \
37         ccan_tokenizer \
38         charset \
39         ciniparser \
40         crc \
41         crcsync \
42         daemonize \
43         daemon_with_notify \
44         dgraph \
45         err \
46         failtest \
47         foreach \
48         grab_file \
49         hash \
50         htable \
51         idtree \
52         ilog \
53         isaac \
54         iscsi \
55         json \
56         lbalance \
57         likely \
58         list \
59         md4 \
60         net \
61         noerr \
62         opt \
63         ptr_valid \
64         rbtree \
65         read_write_all \
66         rfc822 \
67         sparse_bsearch \
68         str \
69         stringmap \
70         strmap \
71         strset \
72         str_talloc \
73         take \
74         tal \
75         tal/path \
76         tal/str \
77         talloc \
78         talloc_link \
79         tally \
80         tap \
81         time \
82         ttxml
83
84 MODS_NORMAL:=$(MODS_NORMAL_WITH_SRC) $(MODS_NORMAL_NO_SRC)
85
86 # Modules which require external dependencies, thus may not pass check.
87 MODS_EXTERNAL_NO_SRC:=
88
89 MODS_EXTERNAL_WITH_SRC:=jmap \
90         jset \
91         nfs \
92         ogg_to_pcm \
93         wwviaudio
94
95 MODS_EXTERNAL:=$(MODS_EXTERNAL_NO_SRC) $(MODS_EXTERNAL_WITH_SRC)
96
97 MODS:=$(MODS_EXTERNAL) $(MODS_NORMAL)
98
99 default: libccan.a
100
101 # Automatic dependency generation: makes ccan/*/*.d files.
102 DEPGEN=-MD
103 -include ccan/*/*.d
104
105 # Anything with C files needs building; dir leaves / on, sort uniquifies
106 DIRS=$(patsubst %/, %, $(sort $(foreach m, $(MODS_NORMAL_WITH_SRC), $(dir $(wildcard ccan/$m/*.c)))))
107
108 # Generate everyone's separate Makefiles.
109 -include $(foreach dir, $(DIRS), $(dir)-Makefile)
110
111 ccan/%-Makefile:
112         @echo $@: $(wildcard ccan/$*/*.[ch]) ccan/$*/_info > $@
113         @echo ccan/$*.o: $(patsubst %.c, %.o, $(wildcard ccan/$*/*.c)) >> $@
114
115 # We compile all the ccan/foo/*.o files together into ccan/foo.o
116 OBJFILES=$(DIRS:=.o)
117
118 # We create all the .o files and link them together.
119 $(OBJFILES): %.o:
120         $(LD) -r -o $@ $^
121
122 libccan.a: $(OBJFILES)
123         $(AR) r $@ $(OBJFILES)