1mNAME0m
       pkg_mkIndex - Build an index for automatic loading of packages

1mSYNOPSIS0m
       1mpkg_mkIndex ?4m22m-lazy24m? ?4m-load24m 4mpkgPat24m? ?4m-verbose24m? 4mdir24m ?4mpattern24m 4mpattern24m 4m...24m?


1mDESCRIPTION0m
       1mPkg_mkIndex  22mis  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  1mpackage require 22mcommands are executed.  To
       use 1mpkg_mkIndex22m, follow these steps:

       [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 1mload 22mcommand with a single  argument;   for
              example, if the file is 1mtest.so 22mit must be possible to load this
              file with the command 1mload test.so22m.  Each script file must  con-
              tain  a  1mpackage provide 22mcommand to declare the package and ver-
              sion number, and  each  binary  file  must  contain  a  call  to
              1mTcl_PkgProvide22m.

       [2]    Create  the  index  by  invoking  1mpkg_mkIndex22m.  The 4mdir24m argument
              gives the name of a directory and each  4mpattern24m  argument  is  a
              1mglob22m-style  pattern  that selects script or binary files in 4mdir24m.
              The default pattern is 1m*.tcl 22mand 1m*.[info sharedlibextension]22m.
              1mPkg_mkIndex 22mwill create a file 1mpkgIndex.tcl 22min 4mdir24m with  package
              information  about all the files given by the 4mpattern24m 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 1mpackage  provide  22mcommands  or  1mTcl_PkgProvide0m
              calls  in the files, as described above).  If you have a package
              split among scripts and binary files, or if you  have  dependen-
              cies among files, you may have to use the 1m-load 22moption or adjust
              the order in which 1mpkg_mkIndex 22mprocesses the files.  See COMPLEX
              CASES below.


       [3]    Install  the package as a subdirectory of one of the directories
              given by the 1mtcl_pkgPath  22mvariable.   If  1m$tcl_pkgPath  22mcontains
              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
              1mpkgIndex.tcl  22mfile.   As  long  as the package is installed as a
              subdirectory of a directory in 1m$tcl_pkgPath  22mit  will  automati-
              cally be found during 1mpackage require 22mcommands.
              If  you  install the package anywhere else, then you must ensure
              that the directory containing the package is  in  the  1mauto_path0m
              global  variable  or  an  immediate  subdirectory  of one of the
              directories in 1mauto_path22m.  1mAuto_path 22mcontains a list of directo-
              ries  that  are searched by both the auto-loader and the package
              loader; by default it includes 1m$tcl_pkgPath22m.  The package loader
              also  checks  all  of  the  subdirectories of the directories in
              1mauto_path22m.  You can add a directory to 1mauto_path  22mexplicitly  in
              your  application,  or you can add the directory to your 1mTCLLIB-0m
              1mPATH 22menvironment variable:   if  this  environment  variable  is
              present,  Tcl  initializes  1mauto_path 22mfrom it during application
              startup.

       [4]    Once the above steps have been taken, all you need to do to  use
              a  package  is  to invoke 1mpackage require22m.  For example, if ver-
              sions 2.1, 2.3, and 3.1 of package 1mTest  22mhave  been  indexed  by
              1mpkg_mkIndex22m,  the command 1mpackage require Test 22mwill make version
              3.1 available and the command 1mpackage require  -exact  Test  2.10m
              will  make version 2.1 available.  There may be many versions of
              a package in the various index files in 1mauto_path22m, but only  one
              will  actually  be  loaded  in a given interpreter, based on the
              first call to 1mpackage require22m.  Different versions of a  package
              may be loaded in different interpreters.


1mOPTIONS0m
       The optional switches are:

       1m-lazy          22mThe  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
                      1mpackage require22m.

       1m-load 4m22mpkgPat24m   The index process will pre-load any packages that  exist
                      in  the  current  interpreter  and match 4mpkgPat24m into the
                      slave interpreter used to generate the index.  The  pat-
                      tern  match  uses string match rules.  See COMPLEX CASES
                      below.

       1m-verbose       22mGenerate output during the indexing process.  Output  is
                      via  the  1mtclLog  22mprocedure,  which by default prints to
                      stderr.

       1m--             22mEnd of the flags, in case 4mdir24m begins with a dash.


