Permalink
Browse files

Makefiles: build into a dedicated directory.

This makes finding source files for editing quite a bit simpler.
  • Loading branch information...
1 parent 64072df commit 73658afc337832fe99f239db2d882e22cf9b4abd @Traumflug committed Jan 3, 2013
Showing with 24 additions and 31 deletions.
  1. +1 −13 .gitignore
  2. +1 −1 Makefile-AVR
  3. +22 −17 Makefile-common
View
@@ -1,18 +1,6 @@
-*.o
-*.elf
-*.lst
-*.map
-*.sym
-*.lss
-*.eep
-*.srec
-*.bin
*.hex
-*.al
-*.i
-*.s
+build
*~
-.depend
temporal.png
temporal_data
View
@@ -137,7 +137,7 @@ LIBS = -lm
program: $(PROGRAM).hex config.h
$(UPLOADER) $(UPLOADER_FLAGS) -U flash:w:$^
-size: $(PROGRAM).elf
+size: $(BUILDDIR)/$(PROGRAM).elf
@echo " SIZES ATmega... '168 '328(P) '644(P) '1280"
@$(OBJDUMP) -h $^ | perl -MPOSIX -ne '/.(text)\s+([0-9a-f]+)/ && do { $$a += eval "0x$$2" }; END { printf " FLASH : %5d bytes %3d%% %3d%% %3d%% %3d%%\n", $$a, ceil($$a * 100 / (14 * 1024)), ceil($$a * 100 / (30 * 1024)),ceil($$a * 100 / (62 * 1024)), ceil($$a * 100 / (126 * 1024)) }'
@$(OBJDUMP) -h $^ | perl -MPOSIX -ne '/.(data|bss)\s+([0-9a-f]+)/ && do { $$a += eval "0x$$2" }; END { printf " RAM : %5d bytes %3d%% %3d%% %3d%% %3d%%\n", $$a, ceil($$a * 100 / (1 * 1024)), ceil($$a * 100 / (2 * 1024)),ceil($$a * 100 / (4 * 1024)), ceil($$a * 100 / (8 * 1024)) }'
View
@@ -31,9 +31,12 @@
# #
##############################################################################
-CFLAGS += -save-temps
+BUILDDIR = build
+DEPEND = $(BUILDDIR)/depend
-OBJ = $(patsubst %.c,%.o,$(SOURCES))
+CFLAGS += -save-temps=obj
+
+OBJ = $(patsubst %.c,$(BUILDDIR)/%.o,$(SOURCES))
CC = $(TOOLCHAIN)gcc
OBJDUMP = $(TOOLCHAIN)objdump
@@ -43,10 +46,11 @@ OBJCOPY = $(TOOLCHAIN)objcopy
.PHONY: all clean doc functionsbysize depend
.PRECIOUS: %.o %.elf
-all: config.h $(PROGRAM).hex $(PROGRAM).lst $(PROGRAM).sym size
+all: config.h $(BUILDDIR)
+all: $(PROGRAM).hex $(BUILDDIR)/$(PROGRAM).lst $(BUILDDIR)/$(PROGRAM).sym size
clean:
- rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex *.al *.i *.s *~ .depend
+ rm -rf $(BUILDDIR) *.hex *~
config.h: config.default.h
@echo "config.default.h is more recent than config.h. You likely want to"
@@ -61,36 +65,37 @@ doc: Doxyfile *.c *.h
functionsbysize: $(OBJ)
@$(OBJDUMP) -h $^ | grep '\.text\.' | perl -ne '/\.text\.(\S+)\s+([0-9a-f]+)/ && printf "%u\t%s\n", eval("0x$$2"), $$1;' | sort -n
-depend: .depend
- @true
+$(BUILDDIR):
+ mkdir $(BUILDDIR)
-.depend: $(SOURCES)
- rm -f .depend
- $(CC) $(CFLAGS) -MM $^ > .depend;
+$(DEPEND): $(SOURCES)
+ rm -f $(DEPEND)
+ mkdir -p $(BUILDDIR)
+ $(CC) $(CFLAGS) -MM $^ > $(DEPEND)
# pull in dependency info
--include .depend
+-include $(DEPEND)
-%.o: %.c config.h Makefile
+$(BUILDDIR)/%.o: %.c config.h Makefile Makefile-common
@echo " CC $@"
- @$(CC) -c $(CFLAGS) -Wa,-adhlns=$(<:.c=.al) -o $@ $(subst .o,.c,$@)
+ @$(CC) -c $(CFLAGS) -Wa,-adhlns=$(@:.o=.al) -o $@ $<
-%.elf: $(OBJ)
+$(BUILDDIR)/%.elf: $(OBJ)
@echo " LINK $@"
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
-%.lst: %.elf
+$(BUILDDIR)/%.lst: $(BUILDDIR)/%.elf
@echo " OBJDUMP $@"
@$(OBJDUMP) -h -S $< > $@
-%.hex: %.elf
+%.hex: $(BUILDDIR)/%.elf
@echo " OBJCOPY $@"
@$(OBJCOPY) -j .text -j .data -O ihex -R .eeprom -R .fuse -R .lock $< $@
-%.bin: %.elf
+$(BUILDDIR)/%.bin: $(BUILDDIR)/%.elf
@echo " OBJCOPY $@"
@$(OBJCOPY) -j .text -j .data -O binary $< $@
-%.sym: %.elf
+$(BUILDDIR)/%.sym: $(BUILDDIR)/%.elf
@echo " SYM $@"
@$(OBJDUMP) -t $< | perl -ne 'BEGIN { printf " ADDR NAME SIZE\n"; } /([0-9a-f]+)\s+(\w+)\s+O\s+\.(bss|data)\s+([0-9a-f]+)\s+(\w+)/ && printf "0x%04x %-20s +%d\n", eval("0x$$1") & 0xFFFF, $$5, eval("0x$$4")' | sort -k1 > $@

0 comments on commit 73658af

Please sign in to comment.