Makefile-ccan 1.3 KB

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