Skip to content

Commit

Permalink
Merge pull request #652 from jimklimov/issue-646
Browse files Browse the repository at this point in the history
Fix `make install` of Perl modules with a custom `DESTDIR` and/or `libdir`
  • Loading branch information
oetiker committed May 28, 2024
2 parents 23f0923 + a298fc4 commit a5480d1
Show file tree
Hide file tree
Showing 7 changed files with 712 additions and 11 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ missingpool
Mkbootstrap
mkdir
mkdirprog
Mksymlists
modled
mojolicious
Morbo
Expand Down Expand Up @@ -413,6 +414,7 @@ passphrase
passwordless
perl
perldoc
PEVANS
pfexec
php
pid
Expand All @@ -436,7 +438,7 @@ posix
prebuilt
precmd
prefork
PREREQ
prereq
primarycache
printf
printsrc
Expand Down Expand Up @@ -470,6 +472,7 @@ resync
RETVAL
RHEL
rindex
RJBS
rmcmd
rmdir
rmprog
Expand Down Expand Up @@ -516,6 +519,7 @@ sourcemissing
sourcetype
sourcing
SPAMALOT
spamming
src
srcame
srcdir
Expand Down
4 changes: 1 addition & 3 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
0.22.1 2024-05-03 10:20:29 +0200 Tobias Oetiker <tobi@oetiker.ch>

-
* Fix make install of Perl modules with a custom DESTDIR and/or libdir @jimklimov

znapzend (0.22.0) unstable; urgency=medium

Expand Down
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SUFFIXES = .1 .man .pm
SUBDIRS = lib thirdparty debian

BIN = bin/@PACKAGE@ bin/znapzendzetup bin/znapzendztatz
PM = @PERL_MODULES@
PM = @PERL_MODULES_EXTRA_DIST@
MAN = man/znapzend.1 man/znapzendzetup.1 man/znapzendztatz.1
POD = doc/znapzend.pod doc/znapzendzetup.pod doc/znapzendztatz.pod

Expand Down
7 changes: 6 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,13 @@ AC_MSG_RESULT(way to expensive!)
AC_ARG_VAR(PERL5LIB, [Colon separated list of perl library directories])
AC_SUBST(PERL5LIB)

AC_MSG_CHECKING([for PERL_MODULES_EXTRA_DIST])
PERL_MODULES_EXTRA_DIST="`find "${srcdir}/lib/" -name "*.pm" | sed "s,^${srcdir}/,"'$(top_srcdir)/', | tr '\n' ' '`"
AC_MSG_RESULT([${PERL_MODULES_EXTRA_DIST}])
AC_SUBST(PERL_MODULES_EXTRA_DIST)

AC_MSG_CHECKING([for PERL_MODULES])
PERL_MODULES="`find "${srcdir}/lib/" -name "*.pm" | sed "s,^${srcdir}/,"'$(top_srcdir)/', | tr '\n' ' '`"
PERL_MODULES="`cd "${srcdir}/lib/" && ( find . -name "*.pm" | sed 's,^\./,,' | tr '\n' ' ' )`"
AC_MSG_RESULT([${PERL_MODULES}])
AC_SUBST(PERL_MODULES)

Expand Down
51 changes: 46 additions & 5 deletions thirdparty/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,79 @@ EXTRA_DIST = bin/cpanm cpanfile*snapshot

all-local: touch

# NOTE: CPANM pulls a number of dependencies which seem to get installed in
# parallel - in a random chaotic order (pun intended), so a few iterations
# may be required - up to the amount of dependencies in the worst case.
# It seems that neutering inheritance of parallel/nested "make" also helps;
# alternately properly annotating such inheritance (`+` starting the line)
# might also help. Trying both belts and suspenders here.
# To add injury to insult, CPANM also uses `make` and is impacted by e.g.
# the DESTDIR setting (if caller of znapzend `make` passes one) which may
# also be made known via MAKEFLAGS (as of GNU Make).
touch: bin/cpanm carton/bin/carton $(CPANSNAPV)
$(AM_V_at)echo "** Installing Dependencies using $(CPANSNAPV)"
cp $(CPANSNAPV) ../cpanfile.snapshot
# if ever DBD::ODBC is compiled, make sure we get the utf8 version
PERL_CPANM_OPT= PERL_CPANM_HOME=$(THIRDPARTY_DIR) DBD_ODBC_UNICODE=1 PERL5LIB=$(THIRDPARTY_DIR)/carton/lib/perl5 PERL_CARTON_PATH=$(THIRDPARTY_DIR) $(PERL) $(THIRDPARTY_DIR)/carton/bin/carton install
+$(AM_V_at)TRIES=5 ; unset DESTDIR || true ; unset MAKEFLAGS || true ; \
while test "$${TRIES}" -gt 0 ; do \
PERL_CPANM_OPT= PERL_CPANM_HOME=$(THIRDPARTY_DIR) DBD_ODBC_UNICODE=1 PERL5LIB=$(THIRDPARTY_DIR)/carton/lib/perl5 PERL_CARTON_PATH=$(THIRDPARTY_DIR) $(PERL) $(THIRDPARTY_DIR)/carton/bin/carton install \
&& exit ; \
TRIES="`expr $${TRIES} - 1`" ; \
echo "** RETRY Installing Dependencies using $(CPANSNAPV) (attempts left: $${TRIES})" ; \
MAKEFLAGS="" ; export MAKEFLAGS ; \
done
$(AM_V_at)rm -f ../cpanfile.snapshot
$(AM_V_at)touch touch

