|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +WGET_VERSION="1.25.0" |
| 6 | + |
| 7 | +usage() |
| 8 | +{ |
| 9 | + echo "Usage: $(basename $0) host source output" |
| 10 | +} |
| 11 | + |
| 12 | +# Validate and parse arguments |
| 13 | +if [ "$1" == "" ]; then |
| 14 | + usage |
| 15 | + echo |
| 16 | + echo "host must be specified." |
| 17 | + exit 1 |
| 18 | +elif [ "$2" == "" ]; then |
| 19 | + usage |
| 20 | + echo |
| 21 | + echo "source must be specified." |
| 22 | + exit 1 |
| 23 | +elif [ "$3" == "" ]; then |
| 24 | + usage |
| 25 | + echo |
| 26 | + echo "output must be specified." |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | + |
| 30 | +BUILD_HOST="$1" |
| 31 | +BUILD_SOURCE="$2" |
| 32 | +BUILD_OUTPUT="$3" |
| 33 | + |
| 34 | +# Set build parameters |
| 35 | +WGET_FLAGS=" \ |
| 36 | + --with-ssl=openssl \ |
| 37 | + --disable-pcre2 \ |
| 38 | + " |
| 39 | + |
| 40 | +if [ "${BUILD_HOST}" == "windows-x86_64" ]; then |
| 41 | + BUILD_PREFIX="${BUILD_OUTPUT}/wget" |
| 42 | + |
| 43 | + WGET_FLAGS+="--host=x86_64-w64-mingw32" |
| 44 | +elif [[ "${BUILD_HOST}" =~ ^macos-.* ]]; then |
| 45 | + BUILD_PREFIX="${BUILD_OUTPUT}/opt/wget" |
| 46 | + |
| 47 | + case ${BUILD_HOST} in |
| 48 | + macos-aarch64) |
| 49 | + HOMEBREW_PREFIX="/opt/homebrew" |
| 50 | + ;; |
| 51 | + macos-x86_64) |
| 52 | + HOMEBREW_PREFIX="/usr/local" |
| 53 | + ;; |
| 54 | + esac |
| 55 | + |
| 56 | + # Ensure that arch-specific Homebrew environment is configured |
| 57 | + eval $(${HOMEBREW_PREFIX}/bin/brew shellenv) |
| 58 | + |
| 59 | + # Specify statically linked libraries and their dependencies |
| 60 | + export LIBIDN2_LIBS=" \ |
| 61 | + ${HOMEBREW_PREFIX}/lib/libidn2.a \ |
| 62 | + ${HOMEBREW_PREFIX}/lib/libunistring.a \ |
| 63 | + " |
| 64 | + |
| 65 | + export OPENSSL_LIBS=" \ |
| 66 | + ${HOMEBREW_PREFIX}/lib/libssl.a \ |
| 67 | + ${HOMEBREW_PREFIX}/lib/libcrypto.a \ |
| 68 | + " |
| 69 | +else |
| 70 | + echo "ERROR: Invalid build host '${BUILD_HOST}'" |
| 71 | + exit 1 |
| 72 | +fi |
| 73 | + |
| 74 | +# Download and extract wget source code |
| 75 | +mkdir -p ${BUILD_SOURCE} |
| 76 | +pushd ${BUILD_SOURCE} |
| 77 | +wget -O wget.tar.gz https://ftp.gnu.org/gnu/wget/wget-${WGET_VERSION}.tar.gz |
| 78 | +tar --strip-components=1 -xvf wget.tar.gz |
| 79 | +popd |
| 80 | + |
| 81 | +# Build wget |
| 82 | +${BUILD_SOURCE}/configure \ |
| 83 | + ${WGET_FLAGS} \ |
| 84 | + --prefix="${BUILD_PREFIX}" |
| 85 | + |
| 86 | +make -j |
| 87 | +make install |
| 88 | + |
| 89 | +# Install root CA certificates (Mozilla CA certificate store) |
| 90 | +mkdir -p ${BUILD_PREFIX}/etc/ssl |
| 91 | +wget \ |
| 92 | + -O ${BUILD_PREFIX}/etc/ssl/cert.pem \ |
| 93 | + https://curl.se/ca/cacert.pem |
| 94 | + |
| 95 | +# Copy required dynamic-link libraries for Windows |
| 96 | +if [ "${BUILD_HOST}" == "windows-x86_64" ]; then |
| 97 | + WGET_WIN_LIBS=" \ |
| 98 | + /opt/mingw-w64-win32/x86_64-w64-mingw32/bin/libcrypto-3-x64.dll \ |
| 99 | + /opt/mingw-w64-win32/x86_64-w64-mingw32/bin/libiconv-2.dll \ |
| 100 | + /opt/mingw-w64-win32/x86_64-w64-mingw32/bin/libidn2-0.dll \ |
| 101 | + /opt/mingw-w64-win32/x86_64-w64-mingw32/bin/libintl-8.dll \ |
| 102 | + /opt/mingw-w64-win32/x86_64-w64-mingw32/bin/libssl-3-x64.dll \ |
| 103 | + /opt/mingw-w64-win32/x86_64-w64-mingw32/bin/libunistring-5.dll \ |
| 104 | + " |
| 105 | + |
| 106 | + for l in ${WGET_WIN_LIBS}; do |
| 107 | + cp -f ${l} ${BUILD_PREFIX}/bin |
| 108 | + done |
| 109 | +fi |
| 110 | + |
| 111 | +# Symlink wget executable for macOS |
| 112 | +if [[ "${BUILD_HOST}" =~ ^macos-.* ]]; then |
| 113 | + mkdir -p ${BUILD_OUTPUT}/usr/bin |
| 114 | + pushd ${BUILD_OUTPUT}/usr/bin |
| 115 | + |
| 116 | + ln -sf ../../opt/wget/bin/wget wget |
| 117 | + |
| 118 | + popd |
| 119 | +fi |
0 commit comments