xref: /openbsd-src/share/man/man7/ports.7 (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1.\"
2.\" Copyright (c) 1997 David E. O'Brien
3.\"
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
16.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
19.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25.\"
26.\" $OpenBSD: ports.7,v 1.110 2016/09/02 12:17:33 tb Exp $
27.\" $FreeBSD: ports.7,v 1.7 1998/06/23 04:38:50 hoek Exp $
28.\"
29.Dd $Mdocdate: September 2 2016 $
30.Dt PORTS 7
31.Os
32.Sh NAME
33.Nm ports
34.Nd contributed applications
35.Sh DESCRIPTION
36The
37.Ox
38Ports Collection
39is the infrastructure used to create binary packages for third party
40applications.
41.Pp
42For normal usage refer to
43.Xr packages 7 ,
44as most ports produce binary packages which are available from
45the official CD-ROM, or on a neighborly FTP mirror.
46.Pp
47Each port contains any patches necessary to make the original
48application source code compile and run on
49.Ox .
50Compiling an application is as simple as typing
51.Ic make
52in the port directory!
53The
54.Pa Makefile
55automatically fetches the
56application source code, either from a local disk or via ftp, unpacks it
57on the local system, applies the patches, and compiles it.
58If all goes well, simply type
59.Ic doas make install
60to install the application.
61.Pp
62For more information about using ports, see
63The
64.Ox
65Ports System
66.Pq Lk https://www.openbsd.org/faq/faq15.html#Ports .
67For information about creating new ports, see
68the
69.Ox
70Porter's Handbook
71.Pq Lk https://www.openbsd.org/faq/ports/ .
72.Pp
73For a detailed description of the build process, see
74.Xr bsd.port.mk 5 .
75.Sh PORTS MASTER MAKEFILE
76The ports master Makefile, normally located in
77.Pa /usr/ports/Makefile
78(but see
79.Ev PORTSDIR
80below)
81offers a few useful targets.
82.Bl -tag -width configure
83.It Cm index
84rebuild the ports complete index,
85.Pa /usr/ports/INDEX
86.It Cm pkglocatedb
87build a
88.Xr pkg_mklocatedb 1
89database file and place it in
90.Pa ${PORTSDIR}/packages/${MACHINE_ARCH}/ftp ,
91for use by
92.Xr locate 1 ,
93.It Cm print-index
94display the contents of the index in a user-friendly way,
95.It Cm search
96invoked with a key, e.g.,
97.Ic make search key=foo ,
98retrieve information relevant to a given port (obsolescent).
99.El
100.Pp
101Starting in
102.Ox 4.0 ,
103there is a port,
104.Pa databases/sqlports
105that builds an sqlite database containing most information relevant to
106every port in the ports tree.
107This database can be searched using any tool able to manipulate such
108databases, for instance sqlitebrowser, or a script language with an
109sqlite interface, e.g., perl, python, ocaml, lua, php5.
110.Sh SELECTING A SET OF PORTS
111One can define
112.Ev SUBDIRLIST
113to point to a file that contains a list of
114.Ev FULLPKGPATHs ,
115one per line, to build stuff only in some directories.
116.Pp
117If
118.Pa /usr/ports/INDEX
119is up to date, it is possible to select subsets by setting the following
120variables on the command line:
121.Bl -tag -width category
122.It Va key
123package name matching the given key,
124.It Va category
125port belonging to category,
126.It Va maintainer
127port maintained by a given person.
128.El
129.Pp
130For instance, to invoke
131.Cm clean
132on all ports in the x11 category, one can say:
133.Bd -literal -offset indent
134$ make category=x11 clean
135.Ed
136.Pp
137The index search is done by a perl script, so all regular expressions from
138.Xr perlre 1
139apply.
140.Sh TARGETS
141Individual ports are controlled through a few documented targets.
142Some of these targets work recursively through subdirectories, so that
143someone can, for example, install all of the net
144ports.
145.Pp
146The variable
147.Ev SKIPDIR
148can hold a set of package directories to avoid during recursion.
149These are always specified relative to the root of the ports tree,
150and can contain a flavor or subpackage part
151.Po
152see
153.Xr packages-specs 7
154.Pc .
155.Ev SKIPDIR
156is handled by a
157.Ic case
158statement, and so can contain simple wildcards
159.Po
160see
161.Xr sh 1
162.Dq File name patterns
163.Pc ,
164e.g., SKIPDIR='editors/openoffice*' .
165.Pp
166The variable
167.Ev STARTDIR
168can hold the path to a starting directory.
169The recursion will skip all directories up to that package path.
170This can be used to resume a full build at some specific point without having
171to go through thousands of directories first.
172.Pp
173The variable
174.Ev STARTAFTER
175can hold the path to a starting directory.
176The recursion will skip all directories up to and including that package path.
177This can be used to resume a full build after some specific point without having
178to go through thousands of directories first.
179.Pp
180In case of failure in a subdirectory, the shell fragment held in
181.Ev REPORT_PROBLEM
182is executed.
183Default behavior is to call exit, but this can be overridden on the command
184line, e.g., to avoid stopping after each problem.
185.Bd -literal -offset indent
186$ make REPORT_PROBLEM=true
187.Ed
188.Pp
189If
190.Ev REPORT_PROBLEM_LOGFILE
191is non empty, then
192.Ev REPORT_PROBLEM
193will default to:
194.Bd -literal -offset indent
195echo $$subdir ($@) >>$${REPORT_PROBLEM_LOGFILE}
196.Ed
197.Pp
198That is, any failure will append the faulty directory name together
199with the target that failed to
200.Pa ${REPORT_PROBLEM_LOGFILE}
201and proceed.
202.Pp
203Some targets that do this are
204.Cm all , build , checksum , clean ,
205.Cm configure , extract , fake ,
206.Cm fetch , install , distclean ,
207.Cm deinstall , reinstall , package , prepare ,
208.Cm link-categories , unlink-categories ,
209.Cm describe , show , regress ,
210.Cm lib-depends-check , homepage-links , manpages-check ,
211.Cm license-check , all-dir-depends , build-dir-depends ,
212.Cm run-dir-depends
213and
214.Cm readmes .
215.Pp
216Target names starting with
217.Sq _
218are private to the ports infrastructure,
219should not be invoked directly, and are liable to change without notice.
220.Pp
221In the following list, each target will run the preceding targets
222in order automatically.
223That is,
224.Cm build
225will be run
226.Pq if necessary
227by
228.Cm install ,
229and so on all the way to
230.Cm fetch .
231In typical use, one will only run
232.Cm install
233explicitly (as normal user, with
234.Ev SUDO
235defined in
236.Pa /etc/mk.conf ) ,
237or
238.Cm build
239(as user), then
240.Cm install
241(as root).
242.Bl -tag -width configure
243.It Cm fetch
244Fetch all of the files needed to build this port from the site(s)
245listed in
246.Ev MASTER_SITES .
247See
248.Ev FETCH_CMD
249and
250.Ev MASTER_SITE_OVERRIDE .
251Use
252.Xr dpb 1
253with option
254.Fl F
255to quickly fetch distfiles for a subtree.
256.It Cm checksum
257Verify that the fetched distfile matches the one the port was tested against.
258Defining
259.Ev NO_CHECKSUM
260to
261.Dv Yes
262will skip this step.
263Sometimes, distfiles change without warning.
264The main
265.Ox
266mirror should still hold a copy of old distfiles, indexed by checksum.
267Using
268.Bd -literal -offset indent
269$ make checksum REFETCH=true
270.Ed
271.Pp
272will try to get a set of distfiles that match the recorded checksum.
273.It Cm prepare
274Install
275any build dependencies of the current port.
276Defining
277.Ev NO_DEPENDS
278to
279.Dv Yes
280will skip this step.
281.It Cm extract
282Expand the distfile into a work directory.
283.It Cm patch
284Apply any patches that are necessary for the port.
285.It Cm configure
286Configure the port.
287Some ports will ask questions during this stage.
288See
289.Ev INTERACTIVE
290and
291.Ev BATCH .
292.It Cm build
293Build the port.
294This is the same as calling the
295.Cm all
296target.
297.It Cm fake
298Pretend to install the port under a subdirectory of the work directory.
299.It Cm package
300Create a binary package from the fake installation.
301The package is a .tgz file that can be used to
302install the port with
303.Xr pkg_add 1 .
304.It Cm install
305Install the resulting package.
306.El
307.Pp
308The following targets are not run during the normal install process.
309.Bl -tag -width fetch-list
310.It Cm print-build-depends , print-run-depends
311Print an ordered list of all the compile and run dependencies.
312.It Cm clean
313Remove the expanded source code.
314This does not recurse to dependencies unless
315.Ev CLEANDEPENDS
316is defined to
317.Dv Yes .
318.It Cm distclean
319Remove the port's distfile(s).
320This does not recurse to dependencies.
321.It Cm regress
322Runs the ports regression tests.
323Usually needs a completed build.
324.It Cm reinstall
325Use this to restore a port after using
326.Xr pkg_delete 1 .
327.It Cm update
328Alternative target to
329.Cm install .
330Does not install new packages, but updates existing ones.
331.It Cm link-categories
332Populate the ports tree with symbolic links for each category the port
333belongs to.
334.It Cm unlink-categories
335Remove the symbolic links created by
336.Cm link-categories .
337.It Cm homepage-links
338creates an html list of links for each port
339.Ev HOMEPAGE .
340.El
341.Sh LOCK INFRASTRUCTURE
342The ports tree can be used concurrently for building several ports at the
343same time, thanks to a locking mechanism.
344By default, locks are stored under
345.Pa /tmp/portslocks .
346Defining
347.Ev LOCKDIR
348will point them elsewhere, or disable the mechanism if set to an empty value.
349.Pp
350All locks will be stored in
351.Pa ${LOCKDIR} .
352.Ev LOCK_CMD
353should be used to acquire a lock, and
354.Ev UNLOCK_CMD
355should be used to release it.
356.Pp
357Locks are named
358.Pa ${LOCKDIR}/${FULLPKGNAME}.lock ,
359or
360.Pa ${LOCKDIR}/${DISTFILE}.lock
361for distfiles fetching.
362.Pp
363The default values of
364.Ev LOCK_CMD
365and
366.Ev UNLOCK_CMD
367are appropriate for most uses.
368.Pp
369The locking protocol follows a big-lock model: each top-level target
370in a port directory will acquire the corresponding lock, complete its job,
371then release the lock, e.g., running
372.Bd -literal -offset indent
373$ make build
374.Ed
375.Pp
376will acquire the lock, run the port
377through
378.Cm fetch ,
379.Cm checksum ,
380.Cm extract ,
381.Cm patch ,
382.Cm configure ,
383.Cm build ,
384then release the lock.
385If dependencies are involved, they will invoke top-level targets in other
386directories, and thus acquire some other locks as well.
387.Pp
388The infrastructure contains some protection against acquiring the same lock
389twice, thus recursive locking is not needed for
390.Ev LOCK_CMD .
391.Pp
392Starting with
393.Ox 4.3 ,
394the infrastructure supports manual locking: the targets
395.Cm lock
396and
397.Cm unlock
398can be used to acquire and release individual locks.
399Both these targets output a shell command that must be used to update
400environment variables.
401Manual locking can be used to protect a directory against interference
402by an automated build job, while the user is looking at or modifying a
403given port.
404.Sh UPDATING PACKAGES
405Instead of deinstalling each package and rebuilding from scratch, the
406ports tree can be used to update installed packages.
407The
408.Cm update
409target will replace an installed package using
410.Xr pkg_add 1
411in replacement mode.
412If
413.Ev FORCE_UPDATE
414is set to
415.Dv Yes ,
416dependencies will also be updated first, and packages will always be updated,
417even if there is no difference between the old and the new packages.
418.Pp
419Updates use a mechanism similar to bulk cookies and deposit cookies in
420the
421.Ev UPDATE_COOKIES_DIR .
422See the next section for more details, since most of the fine points of
423bulk package building also apply to updates.
424.Pp
425There are bugs in the ports tree, most related to libtool, which make some
426updates prefer the already installed libraries instead of the newly built
427ones.
428This shows up as undefined references in libraries, in which case there
429is no choice but to proceed the old way: deinstall the offending package
430and everything built on top of it, build and install new packages.
431.Sh BULK PACKAGE BUILDING
432Building any significant number of packages from the ports tree should use
433.Xr dpb 1 ,
434a tool located inside the ports tree proper
435.Po
436normally as
437.Pa /usr/ports/infrastructure/bin/dpb
438.Pc .
439In particular, it can take advantage of machine clusters (same architecture
440and same installation), and of multi-core machines.
441.Pp
442A few remarks may save a lot of time:
443.Bl -bullet
444.It
445The default limits in
446.Xr login.conf 5
447are inappropriate for bulk builds.
448.Va maxproc , openfiles , datasize
449should be cranked way up, especially for parallel builds.
450For instance, a lot of C++-based ports will require a
451.Va datasize
452over 1G.
453.It
454Cluster builds should have shared
455.Ev PORTSDIR
456and local
457.Ev WRKOBJDIR .
458If possible, dedicated
459.Ev WRKOBJDIR
460partitions mounted
461.Sq noatime,async
462will help.
463.It
464As far as possible, the log directory should be local to the machine running
465.Xr dpb 1 .
466.It
467A full bulk will fetch over 20G of distfiles and create over 17G of packages.
468The largest work directories are about 10G each.
469.It
470Take notice of
471.Ev CHECKSUM_PACKAGES
472in
473.Xr bsd.port.mk 5 .
474This can be set to
475.Sq ftp
476during official package builds to compute partial sha256 checksum files.
477.Pp
478At the end of the build, just
479.Bd -literal -offset indent
480cd ${PORTSDIR}/packages/${MACHINE_ARCH}/cksums && cat * >sha256
481.Ed
482.El
483.Sh NETWORK CONFIGURATION
484The variables pertaining to network access have been marshalled into
485.Pa ${PORTSDIR}/infrastructure/templates/network.conf.template .
486.Pp
487To customize that setup, copy that file into
488.Pa ${PORTSDIR}/infrastructure/db/network.conf
489and edit it.
490.Bl -tag -width MASTER_SITES
491.It Ev MASTER_SITE_OPENBSD
492If set to
493.Dv Yes ,
494include the master
495.Ox
496site when fetching files.
497.It Ev MASTER_SITE_FREEBSD
498If set to
499.Dv Yes ,
500include the master
501.Fx
502site when fetching files.
503.It Ev MASTER_SITE_OVERRIDE
504Go to this site first for all files.
505.El
506.Sh FLAVORS
507The
508.Ox
509ports tree comes with a mechanism called
510.Ic FLAVORS .
511Thanks to this mechanism, users can select specific options provided by
512a given port.
513.Pp
514If a port is
515.Qq flavored ,
516there should be a terse description of available flavors in the
517.Pa pkg/DESCR
518file.
519.Pp
520For example, the
521.Pa misc/screen
522port comes with a flavor called
523.Ic static .
524This changes the building process so a statically compiled version of
525the program will be built.
526To avoid confusion with other packages or flavors,
527the package name will be extended with a dash-separated list of
528the selected flavors.
529.Pp
530In this instance, the corresponding package will be called
531.Ic screen-4.0.2-static .
532.Pp
533To see the flavors of a port, use the
534.Cm show
535target:
536.Bd -literal -offset indent
537$ make show=FLAVORS
538.Ed
539.Pp
540To build a port with a specific flavor, just pass
541.Ev FLAVOR
542in the environment of the
543.Xr make 1
544command:
545.Bd -literal -offset indent
546$ env FLAVOR="static" make package
547.Ed
548.Pp
549and of course, use the same settings for the subsequent invocations of make:
550.Bd -literal -offset indent
551$ env FLAVOR="static" make install
552$ env FLAVOR="static" make clean
553.Ed
554.Pp
555More than one flavor may be specified:
556.Bd -literal -offset indent
557$ cd /usr/ports/mail/exim
558$ env FLAVOR="mysql ldap" make package
559.Ed
560.Pp
561Specifying a flavor that does not exist is an error.
562Additionally, some ports impose some further restrictions on flavor
563combinations, when such combinations do not make sense.
564.Pp
565Lots of ports can be built without X11 requirement and accordingly
566have a
567.Ic no_x11
568flavor.
569.Pp
570Flavor settings are not propagated to dependencies.
571If a specific combination is needed, careful hand-building of the
572required set of packages is still necessary.
573.Sh MULTI_PACKAGES
574The
575.Ox
576ports tree comes with a mechanism called
577.Ic MULTI_PACKAGES .
578This mechanism is used when a larger package is broken down into
579several smaller components referred to as subpackages.
580.Pp
581If a port is
582.Qq subpackaged ,
583each subpackage will have a corresponding description in the
584.Pa pkg/DESCR-subpackage
585file.
586.Pp
587For example, the
588.Pa databases/mariadb
589port comes with subpackages called
590.Ic -main ,
591.Ic -tests
592and
593.Ic -server .
594.Pp
595In this instance, the build will yield multiple packages, one
596corresponding to each subpackage.
597In the case of our mariadb example,
598the packages will be called
599.Ic mariadb-client-<version> ,
600.Ic mariadb-tests-<version> ,
601and
602.Ic mariadb-server-<version> .
603.Pp
604To install/deinstall a specific subpackage of a port, you may
605.Xr pkg_add 1
606them manually, or alternatively, you may set
607.Ev SUBPACKAGE
608in the environment of the
609.Xr make 1
610command during the install/deinstall phase:
611.Bd -literal -offset indent
612$ env SUBPACKAGE="-server" make install
613$ env SUBPACKAGE="-server" make deinstall
614.Ed
615.Sh PORT VARIABLES
616These can be changed in the environment, or in
617.Pa /etc/mk.conf
618for persistence.
619They can also be set on make's command line, e.g.,
620.Ic make VAR_FOO Ns = Ns Dv foo
621.Pp
622Boolean variables should be set to
623.Dv Yes
624instead of simply being defined, for uniformity and future compatibility.
625.Pp
626Variable names starting with
627.Sq _
628are private to the ports infrastructure,
629should not be changed by the user, and are liable to change without notice.
630.Bl -tag -width MASTER_SITES
631.It Ev PORTSDIR
632Location of the ports tree
633(usually
634.Pa /usr/ports ) .
635.It Ev DISTDIR
636Where to find/put distfiles, normally
637.Pa ${PORTSDIR}/distfiles .
638.It Ev PACKAGE_REPOSITORY
639Used only for the
640.Cm package
641target; the base directory for the packages tree, normally
642.Pa ${PORTSDIR}/packages .
643If this directory exists, the package tree will be (partially) constructed.
644.It Ev BULK_COOKIES_DIR
645During bulk package building, used to store cookies for already built
646packages to avoid rebuilding them, since the actual
647working directory will already have been cleaned out.
648Defaults to
649.Pa ${PORTSDIR}/bulk/${MACHINE_ARCH} .
650.It Ev UPDATE_COOKIES_DIR
651Used to store cookies for package updates, defaults to
652.Pa ${PORTSDIR}/update/${MACHINE_ARCH} .
653If set to empty, it will revert to a file under
654.Pa ${WRKDIR} .
655.It Ev LOCALBASE
656Where to install things in general
657(usually
658.Pa /usr/local ) .
659.It Ev MASTER_SITES
660Primary sites for distribution files if not found locally.
661.It Ev CLEANDEPENDS
662If set to
663.Dv Yes ,
664let
665.Cm clean
666recurse to dependencies.
667.It Ev FETCH_CMD
668Command to use to fetch files.
669Normally
670.Xr ftp 1 .
671.It Ev FETCH_PACKAGES
672If set to
673.Dv Yes ,
674try to use
675.Xr pkg_add 1
676to install the missing packages from
677.Ev PKG_PATH .
678.It Ev PATCH_DEBUG
679If defined, display verbose output when applying each patch.
680.It Ev INTERACTIVE
681If defined, only operate on a port if it requires interaction.
682.It Ev BATCH
683If defined, only operate on a port if it can be installed 100% automatically.
684.El
685.Sh USING A READ-ONLY PORTS TREE
686Select read-write partition(s) that can accommodate working directories, the
687distfiles repository, and the built packages.
688Set
689.Ev WRKOBJDIR ,
690.Ev PACKAGE_REPOSITORY ,
691.Ev BULK_COOKIES_DIR ,
692.Ev UPDATE_COOKIES_DIR ,
693.Ev DISTDIR ,
694and
695.Ev PLIST_DB
696in
697.Pa /etc/mk.conf
698accordingly.
699.Sh FILES
700.Bl -tag -width /usr/ports/xxxxxxxx -compact
701.It Pa /usr/ports
702The default ports directory.
703.It Pa /usr/ports/Makefile
704Ports master Makefile.
705.It Pa /usr/ports/INDEX
706Ports index.
707.It Pa /usr/ports/infrastructure/mk/bsd.port.mk
708The ports main engine.
709.It Pa /usr/ports/infrastructure/templates/network.conf.template
710Network configuration defaults.
711.It Pa /usr/ports/infrastructure/db/network.conf
712Local network configuration.
713.It Pa /usr/ports/infrastructure/db/user.list
714List of users and groups created by ports.
715.El
716.Sh SEE ALSO
717.Xr dpb 1 ,
718.Xr make 1 ,
719.Xr pkg_add 1 ,
720.Xr pkg_create 1 ,
721.Xr pkg_delete 1 ,
722.Xr pkg_info 1 ,
723.Xr bsd.port.mk 5 ,
724.Xr port-modules 5 ,
725.Xr mirroring-ports 7 ,
726.Xr packages 7
727.Pp
728The
729.Ox
730Ports System:
731.Lk https://www.openbsd.org/faq/faq15.html#Ports
732.Pp
733The
734.Ox
735Porter's Handbook:
736.Lk https://www.openbsd.org/faq/ports/
737.Sh HISTORY
738.Nm The Ports Collection
739appeared in
740.Fx 1.0 .
741It was introduced in
742.Ox
743by Ejovi Nuwere, with much initial effort by Angelos D. Keromytis.
744Maintenance passed then to Marco S. Hyman, and then to Christopher Turan.
745It is currently managed by Marc Espie, Christian Weisgerber,
746along with a host of others found at
747.Mt ports@openbsd.org .
748.Sh AUTHORS
749This man page was originated by
750.An David O'Brien ,
751from the
752.Fx
753project.
754