From f08ee55dadf74cbb365e9214a61b3f0e54792b05 Mon Sep 17 00:00:00 2001 From: Egor Date: Thu, 5 Jun 2025 00:45:54 +0300 Subject: [PATCH] Makefile: rework to use object files --- .gitignore | 1 + Makefile | 50 ++++++++++++++++++++++++++++---------------------- REUSE.toml | 1 + obj/.gitignore | 1 + 4 files changed, 31 insertions(+), 22 deletions(-) create mode 100644 obj/.gitignore diff --git a/.gitignore b/.gitignore index 3846f5f..be51f83 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ ircd setpass config.mk +deps.mk lua/local.lua diff --git a/Makefile b/Makefile index ca16565..1d0d8d6 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,4 @@ -TARGET := ircd -SOURCES := \ +ircd_SOURCES := \ src/main.cpp \ src/admin.cpp \ src/irc.cpp \ @@ -12,19 +11,11 @@ SOURCES := \ src/map.cpp \ src/util.cpp \ src/crypt_blowfish.cpp -HEADERS := \ - src/common.h \ - src/admin.h \ - src/irc.h \ - src/ircfmt.h \ - src/job.h \ - src/net.h \ - src/netpoll.h \ - src/netsock.h \ - src/passwd.h \ - src/map.h \ - src/util.h \ - src/crypt_blowfish.h +setpass_SOURCES := \ + src/setpass.cpp \ + src/passwd.cpp \ + src/crypt_blowfish.cpp +SOURCES := $(ircd_SOURCES) $(filter-out $(ircd_SOURCES),$(setpass_SOURCES)) -include config.mk @@ -48,12 +39,27 @@ CXXFLAGS += $(shell pkg-config --cflags $(WANTLIBS)) LDLIBS += $(shell pkg-config --libs $(WANTLIBS)) endif -.PHONY: all clean -all: $(TARGET) setpass +.PHONY: all clean deps +all: ircd setpass clean: - $(RM) $(TARGET) setpass + $(RM) ircd setpass $(SOURCES:src/%.cpp=obj/%.o) deps.mk + +deps.mk deps: + $(CXX) $(CXXFLAGS) -MM $(SOURCES) | sed 's!.*:!obj/&!' >deps.mk +-include deps.mk + +V_CXX=$(V_CXX_$(V)) +V_CXX_=$(V_CXX_0) +V_CXX_0=@echo " CXX " $@; +V_CXX_1= +V_CXXLD=$(V_CXXLD_$(V)) +V_CXXLD_=$(V_CXXLD_0) +V_CXXLD_0=@echo " CXXLD " $@; +V_CXXLD_1= -$(TARGET): $(SOURCES) $(HEADERS) - $(CXX) $(CXXFLAGS) $(LDFLAGS) $(SOURCES) $(LDLIBS) -o $@ -setpass: src/setpass.cpp src/passwd.cpp src/crypt_blowfish.cpp src/passwd.h src/netsock.h - $(CXX) $(CXXFLAGS) $(LDFLAGS) src/setpass.cpp src/passwd.cpp src/crypt_blowfish.cpp $(LDLIBS) -o $@ +obj/%.o: src/%.cpp + $(V_CXX)$(CXX) $(CXXFLAGS) -c $< -o $@ +ircd: $(ircd_SOURCES:src/%.cpp=obj/%.o) + $(V_CXXLD)$(CXX) $(CXXFLAGS) $(LDFLAGS) $(ircd_SOURCES:src/%.cpp=obj/%.o) $(LDLIBS) -o $@ +setpass: $(setpass_SOURCES:src/%.cpp=obj/%.o) + $(V_CXXLD)$(CXX) $(CXXFLAGS) $(LDFLAGS) $(setpass_SOURCES:src/%.cpp=obj/%.o) $(LDLIBS) -o $@ diff --git a/REUSE.toml b/REUSE.toml index 26c3a13..981671e 100644 --- a/REUSE.toml +++ b/REUSE.toml @@ -4,6 +4,7 @@ version = 1 path = [ ".gitignore", "data/.gitignore", + "obj/.gitignore", "Makefile", "config.example.mk", diff --git a/obj/.gitignore b/obj/.gitignore new file mode 100644 index 0000000..5761abc --- /dev/null +++ b/obj/.gitignore @@ -0,0 +1 @@ +*.o -- 2.56.0