1#!/usr/bin/env python3 2# Copyright © 2021-2021 Yonggang Luo 3 4# Permission is hereby granted, free of charge, to any person obtaining a copy 5# of this software and associated documentation files (the "Software"), to deal 6# in the Software without restriction, including without limitation the rights 7# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8# copies of the Software, and to permit persons to whom the Software is 9# furnished to do so, subject to the following conditions: 10 11# The above copyright notice and this permission notice shall be included in 12# all copies or substantial portions of the Software. 13 14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20# SOFTWARE. 21 22gen_help = """Generates visual studio module definition file.""" 23 24import argparse 25 26""" 27For input template definition file 28For gcc/x64,gcc/arm64,visual studio 29`wglMakeCurrent@8 @357` => `wglMakeCurrent @357` 30`DrvCopyContext@12` => `DrvCopyContext` 31`stw_get_device` => `stw_get_device` 32For gcc/x86,gcc/arm 33`wglMakeCurrent@8 @357` => `wglMakeCurrent@8 @357 == wglMakeCurrent` 34`DrvCopyContext@12` => `DrvCopyContext@12 == DrvCopyContext` 35`stw_get_device` => `stw_get_device` 36 37""" 38def gen_vs_module_def(in_file: str, out_file: str, compiler_id: str, cpu_family: str) -> None: 39 out_file_lines = ['EXPORTS'] 40 with open(in_file, 'r', encoding='utf-8') as f: 41 lines = f.readlines() 42 for line in lines: 43 line = line.strip() 44 tokens = line.split(';') 45 if not tokens: 46 continue 47 def_infos = [x for x in tokens[0].split(' ') if len(x) > 0] 48 if not def_infos: 49 if line: 50 out_file_lines.append('\t' + line) 51 else: 52 out_file_lines.append('') 53 continue 54 name_infos = def_infos[0].split('@') 55 if not name_infos: 56 out_file_lines.append('\t;' + line) 57 continue 58 order_info = '' if len(def_infos) <= 1 else def_infos[1] 59 if def_infos[0] != name_infos[0] and \ 60 (compiler_id == 'gcc') and (cpu_family not in {'x86_64', 'aarch64'}): 61 if order_info: 62 out_file_lines.append('\t' + def_infos[0] + ' ' + order_info + ' == ' + name_infos[0]) 63 else: 64 out_file_lines.append('\t' + def_infos[0] + ' == ' + name_infos[0]) 65 else: 66 if order_info: 67 out_file_lines.append('\t' + name_infos[0] + ' ' + order_info) 68 else: 69 out_file_lines.append('\t' + name_infos[0]) 70 with open(out_file, 'wb') as f: 71 out_file_content = '\n'.join(out_file_lines) + '\n' 72 f.write(out_file_content.encode('utf-8')) 73''' 74python ./bin/gen_vs_module_defs.py --in_file src/gallium/targets/libgl-gdi/opengl32.def.in --out_file src/gallium/targets/libgl-gdi/opengl32.def --compiler_id gcc --cpu_family x86_64 75python ./bin/gen_vs_module_defs.py --in_file src/gallium/targets/libgl-gdi/opengl32.def.in --out_file src/gallium/targets/libgl-gdi/opengl32.mingw.def --compiler_id gcc --cpu_family x86 76 77python ./bin/gen_vs_module_defs.py --in_file src/gallium/targets/osmesa/osmesa.def.in --out_file src/gallium/targets/osmesa/osmesa.def --compiler_id gcc --cpu_family x86_64 78python ./bin/gen_vs_module_defs.py --in_file src/gallium/targets/osmesa/osmesa.def.in --out_file src/gallium/targets/osmesa/osmesa.mingw.def --compiler_id gcc --cpu_family x86 79 80python ./bin/gen_vs_module_defs.py --in_file src/gallium/targets/wgl/gallium_wgl.def.in --out_file src/gallium/targets/wgl/gallium_wgl.def --compiler_id gcc --cpu_family x86_64 81python ./bin/gen_vs_module_defs.py --in_file src/gallium/targets/wgl/gallium_wgl.def.in --out_file src/gallium/targets/wgl/gallium_wgl.mingw.def --compiler_id gcc --cpu_family x86 82 83python ./bin/gen_vs_module_defs.py --in_file src/egl/main/egl.def.in --out_file src/egl/main/egl.def --compiler_id gcc --cpu_family x86_64 84python ./bin/gen_vs_module_defs.py --in_file src/egl/main/egl.def.in --out_file src/egl/main/egl.mingw.def --compiler_id gcc --cpu_family x86 85 86python ./bin/gen_vs_module_defs.py --in_file src/gallium/targets/lavapipe/vulkan_lvp.def.in --out_file src/gallium/targets/lavapipe/vulkan_lvp.def --compiler_id gcc --cpu_family x86_64 87python ./bin/gen_vs_module_defs.py --in_file src/gallium/targets/lavapipe/vulkan_lvp.def.in --out_file src/gallium/targets/lavapipe/vulkan_lvp.mingw.def --compiler_id gcc --cpu_family x86 88 89''' 90if __name__ == "__main__": 91 parser = argparse.ArgumentParser(description=gen_help) 92 parser.add_argument('--in_file', help='input template moudle definition file') 93 parser.add_argument('--out_file', help='output moudle definition file') 94 parser.add_argument('--compiler_id', help='compiler id') 95 parser.add_argument('--cpu_family', help='cpu family') 96 args = parser.parse_args() 97 # print(args) 98 gen_vs_module_def(args.in_file, args.out_file, args.compiler_id, args.cpu_family) 99