bin/cpanm:
$(AM_V_at)echo "** Installing CPANM tool"
$(AM_V_at)mkdir -p bin
$(URL_CAT) https://cpanmin.us > bin/cpanm
$(AM_V_at)chmod 755 bin/cpanm

carton/bin/carton: bin/cpanm
test -x carton/bin/carton || PERL_CPANM_OPT= PERL_CPANM_HOME=$(THIRDPARTY_DIR) $(PERL) bin/cpanm -q --notest --local-lib-contained $(THIRDPARTY_DIR)/carton Carton Date::Parse
$(AM_V_at)echo "** Installing/Checking Carton tool"
+$(AM_V_at)TRIES=5 ; unset DESTDIR || true ; unset MAKEFLAGS || true ; \
while ! test -x carton/bin/carton ; do \
PERL_CPANM_OPT= PERL_CPANM_HOME=$(THIRDPARTY_DIR) $(PERL) bin/cpanm -q --notest --local-lib-contained $(THIRDPARTY_DIR)/carton Carton Date::Parse \
&& exit ; \
TRIES="`expr $${TRIES} - 1`" ; \
if test "$${TRIES}" -lt 1 ; then exit 1 ; fi ; \
echo "** RETRY Installing/Checking Carton tool (attempts left: $${TRIES})" ; \
MAKEFLAGS="" ; export MAKEFLAGS ; \
done
test -x carton/bin/carton

$(CPANSNAPV): ../cpanfile carton/bin/carton
$(AM_V_at)echo "** Installing Dependencies using Carton install"
test -f $(CPANSNAPV) && cp $(CPANSNAPV) ../cpanfile.snapshot || true
# if ever DBD::ODBC is compiled, make sure we get the utf8 version
PERL_CPANM_OPT= PERL_CPANM_HOME=$(THIRDPARTY_DIR) DBD_ODBC_UNICODE=1 PERL5LIB=$(THIRDPARTY_DIR)/carton/lib/perl5 PERL_CARTON_PATH=$(THIRDPARTY_DIR) $(PERL) $(THIRDPARTY_DIR)/carton/bin/carton install
+$(AM_V_at)TRIES=5 ; unset DESTDIR || true ; unset MAKEFLAGS || true ; \
while test "$${TRIES}" -gt 0 ; do \
PERL_CPANM_OPT= PERL_CPANM_HOME=$(THIRDPARTY_DIR) DBD_ODBC_UNICODE=1 PERL5LIB=$(THIRDPARTY_DIR)/carton/lib/perl5 PERL_CARTON_PATH=$(THIRDPARTY_DIR) $(PERL) $(THIRDPARTY_DIR)/carton/bin/carton install \
&& exit ; \
TRIES="`expr $${TRIES} - 1`" ; \
echo "** RETRY Installing Dependencies using $(CPANSNAPV) (attempts left: $${TRIES})" ; \
MAKEFLAGS="" ; export MAKEFLAGS ; \
done
mv ../cpanfile.snapshot $(CPANSNAPV)
$(AM_V_at)touch touch

update: $(CPANSNAPV)
$(AM_V_at)echo "** Updating Dependencies using Carton update"
$(AM_V_at)cp $(CPANSNAPV) ../cpanfile.snapshot
$(AM_V_at)PERL_CPANM_OPT= PERL_CPANM_HOME=$(THIRDPARTY_DIR) PERL5LIB=$(THIRDPARTY_DIR)/carton/lib/perl5 PERL_CARTON_PATH=$(THIRDPARTY_DIR) $(PERL) $(THIRDPARTY_DIR)/carton/bin/carton update
+$(AM_V_at)TRIES=5 ; unset DESTDIR || true ; unset MAKEFLAGS || true ; \
while test "$${TRIES}" -gt 0 ; do \
$(AM_V_at)PERL_CPANM_OPT= PERL_CPANM_HOME=$(THIRDPARTY_DIR) PERL5LIB=$(THIRDPARTY_DIR)/carton/lib/perl5 PERL_CARTON_PATH=$(THIRDPARTY_DIR) $(PERL) $(THIRDPARTY_DIR)/carton/bin/carton update \
&& exit ; \
TRIES="`expr $${TRIES} - 1`" ; \
echo "** RETRY Installing Dependencies using $(CPANSNAPV) (attempts left: $${TRIES})" ; \
MAKEFLAGS="" ; export MAKEFLAGS ; \
done
$(AM_V_at)mv ../cpanfile.snapshot $(CPANSNAPV)

clean-local:
ls -1 | grep -v Makefile | grep -v cpanfile |grep -v bin | xargs rm -rf
ls -1 | grep -v Makefile | grep -v cpanfile | grep -v bin | xargs rm -rf

distclean-local:
ls -1 | grep -v Makefile | grep -v cpanfile | xargs rm -rf
Expand Down
Loading

0 comments on commit a5480d1

Please sign in to comment.