Gitのインストール

VCS (Version Control System) として,現代的で代表的なGitをソースコードからインストールする。
多くのソフトウェアがVCSにGitを採用しており,ソースコードのダウンロード時にも必要になる。
項目 | 説明 |
---|---|
配布元 | Git |
リポジトリー | git/git: Git Source Code Mirror – This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements. |
手順 | git/INSTALL at master · git/git · GitHub |
依存情報 | |
依存先 (必須) | Make (GNU Make), zlib |
依存先 (任意) |
|
依存元 |
任意の依存先が多数ある。この中でsshとlibcurlは実用上必須だ。OpenSSLはOpenSSHのビルド時にインストールすることになる。
可能であれば,wishも有効にしてGit付属のGUIもビルドするとよいだろう。しかし,wishはGUIであるためビルドが厄介なので,ひとまず後回しにする。
sh -eux <<-"EOT"
PKG=git VER=2.22.0 TAG=v$VER
LOCAL=~/.local J=$(grep -cs '^processor' /proc/cpuinfo || echo 2)
mkdir -p "$LOCAL/src"
cd "$LOCAL/src"
if command -v git >/dev/null; then
[ -e $PKG ] || git clone --depth 1 https://github.com/git/git
cd $PKG
git fetch --depth 1 origin tag $TAG
git checkout -f $TAG
git clean -dfX
if false [ -e .gitmodules ]; then
git submodule update --init --depth 1 --progress ||
git -C $(git submodule status | cut -d ' ' -f 2) pull --shallow-since YYYY-mm-dd
git submodule foreach --recursive git clean -dfX
fi
# [ -e configure.ac ] && autoreconf -is
make configure
else
[ -e $PKG-$VER ] || wget https://mirrors.edge.kernel.org/pub/software/scm/git/$PKG-$VER.tar.xz
tar -xf $PKG-$VER.*
cd $PKG-$VER
make -kj $J distclean clean || :
fi
if [ -e CMakeLists.txt ] && command -v cmake >/dev/null; then
ENABLE_XXX=$(pkg-config --exists xxx && echo ON || echo OFF)
cmake -D CMAKE_INSTALL_PREFIX="$LOCAL/stow/$PKG-$VER" .
ctest -j $J
fi
[ -x configure ] && ./configure --prefix="$LOCAL/stow/$PKG-$VER"
make -j $J
make -j $J test
make -j $J install
cd "$LOCAL/stow"
echo $PKG-[0-9]* | xargs -n 1 stow --ignore=dir -D
stow --ignore=dir $PKG-$VER
EOT
日付 | バージョン | OS | 依存関係 |
---|---|---|---|
2019-02-24 | 2.19.2 | Ubuntu 18.04 | GNU Make 4.2.1, GCC 8.1.0, OpenSSH 7.9p1, cURL 7.59.0, OpenSSL 1.1.1a |
2019-07-05 | 2.22.0 | Ubuntu 18.04 | GNU Make 4.2.1, GCC 7.4.0, OpenSSH 7.9p1, cURL 7.59.0, OpenSSL 1.1.1a |
INSTALLにあるように,make configure; ./configure; make && make install
の代わりに,以下のようにmake時にprefixを指定してもビルドとインストールができる。
make -j $J prefix=$LOCAL/stow/$PKG-$VER && make prefix=$LOCAL/stow/$PKG-$VER install
今回は他のプログラムのインストールと手順を合わせるために,configureを作成する手順を採用した。
依存関係をローカル環境にインストールしている場合,Gitのビルドでは./configure
の実行前にexport LDFLAGS="-L$LOCAL/lib -L$LOCAL/iib64"
を実行するか,LDFLAGS="-L$LOCAL/lib" ./configure
のように,LDFLAGS環境変数にライブラリーの場所を指定する必要があった。そうしないと,ローカル環境にインストールしたcURLを認識せず,make
実行時に以下のエラーが出てしまった。
LINK git-imap-send /usr/bin/ld: cannot find -lcurl collect2: error: ld returned 1 exit status make: *** [Makefile:2349: git-imap-send] Error 1
なお,gitのリポジトリーには,sha1collisiondetectionサブモジュールが存在する。こちらは,MakefileでDC_SHA1とDC_SHA1_SUBMODULEを定義した場合に使用する実験的なオプションのようだ。
# Define DC_SHA1_SUBMODULE in addition to DC_SHA1 to use the
# sha1collisiondetection shipped as a submodule instead of the
# non-submodule copy in sha1dc/. This is an experimental option used
# by the git project to migrate to using sha1collisiondetection as a
# submodule.
通常ビルドでは不要であるため,git submodule関係のコマンドは実行しない。