diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-03-20 18:49:39 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-03-20 23:45:01 +0800 |
| commit | b57f5ff383f9f3093fecbe1c4bc05be6771cc1c0 (patch) | |
| tree | 58f225915b9e25c8ab28125ce34bb90e41b1c978 | |
| parent | 35cde25820fe9077dbc195d3b1485cd3fb82813f (diff) | |
Makefile: build into `build`dir
| -rwxr-xr-x | .gitignore | 1 | ||||
| -rw-r--r-- | Makefile | 25 | ||||
| -rw-r--r-- | compile_commands.json | 55 |
3 files changed, 35 insertions, 46 deletions
@@ -1,2 +1,3 @@ *.o .cache +build @@ -5,16 +5,18 @@ HEADERS = $(wildcard src/*.hpp) PREFIX ?= /usr BINDIR ?= $(PREFIX)/bin DATADIR ?= $(PREFIX)/share +BUILDDIR ?= build -OBJS = $(SRCS:.cpp=.o) +OBJS = $(patsubst src/%, $(BUILDDIR)/%, $(SRCS:.cpp=.o)) CXXFLAGS += -std=c++26 -Oz -s -Wall -flto -fPIC LDFLAGS += -Wl,--as-needed,-z,now,-z,pack-relative-relocs # Debug flags DEBUG_CXXFLAGS = -std=c++26 -g3 -O0 -Wall -fno-lto -fPIC -DDEBUG -DEBUG_LDFLAGS = -Wl,--as-needed,-z,now,-z,pack-relative-relocs +DEBUG_LDFLAGS = -Wl,--no-as-needed,-z,now,-z,pack-relative-relocs +$(shell mkdir -p $(BUILDDIR)) JOB_COUNT := $(BIN) $(OBJS) JOBS_DONE := $(shell ls -l $(JOB_COUNT) 2> /dev/null | wc -l) @@ -30,7 +32,7 @@ all: $(BIN) install: $(all) @echo "Installing..." - @install -D -t $(DESTDIR)$(BINDIR) $(BIN) + @install -D -t $(DESTDIR)$(BINDIR) $(BUILDDIR)/$(BIN) clean: @echo "Cleaning up" @@ -38,18 +40,21 @@ clean: clean-all: clean @echo "Cleaning up all" - -@rm -rf $(BIN) + -@rm -rf $(BUILDDIR)/$(BIN) -$(BIN): $(OBJS) +$(BUILDDIR)/$(BIN): $(OBJS) $(call progress, Linking $@) - @$(CXX) -o $(BIN) \ + @$(CXX) -o $@ \ $(OBJS) \ $(CXXFLAGS) \ - $(LDFLAGS) \ - -Wl,--no-as-needed \ + $(LDFLAGS) +# Create phony target that depends on the actual binary +$(BIN): $(BUILDDIR)/$(BIN) -%.o: %.cpp + + +$(BUILDDIR)/%.o: src/%.cpp $(call progress, Compiling $@) @$(CXX) -c $< -o $@ \ $(CXXFLAGS) @@ -62,6 +67,8 @@ clang-tidy: @echo "Running clang-tidy..." @clang-tidy -fix-errors $(SRCS) -- $(CXXFLAGS) +.PHONY: all install clean clean-all $(BIN) + debug: CXXFLAGS = $(DEBUG_CXXFLAGS) debug: LDFLAGS = $(DEBUG_LDFLAGS) debug: CC = afl-g++ diff --git a/compile_commands.json b/compile_commands.json index a18b372..da0ff90 100644 --- a/compile_commands.json +++ b/compile_commands.json @@ -1,7 +1,7 @@ [ { "arguments": [ - "/usr/bin/x86_64-pc-linux-gnu-g++", + "/usr/bin/afl-g++", "-c", "-std=c++26", "-g3", @@ -11,16 +11,16 @@ "-fPIC", "-DDEBUG", "-o", - "src/chatManager.o", + "build/chatManager.o", "src/chatManager.cpp" ], "directory": "/mnt/DATA/personal/Code/projects/chat-server", "file": "/mnt/DATA/personal/Code/projects/chat-server/src/chatManager.cpp", - "output": "/mnt/DATA/personal/Code/projects/chat-server/src/chatManager.o" + "output": "/mnt/DATA/personal/Code/projects/chat-server/build/chatManager.o" }, { "arguments": [ - "/usr/bin/x86_64-pc-linux-gnu-g++", + "/usr/bin/afl-g++", "-c", "-std=c++26", "-g3", @@ -30,16 +30,16 @@ "-fPIC", "-DDEBUG", "-o", - "src/chatServer.o", + "build/chatServer.o", "src/chatServer.cpp" ], "directory": "/mnt/DATA/personal/Code/projects/chat-server", "file": "/mnt/DATA/personal/Code/projects/chat-server/src/chatServer.cpp", - "output": "/mnt/DATA/personal/Code/projects/chat-server/src/chatServer.o" + "output": "/mnt/DATA/personal/Code/projects/chat-server/build/chatServer.o" }, { "arguments": [ - "/usr/bin/x86_64-pc-linux-gnu-g++", + "/usr/bin/afl-g++", "-c", "-std=c++26", "-g3", @@ -49,35 +49,16 @@ "-fPIC", "-DDEBUG", "-o", - "src/FileDescriptor.o", - "src/FileDescriptor.cpp" - ], - "directory": "/mnt/DATA/personal/Code/projects/chat-server", - "file": "/mnt/DATA/personal/Code/projects/chat-server/src/FileDescriptor.cpp", - "output": "/mnt/DATA/personal/Code/projects/chat-server/src/FileDescriptor.o" - }, - { - "arguments": [ - "/usr/bin/x86_64-pc-linux-gnu-g++", - "-c", - "-std=c++26", - "-g3", - "-O0", - "-Wall", - "-fno-lto", - "-fPIC", - "-DDEBUG", - "-o", - "src/main.o", + "build/main.o", "src/main.cpp" ], "directory": "/mnt/DATA/personal/Code/projects/chat-server", "file": "/mnt/DATA/personal/Code/projects/chat-server/src/main.cpp", - "output": "/mnt/DATA/personal/Code/projects/chat-server/src/main.o" + "output": "/mnt/DATA/personal/Code/projects/chat-server/build/main.o" }, { "arguments": [ - "/usr/bin/x86_64-pc-linux-gnu-g++", + "/usr/bin/afl-g++", "-c", "-std=c++26", "-g3", @@ -87,16 +68,16 @@ "-fPIC", "-DDEBUG", "-o", - "src/server.o", + "build/server.o", "src/server.cpp" ], "directory": "/mnt/DATA/personal/Code/projects/chat-server", "file": "/mnt/DATA/personal/Code/projects/chat-server/src/server.cpp", - "output": "/mnt/DATA/personal/Code/projects/chat-server/src/server.o" + "output": "/mnt/DATA/personal/Code/projects/chat-server/build/server.o" }, { "arguments": [ - "/usr/bin/x86_64-pc-linux-gnu-g++", + "/usr/bin/afl-g++", "-c", "-std=c++26", "-g3", @@ -106,16 +87,16 @@ "-fPIC", "-DDEBUG", "-o", - "src/session.o", + "build/session.o", "src/session.cpp" ], "directory": "/mnt/DATA/personal/Code/projects/chat-server", "file": "/mnt/DATA/personal/Code/projects/chat-server/src/session.cpp", - "output": "/mnt/DATA/personal/Code/projects/chat-server/src/session.o" + "output": "/mnt/DATA/personal/Code/projects/chat-server/build/session.o" }, { "arguments": [ - "/usr/bin/x86_64-pc-linux-gnu-g++", + "/usr/bin/afl-g++", "-c", "-std=c++26", "-g3", @@ -125,11 +106,11 @@ "-fPIC", "-DDEBUG", "-o", - "src/sessionManager.o", + "build/sessionManager.o", "src/sessionManager.cpp" ], "directory": "/mnt/DATA/personal/Code/projects/chat-server", "file": "/mnt/DATA/personal/Code/projects/chat-server/src/sessionManager.cpp", - "output": "/mnt/DATA/personal/Code/projects/chat-server/src/sessionManager.o" + "output": "/mnt/DATA/personal/Code/projects/chat-server/build/sessionManager.o" } ] |
