-
-
Notifications
You must be signed in to change notification settings - Fork 219
/
Makefile
290 lines (241 loc) · 9.2 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
# Makefile
#
# @since 2015-02-21
# @category Library
# @package Pdf
# @author Nicola Asuni <info@tecnick.com>
# @copyright 2015-2024 Nicola Asuni - Tecnick.com LTD
# @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
# @link https://github.com/tecnickcom/tc-lib-pdf
#
# This file is part of tc-lib-pdf software library.
# ----------------------------------------------------------------------------------------------------------------------
SHELL=/bin/bash
.SHELLFLAGS=-o pipefail -c
# Project owner
OWNER=tecnickcom
# Project vendor
VENDOR=${OWNER}
# Project name
PROJECT=tc-lib-pdf
# Project version
VERSION=$(shell cat VERSION)
# Project release number (packaging build number)
RELEASE=$(shell cat RELEASE)
# Name of RPM or DEB package
PKGNAME=php-${OWNER}-${PROJECT}
# Data dir
DATADIR=usr/share
# PHP home folder
PHPHOME=${DATADIR}/php/Com/Tecnick
# Default installation path for code
LIBPATH=${PHPHOME}/Pdf/
# Path for configuration files (etc/$(PKGNAME)/)
CONFIGPATH=etc/$(PKGNAME)/
# Default installation path for documentation
DOCPATH=${DATADIR}/doc/$(PKGNAME)/
# Installation path for the code
PATHINSTBIN=$(DESTDIR)/$(LIBPATH)
# Installation path for the configuration files
PATHINSTCFG=$(DESTDIR)/$(CONFIGPATH)
# Installation path for documentation
PATHINSTDOC=$(DESTDIR)/$(DOCPATH)
# Current directory
CURRENTDIR=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
# Target directory
TARGETDIR=$(CURRENTDIR)target
# RPM Packaging path (where RPMs will be stored)
PATHRPMPKG=$(TARGETDIR)/RPM
# DEB Packaging path (where DEBs will be stored)
PATHDEBPKG=$(TARGETDIR)/DEB
# BZ2 Packaging path (where BZ2s will be stored)
PATHBZ2PKG=$(TARGETDIR)/BZ2
# Default port number for the example server
PORT?=8971
# PHP binary
PHP=$(shell which php)
# Composer executable (disable APC to as a work-around of a bug)
COMPOSER=$(PHP) -d "apc.enable_cli=0" $(shell which composer)
# phpDocumentor executable file
PHPDOC=$(shell which phpDocumentor)
# --- MAKE TARGETS ---
# Display general help about this command
.PHONY: help
help:
@echo ""
@echo "$(PROJECT) Makefile."
@echo "The following commands are available:"
@echo ""
@echo " make buildall : Build and test everything from scratch"
@echo " make bz2 : Package the library in a compressed bz2 archive"
@echo " make clean : Delete the vendor and target directories"
@echo " make codefix : Fix code style violations"
@echo " make deb : Build a DEB package for Debian-like Linux distributions"
@echo " make deps : Download all dependencies"
@echo " make doc : Generate source code documentation"
@echo " make fonts : Build default tc-font-mirror fonts via tc-lib-pdf-font"
@echo " make lint : Test source code for coding standard violations"
@echo " make qa : Run all tests and reports"
@echo " make report : Generate various reports"
@echo " make rpm : Build an RPM package for RedHat-like Linux distributions"
@echo " make server : Start the development server"
@echo " make test : Run unit tests"
@echo " make versionup: Increase the version patch number"
@echo ""
@echo "To test and build everything from scratch:"
@echo "make buildall"
@echo ""
# alias for help target
.PHONY: all
all: help
# Full build and test sequence
.PHONY: x
x: buildall
# Full build and test sequence
.PHONY: buildall
buildall: deps
cd vendor/tecnickcom/tc-lib-pdf-font/ && make buildall
$(MAKE) codefix qa bz2 rpm deb
# Package the library in a compressed bz2 archive
.PHONY: bz2
bz2:
rm -rf $(PATHBZ2PKG)
make install DESTDIR=$(PATHBZ2PKG)
tar -jcvf $(PATHBZ2PKG)/$(PKGNAME)-$(VERSION)-$(RELEASE).tbz2 -C $(PATHBZ2PKG) $(DATADIR)
# Delete the vendor and target directories
.PHONY: clean
clean:
rm -rf ./vendor $(TARGETDIR)
# Fix code style violations
.PHONY: codefix
codefix:
./vendor/bin/phpcbf --ignore="./vendor/" --standard=psr12 src test
# Build a DEB package for Debian-like Linux distributions
.PHONY: deb
deb:
rm -rf $(PATHDEBPKG)
make install DESTDIR=$(PATHDEBPKG)/$(PKGNAME)-$(VERSION)
rm -f $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/$(DOCPATH)LICENSE
tar -zcvf $(PATHDEBPKG)/$(PKGNAME)_$(VERSION).orig.tar.gz -C $(PATHDEBPKG)/ $(PKGNAME)-$(VERSION)
cp -rf ./resources/debian $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian
find $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/ -type f -exec sed -i "s/~#DATE#~/`date -R`/" {} \;
find $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/ -type f -exec sed -i "s/~#VENDOR#~/$(VENDOR)/" {} \;
find $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/ -type f -exec sed -i "s/~#PROJECT#~/$(PROJECT)/" {} \;
find $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/ -type f -exec sed -i "s/~#PKGNAME#~/$(PKGNAME)/" {} \;
find $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/ -type f -exec sed -i "s/~#VERSION#~/$(VERSION)/" {} \;
find $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/ -type f -exec sed -i "s/~#RELEASE#~/$(RELEASE)/" {} \;
echo $(LIBPATH) > $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/$(PKGNAME).dirs
echo "$(LIBPATH)* $(LIBPATH)" > $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/install
echo $(DOCPATH) >> $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/$(PKGNAME).dirs
echo "$(DOCPATH)* $(DOCPATH)" >> $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/install
ifneq ($(strip $(CONFIGPATH)),)
echo $(CONFIGPATH) >> $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/$(PKGNAME).dirs
echo "$(CONFIGPATH)* $(CONFIGPATH)" >> $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/install
endif
echo "new-package-should-close-itp-bug" > $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/$(PKGNAME).lintian-overrides
cd $(PATHDEBPKG)/$(PKGNAME)-$(VERSION) && debuild -us -uc
# Clean all artifacts and download all dependencies
.PHONY: deps
deps: ensuretarget
rm -rf ./vendor/*
($(COMPOSER) install -vvv --no-interaction)
curl --silent --show-error --fail --location --output ./vendor/phpstan.phar https://github.com/phpstan/phpstan/releases/download/1.10.41/phpstan.phar \
&& chmod +x ./vendor/phpstan.phar
# Generate source code documentation
.PHONY: doc
doc: ensuretarget
rm -rf $(TARGETDIR)/doc
$(PHPDOC) -d ./src -t $(TARGETDIR)/doc/
# Create missing target directories for test and build artifacts
.PHONY: ensuretarget
ensuretarget:
mkdir -p $(TARGETDIR)/test
mkdir -p $(TARGETDIR)/report
mkdir -p $(TARGETDIR)/doc
# Build default tc-font-mirror fonts via tc-lib-pdf-font
.PHONY: fonts
fonts:
cd vendor/tecnickcom/tc-lib-pdf-font/ && make deps fonts
# Install this application
.PHONY: install
install: uninstall
mkdir -p $(PATHINSTBIN)
cp -rf ./src/* $(PATHINSTBIN)
cp -f ./resources/autoload.php $(PATHINSTBIN)
find $(PATHINSTBIN) -type d -exec chmod 755 {} \;
find $(PATHINSTBIN) -type f -exec chmod 644 {} \;
mkdir -p $(PATHINSTDOC)
cp -f ./LICENSE $(PATHINSTDOC)
cp -f ./README.md $(PATHINSTDOC)
cp -f ./VERSION $(PATHINSTDOC)
cp -f ./RELEASE $(PATHINSTDOC)
chmod -R 644 $(PATHINSTDOC)*
ifneq ($(strip $(CONFIGPATH)),)
mkdir -p $(PATHINSTCFG)
touch -c $(PATHINSTCFG)*
cp -ru ./resources/${CONFIGPATH}* $(PATHINSTCFG)
find $(PATHINSTCFG) -type d -exec chmod 755 {} \;
find $(PATHINSTCFG) -type f -exec chmod 644 {} \;
endif
# Test source code for coding standard violations
.PHONY: lint
lint:
./vendor/bin/phpcs --ignore="./vendor/" --standard=phpcs.xml src test
./vendor/bin/phpmd src text unusedcode,naming,design --exclude vendor
./vendor/bin/phpmd test text unusedcode,naming,design
php -r 'exit((int)version_compare(PHP_MAJOR_VERSION, "7", ">"));' || ./vendor/phpstan.phar analyse
# Run all tests and reports
.PHONY: qa
qa: version ensuretarget lint test report
# Generate various reports
.PHONY: report
report: ensuretarget
./vendor/bin/pdepend --jdepend-xml=$(TARGETDIR)/report/dependencies.xml --summary-xml=$(TARGETDIR)/report/metrics.xml --jdepend-chart=$(TARGETDIR)/report/dependecies.svg --overview-pyramid=$(TARGETDIR)/report/overview-pyramid.svg --ignore=vendor ./src
#./vendor/bartlett/php-compatinfo/bin/phpcompatinfo --no-ansi analyser:run src/ > $(TARGETDIR)/report/phpcompatinfo.txt
# Build the RPM package for RedHat-like Linux distributions
.PHONY: rpm
rpm:
rm -rf $(PATHRPMPKG)
rpmbuild \
--define "_topdir $(PATHRPMPKG)" \
--define "_vendor $(VENDOR)" \
--define "_owner $(OWNER)" \
--define "_project $(PROJECT)" \
--define "_package $(PKGNAME)" \
--define "_version $(VERSION)" \
--define "_release $(RELEASE)" \
--define "_current_directory $(CURRENTDIR)" \
--define "_libpath /$(LIBPATH)" \
--define "_docpath /$(DOCPATH)" \
--define "_configpath /$(CONFIGPATH)" \
-bb resources/rpm/rpm.spec
# Start the development server
.PHONY: server
server:
$(PHP) -t examples -S localhost:$(PORT)
# Tag this GIT version
.PHONY: tag
tag:
git checkout main && \
git tag -a ${VERSION} -m "Release ${VERSION}" && \
git push origin --tags && \
git pull
# Run unit tests
.PHONY: test
test:
cp phpunit.xml.dist phpunit.xml
./vendor/bin/phpunit --migrate-configuration || true
XDEBUG_MODE=coverage ./vendor/bin/phpunit --stderr test
# Remove all installed files
.PHONY: uninstall
uninstall:
rm -rf $(PATHINSTBIN)
rm -rf $(PATHINSTDOC)
# set the version
version:
sed -i -e "s/protected string \$$version = '.*';/protected string \$$version = '${VERSION}';/g" src/Base.php
# Increase the version patch number
.PHONY: versionup
versionup:
echo ${VERSION} | gawk -F. '{printf("%d.%d.%d\n",$$1,$$2,(($$3+1)));}' > VERSION
$(MAKE) version