Contributed by &a.jkh;, &a.gpalmer;, &a.asami; and
&a.obrien;.
The porting of freely available software, while perhaps not as gratifying as developing your own from scratch, is still a vital part of FreeBSD's growth and of great usefulness to those who would not otherwise know where to turn for it. All ported software is organized into a carefully organized hierarchy known as ``the ports collection''. The collection enables a new user to get a quick and complete overview of what is available for FreeBSD in an easy-to-compile form. It also saves considerable space by not actually containing the majority of the sources being ported, but merely those differences required for running under FreeBSD.
What follows are some guidelines for creating a new port for
FreeBSD. The bulk of the work is done by
/usr/share/mk/bsd.port.mk, which all port Makefiles include.
Please refer to that file for more details on the inner workings of
the ports collection. Even if you don't hack Makefiles daily, it is
well commented, and you will still gain much knowledge from it.
Note: Only a fraction of the overridable variables
(${..}) are mentioned in this document. Most
(if not all) are documented at the start of
bsd.port.mk. This file uses a non-standard tab
setting. Emacs and Vim should recognize the setting
on loading the file. vi or ex can be set to
using the correct value by typing `:set tabstop=4'
once the file has been loaded.
You may come across code that needs modifications or
conditional compilation based upon what version of UNIX it is
running under. If you need to make such changes to the code
for conditional compilation, make sure you make the changes as
general as possible so that we can back-port code to FreeBSD
1.x systems and cross-port to other BSD systems such as 4.4BSD
from CSRG, BSD/386, 386BSD, NetBSD, and OpenBSD.
The preferred way to tell 4.3BSD/Reno (1990) and newer versions of
the BSD code apart is by using the `BSD' macro
defined in <sys/param.h>. Hopefully that file
is already included; if not, add the code:
to the proper place in the .c file. We believe that every
system that defines these to symbols has sys/param.h. If you find
a system that doesn't, we would like to know. Please send
mail to &a.ports;.
Another way is to use the GNU Autoconf style of doing this:
Use sparingly:
In the hundreds of ports that have been done, there have
only been one or two cases where __FreeBSD__
should have been used. Just because an earlier port
screwed up and used it in the wrong place does not mean
you should do so too.
This section tells you how to do a quick port. In many
cases, it is not enough, but we will see.
First, get the original tarball and put it into
${DISTDIR}, which defaults to
/usr/ports/distfiles.
Note: The following assumes that the software compiled
out-of-the-box, i.e., there was absolutely no change required
for the port to work on your FreeBSD box. If you needed to
change something, you will have to refer to the next section
too.
The minimal Makefile would look something like this:
See if you can figure it out. Do not worry about the contents
of the $Id$ line, it will be filled in
automatically by CVS when the port is imported to our main
ports tree. You can find a more detailed example in the section.
There are three required description files that are
required for any port, whether they actually package or not.
They are COMMENT, DESCR, and
PLIST, and reside in the pkg subdirectory.
This is the one-line description of the port. PLEASE
do not include the package name (or version number of the
software) in the comment.
Here is an example:
This is a longer description of the port. One to a few
paragraphs concisely explaining what the port does is
sufficient. This is not a manual or an
in-depth description on how to use or compile the port!
Please be careful if you are copying from the
README or manpage; too often they are not a
concise description of the port or are in an awkward format
(e.g. manpages have justified spacing). If the ported software
has an official WWW homepage, you should list in here.
It is recommended that you sign the name at the end of
this file, as in:
This file lists all the files installed by the port. It
is also called the `packing list' because the package is
generated by packing the files listed here. The pathnames
are relative to the installation prefix (usually
/usr/local or /usr/X11R6). If you are
using the Here is a small example:
Refer to the pkg_create(1) man page for details
on the packing list.
Just type `make makesum'. The ports make rules
will automatically generate the file files/md5.
You should make sure that the port rules do exactly what
you want it to do, including packaging up the port. Try
doing `make install', `make package' and
then `make deinstall' and see if all
the files and directories are correctly deleted. Then do a
`pkg_add `make package-name`.tgz' and see if everything
re-appears and works correctly. Then do another
`make deinstall' and then `make
reinstall; make package' to make sure you haven't
included in the packing list any files that are not
installed by your port.
First, make sure you have read the section.
Now that you are happy with your port, the only thing
remaining is to put it in the main FreeBSD ports tree and
make everybody else happy about it too. We do not need
your work/ directory or the pkgname.tgz
package, so delete them now. Next, simply include the
output of `shar `find port_dir`' in a
bug report and send it with the send-pr(1)
program. If the uncompressed port is larger than 20KB,
you should compress it into a tarfile and use
uuencode(1) before including it in the bug report
(uuencoded tarfiles are acceptable even if the report is
smaller than 20KB but are not preferred). Be sure to classify
the bug report as category `ports' and class `change-request'.
One more time, do not include the original source distfile,
the work/ directory, or the package you built with
`make package'!
See
for more information.
We will look at your port, get back to you if necessary, and put
it in the tree. Your name will also appear in the list of
`Additional FreeBSD contributors' on the FreeBSD Handbook
and other files. Isn't that great?!? :)
Ok, so it was not that simple, and the port required some
modifications to get it to work. In this section, we will
explain, step by step, how to modify it to get it to work with
the ports paradigm.
First, this is the sequence of events which occurs when the
user first types `make' in your port's directory,
and you may find that having bsd.port.mk in another
window while you read this really helps to understand it.
But do not worry if you do not really understand what
bsd.port.mk is doing, not many people
do... :>
The above are the default actions. In addition, you can
define targets `pre-<something>' or
`post-<something>', or put scripts with those
names, in the scripts subdirectory, and they will
be run before or after the default actions are done.
For example, if you have a post-extract target
defined in your Makefile, and a file pre-build in
the scripts subdirectory, the
post-extract target will be called after the
regular extraction actions, and the pre-build
script will be executed before the default build rules are
done. It is recommended that you use Makefile targets if
the actions are simple enough, because it will be easier for
someone to figure out what kind of non-default action the
port requires.
The default actions are done by the bsd.port.mk
targets `do-<something>'. For example, the
commands to extract a port are in the target
`do-extract'. If you are not happy with the
default target, you can fix it by redefining the
`do-<something>' target in your Makefile.
Note that the `main' targets (e.g., extract,
configure, etc.) do nothing more than make sure all
the stages up to that one is completed and call the real
targets or scripts, and they are not intended to be
changed. If you want to fix the extraction, fix
do-extract, but never ever touch extract!
Now that you understand what goes on when the user types
`make', let us go through the recommended steps to
create the perfect port.
Get the original sources (normally) as a compressed tarball
(<foo>.tar.gz or <foo>.tar.Z)
and copy it into ${DISTDIR}. Always use
mainstream sources when and where you can.
If you cannot find a ftp/http site that is well-connected
to the net, or can only find sites that have irritatingly
non-standard formats, you might want to put a copy on a
reliable http or ftp server that you control. If you are a
FreeBSD committer, your public_html directory on
freefall is ideal. Make sure you set MASTER_SITE to
reflect your choice! If you cannot find somewhere convenient
and reliable to put the distfile, we can `house' it ourselves
by putting it on
If your port requires some additional `patches' that are
available on the Internet, fetch them too and put them in
${DISTDIR}. Do not worry if they come from
site other than where you got the main source tarball,
we have a way to handle these situations (see the
description of below).
Unpack a copy of the tarball in a private directory and
make whatever changes are necessary to get the port to
compile properly under the current version of FreeBSD. Keep
careful track of everything you do, as you will be
automating the process shortly. Everything, including the
deletion, addition or modification of files should be doable
using an automated script or patch file when your port is
finished.
If your port requires significant user
interaction/customization to compile or install, you should
take a look at one of Larry Wall's classic Configure scripts
and perhaps do something similar yourself. The goal of the
new ports collection is to make each port as `plug-and-play'
as possible for the end-user while using a minimum of disk
space.
Note: Unless explicitly stated, patch files, scripts, and
other files you have created and contributed to the FreeBSD
ports collection are assumed to be covered by the standard
BSD copyright conditions.
In the preparation of the port, files that have been added
or changed can be picked up with a recursive diff for later
feeding to patch. Each set of patches you wish to apply
should be collected into a file named
`patch-<xx>' where <xx>
denotes the sequence in which the patches will be applied --
these are done in alphabetical order, thus
`aa' first, `ab' second and so on. These
files should be stored in ${PATCHDIR}, from
where they will be automatically applied. All patches
should be relative to ${WRKSRC} (generally
the directory your port's tarball unpacks itself into, that
being where the build is done). To make fixes and upgrades
easier you should avoid having more than one patch fix the
same file (e.g., patch-aa and patch-ab both changing
${WRKSRC}/foobar.c).
Include any additional customization commands to your
configure script and save it in the
`scripts' subdirectory. As mentioned above, you
can also do this as Makefile targets and/or scripts with the
name pre-configure or post-configure.
If your port requires user input to build, configure or
install, then set IS_INTERACTIVE in your Makefile.
This will allow `overnight builds' to skip your port if the
user sets the variable BATCH in his environment
(and if the user sets the variable INTERACTIVE,
then only those ports requiring interaction are
built).
Configuring the Makefile is pretty simple, and again we
suggest that you look at existing examples before starting.
Also, there is a in this handbook, so take a look and please follow
the ordering of variables and sections in that template to
make your port easier for others to read.
Now, consider the following problems in sequence as you
design your new Makefile:
Does it live in ${DISTDIR} as a standard
gzip'd tarball? If so, you can go on to the next step. If
not, you should look at overriding any of the
${EXTRACT_CMD},
${EXTRACT_BEFORE_ARGS},
${EXTRACT_AFTER_ARGS},
${EXTRACT_SUFX}, or
${DISTFILES} variables, depending on how
alien a format your port's distribution file is. (The most
common case is `EXTRACT_SUFX=.tar.Z', when the
tarball is condensed by regular compress, not gzip.)
In the worst case, you can simply create your own
`do-extract' target to override the default, though
this should be rarely, if ever, necessary.
You should set ${DISTNAME} to be the base
name of your port. The default rules expect the
distribution file list (${DISTFILES}) to be
named
${DISTNAME}${EXTRACT_SUFX}
by default which, if it is a normal tarball, is going to be
something like:
When a package is created, it is put under
/usr/ports/packages/All and links are made from one
or more subdirectories of /usr/ports/packages. The
names of these subdirectories are specified by the variable
${CATEGORIES}. It is intended to make life
easier for the user when he is wading through the pile of
packages on the ftp site or the CD-ROM. Please take a look
at the existing categories (you can find them in Record the directory part of the ftp/http-URL pointing at
the original tarball in ${MASTER_SITES}.
Do not forget the trailing slash (/)!
The make macros will try to use this specification for
grabbing the distribution file with ${FETCH}
if they cannot find it already on the system.
It is recommended that you put multiple sites on this list,
preferably from different continents. This will safeguard
against wide-area network problems, and we are even planning
to add support for automatically determining the closest
master site and fetching from there!
If the original tarball is part of one of the following
popular archives: X-contrib, GNU, Perl CPAN, TeX CTAN, or
Linux Sunsite, you refer to those sites in an easy compact
form using MASTER_SITE_XCONTRIB, MASTER_SITE_GNU,
MASTER_SITE_PERL_CPAN, MASTER_SITE_TEX_CTAN, and
MASTER_SITE_SUNSITE. Simply set MASTER_SITE_SUBDIR to the path
with in the archive. Here is an example:
The user can also set the MASTER_SITE_* variables in
/etc/make.conf to override our choices, and use their
favorite mirrors of these popular archives instead.
If your port requires some additional patches that are
available by ftp or http, set ${PATCHFILES}
to the names of the files and ${PATCH_SITES}
to the URL of the directory that contains them (the format
is the same as ${MASTER_SITES}).
If the patch is not relative to the top of the source tree
(i.e., ${WKRSRC}) because it contains some
extra pathnames, set ${PATCH_DIST_STRIP}
accordingly. For instance, if all the pathnames in the
patch has an extra `foozolix-1.0/' in front of the
filenames, then set `PATCH_DIST_STRIP=-p1'.
Do not worry if the patches are compressed, they will be
decompressed automatically if the filenames end with
`.gz' or `.Z'.
If the patch is distributed with some other files, such as
documentation, in a gzip'd tarball, you can't just use
${PATCHFILES}. If that is the case, add the
name and the location of the patch tarball to
${DISTFILES} and
${MASTER_SITES}. Then, from the
pre-patch target, apply the patch either by running
the patch command from there, or copying the patch file into
the ${PATCHDIR} directory and calling it
patch-<xx>. (Note the tarball will have been
extracted alongside the regular source by then, so there is
no need to explicitly extract it if it is a regular gzip'd
or compress'd tarball.) If you do the latter, take extra
care not to overwrite something that already exists in that
directory. Also do not forget to add a command to remove
the copied patch in the pre-clean target.
Set your mail-address here. Please. :)
For detailed description of the responsibility of maintainers,
refer to section.
Many ports depend on other ports. There are five
variables that you can use to ensure that all the required
bits will be on the user's machine.
This variable specifies the shared libraries this port
depends on. It is a list of `lib:dir' pairs
where lib is the name of the shared library, and
dir is the directory in which to find it in case
it is not available. For example,
This variable specifies executables or files this port
depends on during run-time. It is a list of
`path:dir' pairs where path is the name
of the executable or file, and dir is the
directory in which to find it in case it is not
available. If path starts with a slash
(/), it is treated as a file and its existence is
tested with `test -e'; otherwise, it is assumed
to be an executable, and `which -s' is used to
determine if the program exists in the user's search path.
For example,
This variable specifies executables or files this port
requires to build. Like RUN_DEPENDS, it is a
list of `path:dir' pairs. For example,
This variable specifies executables or files this port
requires to fetch. Like the previous two, it is a list of
`path:dir' pairs. For example,
If there is a dependency that does not fall into either of
the above four categories, or your port requires to have
the source of the other port extracted (i.e., having them
installed is not enough), then use this variable. This is
just a list of directories, as there is nothing to check,
unlike the previous four.
If your package uses GNU make, set
`USE_GMAKE=yes'. If your package uses GNU
configure, set `GNU_CONFIGURE=yes'. If
you want to give some extra arguments to GNU
configure (other than the default
`--prefix=${PREFIX}'),
set those extra arguments in
${CONFIGURE_ARGS}.
If your package is an X application that creates Makefiles
from Imakefiles using imake, then set
`USE_IMAKE=yes'. This will cause the configure
stage to automatically do an xmkmf -a. If the
`-a' flag is a problem for your port, set
`XMKMF=xmkmf'.
If your port's source Makefile has something else than
`all' as the main build target, set
${ALL_TARGET} accordingly. Same goes for
`install' and ${INSTALL_TARGET}.
If the port uses imake but does not understand the
`install.man' target,
`NO_INSTALL_MANPAGES=yes' should be set. In
addition, the author of the original port should be
shot. :>
There are many programs that require a Motif library
(available from several commercial vendors, while there is (at
least) one effort to create a free clone) to compile. Since
it is a popular toolkit and their licenses usually permit
redistribution of statically linked binaries, we have made
special provisions for handling ports that require Motif in a
way that we can easily compile binaries linked either
dynamically or statically.
If your port requires Motif, define this variable in the
Makefile. This will prevent people who don't own a copy of
Motif from even attempting to build it.
This variable will be set by bsd.port.mk to be the
appropriate reference to the Motif library. Please patch
the source to use this wherever the Motif library is
referenced in the Makefile or Imakefile.
There are two common cases:
Note that ${MOTIFLIB} (usually) expands to
`-L/usr/X11R6/lib -lXm' or
`/usr/X11R6/lib/libXm.a', so there is no need to
add `-L' or `-l' in front.
Since FreeBSD is moving to ELF from 3.0-release onwards,
we need to convert many ports that build shared libraries
to support ELF. Complicating this task is that a 3.0
system can run as both ELF and a.out, and that there will
be one more release (2.2.8) from the 2.2 branch. Below
are the guidelines on how to convert a.out only ports to
support both a.out and ELF compilation.
Some part of this list is only applicable during the
conversion, but will be left here for awhile for reference
in case you have come across some old port you wish to
upgrade.
A.out libraries should be moved out of
/usr/local/lib and similar to an `src/Makefile (called from `
The ports tree will build packages in the format the
machine is in. This means a.out for 2.2 and a.out or
ELF for 3.0 depending on what `objformat`
returns. Also, once users move a.out libraries
to a subdirectory, building a.out libraries will be
unsupported. (I.e., it may still work if you know what
you are doing, but you are on your own.)
Note: if a port only works for a.out, set
PORTOBJFORMAT=${PORTOBJFORMAT}'. (See comment
on The variable is set using this line:
The following are differences in handling shared
libraries for a.out and ELF.
You need to install a symlink libfoo.so ->
libfoo.so.N to make ELF linkers happy. Since
it should be listed in
All port Makefiles are edited to remove minor numbers
from foo\\.1\\.\\(33|40\\)' -> `foo.2'.)
They will be matched using `grep -wF'.
In cases where you really need to install shlibs with
two versions on an ELF system or those with one version
on an a.out system (for instance, ports that install
compatibility libraries for other operating systems),
define the variable
The The new version of texinfo (included in 2.2.2-RELEASE and
onwards) contains a utility called `&dollar{PREFIX}/info/dir file. (Sorry for the length
of this section, but it is imperative to weave all the info
files together. If done correctly, it will produce a
beautiful listing, so please bear with me! First, this is what you (as a porter) need to know:
Note that this program will not actually Here's a seven-step procedure to convert ports to use
editors/emacs as an
example.
The format should be self-explanatory. Many authors leave
a Note that you can put only one info entry per file because
of a bug in `install-info --delete' that deletes
only the first entry if you specify multiple entries in the
You can give the three The second hunk was necessary because the default target in
the /usr/share/info
(that patch is not shown here).
Do not use anything other than /usr/share/info/dir
and the above command to create a new info file. In fact,
I'd add the first three lines of the above patch to
Edit info/dir with Note that the `@unexec install-info --delete'
commands have to be listed before the info files themselves
so they can read the files. Also, the `@exec
install-info' commands have to be after the info files
and the Test and admire your work.
Some ports, particularly the p5- ports, need to change
their 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 the PLIST of
%%OSREL%%, %%PERL_VER%%, and
%%PERL_VERSION%% will be substituted for
appropriately. If you need to make other substitutions,
you can set the PLIST_SUB variable with a
list of VAR=VALUE pairs and instances
of "%%VAR%%" will be substituted with "VALUE" in the PLIST.
Some software packages have restrictive licenses or can be in
violation to the law (PKP's patent on public key crypto,
ITAR (export of crypto software) to name just two of them).
What we can do with them vary a lot, depending on the exact
wordings of the respective licenses.
Note that it is your responsibility as a porter to read the
licensing terms of the software and make sure that the FreeBSD
project will not be held accountable of violating them by
redistributing the source or compiled binaries either via ftp
or CD-ROM. If in doubt, please contact the &a.ports;.
There are two variables you can set in the Makefile to handle
the situations that arise frequently:
Note: The GNU General Public License (GPL), both version 1
and 2, should not be a problem for ports.
Note: If you are a committer, make sure you update the
ports/LEGAL file too.
When you notice that a port is out of date compared to the
latest version from the original authors, first make sure you
have the latest port. You can find them in the
ports-current directory of the ftp mirror sites.
The next step is to send a mail to the maintainer, if one is
listed in the port's Makefile. That person may already be
working on an upgrade, or have a reason to not upgrade the
port right now (because of, for example, stability problems
of the new version).
If the maintainer asks you to do the upgrade or there isn't
any such person to begin with, please make the upgrade and
send the recursive diff (either unified or context diff is
fine, but port committers appear to prefer unified diff more)
of the new and old ports directories
to us (e.g., if your modified port directory is called
`superedit' and the original as in our tree is
`superedit.bak', then send us the result of `diff
-ruN superedit.bak superedit'). Please examine the output
to make sure all the changes make sense. The best way to send
us the diff is by including it to send-pr(1) (category
`ports'). Please
mention any added or deleted files in the message, as they
have to be explicitly specified to CVS when doing a commit.
If the diff is more than about 20KB, please compress and
uuencode it; otherwise, just include it in as is in the PR.
Here is a list of common do's and dont's that you encounter
during the porting process. You should check your own port
against this list, but you can also check ports in the PR
database that others have submitted. Submit any comments on
ports you check as described in . Checking ports in
the PR database will both make it faster for us to commit them,
and prove that you know what you are doing.
Do not leave anything valuable lying around in the
work subdirectory, `make clean' will
nuke it completely! If you need auxiliary files
that are not scripts or patches, put them in the
${FILESDIR} subdirectory (files by default)
and use the post-extract target to
copy them to the work subdirectory.
Do use portlint! The
Do strip binaries. If the original source already strips
the binaries, fine; otherwise you should add a post-install
rule to do it yourself. Here is an example:
Use the file command on the installed executable
to check whether the binary is stripped or not. If it
does not say `not stripped', it is stripped.
Do use the pkg/PLIST
(this means you must NOMANCOMPRESS Note that this is not usually necessary with ports that are X
applications and use Imake to build.
If your port anchors its man tree somewhere other than
PREFIX, you can use the MANPREFIX to set it.
Also, if only manpages in certain section go in a
non-standard place, such as many Perl modules ports, you
can set individual man paths using
MANsectPREFIX (where sect is one
of 1-9, L or N).
Do use the macros provided in bsd.port.mk to
ensure correct modes and ownership of files in your own
*-install targets. They are:
These are basically the install command with all
the appropriate flags. See below for an example on how to
use them.
If your port needs execute commands when the binary package
is installed with pkg_add you can do with via the pkg/INSTALL
script. This script will automatically be added to the
package, and will be run twice by pkg_add. The first time
will as `INSTALL ${PKGNAME} PRE-INSTALL'
and the second time as `INSTALL ${PKGNAME} POST-INSTALL'.
`$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. See man pkg_add(1)
for additional information.
Note, that this script is not run automatically if you install
the port with `make install'. If you are depending
on it being run, you will have to explicitly call it on your
port's Makefile.
If your port needs to determine if it should install or not, you
can create a pkg/REQ ``requirements'' script. It will be invoked
automatically at installation/deinstallation time to determine
whether or not installation/deinstallation should proceed.
See man pkg_create(1) and man pkg_add(1) for
more information.
If your software has some documentation other than the
standard man and info pages that you think is useful for the
user, install it under ${PREFIX}/share/doc.
This can be done, like the previous item, in the
post-install target.
Create a new directory for your port. The directory name
should reflect what the port is. This usually means
${PKGNAME} minus the version part. However,
if you think the user might want different versions of the
port to be installed at the same time, you
can use the whole ${PKGNAME}.
Make the installation dependent to the variable
NOPORTDOCS so that users can disable it in
/etc/make.conf, like this:
Do not forget to add them to pkg/PLIST too! (Do not
worry about NOPORTDOCS here; there is currently no
way for the packages to read variables from
/etc/make.conf.)
If you need to display a message to the installer, you may
place the message in pkg/MESSAGE. This capability
is often useful to display additional installation steps to
be taken after a pkg_add, or to display licensing information.
(note: the MESSAGE file does not need to be added to pkg/PLIST).
Do not let your port clutter /usr/ports/distfiles. If
your port requires a lot of files to be
fetched, or contains a file that has a name that might conflict
with other ports (e.g., `Makefile'), set
${DIST_SUBDIR} to the name of the port
(${PKGNAME} without the version part should work
fine). This will change ${DISTDIR} from the
default /usr/ports/distfiles to
/usr/ports/distfiles/${DIST_SUBDIR}, and in
effect puts everything that is required for your port into that
subdirectory.
It will also look at the subdirectory with the same name on the
backup master site at ftp.freebsd.org. (Setting
${DISTDIR} explicitly in your Makefile will not
accomplish this, so please use ${DIST_SUBDIR}.)
Note this does not affect the ${MASTER_SITES}
you define in your Makefile.
Do send applicable changes/patches to the original
author/maintainer for inclusion in next release of the code.
This will only make your job that much easier for the next
release.
Do not put RCS strings in patches. CVS will mangle them
when we put the files into the ports tree, and when we check
them out again, they will come out different and the patch
will fail. RCS strings are surrounded by dollar
(`$') signs, and typically start with
`$Id' or `$RCS'.
Using the recurse (`-r') option to diff
to generate patches is fine, but please take a look at the
resulting patches to make sure you don't have any
unnecessary junk in there. In particular, diffs between two
backup files, Makefiles when the port uses Imake or GNU
configure, etc., are unnecessary and should be deleted.
Also, if you had to delete a file, then you can do it in the
post-extract target rather than as part of the
patch. Once you are happy with the resulting diff, please
split it up into one source file per patch file.
Do try to make your port install relative to
${PREFIX}. (The value of this variable will be
set to ${LOCALBASE} (default
/usr/local), unless ${USE_X_PREFIX}
or ${USE_IMAKE} is set, in which case it will be
${X11BASE} (default /usr/X11R6).)
Not hard-coding `/usr/local' or `/usr/X11R6'
anywhere in the source will make the port much more flexible and
able to cater to the needs of other sites. For X ports that use
imake, this is automatic; otherwise, this can often be done by
simply replacing the occurrences of `/usr/local' (or
`/usr/X11R6' for X ports that do not use imake) in the
various scripts/Makefiles in the port to read
`${PREFIX}', as this variable is automatically
passed down to every stage of the build and install processes.
Do not set USE_X_PREFIX unless your port truly requires
it (i.e. it links against X libs or it needs to reference
files in ${X11BASE}.
The variable ${PREFIX} can be reassigned in your
Makefile or in the user's environment. However, it is strongly
discouraged for individual ports to set this variable explicitly
in the Makefiles.
Also, refer to programs/files from other ports with the
variables mentioned above, not explicit pathnames. For instance,
if your port requires a macro PAGER to be the full
pathname of less, use the compiler flag:
Try to let the port put things in the right subdirectories
of ${PREFIX}. Some ports lump everything
and put it in the subdirectory with the port's name, which is
incorrect. Also, many ports put everything except binaries,
header files and manual pages in the a subdirectory of
`lib', which does not bode well with the BSD
paradigm. Many of the files should be moved to one of the
following: `etc' (setup/configuration files),
`libexec' (executables started internally),
`sbin' (executables for superusers/managers),
`info' (documentation for info browser) or
`share' (architecture independent files). See man
hier(7) for details, the rule governing
/usr pretty much applies to /usr/local
too. The exception are ports dealing with USENET `news'.
They may use ${PREFIX}/news as a destination
for their files.
If your port installs a shared library, add a
post-install target to your Makefile that runs
`/sbin/ldconfig -m' on the directory where the new
library is installed (usually ${PREFIX}/lib)
to register it into the shared library cache.
Also, add an @exec line to your pkg/PLIST
file so that a user who installed the package can start
using the shared library immediately. This line should
immediately follow the line for the shared library itself,
as in:
Never, ever, ever add a line that says
`ldconfig' without any arguments to your Makefile
or pkg/PLIST. This will reset the shared library cache to
the contents of /usr/lib only, and will royally
screw up the user's machine ("Help, xinit does not run
anymore after I install this port!"). Anybody who does this
will be shot and cut into 65,536 pieces by a rusty knife and
have his liver chopped out by a bunch of crows and will
eternally rot to death in the deepest bowels of hell (not
necessarily in that order)....
If your port requires a certain user to be on the
installed system, let the pkg/INSTALL script call
pw to create it automatically. Look at
net/cvsup-mirror for an example.
If your port must use the same user/group ID number when it is
installed as a binary package as when it was compiled, then you
must choose a free UID from 50 to 99 and register it
below. Look at japanese/Wnn for an example.
Make sure you don't use a UID already used by the system or
other ports. This is the current list of UIDs between 50
and 99.
Please include a notice when you submit a port (or an upgrade)
that reserves a new UID or GID in this range. This allows us
to keep the list of reserved IDs up to date.
The Makefile should do things simply and reasonably. If you
can make it a couple of lines shorter or more readable, then
do so. Examples include using a make `.if' construct
instead of a shell `if' construct, not redefining
do-extract if you can redefine ${EXTRACT*}
instead, and using $GNU_CONFIGURE instead of
`CONFIGURE_ARGS += --prefix=${PREFIX}'.
The port should respect the ${CFLAGS} variable.
If it doesn't, please add `NO_PACKAGE=ignores cflags'
to the Makefile.
The files pkg/DESCR, pkg/COMMENT, and
pkg/PLIST should each be double-checked. If you are
reviewing a port and feel they can be worded better, do so.
Don't copy more copies of the GNU General Public License into
our system, please.
Please be careful to note any legal issues! Don't let us
illegally distribute software!
Do look at existing examples and the bsd.port.mk
file before asking us questions! ;)
Do ask us questions if you have any trouble! Do not just
beat your head against a wall! :)
Here is a sample Makefile that you can use to create a new
port. Make sure you remove all the extra comments (ones
between brackets)!
It is recommended that you follow this format (ordering of
variables, empty lines between sections, etc.). Not all of
the existing Makefiles are in this format (mostly old ones),
but we are trying to uniformize how they look. This format is
designed so that the most important information is easy to
locate.
The following are the conventions you should follow in
naming your packages. This is to have our package directory
easy to scan, as there are already lots and lots of packages
and users are going to turn away if they hurt their eyes!
The package name should look like
Here are some (real) examples on how to convert a
${DISTNAME} into a suitable
${PKGNAME}:
If there is absolutely no trace of version information in the
original source and it is unlikely that the original author
will ever release another version, just set the version string
to `1.0' (like the piewm example above). Otherwise, ask the
original author or use the date string (`yy.mm.dd') as the
version.
If you maintain a lot of ports, you should consider following
the ports@FreeBSD.ORG mailing-list. Important changes to
the way ports work will be announced there. You can always
find more detailed information on the latest changes by
looking at Boy, this sure was a long tutorial, wasn't it? Thanks for
following us to here, really.
Well, now that you know how to do a port, let us go at it and
convert everything in the world into ports! That is the
easiest way to start contributing to the FreeBSD Project!
:)