summarylogtreecommitdiffstats
path: root/toolchain_generator.py
diff options
context:
space:
mode:
authorNicola Murino2019-12-08 12:03:14 +0100
committerNicola Murino2019-12-08 12:03:14 +0100
commitdd344c749391da36d80b58ee17b6b123f9169468 (patch)
tree0a2d883eb4426a55e47da5434bf99bbc0f5d65d0 /toolchain_generator.py
parent53faa09ac862c1164f2a071b7914f24569a00cff (diff)
downloadaur-dd344c749391da36d80b58ee17b6b123f9169468.tar.gz
use *flags from mingw-w64-environment
Diffstat (limited to 'toolchain_generator.py')
-rwxr-xr-xtoolchain_generator.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/toolchain_generator.py b/toolchain_generator.py
new file mode 100755
index 000000000000..0ef4e5e9dab0
--- /dev/null
+++ b/toolchain_generator.py
@@ -0,0 +1,76 @@
+#!/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"]
+ self.cxxflags = os.environ["CXXFLAGS"]
+ self.ldflags = os.environ["LDFLAGS"]
+ if self.arch == 'i686-w64-mingw32':
+ 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['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),
+ 'fortran':"'{}-gfortran'".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),
+ 'cmake':"'{}-cmake'".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),
+ '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],
+ 'needs_exe_wrapper':'true'
+ }
+
+ def get_host_machine_section(self):
+ return {'system':"'windows'",
+ '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=['i686-w64-mingw32', 'x86_64-w64-mingw32'],
+ 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 exec wrapper")
+ args = parser.parse_args()
+ generator = CrossFileGenerator(args.arch, args.output_file, args.need_exe_wrapper)
+ generator.generate()