From be8f87e3d39f8b388a7d2948b6b893e79f9d2dd4 Mon Sep 17 00:00:00 2001 From: Nicola Murino <> Date: Thu, 23 May 2024 12:00:33 +0800 Subject: [PATCH] cygwin-meson: add package Co-authored-by: Martchus <> Signed-off-by: Ookiineko --- cygwin-meson/PKGBUILD | 43 ++++++++++++++++ cygwin-meson/meson-cygwin-wrapper | 32 ++++++++++++ cygwin-meson/toolchain_generator.py | 80 +++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+) create mode 100644 cygwin-meson/PKGBUILD create mode 100644 cygwin-meson/meson-cygwin-wrapper create mode 100644 cygwin-meson/toolchain_generator.py diff --git a/cygwin-meson/PKGBUILD b/cygwin-meson/PKGBUILD new file mode 100644 index 0000000..e4d2ecd --- /dev/null +++ b/cygwin-meson/PKGBUILD @@ -0,0 +1,43 @@ +pkgname=cygwin-meson +pkgver=1 +pkgrel=25 +pkgdesc="Meson wrapper for Cygwin" +arch=('any') +url="http://fedoraproject.org/wiki/MinGW" +license=('GPL') +groups=('cygwin-toolchain') +depends=('meson' 'cygwin-gcc' 'cygwin-pkg-config') +makedepends=('cygwin-environment') +optdepends=('cygwin-wine: Set NEED_WINE env variable in your PKGBUILD to use wine support in meson') +source=(toolchain_generator.py + meson-cygwin-wrapper) +md5sums=('SKIP' + 'SKIP') + +_targets="x86_64-pc-cygwin" + +build() { + for _target in ${_targets}; do + unset CPPFLAGS + unset CFLAGS + unset CXXFLAGS + unset LDFLAGS + source cygwin-env ${_target} + python toolchain_generator.py --arch ${_target} --output-file toolchain-${_target}.meson + python toolchain_generator.py --arch ${_target} --output-file toolchain-${_target}-wine.meson --need-exe-wrapper + sed "s|@TRIPLE@|${_target}|g;" meson-cygwin-wrapper > ${_target}-meson + done +} + +package() { + install -d "$pkgdir"/usr/bin + install -d "$pkgdir"/usr/share/cygwin + install -m 755 "$srcdir"/toolchain_generator.py "$pkgdir"/usr/bin/cygwin-meson-cross-file-generator + for _target in ${_targets}; do + install -m 755 "$srcdir"/${_target}-meson "$pkgdir"/usr/bin/${_target}-meson + install -m 644 toolchain-${_target}.meson "$pkgdir"/usr/share/cygwin/ + install -m 644 toolchain-${_target}-wine.meson "$pkgdir"/usr/share/cygwin/ + done +} + +# vim: ts=2 sw=2 et: diff --git a/cygwin-meson/meson-cygwin-wrapper b/cygwin-meson/meson-cygwin-wrapper new file mode 100644 index 0000000..f73cd62 --- /dev/null +++ b/cygwin-meson/meson-cygwin-wrapper @@ -0,0 +1,32 @@ +#!/bin/sh + +if [ -z ${CROSS_FILE} ] +then + if [ -z ${NEED_WINE} ] + then + CROSS_FILE=/usr/share/cygwin/toolchain-@TRIPLE@.meson + else + CROSS_FILE=/usr/share/cygwin/toolchain-@TRIPLE@-wine.meson + MESON_EXE_WRAPPER=/usr/bin/@TRIPLE@-wine + fi +fi + +exec meson setup \ + --prefix /usr/@TRIPLE@ \ + --libdir /usr/@TRIPLE@/lib \ + --libexecdir /usr/@TRIPLE@/lib \ + --bindir /usr/@TRIPLE@/bin \ + --sbindir /usr/@TRIPLE@/bin \ + --includedir /usr/@TRIPLE@/include \ + --datadir /usr/@TRIPLE@/share \ + --mandir /usr/@TRIPLE@/share/man \ + --infodir /usr/@TRIPLE@/share/info \ + --localedir /usr/@TRIPLE@/share/locale \ + --sysconfdir /usr/@TRIPLE@/etc \ + --localstatedir /var \ + --sharedstatedir /var/lib \ + --buildtype release \ + --wrap-mode nofallback \ + --cross-file ${CROSS_FILE} \ + --default-library shared \ + "$@" diff --git a/cygwin-meson/toolchain_generator.py b/cygwin-meson/toolchain_generator.py new file mode 100644 index 0000000..65c98d0 --- /dev/null +++ b/cygwin-meson/toolchain_generator.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python +import argparse +import configparser +import os + + +class CrossFileGenerator: + + def __init__(self, arch, output_file, need_exe_wrapper): + self.arch = arch + self.output_file = output_file + self.need_exe_wrapper = need_exe_wrapper + self.cflags = os.environ['CFLAGS'] if 'CFLAGS' in os.environ else '' + self.cxxflags = os.environ["CXXFLAGS"] if 'CXXFLAGS' in os.environ else '' + self.ldflags = os.environ["LDFLAGS"] if 'LDFLAGS' in os.environ else '' + if self.arch == 'i686-pc-cygwin': + self.cpu_family = "x86" + self.processor = 'i686' + else: + self.cpu_family = 'x86_64' + self.processor = 'x86_64' + + def generate(self): + config = configparser.ConfigParser() + config['binaries'] = self.get_binaries_section() + config['properties'] = self.get_properties_section() + config['built-in options'] = self.get_builtin_options_section() + config['host_machine'] = self.get_host_machine_section() + with open(self.output_file, 'w') as configfile: + config.write(configfile) + + def get_binaries_section(self): + binaries = {'c':"'{}-gcc'".format(self.arch), + 'cpp':"'{}-g++'".format(self.arch), + 'ar':"'{}-gcc-ar'".format(self.arch), + 'pkgconfig':"'{}-pkg-config'".format(self.arch), + 'ranlib':"'{}-gcc-ranlib'".format(self.arch), + 'strip':"'{}-strip'".format(self.arch), + 'windres':"'{}-windres'".format(self.arch), + 'dlltool':"'{}-dlltool'".format(self.arch), + } + if self.need_exe_wrapper: + binaries.update({'exe_wrapper':"'{}-wine'".format(self.arch)}) + return binaries + + def get_properties_section(self): + return {'root':"'{}'".format(self.arch), + 'sys_root':"'/usr/{}'".format(self.arch), + 'needs_exe_wrapper':'true' + } + + def get_builtin_options_section(self): + return {'c_args':[f for f in self.cflags.split(" ") if f], + 'cpp_args':[f for f in self.cxxflags.split(" ") if f], + 'c_link_args':[f for f in self.ldflags.split(" ") if f], + 'cpp_link_args':[f for f in self.ldflags.split(" ") if f] + } + + def get_host_machine_section(self): + return {'system':"'cygwin'", + 'cpu_family':"'{}'".format(self.cpu_family), + 'cpu':"'{}'".format(self.processor), + 'endian':"'little'" + } + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Generate a meson cross file using CFLAGS/CXXFLAGS/LDFLAGS from env vars', + add_help=False) + required = parser.add_argument_group('required arguments') + optional = parser.add_argument_group('optional arguments') + required.add_argument('--arch', type=str, required=True, choices=['x86_64-pc-cygwin'], + help='Architecture to use for cross file generation') + required.add_argument('--output-file', type=str, required=True, help='Write the generated cross file to this path') + optional.add_argument('-h', '--help', action='help', default=argparse.SUPPRESS, + help='show this help message and exit') + optional.add_argument("--need-exe-wrapper", dest='need_exe_wrapper', action='store_true', help="Add wine as exe wrapper") + args = parser.parse_args() + generator = CrossFileGenerator(args.arch, args.output_file, args.need_exe_wrapper) + generator.generate()