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

Contents of /trunk/ascend-config.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2083 - (show annotations) (download)
Thu Sep 24 06:37:53 2009 UTC (9 years, 7 months ago) by jpye
File size: 4408 byte(s)
Almost there... ASCEND.app runs OK from command line now, but errors from Finder.
1 #!@PYTHON@
2 from optparse import OptionParser
3 import sys, platform, os
4
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 # this system already but we don't know that about unix shell (eg on Windows).
13 #
14 # Note that SCons supports reading of the output from this script, using
15 # 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 #
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 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 # platform specific name munging for '-L' and '-I' file paths...
34 munge = lambda s: s
35
36 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
46 #assume that these won't change too much on Windows...
47 EXTLIB_SUFFIX = "_ascend.dll"
48 EXTLIB_PREFIX = ""
49
50 _winreg.CloseKey(y)
51 _winreg.CloseKey(x)
52
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 s1 = s1.replace("\\","\\\\")
62 except:
63 # if it doesn't exist, we just return the un-munged path
64 pass
65 return s1
66 munge = munge1
67 except:
68 pass
69
70 elif platform.system()=="Darwin":
71 LIB = path_absolute("")
72 BIN = path_absolute("")
73 INCLUDE = path_absolute("Headers")
74 ASCDATA = path_absolute("Resources")
75 MODELS = path_absolute("""@ASC_LIBRARY_REL_DIST@""")
76 SOLVERS = path_absolute("""@ASC_SOLVERS_REL_DIST@""")
77
78 else:
79 # For Linux and whatever else, use the original values passed to us from SCons:
80 LIB="@INSTALL_LIB@"
81 BIN="@INSTALL_BIN@"
82 INCLUDE="@INSTALL_INCLUDE@"
83 ASCDATA="@INSTALL_ASCDATA@"
84 MODELS="@INSTALL_MODELS@"
85 EXTLIB_SUFFIX="@EXTLIB_SUFFIX@"
86 EXTLIB_PREFIX="@EXTLIB_PREFIX@"
87
88 usage = "usage: %prog [--help,...]"
89 # the rest of this script is about returning those values in the standard way
90 parser = OptionParser(usage=usage, version="@VERSION@")
91
92 parser.add_option("--libs", action="store_true", dest="libs", help="show linker flags (for ASCEND libraries)")
93 parser.add_option("--cppflags", action="store_true", dest="cppflags", help="show C pre-processor flags (for ASCEND header files)")
94 parser.add_option("--data", action="store_true", dest="data", help="show location of ASCEND data files")
95 parser.add_option("--models", action="store_true", dest="models", help="show location of ASCEND model library")
96 parser.add_option("--extlib-suffix", action="store_true", dest="extlibsuff", help="show suffix to be used with external libraries")
97 parser.add_option("--extlib-prefix", action="store_true", dest="extlibpref", help="show prefix to be used with external libraries")
98
99 (options, args) = parser.parse_args()
100
101 ok = False
102
103 if options.cppflags:
104 include = ""
105 if INCLUDE!="/usr/include":
106 include=INCLUDE
107 if -1!=include.find(" "):
108 print "-I"+munge(include)+""
109 elif len(include):
110 print "-I"+include
111 ok = True
112
113 if options.libs:
114 libs = ""
115 if LIB!="/usr/lib":
116 libs = LIB
117 if -1!=libs.find(" "):
118 print "-L"+munge(libs)+" -lascend"
119 else:
120 Lflag = ""
121 if len(libs):
122 Lflag = "-L"+libs+" "
123 print Lflag + "-lascend"
124 ok = True
125
126 if options.data:
127 print ASCDATA
128 ok = True
129
130 if options.models:
131 print MODELS
132 ok = True
133
134 if options.extlibsuff:
135 print EXTLIB_SUFFIX
136 ok = True
137
138 if options.extlibpref:
139 print EXTLIB_PREFIX
140 ok = True
141
142 if not ok:
143 sys.stderr.write("invalid option '%s' (use --help for more info)\n" % args)
144 sys.exit(1)

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