-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathMakefile
executable file
·350 lines (302 loc) · 10.6 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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
###############################################################################
## Makefile for compiling code
###############################################################################
# prefix set to /usr -> remove when ./configure is introduced
PREFIX=/usr
# Set the compiler being used.
CXX ?= $(CXXPREFIX)g++$(CXXSUFFIX)
# Check compiler support for some functions
RESULT_HAS_NP_FUNCTIONS := $(shell $(CXX) -o npfunc checks/npfunc.cpp -pthread 2> /dev/null ; echo $$? ; rm -rf npfunc)
RESULT_HAS_ATOMIC_FUNCTIONS := $(shell $(CXX) -o atomic checks/atomic.cpp 2> /dev/null ; echo $$? ; rm -rf atomic)
RESULT_HAS_BACKTRACE_FUNCTIONS := $(shell $(CXX) -o backtrace checks/backtrace.cpp 2> /dev/null ; echo $$? ; rm -rf backtrace)
RESULT_HAS_SYS_DVBS2X := $(shell $(CXX) -o sysdvb2sx checks/sysdvb2sx.cpp 2> /dev/null ; echo $$? ; rm -rf sysdvb2sx)
RESULT_HAS_STRING_VIEW := $(shell $(CXX) -std=c++17 -o string_view checks/string_view.cpp -pthread 2> /dev/null ; echo $$? ; rm -rf string_view)
# Includes needed for proper compilation
INCLUDES +=
LDFLAGS += $(CPU_FLAGS)
CFLAGS += $(CPU_FLAGS)
CFLAGS_OPT += $(CPU_FLAGS)
# Libraries needed for linking
LDFLAGS += -pthread -lrt
# Enable Backport mode (ancient compilers previous to C++17)
ifeq "$(RESULT_HAS_STRING_VIEW)" "1"
CFLAGS += -isystem nonstd -DNEED_BACKPORT
CFLAGS_OPT += -isystem nonstd -DNEED_BACKPORT
endif
ifeq "$(CPP11)" "yes"
CFLAGS += -isystem nonstd -DNEED_BACKPORT
CFLAGS_OPT += -isystem nonstd -DNEED_BACKPORT
endif
# RESULT_HAS_ATOMIC_FUNCTIONS = 1 if compile fails
ifeq "$(RESULT_HAS_ATOMIC_FUNCTIONS)" "1"
LDFLAGS += -latomic
endif
# RESULT_HAS_BACKTRACE_FUNCTIONS = 1 if compile fails
ifeq "$(RESULT_HAS_BACKTRACE_FUNCTIONS)" "1"
CFLAGS += -DHAS_NO_BACKTRACE_FUNCTIONS
CFLAGS_OPT += -DHAS_NO_BACKTRACE_FUNCTIONS
endif
# RESULT_HAS_SYS_DVBS2X = 1 if compile fails
ifeq "$(RESULT_HAS_SYS_DVBS2X)" "1"
CFLAGS += -DDEFINE_SYS_DVBS2X
CFLAGS_OPT += -DDEFINE_SYS_DVBS2X
endif
# RESULT_HAS_NP_FUNCTIONS = 0 if compile is succesfull which means NP are OK
ifeq "$(RESULT_HAS_NP_FUNCTIONS)" "0"
CFLAGS += -DHAS_NP_FUNCTIONS
CFLAGS_OPT += -DHAS_NP_FUNCTIONS
endif
# Set Compiler Flags
CFLAGS += -I src -std=c++17 -Werror=vla -Wall -Wextra -Winit-self -Wshadow -pthread $(INCLUDES)
CFLAGS_OPT += -I src -std=c++17 -Werror=vla -Wall -Wextra -Winit-self -Wshadow -pthread $(INCLUDES)
# Build "debug", "release" or "simu"
ifeq "$(BUILD)" "debug"
# "Debug" build - no optimization, with debugging symbols
CFLAGS += -O0 -g3 -gdwarf-2 -DDEBUG -DDEBUG_LOG -fstack-protector-all -Wswitch-default
CFLAGS_OPT += -O3 -s -DNDEBUG -DDEBUG_LOG
LDFLAGS += -rdynamic
else ifeq "$(BUILD)" "debug1"
# "Debug" build - with optimization, with debugging symbols
CFLAGS += -O0 -g3 -gdwarf-2 -DDEBUG -DDEBUG_LOG -fstack-protector-all -Wswitch-default
CFLAGS_OPT += -O0 -g3 -gdwarf-2 -DDEBUG -DDEBUG_LOG -fstack-protector-all -Wswitch-default
LDFLAGS += -rdynamic
else ifeq "$(BUILD)" "speed"
# "Debug" build - with optimization, without debugging symbols
CFLAGS += -Os -s -DNDEBUG
CFLAGS_OPT += -Os -s -DNDEBUG
else ifeq "$(BUILD)" "simu"
# "Debug Simu" build - no optimization, with debugging symbols
CFLAGS += -O0 -g3 -DDEBUG -DDEBUG_LOG -DSIMU -fstack-protector-all
CFLAGS_OPT += -O3 -s -DNDEBUG -DDEBUG_LOG
LDFLAGS += -rdynamic
else ifeq "$(BUILD)" "static"
CFLAGS += -O2 -s -DNDEBUG
CFLAGS_OPT += -O3 -s -DNDEBUG
LDFLAGS += -static
else
# "Release" build - optimization, and no debug symbols
CFLAGS += -O2 -s -DNDEBUG
CFLAGS_OPT += -O3 -s -DNDEBUG
LDFLAGS += -rdynamic
endif
# List of source to be compiled
SOURCES = Version.cpp \
InterfaceAttr.cpp \
HeaderVector.cpp \
HttpServer.cpp \
HttpcServer.cpp \
Log.cpp \
Properties.cpp \
RtspServer.cpp \
main.cpp \
Satpi.cpp \
Stream.cpp \
StreamManager.cpp \
StringConverter.cpp \
TransportParamVector.cpp \
Utils.cpp \
base/M3UParser.cpp \
base/Thread.cpp \
base/ThreadBase.cpp \
base/TimeCounter.cpp \
base/XMLSaveSupport.cpp \
base/XMLSupport.cpp \
input/DeviceData.cpp \
input/Transformation.cpp \
input/dvb/Frontend.cpp \
input/dvb/FrontendData.cpp \
input/dvb/delivery/DiSEqc.cpp \
input/dvb/delivery/DiSEqcEN50494.cpp \
input/dvb/delivery/DiSEqcEN50607.cpp \
input/dvb/delivery/DiSEqcLnb.cpp \
input/dvb/delivery/DiSEqcSwitch.cpp \
input/dvb/delivery/DVBC.cpp \
input/dvb/delivery/DVBS.cpp \
input/dvb/delivery/DVBT.cpp \
input/dvb/delivery/FBC.cpp \
input/dvb/delivery/Lnb.cpp \
input/file/TSReader.cpp \
input/file/TSReaderData.cpp \
input/childpipe/TSReader.cpp \
input/childpipe/TSReaderData.cpp \
input/stream/Streamer.cpp \
input/stream/StreamerData.cpp \
mpegts/Filter.cpp \
mpegts/Generator.cpp \
mpegts/NIT.cpp \
mpegts/PacketBuffer.cpp \
mpegts/PAT.cpp \
mpegts/PCR.cpp \
mpegts/PidTable.cpp \
mpegts/PMT.cpp \
mpegts/SDT.cpp \
mpegts/TableData.cpp \
output/StreamClient.cpp \
output/StreamClientOutputHttp.cpp \
output/StreamClientOutputRtp.cpp \
output/StreamClientOutputRtpTcp.cpp \
socket/HttpcSocket.cpp \
socket/TcpSocket.cpp \
socket/SocketAttr.cpp \
socket/UdpSocket.cpp \
upnp/ssdp/Server.cpp
# Add gprof, use gprof-helper.c for multithreading profiling
ifeq "$(GPROF)" "yes"
LDFLAGS += -pg
CFLAGS += -pg
endif
# Add dvbcsa ?
ifeq "$(LIBDVBCSA)" "yes"
LDFLAGS += -ldvbcsa -ldl
# CFLAGS += -DUSE_DEPRECATED_DVBAPI
CFLAGS += -DLIBDVBCSA
CFLAGS_OPT += -DLIBDVBCSA
SOURCES += decrypt/dvbapi/Client.cpp
SOURCES += decrypt/dvbapi/ClientProperties.cpp
SOURCES += decrypt/dvbapi/Keys.cpp
SOURCES += input/dvb/Frontend_DecryptInterface.cpp
endif
# Add dvbca ?
ifeq "$(DVBCA)" "yes"
CFLAGS += -DADDDVBCA
SOURCES += decrypt/dvbca/DVBCA.cpp
endif
# Need to build for Enigma support
ifeq "$(ENIGMA)" "yes"
CFLAGS += -DENIGMA
endif
# Sub dirs for project
OBJ_DIR = obj
SRC_DIR = src
# Get Version from git describe
ifneq ($(wildcard .git),)
VER1 = $(shell git describe --long --match "V*" 2> /dev/null)
ifeq ($(VER1),)
# Git describe failed. Adding "-unknown" postfix to mark this situation
VER1 = $(shell git describe --match "V*" 2> /dev/null)-unknown
endif
# Parse
VER = $(shell echo $(VER1) | sed "s/^V//" | sed "s/-\([0-9]*\)-\(g[0-9a-f]*\)/.\1~\2/")
else
VER = "1.6.2~unknown"
endif
# Do we build for ENIGMA, then add it to version string
FOUND_ENIGMA = $(findstring DENIGMA,$(CFLAGS))
ifneq ($(FOUND_ENIGMA),)
VER += "Enigma"
endif
# Create/Update Version.cpp
VER_FILE = "Version.cpp"
NEW_VER = "const char *satpi_version = \"$(VER)\";"
OLD_VER = $(shell cat $(SRC_DIR)/$(VER_FILE) 2> /dev/null | sed -n -e "/const / s/.*\= \"*//p" | sed -n -e "s/-*\";//p")
#OLD_VER = $(shell cat $(SRC_DIR)/$(VER_FILE) 2> /dev/null)
ifneq ($(NEW_VER), $(OLD_VER))
$(shell echo $(NEW_VER) > $(SRC_DIR)/$(VER_FILE))
endif
# Find all source (*.cpp) across the directories and make a list
SOURCES_UNC = $(shell find $(SRC_DIR)/ -type f -name '*.cpp')
# Find all headers (*.h) across the directories and make a list
HEADERS = $(shell find $(SRC_DIR)/ -type f -name '*.h')
# Objectlist is identical to Sourcelist except that all .cpp extensions need to be replaced by .o extension.
# and add OBJ_DIR to path
OBJECTS = $(SOURCES:%.cpp=$(OBJ_DIR)/%.o)
# Resulting Executable name
EXECUTABLE = satpi
# First rule is also the default rule
# generate the Executable from all the objects
# $@ represents the targetname
$(EXECUTABLE): $(OBJECTS) $(HEADERS)
$(CXX) $(OBJECTS) -o $@ $(LDFLAGS)
# A pattern rule is used to build objects from 'cpp' files
# $< represents the first item in the dependencies list
# $@ represents the targetname
$(OBJ_DIR)/mpegts/%.o: $(SRC_DIR)/mpegts/%.cpp $(HEADERS)
@mkdir -p $(@D)
$(CXX) -c $(CFLAGS_OPT) $< -o $@
$(OBJ_DIR)/decrypt/dvbapi/%.o: $(SRC_DIR)/decrypt/dvbapi/%.cpp $(HEADERS)
@mkdir -p $(@D)
$(CXX) -c $(CFLAGS_OPT) $< -o $@
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(HEADERS)
@mkdir -p $(@D)
$(CXX) -c $(CFLAGS) $< -o $@
# Create debug versions
debug:
$(MAKE) "BUILD=debug"
debug1:
$(MAKE) "BUILD=debug1" LIBDVBCSA=yes
static:
$(MAKE) "BUILD=static"
speed:
$(MAKE) "BUILD=speed" LIBDVBCSA=yes
# Create a 'simulation' version
simu:
$(MAKE) "BUILD=simu"
# Create a 'test suite' Compile
testsuite:
$(MAKE) clean
$(MAKE) debug LIBDVBCSA=yes
$(MAKE) clean
$(MAKE) debug
$(MAKE) clean
$(MAKE) LIBDVBCSA=yes
$(MAKE) clean
$(MAKE)
$(MAKE) clean
# Install Doxygen and Graphviz/dot
# sudo apt-get install graphviz doxygen
docu:
doxygen ./doxygen
help:
@echo "Help, use these command for building this project:"
@echo " - Make project clean : make clean"
@echo " - Make debug version : make debug"
@echo " - Make debug version with DVBAPI(ICAM) : make debug LIBDVBCSA=yes"
@echo " - Make debug version for ENIGMA : make debug ENIGMA=yes"
@echo " - Make production version with DVBAPI : make LIBDVBCSA=yes"
@echo " - Make production version with DVBAPI : make speed LIBDVBCSA=yes"
@echo " - Make PlantUML graph : make plantuml"
@echo " - Make Doxygen docmumentation : make docu"
@echo " - Make Uncrustify Code Beautifier : make uncrustify"
@echo " - Enable compatibility with non-C++17 : make non-c++17"
# Download PlantUML from http://plantuml.com/download.html
# and put it into the root of the project directory
# sudo apt-get install graphviz openjdk-7-jre
plantuml:
java -jar plantuml.jar -tsvg SatPI.plantuml
java -jar plantuml.jar -tpng SatPI.plantuml
uncrustify:
uncrustify -c SatPI.uncrustify --replace $(SOURCES_UNC)
uncrustify -c SatPI.uncrustify --replace $(HEADERS)
@echo uncrustify Done
# Enable compatibility with non-C++17 compilers
# wget -P backports/ https://github.com/Barracuda09/SATPI/pull/173.diff
non-c++17:
patch -p1 < backports/173.diff
@echo patching Done
checkcpp:
~/cppcheck/cppcheck -DENIGMA -DLIBDVBCSA -DDVB_API_VERSION=5 -DDVB_API_VERSION_MINOR=5 -I ./src --enable=all --std=posix --std=c++11 ./src 1> cppcheck.log 2>&1
.PHONY:
clean
clean:
@echo Clearing project...
@rm -rf testcode.c testcode ./obj $(EXECUTABLE) src/Version.cpp /web/*.*~
@rm -rf src/*.*~ src/*~
@echo ...Done
.PHONY: install
install: $(EXECUTABLE)
# install binary
mkdir -p $(DESTDIR)$(PREFIX)/bin
cp $< $(DESTDIR)$(PREFIX)/bin/$(EXECUTABLE)
# install systemd file
mkdir -p $(DESTDIR)/lib/systemd/system
cp data/satpi.service $(DESTDIR)/lib/systemd/system
# install web data
mkdir -p $(DESTDIR)/usr/share/satpi/web
cp -r web/* $(DESTDIR)/usr/share/satpi/web
# create data dir
mkdir -p $(DESTDIR)/var/lib/satpi
.PHONY: uninstall
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/$(EXECUTABLE)
rm -f $(DESTDIR)/lib/systemd/system/satpi.service
rm -f $(DESTDIR)/usr/share/satpi