aboutsummaryrefslogtreecommitdiff
path: root/mingw-w64-build
diff options
context:
space:
mode:
Diffstat (limited to 'mingw-w64-build')
-rwxr-xr-xmingw-w64-build156
1 files changed, 126 insertions, 30 deletions
diff --git a/mingw-w64-build b/mingw-w64-build
index 4d0da33..066a1e2 100755
--- a/mingw-w64-build
+++ b/mingw-w64-build
@@ -1,6 +1,6 @@
-#!/bin/bash
+#!/usr/bin/env bash
#
-# Copyright (C) 2024 Kyle Schwarz <zeranoe@gmail.com>
+# Copyright (C) 2024 Kyle Schwarz <zeranoe@gmail.com>, Toni Uhlig <matzeton@googlemail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -16,12 +16,22 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-ROOT_PATH="$HOME/.zeranoe/mingw-w64"
+ROOT_PATH="$HOME/.mingw-w64-build-ng"
MINGW_W64_BRANCH="master"
BINUTILS_BRANCH="binutils-2_42-branch"
GCC_BRANCH="releases/gcc-14"
+USE_TARBALL_RELEASES=1
+
+MINGW_W64_TARBALL_VERSION="v11.0.0"
+BINUTILS_TARBALL_VERSION="2.43"
+GCC_TARBALL_VERSION="14.2.0"
+
+MINGW_W64_TARBALL_SHA512="5a0a09a572fcf152ed75c6e7830fd62e6c01decc9cbdba5552d4b9c00eebfa79f98e266ba9e403b184eb5a14bd45b24f5a4c16802a40295464e3323b8f2b11bc"
+BINUTILS_TARBALL_SHA512="27a19e23b2e8be9994f13687a6e0d6fd6db58f2013d4fd7b1c7f098069fbbee59e6500de4ea16b2218df5f23861f7925472081c3baec7a98533431c2d522c7b1"
+GCC_TARBALL_SHA512="5d2fdfc296220cc61ea65eaf35d4f880fa557933f3fa3474b5a37008ce186d33a411e4e06a1107d0a55623001708f80b3755618c63ae6d560ec890147371aa69"
+
ENABLE_THREADS="--enable-threads=posix"
JOB_COUNT=$(($(getconf _NPROCESSORS_ONLN) + 2))
@@ -47,10 +57,12 @@ Options:
--keep-artifacts don't remove source and build files after a successful build
--disable-threads disable pthreads and STL <thread>
--cached-sources use existing sources instead of downloading new ones
- --binutils-branch <branch> set Binutils branch (default: $BINUTILS_BRANCH)
- --gcc-branch <branch> set GCC branch (default: $GCC_BRANCH)
- --mingw-w64-branch <branch> set MinGW-w64 branch (default: $MINGW_W64_BRANCH)
+ --binutils-branch <branch> NOT RECOMMENDED - set Binutils branch (default: $BINUTILS_BRANCH)
+ --gcc-branch <branch> NOT RECOMMENDED - set GCC branch (default: $GCC_BRANCH)
+ --mingw-w64-branch <branch> NOT RECOMMENDED - set MinGW-w64 branch (default: $MINGW_W64_BRANCH)
+ --force-git NOT RECOMMENDED - force git clone (default: disabled)
--linked-runtime <runtime> set MinGW Linked Runtime (default: $LINKED_RUNTIME)
+ --tarball <path> generate a toolchain tarball archive (bzip2 compressed)
EOF
}
@@ -125,21 +137,59 @@ download_sources()
create_dir "$SRC_PATH"
change_dir "$SRC_PATH"
- execute "downloading MinGW-w64 source" "" \
- git clone --depth 1 -b "$MINGW_W64_BRANCH" \
- https://git.code.sf.net/p/mingw-w64/mingw-w64 mingw-w64
+ if [ ${USE_TARBALL_RELEASES} -eq 0 ]; then
+ execute "downloading MinGW-w64 source (GIT+HTTPS)" "" \
+ git clone --depth 1 -b "$MINGW_W64_BRANCH" \
+ "https://git.code.sf.net/p/mingw-w64/mingw-w64" mingw-w64
+ else
+ execute "downloading MinGW-w64 source (TAR+HTTPS)" "" \
+ curl -o mingw-w64.tar.gz \
+ "https://codeload.github.com/mirror/mingw-w64/tar.gz/refs/tags/${MINGW_W64_TARBALL_VERSION}"
+
+ MINGW_W64_sha512sum="$(sha512sum mingw-w64.tar.gz | cut -d ' ' -f 1)"
+ execute "verify MinGW-w64 SHA-512" \
+ "Hash verification failed; new: ${MINGW_W64_sha512sum}" \
+ test "${MINGW_W64_sha512sum}" = "${MINGW_W64_TARBALL_SHA512}"
+
+ execute "extract MinGW-w64 tarball" "" \
+ tar -xzf mingw-w64.tar.gz --one-top-level=mingw-w64/ --strip-components=1
+ fi
+
+ if [ ${USE_TARBALL_RELEASES} -eq 0 ]; then
+ execute "downloading Binutils source (GIT+HTTPS)" "" \
+ git clone --depth 1 -b "$BINUTILS_BRANCH" \
+ "https://sourceware.org/git/binutils-gdb.git" binutils
+ else
+ execute "downloading Binutils source (TAR+HTTPS)" "" \
+ curl -o binutils.tar.gz \
+ "https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_TARBALL_VERSION}.tar.gz"
+
+ BINUTILS_sha512sum="$(sha512sum binutils.tar.gz | cut -d ' ' -f 1)"
+ execute "verify Binutils SHA-512" \
+ "Hash verification failed; new: ${BINUTILS_sha512sum}" \
+ test "${BINUTILS_sha512sum}" = "${BINUTILS_TARBALL_SHA512}"
- execute "downloading Binutils source" "" \
- git clone --depth 1 -b "$BINUTILS_BRANCH" \
- https://sourceware.org/git/binutils-gdb.git binutils
+ execute "extract Binutils tarball" "" \
+ tar -xzf binutils.tar.gz --one-top-level=binutils/ --strip-components=1
+ fi
+
+ if [ ${USE_TARBALL_RELEASES} -eq 0 ]; then
+ execute "downloading GCC source (GIT+HTTPS)" "" \
+ git clone --depth 1 -b "$GCC_BRANCH" \
+ "https://gcc.gnu.org/git/gcc.git" gcc
+ else
+ execute "downloading GCC source (TAR+HTTPS)" "" \
+ curl -o gcc.tar.gz \
+ "https://codeload.github.com/gcc-mirror/gcc/tar.gz/refs/tags/releases/gcc-${GCC_TARBALL_VERSION}"
- execute "downloading GCC source" "" \
- git clone --depth 1 -b "$GCC_BRANCH" \
- https://gcc.gnu.org/git/gcc.git gcc
+ GCC_sha512sum="$(sha512sum gcc.tar.gz | cut -d ' ' -f 1)"
+ execute "verify GCC SHA-512" \
+ "Hash verification failed; new: ${GCC_sha512sum}" \
+ test "${GCC_sha512sum}" = "${GCC_TARBALL_SHA512}"
- execute "downloading config.guess" "" \
- curl -o config.guess \
- "https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD"
+ execute "extract GCC tarball" "" \
+ tar -xzf gcc.tar.gz --one-top-level=gcc/ --strip-components=1
+ fi
}
build()
@@ -260,14 +310,14 @@ while :; do
;;
-p|--prefix)
if [ "$2" ]; then
- PREFIX="$2"
+ PREFIX=$(realpath "$2")
shift
else
arg_error "'--prefix' requires a non-empty option argument"
fi
;;
--prefix=?*)
- PREFIX=${1#*=}
+ PREFIX=$(realpath "${1#*=}")
;;
--prefix=)
arg_error "'--prefix' requires a non-empty option argument"
@@ -296,6 +346,7 @@ while :; do
CACHED_SOURCES=1
;;
--binutils-branch)
+ USE_TARBALL_RELEASES=0
if [ "$2" ]; then
BINUTILS_BRANCH="$2"
shift
@@ -304,12 +355,14 @@ while :; do
fi
;;
--binutils-branch=?*)
+ USE_TARBALL_RELEASES=0
BINUTILS_BRANCH=${1#*=}
;;
--binutils-branch=)
arg_error "'--binutils-branch' requires a non-empty option argument"
;;
--gcc-branch)
+ USE_TARBALL_RELEASES=0
if [ "$2" ]; then
GCC_BRANCH="$2"
shift
@@ -318,6 +371,7 @@ while :; do
fi
;;
--gcc-branch=?*)
+ USE_TARBALL_RELEASES=0
GCC_BRANCH=${1#*=}
;;
--gcc-branch=)
@@ -338,6 +392,7 @@ while :; do
arg_error "'--linked-runtime' requires a non-empty option argument"
;;
--mingw-w64-branch)
+ USE_TARBALL_RELEASES=0
if [ "$2" ]; then
MINGW_W64_BRANCH="$2"
shift
@@ -346,11 +401,23 @@ while :; do
fi
;;
--mingw-w64-branch=?*)
+ USE_TARBALL_RELEASES=0
MINGW_W64_BRANCH=${1#*=}
;;
--mingw-w64-branch=)
arg_error "'--mingw-w64-branch' requires a non-empty option argument"
;;
+ --force-git)
+ USE_TARBALL_RELEASES=0
+ ;;
+ --tarball)
+ if [ "$2" ]; then
+ TARBALL=$(realpath "$2")
+ shift
+ else
+ arg_error "'--tarball' requires a non-empty option argument"
+ fi
+ ;;
i586)
BUILD_I586=1
;;
@@ -383,7 +450,7 @@ if [ "$NUM_BUILDS" -eq 0 ]; then
fi
MISSING_EXECS=""
-for exec in g++ flex bison git makeinfo m4 bzip2 curl make diff; do
+for exec in g++ flex bison git makeinfo m4 bzip2 curl make diff sha512sum cut test; do
if ! command -v "$exec" >/dev/null; then
MISSING_EXECS="$MISSING_EXECS $exec"
fi
@@ -394,7 +461,15 @@ fi
TOTAL_STEPS=0
-if [ ! "$CACHED_SOURCES" ]; then
+if [ "${USE_TARBALL_RELEASES}" -ne 0 ]; then
+ TOTAL_STEPS=$((TOTAL_STEPS + 6))
+fi
+
+if [ "$CACHED_SOURCES" ]; then
+ if [ ! -f "$SRC_PATH/mingw-w64.tar.gz" ]; then
+ arg_error "no sources found, run with --keep-artifacts first"
+ fi
+else
TOTAL_STEPS=$((TOTAL_STEPS + 4))
fi
@@ -407,6 +482,10 @@ fi
THREADS_STEPS=$((THREADS_STEPS * NUM_BUILDS))
BUILD_STEPS=$((13 * NUM_BUILDS))
+if [ ! -z "${TARBALL}" ]; then
+ TOTAL_STEPS=$((TOTAL_STEPS + 1))
+fi
+
TOTAL_STEPS=$((TOTAL_STEPS + THREADS_STEPS + BUILD_STEPS))
if [ "$ROOT_PATH_ARG" ]; then
@@ -438,15 +517,13 @@ touch "$LOG_FILE"
if [ ! "$CACHED_SOURCES" ]; then
download_sources
else
- if [ ! -f "$SRC_PATH/config.guess" ]; then
+ if [ ! -f "$SRC_PATH/gcc/config.guess" ]; then
arg_error "no sources found, run with --keep-artifacts first"
fi
fi
-
-BUILD=$(sh "$SRC_PATH/config.guess")
-
change_dir "$SRC_PATH/gcc"
+BUILD=$(sh "./config.guess")
execute "" "failed to download GCC dependencies" \
./contrib/download_prerequisites
@@ -482,9 +559,28 @@ if [ ! "$KEEP_ARTIFACTS" ]; then
remove_path "$LOG_FILE"
fi
-echo "complete, to use MinGW-w64 everywhere add these to your \$PATH:"
-for add_to_path in "${ADD_TO_PATH[@]}"; do
- printf "\t%s\n" "$add_to_path"
-done
+cat >${ROOT_PATH}/activate.sh <<EOF
+#!/usr/bin/env bash
+
+MYDIR="\$(realpath \$(dirname \${BASH_SOURCE[0]}))"
+export PATH="\${MYDIR}/i686/bin:\${MYDIR}/x86_64/bin:\${PATH}"
+EOF
+chmod +x ${ROOT_PATH}/activate.sh
+
+if [ ! -z ${TARBALL} ]; then
+ if [ "$BUILD_I586" ]; then
+ TAR_DIRS="i586"
+ fi
+ if [ "$BUILD_I686" ]; then
+ TAR_DIRS="i686"
+ fi
+ if [ "$BUILD_X86_64" ]; then
+ TAR_DIRS="${TAR_DIRS} x86_64"
+ fi
+ execute "generating tarball ${TARBALL}" "" \
+ cd ${ROOT_PATH} && tar --transform "s,^,mingw-w64-sysroot/," -cjf ${TARBALL} ${TAR_DIRS} activate.sh
+fi
+
+printf "(%d/%d): %s\n" "$CURRENT_STEP" "$TOTAL_STEPS" "complete, to use MinGW-w64 everywhere run: source ${ROOT_PATH}/activate.sh"
exit 0