-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
338 lines (273 loc) · 11.3 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
#-----------------------------------------------------------------------------
#
# TSDuck - The MPEG Transport Stream Toolkit
# Copyright (c) 2005-2023, Thierry Lelegard
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
#
#-----------------------------------------------------------------------------
#
# Root makefile for the TSDuck project.
#
# Additional options which can be defined:
#
# - NOTEST : Do not build unitary tests.
# - NODEKTEC : No Dektec device support, remove dependency to DTAPI.
# - NOHIDES : No HiDes device support.
# - NOVATEK : No Vatek-based device support.
# - NOCURL : No HTTP support, remove dependency to libcurl.
# - NOPCSC : No smartcard support, remove dependency to pcsc-lite.
# - NOSRT : No SRT support, remove dependency to libsrt.
# - NORIST : No RIST support, remove dependency to librist.
# - NOEDITLINE : No interactive line editing, remove dependency to libedit.
# - NOTELETEXT : No Teletext support, remove teletext handling code.
# - NOGITHUB : No version check, no download, no upgrade from GitHub.
#
# Options to define the representation of bitrates:
#
# - BITRATE_INTEGER : Bitrates are 64-bit integer.
# - BITRATE_FRACTION : Bitrates are fractions of two 64-bit integers.
# - BITRATE_FLOAT : Bitrates are 64-bit floating-point.
# - BITRATE_FIXED : Bitrates are 64-bit fixed-point.
# - BITRATE_DECIMALS=n : Number of decimal with fixed-point (default: 1).
#
#-----------------------------------------------------------------------------
include Makefile.inc
# By default, update git hooks and build TSDuck binaries.
default: git-hooks
@$(MAKE) -C src $@
# Build and run all tests.
.PHONY: test-all
test-all: test test-suite
# Build and run unitary tests.
.PHONY: test
test: default
@$(MAKE) -C src/utest $@
# Execute the TSDuck test suite from a sibling directory, if present.
.PHONY: test-suite
test-suite: default
@if [[ -d ../tsduck-test/.git ]]; then \
cd ../tsduck-test; git pull; ./run-all-tests.sh --bin "$(BINDIR)"; \
elif [[ -x ../tsduck-test/run-all-tests.sh ]]; then \
../tsduck-test/run-all-tests.sh --bin "$(BINDIR)"; \
else \
echo >&2 "No test repository in ../tsduck-test"; \
fi
# Alternative target to build with cross-compilation
.PHONY: cross
cross:
+@$(MAKE) CROSS=true
# Alternative target to recompile with debug options
.PHONY: debug
debug:
+@$(MAKE) DEBUG=true
# Alternative target to recompile with optimizations for reduced code size.
.PHONY: optsize
optsize:
+@$(MAKE) CXXFLAGS_OPTIMIZE="$(CXXFLAGS_OPTSIZE)"
# Alternative target to recompile with LLVM (clang) compiler
.PHONY: llvm clang
llvm clang:
+@$(MAKE) LLVM=true
# Alternative target to recompile with gcov support.
.PHONY: gcov
gcov:
+@$(MAKE) DEBUG=true GCOV=true
# Alternative target to recompile with gprof support.
.PHONY: gprof
gprof:
+@$(MAKE) DEBUG=true GPROF=true
# Alternative target to recompile for 32-bit target
.PHONY: m32
m32:
+@$(MAKE) M32=true
# Generate the documentation.
.PHONY: doxygen
doxygen:
@doc/build-doxygen.sh
# Cleanup utilities
.PHONY: clean distclean
clean distclean:
@$(PYTHON) $(SCRIPTSDIR)/cleanup.py
# Build the sample applications.
.PHONY: sample
sample:
@$(MAKE) -C sample $@
# Display the built version
.PHONY: show-version
show-version: default
@$(BINDIR)/tsversion --version=all
# Install files, using SYSROOT as target system root if necessary.
.PHONY: install install-tools install-devel
install install-tools install-devel:
@$(MAKE) NOTEST=true -C src $@
# Build the source tarball for distribution.
VERSION = $(shell $(SCRIPTSDIR)/get-version-from-sources.py)
DISTRO = $(shell $(SCRIPTSDIR)/get-version-from-sources.py --distro)
TARNAME = tsduck-$(VERSION)
TARFILE = $(INSTALLERDIR)/$(TARNAME).tgz
TMPROOT = $(INSTALLERDIR)/tmp
.PHONY: tarball
tarball:
rm -rf $(TMPROOT)
mkdir -p $(TMPROOT)/$(TARNAME)
$(TAR) -cpf - sample/sample-*/japanese-tables.bin \
$(patsubst %,--exclude '%',.git $(if $(NOTELETEXT),tsTeletextDemux.* tsTeletextPlugin.*) $(shell cat .gitignore)) \
. | $(TAR) -C $(TMPROOT)/$(TARNAME) -xpf -
$(if $(NOTELETEXT),$(SED) -i -e '/TeletextDemux/d' -e '/TeletextPlugin/d' $(TMPROOT)/$(TARNAME)/src/libtsduck/tsduck.h)
$(MAKE) -C $(TMPROOT)/$(TARNAME) distclean
$(TAR) -C $(TMPROOT) -czf $(TARFILE) -p --owner=0 --group=0 $(TARNAME)
rm -rf $(TMPROOT)
# Installer target: rpm or deb.
INSTALLER_TYPE = $(if $(wildcard /etc/*fedora* /etc/*redhat*),rpm,$(if $(wildcard /etc/*debian*),deb))
.PHONY: installer install-installer
installer: $(INSTALLER_TYPE)
install-installer: install-$(INSTALLER_TYPE)
# User's RPM build area.
RPMBUILDROOT ?= $(HOME)/rpmbuild
$(RPMBUILDROOT):
rpmdev-setuptree
# RPM package building (Red Hat, Fedora, CentOS, Alma Linux, Rocky Linux, Oracle Linux, etc.)
# The build will take place elsewhere, reuse local Dektec Linux SDK if present.
RPMBUILD ?= rpmbuild
RPMBUILDFLAGS = -ba --clean $(if $(M32),--target $(MAIN_ARCH) -D 'mflags M32=true') $(RPMBUILDFLAGS_EXTRA)
RPM_ARCH = $(shell uname -m)
.PHONY: rpm rpm32
rpm: tarball $(RPMBUILDROOT)
cp -f $(TARFILE) $(RPMBUILDROOT)/SOURCES/
DTAPI_ORIGIN="$(shell $(SCRIPTSDIR)/dtapi-config.sh --tarball)" \
VATEK_SRC_ORIGIN="$(shell $(SCRIPTSDIR)/vatek-config.sh --src-tarball)" \
VATEK_BIN_ORIGIN="$(shell $(SCRIPTSDIR)/vatek-config.sh --bin-tarball)" \
$(RPMBUILD) $(RPMBUILDFLAGS) \
-D 'version $(shell $(SCRIPTSDIR)/get-version-from-sources.py --main)' \
-D 'commit $(shell $(SCRIPTSDIR)/get-version-from-sources.py --commit)' \
-D 'distro $(DISTRO)' \
-D '_smp_mflags $(MAKEFLAGS_SMP)' \
$(if $(NOSRT),-D 'nosrt 1') \
$(if $(NORIST),-D 'norist 1') \
$(if $(NOPCSC),-D 'nopcsc 1') \
$(if $(NOCURL),-D 'nocurl 1') \
$(if $(NOEDITLINE),-D 'noeditline 1') \
$(if $(NOVATEK),-D 'novatek 1') \
$(SCRIPTSDIR)/tsduck.spec
cp -uf $(RPMBUILDROOT)/RPMS/*/tsduck-$(VERSION)$(DISTRO).*.rpm $(INSTALLERDIR)
cp -uf $(RPMBUILDROOT)/RPMS/*/tsduck-devel-$(VERSION)$(DISTRO).*.rpm $(INSTALLERDIR)
cp -uf $(RPMBUILDROOT)/SRPMS/tsduck-$(VERSION)$(DISTRO).src.rpm $(INSTALLERDIR)
rpm32:
$(MAKE) rpm M32=true
install-rpm:
$(SUDO) rpm -Uvh $(INSTALLERDIR)/tsduck-$(VERSION)$(DISTRO).$(RPM_ARCH).rpm $(INSTALLERDIR)/tsduck-devel-$(VERSION)$(DISTRO).$(RPM_ARCH).rpm
# DEB package building (Debian, Ubuntu, Linux Mint, Raspbian, etc.)
# Make deb-dev depend on deb-tools to force serialization in case of -j.
DEB_ARCH = $(if $(wildcard /etc/*debian*),$(shell dpkg-architecture -qDEB_BUILD_ARCH))
.PHONY: deb deb-tools deb-dev
deb: deb-tools deb-dev
deb-tools:
rm -rf $(TMPROOT)
$(MAKE) $(MAKEFLAGS_SMP) NOTEST=true
$(MAKE) $(MAKEFLAGS_SMP) NOTEST=true install-tools SYSROOT=$(TMPROOT)
install -d -m 755 $(TMPROOT)$(SYSPREFIX)/share/doc/tsduck
install -m 644 CHANGELOG.txt LICENSE.txt OTHERS.txt doc/tsduck.pdf $(TMPROOT)$(SYSPREFIX)/share/doc/tsduck
mkdir $(TMPROOT)/DEBIAN
sed -e 's/{{VERSION}}/$(VERSION)$(DISTRO)/g' \
-e 's/{{ARCH}}/$(DEB_ARCH)/g' \
$(if $(NOSRT),-e '/libsrt/d') \
$(if $(NORIST),-e '/librist/d') \
$(if $(NOPCSC),-e '/libpcsc/d') \
$(if $(NOCURL),-e '/libcurl/d') \
$(if $(NOEDITLINE),-e '/libedit/d') \
$(if $(NOVATEK),-e '/libusb/d') \
$(SCRIPTSDIR)/tsduck.control >$(TMPROOT)/DEBIAN/control
dpkg-deb --build --root-owner-group $(TMPROOT) $(INSTALLERDIR)
rm -rf $(TMPROOT)
deb-dev: deb-tools
rm -rf $(TMPROOT)
$(MAKE) $(MAKEFLAGS_SMP) NOTEST=true
$(MAKE) $(MAKEFLAGS_SMP) NOTEST=true install-devel SYSROOT=$(TMPROOT)
mkdir $(TMPROOT)/DEBIAN
sed -e 's/{{VERSION}}/$(VERSION)$(DISTRO)/g' \
-e 's/{{ARCH}}/$(shell dpkg-architecture -qDEB_BUILD_ARCH)/g' \
$(if $(NOSRT),-e '/libsrt/d') \
$(if $(NORIST),-e '/librist/d') \
$(if $(NOPCSC),-e '/libpcsc/d') \
$(if $(NOCURL),-e '/libcurl/d') \
$(if $(NOEDITLINE),-e '/libedit/d') \
$(if $(NOVATEK),-e '/libusb/d') \
$(SCRIPTSDIR)/tsduck-dev.control >$(TMPROOT)/DEBIAN/control
dpkg-deb --build --root-owner-group $(TMPROOT) $(INSTALLERDIR)
rm -rf $(TMPROOT)
install-deb:
$(SUDO) dpkg -i $(INSTALLERDIR)/tsduck_$(VERSION)$(DISTRO)_$(DEB_ARCH).deb $(INSTALLERDIR)/tsduck-dev_$(VERSION)$(DISTRO)_$(DEB_ARCH).deb
# Install Git hooks.
.PHONY: git-hooks
git-hooks:
@$(PYTHON) $(SCRIPTSDIR)/git-hook-update.py
# Count lines of code: Run cloc on the source code tree starting at current directory.
CLOC = cloc
CLOC_SOURCES = src
CLOC_FLAGS = --skip-uniqueness --quiet --exclude-ext=.tgz,.tar.gz,.tar,.pdf,.pptx,.docx
.PHONY: cloc
cloc:
@$(CLOC) $(CLOC_FLAGS) $(CLOC_SOURCES) | \
tee /dev/stderr | grep SUM: | awk '{print "Total lines in source files: " $$3 + $$4 + $$5}'
@echo >&2 '-------------------------------------------'
# Static code analysis: Run Coverity.
COVERITY = cov-build
COVERITY_DIR = cov-int
COVERITY_SOURCES = src
.PHONY: coverity
coverity:
rm -rf $(COVERITY_DIR)
$(COVERITY) --dir $(COVERITY_DIR) $(MAKE) -C $(COVERITY_SOURCES)
$(TAR) czf $(COVERITY_DIR).tgz $(COVERITY_DIR)
# Static code analysis: Run cppcheck on the source code tree.
# In debug mode, the diagnostics are more aggressive but may be false positive.
CPPCHECK = cppcheck
CPPCHECK_SOURCES = src
CPPCHECK_FLAGS = $(CXXFLAGS_INCLUDES) --inline-suppr --quiet --force \
--template="{file}:{line}: ({severity}) {id}: {message}" \
--enable=all --suppress=unusedFunction --suppress=missingIncludeSystem \
$(if $(DEBUG),--inconclusive,)
.PHONY: cppcheck cppcheck-xml
cppcheck:
$(CPPCHECK) $(CPPCHECK_FLAGS) $(CPPCHECK_SOURCES)
cppcheck-xml:
$(CPPCHECK) $(CPPCHECK_FLAGS) --xml --xml-version=2 $(CPPCHECK_SOURCES)
# Static code analysis: Run flawfinder on the source code tree.
FLAWFINDER = flawfinder
FLAWFINDER_SOURCES = src
FLAWFINDER_FLAGS = --quiet --dataonly
.PHONY: flawfinder
flawfinder:
$(FLAWFINDER) $(FLAWFINDER_FLAGS) $(FLAWFINDER_SOURCES)
# Static code analysis: Run scan-build on the source code tree.
SCANBUILD = scan-build
SCANBUILD_SOURCES = src
SCANBUILD_FLAGS = -o $(BINDIR)
.PHONY: scan-build
scan-build:
$(SCANBUILD) $(SCANBUILD_FLAGS) $(MAKE) -C $(SCANBUILD_SOURCES)
# Utilities: display predefined macros for C++
.PHONY: cxxmacros
cxxmacros:
@$(CPP) $(CXXFLAGS) -x c++ -dM /dev/null | sort