Initial revision

git-svn-id: https://svn.macports.org/repository/macports/trunk/base@2 d073be05-634f-4543-b044-5fe20cf6d1d6
This commit is contained in:
Landon Fuller
2002-07-30 00:43:19 +00:00
commit 148ae5bf50
9 changed files with 408 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
# Tcl package index file, version 1.1
# This file is generated by the "pkg_mkIndex" command
# and sourced either when an application starts up or
# by a "package unknown" script. It invokes the
# "package ifneeded" command to set up package-related
# information so that packages will be loaded automatically
# in response to "package require" commands. When this
# script is sourced, the variable $dir must contain the
# full path name of this file's directory.
package ifneeded port 1.0 [list source [file join $dir port.1.0.tcl]]
package ifneeded portchecksum 1.0 [list source [file join $dir portchecksum.1.0.tcl]]
package ifneeded portextract 1.0 [list source [file join $dir portextract.1.0.tcl]]
package ifneeded portfetch 1.0 [list source [file join $dir portfetch.1.0.tcl]]
package ifneeded portmain 1.0 [list source [file join $dir portmain.1.0.tcl]]
package ifneeded portpatch 1.0 [list source [file join $dir portpatch.1.0.tcl]]
package ifneeded portutil 1.0 [list source [file join $dir portutil.1.0.tcl]]
+8
View File
@@ -0,0 +1,8 @@
# standard package load
package provide port 1.0
package require portpatch
package require portchecksum
package require portextract
package require portfetch
package require portmain
+19
View File
@@ -0,0 +1,19 @@
# global port routines
package provide portchecksum 1.0
package require portutil
register_target checksum portchecksum::main main fetch
namespace eval portchecksum {
variable options
}
# define globals
globals portchecksum::options md5sum
# define options
options portchecksum::options md5sum
proc portchecksum::main {args} {
global portname
puts "Checksumming port: $portname"
}
+13
View File
@@ -0,0 +1,13 @@
# global port routines
package provide portextract 1.0
package require portutil
register_target extract portextract::main main fetch checksum
namespace eval portextract {
variable options
}
proc portextract::main {args} {
global portname
puts "Extracting port: $portname"
}
+58
View File
@@ -0,0 +1,58 @@
# global port routines
package provide portfetch 1.0
package require portutil
register_target fetch portfetch::main main
namespace eval portfetch {
variable options
variable internal
}
# define globals: distname master_sites distfiles patchfiles dist_subdir
globals portfetch::options distname master_sites extract_sufx distfiles patchfiles dist_subdir use_zip use_bzip2
# define options: distname master_sites
options portfetch::options distname master_sites extract_sufx distfiles extract_only patchfiles dist_subdir use_zip use_bzip2
proc portfetch::suffix {distname} {
if {[isval portfetch::options extract_sufx]} {
return ${distname}[getval portfetch::options extract_sufx]
} elseif {[isval portfetch::options use_bzip2]} {
return ${distname}.tar.bz2
} elseif {[isval portfetch::options use_zip]} {
return ${distname}.zip
} else {
return ${distname}.tar.gz
}
}
proc portfetch::checkfiles {args} {
global portpath distname master_sites
# XXX This doesn't really belong here
set distdir $portpath/distfiles/
# Set distfile with proper suffix
set distfile [portfetch::suffix $distname]
if {![file isdirectory $distdir]} {
file mkdir $distdir
}
if {![file isfile $distdir/$distfile]} {
puts "$distfile doesn't seem to exist in $distdir"
foreach site $master_sites {
puts "Attempting to fetch from $site"
catch {exec curl -o ${distdir}/${distfile} ${site}${distfile} >&@ stdout} result
if {$result == 0} {
break
}
}
}
}
proc portfetch::main {args} {
global portname
# Check for files, download if neccesary
portfetch::checkfiles
}
+23
View File
@@ -0,0 +1,23 @@
# global port routines
# the 'main' target is provided by this package
# main is a magic target and should not be replaced
package provide portmain 1.0
package require portutil
register_target main portmain::main
namespace eval portmain {
variable options
variable targets
}
# define globals: portname portversion categories maintainers
globals portmain::options portname portversion portrevision categories maintainers
# define options: portname, portversion, categories, maintainers
options portmain::options portname portversion portrevision categories maintainers
proc portmain::main {args} {
global portname
# puts "Building port: $portname"
# do nothing
}
+13
View File
@@ -0,0 +1,13 @@
# global port routines
package provide portpatch 1.0
package require portutil
register_target patch portpatch::main main fetch checksum extract
namespace eval portpatch {
variable options
}
proc portpatch::main {args} {
global portname
puts "Patching port: $portname"
}
+215
View File
@@ -0,0 +1,215 @@
# global port utility procedures
package provide portutil 1.0
namespace eval portutil {
variable globals
variable targets
}
########### External High Level Procedures ###########
# register_target
# Creates a target in the global target list using the internal dependancy
# functions
# Arguments: <target name> <procedure to execute> <dependency list>
proc register_target {target procedure args} {
if {[is_depend portutil::targets $target]} {
puts "Warning: target '$target' re-registered (new procedure: '$procedure')"
}
if {[llength $args] == 0} {
add_depend portutil::targets $target $procedure
} else {
eval "add_depend portutil::targets $target $procedure $args"
}
}
proc deregister_target {target} {
del_depend portutil::targets $target
}
# options
# Exports options in an array as externally callable procedures
# Thus, "options myarray name date" would create procedures named "name"
# and "date" that set the array items keyed by "name" and "date"
# Arguments: <array for export> <options (keys in array) to export>
proc options {array args} {
foreach option $args {
eval proc $option {args} \{ setval $array $option {$args} \}
}
}
# globals
# Specifies which keys from an array should be exported as global variables.
# Often used directly with options procedure
proc globals {array args} {
foreach key $args {
if {[info exists portutil::globals($key)]} {
error "Re-exporting global $key"
}
set portutil::globals($key) $array
}
}
########### Dependancy Manipulation Procedures ###########
# add dependancy
# Will overwrite entries for the same target
# Expects arguments: array, target, procedure, depends (optional)
proc add_depend {array target procedure args} {
upvar $array uparray
if {![isval uparray procedure,$target]} {
lappend uparray(targets) $target
}
setval uparray procedure,$target $procedure
if {[llength $args] > 0} {
setval uparray depends,$target $args
}
}
# del dependancy
proc del_depend {array target} {
upvar $array uparray
set uparray(targets) [ldelete uparray(targets) $target]
delval uparray procedure,$target
if {[isval uparray depends,$target]} {
delval uparray depends,$target
}
}
proc is_depend {array target} {
upvar $array uparray
return [isval uparray procedure,$target]
}
# XXX Well, it works. Could be faster.
proc eval_depend {array} {
upvar $array uparray
set list $uparray(targets)
set slist $uparray(targets)
set i 0
set j [llength $list]
while {$i < $j} {
set target [lindex $slist $i]
if {[isval uparray depends,$target]} {
set depends [getval uparray depends,$target]
set k [llength $depends]
set l 0
while {$l < $k} {
set depend [lindex $depends $l]
if {[lsearch -exact $list $depend] == -1} {
puts "Missing dependancy '$depend'"
return -1
}
set curloc [lsearch -exact $list $target]
set newloc [lsearch -exact $list $depend]
if {$curloc < $newloc} {
set list [lreplace $list $curloc $curloc]
set list [linsert $list $newloc $target]
}
incr l
}
} else {
set curloc [lsearch -exact $list $target]
set list [lreplace $list $curloc $curloc]
set list [linsert $list 0 $target]
}
incr i
}
set uparray(targets) $list
foreach target $uparray(targets) {
if {[info exists uparray(depends,$target)]} {
foreach depend $uparray(depends,$target) {
if {[info exists finished]} {
if {[lsearch $finished $depend] == -1} {
puts "Cyclic dependencies between '$target' and dependancy '$depend'"
return -1
}
}
}
}
$uparray(procedure,$target) $target
lappend finished $target
}
return 0
}
########### Global Variable Manipulation Procedures ###########
proc globalval {array key} {
upvar $array uparray
global $key
set $key $uparray($key)
set portutil::globals($key) $array
}
proc unglobalval {key} {
global $key
if {[info exists $key]} {
unset $key
}
if {[info exists portutil::globals($key)]} {
unset portutil::globals($key)
}
}
########### Stack/List Manipulation Procedures ###########
proc push {list value} {
upvar $list stack
lappend stack $value
}
proc pop {list} {
upvar $list stack
set value [lindex $list end]
set list [lrange $list 0 [expr [llength $list]-2]]
return $value
}
proc ldelete {list value} {
set ix [lsearch -exact $list $value]
if {$ix >= 0} {
return [lreplace $list $ix $ix]
} else {
return $list
}
}
########### Base Data Accessor Procedures ###########
proc setval {array key val} {
upvar $array uparray
set uparray($key) $val
if {[info exists portutil::globals($key)]} {
if {$portutil::globals($key) == $array} {
globalval uparray $key
}
}
}
proc isval {array key} {
upvar $array uparray
return [info exists uparray($key)]
}
proc getval {array key} {
upvar $array uparray
if {![info exists uparray($key)]} {
error "Undefined option $key in $array"
} else {
if {[info exists portutil::globals($key)]} {
upvar #0 $key upkey
setval $array $key $upkey
}
return $uparray($key)
}
}
proc delval {array key} {
upvar $array uparray
unset uparray($key)
if {[info exists portutil::globals($key)]} {
unglobalval $key
}
}
Executable
+42
View File
@@ -0,0 +1,42 @@
#!/usr/bin/tclsh
# portbuild
# globals
set invoice Portfile
set portpath /private/Network/Servers/noether/homes/frodo/landonf/Documents/Code/appleports
set libpath $portpath/Tcl
# Standard procedures
proc print_usage args {
global argv0
puts "Usage: $argv0 \[invoice\]"
}
proc fatal args {
global argv0
puts stderr "$argv0: $args"
exit
}
# Main
if {$argc > 1} {
print_usage
} elseif {$argc == 1} {
set invoice [lindex $argv 0]
}
if [file isdirectory $libpath] {
if [catch {pkg_mkIndex $libpath *.tcl *.so *.dylib */*.tcl */*.so */*.dylib} result] {
fatal Error updating $libpath index: $result
}
lappend auto_path $libpath
} else {
fatal libpath ($libpath) is not a directory or does not exist
}
if [file isfile $invoice] {
source $invoice
} else {
fatal invoice file '$invoice' is not a file or does not exist
}
eval_depend portutil::targets