Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/doc/pkgMkIndex.n @ 44

Last change on this file since 44 was 25, checked in by landauf, 18 years ago

added tcl to libs

File size: 10.5 KB
Line 
1'\"
2'\" Copyright (c) 1996 Sun Microsystems, Inc.
3'\"
4'\" See the file "license.terms" for information on usage and redistribution
5'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6'\"
7'\" RCS: @(#) $Id: pkgMkIndex.n,v 1.23 2007/12/13 15:22:33 dgp Exp $
8'\"
9.so man.macros
10.TH pkg_mkIndex n 8.3 Tcl "Tcl Built-In Commands"
11.BS
12'\" Note:  do not modify the .SH NAME line immediately below!
13.SH NAME
14pkg_mkIndex \- Build an index for automatic loading of packages
15.SH SYNOPSIS
16.nf
17\fBpkg_mkIndex ?\fI\-direct\fR?  ?\fI\-lazy\fR?  ?\fI\-load pkgPat\fR? ?\fI\-verbose\fR? \fIdir\fR ?\fIpattern pattern ...\fR?
18.fi
19.BE
20.SH DESCRIPTION
21.PP
22\fBPkg_mkIndex\fR is a utility procedure that is part of the standard
23Tcl library.
24It is used to create index files that allow packages to be loaded
25automatically when \fBpackage require\fR commands are executed.
26To use \fBpkg_mkIndex\fR, follow these steps:
27.IP [1]
28Create the package(s).
29Each package may consist of one or more Tcl script files or binary files.
30Binary files must be suitable for loading with the \fBload\fR command
31with a single argument;  for example, if the file is \fBtest.so\fR it must
32be possible to load this file with the command \fBload test.so\fR.
33Each script file must contain a \fBpackage provide\fR command to declare
34the package and version number, and each binary file must contain
35a call to \fBTcl_PkgProvide\fR.
36.IP [2]
37Create the index by invoking \fBpkg_mkIndex\fR.
38The \fIdir\fR argument gives the name of a directory and each
39\fIpattern\fR argument is a \fBglob\fR-style pattern that selects
40script or binary files in \fIdir\fR.
41The default pattern is \fB*.tcl\fR and \fB*.[info sharedlibextension]\fR.
42.RS
43.PP
44\fBPkg_mkIndex\fR will create a file \fBpkgIndex.tcl\fR in \fIdir\fR
45with package information about all the files given by the \fIpattern\fR
46arguments.
47It does this by loading each file into a slave
48interpreter and seeing what packages
49and new commands appear (this is why it is essential to have
50\fBpackage provide\fR commands or \fBTcl_PkgProvide\fR calls
51in the files, as described above).
52If you have a package split among scripts and binary files,
53or if you have dependencies among files,
54you may have to use the \fB\-load\fR option
55or adjust the order in which \fBpkg_mkIndex\fR processes
56the files.  See \fBCOMPLEX CASES\fR below.
57.RE
58.IP [3]
59Install the package as a subdirectory of one of the directories given by
60the \fBtcl_pkgPath\fR variable.  If \fB$tcl_pkgPath\fR contains more
61than one directory, machine-dependent packages (e.g., those that
62contain binary shared libraries) should normally be installed
63under the first directory and machine-independent packages (e.g.,
64those that contain only Tcl scripts) should be installed under the
65second directory.
66The subdirectory should include
67the package's script and/or binary files as well as the \fBpkgIndex.tcl\fR
68file.  As long as the package is installed as a subdirectory of a
69directory in \fB$tcl_pkgPath\fR it will automatically be found during
70\fBpackage require\fR commands.
71.RS
72.PP
73If you install the package anywhere else, then you must ensure that
74the directory containing the package is in the \fBauto_path\fR global variable
75or an immediate subdirectory of one of the directories in \fBauto_path\fR.
76\fBAuto_path\fR contains a list of directories that are searched
77by both the auto-loader and the package loader; by default it
78includes \fB$tcl_pkgPath\fR.
79The package loader also checks all of the subdirectories of the
80directories in \fBauto_path\fR.
81You can add a directory to \fBauto_path\fR explicitly in your
82application, or you can add the directory to your \fBTCLLIBPATH\fR
83environment variable:  if this environment variable is present,
84Tcl initializes \fBauto_path\fR from it during application startup.
85.RE
86.IP [4]
87Once the above steps have been taken, all you need to do to use a
88package is to invoke \fBpackage require\fR.
89For example, if versions 2.1, 2.3, and 3.1 of package \fBTest\fR
90have been indexed by \fBpkg_mkIndex\fR, the command
91\fBpackage require Test\fR will make version 3.1 available
92and the command \fBpackage require \-exact Test 2.1\fR will
93make version 2.1 available.
94There may be many versions of a package in the various index files
95in \fBauto_path\fR, but only one will actually be loaded in a given
96interpreter, based on the first call to \fBpackage require\fR.
97Different versions of a package may be loaded in different
98interpreters.
99.SH OPTIONS
100The optional switches are:
101.TP 15
102\fB\-direct\fR
103The generated index will implement direct loading of the package
104upon \fBpackage require\fR.  This is the default.
105.TP 15
106\fB\-lazy\fR
107The generated index will manage to delay loading the package until the
108use of one of the commands provided by the package, instead of loading
109it immediately upon \fBpackage require\fR.  This is not compatible with
110the use of \fIauto_reset\fR, and therefore its use is discouraged.
111.TP 15
112\fB\-load \fIpkgPat\fR
113The index process will pre-load any packages that exist in the
114current interpreter and match \fIpkgPat\fR into the slave interpreter used to
115generate the index.  The pattern match uses string match rules, but without
116making case distinctions.
117See COMPLEX CASES below.
118.TP 15
119\fB\-verbose\fR
120Generate output during the indexing process.  Output is via
121the \fBtclLog\fR procedure, which by default prints to stderr.
122.TP 15
123\fB\-\-\fR
124End of the flags, in case \fIdir\fR begins with a dash.
125.SH "PACKAGES AND THE AUTO-LOADER"
126.PP
127The package management facilities overlap somewhat with the auto-loader,
128in that both arrange for files to be loaded on-demand.
129However, package management is a higher-level mechanism that uses
130the auto-loader for the last step in the loading process.
131It is generally better to index a package with \fBpkg_mkIndex\fR
132rather than \fBauto_mkindex\fR because the package mechanism provides
133version control:  several versions of a package can be made available
134in the index files, with different applications using different
135versions based on \fBpackage require\fR commands.
136In contrast, \fBauto_mkindex\fR does not understand versions so
137it can only handle a single version of each package.
138It is probably not a good idea to index a given package with both
139\fBpkg_mkIndex\fR and \fBauto_mkindex\fR.
140If you use \fBpkg_mkIndex\fR to index a package, its commands cannot
141be invoked until \fBpackage require\fR has been used to select a
142version;  in contrast, packages indexed with \fBauto_mkindex\fR
143can be used immediately since there is no version control.
144.SH "HOW IT WORKS"
145.PP
146\fBPkg_mkIndex\fR depends on the \fBpackage unknown\fR command,
147the \fBpackage ifneeded\fR command, and the auto-loader.
148The first time a \fBpackage require\fR command is invoked,
149the \fBpackage unknown\fR script is invoked.
150This is set by Tcl initialization to a script that
151evaluates all of the \fBpkgIndex.tcl\fR files in the
152\fBauto_path\fR.
153The \fBpkgIndex.tcl\fR files contain \fBpackage ifneeded\fR
154commands for each version of each available package;  these commands
155invoke \fBpackage provide\fR commands to announce the
156availability of the package, and they setup auto-loader
157information to load the files of the package.
158If the \fI\-lazy\fR flag was provided when the \fBpkgIndex.tcl\fR
159was generated,
160a given file of a given version of a given package is not
161actually loaded until the first time one of its commands
162is invoked.
163Thus, after invoking \fBpackage require\fR you may
164not see the package's commands in the interpreter, but you will be able
165to invoke the commands and they will be auto-loaded.
166.SH "DIRECT LOADING"
167.PP
168Some packages, for instance packages which use namespaces and export
169commands or those which require special initialization, might select
170that their package files be loaded immediately upon \fBpackage require\fR
171instead of delaying the actual loading to the first use of one of the
172package's command. This is the default mode when generating the package
173index.  It can be overridden by specifying the \fI\-lazy\fR argument.
174.SH "COMPLEX CASES"
175Most complex cases of dependencies among scripts
176and binary files, and packages being split among scripts and
177binary files are handled OK.  However, you may have to adjust
178the order in which files are processed by \fBpkg_mkIndex\fR.
179These issues are described in detail below.
180.PP
181If each script or file contains one package, and packages
182are only contained in one file, then things are easy.
183You simply specify all files to be indexed in any order
184with some glob patterns.
185.PP
186In general, it is OK for scripts to have dependencies on other
187packages.
188If scripts contain \fBpackage require\fR commands, these are
189stubbed out in the interpreter used to process the scripts,
190so these do not cause problems.
191If scripts call into other packages in global code,
192these calls are handled by a stub \fBunknown\fR command.
193However, if scripts make variable references to other package's
194variables in global code, these will cause errors.  That is
195also bad coding style.
196.PP
197If binary files have dependencies on other packages, things
198can become tricky because it is not possible to stub out
199C-level APIs such as \fBTcl_PkgRequire\fR API
200when loading a binary file.
201For example, suppose the BLT package requires Tk, and expresses
202this with a call to \fBTcl_PkgRequire\fR in its \fBBlt_Init\fR routine.
203To support this, you must run \fBpkg_mkIndex\fR in an interpreter that
204has Tk loaded.  You can achieve this with the
205\fB\-load \fIpkgPat\fR option.  If you specify this option,
206\fBpkg_mkIndex\fR will load any packages listed by
207\fBinfo loaded\fR and that match \fIpkgPat\fR
208into the interpreter used to process files.
209In most cases this will satisfy the \fBTcl_PkgRequire\fR calls
210made by binary files.
211.PP
212If you are indexing two binary files and one depends on the other,
213you should specify the one that has dependencies last.
214This way the one without dependencies will get loaded and indexed,
215and then the package it provides
216will be available when the second file is processed.
217You may also need to load the first package into the
218temporary interpreter used to create the index by using
219the \fB\-load\fR flag;
220it will not hurt to specify package patterns that are not yet loaded.
221.PP
222If you have a package that is split across scripts and a binary file,
223then you should avoid the \fB\-load\fR flag. The problem is that
224if you load a package before computing the index it masks any
225other files that provide part of the same package.
226If you must use \fB\-load\fR,
227then you must specify the scripts first; otherwise the package loaded from
228the binary file may mask the package defined by the scripts.
229.SH "SEE ALSO"
230package(n)
231.SH KEYWORDS
232auto-load, index, package, version
Note: See TracBrowser for help on using the repository browser.