Skip to content

Instantly share code, notes, and snippets.

@tomislacker
Created February 14, 2014 18:09
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomislacker/9005963 to your computer and use it in GitHub Desktop.
Save tomislacker/9005963 to your computer and use it in GitHub Desktop.
Building a statically linked suite of git/git binaries for deployment on 32bit hosts
#!/bin/bash
cd $(dirname $0)
LOG_PREFIX=build-static
LOG_STDOUT=${LOG_PREFIX}.stdout
LOG_STDERR=${LOG_PREFIX}.stderr
REMOVE_TARGET_DIR=n
SOURCE_MAKE_CONF=y
MAKE_ALL_DOC=n
MAKE_CLEAN=y
MAKE_TARBALL=y
getStamp ()
{
date
}
truncateLogs ()
{
( echo -n | tee $LOG_STDOUT | tee $LOG_STDERR ) >>/dev/null 2>&1
}
msgLine ()
{
local myMsg=$*
echo -e "[$(getStamp)] ${myMsg}" | tee -a $LOG_STDOUT
}
failAndExit ()
{
local exitStatus=${1:-1}
shift
local failMsg=$*
( msgLine "[failAndExit][${exitStatus}] ${failMsg}" | tee -a $LOG_STDERR ) >&2
exit $exitStatus
}
msgLine "Truncating log files ..."
truncateLogs || failAndExit 101 "\tFAILED"
msgLine "\tSUCCESS"
targetDir=$(readlink -m ~)/git-static
msgLine "Checking target dir '${targetDir}' ..."
if [ "${REMOVE_TARGET_DIR:0:1}" == "y" ]; then
if [ -d "$targetDir" ]; then
msgLine "\tRemoving target dir '${targetDir}' ..."
( rm -fr $targetDir >>$LOG_STDOUT 2>>$LOG_STDERR ) || failAndExit 102 "\t\tFAILED"
msgLine "\t\tSUCCESS"
fi
fi
if [ "${MAKE_CLEAN:0:1}" == "y" ]; then
msgLine "Executing 'make clean' ..."
( make clean >>$LOG_STDOUT 2>>$LOG_STDERR ) && msgLine "\tSUCCESS" || failAndExit 100 "\tFAILED"
else
msgLine "\t\tSkipping ..."
fi
msgLine 'Checking for -f and -x on ./configure'
if [ ! -x configure ]; then
msgLine "\t./configure doesn't exist. Running 'make configure'"
( make configure >>$LOG_STDOUT 2>>$LOG_STDERR ) || failAndExit 1 "Failed to 'make configure'"
fi
msgLine 'Checking to source make.conf ...'
if [ "${SOURCE_MAKE_CONF:0:1}" == "y" -a -f /etc/portage/make.conf ]; then
msgLine "\tSourcing..." && . /etc/portage/make.conf
else
CFLAGS+="-O2 -pipe"
fi
configureArgs=( \
"--prefix=${targetDir}" \
)
#configureArgs+=('--without-curl')
#configureArgs+=('--without-openssl')
configureArgs+=('--without-tcltk')
#CFLAGS="${CFLAGS}"
CFLAGS+=" -static"
CFLAGS+=" -static-libgcc"
CFLAGS+=" -m32"
#CFLAGS+=" -L/lib/tls"
#CFLAGS+=" $(pkg-config --static --libs libcurl)"
#CFLAGS+=" $(pkg-config --static --libs libcrypto)"
msgLine "Launching ./configure ${configureArgs[*]} CFLAGS=\"${CFLAGS}\""
#( ./configure ${configureArgs[*]} CFLAGS="${CFLAGS}" NO_OPENSSL=1 NO_CURL=1 >>$LOG_STDOUT 2>>$LOG_STDERR ) || failAndExit 2 'Failed to configure build...'
#( ./configure ${configureArgs[*]} CFLAGS="${CFLAGS}" >>$LOG_STDOUT 2>>$LOG_STDERR ) || failAndExit 2 'Failed to configure build...'
( ./configure ${configureArgs[*]} CFLAGS="${CFLAGS}" NO_OPENSSL=1 >>$LOG_STDOUT 2>>$LOG_STDERR ) || failAndExit 2 'Failed to configure build...'
msgLine "\t\tBUILD COMPLETE"
if [ "${MAKE_ALL_DOC:0:1}" == "y" ]; then
###
# Including documentation build
###
msgLine "Executing 'make all doc' ..."
( make all doc >>$LOG_STDOUT 2>>$LOG_STDERR ) || failAndExit 3 "\tFAILED"
msgLine "\tSUCCESS"
msgLine "Executing 'make install install-doc install-html' ..."
( make install install-doc install-html >>$LOG_STDOUT 2>>$LOG_STDERR ) || failAndExit 4 "\tFAILED"
msgLine "\tSUCCESS"
else
###
# Skipping documentation build
###
msgLine "Executing 'make install' ..."
( make install >>$LOG_STDOUT 2>>$LOG_STDERR ) || failAndExit 4 "\tFAILED"
msgLine "\tSUCCESS"
fi
if [ "${MAKE_TARBALL:0:1}" == "y" ]; then
msgLine "Making tarball ..."
tarballName=git-static-$(date +%s).tgz
[ -f $tarballName ] && rm -f $tarballName
( cd $targetDir && tar -cvzf $tarballName * ) >>$LOG_STDOUT 2>>$LOG_STDERR || failAndExit 5 "\tFAILED"
msgLine "\tSUCCESS"
fi
@kilaka
Copy link

kilaka commented May 7, 2018

First of all, thanks!!! I have a few questions:

  1. Saw some issues here when using a statically linked git. Will same issues arise with this binary result?
  2. Is changing to 64bit will only require to change CFLAGS+=" -m32"?
  3. Why do you think official git don't provide a standalone binary?
  4. See related SE question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment