HandBrake-docs/build-tools
Bradley Sepos d68f999bc2 build: Build fewer tools by default.
Image utilties are not needed by build-docs. Adds --all to make build-tools build everything as before.
2016-09-07 15:19:21 -04:00

126 lines
3.2 KiB
Bash
Executable File

#!/bin/bash
# vars
SELF="${BASH_SOURCE[0]}"
SELF_DIR=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd -P)
SELF_DIR="${SELF_DIR:-$(pwd)}"
TOOLS_DIR="${SELF_DIR}/tools"
BUILD_DIR="${TOOLS_DIR}/local/build"
INSTALL_DIR="${TOOLS_DIR}/local"
SYS_NAME=$(uname | awk '{ print tolower($0)}')
TOOLS=('discount')
TOOLS_EXTRA=('zlib' 'libpng' 'pngquant' 'zopfli')
# args
OPTIND=1
OPTSPEC=":-:"
OPTARRAY=('--all') # all short and long options
while getopts "${OPTSPEC}" OPT; do
case "${OPT}" in
-)
case "${OPTARG}" in
all)
TOOLS=("${TOOLS[@]}" "${TOOLS_EXTRA[@]}")
;;
all=*)
# Option with prohibited value
echo "option --${OPTARG%%=*} takes no value" >&2
exit 1
;;
*)
if [[ "${OPTERR}" == 1 ]]; then
# Invalid option specified
echo "invalid option: --${OPTARG}" >&2
exit 1
fi
;;
esac
;;
:)
# Option without required value
echo "option -${OPTARG} requires a value" >&2
exit 1
;;
\?)
# Invalid option specified
echo "invalid option: -${OPTARG}" >&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
# discount
function build_discount {
./configure.sh --prefix="${INSTALL_DIR}" || return 1
make || return 1
make install || return 1
}
# zlib
function build_zlib {
./configure --static --prefix="${INSTALL_DIR}" || return 1
make || return 1
make install || return 1
rm -f "${INSTALL_DIR}/lib/libz*.dylib"
}
# libpng
function build_libpng {
if [[ "${SYS_NAME}" == "darwin" ]]; then
cp scripts/makefile.darwin Makefile
elif [[ "${SYS_NAME}" == "linux" ]]; then
cp scripts/makefile.linux Makefile
else
return 1
fi
make libpng.a prefix="${INSTALL_DIR}" ZLIBINC="${INSTALL_DIR}/include" ZLIBLIB="${INSTALL_DIR}/lib" || return 1
make install-static prefix="${INSTALL_DIR}" || return 1
}
# pngquant
function build_pngquant {
./configure --extra-cflags="-I${INSTALL_DIR}/include" --extra-ldflags="-L${INSTALL_DIR}/lib -lz" --prefix="${INSTALL_DIR}" --with-libpng="${INSTALL_DIR}" --without-cocoa || return 1
sed -i.sedbak -e 's:-L/usr/lib -lz::g' config.mk || return 1
rm -f config.mk.sedbak
make || return 1
make install || return 1
}
# zopfli
function build_zopfli {
make zopfli zopflipng || return 1
cp zopfli zopflipng "${INSTALL_DIR}/bin" || return 1
}
# main
rm -rf "${INSTALL_DIR}"
rm -rf "${BUILD_DIR}"
mkdir -p "${BUILD_DIR}"
cd "${BUILD_DIR}"
ERROR=false
echo "Building:"
for TOOL in "${TOOLS[@]}"; do
echo " ${TOOL}"
cp -R "${TOOLS_DIR}/${TOOL}" "${BUILD_DIR}/"
rm -rf "${BUILD_DIR}/${TOOL}/.git"
cd "${BUILD_DIR}/${TOOL}"
if ! build_${TOOL} >/dev/null 2>&1; then
ERROR=true
echo "Unable to build tool: ${TOOL}" >&2
break
fi
done
# clean up
if [[ "${ERROR}" != true ]]; then
rm -rf "${BUILD_DIR}"
fi
# done
if [[ "${ERROR}" == true ]]; then
exit 1
fi
echo "Complete."
exit 0