Index: head/en_US.ISO8859-1/books/porters-handbook/pkg-files/chapter.xml
===================================================================
--- head/en_US.ISO8859-1/books/porters-handbook/pkg-files/chapter.xml (revision 47394)
+++ head/en_US.ISO8859-1/books/porters-handbook/pkg-files/chapter.xml (revision 47395)
@@ -1,203 +1,204 @@
pkg-*There are some tricks we have not mentioned yet about the
pkg-* files that
come in handy sometimes.pkg-messageTo display a message when the package is installed,
place the message in pkg-message. This
capability is often useful to display additional installation
steps to be taken after a pkg install or to
display licensing information.When some lines about the build-time knobs or warnings
have to be displayed, use ECHO_MSG.
pkg-message is only for
post-installation steps. Likewise, the distinction between
ECHO_MSG is for printing
informational text to the screen and ECHO_CMD
is for
command pipelining:update-etc-shells:
@${ECHO_MSG} "updating /etc/shells"
@${CP} /etc/shells /etc/shells.bak
@( ${GREP} -v ${PREFIX}/bin/bash /etc/shells.bak; \
${ECHO_CMD} ${PREFIX}/bin/bash) >/etc/shells
@${RM} /etc/shells.bakDo not add an entry for pkg-message
in pkg-plist.pkg-installIf the port needs to execute commands when the binary
package is installed with pkg add or
pkg install, use
pkg-install. This script will
automatically be added to the package. It will be run twice by
pkg, the first time as ${SH}
pkg-install ${PKGNAME} PRE-INSTALL before the
package is installed, and the second time as
${SH} pkg-install ${PKGNAME}
POST-INSTALL after it has been installed.
$2 can be tested to determine which
mode the script is being run in. The PKG_PREFIX
environmental variable will be set to the package installation
directory.pkg-deinstallThis script executes when a package is removed.This script will be run twice by pkg
delete The first time as ${SH}
pkg-deinstall ${PKGNAME} DEINSTALL before the
port is de-installed and the second time as
${SH} pkg-deinstall ${PKGNAME}
POST-DEINSTALL after the port has been de-installed.
$2 can be tested to determine which
mode the script is being run in. The PKG_PREFIX
environmental variable will be set to the package installation
directoryChanging the Names of
pkg-*All the names of
pkg-* are
defined using variables that can be changed in the
Makefile if needed. This is especially
useful when sharing the same
pkg-* files
among several ports or when it is necessary to write to one of these files.
See writing to places other than
WRKDIR for why it is a bad idea to
write directly into
the directory containing the
pkg-*
files.Here is a list of variable names and their default values.
(PKGDIR defaults to
${MASTERDIR}.)VariableDefault valueDESCR${PKGDIR}/pkg-descrPLIST${PKGDIR}/pkg-plistPKGINSTALL${PKGDIR}/pkg-installPKGDEINSTALL${PKGDIR}/pkg-deinstallPKGMESSAGE${PKGDIR}/pkg-messageMaking Use of SUB_FILES and
SUB_LISTSUB_FILES and
SUB_LIST are useful for dynamic
values in port files, such as the installation
PREFIX in
pkg-message.SUB_FILES specifies a list
of files to be automatically modified. Each
file in the
SUB_FILES list must have a corresponding
file.in present
in FILESDIR. A modified version will be
created as
${WRKDIR}/file.
Files defined as a value of USE_RC_SUBR (or
the deprecated USE_RCORDER) are automatically
added to SUB_FILES. For the files
pkg-message,
pkg-install, and
pkg-deinstall, the corresponding Makefile
variable is automatically set to point to the processed
version.SUB_LIST is a list of
VAR=VALUE pairs. For each pair,
%%VAR%% will be replaced with
VALUE in each file listed in
SUB_FILES. Several common pairs are
automatically defined: PREFIX,
LOCALBASE, DATADIR,
DOCSDIR, EXAMPLESDIR,
WWWDIR, and ETCDIR. Any
- line beginning with @comment will be deleted
+ line beginning with @comment folowed by a
+ space, will be deleted
from resulting files after a variable substitution.This example replaces
%%ARCH%% with the system architecture in a
pkg-message:SUB_FILES= pkg-message
SUB_LIST= ARCH=${ARCH}Note that for this example,
pkg-message.in must exist in
FILESDIR.Example of a good
pkg-message.in:Now it is time to configure this package.
Copy %%PREFIX%%/share/examples/putsy/%%ARCH%%.conf into your home directory
as .putsy.conf and edit it.
Index: head/en_US.ISO8859-1/books/porters-handbook/plist/chapter.xml
===================================================================
--- head/en_US.ISO8859-1/books/porters-handbook/plist/chapter.xml (revision 47394)
+++ head/en_US.ISO8859-1/books/porters-handbook/plist/chapter.xml (revision 47395)
@@ -1,803 +1,804 @@
Advanced pkg-plist PracticesChanging pkg-plist Based on Make
VariablesSome ports, particularly the p5- ports,
need to change their pkg-plist depending on
what options they are configured with (or version of
perl, in the case of p5-
ports). To make this easy, any instances in
pkg-plist of %%OSREL%%,
%%PERL_VER%%, and
%%PERL_VERSION%% will be substituted
appropriately. The value of %%OSREL%% is the
numeric revision of the operating system (for example,
4.9). %%PERL_VERSION%%
and %%PERL_VER%% is the full version number
of perl (for example, 5.8.9).
Several other
%%VARS%% related
to port's documentation files are described in the relevant
section.To make other substitutions, set
PLIST_SUB with a list of
VAR=VALUE
pairs and instances of
%%VAR%% will be
substituted with VALUE in
pkg-plist.For instance, if a port installs many files
in a version-specific subdirectory, use a placeholder for the
version so that pkg-plist does not have to
be regenerated every time the port is updated. For
example:OCTAVE_VERSION= ${PORTREVISION}
PLIST_SUB= OCTAVE_VERSION=${OCTAVE_VERSION}in the Makefile and use
%%OCTAVE_VERSION%% wherever the version shows
up in pkg-plist. When
the port is upgraded, it will not be necessary to edit dozens (or in some
cases, hundreds) of lines in
pkg-plist.If files are installed conditionally on the options
set in the port, the usual way of handling it is prefixing
pkg-plist lines with a
%%OPT%% for lines needed when the option is
enabled, or %%NO_OPT%% when the option is
disabled, and adding OPTIONS_SUB=yes to the
Makefile. See for more information.For instance, if there are files that are only installed
when the X11 option is enabled, and
Makefile has:OPTIONS_DEFINE= X11
OPTIONS_SUB= yesIn pkg-plist, put
%%X11%% in front of the lines only being
installed when the option is enabled, like this :%%X11%%bin/foo-guiThis substitution will be done between the
pre-install and
do-install targets, by reading from
PLIST and writing to
TMPPLIST (default:
WRKDIR/.PLIST.mktmp). So if the port
builds PLIST on the fly, do so in or before
pre-install. Also, if the port
needs to edit the resulting file, do so in
post-install to a file named
TMPPLIST.Another way of modifying a port's packing list is based on
setting the variables PLIST_FILES and
PLIST_DIRS. The value of each variable is
regarded as a list of pathnames to write to
TMPPLIST along with
PLIST contents. Names listed in
PLIST_FILES and
PLIST_DIRS are subject to
%%VAR%%
substitution as described above. Except for that, names from
PLIST_FILES will appear in the final packing
list unchanged, while @dir
will be prepended to names from
PLIST_DIRS. To take effect,
PLIST_FILES and
PLIST_DIRS must be set before
TMPPLIST is written, that is, in
pre-install or earlier.From time to time, using OPTIONS_SUB
is not enough. In those cases, adding a specific
TAG to PLIST_SUB
inside the Makefile with a special
value of @comment, makes package tools to
ignore the line. For instance, if some files are only installed
when the X11 option is on and the
architecture is i386:.include <bsd.port.pre.mk>
.if ${PORT_OPTIONS:MX11} && ${ARCH} == "i386"
PLIST_SUB+= X11I386=""
.else
PLIST_SUB+= X11I386="@comment "
.endifEmpty DirectoriesCleaning Up Empty DirectoriesWhen being de-installed, a port has to remove empty
directories it created. Most of these directories are removed
automatically by &man.pkg.8;, but for directories created
outside of ${PREFIX}, or empty
directories, some more work needs to be done. This is usually
accomplished by adding @dir lines for those
directories. Subdirectories must be deleted before deleting
parent directories.[...]
@dir /var/games/oneko/saved-games
@dir /var/games/onekoCreating Empty DirectoriesEmpty directories created during port installation need
special attention. They must be present when the package
is created. If they are not created by the port code, create
them in the Makefile:post-stage:
@${MKDIR} ${STAGEDIR}${PREFIX}/some/directoryAdd the directory to pkg-plist
like any other. For example:@dir some/directoryConfiguration FilesIf the port installs configuration files to
PREFIX/etc (or elsewhere) do
not list them in
pkg-plist. That will cause
pkg delete to remove files that have been carefully
edited by the user, and a re-installation will wipe them
out.Instead, install sample files with a
filename.sample
extension. The @sample macro automates this,
see for what it does
exactly. For each sample file, add a line to
pkg-plist:@sample etc/orbit.conf.sampleIf there is a very good reason not to install a working
configuration file by default, only list the sample filename in
- pkg-plist, without the @sample
- part, and add a pkg-plist, without the
+ @sample followed by a space part, and add a
+ message pointing out that the
user must copy and edit the file before the software will
work.When a port installs its configuration in a subdirectory
of ${PREFIX}/etc, use
ETCDIR, which defaults to
${PREFIX}/etc/${PORTNAME}, it can be
overridden in the ports Makefile if there
is a convention for the port to use some other directory. The
%%ETCDIR%% macro will be used in its
stead in pkg-plist.The sample configuration files should always have the
.sample suffix. If for some historical
reason using the standard suffix is not possible, use
this construct:@unexec if cmp -s %D/etc/orbit.conf-dist %D/etc/orbit.conf; then rm -f %D/etc/orbit.conf; fi
etc/orbit.conf-dist
@exec if [ ! -f %D/etc/orbit.conf ] ; then cp -p %D/%F %B/orbit.conf; fiThe order of these lines is important. On deinstallation,
the sample file is compared to the actual configuration file.
If these files are identical, no changes have been made by the
user and the actual file can be safely deleted. Because the
sample file must still exist for the comparison, the
@unexec line comes before the sample
configuration file name. On installation, if an actual
configuration file is not already present, the sample file is
copied to the actual file. The sample file must be present
before it can be copied, so the @exec line
comes after the sample configuration file name.To debug any issues, temporarily remove the
-s flag to &man.cmp.1; for more
output.See &man.pkg-create.8; for more information on
%D and related substitution markers.Dynamic Versus Static Package ListA static package list is a package
list which is available in the Ports Collection either as
pkg-plist (with or without variable
substitution), or embedded into the
Makefile via
PLIST_FILES and
PLIST_DIRS. Even if the contents are
auto-generated by a tool or a target in the Makefile
before the inclusion into the Ports
Collection by a committer (for example, using make
makeplist>), this is still considered a static list,
since it is possible to examine it without having to download or
compile the distfile.A dynamic package list is a package
list which is generated at the time the port is compiled based
upon the files and directories which are installed. It is not
possible to examine it before the source code of the ported
application is downloaded and compiled, or after running a
make clean.While the use of dynamic package lists is not forbidden,
maintainers should use static package lists wherever possible,
as it enables users to &man.grep.1; through available ports to
discover, for example, which port installs a certain file.
Dynamic lists should be primarily used for complex ports where
the package list changes drastically based upon optional
features of the port (and thus maintaining a static package list
is infeasible), or ports which change the package list based
upon the version of dependent software used. For example, ports which
generate docs with Javadoc.Automated Package List CreationFirst, make sure the port is almost complete, with only
pkg-plist missing. Running make
makeplist will show an example for
pkg-plist. The output of
makeplist must be double checked for
correctness as it tries to automatically guess a few things, and
can get it wrong.User configuration files should be installed as
filename.sample,
as it is described in .
info/dir must not be listed and
appropriate install-info lines must be
added as noted in the info
files section. Any libraries installed by the port
must be listed as specified in the shared libraries
section.Expanding Package List with KeywordsAll keywords can also take optional arguments in
parentheses. The arguments are owner, group, and mode. This
argument is used on the file or directory referenced.
To change the owner, group, and mode of a configuration file,
use:@sample(games,games,640) etc/config.sampleThe arguments are optional. If only the group and mode
need to be changed, use:@sample(,games,660) etc/config.sample@desktop-file-utilsWill run update-desktop-database -q
after installation and deinstallation.@fcfontsdirdirectoryAdd a @dir entry for the
directory passed as an argument, and run fc-cache
-s, mkfontscale and
mkfontdir on that directory after
installation and deinstallation. Additionally, on
deinstallation, it removes the
fonts.scale and
fonts.dir cache files if they are
empty.@glib-schemasRuns glib-compile-schemas on
installation and deinstallation.@infofileAdd the file passed as argument to the plist, and updates
the info document index on installation and deinstallation.
Additionally, it removes the index if empty on
deinstallation. This should never be used manually, but
always through INFO. See for more information.@klddirectoryRuns kldxref on the directory
on installation and deinstallation. Additionally, on
deinstallation, it will remove the directory if empty.@rmtryfileWill remove the file on deinstallation, and not give an
error if the file is not there.@samplefileAdd the file passed as argument to the plist.On installation, check for a real file with
just the base name (the name without the
.sample extension). If the real file is
not found, copy the sample file to the base file name. On
deinstallation, remove the configuration file if it has not
been modified. See for more
information.@shared-mime-infodirectoryRuns update-mime-database on the
directory on installation and deinstallation.@shellfileAdd the file passed as argument to the plist.On installation, add the full path to
file to
/etc/shells, while making sure it is not
added twice. On deinstallation, remove it from
/etc/shells.Base KeywordsThere are a few keywords that are hardcoded, and
documented in &man.pkg-create.8;. For the sake of
completeness, they are also documented here.@
[file]The empty keyword is a placeholder to use when the
file's owner, group, or mode need to be changed. For
example, to set the group of the file to
games and add the setgid bit, add:@(,games,2755) sbin/daemon@cwd
[directory] (Deprecated)Set the internal directory pointer to point to
directory. All subsequent filenames are assumed relative to
this directory.@execcommandExecute command as part of
the unpacking process. If command contains any of these
sequences somewhere in it, they are expanded
inline. For these examples, assume that
@cwd is set to
/usr/local and the last
extracted file was bin/emacs.%FExpand to the last filename extracted (as
specified). In the example case
bin/emacs.%DExpand to the current directory prefix, as set
with @cwd. In the example case
/usr/local.%BExpand to the basename of the fully qualified
filename, that is, the current directory prefix plus
the last filespec, minus the trailing filename. In
the example case, that would be
/usr/local/bin.%fExpand to the filename part of the fully qualified
name, or the converse of %B. In
the example case,
emacs.@unexeccommandExecute command as part of
the deinstallation process. Expansion of special
% sequences is the same as for
@exec. This command is not executed
during the package add, as @exec is, but
rather when the package is deleted. This is useful for
deleting links and other ancillary files that were created
as a result of adding the package, but not directly known to
the package's table of contents (and hence not automatically
removable).@modemodeSet default permission for all subsequently extracted
files to mode. Format is the
same as that used by &man.chmod.1;. Use without an arg to
set back to default permissions (mode of the file while
being packed).This must be a numeric mode, like
644, 4755, or
600. It cannnot be a relative mode
like u+s.@owneruserSet default ownership for all subsequent files to
user. Use without an argument to
set back to default ownership (root).@groupgroupSet default group ownership for all subsequent files to
group. Use without an arg to set
back to default group ownership (wheel).@commentstringThis line is ignored when packing.@dirdirectoryDeclare directory name. By default, directories created
under PREFIX by a package installation
are automatically removed. Use this when an empty directory
under PREFIX needs to be created, or when
the directory needs to have non default owner, group, or
mode. Directories outside of PREFIX need
to be registered. For example,
/var/db/${PORTNAME} needs to have a
@dir entry whereas
${PREFIX}/share/${PORTNAME} does not if
it contains files or uses the default owner, group, and
mode.@dirrmdirectory (Deprecated)Declare directory name to be deleted at deinstall time.
By default, directories created under
PREFIX by a package installation are
deleted when the package is deinstalled.@dirrmtrydirectory (Deprecated)Declare directory name to be removed, as for
@dirrm, but does not issue a warning if
the directory cannot be removed.Creating New KeywordsPackage list files can be extended by keywords that are
defined in the ${PORTSDIR}/Keywords
directory. The settings for each keyword are stored in a
UCL file named
keyword.ucl.
The file must contain at least one of the next
sections:attributesChanges the owner, group, or mode used by the
keyword. Contains an associative array where the
possible keys are owner,
group, and mode.
The values are, respectively, a user name, a group name,
and a file mode. For example:attributes: { owner: "games", group: "games", mode: 0555 }actionDefines what happens to the keyword's parameter.
Contains an array where the possible values are:setprefixSet the prefix for the next plist
entries.dirRegister a directory to be created on
install and removed on deinstall.dirrmRegister a directory to be deleted on
deinstall. Deprecated.dirrmtryRegister a directory to try and deleted on
deinstall. Deprecated.fileRegister a file.setmodeSet the mode for the next plist
entries.setownerSet the owner for the next plist
entries.setgroupSet the group for the next plist
entries.commentDoes not do anything, equivalent to not
entering an action
section.ignore_nextIgnore the next entry in the plist.pre-installpost-installpre-deinstallpost-deinstallpre-upgradepost-upgradeThese keywords contains a &man.sh.1; script to be
executed before or after installation, deinstallation,
or upgrade of the package. In addition to the usual
@exec%foo
placeholders described in , there is a new
one, %@, which represents the
argument of the keyword.Example of a @dirrmtryecho
KeywordThis keyword does two things, it adds a
@dirrmtry
directory line to the
packing list, and echoes the fact that the directory is
removed when deinstalling the package.actions: [dirrmtry]
post-deinstall: <<EOD
echo "Directory %D/%@ removed."
EODReal Life Example, How @sample
is ImplementedThis keyword does three things, it adds the
filename passed as an argument to
@sample to the packing list, it adds to
the post-install script instructions to
copy the sample to the actual configuration file if it does
not already exist, and it adds to the
post-deinstall instructions to remove the
configuration file if it has not been modified.actions: [file]
post-install: <<EOD
case "%@" in
/*) sample_file="%@" ;;
*) sample_file="%D/%@" ;;
esac
target_file="${sample_file%.sample}"
if ! [ -f "${target_file}" ]; then
/bin/cp -p "${sample_file}" "${target_file}"
fi
EOD
pre-deinstall: <<EOD
case "%@" in
/*) sample_file="%@" ;;
*) sample_file="%D/%@" ;;
esac
target_file="${sample_file%.sample}"
if cmp -s "${target_file}" "${sample_file}"; then
rm -f "${target_file}"
else
echo "You may need to manually remove ${target_file} if it's no longer needed."
fi
EOD