summaryrefslogtreecommitdiff
path: root/n/avr/make
diff options
context:
space:
mode:
Diffstat (limited to 'n/avr/make')
-rw-r--r--n/avr/make/Makefile.avr54
-rw-r--r--n/avr/make/Makefile.gen44
-rw-r--r--n/avr/make/Makefile.host25
3 files changed, 67 insertions, 56 deletions
diff --git a/n/avr/make/Makefile.avr b/n/avr/make/Makefile.avr
index 81a0c74..b063fe5 100644
--- a/n/avr/make/Makefile.avr
+++ b/n/avr/make/Makefile.avr
@@ -2,41 +2,44 @@
#
# Flags.
-AVR_CFLAGS = $(CFLAGS) -mmcu=$(AVR_MCU)
-AVR_ASFLAGS = $(ASFLAGS) -mmcu=$(AVR_MCU)
-AVR_CPPFLAGS = $(CPPFLAGS) $(AVR_DEFS)
-AVR_LDFLAGS = $(LDFLAGS)
-AVR_LDLIBS = $(LDLIBS) $(AVR_LIBS)
-
-AVR_CC = avr-gcc
-AVR_OBJCOPY = avr-objcopy
-AVR_OBJDUMP = avr-objdump
+AVR_CFLAGS := $(CFLAGS) -mmcu=$(AVR_MCU)
+AVR_ASFLAGS := $(ASFLAGS) -mmcu=$(AVR_MCU)
+AVR_CPPFLAGS := $(CPPFLAGS) $(AVR_DEFS)
+AVR_LDFLAGS := $(LDFLAGS)
+AVR_LDLIBS := $(LDLIBS) $(AVR_LIBS)
+
+AVR_CC := avr-gcc
+AVR_OBJCOPY := avr-objcopy
+AVR_OBJDUMP := avr-objdump
AVR_COMPILE.c = $(AVR_CC) $(AVR_CFLAGS) $(AVR_CPPFLAGS) -c
ifdef L
AVR_COMPILE.c += -Wa,-adhlns=$(@:%.avr.o=%.c.avr.lst)
endif
-AVR_COMPILE.S = $(AVR_CC) $(AVR_ASFLAGS) $(AVR_CPPFLAGS) -c
-AVR_LINK.o = $(AVR_CC) $(AVR_CFLAGS) $(AVR_LDFLAGS)
+AVR_COMPILE.S := $(AVR_CC) $(AVR_ASFLAGS) $(AVR_CPPFLAGS) -c
+AVR_LINK.o := $(AVR_CC) $(AVR_CFLAGS) $(AVR_LDFLAGS)
# Main rules.
avr: elf lst hex
-.PHONY: avr clean.avr elf lst text hex srec bin eeprom ehex esrec ebin
+simu: simuelf
+
+.PHONY: avr simu clean.avr elf simuelf lst \
+ text hex srec bin eeprom ehex esrec ebin
# General rules.
AVR_PROGS += $(PROGS)
-AVR_ELFS = $(AVR_PROGS:%=%.avr.elf)
-AVR_SIMU_ELFS = $(AVR_ELFS:%.avr.elf=%.avr.simu.elf)
-AVR_SOURCES = $(filter-out %.host.c,$(SOURCES))
-AVR_C_SOURCES = $(filter %.c,$(AVR_SOURCES))
-AVR_S_SOURCES = $(filter %.S,$(AVR_SOURCES))
-AVR_OBJECTS = $(AVR_C_SOURCES:%.c=%.avr.o) $(AVR_S_SOURCES:%.S=%.avr.o)
-AVR_SIMU_OBJECTS = $(AVR_OBJECTS:%.avr.o=%.avr.simu.o)
+AVR_ELFS := $(AVR_PROGS:%=%.avr.elf)
+AVR_SIMU_ELFS := $(SIMU_PROGS:%=%.avr.simu.elf)
+AVR_SOURCES := $(filter-out %.host.c,$(ALL_SOURCES))
+AVR_C_SOURCES := $(filter %.c,$(AVR_SOURCES))
+AVR_S_SOURCES := $(filter %.S,$(AVR_SOURCES))
+AVR_OBJECTS := $(AVR_C_SOURCES:%.c=%.avr.o) $(AVR_S_SOURCES:%.S=%.avr.o)
+AVR_SIMU_OBJECTS := $(AVR_OBJECTS:%.avr.o=%.avr.simu.o)
elf: $(AVR_ELFS)
-simu: $(AVR_SIMU_ELFS)
+simuelf: $(AVR_SIMU_ELFS)
lst: $(AVR_PROGS:%=%.avr.lst)
define AVR_PROG_template
@@ -72,7 +75,7 @@ $(AVR_ELFS) $(AVR_SIMU_ELFS):
# Rules for building the .text rom images.
-TEXTS = $(AVR_PROGS:%=%.hex) $(AVR_PROGS:%=%.bin) $(AVR_PROGS:%=%.srec)
+TEXTS := $(AVR_PROGS:%=%.hex) $(AVR_PROGS:%=%.bin) $(AVR_PROGS:%=%.srec)
text: hex
@@ -91,8 +94,8 @@ srec: $(AVR_PROGS:%=%.srec)
# Rules for building the .eeprom rom images.
-EEPROMS = $(AVR_PROGS:%=%_eeprom.hex) $(AVR_PROGS:%=%_eeprom.bin) \
- $(AVR_PROGS:%=%_eeprom.srec)
+EEPROMS := $(AVR_PROGS:%=%_eeprom.hex) $(AVR_PROGS:%=%_eeprom.bin) \
+ $(AVR_PROGS:%=%_eeprom.srec)
eeprom: ehex
@@ -112,6 +115,7 @@ esrec: $(AVR_PROGS:%=%_eeprom.srec)
# Cleaning.
clean.avr:
- rm -f *.avr.o *.avr.d $(AVR_ELFS) *.avr.simu.o *.avr.simu.d $(AVR_SIMU_ELFS)
- rm -f *.avr.lst *.avr.map $(TEXTS) $(EEPROMS)
+ rm -f *.avr.o *.avr.d $(AVR_ELFS) \
+ *.avr.simu.o *.avr.simu.d $(AVR_SIMU_ELFS) \
+ *.avr.lst *.avr.map $(TEXTS) $(EEPROMS)
diff --git a/n/avr/make/Makefile.gen b/n/avr/make/Makefile.gen
index e403923..5193e43 100644
--- a/n/avr/make/Makefile.gen
+++ b/n/avr/make/Makefile.gen
@@ -2,46 +2,50 @@
# 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)
+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)
+
+# Usefull macros.
+## Return $(A) only if defined, else return B.
+## $(call defval A,B)
+defval = $(if $(filter undefined,$(origin $(1))),$(2),$($(1)))
# Main rules.
-all: avr host
+all: avr simu host
.PHONY: all clean doc
# General rules.
-ALL_PROGS = $(PROGS) $(AVR_PROGS) $(HOST_PROGS)
-SOURCES = $(foreach prog,$(ALL_PROGS),$($(prog)_SOURCES))
+ALL_PROGS := $(PROGS) $(AVR_PROGS) $(HOST_PROGS) $(SIMU_PROGS)
+ALL_SOURCES = $(foreach prog,$(ALL_PROGS),$($(prog)_SOURCES))
# Modules.
MODULES += host
-ifneq (,$(MODULES))
-include $(MODULES:%=$(BASE)/modules/%/Makefile.module)
-endif
+ALL_MODULES := $(sort $(MODULES) \
+ $(foreach prog,$(ALL_PROGS),$($(prog)_MODULES)))
-none_SOURCES =
+include $(ALL_MODULES:%=$(BASE)/modules/%/Makefile.module)
define MODULES_template
$(1)_SOURCES += $(foreach module,\
- $(if $($(1)_MODULES),$($(1)_MODULES),$(MODULES)),\
+ $(call defval,$(1)_MODULES,$(MODULES)),\
$($(subst /,_,$(module))_SOURCES)\
)
endef
$(foreach prog,$(ALL_PROGS),$(eval $(call MODULES_template,$(prog))))
-vpath %.c $(MODULES:%=$(BASE)/modules/%)
-vpath %.S $(MODULES:%=$(BASE)/modules/%)
+vpath %.c $(ALL_MODULES:%=$(BASE)/modules/%)
+vpath %.S $(ALL_MODULES:%=$(BASE)/modules/%)
# Compilation test rules.
@@ -51,7 +55,8 @@ test.sub::
endef
define TEST_template
-$$(foreach mcu,$$(if $$($(1:%.h=%)_MCU),$$($(1:%.h=%)_MCU),$$(TEST_MCU)),\
+$$(foreach mcu,\
+ $$(if $$($(1:%.h=%)_TEST_MCU),$$($(1:%.h=%)_TEST_MCU),$$(TEST_MCU)),\
$$(eval $$(call TEST_MCU_template,$(1),$$(mcu))))
test.sub::
$$(MAKE) CONFIGFILE=$(1) clean host
@@ -63,7 +68,7 @@ test: test.sub clean
# Include other Makefiles.
-ifneq (,$(filter-out %.c %.avr.S,$(SOURCES)))
+ifneq (,$(filter-out %.c %.avr.S,$(ALL_SOURCES)))
$(error Sources should be .c or .avr.S files)
endif
@@ -72,6 +77,7 @@ include $(BASE)/make/Makefile.avr
include $(BASE)/make/Makefile.host
else
avr:
+simu:
host:
clean.avr:
clean.host:
diff --git a/n/avr/make/Makefile.host b/n/avr/make/Makefile.host
index 3fd343f..d294250 100644
--- a/n/avr/make/Makefile.host
+++ b/n/avr/make/Makefile.host
@@ -2,13 +2,13 @@
#
# Flags.
-HOST_CFLAGS = $(CFLAGS)
-HOST_CPPFLAGS = $(CPPFLAGS) $(HOST_DEFS) -DHOST=1
-HOST_LDFLAGS = $(LDFLAGS)
-HOST_LDLIBS = $(LDLIBS) $(HOST_LIBS)
+HOST_CFLAGS := $(CFLAGS)
+HOST_CPPFLAGS := $(CPPFLAGS) $(HOST_DEFS) -DHOST=1
+HOST_LDFLAGS := $(LDFLAGS)
+HOST_LDLIBS := $(LDLIBS) $(HOST_LIBS)
-HOST_COMPILE.c = $(CC) $(HOST_CFLAGS) $(HOST_CPPFLAGS) -c
-HOST_LINK.o = $(CC) $(HOST_CFLAGS) $(HOST_LDFLAGS)
+HOST_COMPILE.c := $(CC) $(HOST_CFLAGS) $(HOST_CPPFLAGS) -c
+HOST_LINK.o := $(CC) $(HOST_CFLAGS) $(HOST_LDFLAGS)
# Main rules.
@@ -19,17 +19,18 @@ host: exe
# General rules.
HOST_PROGS += $(PROGS)
-HOST_EXES = $(HOST_PROGS:%=%.host)
-HOST_SOURCES = $(filter-out %.avr.c %.avr.S,$(SOURCES))
-HOST_OBJECTS = $(HOST_SOURCES:%.c=%.host.o)
+HOST_EXES := $(HOST_PROGS:%=%.host)
+HOST_SOURCES := $(filter-out %.avr.c %.avr.S,$(ALL_SOURCES))
+HOST_OBJECTS := $(HOST_SOURCES:%.c=%.host.o)
exe: $(HOST_EXES)
-define AVR_PROG_template
-$(1).host: $$(patsubst %.c,%.host.o,$$(filter-out %.avr.c %.avr.S,$$($(1)_SOURCES)))
+define HOST_PROG_template
+$(1).host: $$(patsubst %.c,%.host.o,\
+ $$(filter-out %.avr.c %.avr.S,$$($(1)_SOURCES)))
endef
-$(foreach prog,$(HOST_PROGS),$(eval $(call AVR_PROG_template,$(prog))))
+$(foreach prog,$(HOST_PROGS),$(eval $(call HOST_PROG_template,$(prog))))
$(HOST_EXES):
$(HOST_LINK.o) $^ $(HOST_LDLIBS) -o $@