With all relevant variables set, at the very end the file uses the line
.include <bsd.port.mk>
to pull in the common infrastructure it shares with all other ports. This is what makes the common targets work, so for example, typing
$ doas make install
(probably the most common port-related make command for end users and administrators) in the port directory will start the process to install the software.
But before you type that command and press
Enter, you may want to consider this: This command will generate a lot of output, most likely more than will fit in the terminal's buffer. If the build fails, it is likely that the message about the first thing that went wrong will have scrolled off the top of your screen and out of the terminal buffer. For that reason, it is good sysadmin practice to create a record of lengthy operations such as building a port by using the
script command. Typing
script in a shell will give you a subshell where everything displayed on the screen will be saved in a file. Escape sequences, asterisk-style progress bars and 'twirling batons' will end up a bit garbled, but that essential message you are looking for will be there too.
man script will give you the details, and unless you're an incurable packrat, do remember to delete the typescript file afterwards.
That process will start with checking dependencies, go on with downloading the source archive and checking that the fetched file matches the cryptographic signatures stored in the
distinfo file. If the signatures match, the source code is extracted to a working directory, the patches from the
patches/ directory are applied, and the compilation starts. If the dependency check finds that one or more pieces are missing, you will see that the process fetches, configures and installs the required package before continuing with the build process for the original package.
After a while, the package build most likely succeeds and the install completes. At this point you will have a new piece of software installed on your system. You should be able to run the program, and the installed package will turn up in the package listings output by
pkg_info, such as
$ pkg_info | grep screen
screen-4.0.3p3 multi-screen window manager
This information is taken from the package's subdirectory in
/var/db/pkg, where the information about currently installed packages is stored.
If you paid close attention during the make install process, you may have noticed that the install step was performed from a binary package. This is one of the distinctive features of the OpenBSD version of the package system. The package build always generates an installable package based on a 'fake' install to a private directory, and software is always installed on the target system from a package.
And now we should mention that on a typical modern OpenBSD system, you wouldn't want to install GNU Screen at all. Since the OpenBSD 4.6 release, equivalent (or better!) functionality has been included in the OpenBSD base system via
tmux(1).
But you don't need to do that!
This means several things. If you have built and installed a package by typing
make install in the relevant ports directory and later run the
make deinstall or
pkg_delete to remove the software, any subsequent install of the software will take place from the package file stored in a subdirectory of
/usr/ports/packages.
But more importantly, in most cases you can keep your system's packages up to date without a ports tree on the machine. The main exceptions to the rule that precompiled packages are available from the
mirrors are software with licenses that do not allow redistribution or require the end user to do specific things such as go to a web site and click a specific button to formally accept a set of conditions. In those cases it cant' be helped, and you will need to go via the ports system to create a package locally and install that.
For each release, a full set of packages is built and made available on the OpenBSD mirrors, and by the time you read this, there is reason to hope that running updates to -stable packages will be available for supported releases too.
The way to make good use of this is to set the PKG_PATH variable to include the packages directory for your release on one or more mirrors close to you and/or a local directory, and then run
pkg_add with the
-u flag.
My laptop runs -current and I'm based in Europe, so the
PKG_PATH is set to
PKG_PATH=https://ftp.eu.openbsd.org/pub/OpenBSD/snapshots/packages/`uname -m`/
On a more conservatively run system, you may want to set it to something like
PKG_PATH=https://ftp.eu.openbsd.org/pub/OpenBSD/`uname -r`/packages/`uname -m`/
If you want to find out what packages are available at your favorite mirror, you can get a listing of package names by fetching the file
$PKG_PATH/index.txt. Another nice resource is
openbsd.app, which offers a nice clickable interface.
Once your
PKG_PATH is set to something sensible, you can use
pkg_add and the package base name to install packages, so a simple
$ doas pkg_add screen
would achieve the same thing as the '
make install' command earlier (minus the lengthy compilations, and still assuming that you would want to install the package instead of getting to know
tmux(1), which is included in the base system), and most likely a lot faster too.
Once you have a set of packages installed, and keeping in mind that you need a meaningful
PKG_PATH, you can keep them up to date using
pkg_add -u. If you want more detailed information about the package update process and want pkg_add to switch to interactive mode when necessary, you can use something like this command:
$ doas pkg_add -vui
I have at times tended to run my
pkg_add -u with some of the
-F flags in order to force resolution of certain types of conflict, but given the quality of the work that goes into the packages, most of the
-F options are rarely needed.
pkg_add and its siblings in the
pkg_* tools collection has a number of options we have not covered here, all intended to make your package management on OpenBSD as comfortable and flexible as possible. The tools come with readable man pages, and may very well be the topic of future articles. You should also be aware that Michael W Lucas's
Absolute OpenBSD, 2nd Edition is available from better bookstores with a more in-depth treatment of the package system than what I've presented here. Look at the end of the article for further links.
How do I make a package then?
That is a large question, and the first question you should ask if you think you want to port a particular piece of software is, "Has this already been ported?". There are several ways to check. If you are thinking of creating a port, you most likely already have the ports tree installed, so using the ports infrastructure's search infrastructure is the obvious first step. Simply go to the
/usr/ports directory and run the command
$ make search key=mykeyword
where
mykeyword is a program name or keyword related to the software you are looking for. One other option with even more flexible search possibilities is to install databases/sqlports. And of course, searching the ports mailing list archives (
https://marc.info/?l=openbsd-ports) or asking the mailing list works too.
When you have determined that the software you want to port is not already available as a package, you can go on to prepare for the porting effort. Porting and package making is the subject of much usenet folklore and rumor, but in addition you have several man pages with specific information on how to proceed. These are,
ports(7),
package(5),
packages(7),
packages-specs(7),
library-specs(7)
and
bsd.port.mk(5).
Read those and use your familiarity with the code you are about to port to find your way. The
OpenBSD web offers a quite a bit of information too. You could start with re-reading the main ports and packages page at
https://www.openbsd.org/faq/faq15.html, and follow up with the pages about the porting process at
https://www.openbsd.org/faq/ports/, testing the port at
https://www.openbsd.org/faq/ports/testing.html and finally the checklist for a sound port at
https://www.openbsd.org/faq/ports/guide.html#PortsChecklist.
All the while, try first to figure out the solution to any problems that pop up, read the supplied documentation, and only then ask port maintainers via the ports mailing list for help. Port maintainers are generally quite busy, but if you show signs of having done your homework first, there is no better resource available for helping you succeed in your porting or port maintenance efforts.
One fine resource for the aspiring porter is Bernd Ahlers' ports tutorial from OpenCon 2007 (hm. doesn't that need a refresh?), you can look up Bernd's slides at
https://www.openbsd.org/papers/opencon07-portstutorial/index.html, and it is possible he can be persuaded to repeat the tutorial at a conference near you. And for some recent advances in the OpenBSD ports and packages system, see Marc Espie's EuroBSDCon 2012 presentation
Advances in packages and ports in OpenBSD.
More information on the net
The main source of information about the OpenBSD ports and packages system is to be found on the OpenBSD project's web site. The FAQ's ports and packages section at
https://www.openbsd.org/faq/faq15.html has more information about all the issues covered in this article, and goes into somewhat more detail than space allows here. If you encounter problems while installing or managing your packages, it is more than likely that you will find a solution or a good explanation there. And of course, if nothing else works or you can't figure it out, there is always the option of asking the good people at
misc@openbsd.org or
ports@openbsd.org (do read the
OpenBSD Mailing Lists page before just butting in) or search the corresponding mailing list archives.
An earlier version of this article appeared in
BSD Magazine 2/2008. You can now also find this updated version
featured at
OpenBSD Journal (aka undeadly.org), the primary OpenBSD news site.
If you're interested in OpenBSD in general, you have a real treat coming up in the form of Michael W. Lucas'
Absolute OpenBSD, 2nd edition. If a firewall or other networking is closer to your heart, you could give my own
The Book of PF and the
PF tutorial (or
here) it grew out of. You can even support the OpenBSD project by buying the books from them at the same time you buy your CD set, see the
OpenBSD Orders page for more information.
Upcoming talks: I'll be speaking at
BSDCan 2013, on
The Hail Mary Cloud And The Lessons Learned, with a preview planned for the
BLUG meeting a couple of weeks before the conference. There will be no PF tutorial at this year's BSDCan, fortunately my staple tutorial item was crowded out by new initiatives from some truly excellent people.