Created
February 20, 2014 18:37
-
-
Save nkoneko/9120317 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/sh | |
usage() { | |
cat 1>&2 <<EOS | |
SYNOPSIS | |
${SCRIPT_NAME} TARGET VERSION | |
TARGET either of the followings: | |
lzip, curl, gcc | |
EOS | |
}; | |
exit_iferror() { | |
EXIT_CODE=$? | |
ERROR_MSG=$@ | |
[ ${EXIT_CODE} -eq 0 ] || | |
cat 1>&2 <<EOS | |
${ERROR_MSG} | |
Exit code=${EXIT_CODE} | |
EOS | |
[ ${EXIT_CODE} -eq 0 ] || exit ${EXIT_CODE} | |
}; | |
# Constants | |
# Some of these are determined at runtime. They should not be touched. | |
SCRIPT_NAME=${0} | |
TOOLS_ROOT=$(readlink -f $(dirname ${0})/..) | |
TOOLS_SRC=${TOOLS_ROOT}/src | |
# Arguments | |
TARGET_NAME=${1} | |
TARGET_VERSION=${2} | |
[ -z "${TARGET_NAME}" ] && usage && exit 1 | |
[ -z "${TARGET_VERSION}" ] && usage && exit 1 | |
SOURCE_DIR="${TOOLS_SRC}/${TARGET_NAME}-${TARGET_VERSION}" | |
[ -d "${SOURCE_DIR}" ] || | |
exit_iferror "[Error] Directory ${SOURCE_DIR} not found." | |
TARGET_DIR="${TOOLS_ROOT}/${TARGET_NAME}-${TARGET_VERSION}" | |
# Variables | |
CONFIGURE_OPTIONS= | |
case "${TARGET_NAME}" in | |
"lzip" ) | |
CONFIGURE_OPTIONS="${CONFIGURE_OPTIONS} --prefix=${TARGET_DIR}" | |
;; | |
"gcc" ) | |
CONFIGURE_OPTIONS="${CONFIGURE_OPTIONS} --prefix=${TARGET_DIR}" | |
CONFIGURE_OPTIONS="${CONFIGURE_OPTIONS} --enable-threads=posix" | |
CONFIGURE_OPTIONS="${CONFIGURE_OPTIONS} --disable-multilib" | |
CONFIGURE_OPTIONS="${CONFIGURE_OPTIONS} --enable-languages=c,c++" | |
;; | |
"curl" ) | |
CONFIGURE_OPTIONS="${CONFIGURE_OPTIONS} --prefix=${TARGET_DIR}" | |
;; | |
* ) | |
cat 1>&2 <<EOS | |
[Error] ${TARGET_NAME} not available. | |
EOS | |
usage | |
exit 1 | |
;; | |
esac | |
cd ${SOURCE_DIR} && | |
./configure ${CONFIGURE_OPTIONS} && | |
make && | |
make install | |
exit_iferror "[Error] Failed to build a tool." | |
[ -d "${TARGET_DIR}/bin" ] && | |
cd ${TOOLS_ROOT}/bin && | |
find ${TARGET_DIR}/bin -maxdepth 1 -type f -nowarn -print0 | \ | |
xargs -0 ln -s --target-directory . | |
[ -d "${TARGET_DIR}/lib" ] && | |
cd ${TOOLS_ROOT}/lib && | |
find ${TARGET_DIR}/lib -maxdepth 1 -type f -nowarn -print0 | \ | |
xargs -0 ln -s --target-directory . && | |
find ${TARGET_DIR}/lib -maxdepth 1 -type l -nowarn -print0 | \ | |
xargs -0 ln -s --target-directory . | |
[ -d "${TARGET_DIR}/include" ] && | |
cd ${TOOLS_ROOT}/include && | |
find ${TARGET_DIR}/include -type d -nowarn | \ | |
sed "s#^${TARGET_DIR}/include##g" | sed "s#^/##g" | grep -vE "^$" | xargs rm -rf && | |
cd - | |
[ -d "${TARGET_DIR}/include" ] && | |
cd ${TOOLS_ROOT}/include && | |
find ${TARGET_DIR}/include -type d -nowarn | \ | |
sed "s#^${TARGET_DIR}/include##g" | sed "s#^/##g" | grep -vE "^$" | \ | |
xargs cp -rp ${TARGET_DIR}/include/{} ${TOOLS_ROOT}/include/{} | |
cd - | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment