-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
157 lines (125 loc) · 3.91 KB
/
makefile
File metadata and controls
157 lines (125 loc) · 3.91 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# BariBot makefile - Miles Shamo 2020
#
# This is a makefile to compile BariBot,
# but is likely able to compile any program if
# the same directory structure is used as it
# is intended to be fully configurable.
#
# This makefile defaults to the "build" target.
# If immediate execution is desired, "make run"
# is implemented.
#
# To build a test suite, "make buildTests" compiles
# the binary and "make test" runs the program.
# All tests are stored in the TESTDIR folder,
# as designated below. To ensure that tests can
# use implementations from the final program, it
# depends on (and links) all object files that are
# not "main.o". Thus, the main function of BariBot
# MUST be in "main.cpp", as main will be created twice
# otherwise.
#
# For development, a number of phony rules are
# defined below to automatically run the program
# with various debugging utilities
# ==============================================
# Variable Assignment/File Management
# ==============================================
CXX = g++
# for gdb add -ggdb and remove -03
CXXFLAGS = -ggdb -Wall -Wextra -std=c++11
# lpthread linked for asio compatability
# lPoco* for HTTP post requests
CXXLIBS = -lpthread \
-lPocoNet -lPocoFoundation -lPocoNetSSL \
-lPocoJSON \
BINARY = BariBot
TSTBINARY = TEST.out
# File structure
SOURCEDIR = ./source/
TESTDIR = ./tests/
OBJECTDIR = ./objects/
DEPENDDIR = ./depends/
# if a goal other than build is desired as default, change this
.DEFAULT_GOAL = build
# Below this point it is likely nothing ever need be changed
# gets files
SOURCES:=$(wildcard $(SOURCEDIR)*.cpp)
OBJECTS:=$(patsubst $(SOURCEDIR)%.cpp, $(OBJECTDIR)%.o, $(SOURCES))
DEPENDS:=$(patsubst $(SOURCEDIR)%.cpp, $(DEPENDDIR)%.d, $(SOURCES))
TSTSRCS:=$(wildcard $(TESTDIR)*.cpp)
TSTOBJS:=$(patsubst $(TESTDIR)%.cpp, $(OBJECTDIR)%.o, $(TSTSRCS))
TSTDEPS:=$(patsubst $(TESTDIR)%.cpp, $(DEPENDDIR)%.d, $(TSTSRCS))
# ==============================================
# Phony Rules
# ==============================================
# out of personal prefference I clear the terminal
# on most specialized builds (run, gdb, etc)
run: build
@clear
@./$(BINARY)
test: buildTests
@clear
@./$(TSTBINARY)
gdb: $(BINARY)
@clear
@gdb $(BINARY)
valgrind: $(BINARY)
@clear
@valgrind ./$(BINARY) -leak-check=full
clean:
@echo Cleaning up!
$(RM) $(BINARY) $(TSTBINARY) $(OBJECTDIR)* $(DEPENDDIR)*
build: $(OBJECTDIR) $(DEPENDDIR) $(BINARY)
@echo
@echo Binary is built!
buildTests: $(OJBECTDIR) $(DEPENDDIR) $(TSTBINARY)
@echo
@echo Tests are built!
# Debug rules to output file lists to ensure
# all files are properly accounted for
printSources:
@echo $(SOURCES)
printTests:
@echo $(TSTSRCS)
printObjects:
@echo $(OBJECTS)
printDepends:
@echo $(DEPENDS)
.PHONY: run test gdb valgrind clean build buildTests printSources printObjects printDepends printTests
# ==============================================
# Compilation rules
# ==============================================
# makes binary
$(BINARY): $(OBJECTS)
@echo
@echo Linking objects!
@$(CXX) $(CXXFLAGS) $(CXXLIBS) $+ -o $(BINARY)
# Makes test binary (depends on all standard objects but main)
$(TSTBINARY): $(TSTOBJS) $(filter-out $(OBJECTDIR)main.o, $(OBJECTS))
@echo
@echo Linking tests!
@$(CXX) $(CXXFLAGS) $(CXXLIBS) $+ -o $(TSTBINARY)
# implicit .cpp file to .o file
# generates dependencies on an object-to-object
# basis at compile time using the "-M" flags
#
# As we have two directories with code,
# we create two copies of the rule below,
# one for each working directory, using eval
define define_compile_rules
$(OBJECTDIR)%.o: $(1)%.cpp
@echo
@echo Compiling $$<
@$(CXX) $(CXXFLAGS) -MMD -MP -MF $(DEPENDDIR)$$*.d -c $$< -o $$@
endef
$(eval $(call define_compile_rules, $(SOURCEDIR)))
$(eval $(call define_compile_rules, $(TESTDIR)))
# makes folders if needed
$(OBJECTDIR):
mkdir $(OBJECTDIR)
$(DEPENDDIR):
mkdir $(DEPENDDIR)
#include dependancies
-include $(DEPENDS)
-include $(TSTDEPS)