# Tcl Extensions

A 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 Tcl extensions that are coded within MacPorts for performing the most common tasks needed for Portfiles. The list below is a list of Tcl extensions provided by MacPorts base.

file

  Description.

  file copy

  file move

  file rename

  file delete [-force]

  file mkdir

macros

  Description.

  copy

    Shorthand alternative to "file copy".

  move

    Shorthand 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.

  touch

    Mimicks the BSD touch command.

  ln

    Mimickes the BSD ln command.

xinstall

  xinstall copies files and creates directories; it is intended to be compatible with install(1).

  xinstall [-o owner] [-g group] [-m mode] [file1 file2 ...] directory

    Install the specified file(s) to a destination directory.

  xinstall [-o owner] [-g group] [-m mode] [-W dir] [file1 file2 ...] directory

    Change to `dir` and install file(s) to a destination directory.

  eval xinstall [-o owner] [-g group] [-m mode] [glob pattern] directory

    Install the file(s) matching the glob pattern to a destination directory.

  xinstall -d [-o owner] [-g group] [-m mode] directory

    Create a directory including parent directories if necessary.

  Defaults:

  - owner -

  - group -

  - mode -

  Examples:

      xinstall -m 640 ${worksrcpath}/doc README \
         ${destroot}${prefix}/share/doc/${name}

      xinstall -m 640 -W ${worksrcpath}/doc README INSTALL COPY \
         ${destroot}${prefix}/share/doc/${name}

      eval xinstall -m 640 [glob ${worksrcpath}/doc/*] \
         ${destroot}${prefix}/share/doc/${name}

      xinstall -d ${destroot}${prefix}/share/doc/${name}

reinplace

  Allows 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 [-E] [--] command file ...

    Replace text given by the regular expression portion of the command with the replacement text, in all files specified.

    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 "s|/usr/local|${prefix}|g" ${worksrcpath}/configure

      reinplace "s|@@PREFIX@@|${prefix}|g" ${worksrcpath}/Makefile

user/group

  adduser 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 username

    Check 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.

  nextuid

    Returns 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 group

    Check if a local group exists and return the corresponding gid. This can be used with adduser:

        addgroup foo
        adduser foo gid=[existsgroup foo]

  nextgid

    Returns the highest used gid plus one.

External program execution

  Use only when ....