2 # -*- coding: utf-8 -*-
4 # Copyright © 2013 Intel Corporation
6 # Permission is hereby granted, free of charge, to any person obtaining a
7 # copy of this software and associated documentation files (the "Software"),
8 # to deal in the Software without restriction, including without limitation
9 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 # and/or sell copies of the Software, and to permit persons to whom the
11 # Software is furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice (including the next
14 # paragraph) shall be included in all copies or substantial portions of the
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
31 # ./gen-symbol-redefs.py i915/.libs/libi915_dri.a old_ i915 i830
32 # ./gen-symbol-redefs.py r200/.libs/libr200_dri.a r200_ r200
34 argparser
= argparse
.ArgumentParser(description
="Generates #defines to hide driver global symbols outside of a driver's namespace.")
35 argparser
.add_argument("file",
37 help='libdrivername.a file to read')
38 argparser
.add_argument("newprefix",
39 metavar
= 'newprefix',
40 help='New prefix to give non-driver global symbols')
41 argparser
.add_argument('prefixes',
44 help='driver-specific prefixes')
45 args
= argparser
.parse_args()
47 stdout
= subprocess
.check_output(['nm', args
.file])
49 for line
in stdout
.splitlines():
50 m
= re
.match("[0-9a-z]+ [BT] (.*)", line
)
56 has_good_prefix
= re
.match(args
.newprefix
, symbol
) != None
57 for prefix
in args
.prefixes
:
58 if re
.match(prefix
, symbol
):
59 has_good_prefix
= True
64 # This is the single public entrypoint.
65 if re
.match("__driDriverGetExtensions", symbol
):
68 print '#define {0:35} {1}{0}'.format(symbol
, args
.newprefix
)