Skip to content

Commit 2489b2d

Browse files
committed
fix: handle paths containing spaces in Makefiles
1 parent 01756f7 commit 2489b2d

3 files changed

Lines changed: 60 additions & 59 deletions

File tree

Makefile

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ PATHINSTCFG=$(DESTDIR)/$(CONFIGPATH)
5757
PATHINSTDOC=$(DESTDIR)/$(DOCPATH)
5858

5959
# Current directory
60-
CURRENTDIR=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
60+
CURRENTDIR=$(CURDIR)/
6161

6262
# Target directory
63-
TARGETDIR=$(CURRENTDIR)target
63+
TARGETDIR=target
6464

6565
# RPM Packaging path (where RPMs will be stored)
6666
PATHRPMPKG=$(TARGETDIR)/RPM
@@ -122,41 +122,41 @@ buildall: deps format qa bz2 rpm deb
122122
## Package the library in a compressed bz2 archive
123123
.PHONY: bz2
124124
bz2:
125-
rm -rf $(PATHBZ2PKG)
126-
make install DESTDIR=$(PATHBZ2PKG)
127-
tar -jcvf $(PATHBZ2PKG)/$(PKGNAME)-$(VERSION)-$(RELEASE).tbz2 -C $(PATHBZ2PKG) $(DATADIR)
125+
rm -rf "$(PATHBZ2PKG)"
126+
make install DESTDIR="$(PATHBZ2PKG)"
127+
tar -jcvf "$(PATHBZ2PKG)/$(PKGNAME)-$(VERSION)-$(RELEASE).tbz2" -C "$(PATHBZ2PKG)" "$(DATADIR)"
128128

129129
## Delete the vendor and target directories
130130
.PHONY: clean
131131
clean:
132-
rm -rf ./vendor $(TARGETDIR)
132+
rm -rf ./vendor "$(TARGETDIR)"
133133

