Skip to content

Instantly share code, notes, and snippets.

@doubleotoo
Last active April 16, 2023 06:30
Show Gist options
  • Save doubleotoo/5860924 to your computer and use it in GitHub Desktop.
Save doubleotoo/5860924 to your computer and use it in GitHub Desktop.
#!/bin/bash -e
#-------------------------------------------------------------------------------
# Default values
#-------------------------------------------------------------------------------
: ${AUTOCONF_VERSION:=$1}
echo "[INFO] Autoconf '$AUTOCONF_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}/${AUTOCONF_VERSION}/gcc/${GCC_VERSION}}
: ${WORKSPACE:=${PREFIX}/workspace}
#-------------------------------------------------------------------------------
# Sanity Checks
#-------------------------------------------------------------------------------
if [ -z "${AUTOCONF_VERSION}" ]; then
echo "Usage: $0 <version: x.xx>"
exit 1
fi
#-------------------------------------------------------------------------------
# Meta Information
#-------------------------------------------------------------------------------
AUTOCONF_SRCDIR="${WORKSPACE}/autoconf-${AUTOCONF_VERSION}"
AUTOCONF_TARBALL="autoconf-${AUTOCONF_VERSION}.tar.xz"
AUTOCONF_DOWNLOAD_URL="http://ftp.gnu.org/gnu/autoconf/${AUTOCONF_TARBALL}"
#-------------------------------------------------------------------------------
# Workspace
#-------------------------------------------------------------------------------
mkdir -p "${WORKSPACE}" || exit 1
pushd "${WORKSPACE}" || exit 1
#-------------------------------------------------------------------------------
# [LLVM] Download and unpack
#-------------------------------------------------------------------------------
if [ ! -f "$AUTOCONF_TARBALL" ]; then
echo "[INFO] Downloading AUTOCONF '$AUTOCONF_DOWNLOAD_URL'"
wget --no-check-certificate "$AUTOCONF_DOWNLOAD_URL" || exit 1
else
echo "[INFO] [SKIP] Autoconf tarball already exists: '$AUTOCONF_TARBALL'"
fi
if [ ! -d "$AUTOCONF_SRCDIR" ]; then
echo "[INFO] Unpacking Autoconf tarball: '$AUTOCONF_TARBALL'"
unxz "$AUTOCONF_TARBALL" || exit 1
tar xvf "${AUTOCONF_TARBALL%.xz}" || exit 1
else
echo "[INFO] [SKIP] Autoconf source code already exists: '$AUTOCONF_SRCDIR'"
fi
#-------------------------------------------------------------------------------
# Build and install
#-------------------------------------------------------------------------------
cd "${AUTOCONF_SRCDIR}"
if [ ! -e "${PREFIX}/bin" ]; then
echo "[INFO] Configuring Autoconf"
echo "[INFO] Installing to '$PREFIX'"
echo "[INFO] \$GCC_HOME='${GCC_HOME}'"
"${AUTOCONF_SRCDIR}/configure" --prefix="$PREFIX" || exit 1
make -j all || exit 1
make -j install || exit 1
echo "[INFO] Creating Autoconf environment setup file"
cat > "${PREFIX}/setup.sh" <<-EOF
#!/bin/bash
#
# Automatically generated by $0 on $(date)
export AUTOCONF_HOME="${PREFIX}"
export PATH="\${AUTOCONF_HOME}/bin:\${PATH}"
export AUTOCONF_GCC_HOME="${GCC_HOME}"
EOF
#-----------------------------------------------
# Set Permissions
#-----------------------------------------------
echo "[INFO] Setting group permissions of '${PREFIX}'"
chmod -R g+r "${PREFIX}"
find "${PREFIX}" -type d -exec chmod g+x {} \;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment