Skip to content

Commit

Permalink
better maefile, avoid full recompile each time
Browse files Browse the repository at this point in the history
  • Loading branch information
PoneyUHC committed Jul 13, 2024
1 parent 5620ed7 commit 8333e48
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@

.vscode

output/
output/

build/
38 changes: 30 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@

BUILD_DIR = build
EXEC_NAME = render.exe
CXX = g++
RM = rm -f
CXXFLAGS = -g -O3 -Wall -Wpedantic -std=c++17 -MMD -MP

EXEC = render.exe
OUTPUT_DIR = output
SRC_DIR = src
SRC = $(wildcard $(SRC_DIR)/*.cpp) $(wildcard $(SRC_DIR)/**/*.cpp)
CFLAGS = -g -O3 -Wall -Wpedantic -std=c++17
BUILD_DIR = build
BUILD_OBJS_DIR = $(BUILD_DIR)/binaries
BUILD_EXEC_DIR = $(BUILD_DIR)/executable

SRCS = $(wildcard $(SRC_DIR)/*.cpp) $(wildcard $(SRC_DIR)/**/*.cpp)
OBJS = $(patsubst %.cpp, %.o, $(SRCS))

OBJS_LOCATION = $(patsubst %.o, $(BUILD_OBJS_DIR)/%.o, $(OBJS))
DEPS = $(patsubst %.o, %.d, $(OBJS_LOCATION))

.PHONY: all clean

all: $(EXEC)

clean:
$(RM) $(OBJS_LOCATION) $(DEPS)

$(EXEC): $(OBJS_LOCATION)
if [ ! -d $(BUILD_EXEC_DIR) ]; then mkdir $(BUILD_EXEC_DIR); fi
$(CXX) $(OBJS_LOCATION) $(CXXFLAGS) -I $(SRC_DIR) -o $(BUILD_EXEC_DIR)/$(EXEC)

-include $(DEPS)

default: render.exe
$(BUILD_OBJS_DIR)/%.o: %.cpp Makefile
if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi
$(CXX) $(CXXFLAGS) -I $(SRC_DIR) -c $< -o $@

$(EXEC_NAME):
@if [ ! -d $(BUILD_DIR) ]; then mkdir $(BUILD_DIR); fi
@g++ $(SRC) $(CFLAGS) -I $(SRC_DIR) -o $(BUILD_DIR)/$(EXEC_NAME)

0 comments on commit 8333e48

Please sign in to comment.