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

Diff of /trunk/scons/tcl-config

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1946 by jpye, Sat Nov 8 01:10:49 2008 UTC revision 1948 by jpye, Mon Nov 10 01:34:32 2008 UTC
# Line 1  Line 1 
1  #! /usr/bin/env python  #! /usr/bin/env python
2    
3  tclscript = """  tclconfigfile = None
4   foreach d [concat \  
5        [list $tcl_library \  import sys, platform, os.path
6              [lindex $tcl_pkgPath 0]] \  if platform.system()=="Windows":
7        $auto_path \      # check for ActiveState Tcl in Windows registry
8        [list [file dirname $tcl_library] \      try:
9              [file dirname [lindex $tcl_pkgPath 0]] \          import _winreg
10              [file dirname [file dirname $tcl_library]] \          x=_winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE)
11              [file dirname [file dirname [lindex $tcl_pkgPath 0]]] \          y= _winreg.OpenKey(x,r"SOFTWARE\ActiveState\ActiveTcl")
12              [file dirname [file dirname [file dirname $tcl_library]]] \          _regversion,t = _winreg.QueryValueEx(y,"CurrentVersion")
13              [file dirname [file dirname [file dirname [lindex $tcl_pkgPath 0]]]]] \          z= _winreg.OpenKey(x,r"SOFTWARE\ActiveState\ActiveTcl\%s" % str(_regversion))
14   ] {          _regpath,t = _winreg.QueryValueEx(z,None)
15       if {[file exists [file join $d tclConfig.sh]]} {          _winreg.CloseKey(y)
16           puts "[file join $d tclConfig.sh]"          _winreg.CloseKey(z)
17           exit          _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  # determine location of tclConfig.sh              tclconfigfile = _regconfig
23        except:
24  import subprocess          pass
25  output = subprocess.Popen(["tclsh"], stdin=subprocess.PIPE, stdout=subprocess.PIPE).communicate(input=tclscript)[0]  
26  tclconfigfile = output.strip()  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  # parse the file to determine the names of the variables it contains
58    
59  f = file(tclconfigfile)  f = file(tclconfigfile)
60    
61  # default variables that are assumed to already be defined somehow  # 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 = {  d = {
66      "CC":"gcc",      "CC":"gcc",
67      "CFLAGS":"",      "CFLAGS":"",
68      "LDFLAGS":"",      "LDFLAGS":"",
69      "AR":"",      "AR":"",
70      "LIBS":"",      "LIBS":"",
71      "VERSION":"$TCL_VERSION",      "VERSION":"",
72      "DBGX":"$TCL_DBGX"      "DBGX":""
73  }  }
74    
75    # regular expression used for variable substitution
76  import re  import re
77  r = re.compile(r'\$\{([A-Z_0-9]+)\}')  r = re.compile(r'\$\{([A-Z_0-9]+)\}')
78    
79    # variable substitution/expansion function
80  def expand(s,d):  def expand(s,d):
81      m = r.search(s)      m = r.search(s)
82      #print "MATCHING",s      #print "MATCHING",s
# Line 68  for l in f: Line 102  for l in f:
102    
103  import getopt, sys  import getopt, sys
104    
105  def usage():  def usage(progname):
106      print """%s [--cflags] [--libs]"""      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:  try:
116      opts, args = getopt.getopt(sys.argv[1:], "h", ["help", "cflags", "libs"])      opts, args = getopt.getopt(sys.argv[1:], "h",
117            ["help", "cflags", "libs","var=","vars"]
118        )
119  except getopt.GetoptError, err:  except getopt.GetoptError, err:
120      print str(err)      print str(err)
121      usage()      usage(sys.argv[0])
122      sys.exit(2)      sys.exit(2)
123    
124  for o, a in opts:  for o, a in opts:
125      if o == "-h" or o == "--help":      if o == "-h" or o == "--help":
126          usage()          usage(sys.argv[0])
127          sys.exit()          sys.exit()
128      elif o == "--cflags":      elif o == "--cflags":
129          print d['TCL_INCLUDE_SPEC']          print d['TCL_INCLUDE_SPEC']
130      elif o == "--libs":      elif o == "--libs":
131          print d['TCL_LIB_SPEC']          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:      else:
141          assert False, "unhandled option"          assert False, "unhandled option"
142    

Legend:
Removed from v.1946  
changed lines
  Added in v.1948

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