From 1ad44b65718a7be81bda7a911a1e84d08dc4fb00 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 3 Feb 2012 12:25:55 +0100 Subject: [PATCH] software: dependencies the Werner way --- software/include.mak | 20 ++++++++++++++++---- software/libbase/Makefile | 5 ++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/software/include.mak b/software/include.mak index b0a774a1..f417bba0 100644 --- a/software/include.mak +++ b/software/include.mak @@ -7,14 +7,14 @@ AR_normal := $(CROSS_COMPILER)ar AS_normal := $(CROSS_COMPILER)as LD_normal := $(CROSS_COMPILER)ld OBJCOPY_normal := $(CROSS_COMPILER)objcopy -RANLIB_normal := $(CROSS_COMPILER)ranlib +RANLIB_normal := $(CROSS_COMPILER)ranlib CC_quiet = @echo " CC " $@ && $(CROSS_COMPILER)gcc AR_quiet = @echo " AR " $@ && $(CROSS_COMPILER)ar AS_quiet = @echo " AS " $@ && $(CROSS_COMPILER)as LD_quiet = @echo " LD " $@ && $(CROSS_COMPILER)ld OBJCOPY_quiet = @echo " OBJCOPY " $@ && $(CROSS_COMPILER)objcopy -RANLIB_quiet = @echo " RANLIB " $@ && $(CROSS_COMPILER)ranlib +RANLIB_quiet = @echo " RANLIB " $@ && $(CROSS_COMPILER)ranlib ifeq ($(V),1) CC = $(CC_normal) @@ -22,14 +22,14 @@ ifeq ($(V),1) AS = $(AS_normal) LD = $(LD_normal) OBJCOPY = $(OBJCOPY_normal) - RANLIB = $(RANLIB_normal) + RANLIB = $(RANLIB_normal) else CC = $(CC_quiet) AR = $(AR_quiet) AS = $(AS_quiet) LD = $(LD_quiet) OBJCOPY = $(OBJCOPY_quiet) - RANLIB = $(RANLIB_quiet) + RANLIB = $(RANLIB_quiet) endif # Toolchain options @@ -43,3 +43,15 @@ CFLAGS = -O9 -Wall -Wstrict-prototypes -Wold-style-definition -Wshadow \ -msign-extend-enabled -fno-builtin -fsigned-char \ -fsingle-precision-constant $(INCLUDES) LDFLAGS = -nostdlib -nodefaultlibs + +# compile and generate dependencies, based on +# http://scottmcpeak.com/autodepend/autodepend.html + +%.o: %.c + $(CC) -c $(CFLAGS) $*.c -o $*.o + @$(CC_normal) -MM $(CFLAGS) $*.c > $*.d + @mv -f $*.d $*.d.tmp + @sed -e 's|.*:|$*.o:|' < $*.d.tmp > $*.d + @sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \ + sed -e 's/^ *//' -e 's/$$/:/' >> $*.d + @rm -f $*.d.tmp diff --git a/software/libbase/Makefile b/software/libbase/Makefile index a9027a27..b01fc7f9 100644 --- a/software/libbase/Makefile +++ b/software/libbase/Makefile @@ -3,6 +3,9 @@ include $(MMDIR)/software/include.mak OBJECTS=divsi3.o libc.o console.o system.o board.o uart.o softfloat.o softfloat-glue.o vsnprintf.o atof.o +# pull in dependency info for *existing* .o files +-include $(OBJECTS:.o=.d) + all: libbase.a libbase.a: $(OBJECTS) @@ -12,4 +15,4 @@ libbase.a: $(OBJECTS) .PHONY: clean clean: - rm -f *.o libbase.a .*~ *~ Makefile.bak + rm -f $(OBJECTS) $(OBJECTS:.o=.d) libbase.a .*~ *~ Makefile.bak -- 2.30.2