A MacPorts Portfile is a Tcl script, so it may contain any arbitrary Tcl code you may learn about in the Tcl documentation. 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.
+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 n section of manpages on your machine using +man n file++-force+) a directory and its contents.+file+ command, MacPorts provides the following shorthands.
These should be used in preference to the Tcl commands above, as they may work around certain bugs.+file copy+.file rename but correctly handles renames that only change the case of a file on a case-insensitive filesystem.+file delete -force+.+owner+] [-g +group+] [-m +mode+] [+file1 file2 …+] directory+owner+] [-g +group+] [-m +mode+] [-W +dir+] [+file1 file2 …+] directorydir and install file(s) to a destination directory.+owner+] [-g +group+] [-m +mode+] {*}[glob +pattern+] directory{*} operator to convert the list returned by +glob+ into separate arguments to +xinstall+.+owner+] [-g +group+] [-m +mode+] directoryCreate a directory including parent directories if necessary.
Defaults:
0755Examples:
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}string s/+regex+/+replacement+/ regex with +replacement+.
Refer to re_format(7) for a definition of regular expression syntax.string g/+regex+/+replacement+/ +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 files
Use -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.py+
reinplace "s|@@PREFIX@@|${prefix}|g" ${worksrcpath}/Makefile+uid+] [gxml:id=+gid+] [passwd=+passwd+] [realname=+realname+] [home=+home+] [shell=+shell+]usernamegroup [gxml:id=+gid+] [passwd=+passwd+] [realname=+realname+] [users=+users+]groupaddgroup foo adduser foo gxml:id=[existsgroup foo]