/[ascend]/branches/harry/ascend-config.in
ViewVC logotype

Annotation of /branches/harry/ascend-config.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1742 - (hide annotations) (download)
Sat Feb 9 22:48:41 2008 UTC (11 years, 5 months ago) by jpye
Original Path: trunk/ascend-config.in
File size: 3297 byte(s)
added path mungeing for Windows, fixed bug #365.
1 johnpye 683 #!@PYTHON@
2     from optparse import OptionParser
3 johnpye 922 import sys, platform
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 1742 # platform specific name munging for '-L' and '-I' file paths...
25     munge = lambda s: s
26    
27 johnpye 922 if platform.system()=="Windows":
28     import _winreg
29     x=_winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE)
30     y= _winreg.OpenKey(x,r"SOFTWARE\ASCEND")
31     LIB,t = _winreg.QueryValueEx(y,"INSTALL_LIB")
32     BIN,t = _winreg.QueryValueEx(y,"INSTALL_BIN")
33     INCLUDE,t = _winreg.QueryValueEx(y,"INSTALL_INCLUDE")
34     ASCDATA,t = _winreg.QueryValueEx(y,"INSTALL_ASCDATA")
35     MODELS,t = _winreg.QueryValueEx(y,"INSTALL_MODELS")
36 johnpye 683
37 johnpye 922 _winreg.CloseKey(y)
38     _winreg.CloseKey(x)
39 jpye 1742
40     try:
41     # if we have access to GetShortPathName, we'll use it...
42     import win32api
43     def munge1(s):
44     s1 = s
45     try:
46     # we can only munge the path if it actually exists
47     s1 = win32api.GetShortPathName(s)
48     except:
49     # if it doesn't exist, we just return the un-munged path
50     pass
51     return s1
52     munge = munge1
53     except:
54     pass
55 johnpye 922 else:
56     # If we're not in Windows, use the original values passed to us from SCons:
57     LIB="@INSTALL_LIB@"
58     BIN="@INSTALL_BIN@"
59     INCLUDE="@INSTALL_INCLUDE@"
60     ASCDATA="@INSTALL_ASCDATA@"
61     MODELS="@INSTALL_MODELS@"
62 johnpye 683
63     usage = "usage: %prog [--help,...]"
64     # the rest of this script is about returning those values in the standard way
65     parser = OptionParser(usage=usage, version="@VERSION@")
66    
67     parser.add_option("--libs", action="store_true", dest="libs", help="show linker flags (for ASCEND libraries)")
68     parser.add_option("--cppflags", action="store_true", dest="cppflags", help="show C pre-processor flags (for ASCEND header files)")
69     parser.add_option("--data", action="store_true", dest="data", help="show location of ASCEND data files")
70 johnpye 721 parser.add_option("--models", action="store_true", dest="models", help="show location of ASCEND model library")
71 johnpye 683
72     (options, args) = parser.parse_args()
73    
74     ok = False
75    
76     if options.cppflags:
77     include = ""
78     if INCLUDE!="/usr/include":
79     include=INCLUDE
80 johnpye 965 if -1!=include.find(" "):
81 jpye 1742 print "-I\""+munge(include)+"\""
82 jpye 1557 elif len(include):
83 johnpye 1160 print "-I"+include
84 johnpye 683 ok = True
85    
86     if options.libs:
87     libs = ""
88     if LIB!="/usr/lib":
89     libs = LIB
90 johnpye 965 if -1!=libs.find(" "):
91 jpye 1742 print "-L\""+munge(libs)+"\" -lascend"
92 johnpye 965 else:
93 jpye 1557 Lflag = ""
94     if len(libs):
95     Lflag = "-L"+libs+" "
96     print Lflag + "-lascend"
97 johnpye 683 ok = True
98    
99     if options.data:
100     print ASCDATA
101     ok = True
102    
103 johnpye 721 if options.models:
104     print MODELS
105     ok = True
106    
107 johnpye 683 if not ok:
108 johnpye 721 sys.stderr.write("invalid option '%s' (use --help for more info)\n" % args)
109 johnpye 683 sys.exit(1)
110 johnpye 922

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