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

Annotation of /trunk/ascend-config.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2083 - (hide annotations) (download)
Thu Sep 24 06:37:53 2009 UTC (9 years, 1 month ago) by jpye
File size: 4408 byte(s)
Almost there... ASCEND.app runs OK from command line now, but errors from Finder.
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 jpye 1999 s1 = s1.replace("\\","\\\\")
62 jpye 1742 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 jpye 2083
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 johnpye 922 else:
79 jpye 2083 # For Linux and whatever else, use the original values passed to us from SCons:
80 johnpye 922 LIB="@INSTALL_LIB@"
81     BIN="@INSTALL_BIN@"
82     INCLUDE="@INSTALL_INCLUDE@"
83     ASCDATA="@INSTALL_ASCDATA@"
84     MODELS="@INSTALL_MODELS@"
85 jpye 1998 EXTLIB_SUFFIX="@EXTLIB_SUFFIX@"
86     EXTLIB_PREFIX="@EXTLIB_PREFIX@"
87 johnpye 683
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 johnpye 721 parser.add_option("--models", action="store_true", dest="models", help="show location of ASCEND model library")
96 jpye 1998 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 johnpye 683
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 johnpye 965 if -1!=include.find(" "):
108 jpye 1743 print "-I"+munge(include)+""
109 jpye 1557 elif len(include):
110 johnpye 1160 print "-I"+include
111 johnpye 683 ok = True
112    
113     if options.libs:
114     libs = ""
115     if LIB!="/usr/lib":
116     libs = LIB
117 johnpye 965 if -1!=libs.find(" "):
118 jpye 1743 print "-L"+munge(libs)+" -lascend"
119 johnpye 965 else:
120 jpye 1557 Lflag = ""
121     if len(libs):
122     Lflag = "-L"+libs+" "
123     print Lflag + "-lascend"
124 johnpye 683 ok = True
125    
126     if options.data:
127     print ASCDATA
128     ok = True
129    
130 johnpye 721 if options.models:
131     print MODELS
132     ok = True
133    
134 jpye 1998 if options.extlibsuff:
135     print EXTLIB_SUFFIX
136     ok = True
137    
138     if options.extlibpref:
139     print EXTLIB_PREFIX
140     ok = True
141    
142 johnpye 683 if not ok:
143 johnpye 721 sys.stderr.write("invalid option '%s' (use --help for more info)\n" % args)
144 johnpye 683 sys.exit(1)
145 johnpye 922

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