8

I'm building git on a pretty minimal system (Ubuntu 16.04 docker image) without using the package manager (except for wget, xz-utils, make and gcc). I thus installed prerequisistes as follows:

apt-get update && apt-get install --yes wget xz-utils make gcc
wget http://www.cpan.org/src/5.0/perl-5.26.1.tar.gz && tar xf perl-5.26.1.tar.gz && cd perl-5.26.1 && ./configure.gnu && make -j16 && make install && cd ..
wget https://ftp.gnu.org/pub/gnu/gettext/gettext-0.19.8.1.tar.xz && tar xf gettext-0.19.8.1.tar.xz && cd gettext-0.19.8.1 && ./configure && make -j16 && make install && cd ..
wget https://www.zlib.net/zlib-1.2.11.tar.gz && tar xf zlib-1.2.11.tar.gz && cd zlib-1.2.11 && ./configure && make -j16 && make install && cd ..
cpan install ExtUtils::MakeMaker
wget https://www.kernel.org/pub/software/scm/git/git-2.13.3.tar.gz && tar xf git-2.13.3.tar.gz && cd git-2.13.3 && ./configure && make -j16 && make install && cd ..

However, make in the git source root fails due to

Can't locate ExtUtils/MakeMaker.pm in @INC (you may need to install the ExtUtils::MakeMaker module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.22.1 /usr/local/share/perl/5.22.1 /usr/lib/x86_64-linux-gnu/perl5/5.22 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.22 /usr/share/perl/5.22 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base .) at Makefile.PL line 3.
BEGIN failed--compilation aborted at Makefile.PL line 3.
make[1]: *** [perl.mak] Error 2
Makefile:83: recipe for target 'perl.mak' failed
make: *** [perl/perl.mak] Error 2
make: *** Waiting for unfinished jobs....
Makefile:1870: recipe for target 'perl/perl.mak' failed

I'm aware that there're a lot of solutions regarding Can't locate [module].pm in @INC for perl projects, How do I tell CPAN to install all dependencies?. However, git uses GNU autotools and options which could fix the issue are probably read from environment variables which I couldn't figure out so far.

The Ubuntu 16.04 provides a perl, but no cpan command (which is why I added the perl source installation). After the perl source installation is recognized, but doesn't seem to be used:

$ which -a perl
/usr/local/bin/perl
/usr/bin/perl
$ which -a cpan
/usr/local/bin/cpan

After cpan I get

$ find / -name MakeMaker.pm
/builds/project-0/perl-5.26.1/lib/ExtUtils/MakeMaker.pm
/builds/project-0/perl-5.26.1/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MakeMaker.pm
/root/.cpan/build/ExtUtils-MakeMaker-7.32-0/lib/ExtUtils/MakeMaker.pm
/root/.cpan/build/ExtUtils-MakeMaker-7.32-0/blib/lib/ExtUtils/MakeMaker.pm
/usr/local/lib/perl5/5.26.1/ExtUtils/MakeMaker.pm
/usr/local/lib/perl5/site_perl/5.26.1/ExtUtils/MakeMaker.pm
$ perl -E 'say for @INC'
/usr/local/lib/perl5/site_perl/5.26.1/x86_64-linux
/usr/local/lib/perl5/site_perl/5.26.1
/usr/local/lib/perl5/5.26.1/x86_64-linux
/usr/local/lib/perl5/5.26.1

The setup is abstracted from a bootstrapping script, so using the package manager is really no option.

You can use docker run -i -t ubuntu:latest in case you care to investigate the environment.

I provided a reproducible build at https://gitlab.com/krichter/git-docker-build and example output of the GitLab CI runner can be found at https://gitlab.com/krichter/git-docker-build/-/jobs/53888412.

Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
  • Where is `MakeMaker.pm`? Is its directory in `perl E 'say for @INC'`? Have you tried running `cpan ExtUtils::MakeMaker` first, on its own? – Borodin Feb 22 '18 at 15:36
  • 1
    Your Git install seems to be running with perl-5.22 (pre-installed on 16.04) whereas you installed perl-5.26. I am not sure to which installation your `cpan` command belongs. – amon Feb 22 '18 at 15:39
  • @Borodin I added the output of `perl -E 'say for @INC'`. Replacing `cpan install ExtUtils::MakeMaker` with `cpan ExtUtils::MakeMaker` doesn't help (I assume that's what you meant). – Kalle Richter Feb 22 '18 at 16:45
  • @amon I added more info about initial perl and cpan commands to the question (there's a `perl`, but no `cpan` command provided, i.e. `cpan` has to belong to the `perl` source installation). Nevertheless autotools are picking up `/usr/bin/perl` instead of `/usr/local/bin/perl`. – Kalle Richter Feb 22 '18 at 16:49
  • Thanks for that. I'm unclear why you have two copies of `ExtUtils::MakeMaker` within `/usr/local/lib/perl5`. What do you get from `perl -MExtUtils::MakeMaker -E 'say for values %INC'`? – Borodin Feb 22 '18 at 16:58
  • 1
    @Borodin I found a solution (see my answer below). Thanks for your support. You can investigate further yourself with the SSCCE I provided. – Kalle Richter Feb 22 '18 at 17:04

2 Answers2

34

In CentOS7, I encounter this issue, I find I should install the perl-devel firstly:

yum install perl-devel

Then retry it.

aircraft
  • 25,146
  • 28
  • 91
  • 166
4

using ./configure --with-perl=/usr/local/bin/perl for git works, however it's unclear for me why /usr/local/bin/perl isn't picked up before /usr/bin/perl if PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin.

The cpan ExtUtils::MakeMaker isn't necessary after adding --with-perl.

Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
  • Ah! I was about to suggest removing the original installation of perl or taking its location out of `PATH`. Well done. – Borodin Feb 22 '18 at 17:13
  • If your regular programs are `/usr/local/bin/perl` and `/usr/local/bin/cpan` but git is using `/usr/bin/perl`, then modules missing in the git build can probably be installed with `/usr/bin/cpan`. – mob Feb 22 '18 at 17:25
  • @mob `/usr/bin/cpan` belonging to `/usr/bin/perl`) doesn't exist (see question). Or do you mean to install everything into prefix `/usr` instead of `/usr/local` and effectively overwrite the `perl` provided by the system? That's not a good idea, right? – Kalle Richter Feb 22 '18 at 17:26