xref: /openbsd/share/man/man7/ports.7 (revision 5dea098c)
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.132 2023/09/07 17:19:19 espie Exp $
27.\" $FreeBSD: ports.7,v 1.7 1998/06/23 04:38:50 hoek Exp $
28.\"
29.Dd $Mdocdate: September 7 2023 $
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 HTTP mirrors.
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 HTTP, 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
63.Lk https://www.openbsd.org/faq/ports/ports.html "Working with Ports" .
64For information about creating new ports, see
65.Lk https://www.openbsd.org/faq/ports/ "The OpenBSD Porter's Handbook" .
66.Pp
67For a detailed description of the build process, see
68.Xr bsd.port.mk 5 .
69.Sh PORTS MASTER MAKEFILE
70The ports master Makefile, normally located in
71.Pa /usr/ports/Makefile
72(but see
73.Ev PORTSDIR
74below)
75offers a few deprecated targets for the time being.
76.Bl -tag -width print-index
77.It Cm print-index
78display the contents of the index in a
79.Sq user-friendly
80way,
81.It Cm search
82invoked with a key, e.g.,
83.Ic make search key=foo ,
84retrieve information relevant to a given port (obsolescent).
85.El
86.Pp
87Starting in
88.Ox 4.0 ,
89there is a port,
90.Pa databases/sqlports ,
91that builds an sqlite database containing most information relevant to
92every port in the ports tree.
93This database can be searched using any tool able to manipulate such
94databases, for instance sqlitebrowser, or a script language with an
95sqlite interface, e.g., perl, python, ocaml, lua, php.
96.Pp
97All static index generating information has now been superseded by the
98.Pa sqlports ,
99.Pa portslist
100or
101.Pa pkglocatedb
102packages, which contain
103similar information to the old INDEX file, but are frequently updated.
104See
105.Pa databases/sqlports
106.Pa databases/pkglocatedb
107and
108.Xr pkg_mklocatedb 1
109for details.
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 portslist
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 show , regress ,
209.Cm lib-depends-check ,
210.Cm license-check , all-dir-depends , build-dir-depends ,
211.Cm run-dir-depends
212and
213.Cm generate-readmes .
214.Pp
215Target names starting with
216.Sq _
217are private to the ports infrastructure,
218should not be invoked directly, and are liable to change without notice.
219.Pp
220In the following list, each target will run the preceding targets
221in order automatically.
222That is,
223.Cm build
224will be run
225.Pq if necessary
226by
227.Cm install ,
228and so on all the way to
229.Cm fetch .
230In typical use, one will only run
231.Cm install
232explicitly (as normal user, with
233.Ev SUDO
234defined in
235.Pa /etc/mk.conf ) ,
236or
237.Cm build
238(as user), then
239.Cm install
240(as root).
241.Bl -tag -width configure
242.It Cm fetch
243Fetch all of the files needed to build this port from the site(s)
244listed in
245.Ev SITES .
246See
247.Ev FETCH_CMD .
248Use
249.Xr dpb 1
250with option
251.Fl F
252to quickly fetch distfiles for a subtree.
253.It Cm checksum
254Verify that the fetched distfile matches the one the port was tested against.
255Defining
256.Ev NO_CHECKSUM
257to
258.Dv Yes
259will skip this step.
260Sometimes, distfiles change without warning.
261The main
262.Ox
263mirror should still hold a copy of old distfiles, indexed by checksum.
264Using
265.Bd -literal -offset indent
266$ make checksum REFETCH=true
267.Ed
268.Pp
269will try to get a set of distfiles that match the recorded checksum.
270.It Cm prepare
271Install
272any build dependencies of the current port.
273Defining
274.Ev NO_DEPENDS
275to
276.Dv Yes
277will skip this step.
278.It Cm extract
279Expand the distfile into a work directory.
280.It Cm patch
281Apply any patches that are necessary for the port.
282.It Cm gen
283Recreate configure machinery if needed, mainly used by GNU based software
284that wants autogen/autoconf/automake.
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 generate-readmes
300Create READMEs and rc scripts under the fake subdirectory.
301.It Cm package
302Create a binary package from the fake installation.
303The package is a .tgz file that can be used to
304install the port with
305.Xr pkg_add 1 .
306.It Cm install
307Install the resulting package.
308.El
309.Pp
310The following targets are not run during the normal install process
311.Po
312exception
313.Cm clean
314is run for dependencies with the default settings of
315.Ev BULK Ns = Ns Dv Auto
316.Pc .
317.Bl -tag -width fetch-list
318.It Cm print-build-depends , print-run-depends
319Print an ordered list of all the compile and run dependencies.
320.It Cm clean
321Remove the expanded source code.
322This does not recurse to dependencies unless
323.Ev CLEANDEPENDS
324is defined to
325.Dv Yes .
326.It Cm distclean
327Remove the port's distfile(s).
328This does not recurse to dependencies.
329.It Cm regress
330Runs the ports regression tests.
331Usually needs a completed build.
332.It Cm reinstall
333Use this to restore a port after using
334.Xr pkg_delete 1 .
335.It Cm update
336Alternative target to
337.Cm install .
338Does not install new packages, but updates existing ones.
339.El
340.Sh LOCK INFRASTRUCTURE
341The ports tree can be used concurrently for building several ports at the
342same time, thanks to a locking mechanism.
343By default, locks are stored under
344.Pa /tmp/portslocks .
345Defining
346.Ev LOCKDIR
347will point them elsewhere, or disable the mechanism if set to an empty value.
348.Pp
349All locks will be stored in
350.Pa ${LOCKDIR} .
351.Ev LOCK_CMD
352should be used to acquire a lock, and
353.Ev UNLOCK_CMD
354should be used to release it.
355.Pp
356Locks are named
357.Pa ${LOCKDIR}/${FULLPKGNAME}.lock ,
358or
359.Pa ${LOCKDIR}/${DISTFILE}.lock
360for distfiles fetching.
361.Pp
362The default values of
363.Ev LOCK_CMD
364and
365.Ev UNLOCK_CMD
366are appropriate for most uses.
367.Pp
368The locking protocol follows a big-lock model: each top-level target
369in a port directory will acquire the corresponding lock, complete its job,
370then release the lock, e.g., running
371.Bd -literal -offset indent
372$ make build
373.Ed
374.Pp
375will acquire the lock, run the port
376through
377.Cm fetch ,
378.Cm checksum ,
379.Cm extract ,
380.Cm patch ,
381.Cm configure ,
382.Cm build ,
383then release the lock.
384If dependencies are involved, they will invoke top-level targets in other
385directories, and thus acquire some other locks as well.
386.Pp
387The infrastructure contains some protection against acquiring the same lock
388twice, thus recursive locking is not needed for
389.Ev LOCK_CMD .
390.Pp
391Starting with
392.Ox 4.3 ,
393the infrastructure supports manual locking: the targets
394.Cm lock
395and
396.Cm unlock
397can be used to acquire and release individual locks.
398Both these targets output a shell command that must be used to update
399environment variables.
400Manual locking can be used to protect a directory against interference
401by an automated build job, while the user is looking at or modifying a
402given port.
403.Sh UPDATING PACKAGES
404Instead of deinstalling each package and rebuilding from scratch, the
405ports tree can be used to update installed packages.
406The
407.Cm update
408target will replace an installed package using
409.Xr pkg_add 1
410in replacement mode.
411If
412.Ev FORCE_UPDATE
413is set to
414.Dv Yes ,
415dependencies will also be updated first, and packages will always be updated,
416even if there is no difference between the old and the new packages.
417.Pp
418Updates use a mechanism similar to bulk cookies and deposit cookies in
419the
420.Ev UPDATE_COOKIES_DIR .
421See the next section for more details, since most of the fine points of
422bulk package building also apply to updates.
423.Pp
424However, also note that
425.Li make update
426is not guaranteed to work, see
427.Sx CAVEATS
428below.
429.Sh BULK PACKAGE BUILDING
430Building any significant number of packages from the ports tree should use
431.Xr dpb 1 ,
432a tool located inside the ports tree proper
433.Po
434normally as
435.Pa /usr/ports/infrastructure/bin/dpb
436.Pc .
437In particular, it can take advantage of machine clusters (same architecture
438and same installation), and of multi-core machines.
439.Pp
440For more detailed information, see
441.Xr bulk 8 .
442.Sh FLAVORS
443The
444.Ox
445ports tree comes with a mechanism called
446.Ic FLAVORS .
447Thanks to this mechanism, users can select specific options provided by
448a given port.
449.Pp
450If a port is
451.Qq flavored ,
452there should be a terse description of available flavors in the
453.Pa pkg/DESCR
454file.
455.Pp
456For example, the
457.Pa misc/screen
458port comes with a flavor called
459.Ic static .
460This changes the building process so a statically compiled version of
461the program will be built.
462To avoid confusion with other packages or flavors,
463the package name will be extended with a dash-separated list of
464the selected flavors.
465.Pp
466In this instance, the corresponding package will be called
467.Ic screen-4.0.2-static .
468.Pp
469To see the flavors of a port, use the
470.Cm show
471target:
472.Bd -literal -offset indent
473$ make show=FLAVORS
474.Ed
475.Pp
476To build a port with a specific flavor, just pass
477.Ev FLAVOR
478in the environment of the
479.Xr make 1
480command:
481.Bd -literal -offset indent
482$ env FLAVOR="static" make package
483.Ed
484.Pp
485and of course, use the same settings for the subsequent invocations of make:
486.Bd -literal -offset indent
487$ env FLAVOR="static" make install
488$ env FLAVOR="static" make clean
489.Ed
490.Pp
491More than one flavor may be specified:
492.Bd -literal -offset indent
493$ cd /usr/ports/mail/exim
494$ env FLAVOR="mysql ldap" make package
495.Ed
496.Pp
497Specifying a flavor that does not exist is an error.
498Additionally, some ports impose some further restrictions on flavor
499combinations, when such combinations do not make sense.
500.Pp
501Lots of ports can be built without X11 requirement and accordingly
502have a
503.Ic no_x11
504flavor.
505.Pp
506Flavor settings are not propagated to dependencies.
507If a specific combination is needed, careful hand-building of the
508required set of packages is still necessary.
509.Sh MULTI_PACKAGES
510The
511.Ox
512ports tree comes with a mechanism called
513.Ic MULTI_PACKAGES .
514This mechanism is used when a larger package is broken down into
515several smaller components referred to as subpackages.
516.Pp
517If a port is
518.Qq subpackaged ,
519each subpackage will have a corresponding description in the
520.Pa pkg/DESCR-subpackage
521file.
522.Pp
523For example, the
524.Pa databases/mariadb
525port comes with subpackages called
526.Ic -main ,
527.Ic -tests
528and
529.Ic -server .
530.Pp
531In this instance, the build will yield multiple packages, one
532corresponding to each subpackage.
533In the case of our mariadb example,
534the packages will be called
535.Ic mariadb-client-<version> ,
536.Ic mariadb-tests-<version> ,
537and
538.Ic mariadb-server-<version> .
539.Pp
540To install/deinstall a specific subpackage of a port, you may
541.Xr pkg_add 1
542them manually, or alternatively, you may set
543.Ev SUBPACKAGE
544in the environment of the
545.Xr make 1
546command during the install/deinstall phase:
547.Bd -literal -offset indent
548$ env SUBPACKAGE="-server" make install
549$ env SUBPACKAGE="-server" make deinstall
550.Ed
551.Sh PORT VARIABLES
552These can be changed in the environment, or in
553.Pa /etc/mk.conf
554for persistence.
555They can also be set on make's command line, e.g.,
556.Ic make VAR_FOO Ns = Ns Dv foo
557.Pp
558Boolean variables should be set to
559.Dv Yes
560instead of simply being defined, for uniformity and future compatibility.
561.Pp
562Variable names starting with
563.Sq _
564are private to the ports infrastructure,
565should not be changed by the user, and are liable to change without notice.
566.Bl -tag -width PORTS_PRIVSEP
567.It Ev PORTS_PRIVSEP
568If set to
569.Sq Yes ,
570all operations will happen as restricted users
571.Ar _pfetch
572and
573.Ar _pbuild .
574.It Ev PORTSDIR
575Location of the ports tree
576(usually
577.Pa /usr/ports ) .
578.It Ev DISTDIR
579Where to find/put distfiles, normally
580.Pa ${PORTSDIR}/distfiles .
581.It Ev PACKAGE_REPOSITORY
582Used only for the
583.Cm package
584target; the base directory for the packages tree, normally
585.Pa ${PORTSDIR}/packages .
586If this directory exists, the package tree will be (partially) constructed.
587.It Ev BULK_COOKIES_DIR
588During bulk package building, used to store cookies for already built
589packages to avoid rebuilding them, since the actual
590working directory will already have been cleaned out.
591Defaults to
592.Pa ${PORTSDIR}/bulk/${MACHINE_ARCH} .
593.It Ev UPDATE_COOKIES_DIR
594Used to store cookies for package updates, defaults to
595.Pa ${PORTSDIR}/update/${MACHINE_ARCH} .
596If set to empty, it will revert to a file under
597.Pa ${WRKDIR} .
598.It Ev LOCALBASE
599Where to install things in general
600(usually
601.Pa /usr/local ) .
602.It Ev SITES
603Primary sites for distribution files if not found locally.
604.It Ev CLEANDEPENDS
605If set to
606.Dv Yes ,
607let
608.Cm clean
609recurse to dependencies.
610.It Ev FETCH_CMD
611Command to use to fetch files.
612Normally
613.Xr ftp 1 .
614.It Ev FETCH_PACKAGES
615If set,
616try to use as options to
617.Xr pkg_add 1
618to install missing packages from
619.Ev PKG_PATH .
620.Xr bsd.port.mk 5
621does not set
622.Ev FETCH_PACKAGES ,
623so even an empty value amounts to setting the variable.
624.Pp
625For instance, to run
626.Xr pkg_add 1
627with default options :
628.Bd -literal -offset indent
629make FETCH_PACKAGES=
630.Ed
631.Pp
632or, to use the snapshots directory during the final beta period:
633.Bd -literal -offset indent
634make FETCH_PACKAGES=-Dsnap
635.Ed
636.It Ev PATCH_DEBUG
637If defined, display verbose output when applying each patch.
638.It Ev INTERACTIVE
639If defined, only operate on a port if it requires interaction.
640.It Ev BATCH
641If defined, only operate on a port if it can be installed 100% automatically.
642.El
643.Sh USING A READ-ONLY PORTS TREE
644Select read-write partition(s) that can accommodate working directories, the
645distfiles repository, and the built packages.
646Set
647.Ev WRKOBJDIR ,
648.Ev PACKAGE_REPOSITORY ,
649.Ev BULK_COOKIES_DIR ,
650.Ev UPDATE_COOKIES_DIR ,
651.Ev DISTDIR ,
652and
653.Ev PLIST_REPOSITORY
654in
655.Pa /etc/mk.conf
656accordingly.
657.Sh FILES
658.Bl -tag -width /usr/ports/xxxxxxxx -compact
659.It Pa /usr/ports
660The default ports directory.
661.It Pa /usr/ports/Makefile
662Ports master Makefile.
663.It Pa /usr/local/share/ports-INDEX
664Ports index, part of the
665.Pa portlist
666package.
667.It Pa /usr/ports/pobj
668Build directories.
669A number of insecurely coded ports require a dedicated file system with the
670.Cm wxallowed
671.Xr mount 8
672option.
673.It Pa /usr/ports/infrastructure/mk/bsd.port.mk
674The ports main engine.
675.It Pa /usr/ports/infrastructure/db/network.conf
676Network configuration.
677.It Pa /usr/ports/infrastructure/db/user.list
678List of users and groups created by ports.
679.El
680.Sh SEE ALSO
681.Xr dpb 1 ,
682.Xr make 1 ,
683.Xr pkg_add 1 ,
684.Xr pkg_create 1 ,
685.Xr pkg_delete 1 ,
686.Xr pkg_info 1 ,
687.Xr bsd.port.mk 5 ,
688.Xr port-modules 5 ,
689.Xr mirroring-ports 7 ,
690.Xr packages 7
691.Pp
692The
693.Ox
694Ports System:
695.Lk https://www.openbsd.org/faq/ports/ports.html
696.Pp
697The
698.Ox
699Porter's Handbook:
700.Lk https://www.openbsd.org/faq/ports/
701.Sh HISTORY
702.Nm The Ports Collection
703appeared in
704.Fx 1.0 .
705It was introduced in
706.Ox
707by Ejovi Nuwere, with much initial effort by Angelos D. Keromytis.
708Maintenance passed then to Marco S. Hyman, and then to Christopher Turan.
709It is currently managed by Marc Espie, Christian Weisgerber,
710along with a host of others found at
711.Mt ports@openbsd.org .
712.Sh AUTHORS
713This man page was originated by
714.An David O'Brien ,
715from the
716.Fx
717project.
718.Sh CAVEATS
719Building a new version of an already installed package is not guaranteed
720to work.
721.Pp
722The safer way would be to create a sandbox for building the updated port
723using
724.Xr proot 1
725.Po see also
726.Xr bulk 8
727.Pc ,
728and then update the installed package.
729.Pp
730Specifically: most software expects building in a virgin environment
731with only the required dependency.
732As a result, lots of time, libraries and headers under
733.Pa /usr/local
734will be favored over the currently building version.
735