-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
79 lines (65 loc) · 2.03 KB
/
Makefile
File metadata and controls
79 lines (65 loc) · 2.03 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Compiles the project
CC=g++
# Project name
PROJ_NAME=bombs++
# Necessary folders
OBJ_FOLDER=./obj
BIN_FOLDER=./bin
# Entry file
ENTRY=main
# Flags only used when compiling the entry file
ENTRY_FLAGS=-l ncursesw
FLAGS=-pedantic -I ./include -Wall -Wextra -Werror -Wpedantic -pedantic-errors
DEBUG_FLAGS=$(FLAGS) -g
SRC_FILES=$(shell find . -regex ".*\.cpp")
OBJ_FILES=$(addprefix $(OBJ_FOLDER)/,$(notdir $(SRC_FILES:.cpp=.o)))
DBG_FILES=$(addprefix $(OBJ_FOLDER)/,$(notdir $(SRC_FILES:.cpp=.dbg.o)))
default: prod
# Global processes
prep:
@echo " Verifying if the necessary folders exists ..."
@if [ ! -d $(OBJ_FOLDER) ]; then mkdir $(OBJ_FOLDER); fi
@if [ ! -d $(BIN_FOLDER) ]; then mkdir $(BIN_FOLDER); fi
@echo " Verification complete"
clean:
@echo " Cleaning up ..."
@rm -rf $(OBJ_FOLDER)
@echo " Clean up complete"
#--------------------
# Entry points
# Output for debug mode is always the same
debug: prep dbg.out clean
@echo ""
@echo "Compilation complete"
@echo "- Mode: DEBUG"
@echo "- Project: $(PROJ_NAME)"
@echo "- Binary: $(BIN_FOLDER)/dbg.out"
@echo ""
prod: prep $(PROJ_NAME) clean
@echo ""
@echo "Compilation complete"
@echo "- Mode: PRODUCTION"
@echo "- Project: $(PROJ_NAME)"
@echo "- Binary: $(BIN_FOLDER)/$(PROJ_NAME)"
@echo ""
#------------------------
# Main file compilation
dbg.out: $(DBG_FILES)
@echo " Compilling project binary ..."
$(CC) $^ -o $(BIN_FOLDER)/$@ $(DEBUG_FLAGS) $(ENTRY_FLAGS)
@echo " Project binary created"
$(PROJ_NAME): $(OBJ_FILES)
@echo " Compilling project binary ..."
@$(CC) $^ -o $(BIN_FOLDER)/$@ $(FLAGS) $(ENTRY_FLAGS)
@echo " Project binary created"
#------------------------
# Object file compilation
$(OBJ_FILES):
@echo " Compilling object file $@ ..."
@$(CC) -c $(shell find . -regex ".*$(@F:.o=.cpp)") -o $@ $(FLAGS)
@echo " Object file $@ compiled"
$(DBG_FILES):
@echo " Compilling object file $@ ..."
$(CC) -c $(shell find . -regex ".*$(@F:.dbg.o=.cpp)") -o $@ $(DEBUG_FLAGS)
@echo " Object file $@ compiled"
#------------------------