-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
64 lines (51 loc) · 1.78 KB
/
makefile
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
# Directory Settings
BUILD_DIR := bin
SRC_DIR := src
OBJ_DIR := obj
INC_DIR := inc
DEP_DIR := obj
ASSETS_DIR := assets
#EXTENSION
SRC_EXT := c
INC_EXT := h
OBJ_EXT := o
DEP_EXT := d
CSFML_INC := CSFML\include
CSFML_LIB := CSFML\lib\gcc
CSFML_BIN := CSFML\bin
CXX := gcc #compilator flag
# -Wall : turn on most of the information
# -g : turn on debug info
CXXFLAGS := -Wall -g
LDFLAGS := -I$(INC_DIR) -I$(CSFML_INC) -L$(CSFML_LIB) -lcsfml-system -lcsfml-window -lcsfml-graphics
# Files loading
FILES := $(wildcard $(SRC_DIR)/*.$(SRC_EXT)) # load all the *.c files
OBJECTS := $(FILES:$(SRC_DIR)/%.$(SRC_EXT)=$(OBJ_DIR)/%.$(OBJ_EXT)) # convert all the *.c into .o object inside the ./obj/ directory
INCLUDES := $(wildcard $(INC_DIR)/*.$(INC_EXT)) # load all the header files
DEPS := $(FILES:%.$(SRC_EXT)=$(OBJ_DIR)/%.$(OBJ_EXT)) # convert all the *.c into .d dependancies inside the ./obj/ directory
EXEC := main # name of the executable generated
# main execution
all: $(BUILD_DIR)/$(EXEC)
# build the executable by linking the object and creating the bin directory if not already created
$(BUILD_DIR)/$(EXEC): $(OBJECTS) | $(BUILD_DIR)
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
cp -f $(ASSETS_DIR)\arial.ttf $(BUILD_DIR)\arial.ttf
xcopy $(CSFML_BIN) $(BUILD_DIR)
# build all the object and dependancies files from the *.c files
$(OBJ_DIR)/%.$(OBJ_EXT): $(SRC_DIR)/%.$(SRC_EXT) $(INCLUDES) | $(OBJ_DIR)
$(CXX) -c $(CXXFLAGS) $(LDFLAGS) $< -o $@
$(CXX) -MM $(CXXFLAGS) $(LDFLAGS) $< > $(DEP_DIR)/$*.$(DEP_EXT)
# create the directory build
$(BUILD_DIR):
mkdir bin
# create the object build
$(OBJ_DIR):
mkdir obj
# clean all the project
.PHONY: clean mrproper
clean:
rm *.$(OBJ_EXT)
mrproper: clean
rm $(EXEC)
# pull in dependency info for *existing* .o files
-include $(OBJECTS:.$(OBJ_EXT)=.$(DEP_EXT))