From c69a954d8f100a31a98bf627ef3235d7c9500be8 Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Thu, 8 Nov 2018 01:56:19 +0100 Subject: [PATCH] Makefile: Bring back -O3 in a downstream-compatible way This commit brings back -O3 but in an overridable way. This should make downstream distributions happy enough to accept it. While at the subject, let's apply the same fixup logic to LDFLAGS, too. This commit also properly gets rid of the implicit rules which collided too easily with the depends.mk. Signed-off-by: Kai Krakow --- lib/Makefile | 8 +++++--- makeflags | 12 +++++++----- src/Makefile | 24 +++++++++++++----------- test/Makefile | 12 +++++------- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index 010ef07..f876fc2 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -22,6 +22,8 @@ CRUCIBLE_OBJS = \ include ../makeflags include ../Defines.mk +BEES_LDFLAGS = $(LDFLAGS) + configure.h: configure.h.in $(TEMPLATE_COMPILER) @@ -29,7 +31,7 @@ configure.h: configure.h.in mkdir -p $@ .depends/%.dep: %.cc configure.h Makefile | .depends - $(CXX) $(CXXFLAGS) -M -MF $@ -MT $(<:.cc=.o) $< + $(CXX) $(BEES_CXXFLAGS) -M -MF $@ -MT $(<:.cc=.o) $< depends.mk: $(CRUCIBLE_OBJS:%.o=.depends/%.dep) cat $^ > $@.new @@ -42,7 +44,7 @@ depends.mk: $(CRUCIBLE_OBJS:%.o=.depends/%.dep) include depends.mk %.o: %.cc ../makeflags - $(CXX) $(CXXFLAGS) -fPIC -o $@ -c $< + $(CXX) $(BEES_CXXFLAGS) -fPIC -o $@ -c $< libcrucible.so: $(CRUCIBLE_OBJS) .version.o - $(CXX) $(LDFLAGS) -fPIC -shared -Wl,-soname,$@ -o $@ $^ -luuid + $(CXX) $(BEES_LDFLAGS) -fPIC -shared -Wl,-soname,$@ -o $@ $^ -luuid diff --git a/makeflags b/makeflags index c9ed421..2afa254 100644 --- a/makeflags +++ b/makeflags @@ -1,11 +1,13 @@ # Default: -CCFLAGS = -Wall -Wextra -Werror -I../include -fpic -D_FILE_OFFSET_BITS=64 +CCFLAGS = -Wall -Wextra -Werror -O3 # Optimized: -# CCFLAGS = -Wall -Wextra -Werror -O3 -march=native -I../include -fpic -D_FILE_OFFSET_BITS=64 +# CCFLAGS = -Wall -Wextra -Werror -O3 -march=native # Debug: -# CCFLAGS = -Wall -Wextra -Werror -O0 -I../include -ggdb -fpic -D_FILE_OFFSET_BITS=64 +# CCFLAGS = -Wall -Wextra -Werror -O0 -ggdb -CFLAGS += $(CCFLAGS) -std=c99 -CXXFLAGS += $(CCFLAGS) -std=c++11 -Wold-style-cast +CCFLAGS += -I../include -fpic -D_FILE_OFFSET_BITS=64 + +BEES_CFLAGS = $(CCFLAGS) -std=c99 $(CFLAGS) +BEES_CXXFLAGS = $(CCFLAGS) -std=c++11 -Wold-style-cast $(CXXFLAGS) diff --git a/src/Makefile b/src/Makefile index 25fe4c2..dbe9f9e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,14 +1,14 @@ +BEES = ../bin/bees PROGRAMS = \ - ../bin/bees \ ../bin/fiemap \ ../bin/fiewalk \ -all: $(PROGRAMS) +all: $(BEES) $(PROGRAMS) include ../makeflags LIBS = -lcrucible -lpthread -LDFLAGS = -L../lib +BEES_LDFLAGS = -L../lib $(LDFLAGS) BEES_OBJS = \ bees.o \ @@ -27,7 +27,7 @@ bees-version.c: bees.h $(BEES_OBJS:.o=.cc) Makefile mkdir -p $@ .depends/%.dep: %.cc Makefile | .depends - $(CXX) $(CXXFLAGS) -M -MF $@ -MT $(<:.cc=.o) $< + $(CXX) $(BEES_CXXFLAGS) -M -MF $@ -MT $(<:.cc=.o) $< depends.mk: $(BEES_OBJS:%.o=.depends/%.dep) cat $^ > $@.new @@ -35,15 +35,17 @@ depends.mk: $(BEES_OBJS:%.o=.depends/%.dep) include depends.mk -%.o: %.cc %.h - $(CXX) $(CXXFLAGS) -o $@ -c $< +$(BEES_OBJS) fiemap.o fiewalk.o: %.o: %.cc + $(CXX) $(BEES_CXXFLAGS) -o $@ -c $< -../bin/%: %.o - @echo Implicit bin rule "$<" '->' "$@" - $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) +$(PROGRAMS): ../bin/%: %.o + $(CXX) $(BEES_CXXFLAGS) $(BEES_LDFLAGS) -o $@ $< $(LIBS) -../bin/bees: $(BEES_OBJS) bees-version.o - $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) +bees-version.o: %.o: %.c + $(CC) $(BEES_CFLAGS) -o $@ -c $< + +$(BEES): $(BEES_OBJS) bees-version.o + $(CXX) $(BEES_CXXFLAGS) $(BEES_LDFLAGS) -o $@ $^ $(LIBS) clean: rm -fv *.o bees-version.c diff --git a/test/Makefile b/test/Makefile index d20109a..4c267d3 100644 --- a/test/Makefile +++ b/test/Makefile @@ -16,13 +16,13 @@ FORCE: include ../makeflags LIBS = -lcrucible -lpthread -LDFLAGS = -L../lib -Wl,-rpath=$(shell realpath ../lib) +BEES_LDFLAGS = -L../lib -Wl,-rpath=$(abspath ../lib) $(LDFLAGS) .depends: mkdir -p $@ .depends/%.dep: %.cc tests.h Makefile | .depends - $(CXX) $(CXXFLAGS) -M -MF $@ -MT $(<:.cc=.o) $< + $(CXX) $(BEES_CXXFLAGS) -M -MF $@ -MT $(<:.cc=.o) $< depends.mk: $(PROGRAMS:%=.depends/%.dep) cat $^ > $@.new @@ -30,13 +30,11 @@ depends.mk: $(PROGRAMS:%=.depends/%.dep) include depends.mk -%.o: %.cc %.h ../makeflags Makefile - @echo "Implicit rule %.o: %.cc" - $(CXX) $(CXXFLAGS) -o $@ -c $< +$(PROGRAMS:%=%.o): %.o: %.cc ../makeflags Makefile + $(CXX) $(BEES_CXXFLAGS) -o $@ -c $< $(PROGRAMS): %: %.o ../makeflags Makefile - @echo "Implicit rule %: %.o" - $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) + $(CXX) $(BEES_CXXFLAGS) $(BEES_LDFLAGS) -o $@ $< $(LIBS) %.txt: % Makefile FORCE ./$< >$@ 2>&1 || (RC=$$?; cat $@; exit $$RC)