]> git.ozlabs.org Git - ccan/blob - Makefile-ccan
ccanlint: link api tests against compiled objects
[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 CFLAGS=-g -O3 -Wall -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Werror -I. $(DEPGEN)
6 #CFLAGS=-g -Wall -Wstrict-prototypes -Wold-style-definition -Werror -I. $(DEPGEN)
7
8 default: libccan.a
9
10 # Automatic dependency generation: makes ccan/*/*.d files.
11 DEPGEN=-MD
12 -include ccan/*/*.d
13
14 # Every directory with .c files is included.
15 DIRS=$(filter-out $(foreach d,$(EXCLUDE),ccan/$d), $(patsubst %/, %, $(sort $(dir $(wildcard ccan/*/*.c)))))
16
17 # Generate everyone's separate Makefiles.
18 -include $(foreach dir, $(DIRS), $(dir)-Makefile)
19
20 ccan/%-Makefile:
21         @echo $@: $(wildcard ccan/$*/*.[ch]) ccan/$*/_info > $@
22         @echo ccan/$*.o: $(patsubst %.c, %.o, $(wildcard ccan/$*/*.c)) >> $@
23
24 # We compile all the ccan/foo/*.o files together into ccan/foo.o
25 OBJFILES=$(DIRS:=.o)
26
27 # We create all the .o files and link them together.
28 $(OBJFILES): %.o:
29         $(LD) -r -o $@ $^
30
31 libccan.a: $(OBJFILES)
32         $(AR) r $@ $(OBJFILES)