Skip to content

Commit be8f87e

Browse files
Nicola MurinoOokiineko
authored andcommitted
cygwin-meson: add package
Co-authored-by: Martchus <> Signed-off-by: Ookiineko <[email protected]>
1 parent ae2e811 commit be8f87e

File tree

3 files changed

+155
-0
lines changed

3 files changed

+155
-0
lines changed

cygwin-meson/PKGBUILD

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
pkgname=cygwin-meson
2+
pkgver=1
3+
pkgrel=25
4+
pkgdesc="Meson wrapper for Cygwin"
5+
arch=('any')
6+
url="http://fedoraproject.org/wiki/MinGW"
7+
license=('GPL')
8+
groups=('cygwin-toolchain')
9+
depends=('meson' 'cygwin-gcc' 'cygwin-pkg-config')
10+
makedepends=('cygwin-environment')
11+
optdepends=('cygwin-wine: Set NEED_WINE env variable in your PKGBUILD to use wine support in meson')
12+
source=(toolchain_generator.py
13+
meson-cygwin-wrapper)
14+
md5sums=('SKIP'
15+
'SKIP')
16+
17+
_targets="x86_64-pc-cygwin"
18+
19+
build() {
20+
for _target in ${_targets}; do
21+
unset CPPFLAGS
22+
unset CFLAGS
23+
unset CXXFLAGS
24+
unset LDFLAGS
25+
source cygwin-env ${_target}
26+
python toolchain_generator.py --arch ${_target} --output-file toolchain-${_target}.meson
27+
python toolchain_generator.py --arch ${_target} --output-file toolchain-${_target}-wine.meson --need-exe-wrapper
28+
sed "s|@TRIPLE@|${_target}|g;" meson-cygwin-wrapper > ${_target}-meson
29+
done
30+
}
31+
32+
package() {
33+
install -d "$pkgdir"/usr/bin
34+
install -d "$pkgdir"/usr/share/cygwin
35+
install -m 755 "$srcdir"/toolchain_generator.py "$pkgdir"/usr/bin/cygwin-meson-cross-file-generator
36+
for _target in ${_targets}; do
37+
install -m 755 "$srcdir"/${_target}-meson "$pkgdir"/usr/bin/${_target}-meson
38+
install -m 644 toolchain-${_target}.meson "$pkgdir"/usr/share/cygwin/
39+
install -m 644 toolchain-${_target}-wine.meson "$pkgdir"/usr/share/cygwin/
40+
done
41+
}
42+
43+
# vim: ts=2 sw=2 et:

