OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [doc/] [pkgMkIndex.n] - Blame information for rev 1780

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.