summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--n/asserv/src/Makefile13
-rw-r--r--n/asserv/src/Makefile.avr54
2 files changed, 42 insertions, 25 deletions
diff --git a/n/asserv/src/Makefile b/n/asserv/src/Makefile
index 474512c..1ba351e 100644
--- a/n/asserv/src/Makefile
+++ b/n/asserv/src/Makefile
@@ -1,7 +1,6 @@
-#PROGS = test_pwm
-#SOURCES = test_pwm.c pwm.c
-PROGS = asserv
-SOURCES = motor.c main.c
+PROGS = test_pwm asserv
+asserv_OBJECTS = motor.o main.o rs232.o proto.o
+test_pwm_OBJECTS = test_pwm.o pwm.o rs232.o proto.o
DOC =
EXTRACTDOC =
MODULES = n/avr/rs232 n/avr/proto n/avr/utils
@@ -13,6 +12,10 @@ MCU_TARGET = atmega128
OPTIMIZE = -O2
DEFS =
-LIBS =
+LDLIBS =
include Makefile.avr
+
+asserv.elf: $(asserv_OBJECTS)
+
+test_pwm.elf: $(test_pwm_OBJECTS)
diff --git a/n/asserv/src/Makefile.avr b/n/asserv/src/Makefile.avr
index 01c9b7b..325be3f 100644
--- a/n/asserv/src/Makefile.avr
+++ b/n/asserv/src/Makefile.avr
@@ -1,52 +1,66 @@
# Flags. {{{1
-CC = avr-gcc
-
-CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) \
- $(if $(CONFIGFILE), $(CONFIGFILE:%=-include %))
-CPPFLAGS = $(DEFS) -Imodules
+CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET)
+CPPFLAGS = $(DEFS) -MMD $(INCLUDES) \
+ $(if $(CONFIGFILE), $(CONFIGFILE:%=-include %))
+INCLUDES = -Imodules
LDFLAGS =
+CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
# Main rules. {{{1
-CSOURCES = $(filter %.c, $(SOURCES))
-SSOURCES = $(filter %.s, $(SOURCES))
-OBJECTS = $(CSOURCES:%.c=%.o) $(SSOURCES:%.s=%.o)
-ELFS = $(PROGS:%=%.elf)
-
all: elf lst hex
.PHONY: all clean elf lst doc text hex srec bin eeprom ehex esrec ebin
# Rules for modules. {{{1
-MODULESFILES = $(MODULES:%=modules/%/Makefile.module)
+VPATH = $(MODULES:%=modules/%)
-include $(MODULESFILES)
+modules_checkout: modules_co
-SOURCES += $(MODULESSOURCES)
+modules_co: $(MODULES:%=modules_co.%)
-$(MODULESFILES):
+$(MODULES:%=modules_co.%):
mkdir -p modules
- cd modules && cvs co $(@:modules/%/Makefile.module=%)
- test -f $@
+ cd modules && cvs co $(@:modules_co.%=%)
+
+modules_update: modules_up
+
+modules_up: $(MODULES:%=modules_up.%)
+
+$(MODULES:%=modules_up.%):
+ cd modules/$(@:modules_up.%=%) && cvs up
# General rules. {{{1
-elf: $(PROGS:%=%.elf)
+ELFS = $(PROGS:%=%.elf)
+OBJECTS = $(filter %.o,$(foreach prog,$(PROGS),$($(prog)_OBJECTS)))
+
+elf: $(ELFS)
lst: $(PROGS:%=%.lst)
-$(PROGS:%=%.elf): $(OBJECTS)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
+# Great piece of rules which only works in make 3.80+.
+# define PROG_template
+# $(1).elf: $$($(1)_OBJECTS)
+# endef
+#
+# $(foreach prog,$(PROGS),$(eval $(call PROG_template,$(prog))))
+
+$(ELFS):
+ $(LINK.o) $^ $(LDLIBS) -o $@
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
+# Dependency checking.
+-include $(OBJECTS:%.o=%.d)
+
clean:
- rm -f *.o $(OBJECTS) $(PROGS:%=%.elf) *.lst *.map *.bak *~
+ rm -f *.o *.d $(ELFS) *.lst *.map *.bak *~
rm -f $(DOC) *.exd $(EXTRA_CLEAN_FILES) $(TEXTS) $(EEPROMS)
# Rules for building the doc. {{{1