From e7c2eeb6c82d5341019cbb00cfefc55c8a27f232 Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Sun, 26 Jun 2022 21:48:45 -0700 Subject: Move a bunch of code from headers to separate compilation units. --- Makefile | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index ed96817..be9dc32 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ CHRONIC ?= chronic PKGS := fmt PKG_FLAGS := $(shell pkg-config --cflags ${PKGS}) -PKG_LIBS := -Wl,--push-state,--as-needed $(shell pkg-config --libs ${PKGS}) -Wl,--pop-state +PKG_LIBS := -Wl,--push-state,--as-needed,--start-group $(shell pkg-config --libs ${PKGS}) -Wl,--end-group,--pop-state CXXFLAGS := -Wall -Werror -std=c++20 -fPIC -iquote . ${PKG_FLAGS} ${OPTIMIZE} ${DEBUG} @@ -28,7 +28,7 @@ endef export GITTAGCPP ifneq ($(shell which ${IWYU}),) -iwyu = ${CHRONIC} ${IWYU} -Xiwyu --error -Xiwyu --mapping_file=tools/iwyu.imp ${CXXFLAGS} $(1) +iwyu = ${CHRONIC} ${IWYU} -Xiwyu --error -Xiwyu --mapping_file=tools/iwyu.imp -Xiwyu --no_fwd_decls ${CXXFLAGS} $(1) else $(warning Not using IWYU) iwyu = @@ -36,6 +36,10 @@ endif libname = $(shell realpath --canonicalize-missing --relative-to . build/$(dir $(1))/lib$(notdir $(1))) +define mksodeps = +$(1)_SODEPS := +endef + define mklib = ifneq ($(wildcard $(1)/*.cpp),) @@ -44,9 +48,9 @@ $(call libname,$(1).a): $(patsubst %.cpp,build/%.o,$(wildcard $(1)/*.cpp)) @mkdir -p $$(dir $$@) $${AR} cr $$@ $$+ -$(call libname,$(1).so): $(patsubst %.cpp,build/%.o,$(wildcard $(1)/*.cpp)) +$(call libname,$(1).so): $(patsubst %.cpp,build/%.o,$(wildcard $(1)/*.cpp)) $${$(1)_SODEPS} @mkdir -p $$(dir $$@) - $${CXX} $${CXXFLAGS} -shared -o $$@ $$+ ${PKG_LIBS} + $${CXX} $${CXXFLAGS} -shared -o $$@ -Wl,--start-group $$+ -Wl,--end-group PARTARS += $(call libname,$(1).a) PARTSOS += $(call libname,$(1).so) @@ -73,6 +77,11 @@ PARTARS := PARTSOS := IWYU_CPPS := +$(foreach part,${PARTS},$(eval $(call mksodeps,${part}))) + +DEPFILES := $(shell find -mindepth 1 -name .\* -prune -o -type f -name \*.d -print) +include ${DEPFILES} + $(foreach part,${PARTS},$(eval $(call mklib,${part}))) MAINOBJS := $(patsubst %.cpp,build/%.o,$(wildcard *.cpp)) @@ -92,11 +101,11 @@ issim-static: build/issim-static build/issim-dynamic: ${MAINOBJS} ${PARTSOS} @mkdir -p $(dir $@) - ${CXX} ${CXXFLAGS} -o $@ $+ ${PKG_LIBS} + ${CXX} ${CXXFLAGS} -o $@ -Wl,--start-group $+ -Wl,--end-group ${PKG_LIBS} build/issim-static: ${MAINOBJS} ${PARTARS} @mkdir -p $(dir $@) - ${CXX} ${CXXFLAGS} -o $@ $+ ${PKG_LIBS} + ${CXX} ${CXXFLAGS} -o $@ -Wl,--start-group $+ -Wl,--end-group ${PKG_LIBS} clean: rm -rf build issim issim-static @@ -107,8 +116,6 @@ build/git-tag.cpp: @echo "$$GITTAGCPP" > $@ .PHONY: build/git-tag.cpp -include $(shell find -type f -name \*.d) - build/%.o: %.cpp @mkdir -p $(dir $@) @$(call iwyu,$<) -- cgit v1.2.3