/[ascend]/trunk/scons/tcl-config.py
ViewVC logotype

Contents of /trunk/scons/tcl-config.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1953 - (show annotations) (download) (as text)
Mon Nov 10 08:22:00 2008 UTC (11 years, 10 months ago) by jpye
File MIME type: text/x-python
File size: 4091 byte(s)
Fix for old versions of Python (hopefully)
1 #! /usr/bin/env python
2
3 tclconfigfile = None
4
5 import sys, os.path
6 if sys.platform.startswith("win"):
7 # check for ActiveState Tcl in Windows registry
8 try:
9 import _winreg
10 x=_winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE)
11 y= _winreg.OpenKey(x,r"SOFTWARE\ActiveState\ActiveTcl")
12 _regversion,t = _winreg.QueryValueEx(y,"CurrentVersion")
13 z= _winreg.OpenKey(x,r"SOFTWARE\ActiveState\ActiveTcl\%s" % str(_regversion))
14 _regpath,t = _winreg.QueryValueEx(z,None)
15 _winreg.CloseKey(y)
16 _winreg.CloseKey(z)
17 _winreg.CloseKey(x)
18 # typically, c:\Tcl\lib\tclConfig.sh.
19 _regconfig = os.path.join(_regpath,os.path.join("lib","tclConfig.sh"))
20 if os.path.exists(_regconfig):
21 # if the file exists, good...
22 tclconfigfile = _regconfig
23 except:
24 pass
25
26 if tclconfigfile is None:
27 # use a 'tclsh' script to find location of tclConfig.sh
28 tclscript = """
29 foreach d [concat \
30 [list $tcl_library \
31 [lindex $tcl_pkgPath 0]] \
32 $auto_path \
33 [list [file dirname $tcl_library] \
34 [file dirname [lindex $tcl_pkgPath 0]] \
35 [file dirname [file dirname $tcl_library]] \
36 [file dirname [file dirname [lindex $tcl_pkgPath 0]]] \
37 [file dirname [file dirname [file dirname $tcl_library]]] \
38 [file dirname [file dirname [file dirname [lindex $tcl_pkgPath 0]]]]] \
39 ] {
40 if {[file exists [file join $d tclConfig.sh]]} {
41 puts "[file join $d tclConfig.sh]"
42 exit
43 }
44 }
45 """
46
47 import subprocess
48 output = subprocess.Popen(["tclsh"], stdin=subprocess.PIPE, stdout=subprocess.PIPE).communicate(input=tclscript)[0]
49 if os.path.exists(output.strip()):
50 # only report the file if it actually exists...
51 tclconfigfile = output.strip()
52
53 if tclconfigfile is None:
54 print "Unable to locate tclConfig.sh"
55 sys.exit(1)
56
57 # parse the file to determine the names of the variables it contains
58
59 f = file(tclconfigfile)
60
61 # default build environment variables that are assumed to already be defined
62 # note that these are normally given default values in GNU Make, but we're
63 # not inside make, so we might not have these.
64 # FIXME: could try importing these from the environment?
65 d = {
66 "CC":"gcc"
67 ,"CFLAGS":""
68 ,"LDFLAGS":""
69 ,"AR":""
70 ,"LIBS":""
71 ,"VERSION":""
72 ,"DBGX":""
73 ,"NODOT_VERSION":"" # required for ActiveState Tcl 8.4 on Windows
74 }
75
76 # regular expression used for variable substitution
77 import re
78 r = re.compile(r'\$\{([A-Z_0-9]+)\}')
79
80 # variable substitution/expansion function
81 def expand(s,d):
82 m = r.search(s)
83 #print "MATCHING",s
84 if m:
85 #print "MATCH!"
86 if d.has_key(m.group(1)):
87 return expand(s[:m.start()] + d[m.group(1)] + s[m.end():],d)
88 else:
89 raise RuntimeError("Missing variable '%s'" % m.group(1))
90 return s
91
92 for l in f:
93 ls = l.strip()
94 if ls == "" or ls[0]=="#":
95 continue
96 k,v = ls.split("=",1)
97 if len(v) >= 2 and v[0] == "'" and v[len(v)-1] == "'":
98 v = v[1:len(v)-1]
99
100 d[k] = expand(v,d)
101
102 # output the variable that the user requests
103
104 import getopt, sys
105
106 def usage(progname):
107 print "%s [--cflags] [--libs] [--var=TCL_VAR_NAME] [--vars]" % progname
108 print "Output configuration variables for the Tcl script interpreter."
109 print "Options:"
110 print "\t--cflags Compiler flags for C code that uses Tcl"
111 print "\t--libs Linker flags for code that uses Tcl"
112 print "\t--vars List all variables defined in tclConfig.sh"
113 print "\t--var=VARNAME Output the value of a specific variable"
114 print "\nSee http://ascendwiki.cheme.cmu.edu/Tcl-config for more info."
115
116 try:
117 opts, args = getopt.getopt(sys.argv[1:], "h",
118 ["help", "cflags", "libs","var=","vars"]
119 )
120 except getopt.GetoptError, err:
121 print str(err)
122 usage(sys.argv[0])
123 sys.exit(2)
124
125 for o, a in opts:
126 if o == "-h" or o == "--help":
127 usage(sys.argv[0])
128 sys.exit()
129 elif o == "--cflags":
130 print d['TCL_INCLUDE_SPEC']
131 elif o == "--libs":
132 print d['TCL_LIB_SPEC']
133 elif o == "--var":
134 if d.has_key(a):
135 print d[a]
136 else:
137 raise RuntimeError("Unknown variable '%s'" % a)
138 elif o == "--vars":
139 for k in sorted(d.keys()):
140 print k
141 else:
142 assert False, "unhandled option"
143
144
145

Properties

Name Value
svn:executable *

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