comparison doc/interpreter/package.txi @ 6537:062bade36bf7

[project @ 2007-04-18 16:40:25 by jwe]
author jwe
date Wed, 18 Apr 2007 16:40:25 +0000
parents
children e3a7611430a8
comparison
equal deleted inserted replaced
6536:3c89a3f9d23e 6537:062bade36bf7
1 @c Copyright (C) 2007 Søren Hauberg
2 @c This is part of the Octave manual.
3 @c For copying conditions, see the file gpl.texi.
4
5 @node Packages
6 @chapter Packages
7
8 Since Octave is Free Software users are encouraged to share their
9 programs amongst each other. To aid this sharing Octave supports the
10 installation of extra packages. The `Octave-Forge' project is a
11 community-maintained set of packages that can be downloaded and
12 installed in Octave. At the time of writing the `Octave-Forge' project
13 can be found on-line at @uref{http://octave.sourceforge.net}, but
14 since the Internet is an ever-changing place this may not be true at
15 the time of reading. Therefore it is recommended to see the Octave
16 website for an updated reference.
17
18 @menu
19 * Installing and Removing Packages::
20 * Using Packages::
21 * Administrating Packages::
22 * Creating Packages::
23 @end menu
24
25 @node Installing and Removing Packages
26 @section Installing and Removing Packages
27
28 Assuming a package is available in the file @code{image-1.0.0.tar.gz}
29 it can be installed from the Octave prompt by writing
30
31 @example
32 pkg install image-1.0.0.tar.gz
33 @end example
34
35 @noindent
36 If the package is installed successfully nothing will be printed on
37 the prompt, but if an error occurred during installation it will be
38 reported. It is possible to install several packages at once by
39 writing several package files after the @code{pkg install} command.
40 If a different version of the package is already installed it will
41 be removed prior to installing the new package. This makes it easy to
42 upgrade and downgrade the version of a package, but makes it
43 impossible to have several versions of the same package installed at
44 once.
45
46 To see which packages are installed type
47
48 @example
49 @group
50 pkg list
51 @print{} Package Name | Version | Installation directory
52 @print{} -------------+---------+-----------------------
53 @print{} image | 1.0.0 | /home/jwe/octave/image-1.0.0
54 @end group
55 @end example
56
57 @noindent
58 In this case only version 1.0.0 of the @code{image} package is
59 installed.
60
61 It is possible to remove a package from the system using the
62 @code{pkg uninstall} command like this
63
64 @example
65 pkg uninstall image
66 @end example
67
68 @noindent
69 If the package is removed successfully nothing will be printed in the
70 prompt, but if an error occurred it will be reported. It should be
71 noted that the package file used for installation is not needed for
72 removal, and that only the package name as reported by @code{pkg list}
73 should be used when removing a package. It is possible to remove
74 several packages at once by writing several package names after the
75 @code{pkg uninstall} command.
76
77 To minimize the amount of code duplication between packages it is
78 possible that one package depends on another one. If a package
79 depends on another, it will check if that package is installed
80 during installation. If it is not, an error will be reported and
81 the package will not be installed. This behaviour can be disabled
82 by passing the @code{-nodeps} flag to the @code{pkg install}
83 command
84
85 @example
86 pkg install -nodeps my_package_with_dependencies.tar.gz
87 @end example
88
89 @noindent
90 Since the installed package expects its dependencies to be installed
91 it may not function correctly. Because of this it is not recommended
92 to disable dependency checking.
93
94 @node Using Packages
95 @section Using Packages
96
97 By default installed packages are available from the Octave prompt,
98 but it is possible to control this using the @code{pkg load} and
99 @code{pkg unload} commands. The functions from a package can be
100 removed from the Octave path by typing
101
102 @example
103 pkg unload package_name
104 @end example
105
106 @noindent
107 where @code{package_name} is the name of the package to be removed
108 from the path.
109
110 In much the same way a package can be added to the Octave path by
111 typing
112
113 @example
114 pkg load package_name
115 @end example
116
117 @node Administrating Packages
118 @section Administrating Packages
119
120 On UNIX-like systems it is possible to make both per-user and
121 system-wide installations of a package. If the user performing the
122 installation is @code{root} the packages will be installed in a
123 system-wide directory that defaults to
124 @code{OCTAVE_HOME/share/octave/packages/}. If the user is not
125 @code{root} the default installation directory is
126 @code{~/octave/}. Packages will be installed in a subdirectory of the
127 installation directory that will be named after the package. It is
128 possible to change the installation directory by using the
129 @code{pkg prefix} command
130
131 @example
132 pkg prefix new_installation_directory
133 @end example
134
135 @noindent
136 The current installation directory can be retrieved by typing
137
138 @example
139 current_installation_directory = pkg prefix
140 @end example
141
142 To function properly the package manager needs to keep some
143 information about the installed packages. For per-user packages this
144 information is by default stored in the file @code{~/.octave_packages}
145 and for system-wide installations it is stored in
146 @code{OCTAVE_HOME/share/octave/octave_packages}. The path to the
147 per-user file can be changed with the @code{pkg local_list} command
148
149 @example
150 pkg local_list /path/to/new_file
151 @end example
152
153 @noindent
154 For system-wide installations this can be changed in the same way
155 using the @code{pkg global_list} command. If these commands are
156 called without a new path, the current path will be returned.
157
158 @node Creating Packages
159 @section Creating Packages
160
161 Internally a package is simply a gzipped tar file that contains a
162 top level directory of any given name. This directory will in the
163 following be referred to as @code{package} and may contain the
164 following files
165
166 @noindent
167 @table @code
168 @item package/DESCRIPTION
169 This is a required file containing information about the package.
170 @xref{The DESCRIPTION File}, for details on this file.
171
172 @item package/COPYING
173 This is a required file containing the license of the package. No
174 restrictions is made on the license in general. If however the
175 package contains dynamically linked functions the license must be
176 compatible with the GNU General Public License.
177
178 @item package/INDEX
179 This is an optional file describing the functions provided by the
180 package. If this file is not given then one with be created
181 automatically from the functions in the package and the
182 @code{Categories} keyword in the @code{DESCRIPTION} file.
183 @xref{The INDEX file}, for details on this file.
184
185 @item package/PKG_ADD
186 An optional file that includes commands that are run when the package
187 is added to the users path. Note that @code{PKG_ADD} directives in the
188 source code of the package will also be added to this file by the
189 Octave package manager. Note that symbolic links are to be avoided in
190 packages, as symbolic links do not exist on some file systems, and so
191 a typical use for this file is the replacement of the symbolic link
192
193 @example
194 ln -s foo.oct bar.oct
195 @end example
196
197 @noindent
198 with an autoload directive like
199
200 @example
201 autoload ('bar', which ('foo'));
202 @end example
203
204 @noindent
205 @xref{PKG_ADD and PKG_DEL directives}, for details on @code{PKG_ADD}
206 directives.
207
208 @item package/PKG_DEL
209 An optional file that includes commands that are run when the package
210 is removed from the users path. Note that @code{PKG_DEL} directives in
211 the source code of the package will also be added to this file by the
212 Octave package manager.
213 @xref{PKG_ADD and PKG_DEL directives}, for details on @code{PKG_DEL}
214 directives.
215
216 @item package/pre_install.m
217 This is an optional script that is run prior to the installation of a
218 package.
219
220 @item package/post_install.m
221 This is an optional script that is run after the installation of a
222 package.
223
224 @item package/on_uninstall.m
225 This is an optional script that is run prior to the removal of a
226 package.
227 @end table
228
229 Besides the above mentioned files, a package can also contain on or
230 more of the following directories
231
232 @noindent
233 @table @code
234 @item package/inst
235 An optional directory containing any files that are directly installed
236 by the package. Typically this will include any @code{m}-files.
237
238 @item package/src
239 An optional directory containing code that must be built prior to the
240 packages installation. The Octave package manager will execute
241 @code{./configure} in this directory if this script exists, and will
242 then call @code{make} if a file @code{Makefile} exists in this
243 directory. @code{make install} will however not be called. If a file
244 called @code{FILES} exist all files listed there will be copied to the
245 @code{inst} directory, so they also will be installed. If the
246 @code{FILES} file doesn't exist, @code{src/*.m} and @code{src/*.oct}
247 will be copied to the @code{inst} directory.
248
249 @item package/doc
250 An optional directory containing documentation for the package. The
251 files in this directory will be directly installed in a sub-directory
252 of the installed package for future reference.
253
254 @item package/bin
255 An optional directory containing files that will be added to the
256 Octave @code{EXEC_PATH} when the package is loaded. This might contain
257 external scripts, etc, called by functions within the package.
258 @end table
259
260 @menu
261 * The DESCRIPTION File::
262 * The INDEX file::
263 * PKG_ADD and PKG_DEL directives::
264 @end menu
265
266 @node The DESCRIPTION File
267 @subsection The DESCRIPTION File
268
269 The @code{DESCRIPTION} file contains various information about the
270 package, such as it's name, author, and version. This file has a very
271 simple format
272
273 @noindent
274 @itemize
275 @item
276 Lines starting with @code{#} are comments.
277
278 @item
279 Lines starting with a blank character are continuations from the
280 previous line.
281
282 @item
283 Everything else is of the form @code{NameOfOption: ValueOfOption}.
284 @end itemize
285
286 @noindent
287 The following is a simple example of a @code{DESCRIPTION} file
288
289 @example
290 Name: The name of my package
291 Version: 1.0.0
292 Date: 2007-18-04
293 Author: The name (and possibly email) of the package author.
294 Maintainer: The name (and possibly email) of the current package maintainer.
295 Title: The title of the package
296 Description: A short description of the package. If this description
297 gets too long for one line it can continue on the next by adding a
298 space to the beginning of the following lines.
299 License: GPL version 2 or later
300 @end example
301
302 The package manager currently recognizes the following keywords
303
304 @noindent
305 @table @code
306 @item Name
307 Name of the package.
308
309 @item Version
310 Version of the package.
311
312 @item Date
313 Date of last update.
314
315 @item Author
316 Original author of the package.
317
318 @item Maintainer
319 Maintainer of the package.
320
321 @item Title
322 A one line description of the package.
323
324 @item Description
325 A one paragraph description of the package.
326
327 @item Categories
328 Optional keyword describing the package (if no @code{INDEX} file is
329 given this is mandatory).
330
331 @item Problems
332 Optional list of known problems.
333
334 @item Url
335 Optional list of homepages related to the package.
336
337 @item Autoload
338 Optional field that sets the default loading behavior for the package.
339 If set to @code{yes}, @code{true} or @code{on}, then Octave will
340 automatically load the package when starting. Otherwise the package
341 must be manually loaded with the pkg load command. This default
342 behavior can be overridden when the package is installed.
343
344 @item Depends
345 A list of other Octave packages that this package depends on. This can
346 include dependencies on particular versions, with a format
347
348 @example
349 Depends: package (>= 1.0.0)
350 @end example
351
352 @noindent
353 Possible operators are @code{<}, @code{<=}, @code{==}, @code{>=} or
354 @code{>}. If the part of the dependency in @code{()} is missing, any
355 version of the package is acceptable. Multiple dependencies can be
356 defined either as a comma separated list or on separate @code{Depends}
357 lines.
358
359 @item License
360 An optional short description of the used license (e.g. GPL version 2
361 or newer). This is optional since the file @code{COPYING} is mandatory.
362
363 @item SystemRequirements
364 These are the external install dependencies of the package and are not
365 checked by the package manager. This is here as a hint to the
366 distribution packager. They follows the same conventions as the
367 @code{Depends} keyword.
368
369 @item BuildRequires
370 These are the external build dependencies of the package and are not
371 checked by the package manager. This is here as a hint to the
372 distribution packager. They follows the same conventions as the
373 @code{Depends} keyword. Note that in general, packaging systems such
374 as @code{rpm} or @code{deb} and autoprobe the install dependencies
375 from the build dependencies, and therefore the often a
376 @code{BuildRequires} dependency removes the need for a
377 @code{SystemRequirements} dependency.
378
379 @end table
380
381 @noindent
382 The developer is free to add additional arguments to the
383 @code{DESCRIPTION} file for their own purposes. One further detail to
384 aid the packager is that the @code{SystemRequirments} and
385 @code{BuildRequires} keywords can have distribution dependent section,
386 and the automatic build process will use these. An example of the
387 format of this is
388
389 @example
390 BuildRequires: libtermcap-devel [Mandriva] libtermcap2-devel
391 @end example
392
393 @noindent
394 where the first package name will be used as a default and if the
395 RPMs are built on a Mandriva distribution, then the second package
396 name will be used instead.
397
398 @node The INDEX file
399 @subsection The INDEX file
400
401 The optional @code{INDEX} file provides an categorical view of the
402 functions in the package. This file has a very simple format
403
404 @noindent
405 @itemize
406 @item Lines beginning with @code{#} are comments.
407
408 @item The first non-comment line should look like this
409
410 @example
411 toolbox >> Toolbox name
412 @end example
413
414 @item Lines beginning with an alphabetical character indicates a new
415 category of functions.
416
417 @item Lines starting with a white space character indicate that the
418 function names on the line belong to last mentioned category.
419 @end itemize
420
421 @noindent
422 The format can be summarized with the following example
423
424 @example
425 # A comment
426 toolbox >> Toolbox name
427 Category Name 1
428 function1 function2 function3
429 function4
430 Category Name 2
431 functio2 function5
432 @end example
433
434 @node PKG_ADD and PKG_DEL directives
435 @subsection PKG_ADD and PKG_DEL directives
436
437 If the package contains files called @code{PKG_ADD} or @code{PKG_DEL}
438 the commands in these files will be executed when the package is
439 added or removed from the users path. In some situations such files
440 are a bit cumbersome to maintain, so the package manager supports
441 automatic creation of such files. If a source file in the package
442 contains a @code{PKG_ADD} or @code{PKG_DEL} directive they will be
443 added to either the @code{PKG_ADD} or @code{PKG_DEL} files.
444
445 In @code{m}-files a @code{PKG_ADD} directive looks like this
446
447 @example
448 ## PKG_ADD: some_octave_command
449 @end example
450
451 @noindent
452 Such lines should be added before the @code{function} keyword.
453 In C++ files a @code{PKG_ADD} directive looks like this
454
455 @example
456 // PKG_ADD: some_octave_command
457 @end example
458
459 @noindent
460 In both cases @code{some_octave_command} should be replaced by the
461 command that should be placed in the @code{PKG_ADD} file.
462 @code{PKG_DEL} directives work in the same way, except the @code{PKG_ADD}
463 keyword is replaced with @code{PKG_DEL} and the commands get added
464 to the @code{PKG_DEL} file.
465
466 @c Perhaps we should include this line when creating info files?
467 @c That way the user can still type 'doc pkg'.
468 @c DOCSTRING(pkg)