From 96f057488e31750a83b7e3a8cdd86effdce67fe0 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 2 Sep 2015 06:50:54 +0200 Subject: automate some parts of intconf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index aaaf03b..50c156a 100644 --- a/Makefile +++ b/Makefile @@ -55,17 +55,22 @@ CCFLAGS_STATIC = $(CCFLAGS_COMMON) CCFLAGS_SHARED = $(CCFLAGS_COMMON) -fPIC -DSHARED # Flags required when genering header file dependency list. -MMFLAGS = $(CCFLAGS_COMMON) -MG +MMFLAGS = $(CCFLAGS_COMMON) -Igen -MG +SHE = '\#' + # Object files to build. -OBJECTS = $(shell find src | grep '\.c$$' | sed -e 's:^src/:obj/:' -e 's:\.c$$:\.o:') +OBJECTS = $(shell find src | grep '\.c$$' | grep -v $(SHE) | sed -e 's:^src/:obj/:' -e 's:\.c$$:\.o:') # All header files. -HEADERS = $(shell find . | grep '\.h$$' | sed -e 's:^\./::') +HEADERS = $(shell find . | grep '\.h$$' | grep -v $(SHE) | sed -e 's:^\./::') # All code files. -SOURCES = $(shell find src | grep '\.c$$') +SOURCES = $(shell find src | grep '\.c$$' | grep -v $(SHE)) + +# Generated headers files. +GENERATED = include/bits/intconf.h @@ -89,19 +94,31 @@ all: $(OBJECTS) # Build object file. -obj/%.o: +obj/%.o: $(GENERATED) @mkdir -p $$(dirname $@) $(CC) -c -o $@ src/$*.c $(CCFLAGS_SHARED) +# Preprocess header files. +include/%.h: gen/%.h bin/gen/% + @mkdir -p $$(dirname $@) + gpp -s // < $< > $@ + +bin/gen/%: obj/gen/%.o + @mkdir -p $$(dirname $@) + $(CC) $(CCFLAGS_WARNINGS) -std=c99 -o $@ $^ +obj/gen/%.o: gen/%.c + @mkdir -p $$(dirname $@) + $(CC) -c -o $@ $< # Generate list of file dependencies for object files. -obj/deps.mk: Makefile $(HEADERS) $(SOURCES) +obj/deps.mk: Makefile $(HEADERS) $(SOURCES) $(GENERATED) @mkdir -p obj - @find src | grep '\.c$$' | xargs $(CC) -MM $(MMFLAGS) > $@ - @sed -i 's#^[^ :]*\.o: src\([^ ]*\)/[^ /]*\.c#obj\1/&#' $@ + find src | grep '\.c$$' | xargs $(CC) -MM $(MMFLAGS) > $@ + sed -i 's#^[^ :]*\.o: src\([^ ]*\)/[^ /]*\.c#obj\1/&#' $@ + sed -i 's# gen/\([^ ]*\.h\)# \1#g' $@ @@ -109,6 +126,7 @@ obj/deps.mk: Makefile $(HEADERS) $(SOURCES) .PHONY: clean clean: -rm -rf obj bin + -rm -f include/bits/intconf.h # Remove all files that are not part of the source. .PHONY: distclean -- cgit v1.2.3-70-g09d2