root/branches/fcptr_stable_jun07/osg-config.in

Revision 1377, 5.8 kB (checked in by allenb, 6 months ago)

Make osg-config relocatable. This should allow for installed version of OpenSG to be moved from one location to another and keep working.

  • 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 = r"""@LIB_MAP_STR@"""
26
27 # various other variables needed
28 inst_prefix = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
29 inst_lib_path = os.path.join(inst_prefix, "@LIBRELPATH@")
30 inst_inc_path = os.path.join(inst_prefix, "@INCRELPATH@")
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 OpenSG'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="Output options for optimized libraries.")
79    parser.add_option("--dbg",action="store_true",help="Output options for debug libraries.")
80    if "win32" == sys.platform:
81       parser.add_option("--dbg-rt",action="store_true",help="Output options for debug runtime libraries.")
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 "win32" == sys.platform:
126        if options.dbg_rt:
127            lib_suffix = "_d"
128
129    config_info = ConfigInfoAdapter(libraries, lib_map, default_lib_settings,
130                                    options.inc_prefix, options.lib_prefix,
131                                    options.libpath_prefix, lib_suffix, options.lib_ext)
132
133    if options.cflags:
134       print config_info.getIncPathStr()
135    elif options.libs or options.llibs or options.lflags:
136       if options.libs:
137          print "%s %s"%(config_info.getLibPathStr(), config_info.getLibsStr())
138       elif options.llibs:
139          print config_info.getLibsStr()
140       elif options.lflags:
141          print config_info.getLibPathStr()
142    else:
143       printUsage()
144       sys.exit(1)
145
146    
147
148 def printUsage():
149    global parser, lib_map
150    parser.print_help()
151    print "\nLibraries: "
152    for lib_name in lib_map.keys():
153       print "   %s"%lib_name
154
155 # --- Copied from Source file --- #
156 # DO NOT MODIFY HERE
157 @LIBRARY_UTIL_SRC@
158 # ----------------------------------- #   
159
160 # Main
161 main()
Note: See TracBrowser for help on using the browser.