summaryrefslogtreecommitdiffstats
path: root/pressure_control/firmware/Makefile
diff options
context:
space:
mode:
authorMichael Buesch <mb@bu3sch.de>2010-01-18 02:00:29 +0100
committerMichael Buesch <mb@bu3sch.de>2010-01-18 02:00:29 +0100
commit65447104d64adb99db9c862ed501e930d091fe15 (patch)
treea2a9b0c6816fe9d1074548462bae2a72f9e4fde9 /pressure_control/firmware/Makefile
parentf6bf6e1072f566c5b57ae1bf4a65c4390e0896f3 (diff)
downloadcnc-65447104d64adb99db9c862ed501e930d091fe15.tar.xz
cnc-65447104d64adb99db9c862ed501e930d091fe15.zip
pressure_control: Implement auto-deps
Signed-off-by: Michael Buesch <mb@bu3sch.de>
Diffstat (limited to 'pressure_control/firmware/Makefile')
-rw-r--r--pressure_control/firmware/Makefile38
1 files changed, 27 insertions, 11 deletions
diff --git a/pressure_control/firmware/Makefile b/pressure_control/firmware/Makefile
index cfb0105..5966490 100644
--- a/pressure_control/firmware/Makefile
+++ b/pressure_control/firmware/Makefile
@@ -1,3 +1,4 @@
+# The architecture configuration
ARCH = atmega8
AVRDUDE_ARCH = m8
AVRDUDE = avrdude
@@ -5,17 +6,21 @@ AVRDUDE_SPEED = 1
PROGRAMMER = avrisp2
PROGPORT = usb
+# The toolchain definitions
CC = avr-gcc
OBJCOPY = avr-objcopy
SIZE = avr-size
+READELF = avr-readelf
SPARSE = sparse
V = @ # Verbose build: make V=1
C = 0 # Sparsechecker build: make C=1
Q = $(V:1=)
QUIET_CC = $(Q:@=@echo ' CC '$@;)$(CC)
+QUIET_DEPEND = $(Q:@=@echo ' DEPEND '$@;)$(CC)
QUIET_OBJCOPY = $(Q:@=@echo ' OBJCOPY '$@;)$(OBJCOPY)
QUIET_SIZE = $(Q:@=@echo ' SIZE '$@;)$(SIZE)
+QUIET_READELF = $(Q:@=@echo ' READELF '$@;)$(READELF)
ifeq ($(C),1)
QUIET_SPARSE = $(Q:@=@echo ' SPARSE '$@;)$(SPARSE)
else
@@ -29,7 +34,7 @@ SPARSEFLAGS = $(CFLAGS) -I "/usr/lib/avr/include" -D__AVR_ARCH__=4 \
-Dexternally_visible=dllexport
-OBJECTS = main.o util.o valves.o sensor.o remote.o
+SRCS = main.c util.c valves.c sensor.c remote.c
NAME = pressure_control
BIN = $(NAME).bin
@@ -37,17 +42,27 @@ HEX = $(NAME).hex
EEP = $(NAME).eep.hex
FUSES = $(NAME).fuses.bin
-all: $(HEX) $(FUSES)
+.SUFFIXES:
+.PHONY: all avrdude install_flash install_eeprom install reset writefuse clean distclean
+.DEFAULT_GOAL := all
-main.o: util.h calibration.h valves.h sensor.h remote.h main.h
+DEPS = $(sort $(patsubst %.c,dep/%.d,$(1)))
+OBJS = $(sort $(patsubst %.c,obj/%.o,$(1)))
-util.o: util.h calibration.h
+# Generate dependencies
+$(call DEPS,$(SRCS)): dep/%.d: %.c
+ @mkdir -p $(dir $@)
+ $(QUIET_DEPEND) -o $@.tmp -MM -MG -MT "$@ $(patsubst dep/%.d,obj/%.o,$@)" $(CFLAGS) $< && mv -f $@.tmp $@
-valves.o: util.h valves.h main.h
+-include $(call DEPS,$(SRCS))
-sensor.o: util.h sensor.h
+# Generate object files
+$(call OBJS,$(SRCS)): obj/%.o:
+ @mkdir -p $(dir $@)
+ $(QUIET_SPARSE) $(SPARSEFLAGS) $<
+ $(QUIET_CC) -o $@ -c $(CFLAGS) $<
-remote.o: util.h remote.h calibration.h main.h valves.h
+all: $(HEX) $(FUSES)
%.s: %.c
$(QUIET_CC) $(CFLAGS) -S $*.c
@@ -56,14 +71,15 @@ remote.o: util.h remote.h calibration.h main.h valves.h
$(QUIET_SPARSE) $(SPARSEFLAGS) $<
$(QUIET_CC) -o $@ -c $(CFLAGS) $<
-$(BIN): $(OBJECTS)
- $(QUIET_CC) $(CFLAGS) -o $(BIN) $(OBJECTS) $(LDFLAGS)
+$(BIN): $(call OBJS,$(SRCS))
+ $(QUIET_CC) $(CFLAGS) -o $(BIN) $(call OBJS,$(SRCS)) $(LDFLAGS)
$(HEX): $(BIN)
$(QUIET_OBJCOPY) -R.eeprom -R.fuse -O ihex $(BIN) $(HEX)
$(QUIET_OBJCOPY) -j.eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O ihex $(BIN) $(EEP)
$(QUIET_SIZE) $(BIN)
+ $(QUIET_READELF) -S $(BIN) | egrep '(Name|text|eeprom|data|bss)'
avrdude:
$(AVRDUDE) -B $(AVRDUDE_SPEED) -p $(AVRDUDE_ARCH) \
@@ -97,10 +113,10 @@ writefuses: $(FUSES)
-U hfuse:w:$$(hexdump -e '1/1 "0x%02X "' $(FUSES) | cut -d ' ' -f 2):m
clean:
- -rm -f *~ *.o $(BIN)
+ rm -Rf *~ *.o obj dep $(BIN)
distclean: clean
- -rm -f *.s $(HEX) $(EEP) $(FUSES)
+ rm -f *.s $(HEX) $(EEP) $(FUSES)
help:
@echo "Makefile"
bues.ch cgit interface