From cdd573583978a3800b24d868d32604a427b669a2 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 24 May 2012 21:55:14 +0000 Subject: moved lib code to lib dir updated Makefile to work it's funky magic git-svn-id: https://svn.spreadspace.org/avr/trunk@29 aa12f405-d877-488e-9caf-2d797e2a1cc7 --- include.mk | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'include.mk') diff --git a/include.mk b/include.mk index ce21fd7..92d6a0d 100644 --- a/include.mk +++ b/include.mk @@ -105,6 +105,7 @@ endif CC = avr-gcc OBJCOPY = avr-objcopy +LIB_DIR = ../lib DFU = dfu-programmer teensy = teensy_loader_cli @@ -123,6 +124,7 @@ CFLAGS += -fpack-struct CFLAGS += -fshort-enums CFLAGS += -Wall CFLAGS += -Wstrict-prototypes +CFLAGS += -I$(LIB_DIR) CFLAGS += -DF_CPU=$(F_CPU)UL CFLAGS += -D__BOARD_$(BOARD_TYPE)__ @@ -132,6 +134,10 @@ LDFLAGS += SRC := $(OBJ:%.o=%.c) +OBJ_LIB := $(LIBS:%=lib-%.o) +SRC_LIB := $(LIBS:%=$(LIB_DIR)/%.c) +DEP_LIB := $(LIBS:%=lib-%.d) + .PHONY: clean program erase flash reset run ELFFILE := $(NAME).elf @@ -139,21 +145,31 @@ HEXFILE := $(NAME).hex all: $(HEXFILE) +lib-%.d: $(LIB_DIR)/%.c + @set -e; rm -f $@; \ + $(CC) -MM $(CFLAGS) $< > $@.$$$$; \ + sed 's,\($*\)\.o[ :]*,lib-\1.o $@ : ,g' < $@.$$$$ > $@; \ + rm -f $@.$$$$; echo '(re)building $@' + %.d: %.c @set -e; rm -f $@; \ $(CC) -MM $(CFLAGS) $< > $@.$$$$; \ sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ rm -f $@.$$$$; echo '(re)building $@' -ifneq ($(MAKECMDGOALS),distclean) +ifneq ($(MAKECMDGOALS),clean) -include $(SRC:%.c=%.d) +-include $(DEP_LIB) endif +lib-%.o: $(LIB_DIR)/%.c + $(CC) $(CFLAGS) -o $@ -c $< + %.o: %.c - $(CC) $(CFLAGS) -c $< + $(CC) $(CFLAGS) -o $@ -c $< -$(ELFFILE): $(OBJ) - $(CC) $(OBJ) -o $@ $(LDFLAGS) +$(ELFFILE): $(OBJ) $(OBJ_LIB) + $(CC) $(OBJ) $(OBJ_LIB) -o $@ $(LDFLAGS) $(HEXFILE): $(ELFFILE) $(OBJCOPY) -O ihex -R .eeprom -R .fuse -R .lock -R .signature $< $@ -- cgit v1.2.3