编译静态链接的Git

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

袁保康

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值