/[ascend]/trunk/ascend-config.in
ViewVC logotype

Annotation of /trunk/ascend-config.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2415 - (hide annotations) (download)
Tue Mar 15 00:36:13 2011 UTC (13 years, 7 months ago) by jpye
File size: 4372 byte(s)
Hopefully provide output from ascend-config that is acceptable to SCons 1.3.x and newer.
1 johnpye 683 #!@PYTHON@
2     from optparse import OptionParser
3 jpye 2083 import sys, platform, os
4 johnpye 683
5     #---------------------
6     # This file is generated automatically by SCons and installed in at INSTALL_BIN.
7     # Use it to query for local configuration of ASCEND on your system for example
8     # when building external 'plugins' such as external computations and external
9     # solvers etc.
10     #
11     # It's written in python since (because of SCons) we know we have Python on
12 johnpye 692 # this system already but we don't know that about unix shell (eg on Windows).
13 johnpye 683 #
14     # Note that SCons supports reading of the output from this script, using
15 johnpye 965 # features offered since version 0.96.91, although this functionality
16     # is a bit problematic on the Windows platform, and/or when paths contain spaces.
17 johnpye 683 #
18     # This file inspired by other software that uses the same approach, eg
19     # ginac-config, xft-config, cppunit-config.
20     #
21     # Type ascend-config --help for usage.
22     #---------------------
23    
24 jpye 2083 def path_absolute(p):
25     """Mac-specific routine for making absolute paths based on location of this
26     Python script, which will have been embedded in the ASCEND.app/Contents
27     dir."""
28     if os.path.isabs(p):
29     return p
30     else:
31     return os.path.join(sys.path[0],p)
32    
33 jpye 1742 # platform specific name munging for '-L' and '-I' file paths...
34     munge = lambda s: s
35    
36 johnpye 922 if platform.system()=="Windows":
37     import _winreg
38     x=_winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE)
39     y= _winreg.OpenKey(x,r"SOFTWARE\ASCEND")
40     LIB,t = _winreg.QueryValueEx(y,"INSTALL_LIB")
41     BIN,t = _winreg.QueryValueEx(y,"INSTALL_BIN")
42     INCLUDE,t = _winreg.QueryValueEx(y,"INSTALL_INCLUDE")
43     ASCDATA,t = _winreg.QueryValueEx(y,"INSTALL_ASCDATA")
44     MODELS,t = _winreg.QueryValueEx(y,"INSTALL_MODELS")
45 johnpye 683
46 jpye 1998 #assume that these won't change too much on Windows...
47     EXTLIB_SUFFIX = "_ascend.dll"
48     EXTLIB_PREFIX = ""
49    
50 johnpye 922 _winreg.CloseKey(y)
51     _winreg.CloseKey(x)
52 jpye 1742
53     try:
54     # if we have access to GetShortPathName, we'll use it...
55     import win32api
56     def munge1(s):
57     s1 = s
58     try:
59     # we can only munge the path if it actually exists
60     s1 = win32api.GetShortPathName(s)
61     except:
62     # if it doesn't exist, we just return the un-munged path
63     pass
64 jpye 2415 # follow the pkg-config approach and use forward slashes instead of backslashes
65     s1 = s1.replace("\\","/")
66 jpye 1742 return s1
67     munge = munge1
68     except:
69     pass
70 jpye 2083
71     elif platform.system()=="Darwin":
72     LIB = path_absolute("")
73     BIN = path_absolute("")
74     INCLUDE = path_absolute("Headers")
75     ASCDATA = path_absolute("Resources")
76     MODELS = path_absolute("""@ASC_LIBRARY_REL_DIST@""")
77     SOLVERS = path_absolute("""@ASC_SOLVERS_REL_DIST@""")
78    
79 johnpye 922 else:
80 jpye 2083 # For Linux and whatever else, use the original values passed to us from SCons:
81 johnpye 922 LIB="@INSTALL_LIB@"
82     BIN="@INSTALL_BIN@"
83     INCLUDE="@INSTALL_INCLUDE@"
84     ASCDATA="@INSTALL_ASCDATA@"
85     MODELS="@INSTALL_MODELS@"
86 jpye 1998 EXTLIB_SUFFIX="@EXTLIB_SUFFIX@"
87     EXTLIB_PREFIX="@EXTLIB_PREFIX@"
88 johnpye 683
89     usage = "usage: %prog [--help,...]"
90     # the rest of this script is about returning those values in the standard way
91     parser = OptionParser(usage=usage, version="@VERSION@")
92    
93     parser.add_option("--libs", action="store_true", dest="libs", help="show linker flags (for ASCEND libraries)")
94     parser.add_option("--cppflags", action="store_true", dest="cppflags", help="show C pre-processor flags (for ASCEND header files)")
95     parser.add_option("--data", action="store_true", dest="data", help="show location of ASCEND data files")
96 johnpye 721 parser.add_option("--models", action="store_true", dest="models", help="show location of ASCEND model library")
97 jpye 1998 parser.add_option("--extlib-suffix", action="store_true", dest="extlibsuff", help="show suffix to be used with external libraries")
98     parser.add_option("--extlib-prefix", action="store_true", dest="extlibpref", help="show prefix to be used with external libraries")
99 johnpye 683
100     (options, args) = parser.parse_args()
101    
102     ok = False
103    
104     if options.cppflags:
105     include = ""
106     if INCLUDE!="/usr/include":
107     include=INCLUDE
108 jpye 2415 if len(include):
109 jpye 1743 print "-I"+munge(include)+""
110 johnpye 683 ok = True
111    
112     if options.libs:
113     libs = ""
114     if LIB!="/usr/lib":
115     libs = LIB
116 jpye 2415 Lflag = ""
117     if len(libs):
118     Lflag = "-L"+munge(libs)+" "
119     print Lflag + "-lascend"
120 johnpye 683 ok = True
121    
122     if options.data:
123     print ASCDATA
124     ok = True
125    
126 johnpye 721 if options.models:
127     print MODELS
128     ok = True
129    
130 jpye 1998 if options.extlibsuff:
131     print EXTLIB_SUFFIX
132     ok = True
133    
134     if options.extlibpref:
135     print EXTLIB_PREFIX
136     ok = True
137    
138 johnpye 683 if not ok:
139 johnpye 721 sys.stderr.write("invalid option '%s' (use --help for more info)\n" % args)
140 johnpye 683 sys.exit(1)
141 johnpye 922

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22