|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Build only in new directories. The optional third argument is an offline |
| 3 | +# directory containing the exact source archives from sources.lock.json. |
| 4 | +set -euo pipefail |
| 5 | +RECIPE_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" |
| 6 | +WORK_ROOT="$(realpath -m -- "${1:?Pass a new build directory}")" |
| 7 | +OUTPUT_ROOT="$(realpath -m -- "${2:?Pass a new output directory}")" |
| 8 | +SOURCE_CACHE="${3:-}" |
| 9 | +if [[ -e "$WORK_ROOT" || -e "$OUTPUT_ROOT" ]]; then |
| 10 | + echo 'Build and output directories must not already exist.' >&2 |
| 11 | + exit 1 |
| 12 | +fi |
| 13 | +mkdir -p "$WORK_ROOT" "$OUTPUT_ROOT" |
| 14 | +exec > >(tee "$OUTPUT_ROOT/build.log") 2>&1 |
| 15 | +export LC_ALL=C TZ=UTC SOURCE_DATE_EPOCH=1782568800 |
| 16 | +export CROSS=x86_64-w64-mingw32 |
| 17 | +export CC="$CROSS-gcc-posix" CXX="$CROSS-g++-posix" |
| 18 | +export AR="$CROSS-ar" RANLIB="$CROSS-ranlib" STRIP="$CROSS-strip" |
| 19 | +export CFLAGS='-O2 -pipe -fno-ident' CXXFLAGS='-O2 -pipe -fno-ident' |
| 20 | +export LDFLAGS='-static -static-libgcc -static-libstdc++ -Wl,--no-insert-timestamp' |
| 21 | +PREFIX="$WORK_ROOT/prefix" |
| 22 | +export PKG_CONFIG_LIBDIR="$PREFIX/lib/pkgconfig" |
| 23 | +export PKG_CONFIG_PATH='' PKG_CONFIG_SYSROOT_DIR='' |
| 24 | +JOBS="${JOBS:-$(nproc)}" |
| 25 | +mkdir -p "$PREFIX" "$WORK_ROOT/configuration" "$WORK_ROOT/toolchain-licenses" |
| 26 | +python3 "$RECIPE_DIR/package.py" fetch "$WORK_ROOT" "$SOURCE_CACHE" |
| 27 | + |
| 28 | +cat > "$WORK_ROOT/cross.ini" <<EOF |
| 29 | +[binaries] |
| 30 | +c = '$CC' |
| 31 | +cpp = '$CXX' |
| 32 | +ar = '$AR' |
| 33 | +strip = '$STRIP' |
| 34 | +windres = '$CROSS-windres' |
| 35 | +pkg-config = 'pkg-config' |
| 36 | +[properties] |
| 37 | +needs_exe_wrapper = true |
| 38 | +pkg_config_libdir = ['$PKG_CONFIG_LIBDIR'] |
| 39 | +[host_machine] |
| 40 | +system = 'windows' |
| 41 | +cpu_family = 'x86_64' |
| 42 | +cpu = 'x86_64' |
| 43 | +endian = 'little' |
| 44 | +EOF |
| 45 | +cp "$WORK_ROOT/cross.ini" "$WORK_ROOT/configuration/cross.ini" |
| 46 | +{ |
| 47 | + "$CC" --version |
| 48 | + "$CXX" --version |
| 49 | + "$CROSS-ld" --version |
| 50 | + meson --version |
| 51 | + ninja --version |
| 52 | + nasm -v |
| 53 | + python3 --version |
| 54 | + dpkg-query -W -f='${binary:Package}\t${Version}\t${source:Package}\t${source:Version}\n' \ |
| 55 | + gcc-mingw-w64-x86-64-posix g++-mingw-w64-x86-64-posix \ |
| 56 | + mingw-w64-common mingw-w64-x86-64-dev |
| 57 | +} > "$WORK_ROOT/configuration/toolchain.txt" |
| 58 | +for package in gcc-mingw-w64-x86-64-posix g++-mingw-w64-x86-64-posix mingw-w64-common mingw-w64-x86-64-dev; do |
| 59 | + cp -L "/usr/share/doc/$package/copyright" "$WORK_ROOT/toolchain-licenses/$package.txt" |
| 60 | +done |
| 61 | + |
| 62 | +meson_build() { |
| 63 | + local name="$1"; shift |
| 64 | + meson setup "$WORK_ROOT/build-$name" "$WORK_ROOT/src/$name" \ |
| 65 | + --cross-file "$WORK_ROOT/cross.ini" --prefix "$PREFIX" --libdir lib \ |
| 66 | + --buildtype release --default-library static --wrap-mode nofallback \ |
| 67 | + -Dauto_features=disabled "$@" |
| 68 | + ninja -C "$WORK_ROOT/build-$name" -j "$JOBS" |
| 69 | + ninja -C "$WORK_ROOT/build-$name" install |
| 70 | + cp "$WORK_ROOT/build-$name/meson-info/intro-buildoptions.json" \ |
| 71 | + "$WORK_ROOT/configuration/$name-buildoptions.json" |
| 72 | +} |
| 73 | +meson_build freetype -Dharfbuzz=disabled -Dbrotli=disabled -Dbzip2=disabled -Dpng=disabled -Dzlib=none -Dtests=disabled |
| 74 | +meson_build fribidi -Ddocs=false -Dbin=false -Dtests=false |
| 75 | +meson_build harfbuzz -Dglib=disabled -Dgobject=disabled -Dcairo=disabled -Dicu=disabled \ |
| 76 | + -Dfreetype=disabled -Dgraphite2=disabled -Dtests=disabled -Dutilities=disabled \ |
| 77 | + -Ddocs=disabled -Dintrospection=disabled -Dwith_libstdcxx=false |
| 78 | +meson_build libass -Ddirectwrite=enabled -Dfontconfig=disabled -Dcoretext=disabled \ |
| 79 | + -Dlibunibreak=disabled -Dtest=disabled -Dcompare=disabled -Dprofile=disabled \ |
| 80 | + -Dfuzz=disabled -Dcheckasm=disabled -Dasm=enabled |
| 81 | + |
| 82 | +( |
| 83 | + cd "$WORK_ROOT/src/x264" |
| 84 | + ./configure --prefix="$PREFIX" --host="$CROSS" --cross-prefix="$CROSS-" \ |
| 85 | + --enable-static --disable-cli --disable-opencl --disable-lavf --disable-swscale |
| 86 | + make -j "$JOBS" |
| 87 | + make install |
| 88 | + cp config.mak "$WORK_ROOT/configuration/x264-config.mak" |
| 89 | +) |
| 90 | +( |
| 91 | + cd "$WORK_ROOT/src/lame" |
| 92 | + ./configure --prefix="$PREFIX" --host="$CROSS" \ |
| 93 | + --enable-static --disable-shared --disable-frontend --disable-decoder --disable-cpml |
| 94 | + make -j "$JOBS" |
| 95 | + make install |
| 96 | + cp config.log "$WORK_ROOT/configuration/lame-config.log" |
| 97 | +) |
| 98 | +( |
| 99 | + cd "$WORK_ROOT/src/ffmpeg" |
| 100 | + ./configure --prefix="$PREFIX" --target-os=mingw32 --arch=x86_64 \ |
| 101 | + --cross-prefix="$CROSS-" --cc="$CC" --cxx="$CXX" --ar="$AR" --ranlib="$RANLIB" \ |
| 102 | + --pkg-config=pkg-config --pkg-config-flags=--static \ |
| 103 | + --extra-cflags="$CFLAGS -I$PREFIX/include" --extra-cxxflags="$CXXFLAGS -I$PREFIX/include" \ |
| 104 | + --extra-ldflags="$LDFLAGS -L$PREFIX/lib" \ |
| 105 | + --extra-version=ufriend1 --enable-gpl --enable-version3 \ |
| 106 | + --enable-static --disable-shared --disable-autodetect --disable-doc --disable-debug \ |
| 107 | + --disable-ffplay --disable-network --disable-pthreads --enable-w32threads \ |
| 108 | + --enable-libass --enable-libx264 --enable-libmp3lame |
| 109 | + make -j "$JOBS" |
| 110 | + make install |
| 111 | + cp ffbuild/config.mak ffbuild/config.log config.h "$WORK_ROOT/configuration/" |
| 112 | +) |
| 113 | +python3 "$RECIPE_DIR/package.py" package "$WORK_ROOT" "$OUTPUT_ROOT" |
0 commit comments