summaryrefslogtreecommitdiffhomepage
path: root/digital/avr/make
diff options
context:
space:
mode:
authorNicolas Schodet2007-10-07 22:16:03 +0200
committerNicolas Schodet2007-10-07 22:16:03 +0200
commit583f00e0b8efe2832f63efb478a51d3ad35e92ed (patch)
treee2cd42af768a4d248883d7fcebcb2124aad6fbe5 /digital/avr/make
parente38de75f64149d148e66572e330b7ce808782b1f (diff)
Included SI2E avr modules.
Well, this need more works...
Diffstat (limited to 'digital/avr/make')
-rw-r--r--digital/avr/make/Makefile.avr121
-rw-r--r--digital/avr/make/Makefile.gen101
-rw-r--r--digital/avr/make/Makefile.host48
3 files changed, 270 insertions, 0 deletions
diff --git a/digital/avr/make/Makefile.avr b/digital/avr/make/Makefile.avr
new file mode 100644
index 00000000..b063fe53
--- /dev/null
+++ b/digital/avr/make/Makefile.avr
@@ -0,0 +1,121 @@
+# Makefile.avr - AVR part Makefile.
+#
+# 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_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)
+
+# Main rules.
+
+avr: elf lst hex
+
+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 := $(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)
+simuelf: $(AVR_SIMU_ELFS)
+lst: $(AVR_PROGS:%=%.avr.lst)
+
+define AVR_PROG_template
+$(1).avr.elf: $$(patsubst %.S,%.avr.o,$$(patsubst %.c,%.avr.o,\
+ $$(filter-out %.host.c,$$($(1)_SOURCES))))
+$(1).avr.simu.elf: $$(patsubst %.S,%.avr.simu.o,$$(patsubst %.c,%.avr.simu.o,\
+ $$(filter-out %.host.c,$$($(1)_SOURCES))))
+endef
+
+$(foreach prog,$(AVR_PROGS),$(eval $(call AVR_PROG_template,$(prog))))
+
+$(AVR_ELFS) $(AVR_SIMU_ELFS):
+ $(AVR_LINK.o) $^ $(AVR_LDLIBS) -o $@
+
+%.avr.lst: %.avr.elf
+ $(AVR_OBJDUMP) -h -S $< > $@
+
+%.avr.o: %.c
+ $(AVR_COMPILE.c) -o $@ $<
+
+%.avr.simu.o: %.c
+ $(AVR_COMPILE.c) -DSIMU=1 -o $@ $<
+
+%.avr.o: %.S
+ $(AVR_COMPILE.S) -o $@ $<
+
+%.avr.simu.o: %.S
+ $(AVR_COMPILE.S) -DSIMU=1 -o $@ $<
+
+# Dependency checking.
+-include $(AVR_OBJECTS:%.avr.o=%.avr.d)
+-include $(AVR_SIMU_OBJECTS:%.avr.simu.o=%.avr.d)
+
+# Rules for building the .text rom images.
+
+TEXTS := $(AVR_PROGS:%=%.hex) $(AVR_PROGS:%=%.bin) $(AVR_PROGS:%=%.srec)
+
+text: hex
+
+hex: $(AVR_PROGS:%=%.hex)
+bin: $(AVR_PROGS:%=%.bin)
+srec: $(AVR_PROGS:%=%.srec)
+
+%.hex: %.avr.elf
+ $(AVR_OBJCOPY) -j .text -j .data -O ihex $< $@
+
+%.srec: %.avr.elf
+ $(AVR_OBJCOPY) -j .text -j .data -O srec $< $@
+
+%.bin: %.avr.elf
+ $(AVR_OBJCOPY) -j .text -j .data -O binary $< $@
+
+# Rules for building the .eeprom rom images.
+
+EEPROMS := $(AVR_PROGS:%=%_eeprom.hex) $(AVR_PROGS:%=%_eeprom.bin) \
+ $(AVR_PROGS:%=%_eeprom.srec)
+
+eeprom: ehex
+
+ehex: $(AVR_PROGS:%=%_eeprom.hex)
+ebin: $(AVR_PROGS:%=%_eeprom.bin)
+esrec: $(AVR_PROGS:%=%_eeprom.srec)
+
+%_eeprom.hex: %.avr.elf
+ $(AVR_OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
+
+%_eeprom.srec: %.avr.elf
+ $(AVR_OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O srec $< $@
+
+%_eeprom.bin: %.avr.elf
+ $(AVR_OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@
+
+# Cleaning.
+
+clean.avr:
+ 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/digital/avr/make/Makefile.gen b/digital/avr/make/Makefile.gen
new file mode 100644
index 00000000..0fa9b983
--- /dev/null
+++ b/digital/avr/make/Makefile.gen
@@ -0,0 +1,101 @@
+# Makefile.gen - General Makefile.
+
+# Flags
+
+INCLUDES := -I$(BASE) -I$(BASE)/common
+CFLAGS := -g -Wall -W -Wundef -Wno-unused-parameter -Wno-pointer-sign \
+ $(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 simu host
+
+.PHONY: all clean doc
+
+# General rules.
+
+ALL_PROGS := $(PROGS) $(AVR_PROGS) $(HOST_PROGS) $(SIMU_PROGS)
+ALL_SOURCES = $(foreach prog,$(ALL_PROGS),$($(prog)_SOURCES))
+
+# Modules.
+
+MODULES += host
+
+ALL_MODULES := $(sort $(MODULES) \
+ $(foreach prog,$(ALL_PROGS),$($(prog)_MODULES)))
+
+include $(ALL_MODULES:%=$(BASE)/modules/%/Makefile.module)
+
+define MODULES_template
+$(1)_SOURCES += $(foreach module,\
+ $(call defval,$(1)_MODULES,$(MODULES)),\
+ $($(subst /,_,$(module))_SOURCES)\
+)
+endef
+
+$(foreach prog,$(ALL_PROGS),$(eval $(call MODULES_template,$(prog))))
+
+vpath %.c $(ALL_MODULES:%=$(BASE)/modules/%)
+vpath %.S $(ALL_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=%)_TEST_MCU),$$($(1:%.h=%)_TEST_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,$(ALL_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:
+simu:
+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)
+
diff --git a/digital/avr/make/Makefile.host b/digital/avr/make/Makefile.host
new file mode 100644
index 00000000..d2942506
--- /dev/null
+++ b/digital/avr/make/Makefile.host
@@ -0,0 +1,48 @@
+# Makefile.host - Host Makefile.
+#
+# Flags.
+
+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)
+
+# Main rules.
+
+host: exe
+
+.PHONY: host clean.host exe
+
+# General rules.
+
+HOST_PROGS += $(PROGS)
+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 HOST_PROG_template
+$(1).host: $$(patsubst %.c,%.host.o,\
+ $$(filter-out %.avr.c %.avr.S,$$($(1)_SOURCES)))
+endef
+
+$(foreach prog,$(HOST_PROGS),$(eval $(call HOST_PROG_template,$(prog))))
+
+$(HOST_EXES):
+ $(HOST_LINK.o) $^ $(HOST_LDLIBS) -o $@
+
+%.host.o: %.c
+ $(HOST_COMPILE.c) -o $@ $<
+
+# Dependency checking.
+-include $(HOST_OBJECTS:%.host.o=%.host.d)
+
+# Cleaning.
+
+clean.host:
+ rm -f *.host.o *.host.d $(HOST_EXES)
+