pkgMkIndex.n
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:10k
- '"
- '" Copyright (c) 1996 Sun Microsystems, Inc.
- '"
- '" See the file "license.terms" for information on usage and redistribution
- '" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- '"
- '" RCS: @(#) $Id: pkgMkIndex.n,v 1.14 2003/02/25 23:58:09 dgp Exp $
- '"
- .so man.macros
- .TH pkg_mkIndex n 8.3 Tcl "Tcl Built-In Commands"
- .BS
- '" Note: do not modify the .SH NAME line immediately below!
- .SH NAME
- pkg_mkIndex - Build an index for automatic loading of packages
- .SH SYNOPSIS
- .nf
- .VS 8.3.0
- fBpkg_mkIndex ?fI-directfR? ?fI-lazyfR? ?fI-load pkgPatfR? ?fI-verbosefR? fIdirfR ?fIpattern pattern ...fR?
- .VE
- .fi
- .BE
- .SH DESCRIPTION
- .PP
- fBPkg_mkIndexfR is a utility procedure that is part of the standard
- Tcl library.
- It is used to create index files that allow packages to be loaded
- automatically when fBpackage requirefR commands are executed.
- To use fBpkg_mkIndexfR, follow these steps:
- .IP [1]
- Create the package(s).
- Each package may consist of one or more Tcl script files or binary files.
- Binary files must be suitable for loading with the fBloadfR command
- with a single argument; for example, if the file is fBtest.sofR it must
- be possible to load this file with the command fBload test.sofR.
- Each script file must contain a fBpackage providefR command to declare
- the package and version number, and each binary file must contain
- a call to fBTcl_PkgProvidefR.
- .IP [2]
- Create the index by invoking fBpkg_mkIndexfR.
- The fIdirfR argument gives the name of a directory and each
- fIpatternfR argument is a fBglobfR-style pattern that selects
- script or binary files in fIdirfR.
- .VS 8.0.3
- The default pattern is fB*.tclfR and fB*.[info sharedlibextension]fR.
- .VE
- .br
- fBPkg_mkIndexfR will create a file fBpkgIndex.tclfR in fIdirfR
- with package information about all the files given by the fIpatternfR
- arguments.
- It does this by loading each file into a slave
- interpreter and seeing what packages
- and new commands appear (this is why it is essential to have
- fBpackage providefR commands or fBTcl_PkgProvidefR calls
- in the files, as described above).
- If you have a package split among scripts and binary files,
- or if you have dependencies among files,
- you may have to use the fB-loadfP option
- or adjust the order in which fBpkg_mkIndexfR processes
- the files. See COMPLEX CASES below.
- .IP [3]
- Install the package as a subdirectory of one of the directories given by
- the fBtcl_pkgPathfR variable. If fB$tcl_pkgPathfR contains more
- than one directory, machine-dependent packages (e.g., those that
- contain binary shared libraries) should normally be installed
- under the first directory and machine-independent packages (e.g.,
- those that contain only Tcl scripts) should be installed under the
- second directory.
- The subdirectory should include
- the package's script and/or binary files as well as the fBpkgIndex.tclfR
- file. As long as the package is installed as a subdirectory of a
- directory in fB$tcl_pkgPathfR it will automatically be found during
- fBpackage requirefR commands.
- .br
- If you install the package anywhere else, then you must ensure that
- the directory containing the package is in the fBauto_pathfR global variable
- or an immediate subdirectory of one of the directories in fBauto_pathfR.
- fBAuto_pathfR contains a list of directories that are searched
- by both the auto-loader and the package loader; by default it
- includes fB$tcl_pkgPathfR.
- The package loader also checks all of the subdirectories of the
- directories in fBauto_pathfR.
- You can add a directory to fBauto_pathfR explicitly in your
- application, or you can add the directory to your fBTCLLIBPATHfR
- environment variable: if this environment variable is present,
- Tcl initializes fBauto_pathfR from it during application startup.
- .IP [4]
- Once the above steps have been taken, all you need to do to use a
- package is to invoke fBpackage requirefR.
- For example, if versions 2.1, 2.3, and 3.1 of package fBTestfR
- have been indexed by fBpkg_mkIndexfR, the command
- fBpackage require TestfR will make version 3.1 available
- and the command fBpackage require -exact Test 2.1fR will
- make version 2.1 available.
- There may be many versions of a package in the various index files
- in fBauto_pathfR, but only one will actually be loaded in a given
- interpreter, based on the first call to fBpackage requirefR.
- Different versions of a package may be loaded in different
- interpreters.
- .SH OPTIONS
- The optional switches are:
- .TP 15
- fB-directfR
- The generated index will implement direct loading of the package
- upon fBpackage requirefR. This is the default.
- .TP 15
- fB-lazyfR
- The generated index will manage to delay loading the package until the
- use of one of the commands provided by the package, instead of loading
- it immediately upon fBpackage requirefR.
- .TP 15
- fB-load fIpkgPatfR
- The index process will pre-load any packages that exist in the
- current interpreter and match fIpkgPatfP into the slave interpreter used to
- generate the index. The pattern match uses string match rules, but without
- making case distinctions.
- See COMPLEX CASES below.
- .TP 15
- fB-verbosefR
- Generate output during the indexing process. Output is via
- the fBtclLogfP procedure, which by default prints to stderr.
- .TP 15
- fB--fR
- End of the flags, in case fIdirfP begins with a dash.
- .SH "PACKAGES AND THE AUTO-LOADER"
- .PP
- The package management facilities overlap somewhat with the auto-loader,
- in that both arrange for files to be loaded on-demand.
- However, package management is a higher-level mechanism that uses
- the auto-loader for the last step in the loading process.
- It is generally better to index a package with fBpkg_mkIndexfR
- rather than fBauto_mkindexfR because the package mechanism provides
- version control: several versions of a package can be made available
- in the index files, with different applications using different
- versions based on fBpackage requirefR commands.
- In contrast, fBauto_mkindexfR does not understand versions so
- it can only handle a single version of each package.
- It is probably not a good idea to index a given package with both
- fBpkg_mkIndexfR and fBauto_mkindexfR.
- If you use fBpkg_mkIndexfR to index a package, its commands cannot
- be invoked until fBpackage requirefR has been used to select a
- version; in contrast, packages indexed with fBauto_mkindexfR
- can be used immediately since there is no version control.
- .SH "HOW IT WORKS"
- .PP
- fBPkg_mkIndexfR depends on the fBpackage unknownfR command,
- the fBpackage ifneededfR command, and the auto-loader.
- The first time a fBpackage requirefR command is invoked,
- the fBpackage unknownfR script is invoked.
- This is set by Tcl initialization to a script that
- evaluates all of the fBpkgIndex.tclfR files in the
- fBauto_pathfR.
- The fBpkgIndex.tclfR files contain fBpackage ifneededfR
- commands for each version of each available package; these commands
- invoke fBpackage providefR commands to announce the
- availability of the package, and they setup auto-loader
- information to load the files of the package.
- .VS 8.3
- If the fI-lazyfR flag was provided when the fBpkgIndex.tclfR
- was generated,
- .VE
- a given file of a given version of a given package isn't
- actually loaded until the first time one of its commands
- is invoked.
- Thus, after invoking fBpackage requirefR you may
- not see the package's commands in the interpreter, but you will be able
- to invoke the commands and they will be auto-loaded.
- .VS 8.3
- .SH "DIRECT LOADING"
- .PP
- Some packages, for instance packages which use namespaces and export
- commands or those which require special initialization, might select
- that their package files be loaded immediately upon fBpackage requirefR
- instead of delaying the actual loading to the first use of one of the
- package's command. This is the default mode when generating the package
- index. It can be overridden by specifying the fI-lazyfR argument.
- .VE
- .SH "COMPLEX CASES"
- Most complex cases of dependencies among scripts
- and binary files, and packages being split among scripts and
- binary files are handled OK. However, you may have to adjust
- the order in which files are processed by fBpkg_mkIndexfR.
- These issues are described in detail below.
- .PP
- If each script or file contains one package, and packages
- are only contained in one file, then things are easy.
- You simply specify all files to be indexed in any order
- with some glob patterns.
- .PP
- In general, it is OK for scripts to have dependencies on other
- packages.
- If scripts contain fBpackage requirefP commands, these are
- stubbed out in the interpreter used to process the scripts,
- so these do not cause problems.
- If scripts call into other packages in global code,
- these calls are handled by a stub fBunknownfP command.
- However, if scripts make variable references to other package's
- variables in global code, these will cause errors. That is
- also bad coding style.
- .PP
- If binary files have dependencies on other packages, things
- can become tricky because it is not possible to stub out
- C-level APIs such as fBTcl_PkgRequirefP API
- when loading a binary file.
- For example, suppose the BLT package requires Tk, and expresses
- this with a call to fBTcl_PkgRequirefP in its fBBlt_InitfP routine.
- To support this, you must run fBpkg_mkIndexfR in an interpreter that
- has Tk loaded. You can achieve this with the
- fB-load fIpkgPatfR option. If you specify this option,
- fBpkg_mkIndexfR will load any packages listed by
- fBinfo loadedfP and that match fIpkgPatfP
- into the interpreter used to process files.
- In most cases this will satisfy the fBTcl_PkgRequirefP calls
- made by binary files.
- .PP
- If you are indexing two binary files and one depends on the other,
- you should specify the one that has dependencies last.
- This way the one without dependencies will get loaded and indexed,
- and then the package it provides
- will be available when the second file is processed.
- You may also need to load the first package into the
- temporary interpreter used to create the index by using
- the fB-loadfP flag;
- it won't hurt to specify package patterns that are not yet loaded.
- .PP
- If you have a package that is split across scripts and a binary file,
- then you should avoid the fB-loadfP flag. The problem is that
- if you load a package before computing the index it masks any
- other files that provide part of the same package.
- If you must use fB-loadfP,
- then you must specify the scripts first; otherwise the package loaded from
- the binary file may mask the package defined by the scripts.
- .SH "SEE ALSO"
- package(n)
- .SH KEYWORDS
- auto-load, index, package, version