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

Contents of /trunk/scons/tcl-config

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1946 - (show annotations) (download)
Sat Nov 8 01:10:49 2008 UTC (12 years, 3 months ago) by jpye
File size: 2125 byte(s)
Add tcl-config first draft.
1 #! /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 # default variables that are assumed to already be defined somehow
33 d = {
34 "CC":"gcc",
35 "CFLAGS":"",
36 "LDFLAGS":"",
37 "AR":"",
38 "LIBS":"",
39 "VERSION":"$TCL_VERSION",
40 "DBGX":"$TCL_DBGX"
41 }
42
43 import re
44 r = re.compile(r'\$\{([A-Z_0-9]+)\}')
45
46 def expand(s,d):
47 m = r.search(s)
48 #print "MATCHING",s
49 if m:
50 #print "MATCH!"
51 if d.has_key(m.group(1)):
52 return expand(s[:m.start()] + d[m.group(1)] + s[m.end():],d)
53 else:
54 raise RuntimeError("Missing variable '%s'" % m.group(1))
55 return s
56
57 for l in f:
58 ls = l.strip()
59 if ls == "" or ls[0]=="#":
60 continue
61 k,v = ls.split("=",1)
62 if len(v) >= 2 and v[0] == "'" and v[len(v)-1] == "'":
63 v = v[1:len(v)-1]
64
65 d[k] = expand(v,d)
66
67 # output the variable that the user requests
68
69 import getopt, sys
70
71 def usage():
72 print """%s [--cflags] [--libs]"""
73
74 try:
75 opts, args = getopt.getopt(sys.argv[1:], "h", ["help", "cflags", "libs"])
76 except getopt.GetoptError, err:
77 print str(err)
78 usage()
79 sys.exit(2)
80
81 for o, a in opts:
82 if o == "-h" or o == "--help":
83 usage()
84 sys.exit()
85 elif o == "--cflags":
86 print d['TCL_INCLUDE_SPEC']
87 elif o == "--libs":
88 print d['TCL_LIB_SPEC']
89 else:
90 assert False, "unhandled option"

Properties

Name Value
svn:executable *

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