2 # Copyright © 2021-2021 Yonggang Luo
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:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
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
22 gen_help
= """Generates visual studio module definition file."""
27 For input template definition file
28 For gcc/x64,gcc/arm64,visual studio
29 `wglMakeCurrent@8 @357` => `wglMakeCurrent @357`
30 `DrvCopyContext@12` => `DrvCopyContext`
31 `stw_get_device` => `stw_get_device`
33 `wglMakeCurrent@8 @357` => `wglMakeCurrent@8 @357 == wglMakeCurrent`
34 `DrvCopyContext@12` => `DrvCopyContext@12 == DrvCopyContext`
35 `stw_get_device` => `stw_get_device`
38 def gen_vs_module_def(in_file
: str, out_file
: str, compiler_abi
: str, compiler_id
: str, cpu_family
: str) -> None:
39 out_file_lines
= ['EXPORTS']
40 with
open(in_file
, 'r', encoding
='utf-8') as f
:
44 tokens
= line
.split(';')
47 def_infos
= [x
for x
in tokens
[0].split(' ') if len(x
) > 0]
50 out_file_lines
.append('\t' + line
)
52 out_file_lines
.append('')
54 name_infos
= def_infos
[0].split('@')
56 out_file_lines
.append('\t;' + line
)
58 order_info
= '' if len(def_infos
) <= 1 else def_infos
[1]
59 if def_infos
[0] != name_infos
[0] and \
60 (compiler_abi
== 'gcc' and compiler_id
!= 'clang') and (cpu_family
not in {'x86_64', 'aarch64'}):
62 out_file_lines
.append('\t' + def_infos
[0] + ' ' + order_info
+ ' == ' + name_infos
[0])
64 out_file_lines
.append('\t' + def_infos
[0] + ' == ' + name_infos
[0])
67 out_file_lines
.append('\t' + name_infos
[0] + ' ' + order_info
)
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'))
74 python ./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_abi gcc --cpu_family x86_64
75 python ./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_abi gcc --cpu_family x86
77 python ./bin/gen_vs_module_defs.py --in_file src/gallium/targets/osmesa/osmesa.def.in --out_file src/gallium/targets/osmesa/osmesa.def --compiler_abi gcc --cpu_family x86_64
78 python ./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_abi gcc --cpu_family x86
80 python ./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_abi gcc --cpu_family x86_64
81 python ./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_abi gcc --cpu_family x86
83 python ./bin/gen_vs_module_defs.py --in_file src/egl/main/egl.def.in --out_file src/egl/main/egl.def --compiler_abi gcc --cpu_family x86_64
84 python ./bin/gen_vs_module_defs.py --in_file src/egl/main/egl.def.in --out_file src/egl/main/egl.mingw.def --compiler_abi gcc --cpu_family x86
86 python ./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_abi gcc --cpu_family x86_64
87 python ./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_abi gcc --cpu_family x86
90 if __name__
== "__main__":
91 parser
= argparse
.ArgumentParser(description
=gen_help
)
92 parser
.add_argument('--in_file', help='input template module definition file')
93 parser
.add_argument('--out_file', help='output module definition file')
94 parser
.add_argument('--compiler_abi', help='compiler abi')
95 parser
.add_argument('--compiler_id', help='compiler id')
96 parser
.add_argument('--cpu_family', help='cpu family')
97 args
= parser
.parse_args()
99 gen_vs_module_def(args
.in_file
, args
.out_file
, args
.compiler_abi
, args
.compiler_id
, args
.cpu_family
)