summaryrefslogtreecommitdiff
path: root/n/avr
diff options
context:
space:
mode:
authorschodet2005-06-26 23:31:42 +0000
committerschodet2005-06-26 23:31:42 +0000
commitd237184f11ebdf3147e03bd297f16797a8e990ca (patch)
tree65e5e0524472370756b6f6a8245728ecbab2024b /n/avr
parent21356146e4d51bdcc5d409fa167bd84af6b0c706 (diff)
Ajout du Makefile pour les modules AVR.
Diffstat (limited to 'n/avr')
-rw-r--r--n/avr/make/Makefile.avr92
-rw-r--r--n/avr/make/Makefile.gen58
-rw-r--r--n/avr/make/Makefile.host45
3 files changed, 195 insertions, 0 deletions
diff --git a/n/avr/make/Makefile.avr b/n/avr/make/Makefile.avr
new file mode 100644
index 0000000..ace4331
--- /dev/null
+++ b/n/avr/make/Makefile.avr
@@ -0,0 +1,92 @@
+# Makefile.avr - AVR part Makefile.
+#
+# Flags. {{{1
+
+AVR_CFLAGS = $(CFLAGS) -mmcu=$(AVR_MCU)
+AVR_CPPFLAGS = $(CPPFLAGS) $(AVR_DEFS)
+AVR_LDFLAGS = $(LDFLAGS)
+
+AVR_CC = avr-gcc
+AVR_OBJCOPY = avr-objcopy
+AVR_OBJDUMP = avr-objdump
+AVR_COMPILE.c = $(AVR_CC) $(AVR_CFLAGS) $(AVR_CPPFLAGS) -c
+AVR_LINK.o = $(AVR_CC) $(AVR_CFLAGS) $(AVR_LDFLAGS)
+
+# Main rules. {{{1
+
+avr: elf lst hex
+ echo $(AVR_SOURCES)
+
+.PHONY: avr clean.avr elf lst text hex srec bin eeprom ehex esrec ebin
+
+# General rules. {{{1
+
+AVR_ELFS = $(PROGS:%=%.avr.elf)
+AVR_SOURCES = $(filter-out %.host.c,$(SOURCES))
+AVR_OBJECTS = $(AVR_SOURCES:%.c=%.avr.o)
+
+elf: $(AVR_ELFS)
+lst: $(PROGS:%=%.avr.lst)
+
+define AVR_PROG_template
+$(1).avr.elf: $$(patsubst %.c,%.avr.o,$$(filter-out %.host.c,$$($(1)_SOURCES)))
+endef
+
+$(foreach prog,$(PROGS),$(eval $(call AVR_PROG_template,$(prog))))
+
+$(AVR_ELFS):
+ $(AVR_LINK.o) $^ $(AVR_LDLIBS) -o $@
+
+%.avr.lst: %.avr.elf
+ $(AVR_OBJDUMP) -h -S $< > $@
+
+%.avr.o: %.c
+ $(AVR_COMPILE.c) -o $@ $^
+
+# Dependency checking.
+-include $(AVR_OBJECTS:%.avr.o=%.avr.d)
+
+# Rules for building the .text rom images. {{{1
+
+TEXTS = $(PROGS:%=%.hex) $(PROGS:%=%.bin) $(PROGS:%=%.srec)
+
+text: hex
+
+hex: $(PROGS:%=%.hex)
+bin: $(PROGS:%=%.bin)
+srec: $(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. {{{1
+
+EEPROMS = $(PROGS:%=%_eeprom.hex) $(PROGS:%=%_eeprom.bin) \
+ $(PROGS:%=%_eeprom.srec)
+
+eeprom: ehex
+
+ehex: $(PROGS:%=%_eeprom.hex)
+ebin: $(PROGS:%=%_eeprom.bin)
+esrec: $(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. {{{1
+
+clean.avr:
+ rm -f *.avr.o *.avr.d $(AVR_ELFS) *.avr.lst *.avr.map $(TEXTS) $(EEPROMS)
+
diff --git a/n/avr/make/Makefile.gen b/n/avr/make/Makefile.gen
new file mode 100644
index 0000000..d6fdcca
--- /dev/null
+++ b/n/avr/make/Makefile.gen
@@ -0,0 +1,58 @@
+# Makefile.gen - General Makefile.
+
+# Flags {{{1
+
+INCLUDES = -Imodules
+OPTIMIZE =
+CFLAGS = -g -Wall $(OPTIMIZE)
+DEFS =
+CPPFLAGS = $(DEFS) $(INCLUDES) -MMD \
+ $(if $(CONFIGFILE),$(CONFIGFILE:%=-include %))
+LDFLAGS =
+
+# Main rules. {{{1
+
+all: avr host
+
+.PHONY: all clean doc
+
+# General rules. {{{1
+
+SOURCES = $(foreach prog,$(PROGS),$($(prog)_SOURCES))
+
+ifneq (,$(filter-out %.c,$(SOURCES)))
+$(error Sources should be c files)
+endif
+
+# Modules. {{{1
+
+include $(MODULES:%=$(BASE)/modules/%/Makefile.module)
+
+define MODULES_template
+$(1)_SOURCES += $(foreach module,$(MODULES),$($(module)_SOURCES))
+endef
+
+$(foreach prog,$(PROGS),$(eval $(call MODULES_template,$(prog))))
+
+vpath %.c $(MODULES:%=$(BASE)/modules/%)
+
+# Include other Makefiles. {{{1
+
+include $(BASE)/make/Makefile.avr
+include $(BASE)/make/Makefile.host
+
+# Rules for building the doc. {{{1
+
+doc: $(DOC)
+
+%.html: %.txt %.exd
+ aft $<
+
+%.exd: $(EXTRACTDOC)
+ test -n "$^" && extractdoc $^ > $@ || true
+
+# Cleanning. {{{1
+
+clean: clean.avr clean.host
+ rm -f *.bak *~ $(DOC) *.exd $(EXTRA_CLEAN_FILES)
+
diff --git a/n/avr/make/Makefile.host b/n/avr/make/Makefile.host
new file mode 100644
index 0000000..c50c83b
--- /dev/null
+++ b/n/avr/make/Makefile.host
@@ -0,0 +1,45 @@
+# Makefile.host - Host Makefile.
+#
+# Flags. {{{1
+
+HOST_CFLAGS = $(CFLAGS)
+HOST_CPPFLAGS = $(CPPFLAGS) $(HOST_DEFS) -DHOST=1
+HOST_LDFLAGS = $(LDFLAGS)
+
+HOST_COMPILE.c = $(CC) $(HOST_CFLAGS) $(HOST_CPPFLAGS) -c
+HOST_LINK.o = $(CC) $(HOST_CFLAGS) $(HOST_LDFLAGS)
+
+# Main rules. {{{1
+
+host: exe
+
+.PHONY: host clean.host exe
+
+# General rules. {{{1
+
+HOST_EXES = $(PROGS:%=%.host)
+HOST_SOURCES = $(filter-out %.avr.c,$(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,$$($(1)_SOURCES)))
+endef
+
+$(foreach prog,$(PROGS),$(eval $(call AVR_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. {{{1
+
+clean.host:
+ rm -f *.host.o *.host.d $(HOST_EXES)
+