2 # GObject-Introspection - a framework for introspecting GObject libraries
3 # Copyright (C) 2008 Johan Dahlin
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 # Boston, MA 02111-1307, USA.
24 # Copied from h2defs.py
25 _upperstr_pat1 = re.compile(r'([^A-Z])([A-Z])')
26 _upperstr_pat2 = re.compile(r'([A-Z][A-Z])([A-Z][0-9a-z])')
27 _upperstr_pat3 = re.compile(r'^([A-Z])([A-Z])')
30 def to_underscores(name):
31 """Converts a typename to the equivalent underscores name.
32 This is used to form the type conversion macros and enum/flag
34 name = _upperstr_pat1.sub(r'\1_\2', name)
35 name = _upperstr_pat2.sub(r'\1_\2', name)
36 name = _upperstr_pat3.sub(r'\1_\2', name, count=1)
40 def to_underscores_noprefix(name):
41 """Like to_underscores, but designed for "unprefixed" names.
42 to_underscores("DBusFoo") => dbus_foo, not d_bus_foo."""
43 name = _upperstr_pat1.sub(r'\1_\2', name)
44 name = _upperstr_pat2.sub(r'\1_\2', name)
47 _libtool_pat = re.compile("dlname='([A-z0-9\.\-\+]+)'\n")
50 def extract_libtool(libname):
51 data = open(libname).read()
52 filename = _libtool_pat.search(data).groups()[0]
53 libname = os.path.join(os.path.dirname(libname),
55 # FIXME: This hackish, but I'm not sure how to do this
56 # in a way which is compatible with both libtool 2.2
57 # and pre-2.2. Johan 2008-10-21
58 libname = libname.replace('.libs/.libs', '.libs')