]> PatchyGit - patchyircd.git/commitdiff
Makefile: rework to use object files
authorEgor <egor@patchysicp.xyz>
Wed, 4 Jun 2025 21:45:54 +0000 (00:45 +0300)
committerEgor <egor@patchysicp.xyz>
Wed, 4 Jun 2025 21:46:50 +0000 (00:46 +0300)
.gitignore
Makefile
REUSE.toml
obj/.gitignore [new file with mode: 0644]

index 3846f5f..be51f83 100644 (file)
@@ -1,4 +1,5 @@
 ircd
 setpass
 config.mk
+deps.mk
 lua/local.lua
index ca16565..1d0d8d6 100644 (file)
--- 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 $@
index 26c3a13..981671e 100644 (file)
@@ -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 (file)
index 0000000..5761abc
--- /dev/null
@@ -0,0 +1 @@
+*.o