-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
42 lines (34 loc) · 1.31 KB
/
Copy pathMakefile
File metadata and controls
42 lines (34 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
CXX = g++
CXXFLAGS = -std=c++17 -Wall -Wextra -I./include
SRC_DIR = src
BUILD_DIR = build
PROBLEM_NAME ?= TwoSum # Default problem name
# Find the problem source file
PROBLEM_SRC = $(shell find $(SRC_DIR) -name "$(PROBLEM_NAME).cpp" -o -name "$(PROBLEM_NAME)_*.cpp" | head -1)
all: clean $(BUILD_DIR)/$(PROBLEM_NAME)
$(BUILD_DIR)/$(PROBLEM_NAME): $(PROBLEM_SRC) $(SRC_DIR)/main.cpp
@mkdir -p $(BUILD_DIR)
$(CXX) $(CXXFLAGS) -DCURRENT_SOLUTION $(SRC_DIR)/main.cpp $(PROBLEM_SRC) -o $@
run: $(BUILD_DIR)/$(PROBLEM_NAME)
./$(BUILD_DIR)/$(PROBLEM_NAME) $(PROBLEM_NAME)
new:
@if [ -z "$(PROBLEM_NAME)" ]; then \
echo "Please provide a problem name: make new PROBLEM_NAME=YourProblemName"; \
exit 1; \
fi
@if [ -f "$(SRC_DIR)/$(PROBLEM_NAME).cpp" ]; then \
echo "Problem already exists!"; \
exit 1; \
fi
@mkdir -p $(SRC_DIR)
@sed "s/\[PROBLEM_NAME\]/$(PROBLEM_NAME)/g" template.cpp > $(SRC_DIR)/$(PROBLEM_NAME).cpp
@sed "s/\[PROBLEM_NAME\]/$(PROBLEM_NAME)/g" template.md > docs/$(PROBLEM_NAME).md
@echo "Created new problem: $(PROBLEM_NAME)"
@echo "Source file: $(SRC_DIR)/$(PROBLEM_NAME).cpp"
@echo "Documentation: docs/$(PROBLEM_NAME).md"
list:
@echo "Available problems:"
@find $(SRC_DIR) -name "*.cpp" | grep -v "main.cpp" | sed 's/.*\/\(.*\)\.cpp/\1/'
clean:
rm -rf $(BUILD_DIR)/*
.PHONY: all run new list clean