-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
104 lines (84 loc) · 2.54 KB
/
Makefile
File metadata and controls
104 lines (84 loc) · 2.54 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# ------------------------------------------------
# Generic Makefile for C++
# author: Earl John Abaquita
# -----------------------------------------------
# NOTES:
# create necessary folders
# 1. bin = location of executable file.
# 2. src = location of source files and header files.
# 3. obj = location of object files to be used in linking
#
# IMPORTANT VARIABLES and QUICK DEFINITION
#
# TARGET change to the project name
# LIBRARIES add the necessary libraries of the current project
#
# IMPORTANT CLFAGS
# -DEBUG_TOOL = when using the defined macro for debugging
# -TEST_MODE = when using the unit_framework
# ------------------------------------------------
# project name (generate executable with this name)
TARGET = TestApplication
# change these to set the proper directories where each files shoould be
SRCDIR = src
OBJDIR = obj
BINDIR = bin
INCDIR = inc
# ---------------------
# Compiler variables
CC = g++
# Change the version
CCVERSION = -std=c++17
# compiling flags here
CFLAGS = -Wall\
-g\
-I$(INCDIR)/ \
-DDEBUG_TOOL \
-DTEST_MODE
# linking flags here
LFLAGS = -Wall\
# Compiler variables end
# ---------------------
# add needed libraries
LIBRARIES :=
SOURCES := $(wildcard $(SRCDIR)/*.cpp)
INCLUDES := $(wildcard $(SRCDIR)/*.h)
OBJECTS := $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)
rm = rm -f
$(BINDIR)/$(TARGET): $(OBJECTS)
@echo "$(CC) -o $@ $(OBJECTS) $(LFLAGS) $(LIBRARIES)"
@$(CC) -o $@ $(OBJECTS) $(LIBRARIES)
@echo -e "\nBuild Success"
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.cpp
@$(CC) $(CCVERSION) $(CFLAGS) -c -o $@ $<
@echo "generating... $@ $<"
# add 1 argument to unit at make execution
# make unittest unit=src/logic.cpp
.PHONEY: unittest
unittest:
$(eval OBJVAR=$(subst cpp,o,$(unit)))
$(eval OBJVAR=$(subst src,obj,$(OBJVAR)))
$(eval TESTVAR=$(subst src,test,$(unit)))
$(eval TESTVAR=$(subst .cpp,_unit_test.cpp,$(TESTVAR)))
$(eval TESTVAROBJ=$(subst test/,obj/,$(TESTVAR)))
$(eval TESTVAROBJ=$(subst cpp,o,$(TESTVAROBJ)))
@if $(CC) $(CCVERSION) $(CFLAGS) -c -o $(OBJVAR) $(unit); then \
echo generating $(OBJVAR) completed; \
else \
echo File does not exist; exit 1;\
fi
@if $(CC) $(CCVERSION) $(CFLAGS) -I$(SRCDIR) -c -o $(TESTVAROBJ) $(TESTVAR); then \
echo generating $(TESTVAROBJ) completed;\
else \
echo [ERROR] create a unit test file.; exit 1;\
fi
@$(CC) -o bin/$@ $(OBJVAR) $(TESTVAROBJ)
@$(BINDIR)/$@
.PHONEY: clean
clean:
@$(rm) $(OBJECTS)
@$(rm) $(BINDIR)/*
@echo "Cleanup complete!"
.PHONEY: run
run:
@$(BINDIR)/$(TARGET)