Created
July 5, 2013 18:34
-
-
Save doubleotoo/5936387 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
#------------------------------------------------------------------------------- | |
# Default values | |
#------------------------------------------------------------------------------- | |
: ${CCACHE_VERSION:=$1} | |
echo "[INFO] CCACHE version '$CCACHE_VERSION'" | |
: ${GCC_HOME:=} | |
if [ -z "${GCC_HOME}" ]; then | |
echo "[FATAL] \$GCC_HOME is not set" | |
exit 1 | |
fi | |
GCC_VERSION="$(gcc -dumpversion)" | |
: ${DESTDIR:=$(pwd)} | |
: ${PREFIX:=${DESTDIR}/${CCACHE_VERSION}/gcc/${GCC_VERSION}} | |
: ${WORKSPACE:=${PREFIX}/workspace} | |
#------------------------------------------------------------------------------- | |
# Sanity Checks | |
#------------------------------------------------------------------------------- | |
if [ -z "${CCACHE_VERSION}" ]; then | |
echo "Usage: $0 <version: x.x.x>" | |
exit 1 | |
fi | |
#------------------------------------------------------------------------------- | |
# Meta Information | |
#------------------------------------------------------------------------------- | |
CCACHE_SRCDIR="${WORKSPACE}/ccache-${CCACHE_VERSION}" | |
CCACHE_TARBALL="ccache-${CCACHE_VERSION}.tar.gz" | |
CCACHE_DOWNLOAD_URL="http://samba.org/ftp/ccache/${CCACHE_TARBALL}" | |
#------------------------------------------------------------------------------- | |
# Workspace | |
#------------------------------------------------------------------------------- | |
mkdir -p "${WORKSPACE}" || exit 1 | |
pushd "${WORKSPACE}" || exit 1 | |
#------------------------------------------------------------------------------- | |
# Download and unpack | |
#------------------------------------------------------------------------------- | |
if [ ! -f "$CCACHE_TARBALL" -a ! -f "${CCACHE_TARBALL%.xz}" ]; then | |
echo "[INFO] Downloading CCACHE '$CCACHE_DOWNLOAD_URL'" | |
wget --no-check-certificate "$CCACHE_DOWNLOAD_URL" || exit 1 | |
else | |
echo "[INFO] [SKIP] ccache tarball already exists: '$CCACHE_TARBALL'" | |
fi | |
if [ ! -d "$CCACHE_SRCDIR" ]; then | |
echo "[INFO] Unpacking ccache tarball: '$CCACHE_TARBALL'" | |
tar xvzf "${CCACHE_TARBALL}" | |
else | |
echo "[INFO] [SKIP] ccache source code already exists: '$CCACHE_SRCDIR'" | |
fi | |
#------------------------------------------------------------------------------- | |
# Build and install | |
#------------------------------------------------------------------------------- | |
cd "${CCACHE_SRCDIR}" | |
if [ ! -e "${PREFIX}/bin" ]; then | |
echo "[INFO] Configuring ccache" | |
echo "[INFO] Installing to '$PREFIX'" | |
echo "[INFO] \$GCC_HOME='${GCC_HOME}'" | |
"${CCACHE_SRCDIR}/configure" --prefix="$PREFIX" || exit 1 | |
make -j || exit 1 | |
make -j install || exit 1 | |
fi | |
echo "[INFO] Creating ccache environment setup file" | |
cat > "${PREFIX}/setup.sh" <<-EOF | |
#!/bin/bash | |
# | |
# Automatically generated by $0 on $(date) | |
source "${GCC_HOME}/setup.sh" || return 1 | |
export CCACHE_VERSION="${CCACHE_VERSION}" | |
export CCACHE_HOME="${PREFIX}" | |
export PATH="\${CCACHE_HOME}/bin:\${PATH}" | |
export CCACHE_GCC_HOME="${GCC_HOME}" | |
if [ -z "\${CCACHE_DIR}" ]; then | |
export CCACHE_DIR="/tmp/ccache" | |
mkdir -p "\${CCACHE_DIR}" || return 1 | |
ccache --max-size="1G" > /dev/null || return 1 | |
true | |
fi | |
EOF | |
#----------------------------------------------- | |
# Set Permissions | |
#----------------------------------------------- | |
echo "[INFO] Setting group permissions of '${PREFIX}'" | |
chmod -R g+r "${PREFIX}" | |
find "${PREFIX}" -type d -exec chmod g+x {} \; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment