Tcl Extensions & Useful Tcl CommandsA MacPorts Portfile is a Tcl script, so it may contain any arbitrary
Tcl code you may learn about in a Tcl reference manual.
However, few authors will use arbitrary Tcl code; the vast majority will use
a subset of Tcl commands and a number of Tcl extensions that are coded within
MacPorts for performing the most common tasks needed for Portfiles. The list
below is a list of useful Tcl commands for Portfile development and Tcl
extensions provided by MacPorts base.fileThe standard Tcl file command can be used for
a number of operations on files, such as moving, renaming, deleting,
or creating directories, among others. For a complete list, consult
the Tcl
reference manual for the file command,
or the Tcl file manpage in the section of manpages
on your machine using man n filefile copyCopy a file.file renameRename a file.file delete [-force]Remove a file or (with ) a directory
and its contents.file mkdirCreate a directory.macrosFor the above operations provided by Tcl's
file command, MacPorts provides the following
shorthands. These used to be separate functions to work around bugs
in older Tcl versions or on old versions of OS X. Nowadays those are
simple aliases.copyShorthand alternative to file copy.moveShorthand alternative to file rename.delete file ...Deletes each of the given files/directories. Behaves
similarly to file delete -force except that file delete -force
will fail to delete directories properly on 10.3
systems.touchMimics the BSD touch command.lnMimics the BSD ln command.xinstallxinstall copies files and creates directories; it is intended to
be compatible with install(1).xinstall [-o owner] [-g
group] [-m
mode] [file1 file2
...] directoryInstall the specified file(s) to a destination
directory.xinstall [-o owner] [-g
group] [-m
mode] [-W
dir] [file1 file2
...] directoryChange to and install file(s) to a
destination directory.xinstall [-o owner] [-g
group] [-m
mode] {*}[glob
pattern]
directoryInstall the file(s) matching the glob pattern to a
destination directory. Note the use of the
operator to convert the list returned by glob
into separate arguments to xinstall.xinstall -d [-o owner] [-g
group] [-m
mode]
directoryCreate a directory including parent directories if
necessary.Defaults:owner -group -mode - Examples:xinstall -m 640 ${worksrcpath}/README \
${destroot}${prefix}/share/doc/${name}xinstall -m 640 -W ${worksrcpath}/doc README INSTALL COPY \
${destroot}${prefix}/share/doc/${name}xinstall -m 640 {*}[glob ${worksrcpath}/doc/*] \
${destroot}${prefix}/share/doc/${name}xinstall -d ${destroot}${prefix}/share/doc/${name}strsedstrsed can be used for string manipulations using regular
expressions. It supports a small subset of the commands known
from sed(1).strsed string
s/regex/replacement/
Replaces the first instance of
regex with
replacement. Refer to
re_format(7) for a definition of regular expression
syntax.strsed string
g/regex/replacement/
The same as the previous format, except all
instances of the pattern will be replaced, not only
the first (mnemonic: 'g' is for global).reinplaceAllows text specified by a regular expression to be replaced by
new text, in-place (the file will be updated itself, no need to place
output into a new file and rename).
reinplace
[-locale locale]
[-n]
[-W dir]
[--] commandfile ...Replace text given by the regular expression portion of
the command with the replacement text, in all files
specified.Use -locale to set the locale. The default locale is en_US.UTF-8.
For example, -locale C will allow a non-UTF-8 file to be modified (which
may otherwise give the error "sed: RE error: illegal byte sequence"), but only operating
on ASCII characters. If you need it to work on non-ASCII characters you need to set a
locale with the correct charset for the file, e.g. "en_US.ISO8859-1".-n is passed to sed to suppress echoing result-W to set a common working directory for multiple
filesUse -E to use the extended regular expression style (see
re_format(7) for a description of the basic and extended
styles)Use -- to end option processing and allow any further
dashes not to be treated as options.Examples:reinplace -W ${worksrcpath} "s|/usr/local|${prefix}|g" configure setup.pyreinplace "s|@@PREFIX@@|${prefix}|g" ${worksrcpath}/Makefileuser/groupadduser username [uid=uid]
[gid=gid]
[passwd=passwd]
[realname=realname]
[home=home]
[shell=shell]Add a new local user to the system with the specified uid,
gid, password, real name, home directory and login shell.existsuser usernameCheck if a local user exists. Returns the uid for the
given user, or 0 if the user wasn't found. Checking for the root
user is not supported because its uid is 0, and it will always
exist anyway.nextuidReturns the highest used uid plus one.addgroup group
[gid=gid]
[passwd=passwd]
[realname=realname]
[users=users]Add a new local group to the system, with the specified
gid, password, real name, and with a list users as
members.existsgroup groupCheck if a local group exists and return the corresponding
gid. This can be used with adduser:addgroup foo
adduser foo gid=[existsgroup foo]nextgidReturns the highest used gid plus one.External program executionUse only when ....