-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
executable file
·95 lines (74 loc) · 1.84 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
####################
# DEFINITIONS
####################
# TARGET BINARY NAMES
TDIR = ./deploy
TARGET = exe
# DEBUG CONFIGURATION
# 0: NO DEBUG
# 1: MINIMAL
# 2: DEFAULT (IF EMPTY)
# 3: MAXIMAL
DEBUG = 3
# MAIN CONFIGURATION
COMPILER = gcc
CFLAGS = -I$(D-INC)
# EXTERNAL LIBRARIES IF NEEDED
LIBS = # -lm
LDIR = ./lib
# COMPILATION PATHS
D-OBJ = ./.obj
D-INC = ./inc
D-SRC = ./src
####################
# POPULATE FOLDERS
####################
DEPS = $(wildcard $(D-INC)/*.h)
SRC = $(wildcard $(D-SRC)/*.c)
OBJ = $(patsubst $(D-SRC)/%.c,$(D-OBJ)/%.o,$(SRC))
############################################################
# MAKEFILE START #
############################################################
# DEFAULT RULE FOR MAKE
$(TDIR)/$(TARGET): $(OBJ)
@echo "Target compilation"
mkdir -p $(TDIR)
$(COMPILER) -g$(DEBUG) -o $@ $^ $(DEPS) $(CFLAGS) $(LIBS)
# EXECUTE COMMAND FOR TESTING
.PHONY: call
call:
echo "TESTING"
$(TDIR)/$(TARGET)
####################
# COMPILATION RULES
####################
$(D-OBJ)/%.o: $(D-SRC)/%.c $(DEPS)
@echo "Compiling: $< into $@"
mkdir -p $(D-OBJ)
$(COMPILER) -g$(DEBUG) -c -o $@ $< $(CFLAGS)
####################
# HELP
####################
.PHONY: help
help:
@echo ""
@echo "Next commands works with current makefile."
@echo ""
@echo "If it's needed to contact the maintainer, please send an email to Joseba R.G."
@echo ""
@echo "Commands for compilation:"
@echo " make : compiles everything and leaves the bynary files in ./deploy."
@echo ""
@echo "Commands for cleaning:"
@echo " make clean : deletes compilation results and temporary files."
@echo ""
####################
# RULES FOR CLEANING
####################
# CLEAN COMMAND
.PHONY: clean
clean:
@echo "DELETING FILES"
rm -f -r $(D-OBJ)
rm -f $(TDIR)/$(TARGET)
rm -d $(TDIR) # DELETE ONLY IF EMPTY FOLDER