root/trunk/osg-config.in

Revision 839, 5.7 kB (checked in by vossg, 1 year ago)

fixed : readded the _d suffix for windows

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1 #!/usr/bin/env python
2 #
3 # Commandline tool for querying information about OpenSG libraries and required
4 # flags to compile.
5 #
6 # Much of this file is autogenerated at build time, so make sure to modify
7 # the .in version of this file in the build if you want to make changes
8 #
9 # The main components of this file are:
10 # - A set of classes at the end of the file that are automatically included
11 #   from the OpenSG build system.  These are used to store and analyze
12 #   the library information.  Most of the logic used in this tool is in these classes.
13 # - A string rep list of dictionaries that are automatically created by the build
14 #   and represent the state of the library objects from the build.  This list
15 #   is used to construct a local representation of the library information for OpenSG.
16 # - The option parser.  This section of the code is responsible for reading options and
17 #   calling the appropriate methods of the library info classes.
18 #
19 import os, os.path, sys
20 pj = os.path.join
21 from optparse import OptionParser
22
23 # List of dictionaries in string format that will
24 # be used to build library information
25 lib_map_str = """@LIB_MAP_STR@"""
26
27 # various other variables needed
28 inst_prefix = "@PREFIX@"
29 inst_lib_path = "@LIBPATH@"
30 inst_inc_path = "@INCPATH@"
31 version = "@VERSION@"
32
33 lib_map_list = eval(lib_map_str)
34 parser = None
35 lib_map = {}
36
37 def main():
38    global parser, lib_map
39    
40    # Create library map from the dumped set of dictionaries
41    for i in lib_map_list:
42       if i.has_key("name"):
43          name = i["name"]
44          lib_map[name] = LibraryInfo(name)
45          lib_map[name].load(i)
46
47    # Determine defaults
48    if "win32" == sys.platform:
49       def_incprefix = "/I"
50       def_libprefix = ""
51       def_libext = ".lib"
52       def_libpathprefix = "/LIBPATH:"
53    else:
54       def_incprefix = "-I"
55       def_libprefix = "-l"
56       def_libext = ""
57       def_libpathprefix = "-L"
58      
59    # Create parser
60    parser = OptionParser(usage="%prog [LIBRARY] [OPTIONS]", description="OpenSG config options.")
61
62    parser.add_option("--prefix",action="store_true",help="Print the installation prefix.")
63    parser.add_option("--version",action="store_true",help="Print the installed CppDom's version number.")
64    parser.add_option("--cflags",action="store_true",help="Print OpenSG specific cflags.")
65    parser.add_option("--lflags",action="store_true",help="Print library flags.")
66    parser.add_option("--llibs",action="store_true",help="Print library list.")
67    parser.add_option("--libs",action="store_true",help="Print libraries and flags.")
68    parser.add_option("--no-prefix-flags",action="store_true",
69                      help="When printing list of libraries and paths, don't include compiler prefix flags (-I,-l,-L)")
70    parser.add_option("--inc-prefix",default=def_incprefix,
71                      help="Compiler include path prefix to use. (%s)"%def_incprefix)
72    parser.add_option("--lib-prefix",default=def_libprefix,
73                      help="Linker lib prefix to use. (%s)"%def_libprefix)
74    parser.add_option("--lib-ext",default=def_libext,
75                      help="Linker lib subfix to use. (%s)"%def_libext)
76    parser.add_option("--libpath-prefix",default=def_libpathprefix,
77                      help="Linker library path prefix to use. (%s)"%def_libpathprefix)
78    parser.add_option("--opt",action="store_true",help="Ignored for backwards compatibility.")
79    parser.add_option("--dbg",action="store_true",help="Ignored for backwards compatibility.")
80    if "win32" == sys.platform:
81       parser.add_option("--hybrid",action="store_true",help="Ignored for backwards compatibility.")
82
83    (options, pos_args) = parser.parse_args() 
84
85    # Process simple single options
86    if options.prefix:
87       print inst_prefix
88       return
89    elif options.version:
90       print version
91       return
92
93    # Try to find libname
94    # - Try given name and name with OSG or OSGWindow prefix
95    libraries = []
96    if len(pos_args):     
97       for n in pos_args:
98          for name_alt in [n, "OSG"+n, "OSGWindow"+n, None]:
99             if not name_alt:
100                print "Error: Can not find library named: ", n           
101             elif lib_map.has_key(name_alt):
102                libraries.append(lib_map[name_alt])
103                break
104
105
106    # Make sure we have libraries
107    if len(libraries) == 0:
108       printUsage()
109       sys.exit(1)
110
111    # If set to no prefix flags, then clear all defaults
112    if options.no_prefix_flags:
113       options.inc_prefix = ""
114       options.lib_prefix = ""
115       options.lib_ext = ""
116       options.libpath_prefix = ""
117
118    # Create a configuration adapter for the required library
119    default_lib_settings = LibraryInfo()
120    default_lib_settings.libpath.insert(0, inst_lib_path)
121    default_lib_settings.cpppath.insert(0, inst_inc_path)
122
123    lib_suffix = ""
124
125    if options.dbg and sys.platform == "win32":
126        lib_suffix = "_d"
127    elif "win32" == sys.platform and options.hybrid:
128        lib_suffix = "_h"
129
130    config_info = ConfigInfoAdapter(libraries, lib_map, default_lib_settings,
131                                    options.inc_prefix, options.lib_prefix,
132                                    options.libpath_prefix, lib_suffix, options.lib_ext)
133
134    if options.cflags:
135       print config_info.getIncPathStr()
136    elif options.libs or options.llibs or options.lflags:
137       if options.libs:
138          print "%s %s"%(config_info.getLibPathStr(), config_info.getLibsStr())
139       elif options.llibs:
140          print config_info.getLibsStr()
141       elif options.lflags:
142          print config_info.getLibPathStr()
143    else:
144       printUsage()
145       sys.exit(1)
146
147    
148
149 def printUsage():
150    global parser, lib_map
151    parser.print_help()
152    print "\nLibraries: "
153    for lib_name in lib_map.keys():
154       print "   %s"%lib_name
155
156 # --- Copied from Source file --- #
157 # DO NOT MODIFY HERE
158 @LIBRARY_UTIL_SRC@
159 # ----------------------------------- #   
160
161 # Main
162 main()
Note: See TracBrowser for help on using the browser.