From 6f84a4f2d7faf9d2cd30cb96d7756be21723497e Mon Sep 17 00:00:00 2001 From: David Holm Date: Sat, 5 Jan 2019 11:07:34 +0100 Subject: [PATCH 1/3] makefile: Move defines to DFLAGS All defines should be set in `DFLAGS` or dependencies might not be generated correctly. --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ce193d8..c4ae010 100644 --- a/Makefile +++ b/Makefile @@ -29,8 +29,8 @@ VPATH = ./:./support/minimig:./support/sharpmz:./support/archie:./support/st:./s OBJ = $(SRC:.c=.o) $(SRC2:.cpp=.o) $(MINIMIG_SRC:.cpp=.o) $(SHARPMZ_SRC:.cpp=.o) $(ARCHIE_SRC:.cpp=.o) $(ST_SRC:.cpp=.o) $(X86_SRC:.cpp=.o) $(SNES_SRC:.cpp=.o) $(LIBCO_SRC:.c=.o) DEP = $(SRC:.c=.d) $(SRC2:.cpp=.d) $(MINIMIG_SRC:.cpp=.d) $(SHARPMZ_SRC:.cpp=.d) $(ARCHIE_SRC:.cpp=.d) $(ST_SRC:.cpp=.d) $(X86_SRC:.cpp=.d) $(SNES_SRC:.cpp=.d) $(LIBCO_SRC:.c=.d) -DFLAGS = $(INCLUDE) -CFLAGS = $(DFLAGS) -Wall -Wextra -c -O3 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -DVDATE=\"`date +"%y%m%d"`\" +DFLAGS = $(INCLUDE) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -DVDATE=\"`date +"%y%m%d"`\" +CFLAGS = $(DFLAGS) -Wall -Wextra -c -O3 LFLAGS = -lc -lstdc++ -lrt $(PRJ): $(OBJ) From 65a07e2c122ef8ccbe83b7859204e2c67dd19fff Mon Sep 17 00:00:00 2001 From: David Holm Date: Thu, 27 Dec 2018 21:26:00 +0100 Subject: [PATCH 2/3] makefile: Support verbose build Show build commands as they are being executed if `V=1` is specified when running `make`. --- Makefile | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index c4ae010..4c8ebda 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,3 @@ - # makefile to fail if any command in pipe is failed. SHELL = /bin/bash -o pipefail @@ -9,6 +8,12 @@ CC = $(BASE)-gcc LD = $(CC) STRIP = $(BASE)-strip +ifeq ($(V),1) + Q := +else + Q := @ +endif + INCLUDE = -I./ INCLUDE += -I./support/minimig INCLUDE += -I./3pp/libco @@ -34,35 +39,35 @@ CFLAGS = $(DFLAGS) -Wall -Wextra -c -O3 LFLAGS = -lc -lstdc++ -lrt $(PRJ): $(OBJ) - @$(info $@) - @$(LD) -o $@ $+ $(LFLAGS) - @cp $@ $@.elf - @$(STRIP) $@ + $(Q)$(info $@) + $(Q)$(LD) -o $@ $+ $(LFLAGS) + $(Q)cp $@ $@.elf + $(Q)$(STRIP) $@ clean: - rm -f *.d *.o *.elf *.map *.lst *.bak *.rej *.org *.user *~ $(PRJ) - rm -rf obj .vs DTAR* x64 + $(Q)rm -f *.d *.o *.elf *.map *.lst *.bak *.rej *.org *.user *~ $(PRJ) + $(Q)rm -rf obj .vs DTAR* x64 cleanall: - rm -rf *.d *.o *.elf *.map *.lst *.bak *.rej *.org *.user *~ $(PRJ) - rm -rf obj .vs DTAR* x64 - find . -name '*.o' -delete - find . -name '*.d' -delete + $(Q)rm -rf $(OBJ) $(DEP) *.elf *.map *.lst *.bak *.rej *.org *.user *~ $(PRJ) + $(Q)rm -rf obj .vs DTAR* x64 + $(Q)find . -name '*.o' -delete + $(Q)find . -name '*.d' -delete %.o: %.c - @$(info $<) - @$(CC) $(CFLAGS) -std=gnu99 -o $@ -c $< 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):\([0-9]\+\):/\1(\2,\ \3):/g' + $(Q)$(info $<) + $(Q)$(CC) $(CFLAGS) -std=gnu99 -o $@ -c $< 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):\([0-9]\+\):/\1(\2,\ \3):/g' %.o: %.cpp - @$(info $<) - @$(CC) $(CFLAGS) -std=gnu++14 -o $@ -c $< 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):\([0-9]\+\):/\1(\2,\ \3):/g' + $(Q)$(info $<) + $(Q)$(CC) $(CFLAGS) -std=gnu++14 -o $@ -c $< 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):\([0-9]\+\):/\1(\2,\ \3):/g' -include $(DEP) %.d: %.c - @$(CC) $(DFLAGS) -MM $< -MT $@ -MT $*.o -MF $@ 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):\([0-9]\+\):/\1(\2,\ \3):/g' + $(Q)$(CC) $(DFLAGS) -MM $< -MT $@ -MT $*.o -MF $@ 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):\([0-9]\+\):/\1(\2,\ \3):/g' %.d: %.cpp - @$(CC) $(DFLAGS) -MM $< -MT $@ -MT $*.o -MF $@ 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):\([0-9]\+\):/\1(\2,\ \3):/g' + $(Q)$(CC) $(DFLAGS) -MM $< -MT $@ -MT $*.o -MF $@ 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):\([0-9]\+\):/\1(\2,\ \3):/g' # Ensure correct time stamp main.o: $(filter-out main.o, $(OBJ)) From 7abfbd07dd79c5bfada6bce46a10dce1ef7d0823 Mon Sep 17 00:00:00 2001 From: David Holm Date: Sat, 5 Jan 2019 11:20:14 +0100 Subject: [PATCH 3/3] makefile: Make obj and dep rules unique per language The make rules for objects and dependency files must be unique per language or make won't understand when to rebuild them. Before this change, if a cpp-file was changed, make would match it to the rule for C files because it comes first in the `Makefile` and not rebuild anything. --- Makefile | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 4c8ebda..4d17d69 100644 --- a/Makefile +++ b/Makefile @@ -31,8 +31,8 @@ LIBCO_SRC = 3pp/libco/arm.c VPATH = ./:./support/minimig:./support/sharpmz:./support/archie:./support/st:./support/x86:./support/snes -OBJ = $(SRC:.c=.o) $(SRC2:.cpp=.o) $(MINIMIG_SRC:.cpp=.o) $(SHARPMZ_SRC:.cpp=.o) $(ARCHIE_SRC:.cpp=.o) $(ST_SRC:.cpp=.o) $(X86_SRC:.cpp=.o) $(SNES_SRC:.cpp=.o) $(LIBCO_SRC:.c=.o) -DEP = $(SRC:.c=.d) $(SRC2:.cpp=.d) $(MINIMIG_SRC:.cpp=.d) $(SHARPMZ_SRC:.cpp=.d) $(ARCHIE_SRC:.cpp=.d) $(ST_SRC:.cpp=.d) $(X86_SRC:.cpp=.d) $(SNES_SRC:.cpp=.d) $(LIBCO_SRC:.c=.d) +OBJ = $(SRC:.c=.c.o) $(SRC2:.cpp=.cpp.o) $(MINIMIG_SRC:.cpp=.cpp.o) $(SHARPMZ_SRC:.cpp=.cpp.o) $(ARCHIE_SRC:.cpp=.cpp.o) $(ST_SRC:.cpp=.cpp.o) $(X86_SRC:.cpp=.cpp.o) $(SNES_SRC:.cpp=.cpp.o) $(LIBCO_SRC:.c=.c.o) +DEP = $(SRC:.c=.cpp.d) $(SRC2:.cpp=.cpp.d) $(MINIMIG_SRC:.cpp=.cpp.d) $(SHARPMZ_SRC:.cpp=.cpp.d) $(ARCHIE_SRC:.cpp=.cpp.d) $(ST_SRC:.cpp=.cpp.d) $(X86_SRC:.cpp=.cpp.d) $(SNES_SRC:.cpp=.cpp.d) $(LIBCO_SRC:.c=.c.d) DFLAGS = $(INCLUDE) -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -DVDATE=\"`date +"%y%m%d"`\" CFLAGS = $(DFLAGS) -Wall -Wextra -c -O3 @@ -54,20 +54,20 @@ cleanall: $(Q)find . -name '*.o' -delete $(Q)find . -name '*.d' -delete -%.o: %.c +%.c.o: %.c $(Q)$(info $<) $(Q)$(CC) $(CFLAGS) -std=gnu99 -o $@ -c $< 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):\([0-9]\+\):/\1(\2,\ \3):/g' -%.o: %.cpp +%.cpp.o: %.cpp $(Q)$(info $<) $(Q)$(CC) $(CFLAGS) -std=gnu++14 -o $@ -c $< 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):\([0-9]\+\):/\1(\2,\ \3):/g' -include $(DEP) -%.d: %.c - $(Q)$(CC) $(DFLAGS) -MM $< -MT $@ -MT $*.o -MF $@ 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):\([0-9]\+\):/\1(\2,\ \3):/g' +%.c.d: %.c + $(Q)$(CC) $(DFLAGS) -MM $< -MT $@ -MT $*.c.o -MF $@ 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):\([0-9]\+\):/\1(\2,\ \3):/g' -%.d: %.cpp - $(Q)$(CC) $(DFLAGS) -MM $< -MT $@ -MT $*.o -MF $@ 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):\([0-9]\+\):/\1(\2,\ \3):/g' +%.cpp.d: %.cpp + $(Q)$(CC) $(DFLAGS) -MM $< -MT $@ -MT $*.cpp.o -MF $@ 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):\([0-9]\+\):/\1(\2,\ \3):/g' # Ensure correct time stamp -main.o: $(filter-out main.o, $(OBJ)) +main.cpp.o: $(filter-out main.cpp.o, $(OBJ))