Git在Windows,Mac,Linux上安装使用都比较方便,如果要在Android中使用,特别是Android底层的Linux使用会比较麻烦。这和其它开源程序一样,需要静态编译才可以方便地安装和使用。
静态编译我找的How to Create a Statically Linked Version of git Binaries这个文章,步骤比较简单:
# let's make sure we have all we need to proceed
$ sudo apt-get install libexpat1-dev asciidoc libz-dev gettext curl
# let's create the directory to host the built artifacts
$ sudo mkdir /opt/git-1.7.4.1-static
# we are ready to download and unpack latest version of git sources
$ curl http://kernel.org/pub/software/scm/git/git-1.7.4.1.tar.bz2 | tar xvj
$ cd git-1.7.4.1/
# then compile and install the files in the target directory we created
$ ./configure --prefix=/opt/git-1.7.4.1-static CFLAGS="${CFLAGS} -static" NO_OPENSSL=1 NO_CURL=1
$ sudo make install
$ sudo make install-doc
这里下载的源码过期了,我从Github上下载的,遇到一些问题。压缩包中并没有configure这个配置文件,导致我没有办法配置。最终从http://mirror.linux.org.au/software/scm/git/下载了对应的版本中有configure文件(这里我感到十分奇怪,Git源码还重复发布了,为什么相同版本的压缩包在不同地址下载还有不同之处)。
按照这个方法编译:
# 安装必要的库
$ sudo apt-get install libssl-dev libcurl4-openssl-dev libexpat1-dev
$ wget http://mirror.linux.org.au/software/scm/git/git-1.7.4.1.tar.bz2
$ tar xvf git-1.7.4.1.tar.bz2 && cd git-1.7.4.1
# 配置
$ ./configure CFLAGS="${CFLAGS} -static" NO_OPENSSL=1 NO_CURL=1
# 编译
$ make -j32
# 查看编译静态链接的Git
$ file git
git: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.24, BuildID[sha1]=26ebe34dee1605b53b780e3eaff9f567cef47b99, not stripped
同理,在arm平台的Ubuntu系统可以编译出arm版本静态链接git:
$ file git
git: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, for GNU/Linux 2.6.31, BuildID[sha1]=57f6182c303fdb12d0761da135003e3a74e8df9e, not stripped
由于ARM平台编译环境不好搭建,这里把ARM版本静态链接的git文件上传方便后来都直接使用git-arm。