# Makefile.gen - General Makefile. # Flags INCLUDES = -I$(BASE) -I$(BASE)/common CFLAGS = -g -Wall -W -Wundef -Wno-unused-parameter $(OPTIMIZE) ASFLAGS = -Wa,--gstabs CPPFLAGS = $(DEFS) $(INCLUDES) -MMD \ $(if $(CONFIGFILE),$(CONFIGFILE:%=-include %)) LDFLAGS = LDLIBS = $(LIBS) # Main rules. all: avr host .PHONY: all clean doc # General rules. ALL_PROGS = $(PROGS) $(AVR_PROGS) $(HOST_PROGS) SOURCES = $(foreach prog,$(ALL_PROGS),$($(prog)_SOURCES)) # Modules. MODULES += host ifneq (,$(MODULES)) include $(MODULES:%=$(BASE)/modules/%/Makefile.module) endif define MODULES_template $(1)_SOURCES += $(foreach module,$(MODULES),$($(subst /,_,$(module))_SOURCES)) endef $(foreach prog,$(ALL_PROGS),$(eval $(call MODULES_template,$(prog)))) vpath %.c $(MODULES:%=$(BASE)/modules/%) vpath %.S $(MODULES:%=$(BASE)/modules/%) # Compilation test rules. define TEST_MCU_template test.sub:: $$(MAKE) CONFIGFILE=$(1) AVR_MCU=$(2) clean elf endef define TEST_template $$(foreach mcu,$$(if $$($(1:%.h=%)_MCU),$$($(1:%.h=%)_MCU),$$(TEST_MCU)),\ $$(eval $$(call TEST_MCU_template,$(1),$$(mcu)))) test.sub:: $$(MAKE) CONFIGFILE=$(1) clean host endef $(foreach config,$(TEST_CONFIGFILES),$(eval $(call TEST_template,$(config)))) test: test.sub clean # Include other Makefiles. ifneq (,$(filter-out %.c %.avr.S,$(SOURCES))) $(error Sources should be .c or .avr.S files) endif ifneq (,$(strip $(ALL_PROGS))) include $(BASE)/make/Makefile.avr include $(BASE)/make/Makefile.host else avr: host: clean.avr: clean.host: endif # Rules for building the doc. doc: $(DOC) %.html: %.txt %.exd aft $< %.exd: $(EXTRACTDOC) test -n "$^" && extractdoc $^ > $@ || true # Cleaning. clean: clean.avr clean.host rm -f *.bak *~ $(DOC) *.exd $(EXTRA_CLEAN_FILES)