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

Annotation of /trunk/scons/tcl-config

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1947 - (hide annotations) (download)
Mon Nov 10 01:04:27 2008 UTC (12 years, 3 months ago) by jpye
File size: 3080 byte(s)
Added --vars and --var flags for more output.
1 jpye 1946 #! /usr/bin/env python
2    
3     tclscript = """
4     foreach d [concat \
5     [list $tcl_library \
6     [lindex $tcl_pkgPath 0]] \
7     $auto_path \
8     [list [file dirname $tcl_library] \
9     [file dirname [lindex $tcl_pkgPath 0]] \
10     [file dirname [file dirname $tcl_library]] \
11     [file dirname [file dirname [lindex $tcl_pkgPath 0]]] \
12     [file dirname [file dirname [file dirname $tcl_library]]] \
13     [file dirname [file dirname [file dirname [lindex $tcl_pkgPath 0]]]]] \
14     ] {
15     if {[file exists [file join $d tclConfig.sh]]} {
16     puts "[file join $d tclConfig.sh]"
17     exit
18     }
19     }
20     """
21    
22     # determine location of tclConfig.sh
23    
24     import subprocess
25     output = subprocess.Popen(["tclsh"], stdin=subprocess.PIPE, stdout=subprocess.PIPE).communicate(input=tclscript)[0]
26     tclconfigfile = output.strip()
27    
28     # parse the file to determine the names of the variables it contains
29    
30     f = file(tclconfigfile)
31    
32 jpye 1947 # default build environment variables that are assumed to already be defined
33     # note that these are normally given default values in GNU Make, but we're
34     # not inside make, so we might not have these.
35     # FIXME: could try importing these from the environment?
36 jpye 1946 d = {
37     "CC":"gcc",
38     "CFLAGS":"",
39     "LDFLAGS":"",
40     "AR":"",
41     "LIBS":"",
42 jpye 1947 "VERSION":"",
43     "DBGX":""
44 jpye 1946 }
45    
46 jpye 1947 # regular expression used for variable substitution
47 jpye 1946 import re
48     r = re.compile(r'\$\{([A-Z_0-9]+)\}')
49    
50 jpye 1947 # variable substitution/expansion function
51 jpye 1946 def expand(s,d):
52     m = r.search(s)
53     #print "MATCHING",s
54     if m:
55     #print "MATCH!"
56     if d.has_key(m.group(1)):
57     return expand(s[:m.start()] + d[m.group(1)] + s[m.end():],d)
58     else:
59     raise RuntimeError("Missing variable '%s'" % m.group(1))
60     return s
61    
62     for l in f:
63     ls = l.strip()
64     if ls == "" or ls[0]=="#":
65     continue
66     k,v = ls.split("=",1)
67     if len(v) >= 2 and v[0] == "'" and v[len(v)-1] == "'":
68     v = v[1:len(v)-1]
69    
70     d[k] = expand(v,d)
71    
72     # output the variable that the user requests
73    
74     import getopt, sys
75    
76 jpye 1947 def usage(progname):
77     print "%s [--cflags] [--libs] [--var=TCL_VAR_NAME] [--vars]" % progname
78     print "Output configuration variables for the Tcl script interpreter."
79     print "Options:"
80     print "\t--cflags Compiler flags for C code that uses Tcl"
81     print "\t--libs Linker flags for code that uses Tcl"
82     print "\t--vars List all variables defined in tclConfig.sh"
83     print "\t--var=VARNAME Output the value of a specific variable"
84     print "\nSee http://ascendwiki.cheme.cmu.edu/Tcl-config for more info."
85 jpye 1946
86     try:
87 jpye 1947 opts, args = getopt.getopt(sys.argv[1:], "h",
88     ["help", "cflags", "libs","var=","vars"]
89     )
90 jpye 1946 except getopt.GetoptError, err:
91     print str(err)
92 jpye 1947 usage(sys.argv[0])
93 jpye 1946 sys.exit(2)
94    
95     for o, a in opts:
96     if o == "-h" or o == "--help":
97 jpye 1947 usage(sys.argv[0])
98 jpye 1946 sys.exit()
99     elif o == "--cflags":
100     print d['TCL_INCLUDE_SPEC']
101     elif o == "--libs":
102     print d['TCL_LIB_SPEC']
103 jpye 1947 elif o == "--var":
104     if d.has_key(a):
105     print d[a]
106     else:
107     raise RuntimeError("Unknown variable '%s'" % a)
108     elif o == "--vars":
109     for k in d.keys():
110     print k
111 jpye 1946 else:
112     assert False, "unhandled option"
113    
114    
115    

Properties

Name Value
svn:executable *

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