134134
## Build a DEB package for Debian-like Linux distributions
135135
.PHONY: deb
136136
deb:
137-
rm -rf $(PATHDEBPKG)
138-
$(MAKE) install DESTDIR=$(PATHDEBPKG)/$(PKGNAME)-$(VERSION)
139-
rm -f $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/$(DOCPATH)LICENSE
140-
tar -zcvf $(PATHDEBPKG)/$(PKGNAME)_$(VERSION).orig.tar.gz -C $(PATHDEBPKG)/ $(PKGNAME)-$(VERSION)
141-
cp -rf ./resources/debian $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian
142-
find $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/ -type f -name '*.bak' -delete
143-
chmod 755 $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/rules
144-
find $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/ -type f -exec sed $(SEDINPLACE) "s/~#DATE#~/`date -R`/" {} \;
145-
find $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/ -type f -exec sed $(SEDINPLACE) "s/~#VENDOR#~/$(VENDOR)/" {} \;
146-
find $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/ -type f -exec sed $(SEDINPLACE) "s/~#PROJECT#~/$(PROJECT)/" {} \;
147-
find $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/ -type f -exec sed $(SEDINPLACE) "s/~#PKGNAME#~/$(PKGNAME)/" {} \;
148-
find $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/ -type f -exec sed $(SEDINPLACE) "s/~#VERSION#~/$(VERSION)/" {} \;
149-
find $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/ -type f -exec sed $(SEDINPLACE) "s/~#RELEASE#~/$(RELEASE)/" {} \;
150-
echo $(LIBPATH) > $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/$(PKGNAME).dirs
151-
echo "$(LIBPATH)* $(LIBPATH)" > $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/install
152-
echo $(DOCPATH) >> $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/$(PKGNAME).dirs
153-
echo "$(DOCPATH)* $(DOCPATH)" >> $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/install
137+
rm -rf "$(PATHDEBPKG)"
138+
$(MAKE) install DESTDIR="$(PATHDEBPKG)/$(PKGNAME)-$(VERSION)"
139+
rm -f "$(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/$(DOCPATH)LICENSE"
140+
tar -zcvf "$(PATHDEBPKG)/$(PKGNAME)_$(VERSION).orig.tar.gz" -C "$(PATHDEBPKG)/" "$(PKGNAME)-$(VERSION)"
141+
cp -rf ./resources/debian "$(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian"
142+
find "$(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/" -type f -name '*.bak' -delete
143+
chmod 755 "$(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/rules"
144+
find "$(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/" -type f -exec sed $(SEDINPLACE) "s/~#DATE#~/`date -R`/" {} \;
145+
find "$(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/" -type f -exec sed $(SEDINPLACE) "s/~#VENDOR#~/$(VENDOR)/" {} \;
146+
find "$(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/" -type f -exec sed $(SEDINPLACE) "s/~#PROJECT#~/$(PROJECT)/" {} \;
147+
find "$(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/" -type f -exec sed $(SEDINPLACE) "s/~#PKGNAME#~/$(PKGNAME)/" {} \;
148+
find "$(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/" -type f -exec sed $(SEDINPLACE) "s/~#VERSION#~/$(VERSION)/" {} \;
149+
find "$(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/" -type f -exec sed $(SEDINPLACE) "s/~#RELEASE#~/$(RELEASE)/" {} \;
150+
echo "$(LIBPATH)" > "$(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/$(PKGNAME).dirs"
151+
echo "$(LIBPATH)* $(LIBPATH)" > "$(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/install"
152+
echo "$(DOCPATH)" >> "$(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/$(PKGNAME).dirs"
153+
echo "$(DOCPATH)* $(DOCPATH)" >> "$(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/install"
154154
ifneq ($(strip $(CONFIGPATH)),)
155-
echo $(CONFIGPATH) >> $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/$(PKGNAME).dirs
156-
echo "$(CONFIGPATH)* $(CONFIGPATH)" >> $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/install
155+
echo "$(CONFIGPATH)" >> "$(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/$(PKGNAME).dirs"
156+
echo "$(CONFIGPATH)* $(CONFIGPATH)" >> "$(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/install"
157157
endif
158-
echo "new-package-should-close-itp-bug" > $(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/$(PKGNAME).lintian-overrides
159-
cd $(PATHDEBPKG)/$(PKGNAME)-$(VERSION) && debuild -us -uc
158+
echo "new-package-should-close-itp-bug" > "$(PATHDEBPKG)/$(PKGNAME)-$(VERSION)/debian/$(PKGNAME).lintian-overrides"
159+
cd "$(PATHDEBPKG)/$(PKGNAME)-$(VERSION)" && debuild -us -uc
160160

161161
## Clean all artifacts and download all dependencies
162162
.PHONY: deps
@@ -168,36 +168,36 @@ deps: ensuretarget
168168
## Generate source code documentation
169169
.PHONY: doc
170170
doc: ensuretarget
171-
rm -rf $(TARGETDIR)/doc
172-
$(PHPDOC) -d ./src -t $(TARGETDIR)/doc/
171+
rm -rf "$(TARGETDIR)/doc"
172+
$(PHPDOC) -d ./src -t "$(TARGETDIR)/doc/"
173173

174174
## Create missing target directories for test and build artifacts
175175
.PHONY: ensuretarget
176176
ensuretarget:
177-
mkdir -p $(TARGETDIR)/test
178-
mkdir -p $(TARGETDIR)/report
179-
mkdir -p $(TARGETDIR)/doc
177+
mkdir -p "$(TARGETDIR)/test"
178+
mkdir -p "$(TARGETDIR)/report"
179+
mkdir -p "$(TARGETDIR)/doc"
180180

181181
## Install this application
182182
.PHONY: install
183183
install: uninstall
184-
mkdir -p $(PATHINSTBIN)
185-
cp -rf ./src/* $(PATHINSTBIN)
186-
cp -f ./resources/autoload.php $(PATHINSTBIN)
187-
find $(PATHINSTBIN) -type d -exec chmod 755 {} \;
188-
find $(PATHINSTBIN) -type f -exec chmod 644 {} \;
189-
mkdir -p $(PATHINSTDOC)
190-
cp -f ./LICENSE $(PATHINSTDOC)
191-
cp -f ./README.md $(PATHINSTDOC)
192-
cp -f ./VERSION $(PATHINSTDOC)
193-
cp -f ./RELEASE $(PATHINSTDOC)
194-
chmod -R 644 $(PATHINSTDOC)*
184+
mkdir -p "$(PATHINSTBIN)"
185+
cp -rf ./src/* "$(PATHINSTBIN)"
186+
cp -f ./resources/autoload.php "$(PATHINSTBIN)"
187+
find "$(PATHINSTBIN)" -type d -exec chmod 755 {} \;
188+
find "$(PATHINSTBIN)" -type f -exec chmod 644 {} \;
189+
mkdir -p "$(PATHINSTDOC)"
190+
cp -f ./LICENSE "$(PATHINSTDOC)"
191+
cp -f ./README.md "$(PATHINSTDOC)"
192+
cp -f ./VERSION "$(PATHINSTDOC)"
193+
cp -f ./RELEASE "$(PATHINSTDOC)"
194+
chmod -R 644 "$(PATHINSTDOC)"*
195195
ifneq ($(strip $(CONFIGPATH)),)
196-
mkdir -p $(PATHINSTCFG)
197-
touch -c $(PATHINSTCFG)*
198-
cp -ru ./resources/${CONFIGPATH}* $(PATHINSTCFG)
199-
find $(PATHINSTCFG) -type d -exec chmod 755 {} \;
200-
find $(PATHINSTCFG) -type f -exec chmod 644 {} \;
196+
mkdir -p "$(PATHINSTCFG)"
197+
touch -c "$(PATHINSTCFG)"*
198+
cp -ru "./resources/${CONFIGPATH}"* "$(PATHINSTCFG)"
199+
find "$(PATHINSTCFG)" -type d -exec chmod 755 {} \;
200+
find "$(PATHINSTCFG)" -type f -exec chmod 644 {} \;
201201
endif
202202

203203
## Format the source code
@@ -221,18 +221,19 @@ qa: ensuretarget lint test report
221221
.PHONY: report
222222
report: ensuretarget
223223
#./vendor/bin/phpcpd --exclude vendor --exclude src/Encoding.php src > $(TARGETDIR)/report/phpcpd.txt
224-
./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
224+
./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
225225
#./vendor/bartlett/php-compatinfo/bin/phpcompatinfo --no-ansi analyser:run src/ > $(TARGETDIR)/report/phpcompatinfo.txt
226226

227227
## Build the RPM package for RedHat-like Linux distributions
228228
.PHONY: rpm
229229
rpm:
230-
rm -rf $(PATHRPMPKG)
231-
mkdir -p $(RPMDBPATH) $(PATHRPMPKG)/tmp
230+
@test $(words $(CURDIR)) -eq 1 || { echo "ERROR: rpmbuild does not support spaces in the project path: $(CURDIR)"; exit 1; }
231+
rm -rf "$(PATHRPMPKG)"
232+
mkdir -p "$(RPMDBPATH)" "$(PATHRPMPKG)/tmp"
232233
rpmbuild \
233-
--define "_topdir $(PATHRPMPKG)" \
234-
--define "_dbpath $(RPMDBPATH)" \
235-
--define "_tmppath $(PATHRPMPKG)/tmp" \
234+
--define "_topdir $(CURRENTDIR)$(PATHRPMPKG)" \
235+
--define "_dbpath $(CURRENTDIR)$(RPMDBPATH)" \
236+
--define "_tmppath $(CURRENTDIR)$(PATHRPMPKG)/tmp" \
236237
--define "_vendor $(VENDOR)" \
237238
--define "_owner $(OWNER)" \
238239
--define "_project $(PROJECT)" \
@@ -268,8 +269,8 @@ test:
268269
## Remove all installed files
269270
.PHONY: uninstall
270271
uninstall:
271-
rm -rf $(PATHINSTBIN)
272-
rm -rf $(PATHINSTDOC)
272+
rm -rf "$(PATHINSTBIN)"
273+
rm -rf "$(PATHINSTDOC)"
273274

274275
## Increase the version patch number
275276
.PHONY: versionup

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.6.3
1+
2.6.4

resources/rpm/rpm.spec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ PHP library containing Unicode definitions
2626
#(cd %{_current_directory} && make build)
2727

2828
%install
29-
rm -rf %{buildroot}
30-
(cd %{_current_directory} && make install DESTDIR=%{buildroot})
29+
rm -rf "%{buildroot}"
30+
(cd "%{_current_directory}" && make install DESTDIR="%{buildroot}")
3131

3232
%files
3333
%attr(-,root,root) %{_libpath}

0 commit comments

Comments
 (0)