1# simple installer for Sybtcl/Oratcl
2# Copyright 1997 Tom Poindexter
3# 1.2 - add support for install on Macs
4
5# read in the makefile, to figure out which package and version
6
7if {"$tcl_platform(platform)" == "macintosh"} {
8  rename exit tcl_exit
9  proc exit {args} {
10    puts "press any key to exit"
11	flush stdout
12	gets stdin
13	tcl_exit
14  }
15}
16
17set win_mk makefile.vc
18set mac_mk [lindex [glob -nocomplain *.make] 0]
19set makefiles [list $win_mk $mac_mk]
20
21set fd ""
22foreach mk $makefiles {
23  if {[catch {set fd [open $mk]}] == 0} {
24    break
25  }
26}
27if {"$fd" == ""} {
28    puts "can't find a suitable makefile as $makefiles"
29    exit
30}
31
32set mf [read $fd]
33close $fd
34
35set project ""
36set version ""
37set dllvers ""
38set dll [info sharedlibextension]
39
40set ws "\[ \t]?"
41set al "\[A-Za-z_]*"
42set vn "\[0-9]*\\.\[0-9]*"
43set dl "\[0-9]*"
44
45# parse project name, version, and dll version
46
47if {! [regexp "${ws}PROJECT${ws}=${ws}(${al})"          $mf match project] } {
48  puts "can't find package name"
49  exit
50}
51if {! [regexp -nocase "${ws}${project}_VERSION${ws}=${ws}(${vn})" $mf \
52							  match version] } {
53  puts "can't find package version"
54  exit
55}
56if {! [regexp "${ws}DLL_VERSION${ws}=${ws}(${dl})"      $mf match dllvers] } {
57  puts "can't find package dll version"
58  exit
59}
60
61
62# figure out tcl version, and strip out dots
63
64set tclver [info tclversion]
65regsub -all {\.} $tclver "" tclver
66
67# set directory for pkgIndex.tcl, set required dll, and install dll name
68
69set proj_dir ${project}${dllvers}
70set proj_dll ${project}${dllvers}${dll}
71set inst_dll ${project}${dllvers}${dll}
72
73# set package name, assumes that shared lib Xxx_Init is first letter caps
74
75set package "[string toupper [string range $project 0 0]][string tolower [string range $project 1 end]]"
76
77# see if project dll file exists
78
79if {! [file isfile $proj_dll] } {
80  puts "can't find $proj_dll"
81  puts "there doesn't seem to be a dll/shared lib for $project version $version"
82  puts "for Tcl version [info tclversion]"
83  exit
84}
85
86# get tcl lib location, location based on nameofexecutable
87
88set tcllib [file dirname [info library]]
89
90# install project pkgIndex.tcl in private project directory
91set proj_dir [file join $tcllib $proj_dir]
92
93# create package ifneeded script, location based on Tcl library location
94
95set pkg "package ifneeded $package $version \"load \[list \[file join \$dir .. $inst_dll\]\]\""
96
97# tell user what we are about to to
98
99puts ""
100puts "installing $package"
101puts ""
102puts "steps to be performed:"
103puts ""
104puts "  file copy  $proj_dll [file join $tcllib $inst_dll]"
105if {! [file isdirectory [file join $proj_dir]] } {
106  puts "  file mkdir [file join $proj_dir]"
107}
108puts "  create [file join $proj_dir pkgIndex.tcl] as:"
109puts "  $pkg"
110puts ""
111puts -nonewline "continue (yes/no) ? "
112flush stdout
113gets stdin ans
114
115# install if answer was yes,y
116
117switch -glob -- $ans {
118  y* -
119  Y* {
120    puts "file copy  $proj_dll [file join $tcllib $inst_dll]"
121    if {[catch {file copy -force $proj_dll [file join $tcllib $inst_dll]}]} {
122      puts "oops, can't copy  $proj_dll [file join $tcllib $inst_dll]"
123      exit
124    }
125    if {! [file isdirectory $proj_dir] } {
126      puts "file mkdir file join $proj_dir"
127      if {[catch {file mkdir $proj_dir}]} {
128	puts "oops, can't mkdir $proj_dir"
129	exit
130      }
131    }
132    puts "creating [file join $proj_dir pkgIndex.tcl]"
133    if {[catch {set fd [open [file join $proj_dir pkgIndex.tcl] w]}]} {
134      puts "oops, can't create or append [file join $proj_dir pkgIndex.tcl]"
135      exit
136    }
137    puts $fd $pkg
138    close $fd
139    puts ""
140    puts "installation complete"
141  }
142  default {puts "no action taken, exiting $package install"}
143}
144
145exit
146