-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
103 lines (84 loc) · 3.07 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
96
97
98
99
100
101
102
103
# COMPILER
CC:=g++
CFLAGS:=-Wall -ggdb -std=c++11
# APP
APPNAME:=ttracker
# APP DIRECTORIES
BUILDDIR:=bin
INCLUDEDIR:=include
LIBDIR:=lib
SRCDIR:=src
TMPDIR:=.obj
# SOURCES
MAINFILE=$(SRCDIR)/main.cpp
SOURCES:=$(shell find $(SRCDIR) -name '*.cpp')
_SOURCESFOLDERS:=$(shell find $(SRCDIR) -type d)
SOURCESFOLDERS:=$(subst ./,,$(_SOURCESFOLDERS))
# OBJECTS
_OBJECTS:=$(addprefix $(TMPDIR)/,$(SOURCES:%.cpp=%.o))
_OBJECTS:=$(subst ./,,$(_OBJECTS))
OBJECTS:=$(subst $(TMPDIR)/$(SRCDIR)/main.o,,$(_OBJECTS))
# EXTERNAL DEPENDENCIES
#SHAREDIR:=../shared
#SHAREDLIB:=$(SHAREDIR)/lib
#SHAREDHEADERS:=$(SHAREDIR)/include
_EXTLIBS:=cppunit sfml-system
EXTLIBS:=$(addprefix -l,$(_EXTLIBS))
# TESTS
TESTDIR:=tests
TMPTESTDIR:=.obj_tests
TESTMAINFILE:=$(TESTDIR)/main.cpp
TESTOUTPUTFILE:=test-runner
TESTSOURCES:=$(shell find $(TESTDIR) -name '*.cpp')
TESTSOURCES:=$(subst $(TESTMAINFILE),,$(TESTSOURCES))
_TESTSOURCESFOLDERS:=$(shell find $(TESTDIR) -type d)
TESTSOURCESFOLDERS:=$(subst ./,,$(_TESTSOURCESFOLDERS))
_TESTOBJECTS:=$(addprefix $(TMPTESTDIR)/,$(TESTSOURCES:%.cpp=%.o))
TESTOBJECTS:=$(subst ./,,$(_TESTOBJECTS))
_TESTEXTLIBS:=cppunit
TESTEXTLIBS:=$(addprefix -l,$(_TESTEXTLIBS))
# INSTALLATION VARS
INSTALLDIR:=/usr/local/bin
# ================================== COMPILE ===================================
all: check $(OBJECTS) $(MAINFILE)
@echo "========================="
@echo " Building $(APPNAME) ..."
@echo "========================="
$(CC) $(CFLAGS) -I$(INCLUDEDIR) $(MAINFILE) $(OBJECTS) $(EXTLIBS) -o $(BUILDDIR)/$(APPNAME)
$(TMPDIR)/%.o: %.cpp
@echo "------------------------"
@echo "> COMPILING $< ..."
$(CC) $(CFLAGS) -I$(INCLUDEDIR) $< -c -o $@
check:
@test -d $(BUILDDIR) || mkdir $(BUILDDIR)
@$(shell find $(SRCDIR) -depth -type d -print | cpio -pd $(TMPDIR))
# =================================== TEST =====================================
check-test:
@echo "Checking test dirs ..."
@test -d $(TESTDIR) || { echo "The directory '$(TESTDIR)' doesn't exists. No tests to run."; exit 1; }
@test -d $(TMPTESTDIR) || mkdir $(TMPTESTDIR)
@$(shell find $(TESTSRCDIR) -depth -type d -print | cpio -pd $(TMPTESTDIR))
$(TMPTESTDIR)/%.o: %.cpp
@echo "------------------------"
@echo "> COMPILING $< ..."
$(CC) $(CFLAGS) -I$(INCLUDEDIR) -I$(TESTDIR) $< -c -o $@
test: all check-test $(TESTOBJECTS)
@echo "==============================="
@echo "> Building $(APPNAME) tests ..."
@echo "==============================="
@echo "$(TESTOBJECTS)"
$(CC) $(CFLAGS) -I$(INCLUDEDIR) -I$(TESTDIR) $(TESTMAINFILE) $(OBJECTS) $(TESTOBJECTS) $(TESTEXTLIBS) -o $(BUILDDIR)/$(TESTOUTPUTFILE)
# ================================== INSTALL ===================================
install:
@echo "==============================="
@echo "> INSTALLING $(APPNAME) ..."
@echo "==============================="
@echo "InstallDir is $(INSTALLDIR)"
@sudo test $(INSTALLDIR)/$(APPNAME) || rm $(INSTALLDIR)/$(APPNAME)
@sudo cp $(BUILDDIR)/$(APPNAME) $(INSTALLDIR)
@echo "DONE!"
# =================================== OTHER ====================================
clean:
-rm -Rf $(TMPDIR)
-rm -Rf $(TMPTESTDIR)
.PHONY: clean all