1mPACKAGES AND THE AUTO-LOADER0m
       The package management  facilities  overlap  somewhat  with  the  auto-
       loader,  in  that  both arrange for files to be loaded on-demand.  How-
       ever, 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  1mpkg_mkIndex  22mrather  than  1mauto_mkindex0m
       because  the  package mechanism provides version control:  several ver-
       sions of a package can be made available in the index files, with  dif-
       ferent  applications  using different versions based on 1mpackage require0m
       commands.  In contrast, 1mauto_mkindex 22mdoes 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  1mpkg_mkIndex   22mand
       1mauto_mkindex22m.   If you use 1mpkg_mkIndex 22mto index a package, its commands
       cannot be invoked until 1mpackage require 22mhas been used to select a  ver-
       sion;   in  contrast,  packages  indexed  with 1mauto_mkindex 22mcan be used
       immediately since there is no version control.


1mHOW IT WORKS0m
       1mPkg_mkIndex  22mdepends  on  the  1mpackage  unknown  22mcommand,  the  1mpackage0m
       1mifneeded  22mcommand,  and  the  auto-loader.   The  first  time a 1mpackage0m
       1mrequire 22mcommand is invoked, the  1mpackage  unknown  22mscript  is  invoked.
       This is set by Tcl initialization to a script that evaluates all of the
       1mpkgIndex.tcl 22mfiles in the 1mauto_path22m.  The  1mpkgIndex.tcl  22mfiles  contain
       1mpackage  ifneeded  22mcommands for each version of each available package;
       these commands invoke 1mpackage provide 22mcommands to announce  the  avail-
       ability  of the package, and they setup auto-loader information to load
       the files of the package.  If the 4m-lazy24m  flag  was  provided  when  the
       1mpkgIndex.tcl  22mwas generated, 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 1mpackage require 22myou 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.


1mDIRECT LOADING0m
       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 1mpackage require0m
       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 4m-lazy24m argument.


1mCOMPLEX CASES0m
       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 1mpkg_mkIndex22m.  These issues are described in detail below.

       If each script or file contains one package, and packages are only con-
       tained in one file, then things are easy.  You simply specify all files
       to be indexed in any order with some glob patterns.

       In  general,  it  is OK for scripts to have dependencies on other pack-
       ages.  If scripts contain 1mpackage require 22mcommands, 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 1munknown 22mcommand.  However, if scripts
       make variable references to other package's variables in  global  code,
       these will cause errors.  That is also bad coding style.

       If  binary files have dependencies on other packages, things can become
       tricky because it is not possible to stub out  C-level  API's  such  as
       1mTcl_PkgRequire  22mAPI  when  loading a binary file.  For example, suppose
       the BLT package  requires  Tk,  and  expresses  this  with  a  call  to
       1mTcl_PkgRequire  22min its 1mBlt_Init 22mroutine.  To support this, you must run
       1mpkg_mkIndex 22min an interpreter that has Tk loaded.  You can achieve this
       with  the 1m-load 4m22mpkgPat24m option.  If you specify this option, 1mpkg_mkIndex0m
       will load any packages listed by 1minfo loaded 22mand that match 4mpkgPat24m into
       the interpreter used to process files.  In most cases this will satisfy
       the 1mTcl_PkgRequire 22mcalls made by binary files.

       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 1m-load 22mflag; it won't hurt to
       specify package patterns that are not yet loaded.

       If you have a package that is split across scripts and a  binary  file,
       then you should avoid the 1m-load 22mflag. The problem is that if you load a
       package before computing the index it masks any other files  that  pro-
       vide  part  of  the same package.  If you must use 1m-load22m, then you must
       specify the scripts first; otherwise the package loaded from the binary
       file may mask the package defined by the scripts.


1mSEE ALSO0m
       package(n)


1mKEYWORDS0m
