|
| 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