How to build git with static linking?

2020-07-03 09:20发布

问题:

I downloaded git source from https://github.com/git/git as a zip file.

I extracted it into /home/Desktop/denis/git (using Ubuntu).

Now the tutorial here says that I should run

./configure --prefix=/home/denis/git-static CFLAGS="${CFLAGS} -static"

from the above mentioned folder as a step for building git.

But the git source does not appear to have a configure file in it's root folder which I can run (only configure.ac, which I suspect is not what I'm looking for).

What am I missing here? How to build git manually?

I'm doing this because I'm trying to get git working on a shared hosting server where I'm not able to install git.

回答1:

Read the INSTALL file in the root folder of the unzipped file, it seems there is some useful instruction in it, what I suspect:

Alternatively you can use autoconf generated ./configure script to set up install paths (via config.mak.autogen), so you can write instead

    $ make configure ;# as yourself
    $ ./configure --prefix=/usr ;# as yourself
    $ make all doc ;# as yourself
    # make install install-doc install-html;# as root

or just simply:

    $ make prefix=/usr all doc info ;# as yourself
    # make prefix=/usr install install-doc install-html install-info ;# as root


回答2:

The other answers did not work for me. Perhaps they will for others. What did work for me was:

  1. Get the source code
  2. Make a target directory
  3. Enter the source directory
  4. Configure
  5. Build
  6. Install

Use the following commands:

git clone git@github.com:git/git.git
mkdir git-static
cd git
./configure prefix=/path/to/git-static/ CFLAGS="${CFLAGS} -static"
make
make install

This will leave you with a few folders in the git-static directory, but the executable is statically linked. It is also substantially bigger than usual (maybe 1.5 MB bigger).