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

Contents of /trunk/scons/tcl-config

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1948 - (show annotations) (download)
Mon Nov 10 01:34:32 2008 UTC (11 years, 8 months ago) by jpye
File size: 4022 byte(s)
Working on Windows detection.
1 #! /usr/bin/env python
2
3 tclconfigfile = None
4
5 import sys, platform, os.path
6 if platform.system()=="Windows":
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 }
74
75 # regular expression used for variable substitution
76 import re
77 r = re.compile(r'\$\{([A-Z_0-9]+)\}')
78
79 # variable substitution/expansion function
80 def expand(s,d):
81 m = r.search(s)
82 #print "MATCHING",s
83 if m:
84 #print "MATCH!"
85 if d.has_key(m.group(1)):
86 return expand(s[:m.start()] + d[m.group(1)] + s[m.end():],d)
87 else:
88 raise RuntimeError("Missing variable '%s'" % m.group(1))
89 return s
90
91 for l in f:
92 ls = l.strip()
93 if ls == "" or ls[0]=="#":
94 continue
95 k,v = ls.split("=",1)
96 if len(v) >= 2 and v[0] == "'" and v[len(v)-1] == "'":
97 v = v[1:len(v)-1]
98
99 d[k] = expand(v,d)
100
101 # output the variable that the user requests
102
103 import getopt, sys
104
105 def usage(progname):
106 print "%s [--cflags] [--libs] [--var=TCL_VAR_NAME] [--vars]" % progname
107 print "Output configuration variables for the Tcl script interpreter."
108 print "Options:"
109 print "\t--cflags Compiler flags for C code that uses Tcl"
110 print "\t--libs Linker flags for code that uses Tcl"
111 print "\t--vars List all variables defined in tclConfig.sh"
112 print "\t--var=VARNAME Output the value of a specific variable"
113 print "\nSee http://ascendwiki.cheme.cmu.edu/Tcl-config for more info."
114
115 try:
116 opts, args = getopt.getopt(sys.argv[1:], "h",
117 ["help", "cflags", "libs","var=","vars"]
118 )
119 except getopt.GetoptError, err:
120 print str(err)
121 usage(sys.argv[0])
122 sys.exit(2)
123
124 for o, a in opts:
125 if o == "-h" or o == "--help":
126 usage(sys.argv[0])
127 sys.exit()
128 elif o == "--cflags":
129 print d['TCL_INCLUDE_SPEC']
130 elif o == "--libs":
131 print d['TCL_LIB_SPEC']
132 elif o == "--var":
133 if d.has_key(a):
134 print d[a]
135 else:
136 raise RuntimeError("Unknown variable '%s'" % a)
137 elif o == "--vars":
138 for k in d.keys():
139 print k
140 else:
141 assert False, "unhandled option"

Properties

Name Value
svn:executable *

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