diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-03-04 23:29:39 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-03-04 23:29:39 +0800 |
| commit | 09d899230c3d31bd405cc3407c6c372ab9091e98 (patch) | |
| tree | c6a34436ec3d1a3e99dde3b97dea820d85dc37b9 /Makefile | |
| parent | bf95e496e2f03fcffb9c6043307f13c99a18d8d0 (diff) | |
refactor!: python -> c++
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..afd0ce8 --- /dev/null +++ b/Makefile @@ -0,0 +1,61 @@ +BIN = chat-server +SRCS = $(wildcard src/*.cpp) +HEADERS = $(wildcard src/*.hpp) + +PREFIX ?= /usr/local +BINDIR ?= $(PREFIX)/bin +DATADIR ?= $(PREFIX)/share + +OBJS = $(SRCS:.cpp=.o) + +CXXFLAGS += -std=c++23 -Oz -s -Wall -flto -fPIC +LDFLAGS += -Wl,--as-needed,-z,now,-z,pack-relative-relocs + +# Debug flags +DEBUG_CXXFLAGS = -std=c++23 -g3 -O0 -Wall -fno-lto -fPIC -DDEBUG +DEBUG_LDFLAGS = -Wl,--as-needed,-z,now,-z,pack-relative-relocs + +JOB_COUNT := $(BIN) $(OBJS) +JOBS_DONE := $(shell ls -l $(JOB_COUNT) 2> /dev/null | wc -l) + +define progress + $(eval JOBS_DONE := $(shell echo $$(($(JOBS_DONE) + 1)))) + @printf "[$(JOBS_DONE)/$(shell echo $(JOB_COUNT) | wc -w)] %s %s\n" $(1) $(2) +endef + +all: $(BIN) + +install: $(all) + @echo "Installing..." + @install -D -t $(DESTDIR)$(BINDIR) $(BIN) + +clean: + @echo "Cleaning up" + -@rm $(BIN) $(OBJS) + +$(BIN): $(OBJS) + $(call progress, Linking $@) + @$(CXX) -o $(BIN) \ + $(OBJS) \ + $(CXXFLAGS) \ + $(LDFLAGS) \ + -Wl,--no-as-needed \ + + +%.o: %.cpp + $(call progress, Compiling $@) + @$(CXX) -c $< -o $@ \ + $(CXXFLAGS) + +clang-format: + @echo "Formatting code..." + @clang-format -i $(SRCS) $(HEADERS) + +clang-tidy: + @echo "Running clang-tidy..." + @clang-tidy $(SRCS) -- $(CXXFLAGS) + +debug: CXXFLAGS = $(DEBUG_CXXFLAGS) +debug: LDFLAGS = $(DEBUG_LDFLAGS) +debug: $(BIN) + @echo "Debug build complete" |
