summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIonen Wolkens <ionen@gentoo.org>2022-05-07 00:19:38 -0400
committerIonen Wolkens <ionen@gentoo.org>2022-05-12 22:29:29 -0400
commit597109c08904d741e50ce36ab94856c00fd8562f (patch)
tree67dc47af2c3b6546fc03b424999880b7bd9a2ee1 /dev-util/mingw64-toolchain
parentmedia-video/wireplumber: patch 0.4.10 to default enable backends (diff)
downloadgentoo-597109c08904d741e50ce36ab94856c00fd8562f.tar.gz
gentoo-597109c08904d741e50ce36ab94856c00fd8562f.tar.bz2
gentoo-597109c08904d741e50ce36ab94856c00fd8562f.zip
dev-util/mingw64-toolchain: new package, add 10.0.0
This package attempts to bootstrap a mingw toolchain (binutils+gcc+mingw64-runtime) without crossdev for easy use with wine and related packages like dxvk. crossdev is generally intended for advanced use, and not for a user who just want to play games (e.g. many Blizzard games don't work without USE=mingw on wine). Not the greatest solution, but should allow improving the wine situation for users until there's a better option. Signed-off-by: Ionen Wolkens <ionen@gentoo.org>
Diffstat (limited to 'dev-util/mingw64-toolchain')
-rw-r--r--dev-util/mingw64-toolchain/Manifest3
-rw-r--r--dev-util/mingw64-toolchain/files/mingw64-runtime-10.0.0-tmp-files-clash.patch10
-rw-r--r--dev-util/mingw64-toolchain/metadata.xml13
-rw-r--r--dev-util/mingw64-toolchain/mingw64-toolchain-10.0.0.ebuild300
4 files changed, 326 insertions, 0 deletions
diff --git a/dev-util/mingw64-toolchain/Manifest b/dev-util/mingw64-toolchain/Manifest
new file mode 100644
index 000000000000..059c493a8601
--- /dev/null
+++ b/dev-util/mingw64-toolchain/Manifest
@@ -0,0 +1,3 @@
+DIST binutils-2.37.tar.xz 22916924 BLAKE2B f5a374fdf0300f7734d1e462333296b16c9d5ed6eba167e1742a4da7082f4388c929e286bf76c3933b3e434937380340732a31790723654b491ea0c8ab5b9ba5 SHA512 5c11aeef6935860a6819ed3a3c93371f052e52b4bdc5033da36037c1544d013b7f12cb8d561ec954fe7469a68f1b66f1a3cd53d5a3af7293635a90d69edd15e7
+DIST gcc-11.3.0.tar.xz 81141364 BLAKE2B 7e562d25446ca4ab9fe8cdb714866f66aba3744d78bf84f31bfb097c1a981e4c7f990cb1e6bcfec5ae6671836a4984e2b70eb8fed81dcef5e244f88da8623469 SHA512 f0be5ad705c73b84477128a69c047f57dd47002f375eb60e1e842e08cf2009a509e92152bca345823926d550b7395ae6d4de7db51d1ee371c2dc37313881fca7
+DIST mingw-w64-v10.0.0.tar.bz2 9620291 BLAKE2B 451372403289c492ca939d65bb4d9f6e9fa6bdd6b32d79d6438d858e106e8cc291712ada1f3f7b951a4c6908e7d0385d485ca76920af39bcf86effa48408e330 SHA512 3c0827af7c40809a867758f6cd9ef3ff0c988b43082345bf725e03949af95968d634ace99a7ffae323189549221dcb5d861de9e801f1fbc7904e446641b60516
diff --git a/dev-util/mingw64-toolchain/files/mingw64-runtime-10.0.0-tmp-files-clash.patch b/dev-util/mingw64-toolchain/files/mingw64-runtime-10.0.0-tmp-files-clash.patch
new file mode 100644
index 000000000000..38c4abf91e77
--- /dev/null
+++ b/dev-util/mingw64-toolchain/files/mingw64-runtime-10.0.0-tmp-files-clash.patch
@@ -0,0 +1,10 @@
+Fix clash when enabling lib32 and lib64 at same time, backport from:
+https://sourceforge.net/p/mingw-w64/mingw-w64/ci/953bcd32ae470c4647e94de8548dda5a8f07d82d/
+(except directly to Makefile.in to avoid autoreconf over this)
+--- a/mingw64/mingw-w64-crt/Makefile.in
++++ b/mingw64/mingw-w64-crt/Makefile.in
+@@ -153,3 +153,3 @@
+ host_triplet = @host@
+-@DLLTOOL_HAS_TEMP_PREFIX_TRUE@am__append_1 = --temp-prefix $$(basename $@ .a)
++@DLLTOOL_HAS_TEMP_PREFIX_TRUE@am__append_1 = --temp-prefix $(basename $@)
+ @DELAY_IMPORT_LIBS_TRUE@am__append_2 = --output-delaylib $@.delayimp.a
diff --git a/dev-util/mingw64-toolchain/metadata.xml b/dev-util/mingw64-toolchain/metadata.xml
new file mode 100644
index 000000000000..7a95ab69a652
--- /dev/null
+++ b/dev-util/mingw64-toolchain/metadata.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+ <maintainer type="person">
+ <email>ionen@gentoo.org</email>
+ <name>Ionen Wolkens</name>
+ </maintainer>
+ <upstream>
+ <remote-id type="cpe">cpe:/a:gnu:gcc</remote-id>
+ <remote-id type="cpe">cpe:/a:gnu:binutils</remote-id>
+ <remote-id type="sourceforge">mingw-w64</remote-id>
+ </upstream>
+</pkgmetadata>
diff --git a/dev-util/mingw64-toolchain/mingw64-toolchain-10.0.0.ebuild b/dev-util/mingw64-toolchain/mingw64-toolchain-10.0.0.ebuild
new file mode 100644
index 000000000000..1ae7b097c037
--- /dev/null
+++ b/dev-util/mingw64-toolchain/mingw64-toolchain-10.0.0.ebuild
@@ -0,0 +1,300 @@
+# Copyright 2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+MULTILIB_COMPAT=( abi_x86_{32,64} )
+inherit edo flag-o-matic multilib-build toolchain-funcs
+
+# Pick versions known to work for Wine and use vanilla for simplicity,
+# ideally update only on mingw64-runtime bumps or if there's known issues
+# (please report) to avoid rebuilding the entire toolchain too often.
+# Do _p1++ rather than revbump if changing without bumping mingw64 itself.
+BINUTILS_PV=2.37 # 2.38 needs bug #838106
+GCC_PV=11.3.0
+
+DESCRIPTION="All-in-one mingw64 toolchain intended for building Wine without crossdev"
+HOMEPAGE="
+ https://www.mingw-w64.org/
+ https://gcc.gnu.org/
+ https://sourceware.org/binutils/"
+SRC_URI="
+ mirror://sourceforge/mingw-w64/mingw-w64/mingw-w64-release/mingw-w64-v${PV}.tar.bz2
+ mirror://gnu/gcc/gcc-${GCC_PV}/gcc-${GCC_PV}.tar.xz
+ mirror://gnu/binutils/binutils-${BINUTILS_PV}.tar.xz"
+S="${WORKDIR}"
+
+# l1:binutils+gcc, l2:gcc(libraries), l3:mingw64-runtime
+LICENSE="
+ GPL-3+
+ LGPL-3+ || ( GPL-3+ libgcc libstdc++ gcc-runtime-library-exception-3.1 )
+ ZPL BSD BSD-2 ISC LGPL-2+ LGPL-2.1+ MIT public-domain"
+SLOT="0"
+KEYWORDS="-* ~amd64 ~x86"
+IUSE="+abi_x86_32 custom-cflags debug"
+
+RDEPEND="
+ dev-libs/gmp:=
+ dev-libs/mpc:=
+ dev-libs/mpfr:=
+ sys-libs/zlib:=
+ virtual/libiconv"
+DEPEND="${RDEPEND}"
+
+PATCHES=(
+ "${FILESDIR}"/mingw64-runtime-10.0.0-tmp-files-clash.patch
+)
+
+pkg_pretend() {
+ [[ ${MERGE_TYPE} == binary ]] && return
+
+ tc-is-cross-compiler &&
+ die "cross-compilation of the toolchain itself is unsupported"
+}
+
+src_prepare() {
+ # rename directories to simplify both patching and the ebuild
+ mv binutils{-${BINUTILS_PV},} || die
+ mv gcc{-${GCC_PV},} || die
+ mv mingw-w64-v${PV} mingw64 || die
+
+ default
+}
+
+src_compile() {
+ # not great but do everything in src_compile given bootstrapping
+ # process needs to be done in steps of configure+compile+install
+ # (done modular to have most package-specific things in one place)
+
+ CTARGET=$(usex x86 i686 x86_64)-w64-mingw32
+
+ MWT_D=${T}/root # use ${T} to respect VariableScope for ${D}
+ local mwtdir=/usr/lib/${PN}
+ local prefix=${EPREFIX}${mwtdir}
+ local sysroot=${MWT_D}${prefix}
+ local -x PATH=${sysroot}/bin:${PATH}
+
+ use custom-cflags || strip-flags # fancy flags are not realistic here
+
+ local multilib=false
+ use abi_x86_32 && use abi_x86_64 && multilib=true
+
+ # global configure flags
+ local conf=(
+ --build=${CBUILD:-${CHOST}}
+ --target=${CTARGET}
+ --{doc,info,man}dir=/.skip # let individual packages handle docs
+ )
+
+ # binutils
+ local conf_binutils=(
+ --prefix="${prefix}"
+ --host=${CHOST}
+ --disable-cet
+ --disable-nls
+ --disable-shared
+ --with-system-zlib
+ --without-debuginfod
+ )
+ mwt-binutils() {
+ # replace duplicates with symlinks
+ local bin
+ for bin in "${sysroot}"/${CTARGET}/bin/*; do
+ ln -sf {../${CTARGET}/bin/,"${sysroot}"/bin/${CTARGET}-}${bin##*/} || die
+ done
+ ln -sf ld.bfd "${sysroot}"/${CTARGET}/bin/ld || die
+ }
+
+ # gcc (minimal -- if need more, disable only in stage1 / enable in stage3)
+ local conf_gcc=(
+ --prefix="${prefix}"
+ --host=${CHOST}
+ --disable-bootstrap
+ --disable-cet
+ --disable-gomp
+ --disable-libquadmath
+ --disable-libsanitizer
+ --disable-libssp
+ --disable-libvtv
+ --disable-shared
+ --with-system-zlib
+ --without-isl
+ --without-zstd
+ )
+ ${multilib} || conf_gcc+=( --disable-multilib )
+
+ local conf_gcc_stage1=(
+ --enable-languages=c
+ --disable-libatomic
+ --with-sysroot="${sysroot}"
+ )
+ local -n conf_gcc_stage2=conf_gcc_stage1
+
+ local conf_gcc_stage3=(
+ --enable-languages=c,c++
+ --enable-threads=posix # needs stage3, and is required for dxvk/vkd3d
+ --with-sysroot="${prefix}"
+ --with-build-sysroot="${sysroot}"
+ )
+ mwt-gcc_stage3() {
+ # replace duplicate with symlink
+ ln -sf ${CTARGET}-gcc "${sysroot}"/bin/${CTARGET}-gcc-${GCC_PV} || die
+ }
+
+ # mingw64-runtime (split in several parts, 3 needed for gcc stages)
+ local conf_mingw64=(
+ --prefix="${prefix}"/${CTARGET}
+ --host=${CTARGET}
+ --with-sysroot=no
+ --without-{crt,headers}
+
+ # mingw .dll aren't used by wine and packages wouldn't find them
+ # at runtime, use crossdev if need dll and proper search paths
+ --disable-shared
+ )
+
+ local conf_mingw64_headers=(
+ --enable-idl
+ --with-headers
+ )
+ mwt-mingw64_headers() { ln -s ${CTARGET} "${sysroot}"/mingw || die; } #419601
+
+ local conf_mingw64_runtime=( --with-crt )
+ ${multilib} ||
+ conf_mingw64_runtime+=( $(usex x86 --disable-lib64 --disable-lib32 ) )
+
+ local conf_mingw64_libraries=( --with-libraries )
+ local conf_mingw64_libraries32=(
+ --libdir="${prefix}"/${CTARGET}/lib32
+ --with-libraries
+ CC="${CTARGET}-gcc -m32"
+ RCFLAGS="--target=pe-i386 ${RCFLAGS}"
+ )
+
+ # mingw64-runtime's idl compiler (useful not to depend on wine for widl)
+ local conf_widl=( --prefix="${prefix}" )
+
+ # mwt-build [-x] <path/package-name> [stage-name]
+ # -> ./configure && make && make install && mwt-package() && mwt-package_stage()
+ # passes conf, conf_package, and conf_package_stage arrays to configure, and
+ # users can add options through environment with e.g.
+ # MWT_BINUTILS_CONF="--some-option"
+ # MWT_GCC_STAGE1_CONF="--some-gcc-stage1-only-option"
+ # MWT_WIDL_CONF="--some-other-option"
+ # EXTRA_ECONF="--global-option" (generic naming for if not reading this)
+ mwt-build() {
+ if [[ ${1} == -x ]]; then
+ (
+ # cross-compiling, cleanup and let ./configure handle it
+ unset AR AS CC CPP CXX LD NM OBJCOPY OBJDUMP RANLIB RC STRIP
+ CHOST=${CTARGET}
+ strip-unsupported-flags
+ mwt-build "${@:2}"
+ )
+ return
+ fi
+
+ local id=${1##*/}
+ local build_dir=${WORKDIR}/${1}${2+_${2}}-build
+
+ # econf is not allowed in src_compile and its defaults are
+ # mostly unused here, so use configure directly
+ eval '
+ local conf=( "${WORKDIR}/${1}"/configure "${conf[@]}" )
+ [[ ${conf_'${id}'@a} ]] && conf+=( "${conf_'${id}'[@]}" )
+ [[ ${2} && ${conf_'${id}_${2}'@a} ]] && conf+=( "${conf_'${id}_${2}'[@]}" )
+ conf+=( ${EXTRA_ECONF} ${MWT_'${id^^}'_CONF} )
+ [[ ${2} ]] && conf+=( ${MWT_'${1^^}_${2^^}'_CONF} )'
+
+ einfo "Building ${id}${2+ ${2}} in ${build_dir} ..."
+
+ mkdir "${build_dir}" || die
+ pushd "${build_dir}" >/dev/null || die
+
+ edo "${conf[@]}"
+ emake
+ emake DESTDIR="${MWT_D}" install
+
+ declare -f mwt-${id} >/dev/null && edo mwt-${id}
+ declare -f mwt-${id}_${2} >/dev/null && edo mwt-${id}_${2}
+
+ popd >/dev/null || die
+ }
+
+ # build with same ordering that crossdev would do + stage3 for pthreads
+ mwt-build binutils
+ mwt-build mingw64 headers
+ mwt-build gcc stage1
+ mwt-build -x mingw64 runtime
+ mwt-build gcc stage2
+ ${multilib} && mwt-build -x mingw64 libraries32
+ mwt-build -x mingw64 libraries
+ mwt-build gcc stage3
+ mwt-build mingw64/mingw-w64-tools/widl
+ # note: /could/ system-bootstrap if already installed, but gcc and
+ # libraries will use the system's older mingw64 headers/static-libs
+ # and make this potentially fragile without more workarounds/stages
+
+ if ${multilib}; then
+ # Like system's gcc, `x86_64-w64-mingw32-gcc -m32` can build for x86,
+ # but packages expect crossdev's i686-w64-mingw32-gcc which is the same
+ # just without 64bit support and would rather not build the toolchain
+ # twice. Dirty but wrap to allow simple interoperability with crossdev.
+ mwt-i686_wrapper() {
+ printf "#!/usr/bin/env sh\nexec \"${prefix}/bin/${bin}\" ${*} "'"${@}"\n' \
+ > ${bin32} || die
+ chmod +x ${bin32} || die
+ }
+ pushd "${sysroot}"/bin >/dev/null || die
+ local bin bin32
+ for bin in ${CTARGET}-*; do
+ bin32=${bin/x86_64-w64/i686-w64}
+ case ${bin#${CTARGET}-} in
+ gcc|gcc-${GCC_PV}|g++|widl) mwt-i686_wrapper -m32;;
+ ld|ld.bfd) mwt-i686_wrapper -m i386pe;;
+ windres) mwt-i686_wrapper --target=pe-i386;;
+ *) ln -s ${bin} ${bin32} || die;;
+ esac
+ done
+ popd >/dev/null || die
+ fi
+
+ # portage doesn't know the right strip executable to use for CTARGET
+ # and it can lead to .a mangling, notably with 32bit (breaks toolchain)
+ dostrip -x ${mwtdir}/{${CTARGET}/lib{,32},lib/gcc/${CTARGET}}
+
+ # ... and instead do it here given this saves ~60MB
+ if use !debug; then
+ einfo "Stripping ${CTARGET} static libraries ..."
+ find "${sysroot}"/{,lib/gcc/}${CTARGET} -type f -name '*.a' \
+ -exec ${CTARGET}-strip --strip-unneeded {} + || die
+ fi
+}
+
+src_install() {
+ # use mv over copying given it's ~370MB
+ mv "${MWT_D}${EPREFIX}"/* "${ED}" || die
+
+ # gcc handles static libs internally without needing .la
+ find "${ED}" -type f -name '*.la' -delete || die
+}
+
+pkg_postinst() {
+ if [[ ! ${REPLACING_VERSIONS} ]]; then
+ elog "Note that this package is primarily intended for Wine and related"
+ elog "packages to depend on without needing a manual crossdev setup."
+ elog
+ elog "Settings are oriented only for what these need and simplicity."
+ elog "Please use sys-devel/crossdev for full toolchain/customization:"
+ elog " https://wiki.gentoo.org/wiki/Mingw"
+ elog " https://wiki.gentoo.org/wiki/Crossdev"
+ fi
+
+ local cross_gcc=cross-$(usex x86 i686 x86_64)-w64-mingw32/gcc
+ if has_version ${cross_gcc}; then
+ # encourage cleanup given users may not realize if switch by default
+ ewarn "${cross_gcc} is installed, note that ${PN}"
+ ewarn "is redundant with the *-w64-mingw32/{binutils,gcc,mingw64-runtime}"
+ ewarn "packages and optionally only one needs to be kept."
+ fi
+}