cygwin-meson/meson-cygwin-wrapper

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
3+
if [ -z ${CROSS_FILE} ]
4+
then
5+
if [ -z ${NEED_WINE} ]
6+
then
7+
CROSS_FILE=/usr/share/cygwin/toolchain-@[email protected]
8+
else
9+
CROSS_FILE=/usr/share/cygwin/toolchain-@[email protected]
10+
MESON_EXE_WRAPPER=/usr/bin/@TRIPLE@-wine
11+
fi
12+
fi
13+
14+
exec meson setup \
15+
--prefix /usr/@TRIPLE@ \
16+
--libdir /usr/@TRIPLE@/lib \
17+
--libexecdir /usr/@TRIPLE@/lib \
18+
--bindir /usr/@TRIPLE@/bin \
19+
--sbindir /usr/@TRIPLE@/bin \
20+
--includedir /usr/@TRIPLE@/include \
21+
--datadir /usr/@TRIPLE@/share \
22+
--mandir /usr/@TRIPLE@/share/man \
23+
--infodir /usr/@TRIPLE@/share/info \
24+
--localedir /usr/@TRIPLE@/share/locale \
25+
--sysconfdir /usr/@TRIPLE@/etc \
26+
--localstatedir /var \
27+
--sharedstatedir /var/lib \
28+
--buildtype release \
29+
--wrap-mode nofallback \
30+
--cross-file ${CROSS_FILE} \
31+
--default-library shared \
32+
"$@"
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env python
2+
import argparse
3+
import configparser
4+
import os
5+
6+
7+
class CrossFileGenerator:
8+
9+
def __init__(self, arch, output_file, need_exe_wrapper):
10+
self.arch = arch
11+
self.output_file = output_file
12+
self.need_exe_wrapper = need_exe_wrapper
13+
self.cflags = os.environ['CFLAGS'] if 'CFLAGS' in os.environ else ''
14+
self.cxxflags = os.environ["CXXFLAGS"] if 'CXXFLAGS' in os.environ else ''
15+
self.ldflags = os.environ["LDFLAGS"] if 'LDFLAGS' in os.environ else ''
16+
if self.arch == 'i686-pc-cygwin':
17+
self.cpu_family = "x86"
18+
self.processor = 'i686'
19+
else:
20+
self.cpu_family = 'x86_64'
21+
self.processor = 'x86_64'
22+
23+
def generate(self):
24+
config = configparser.ConfigParser()
25+
config['binaries'] = self.get_binaries_section()
26+
config['properties'] = self.get_properties_section()
27+
config['built-in options'] = self.get_builtin_options_section()
28+
config['host_machine'] = self.get_host_machine_section()
29+
with open(self.output_file, 'w') as configfile:
30+
config.write(configfile)
31+
32+
def get_binaries_section(self):
33+
binaries = {'c':"'{}-gcc'".format(self.arch),
34+
'cpp':"'{}-g++'".format(self.arch),
35+
'ar':"'{}-gcc-ar'".format(self.arch),
36+
'pkgconfig':"'{}-pkg-config'".format(self.arch),
37+
'ranlib':"'{}-gcc-ranlib'".format(self.arch),
38+
'strip':"'{}-strip'".format(self.arch),
39+
'windres':"'{}-windres'".format(self.arch),
40+
'dlltool':"'{}-dlltool'".format(self.arch),
41+
}
42+
if self.need_exe_wrapper:
43+
binaries.update({'exe_wrapper':"'{}-wine'".format(self.arch)})
44+
return binaries
45+
46+
def get_properties_section(self):
47+
return {'root':"'{}'".format(self.arch),
48+
'sys_root':"'/usr/{}'".format(self.arch),
49+
'needs_exe_wrapper':'true'
50+
}
51+
52+
def get_builtin_options_section(self):
53+
return {'c_args':[f for f in self.cflags.split(" ") if f],
54+
'cpp_args':[f for f in self.cxxflags.split(" ") if f],
55+
'c_link_args':[f for f in self.ldflags.split(" ") if f],
56+
'cpp_link_args':[f for f in self.ldflags.split(" ") if f]
57+
}
58+
59+
def get_host_machine_section(self):
60+
return {'system':"'cygwin'",
61+
'cpu_family':"'{}'".format(self.cpu_family),
62+
'cpu':"'{}'".format(self.processor),
63+
'endian':"'little'"
64+
}
65+
66+
67+
if __name__ == '__main__':
68+
parser = argparse.ArgumentParser(description='Generate a meson cross file using CFLAGS/CXXFLAGS/LDFLAGS from env vars',
69+
add_help=False)
70+
required = parser.add_argument_group('required arguments')
71+
optional = parser.add_argument_group('optional arguments')
72+
required.add_argument('--arch', type=str, required=True, choices=['x86_64-pc-cygwin'],
73+
help='Architecture to use for cross file generation')
74+
required.add_argument('--output-file', type=str, required=True, help='Write the generated cross file to this path')
75+
optional.add_argument('-h', '--help', action='help', default=argparse.SUPPRESS,
76+
help='show this help message and exit')
77+
optional.add_argument("--need-exe-wrapper", dest='need_exe_wrapper', action='store_true', help="Add wine as exe wrapper")
78+
args = parser.parse_args()
79+
generator = CrossFileGenerator(args.arch, args.output_file, args.need_exe_wrapper)
80+
generator.generate()

0 commit comments

Comments
 (0)