]> git.ozlabs.org Git - ccan/blob - Makefile-ccan
tdb2: unify tdb1_fetch into tdb_fetch
[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
6 CCAN_CFLAGS=-g -Wall -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wwrite-strings -DCCAN_STR_DEBUG=1
7 CFLAGS = $(CCAN_CFLAGS) -I. $(DEPGEN)
8
9
10 default: libccan.a
11
12 # Automatic dependency generation: makes ccan/*/*.d files.
13 DEPGEN=-MD
14 -include ccan/*/*.d
15
16 # Anything with an _info file is a module.
17 REALLY_ALL=$(patsubst ccan/%/_info, %, $(wildcard ccan/*/_info))
18
19 # Exclude any modules we can't build.
20 ALL=$(filter-out $(EXCLUDE), $(REALLY_ALL))
21
22 # Anything with C files needs building; dir leaves / on, sort uniquifies
23 DIRS=$(patsubst %/, %, $(sort $(foreach m, $(ALL), $(dir $(wildcard ccan/$m/*.c)))))
24
25 # Generate everyone's separate Makefiles.
26 -include $(foreach dir, $(DIRS), $(dir)-Makefile)
27
28 ccan/%-Makefile:
29         @echo $@: $(wildcard ccan/$*/*.[ch]) ccan/$*/_info > $@
30         @echo ccan/$*.o: $(patsubst %.c, %.o, $(wildcard ccan/$*/*.c)) >> $@
31
32 # We compile all the ccan/foo/*.o files together into ccan/foo.o
33 OBJFILES=$(DIRS:=.o)
34
35 # We create all the .o files and link them together.
36 $(OBJFILES): %.o:
37         $(LD) -r -o $@ $^
38
39 libccan.a: $(OBJFILES)
40         $(AR) r $@ $(OBJFILES)