#!/usr/bin/env bash # Written and placed in public domain by Jeffrey Walton # This script builds Mawk and its dependencies from sources. # It is needed on Debian and Ubuntu, not Fedora, OS X, Solaris or friends MAWK_TAR=mawk.tar.gz MAWK_DIR=mawk-1.3.4-20200120 PKG_NAME=mawk ############################################################################### # Get the environment as needed. if [[ "${SETUP_ENVIRON_DONE}" != "yes" ]]; then if ! source ./setup-environ.sh then echo "Failed to set environment" exit 1 fi fi # The password should die when this subshell goes out of scope if [[ "${SUDO_PASSWORD_DONE}" != "yes" ]]; then if ! source ./setup-password.sh then echo "Failed to process password" exit 1 fi fi ############################################################################### if ! ./build-cacert.sh then echo "Failed to install CA Certs" exit 1 fi ############################################################################### if ! ./build-ncurses-readline.sh then echo "Failed to build Ncurses and Readline" exit 1 fi ############################################################################### echo "" echo "========================================" echo "================= Mawk =================" echo "========================================" echo "" echo "************************" echo "Downloading package" echo "************************" if ! "${WGET}" -q -O "$MAWK_TAR" --ca-certificate="${THE_CA_ZOO}" \ "http://invisible-island.net/datafiles/release/$MAWK_TAR" then echo "Failed to download mawk" exit 1 fi rm -rf "$MAWK_DIR" &>/dev/null gzip -d < "$MAWK_TAR" | tar xf - cd "$MAWK_DIR" || exit 1 if [[ -e ../patch/mawk.patch ]]; then echo "" echo "**********************" echo "Patching package" echo "**********************" patch -u -p0 < ../patch/mawk.patch fi # Fix sys_lib_dlsearch_path_spec bash "${INSTX_TOPDIR}/fix-configure.sh" echo "" echo "************************" echo "Configuring package" echo "************************" PKG_CONFIG_PATH="${INSTX_PKGCONFIG}" \ CPPFLAGS="${INSTX_CPPFLAGS}" \ ASFLAGS="${INSTX_ASFLAGS}" \ CFLAGS="${INSTX_CFLAGS}" \ CXXFLAGS="${INSTX_CXXFLAGS}" \ LDFLAGS="${INSTX_LDFLAGS}" \ LIBS="${INSTX_LDLIBS}" \ ./configure \ --build="${AUTOCONF_BUILD}" \ --prefix="${INSTX_PREFIX}" \ --libdir="${INSTX_LIBDIR}" if [[ "$?" -ne 0 ]]; then echo "" echo "************************" echo "Failed to configure Mawk" echo "************************" bash "${INSTX_TOPDIR}/collect-logs.sh" "${PKG_NAME}" exit 1 fi # Escape dollar sign for $ORIGIN in makefiles. Required so # $ORIGIN works in both configure tests and makefiles. bash "${INSTX_TOPDIR}/fix-makefiles.sh" echo "" echo "************************" echo "Building package" echo "************************" MAKE_FLAGS=("-j" "${INSTX_JOBS}") if ! "${MAKE}" "${MAKE_FLAGS[@]}" then echo "" echo "************************" echo "Failed to build Mawk" echo "************************" bash "${INSTX_TOPDIR}/collect-logs.sh" "${PKG_NAME}" exit 1 fi # Fix flags in *.pc files bash "${INSTX_TOPDIR}/fix-pkgconfig.sh" # Fix runpaths bash "${INSTX_TOPDIR}/fix-runpath.sh" echo "" echo "************************" echo "Testing package" echo "************************" MAKE_FLAGS=("check") if ! "${MAKE}" "${MAKE_FLAGS[@]}" then echo "" echo "************************" echo "Failed to test Mawk" echo "************************" bash "${INSTX_TOPDIR}/collect-logs.sh" "${PKG_NAME}" exit 1 fi # Fix runpaths again bash "${INSTX_TOPDIR}/fix-runpath.sh" echo "" echo "************************" echo "Installing package" echo "************************" MAKE_FLAGS=("install") if [[ -n "${SUDO_PASSWORD}" ]]; then printf "%s\n" "${SUDO_PASSWORD}" | sudo ${SUDO_ENV_OPT} -S "${MAKE}" "${MAKE_FLAGS[@]}" #printf "%s\n" "${SUDO_PASSWORD}" | sudo ${SUDO_ENV_OPT} -S ln -s "${INSTX_PREFIX}/bin/mawk" "${INSTX_PREFIX}/bin/awk" 2>/dev/null printf "%s\n" "${SUDO_PASSWORD}" | sudo ${SUDO_ENV_OPT} -S bash "${INSTX_TOPDIR}/fix-permissions.sh" "${INSTX_PREFIX}" else "${MAKE}" "${MAKE_FLAGS[@]}" #ln -s "${INSTX_PREFIX}/bin/mawk" "${INSTX_PREFIX}/bin/awk" 2>/dev/null bash "${INSTX_TOPDIR}/fix-permissions.sh" "${INSTX_PREFIX}" fi ############################################################################### echo "" echo "*****************************************************************************" echo "Please run Bash's 'hash -r' to update program cache in the current shell" echo "*****************************************************************************" ############################################################################### touch "${INSTX_PKG_CACHE}/${PKG_NAME}" cd "${CURR_DIR}" || exit 1 ############################################################################### # Set to false to retain artifacts if true; then ARTIFACTS=("$MAWK_TAR" "$MAWK_DIR") for artifact in "${ARTIFACTS[@]}"; do rm -rf "$artifact" done fi exit 0