Skip to content

Commit 20d2a30

Browse files
avargitster
authored andcommitted
Makefile: replace perl/Makefile.PL with simple make rules
Replace the perl/Makefile.PL and the fallback perl/Makefile used under NO_PERL_MAKEMAKER=NoThanks with a much simpler implementation heavily inspired by how the i18n infrastructure's build process works[1]. The reason for having the Makefile.PL in the first place is that it was initially[2] building a perl C binding to interface with libgit, this functionality, that was removed[3] before Git.pm ever made it to the master branch. We've since since started maintaining a fallback perl/Makefile, as MakeMaker wouldn't work on some platforms[4]. That's just the tip of the iceberg. We have the PM.stamp hack in the top-level Makefile[5] to detect whether we need to regenerate the perl/perl.mak, which I fixed just recently to deal with issues like the perl version changing from under us[6]. There is absolutely no reason for why this needs to be so complex anymore. All we're getting out of this elaborate Rube Goldberg machine was copying perl/* to perl/blib/* as we do a string-replacement on the *.pm files to hardcode @@LOCALEDIR@@ in the source, as well as pod2man-ing Git.pm & friends. So replace the whole thing with something that's pretty much a copy of how we generate po/build/**.mo from po/*.po, just with a small sed(1) command instead of msgfmt. As that's being done rename the files from *.pm to *.pmc just to indicate that they're generated (see "perldoc -f require"). While I'm at it, change the fallback for Error.pm from being something where we'll ship our own Error.pm if one doesn't exist at build time to one where we just use a Git::Error wrapper that'll always prefer the system-wide Error.pm, only falling back to our own copy if it really doesn't exist at runtime. It's now shipped as Git::FromCPAN::Error, making it easy to add other modules to Git::FromCPAN::* in the future if that's needed. Functional changes: * This will not always install into perl's idea of its global "installsitelib". This only potentially matters for packagers that need to expose Git.pm for non-git use, and as explained in the INSTALL file there's a trivial workaround. * The scripts themselves will 'use lib' the target directory, but if INSTLIBDIR is set it overrides it. It doesn't have to be this way, it could be set in addition to INSTLIBDIR, but my reading of [7] is that this is the desired behavior. * We don't build man pages for all of the perl modules as we used to, only Git(3pm). As discussed on-list[8] that we were building installed manpages for purely internal APIs like Git::I18N or private-Error.pm was always a bug anyway, and all the Git::SVN::* ones say they're internal APIs. There are apparently external users of Git.pm, but I don't expect there to be any of the others. As a side-effect of these general changes the perl documentation now only installed by install-{doc,man}, not a mere "install" as before. 1. 5e9637c ("i18n: add infrastructure for translating Git with gettext", 2011-11-18) 2. b1edc53 ("Introduce Git.pm (v4)", 2006-06-24) 3. 18b0fc1 ("Git.pm: Kill Git.xs for now", 2006-09-23) 4. f848718 ("Make perl/ build procedure ActiveState friendly.", 2006-12-04) 5. ee9be06 ("perl: detect new files in MakeMaker builds", 2012-07-27) 6. c59c493 ("perl: regenerate perl.mak if perl -V changes", 2017-03-29) 7. 0386dd3 ("Makefile: add PERLLIB_EXTRA variable that adds to default perl path", 2013-11-15) 8. [email protected] ("Re: [PATCH] Makefile: replace perl/Makefile.PL with simple make rules" Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1a4e40a commit 20d2a30

14 files changed

+106
-199
lines changed

INSTALL

+16-1
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,24 @@ Issues of note:
8484

8585
GIT_EXEC_PATH=`pwd`
8686
PATH=`pwd`:$PATH
87-
GITPERLLIB=`pwd`/perl/blib/lib
87+
GITPERLLIB=`pwd`/perl/build/lib
8888
export GIT_EXEC_PATH PATH GITPERLLIB
8989

90+
- By default (unless NO_PERL is provided) Git will ship various perl
91+
scripts & libraries it needs. However, for simplicity it doesn't
92+
use the ExtUtils::MakeMaker toolchain to decide where to place the
93+
perl libraries. Depending on the system this can result in the perl
94+
libraries not being where you'd like them if they're expected to be
95+
used by things other than Git itself.
96+
97+
Manually supplying a perllibdir prefix should fix this, if this is
98+
a problem you care about, e.g.:
99+
100+
prefix=/usr perllibdir=/usr/$(/usr/bin/perl -MConfig -wle 'print substr $Config{installsitelib}, 1 + length $Config{siteprefixexp}')
101+
102+
Will result in e.g. perllibdir=/usr/share/perl/5.26.1 on Debian,
103+
perllibdir=/usr/share/perl5 (which we'd use by default) on CentOS.
104+
90105
- Git is reasonably self-sufficient, but does depend on a few external
91106
programs and libraries. Git can be used without most of them by adding
92107
the approriate "NO_<LIBRARY>=YesPlease" to the make command line or

Makefile

+36-31
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,6 @@ all::
295295
#
296296
# Define PERL_PATH to the path of your Perl binary (usually /usr/bin/perl).
297297
#
298-
# Define NO_PERL_MAKEMAKER if you cannot use Makefiles generated by perl's
299-
# MakeMaker (e.g. using ActiveState under Cygwin).
300-
#
301298
# Define NO_PERL if you do not want Perl scripts or libraries at all.
302299
#
303300
# Define PYTHON_PATH to the path of your Python binary (often /usr/bin/python
@@ -473,6 +470,7 @@ gitexecdir = libexec/git-core
473470
mergetoolsdir = $(gitexecdir)/mergetools
474471
sharedir = $(prefix)/share
475472
gitwebdir = $(sharedir)/gitweb
473+
perllibdir = $(sharedir)/perl5
476474
localedir = $(sharedir)/locale
477475
template_dir = share/git-core/templates
478476
htmldir = $(prefix)/share/doc/git-doc
@@ -486,7 +484,7 @@ mandir_relative = $(patsubst $(prefix)/%,%,$(mandir))
486484
infodir_relative = $(patsubst $(prefix)/%,%,$(infodir))
487485
htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir))
488486

489-
export prefix bindir sharedir sysconfdir gitwebdir localedir
487+
export prefix bindir sharedir sysconfdir gitwebdir perllibdir localedir
490488

491489
CC = cc
492490
AR = ar
@@ -1525,9 +1523,6 @@ ifdef SHA1_MAX_BLOCK_SIZE
15251523
LIB_OBJS += compat/sha1-chunked.o
15261524
BASIC_CFLAGS += -DSHA1_MAX_BLOCK_SIZE="$(SHA1_MAX_BLOCK_SIZE)"
15271525
endif
1528-
ifdef NO_PERL_MAKEMAKER
1529-
export NO_PERL_MAKEMAKER
1530-
endif
15311526
ifdef NO_HSTRERROR
15321527
COMPAT_CFLAGS += -DNO_HSTRERROR
15331528
COMPAT_OBJS += compat/hstrerror.o
@@ -1714,8 +1709,10 @@ ETC_GITATTRIBUTES_SQ = $(subst ','\'',$(ETC_GITATTRIBUTES))
17141709
DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
17151710
bindir_SQ = $(subst ','\'',$(bindir))
17161711
bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
1712+
mandir_SQ = $(subst ','\'',$(mandir))
17171713
mandir_relative_SQ = $(subst ','\'',$(mandir_relative))
17181714
infodir_relative_SQ = $(subst ','\'',$(infodir_relative))
1715+
perllibdir_SQ = $(subst ','\'',$(perllibdir))
17191716
localedir_SQ = $(subst ','\'',$(localedir))
17201717
gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
17211718
template_dir_SQ = $(subst ','\'',$(template_dir))
@@ -1824,9 +1821,6 @@ all::
18241821
ifndef NO_TCLTK
18251822
$(QUIET_SUBDIR0)git-gui $(QUIET_SUBDIR1) gitexecdir='$(gitexec_instdir_SQ)' all
18261823
$(QUIET_SUBDIR0)gitk-git $(QUIET_SUBDIR1) all
1827-
endif
1828-
ifndef NO_PERL
1829-
$(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' localedir='$(localedir_SQ)' all
18301824
endif
18311825
$(QUIET_SUBDIR0)templates $(QUIET_SUBDIR1) SHELL_PATH='$(SHELL_PATH_SQ)' PERL_PATH='$(PERL_PATH_SQ)'
18321826

@@ -1907,7 +1901,8 @@ common-cmds.h: $(wildcard Documentation/git-*.txt)
19071901

19081902
SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\
19091903
$(localedir_SQ):$(NO_CURL):$(USE_GETTEXT_SCHEME):$(SANE_TOOL_PATH_SQ):\
1910-
$(gitwebdir_SQ):$(PERL_PATH_SQ):$(SANE_TEXT_GREP):$(PAGER_ENV)
1904+
$(gitwebdir_SQ):$(PERL_PATH_SQ):$(SANE_TEXT_GREP):$(PAGER_ENV):\
1905+
$(perllibdir_SQ)
19111906
define cmd_munge_script
19121907
$(RM) $@ $@+ && \
19131908
sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
@@ -1951,29 +1946,17 @@ git.res: git.rc GIT-VERSION-FILE
19511946
$(SCRIPT_PERL_GEN): GIT-BUILD-OPTIONS
19521947

19531948
ifndef NO_PERL
1954-
$(SCRIPT_PERL_GEN): perl/perl.mak
1955-
1956-
perl/perl.mak: perl/PM.stamp
1957-
1958-
perl/PM.stamp: FORCE
1959-
@$(FIND) perl -type f -name '*.pm' | sort >$@+ && \
1960-
$(PERL_PATH) -V >>$@+ && \
1961-
{ cmp $@+ $@ >/dev/null 2>/dev/null || mv $@+ $@; } && \
1962-
$(RM) $@+
1963-
1964-
perl/perl.mak: GIT-CFLAGS GIT-PREFIX perl/Makefile perl/Makefile.PL
1965-
$(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' $(@F)
1949+
$(SCRIPT_PERL_GEN):
19661950

1967-
PERL_DEFINES = $(PERL_PATH_SQ):$(PERLLIB_EXTRA_SQ)
1968-
$(SCRIPT_PERL_GEN): % : %.perl perl/perl.mak GIT-PERL-DEFINES GIT-VERSION-FILE
1951+
PERL_DEFINES = $(PERL_PATH_SQ):$(PERLLIB_EXTRA_SQ):$(perllibdir_SQ)
1952+
$(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-VERSION-FILE
19691953
$(QUIET_GEN)$(RM) $@ $@+ && \
1970-
INSTLIBDIR=`MAKEFLAGS= $(MAKE) -C perl -s --no-print-directory instlibdir` && \
19711954
INSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \
19721955
INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \
19731956
sed -e '1{' \
19741957
-e ' s|#!.*perl|#!$(PERL_PATH_SQ)|' \
19751958
-e ' h' \
1976-
-e ' s=.*=use lib (split(/$(pathsep)/, $$ENV{GITPERLLIB} || "'"$$INSTLIBDIR"'"));=' \
1959+
-e ' s=.*=use lib (split(/$(pathsep)/, $$ENV{GITPERLLIB} || "'"$$INSTLIBDIR"'" || "'"$(perllibdir_SQ)"'"));=' \
19771960
-e ' H' \
19781961
-e ' x' \
19791962
-e '}' \
@@ -2291,6 +2274,21 @@ endif
22912274
po/build/locale/%/LC_MESSAGES/git.mo: po/%.po
22922275
$(QUIET_MSGFMT)mkdir -p $(dir $@) && $(MSGFMT) -o $@ $<
22932276

2277+
PMFILES := $(wildcard perl/*.pm perl/*/*.pm perl/*/*/*.pm perl/*/*/*/*.pm)
2278+
PMCFILES := $(patsubst perl/%.pm,perl/build/lib/%.pmc,$(PMFILES))
2279+
2280+
ifndef NO_PERL
2281+
all:: $(PMCFILES)
2282+
endif
2283+
2284+
perl/build/lib/%.pmc: perl/%.pm
2285+
$(QUIET_GEN)mkdir -p $(dir $@) && \
2286+
sed -e 's|@@LOCALEDIR@@|$(localedir_SQ)|g' < $< > $@
2287+
2288+
perl/build/man/man3/Git.3pm: perl/Git.pm
2289+
$(QUIET_GEN)mkdir -p $(dir $@) && \
2290+
pod2man $< $@
2291+
22942292
FIND_SOURCE_FILES = ( \
22952293
git ls-files \
22962294
'*.[hcS]' \
@@ -2550,7 +2548,9 @@ ifndef NO_GETTEXT
25502548
(cd '$(DESTDIR_SQ)$(localedir_SQ)' && umask 022 && $(TAR) xof -)
25512549
endif
25522550
ifndef NO_PERL
2553-
$(MAKE) -C perl prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install
2551+
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perllibdir_SQ)'
2552+
(cd perl/build/lib && $(TAR) cf - .) | \
2553+
(cd '$(DESTDIR_SQ)$(perllibdir_SQ)' && umask 022 && $(TAR) xof -)
25542554
$(MAKE) -C gitweb install
25552555
endif
25562556
ifndef NO_TCLTK
@@ -2600,12 +2600,17 @@ endif
26002600
install-gitweb:
26012601
$(MAKE) -C gitweb install
26022602

2603-
install-doc:
2603+
install-doc: install-man-perl
26042604
$(MAKE) -C Documentation install
26052605

2606-
install-man:
2606+
install-man: install-man-perl
26072607
$(MAKE) -C Documentation install-man
26082608

2609+
install-man-perl: perl/build/man/man3/Git.3pm
2610+
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mandir_SQ)/man3'
2611+
(cd perl/build/man/man3 && $(TAR) cf - .) | \
2612+
(cd '$(DESTDIR_SQ)$(mandir_SQ)/man3' && umask 022 && $(TAR) xof -)
2613+
26092614
install-html:
26102615
$(MAKE) -C Documentation install-html
26112616

@@ -2697,7 +2702,7 @@ clean: profile-clean coverage-clean
26972702
$(MAKE) -C Documentation/ clean
26982703
ifndef NO_PERL
26992704
$(MAKE) -C gitweb clean
2700-
$(MAKE) -C perl clean
2705+
$(RM) -r perl/build/
27012706
endif
27022707
$(MAKE) -C templates/ clean
27032708
$(MAKE) -C t/ clean

contrib/examples/git-difftool.perl

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use 5.008;
1414
use strict;
1515
use warnings;
16-
use Error qw(:try);
16+
use Git::Error qw(:try);
1717
use File::Basename qw(dirname);
1818
use File::Copy;
1919
use File::Find;

git-send-email.perl

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
use Term::ANSIColor;
2727
use File::Temp qw/ tempdir tempfile /;
2828
use File::Spec::Functions qw(catdir catfile);
29-
use Error qw(:try);
29+
use Git::Error qw(:try);
3030
use Cwd qw(abs_path cwd);
3131
use Git;
3232
use Git::I18N;

perl/.gitignore

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
perl.mak
2-
perl.mak.old
3-
MYMETA.json
4-
MYMETA.yml
5-
blib
6-
blibdirs
7-
pm_to_blib
8-
PM.stamp
1+
/build/

perl/Git.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ increase notwithstanding).
101101

102102

103103
use Carp qw(carp croak); # but croak is bad - throw instead
104-
use Error qw(:try);
104+
use Git::Error qw(:try);
105105
use Cwd qw(abs_path cwd);
106106
use IPC::Open2 qw(open2);
107107
use Fcntl qw(SEEK_SET SEEK_CUR);

perl/Git/Error.pm

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package Git::Error;
2+
use 5.008;
3+
use strict;
4+
use warnings;
5+
6+
=head1 NAME
7+
8+
Git::Error - Wrapper for the L<Error> module, in case it's not installed
9+
10+
=head1 DESCRIPTION
11+
12+
Wraps the import function for the L<Error> module.
13+
14+
This module is only intended to be used for code shipping in the
15+
C<git.git> repository. Use it for anything else at your peril!
16+
17+
=cut
18+
19+
sub import {
20+
shift;
21+
my $caller = caller;
22+
23+
eval {
24+
require Error;
25+
1;
26+
} or do {
27+
my $error = $@ || "Zombie Error";
28+
29+
my $Git_Error_pm_path = $INC{"Git/Error.pm"} || die "BUG: Should have our own path from %INC!";
30+
31+
require File::Basename;
32+
my $Git_Error_pm_root = File::Basename::dirname($Git_Error_pm_path) || die "BUG: Can't figure out lib/Git dirname from '$Git_Error_pm_path'!";
33+
34+
require File::Spec;
35+
my $Git_pm_FromCPAN_root = File::Spec->catdir($Git_Error_pm_root, 'FromCPAN');
36+
die "BUG: '$Git_pm_FromCPAN_root' should be a directory!" unless -d $Git_pm_FromCPAN_root;
37+
38+
local @INC = ($Git_pm_FromCPAN_root, @INC);
39+
require Error;
40+
};
41+
42+
local @_ = ($caller, @_);
43+
goto &Error::import;
44+
}
45+
46+
1;
File renamed without changes.

perl/Git/I18N.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ our @EXPORT_OK = @EXPORT;
1818

1919
sub __bootstrap_locale_messages {
2020
our $TEXTDOMAIN = 'git';
21-
our $TEXTDOMAINDIR = $ENV{GIT_TEXTDOMAINDIR} || '++LOCALEDIR++';
21+
our $TEXTDOMAINDIR = $ENV{GIT_TEXTDOMAINDIR} || '@@LOCALEDIR@@';
2222

2323
require POSIX;
2424
POSIX->import(qw(setlocale));

perl/Makefile

-90
This file was deleted.

0 commit comments

Comments
 (0)