diff options
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 23 |
1 files changed, 15 insertions, 8 deletions
| @@ -8,7 +8,7 @@ CHRONIC ?= chronic | |||
| 8 | 8 | ||
| 9 | PKGS := fmt | 9 | PKGS := fmt |
| 10 | PKG_FLAGS := $(shell pkg-config --cflags ${PKGS}) | 10 | PKG_FLAGS := $(shell pkg-config --cflags ${PKGS}) |
| 11 | PKG_LIBS := -Wl,--push-state,--as-needed $(shell pkg-config --libs ${PKGS}) -Wl,--pop-state | 11 | PKG_LIBS := -Wl,--push-state,--as-needed,--start-group $(shell pkg-config --libs ${PKGS}) -Wl,--end-group,--pop-state |
| 12 | 12 | ||
| 13 | CXXFLAGS := -Wall -Werror -std=c++20 -fPIC -iquote . ${PKG_FLAGS} ${OPTIMIZE} ${DEBUG} | 13 | CXXFLAGS := -Wall -Werror -std=c++20 -fPIC -iquote . ${PKG_FLAGS} ${OPTIMIZE} ${DEBUG} |
| 14 | 14 | ||
| @@ -28,7 +28,7 @@ endef | |||
| 28 | export GITTAGCPP | 28 | export GITTAGCPP |
| 29 | 29 | ||
| 30 | ifneq ($(shell which ${IWYU}),) | 30 | ifneq ($(shell which ${IWYU}),) |
| 31 | iwyu = ${CHRONIC} ${IWYU} -Xiwyu --error -Xiwyu --mapping_file=tools/iwyu.imp ${CXXFLAGS} $(1) | 31 | iwyu = ${CHRONIC} ${IWYU} -Xiwyu --error -Xiwyu --mapping_file=tools/iwyu.imp -Xiwyu --no_fwd_decls ${CXXFLAGS} $(1) |
| 32 | else | 32 | else |
| 33 | $(warning Not using IWYU) | 33 | $(warning Not using IWYU) |
| 34 | iwyu = | 34 | iwyu = |
| @@ -36,6 +36,10 @@ endif | |||
| 36 | 36 | ||
| 37 | libname = $(shell realpath --canonicalize-missing --relative-to . build/$(dir $(1))/lib$(notdir $(1))) | 37 | libname = $(shell realpath --canonicalize-missing --relative-to . build/$(dir $(1))/lib$(notdir $(1))) |
| 38 | 38 | ||
| 39 | define mksodeps = | ||
| 40 | $(1)_SODEPS := | ||
| 41 | endef | ||
| 42 | |||
| 39 | define mklib = | 43 | define mklib = |
| 40 | 44 | ||
| 41 | ifneq ($(wildcard $(1)/*.cpp),) | 45 | ifneq ($(wildcard $(1)/*.cpp),) |
| @@ -44,9 +48,9 @@ $(call libname,$(1).a): $(patsubst %.cpp,build/%.o,$(wildcard $(1)/*.cpp)) | |||
| 44 | @mkdir -p $$(dir $$@) | 48 | @mkdir -p $$(dir $$@) |
| 45 | $${AR} cr $$@ $$+ | 49 | $${AR} cr $$@ $$+ |
| 46 | 50 | ||
| 47 | $(call libname,$(1).so): $(patsubst %.cpp,build/%.o,$(wildcard $(1)/*.cpp)) | 51 | $(call libname,$(1).so): $(patsubst %.cpp,build/%.o,$(wildcard $(1)/*.cpp)) $${$(1)_SODEPS} |
| 48 | @mkdir -p $$(dir $$@) | 52 | @mkdir -p $$(dir $$@) |
| 49 | $${CXX} $${CXXFLAGS} -shared -o $$@ $$+ ${PKG_LIBS} | 53 | $${CXX} $${CXXFLAGS} -shared -o $$@ -Wl,--start-group $$+ -Wl,--end-group |
| 50 | 54 | ||
| 51 | PARTARS += $(call libname,$(1).a) | 55 | PARTARS += $(call libname,$(1).a) |
| 52 | PARTSOS += $(call libname,$(1).so) | 56 | PARTSOS += $(call libname,$(1).so) |
| @@ -73,6 +77,11 @@ PARTARS := | |||
| 73 | PARTSOS := | 77 | PARTSOS := |
| 74 | IWYU_CPPS := | 78 | IWYU_CPPS := |
| 75 | 79 | ||
| 80 | $(foreach part,${PARTS},$(eval $(call mksodeps,${part}))) | ||
| 81 | |||
| 82 | DEPFILES := $(shell find -mindepth 1 -name .\* -prune -o -type f -name \*.d -print) | ||
| 83 | include ${DEPFILES} | ||
| 84 | |||
| 76 | $(foreach part,${PARTS},$(eval $(call mklib,${part}))) | 85 | $(foreach part,${PARTS},$(eval $(call mklib,${part}))) |
| 77 | 86 | ||
| 78 | MAINOBJS := $(patsubst %.cpp,build/%.o,$(wildcard *.cpp)) | 87 | MAINOBJS := $(patsubst %.cpp,build/%.o,$(wildcard *.cpp)) |
| @@ -92,11 +101,11 @@ issim-static: build/issim-static | |||
| 92 | 101 | ||
| 93 | build/issim-dynamic: ${MAINOBJS} ${PARTSOS} | 102 | build/issim-dynamic: ${MAINOBJS} ${PARTSOS} |
| 94 | @mkdir -p $(dir $@) | 103 | @mkdir -p $(dir $@) |
| 95 | ${CXX} ${CXXFLAGS} -o $@ $+ ${PKG_LIBS} | 104 | ${CXX} ${CXXFLAGS} -o $@ -Wl,--start-group $+ -Wl,--end-group ${PKG_LIBS} |
| 96 | 105 | ||
| 97 | build/issim-static: ${MAINOBJS} ${PARTARS} | 106 | build/issim-static: ${MAINOBJS} ${PARTARS} |
| 98 | @mkdir -p $(dir $@) | 107 | @mkdir -p $(dir $@) |
| 99 | ${CXX} ${CXXFLAGS} -o $@ $+ ${PKG_LIBS} | 108 | ${CXX} ${CXXFLAGS} -o $@ -Wl,--start-group $+ -Wl,--end-group ${PKG_LIBS} |
| 100 | 109 | ||
| 101 | clean: | 110 | clean: |
| 102 | rm -rf build issim issim-static | 111 | rm -rf build issim issim-static |
| @@ -107,8 +116,6 @@ build/git-tag.cpp: | |||
| 107 | @echo "$$GITTAGCPP" > $@ | 116 | @echo "$$GITTAGCPP" > $@ |
| 108 | .PHONY: build/git-tag.cpp | 117 | .PHONY: build/git-tag.cpp |
| 109 | 118 | ||
| 110 | include $(shell find -type f -name \*.d) | ||
| 111 | |||
| 112 | build/%.o: %.cpp | 119 | build/%.o: %.cpp |
| 113 | @mkdir -p $(dir $@) | 120 | @mkdir -p $(dir $@) |
| 114 | @$(call iwyu,$<) | 121 | @$(call iwyu,$<) |
