From f941dd545114b7c236016b8dda28d26650ccf94c Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Sat, 9 Jul 2011 20:17:00 +0200 Subject: [PATCH] Optimize Makefiles (add auto-dependencies), and convert basic/ into a lib like the other subdirs --- firmware/.gitignore | 1 + firmware/Makefile | 53 ++++++++++++++++-------------------- firmware/Makefile.inc | 1 - firmware/Makefile.util | 21 ++++++++++++++ firmware/basic/Makefile | 31 +++++++++++++++++++++ firmware/filesystem/Makefile | 17 ++---------- firmware/funk/Makefile | 17 ++---------- firmware/usb/Makefile | 15 ++-------- 8 files changed, 83 insertions(+), 73 deletions(-) create mode 100644 firmware/Makefile.util create mode 100644 firmware/basic/Makefile diff --git a/firmware/.gitignore b/firmware/.gitignore index b6e09dd..ca10624 100644 --- a/firmware/.gitignore +++ b/firmware/.gitignore @@ -3,3 +3,4 @@ firmware.elf lpc1xxx/memory.ld applications/wrapper.c lcd/allfonts.h +Makefile.dep diff --git a/firmware/Makefile b/firmware/Makefile index 2f5e009..4d0f531 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -1,15 +1,21 @@ VPATH = -OBJS = main.o +OBJS = +LIBS = ########################################################################## # Project-specific files ########################################################################## VPATH += -OBJS += -OBJS += basic/basic.o basic/reinvoke_isp.o basic/delayms.o basic/voltage.o -OBJS += basic/keyin.o basic/uuid.o basic/crc.o -LIBS += core/libcore.a lcd/liblcd.a applications/libapp.a filesystem/libfat.a usb/libusb.a funk/libfunk.a +OBJS += main.o + +LIBS += lcd/liblcd.a +LIBS += basic/libbasic.a +LIBS += core/libcore.a +LIBS += applications/libapp.a +LIBS += filesystem/libfat.a +LIBS += usb/libusb.a +LIBS += funk/libfunk.a ########################################################################## # GNU GCC compiler flags @@ -32,9 +38,12 @@ LDLIBS += -Lfunk -lfunk LDLIBS += -Llcd -llcd LDLIBS += -Lusb -lusb LDLIBS += -Lfilesystem -lfat +LDLIBS += -Lbasic -lbasic LDLIBS += -Lcore -lcore OCFLAGS = --strip-unneeded +SUBDIRS?= $(foreach lib,$(LIBS),$(dir $(lib))) + LD_PATH = lpc1xxx LD_SCRIPT = $(LD_PATH)/linkscript.ld LD_TEMP = $(LD_PATH)/memory.ld @@ -51,36 +60,22 @@ loadables: $(OUTFILE).bin clean: rm -f $(OBJS) $(LD_TEMP) $(OUTFILE).elf $(OUTFILE).bin $(OUTFILE).hex - @cd core && $(MAKE) clean - @cd ../tools/bootloader && $(MAKE) clean - @cd lcd && $(MAKE) clean - @cd applications && $(MAKE) clean - @cd filesystem && $(MAKE) clean - @cd usb && $(MAKE) clean - @cd loadable && $(MAKE) clean + for dir in $(SUBDIRS); do \ + $(MAKE) --no-print-directory -C $$dir clean; \ + done ### Internal targets %.o : %.c $(CC) $(CFLAGS) -o $@ $< -core/libcore.a: core/projectconfig.h - cd core && $(MAKE) ROOT_PATH=../$(ROOT_PATH) +### Make all libraries... +.PHONY: subdirs $(SUBDIRS) -lcd/liblcd.a lcd/render.o lcd/display.o: - cd lcd && $(MAKE) ROOT_PATH=../$(ROOT_PATH) +subdirs: $(SUBDIRS) -applications/libapp.a: - cd applications && $(MAKE) ROOT_PATH=../$(ROOT_PATH) - -filesystem/libfat.a: - cd filesystem && $(MAKE) ROOT_PATH=../$(ROOT_PATH) - -usb/libusb.a: - cd usb && $(MAKE) ROOT_PATH=../$(ROOT_PATH) - -funk/libfunk.a: - cd funk && $(MAKE) ROOT_PATH=../$(ROOT_PATH) +$(SUBDIRS): + $(MAKE) ROOT_PATH=../$(ROOT_PATH) --no-print-directory -C $@ ../tools/bootloader/lpcfix: cd ../tools/bootloader && $(MAKE) @@ -93,7 +88,7 @@ $(LD_TEMP): -@echo "}" >> $(LD_TEMP) -@echo "INCLUDE $(LD_SCRIPT)" >> $(LD_TEMP) -$(OUTFILE).elf: $(OBJS) $(SYS_OBJS) $(LIBS) $(LPCFIX) $(LD_TEMP) +$(OUTFILE).elf: $(OBJS) $(SYS_OBJS) $(SUBDIRS) $(LPCFIX) $(LD_TEMP) $(CC) $(LDFLAGS) -T $(LD_TEMP) -o $(OUTFILE).elf $(OBJS) $(LDLIBS) -@echo "" $(SIZE) $(OUTFILE).elf @@ -104,5 +99,5 @@ $(OUTFILE).elf: $(OBJS) $(SYS_OBJS) $(LIBS) $(LPCFIX) $(LD_TEMP) -@echo "" $(LPCFIX) -c $@ -.PHONY: $(LD_TEMP) lcd/liblcd.a applications/libapp.a filesystem/libfat.a usb/libusb.a funk/libfunk.a +.PHONY: $(LD_TEMP) diff --git a/firmware/Makefile.inc b/firmware/Makefile.inc index 1a6ddd2..2c06605 100644 --- a/firmware/Makefile.inc +++ b/firmware/Makefile.inc @@ -42,4 +42,3 @@ CPU_TYPE = cortex-$(CORTEX_TYPE) CFLAGS = -std=c99 -c -g -Os $(INCLUDE_PATHS) -Wall -mthumb -ffunction-sections -fdata-sections -fmessage-length=0 -mcpu=$(CPU_TYPE) -DTARGET=$(TARGET) -DRAMCODE=$(RAMCODE) -fno-builtin LDFLAGS = -nostartfiles - diff --git a/firmware/Makefile.util b/firmware/Makefile.util new file mode 100644 index 0000000..6b198ff --- /dev/null +++ b/firmware/Makefile.util @@ -0,0 +1,21 @@ +LIBFILE?=lib$(LIBNAME).a +SRCS?= $(foreach mod,$(OBJS),$(subst .o,.c,$(mod))) +DEPFILE?=Makefile.dep + +all: $(LIBFILE) + +$(LIBFILE): $(OBJS) + $(AR) rcs $@ $(OBJS) + +%.o : %.c + $(CC) $(CFLAGS) -o $@ $< + +clean: + rm -f $(OBJS) $(LIBFILE) $(CLEANFILES) + +depend: + @$(CC) $(CFLAGS) -MM -MF Makefile.dep $(SRCS) + +include $(DEPFILE) + +$(DEPFILE): depend diff --git a/firmware/basic/Makefile b/firmware/basic/Makefile new file mode 100644 index 0000000..728d1ff --- /dev/null +++ b/firmware/basic/Makefile @@ -0,0 +1,31 @@ +########################################################################## +# User configuration and firmware specific object files +########################################################################## + +OBJS = + +OBJS += basic.o +OBJS += reinvoke_isp.o +OBJS += delayms.o +OBJS += voltage.o +OBJS += keyin.o +OBJS += uuid.o +OBJS += crc.o + +LIBNAME=basic + +########################################################################## +# GNU GCC compiler flags +########################################################################## +ROOT_PATH?= .. +INCLUDE_PATHS = -I$(ROOT_PATH) -I../core -I. + +include $(ROOT_PATH)/Makefile.inc + +CFLAGS+= + +########################################################################## +# Actual work +########################################################################## + +include $(ROOT_PATH)/Makefile.util diff --git a/firmware/filesystem/Makefile b/firmware/filesystem/Makefile index dd584dd..d35cdb3 100644 --- a/firmware/filesystem/Makefile +++ b/firmware/filesystem/Makefile @@ -20,21 +20,8 @@ INCLUDE_PATHS = -I$(ROOT_PATH) -I../core -I. include $(ROOT_PATH)/Makefile.inc -LIBFILE=lib$(LIBNAME).a ########################################################################## -# Compiler settings, parameters and flags +# Actual work ########################################################################## -all: $(LIBFILE) - -$(LIBFILE): $(OBJS) - $(AR) rcs $@ $(OBJS) - -%.o : %.c - $(CC) $(CFLAGS) -o $@ $< - -clean: - rm -f $(OBJS) $(LIBFILE) - -ff.o: ff.c ffconf.h diskio.h ff.h integer.h - +include $(ROOT_PATH)/Makefile.util diff --git a/firmware/funk/Makefile b/firmware/funk/Makefile index 88dbfc0..6946c13 100644 --- a/firmware/funk/Makefile +++ b/firmware/funk/Makefile @@ -16,21 +16,8 @@ INCLUDE_PATHS = -I$(ROOT_PATH) -I../core -I. include $(ROOT_PATH)/Makefile.inc -LIBFILE=lib$(LIBNAME).a ########################################################################## -# Compiler settings, parameters and flags +# Actual work ########################################################################## -all: $(LIBFILE) - -$(LIBFILE): $(OBJS) - $(AR) rcs $@ $(OBJS) - -%.o : %.c - $(CC) $(CFLAGS) -o $@ $< - -clean: - rm -f $(OBJS) $(LIBFILE) - -nrf24l01p.o: nrf24l01p.c nrf24l01p.h - +include $(ROOT_PATH)/Makefile.util diff --git a/firmware/usb/Makefile b/firmware/usb/Makefile index d54ddf3..68d0a58 100644 --- a/firmware/usb/Makefile +++ b/firmware/usb/Makefile @@ -18,19 +18,8 @@ INCLUDE_PATHS = -I$(ROOT_PATH) -I../core -I. include $(ROOT_PATH)/Makefile.inc -LIBFILE=lib$(LIBNAME).a ########################################################################## -# Compiler settings, parameters and flags +# Actual work ########################################################################## -all: $(LIBFILE) - -$(LIBFILE): $(OBJS) - $(AR) rcs $@ $(OBJS) - -%.o : %.c - $(CC) $(CFLAGS) -o $@ $< - -clean: - rm -f $(OBJS) $(LIBFILE) - +include $(ROOT_PATH)/Makefile.util