Annotation of htdocs/docs/pkgsrc/pkgsrc.txt, revision 1.232

1.1       dsieger     1: The pkgsrc guide
                      2: 
                      3: Documentation on the NetBSD packages system
                      4: 
                      5: Alistair Crooks
                      6: 
                      7: <agc@NetBSD.org>
                      8: 
                      9: Hubert Feyrer
                     10: 
                     11: <hubertf@NetBSD.org>
                     12: 
                     13: The pkgsrc Developers
                     14: 
1.231     jnemeth    15: Copyright   1994-2023 The NetBSD Foundation, Inc
1.1       dsieger    16: 
1.231     jnemeth    17: $NetBSD: pkgsrc.xml,v 1.42 2023/01/02 05:45:23 jnemeth Exp $
1.1       dsieger    18: 
                     19: Abstract
                     20: 
                     21: pkgsrc is a centralized package management system for Unix-like operating
                     22: systems. This guide provides information for users and developers of pkgsrc. It
                     23: covers installation of binary and source packages, creation of binary and
                     24: source packages and a high-level overview about the infrastructure.
                     25: 
                     26: -------------------------------------------------------------------------------
                     27: 
                     28: Table of Contents
                     29: 
                     30: 1. What is pkgsrc?
                     31:     1.1. Introduction
                     32:         1.1.1. Why pkgsrc?
                     33:         1.1.2. Supported platforms
                     34:     1.2. Overview
                     35:     1.3. Terminology
                     36:         1.3.1. Roles involved in pkgsrc
                     37:     1.4. Typography
                     38: I. The pkgsrc user's guide
1.154     rillig     39:     2. Getting help
                     40:     3. Where to get pkgsrc and how to keep it up-to-date
                     41:         3.1. Getting pkgsrc for the first time
                     42:             3.1.1. As tar archive
                     43:             3.1.2. Via anonymous CVS
                     44:         3.2. Keeping pkgsrc up-to-date
                     45:             3.2.1. Via tar files
                     46:             3.2.2. Via CVS
                     47:     4. Using pkgsrc on systems other than NetBSD
                     48:         4.1. Binary distribution
                     49:         4.2. Bootstrapping pkgsrc
                     50:     5. Using pkgsrc
                     51:         5.1. Using binary packages
                     52:             5.1.1. Finding binary packages
                     53:             5.1.2. Installing binary packages
1.202     nia        54:             5.1.3. Updating packages
                     55:             5.1.4. Deinstalling packages
                     56:             5.1.5. Getting information about installed packages
                     57:             5.1.6. Checking for security vulnerabilities in installed packages
                     58:             5.1.7. Finding if newer versions of your installed packages are in
1.232   ! gutterid   59:             pkgsrc
1.202     nia        60:             5.1.8. Other administrative functions
1.154     rillig     61:         5.2. Building packages from source
                     62:             5.2.1. Requirements
                     63:             5.2.2. Fetching distfiles
                     64:             5.2.3. How to build and install
                     65:     6. Configuring pkgsrc
                     66:         6.1. General configuration
                     67:         6.2. Variables affecting the build process
                     68:         6.3. Variables affecting the installation process
                     69:         6.4. Selecting and configuring the compiler
                     70:             6.4.1. Selecting the compiler
                     71:             6.4.2. Additional flags to the compiler (CFLAGS)
                     72:             6.4.3. Additional flags to the linker (LDFLAGS)
                     73:         6.5. Developer/advanced settings
                     74:         6.6. Selecting Build Options
                     75:     7. Creating binary packages
                     76:         7.1. Building a single binary package
                     77:         7.2. Settings for creation of binary packages
                     78:     8. Creating binary packages for everything in pkgsrc (bulk builds)
                     79:         8.1. Preparations
1.180     rillig     80:         8.2. Running a bulk build
1.154     rillig     81:             8.2.1. Configuration
                     82:         8.3. Requirements of a full bulk build
1.178     rillig     83:         8.4. Bulk build variants
1.179     rillig     84:             8.4.1. Detect unknown configure options
                     85:             8.4.2. Detect classes of bugs by forcing compiler warnings
1.181     rillig     86:             8.4.3. Force compiler options only in the build phase
                     87:             8.4.4. Use custom directories
                     88:             8.4.5. Turn warnings into errors
                     89:             8.4.6. Reject packages for which pkglint reports errors
                     90:             8.4.7. Reject packages that contain forbidden strings
                     91:             8.4.8. Reject packages whose self-test fails
                     92:             8.4.9. Reject packages that use undefined shell variables
                     93:             8.4.10. Turn off verbose logging
1.178     rillig     94:         8.5. Creating a multiple CD-ROM packages collection
                     95:             8.5.1. Example of cdpack
1.154     rillig     96:     9. Directory layout of the installed files
                     97:         9.1. File system layout in ${LOCALBASE}
                     98:         9.2. File system layout in ${VARBASE}
                     99:     10. Frequently Asked Questions
                    100:         10.1. Are there any mailing lists for pkg-related discussion?
                    101:         10.2. Utilities for package management (pkgtools)
                    102:         10.3. How to use pkgsrc as non-root
                    103:         10.4. How to resume transfers when fetching distfiles?
                    104:         10.5. How can I install/use modular X.org from pkgsrc?
                    105:         10.6. How to fetch files from behind a firewall
                    106:         10.7. How to fetch files from HTTPS sites
                    107:         10.8. How do I tell make fetch to do passive FTP?
                    108:         10.9. How to fetch all distfiles at once
                    109:         10.10. What does "Don't know how to make /usr/share/tmac/tmac.andoc"
1.232   ! gutterid  110:         mean?
1.154     rillig    111:         10.11. What does "Could not find bsd.own.mk" mean?
1.221     nia       112:         10.12. Using 'sudo' or `priv` with pkgsrc
1.154     rillig    113:         10.13. How do I change the location of configuration files?
                    114:         10.14. Automated security checks
                    115:         10.15. Why do some packages ignore my CFLAGS?
                    116:         10.16. A package does not build. What shall I do?
                    117:         10.17. What does "Makefile appears to contain unresolved cvs/rcs/???
1.232   ! gutterid  118:         merge conflicts" mean?
1.1       dsieger   119: II. The pkgsrc developer's guide
1.154     rillig    120:     11. Getting help
1.184     rillig    121:     12. Package components - files, directories and contents
                    122:         12.1. Makefile
                    123:         12.2. distinfo
                    124:         12.3. patches/*
                    125:             12.3.1. Structure of a single patch file
                    126:             12.3.2. Creating patch files
                    127:             12.3.3. Sources where the patch files come from
                    128:             12.3.4. Patching guidelines
                    129:             12.3.5. Feedback to the author
                    130:         12.4. Other mandatory files
                    131:         12.5. Optional files
                    132:             12.5.1. Files affecting the binary package
                    133:             12.5.2. Files affecting the build process
                    134:             12.5.3. Files affecting nothing at all
                    135:         12.6. work*
                    136:         12.7. files/*
                    137:     13. The build process
                    138:         13.1. Introduction
                    139:         13.2. Program location
                    140:         13.3. Directories used during the build process
                    141:         13.4. Running a phase
                    142:         13.5. The fetch phase
                    143:             13.5.1. What to fetch and where to get it from
                    144:             13.5.2. How are the files fetched?
                    145:         13.6. The checksum phase
                    146:         13.7. The extract phase
                    147:         13.8. The patch phase
                    148:         13.9. The tools phase
                    149:         13.10. The wrapper phase
                    150:         13.11. The configure phase
                    151:         13.12. The build phase
                    152:         13.13. The test phase
                    153:         13.14. The install phase
                    154:         13.15. The package phase
                    155:         13.16. Cleaning up
                    156:         13.17. Other helpful targets
                    157:     14. Creating a new pkgsrc package from scratch
                    158:         14.1. Common types of packages
1.219     nia       159:             14.1.1. Python modules and programs
                    160:             14.1.2. R packages
                    161:             14.1.3. TeXlive packages
1.184     rillig    162:         14.2. Examples
                    163:             14.2.1. How the www/nvu package came into pkgsrc
                    164:     15. Programming in Makefiles
                    165:         15.1. Caveats
                    166:         15.2. Makefile variables
                    167:             15.2.1. Naming conventions
                    168:         15.3. Code snippets
                    169:             15.3.1. Adding things to a list
                    170:             15.3.2. Echoing a string exactly as-is
                    171:             15.3.3. Passing CFLAGS to GNU configure scripts
                    172:             15.3.4. Handling possibly empty variables
1.229     gutterid  173:             15.3.5. Testing yes/no variables in conditions
1.184     rillig    174:     16. Options handling
                    175:         16.1. Global default options
                    176:         16.2. Converting packages to use bsd.options.mk
                    177:         16.3. Option Names
                    178:         16.4. Determining the options of dependencies
                    179:     17. Tools needed for building or running
                    180:         17.1. Tools for pkgsrc builds
                    181:         17.2. Tools needed by packages
                    182:         17.3. Tools provided by platforms
                    183:     18. Buildlink methodology
                    184:         18.1. Converting packages to use buildlink3
                    185:         18.2. Writing buildlink3.mk files
                    186:             18.2.1. Anatomy of a buildlink3.mk file
                    187:             18.2.2. Updating BUILDLINK_API_DEPENDS.pkg and
1.232   ! gutterid  188:             BUILDLINK_ABI_DEPENDS.pkg in buildlink3.mk files
1.184     rillig    189:         18.3. Writing builtin.mk files
                    190:             18.3.1. Anatomy of a builtin.mk file
                    191:             18.3.2. Global preferences for native or pkgsrc software
                    192:     19. PLIST issues
                    193:         19.1. RCS ID
                    194:         19.2. Semi-automatic PLIST generation
                    195:         19.3. Tweaking output of make print-PLIST
                    196:         19.4. Variable substitution in PLIST
                    197:         19.5. Man page compression
                    198:         19.6. Changing PLIST source with PLIST_SRC
                    199:         19.7. Platform-specific and differing PLISTs
                    200:         19.8. Build-specific PLISTs
                    201:         19.9. Sharing directories between packages
                    202:     20. The pkginstall framework
                    203:         20.1. Files and directories outside the installation prefix
                    204:             20.1.1. Directory manipulation
                    205:             20.1.2. File manipulation
                    206:         20.2. Configuration files
                    207:             20.2.1. How PKG_SYSCONFDIR is set
                    208:             20.2.2. Telling the software where configuration files are
                    209:             20.2.3. Patching installations
                    210:             20.2.4. Disabling handling of configuration files
                    211:         20.3. System startup scripts
                    212:             20.3.1. Disabling handling of system startup scripts
                    213:         20.4. System users and groups
                    214:         20.5. System shells
                    215:             20.5.1. Disabling shell registration
                    216:         20.6. Fonts
                    217:             20.6.1. Disabling automatic update of the fonts databases
1.154     rillig    218:     21. Making your package work
                    219:         21.1. General operation
                    220:             21.1.1. How to pull in user-settable variables from mk.conf
                    221:             21.1.2. User interaction
                    222:             21.1.3. Handling licenses
                    223:             21.1.4. Restricted packages
                    224:             21.1.5. Handling dependencies
                    225:             21.1.6. Handling conflicts with other packages
                    226:             21.1.7. Packages that cannot or should not be built
                    227:             21.1.8. Packages which should not be deleted, once installed
                    228:             21.1.9. Handling packages with security problems
                    229:             21.1.10. How to handle incrementing versions when fixing an
1.232   ! gutterid  230:             existing package
1.154     rillig    231:             21.1.11. Substituting variable text in the package files (the SUBST
1.232   ! gutterid  232:             framework)
1.154     rillig    233:         21.2. The fetch phase
                    234:             21.2.1. Packages whose distfiles aren't available for plain
1.232   ! gutterid  235:             downloading
1.154     rillig    236:             21.2.2. How to handle modified distfiles with the 'old' name
                    237:             21.2.3. Packages hosted on github.com
                    238:         21.3. The configure phase
                    239:             21.3.1. Shared libraries - libtool
                    240:             21.3.2. Using libtool on GNU packages that already support libtool
                    241:             21.3.3. GNU Autoconf/Automake
1.223     nia       242:             21.3.4. Meson / ninja
1.154     rillig    243:         21.4. Programming languages
                    244:             21.4.1. C, C++, and Fortran
                    245:             21.4.2. Java
1.205     wiz       246:             21.4.3. Go
1.223     nia       247:             21.4.4. Rust
                    248:             21.4.5. Packages containing Perl scripts
                    249:             21.4.6. Packages containing shell scripts
                    250:             21.4.7. Other programming languages
1.154     rillig    251:         21.5. The build phase
                    252:             21.5.1. Compiling C and C++ code conditionally
                    253:             21.5.2. How to handle compiler bugs
1.172     rillig    254:             21.5.3. No such file or directory
                    255:             21.5.4. Undefined reference to "..."
                    256:             21.5.5. Running out of memory
1.154     rillig    257:         21.6. The install phase
                    258:             21.6.1. Creating needed directories
                    259:             21.6.2. Where to install documentation
                    260:             21.6.3. Installing highscore files
                    261:             21.6.4. Adding DESTDIR support to packages
                    262:             21.6.5. Packages with hardcoded paths to other interpreters
1.203     nia       263:             21.6.6. Packages installing Perl modules
1.154     rillig    264:             21.6.7. Packages installing info files
                    265:             21.6.8. Packages installing man pages
1.203     nia       266:             21.6.9. Packages installing X11 fonts
                    267:             21.6.10. Packages installing SGML or XML data
                    268:             21.6.11. Packages installing extensions to the MIME database
                    269:             21.6.12. Packages using intltool
                    270:             21.6.13. Packages installing startup scripts
                    271:             21.6.14. Packages installing TeX modules
                    272:             21.6.15. Packages supporting running binaries in emulation
                    273:             21.6.16. Packages installing hicolor icons
                    274:             21.6.17. Packages installing desktop files
1.154     rillig    275:         21.7. Marking packages as having problems
1.184     rillig    276:     22. GNOME packaging and porting
                    277:         22.1. Meta packages
                    278:         22.2. Packaging a GNOME application
                    279:         22.3. Updating GNOME to a newer version
                    280:         22.4. Patching guidelines
1.154     rillig    281:     23. Submitting and Committing
                    282:         23.1. Submitting binary packages
                    283:         23.2. Submitting source packages (for non-NetBSD-developers)
                    284:         23.3. General notes when adding, updating, or removing packages
                    285:         23.4. Commit Messages
                    286:         23.5. Committing: Adding a package to CVS
                    287:         23.6. Updating a package to a newer version
                    288:         23.7. Renaming a package in pkgsrc
                    289:         23.8. Moving a package in pkgsrc
                    290:     24. Frequently Asked Questions
1.1       dsieger   291: III. The pkgsrc infrastructure internals
1.184     rillig    292:     25. Design of the pkgsrc infrastructure
                    293:         25.1. The meaning of variable definitions
                    294:         25.2. Avoiding problems before they arise
                    295:         25.3. Variable evaluation
                    296:             25.3.1. At load time
                    297:             25.3.2. At runtime
                    298:         25.4. How can variables be specified?
                    299:         25.5. Designing interfaces for Makefile fragments
                    300:             25.5.1. Procedures with parameters
                    301:             25.5.2. Actions taken on behalf of parameters
                    302:         25.6. The order in which files are loaded
                    303:             25.6.1. The order in bsd.prefs.mk
                    304:             25.6.2. The order in bsd.pkg.mk
                    305:     26. Regression tests
                    306:         26.1. Running the regression tests
                    307:         26.2. Adding a new regression test
                    308:             26.2.1. Overridable functions
                    309:             26.2.2. Helper functions
                    310:     27. Porting pkgsrc
                    311:         27.1. Porting pkgsrc to a new operating system
1.1       dsieger   312: A. A simple example package: bison
                    313:     A.1. files
                    314:         A.1.1. Makefile
                    315:         A.1.2. DESCR
                    316:         A.1.3. PLIST
                    317:         A.1.4. Checking a package with pkglint
                    318:     A.2. Steps for building, installing, packaging
1.207     leot      319: B. Security hardening
                    320:     B.1. Mechanisms
                    321:         B.1.1. Enabled by default
                    322:         B.1.2. Not enabled by default
                    323:     B.2. Caveats
                    324:         B.2.1. Problems with PKGSRC_MKPIE
                    325:         B.2.2. Problems with PKGSRC_USE_FORTIFY
                    326:         B.2.3. Problems with PKGSRC_USE_RELRO
                    327:         B.2.4. Problems with PKGSRC_USE_SSP
                    328:     B.3. Auditing the system
                    329:         B.3.1. Checking for PIE
                    330:         B.3.2. Checking for partial RELRO
                    331:         B.3.3. Checking for full RELRO
                    332:         B.3.4. Checking for SSP
                    333: C. Build logs
                    334:     C.1. Building figlet
                    335:     C.2. Packaging figlet
                    336: D. Directory layout of the pkgsrc FTP server
                    337:     D.1. distfiles: The distributed source files
                    338:     D.2. misc: Miscellaneous things
                    339:     D.3. packages: Binary packages
                    340:     D.4. reports: Bulk build reports
                    341:     D.5. current, stable, pkgsrc-20xxQy: source packages
                    342: E. Help topics
                    343: F. Editing guidelines for the pkgsrc guide
                    344:     F.1. Make targets
                    345:     F.2. Procedure
1.1       dsieger   346: 
                    347: List of Tables
                    348: 
                    349: 1.1. Platforms supported by pkgsrc
1.184     rillig    350: 12.1. Patching examples
                    351: 22.1. PLIST handling for GNOME packages
1.1       dsieger   352: 
                    353: Chapter 1. What is pkgsrc?
                    354: 
                    355: Table of Contents
                    356: 
                    357: 1.1. Introduction
                    358:     1.1.1. Why pkgsrc?
                    359:     1.1.2. Supported platforms
                    360: 1.2. Overview
                    361: 1.3. Terminology
                    362:     1.3.1. Roles involved in pkgsrc
                    363: 1.4. Typography
                    364: 
                    365: 1.1. Introduction
                    366: 
                    367: There is a lot of software freely available for Unix-based systems, which is
                    368: usually available in form of the source code. Before such software can be used,
                    369: it needs to be configured to the local system, compiled and installed, and this
                    370: is exactly what The NetBSD Packages Collection (pkgsrc) does. pkgsrc also has
                    371: some basic commands to handle binary packages, so that not every user has to
                    372: build the packages for himself, which is a time-costly task.
                    373: 
                    374: pkgsrc currently contains several thousand packages, including:
                    375: 
1.104     sevan     376:   * www/apache24 - The Apache web server
1.1       dsieger   377: 
                    378:   * www/firefox - The Firefox web browser
                    379: 
                    380:   * meta-pkgs/gnome - The GNOME Desktop Environment
                    381: 
1.102     ryoon     382:   * meta-pkgs/kde4 - The K Desktop Environment
1.1       dsieger   383: 
1.108     rillig    384: ? just to name a few.
1.1       dsieger   385: 
                    386: pkgsrc has built-in support for handling varying dependencies, such as pthreads
                    387: and X11, and extended features such as IPv6 support on a range of platforms.
                    388: 
                    389: 1.1.1. Why pkgsrc?
                    390: 
                    391: pkgsrc provides the following key features:
                    392: 
                    393:   * Easy building of software from source as well as the creation and
                    394:     installation of binary packages. The source and latest patches are
                    395:     retrieved from a master or mirror download site, checksum verified, then
                    396:     built on your system. Support for binary-only distributions is available
                    397:     for both native platforms and NetBSD emulated platforms.
                    398: 
                    399:   * All packages are installed in a consistent directory tree, including
                    400:     binaries, libraries, man pages and other documentation.
                    401: 
1.104     sevan     402:   * Tracking of package dependencies automatically, including when performing
                    403:     updates, to ensure required packages are installed. The configuration files
                    404:     of various packages are handled automatically during updates, so local
                    405:     changes are preserved.
1.1       dsieger   406: 
                    407:   * Like NetBSD, pkgsrc is designed with portability in mind and consists of
                    408:     highly portable code. This allows the greatest speed of development when
1.26      spz       409:     porting to a new platform. This portability also ensures that pkgsrc is 
1.1       dsieger   410:     consistent across all platforms.
                    411: 
                    412:   * The installation prefix, acceptable software licenses, international
                    413:     encryption requirements and build-time options for a large number of
                    414:     packages are all set in a simple, central configuration file.
                    415: 
                    416:   * The entire source (not including the distribution files) is freely
                    417:     available under a BSD license, so you may extend and adapt pkgsrc to your
                    418:     needs. Support for local packages and patches is available right out of the
                    419:     box, so you can configure it specifically for your environment.
                    420: 
                    421: The following principles are basic to pkgsrc:
                    422: 
1.198     leot      423:   * "It should only work if it's right." -- That means, if a package contains
1.1       dsieger   424:     bugs, it's better to find them and to complain about them rather than to
                    425:     just install the package and hope that it works. There are numerous checks
1.175     gutterid  426:     in pkgsrc that try to find such bugs: static analysis tools (pkgtools/
1.1       dsieger   427:     pkglint), build-time checks (portability of shell scripts), and
                    428:     post-installation checks (installed files, references to shared libraries,
                    429:     script interpreters).
                    430: 
1.198     leot      431:   * "If it works, it should work everywhere" -- Like NetBSD has been ported to
1.1       dsieger   432:     many hardware architectures, pkgsrc has been ported to many operating
                    433:     systems. Care is taken that packages behave the same on all platforms.
                    434: 
                    435: 1.1.2. Supported platforms
                    436: 
                    437: pkgsrc consists of both a source distribution and a binary distribution for
                    438: these operating systems. After retrieving the required source or binaries, you
                    439: can be up and running with pkgsrc in just minutes!
                    440: 
                    441: pkgsrc was derived from FreeBSD's ports system, and initially developed for
                    442: NetBSD only. Since then, pkgsrc has grown a lot, and now supports the following
                    443: platforms:
                    444: 
                    445: Table 1.1. Platforms supported by pkgsrc
                    446: 
1.92      sevan     447: +-----------------------------------------------------------------------------+
1.229     gutterid  448: |              Platform               | Date Support  |         Notes         |
                    449: |                                     |     Added     |                       |
                    450: |-------------------------------------+---------------+-----------------------|
                    451: |NetBSD                               |   Aug 1997    |                       |
                    452: |-------------------------------------+---------------+-----------------------|
                    453: |Solaris                              |   Mar 1999    |README.Solaris         |
                    454: |-------------------------------------+---------------+-----------------------|
                    455: |Linux                                |   Jun 1999    |README.Linux           |
                    456: |-------------------------------------+---------------+-----------------------|
                    457: |Darwin / Mac OS X / OS X / macOS     |   Oct 2001    |README.macOS           |
                    458: |-------------------------------------+---------------+-----------------------|
                    459: |FreeBSD                              |   Nov 2002    |README.FreeBSD         |
                    460: |-------------------------------------+---------------+-----------------------|
                    461: |OpenBSD                              |   Nov 2002    |README.OpenBSD         |
                    462: |-------------------------------------+---------------+-----------------------|
                    463: |IRIX                                 |   Dec 2002    |README.IRIX            |
                    464: |-------------------------------------+---------------+-----------------------|
                    465: |BSD/OS                               |   Dec 2003    |                       |
                    466: |-------------------------------------+---------------+-----------------------|
                    467: |AIX                                  |   Dec 2003    |README.AIX             |
                    468: |-------------------------------------+---------------+-----------------------|
                    469: |Interix (Microsoft Windows Services  |   Mar 2004    |README.Interix         |
                    470: |for Unix)                            |               |                       |
                    471: |-------------------------------------+---------------+-----------------------|
                    472: |DragonFlyBSD                         |   Oct 2004    |                       |
                    473: |-------------------------------------+---------------+-----------------------|
                    474: |OSF/1                                |   Nov 2004    |README.OSF1            |
                    475: |-------------------------------------+---------------+-----------------------|
                    476: |HP-UX                                |   Apr 2007    |README.HPUX            |
                    477: |-------------------------------------+---------------+-----------------------|
                    478: |Haiku                                |   Sep 2010    |README.Haiku           |
                    479: |-------------------------------------+---------------+-----------------------|
                    480: |MirBSD                               |   Jan 2011    |                       |
                    481: |-------------------------------------+---------------+-----------------------|
                    482: |Minix3                               |   Nov 2011    |README.Minix3          |
                    483: |-------------------------------------+---------------+-----------------------|
                    484: |Cygwin                               |   Mar 2013    |README.Cygwin          |
                    485: |-------------------------------------+---------------+-----------------------|
                    486: |GNU/kFreeBSD                         |   Jul 2013    |README.GNUkFreeBSD     |
                    487: |-------------------------------------+---------------+-----------------------|
                    488: |Bitrig                               |   Jun 2014    |Removed from pkgsrc Sep|
                    489: |                                     |               |2022                   |
1.92      sevan     490: +-----------------------------------------------------------------------------+
1.1       dsieger   491: 
                    492: 
                    493: 1.2. Overview
                    494: 
                    495: This document is divided into three parts. The first, The pkgsrc user's guide,
                    496: describes how one can use one of the packages in the Package Collection, either
                    497: by installing a precompiled binary package, or by building one's own copy using
                    498: the NetBSD package system. The second part, The pkgsrc developer's guide,
                    499: explains how to prepare a package so it can be easily built by other NetBSD
                    500: users without knowing about the package's building details. The third part, The
                    501: pkgsrc infrastructure internals is intended for those who want to understand
                    502: how pkgsrc is implemented.
                    503: 
                    504: This document is available in various formats: HTML, PDF, PS, TXT.
                    505: 
                    506: 1.3. Terminology
                    507: 
                    508: There has been a lot of talk about "ports", "packages", etc. so far. Here is a
                    509: description of all the terminology used within this document.
                    510: 
                    511: Package
                    512: 
                    513:     A set of files and building instructions that describe what's necessary to
                    514:     build a certain piece of software using pkgsrc. Packages are traditionally
1.123     wiz       515:     stored under /usr/pkgsrc, but may be stored in any location, referred to as
                    516:     PKGSRCDIR.
1.1       dsieger   517: 
                    518: The NetBSD package system
                    519: 
                    520:     This is the former name of "pkgsrc". It is part of the NetBSD operating
                    521:     system and can be bootstrapped to run on non-NetBSD operating systems as
                    522:     well. It handles building (compiling), installing, and removing of
                    523:     packages.
                    524: 
                    525: Distfile
                    526: 
                    527:     This term describes the file or files that are provided by the author of
                    528:     the piece of software to distribute his work. All the changes necessary to
                    529:     build on NetBSD are reflected in the corresponding package. Usually the
                    530:     distfile is in the form of a compressed tar-archive, but other types are
                    531:     possible, too. Distfiles are usually stored below /usr/pkgsrc/distfiles.
                    532: 
                    533: Port
                    534: 
                    535:     This is the term used by FreeBSD and OpenBSD people for what we call a
                    536:     package. In NetBSD terminology, "port" refers to a different architecture.
                    537: 
                    538: Precompiled/binary package
                    539: 
                    540:     A set of binaries built with pkgsrc from a distfile and stuffed together in
                    541:     a single .tgz file so it can be installed on machines of the same machine
                    542:     architecture without the need to recompile. Packages are usually generated
                    543:     in /usr/pkgsrc/packages; there is also an archive on ftp.NetBSD.org.
                    544: 
                    545:     Sometimes, this is referred to by the term "package" too, especially in the
                    546:     context of precompiled packages.
                    547: 
                    548: Program
                    549: 
                    550:     The piece of software to be installed which will be constructed from all
                    551:     the files in the distfile by the actions defined in the corresponding
                    552:     package.
                    553: 
                    554: 1.3.1. Roles involved in pkgsrc
                    555: 
                    556: pkgsrc users
                    557: 
                    558:     The pkgsrc users are people who use the packages provided by pkgsrc.
                    559:     Typically they are system administrators. The people using the software
                    560:     that is inside the packages (maybe called "end users") are not covered by
                    561:     the pkgsrc guide.
                    562: 
                    563:     There are two kinds of pkgsrc users: Some only want to install pre-built
                    564:     binary packages. Others build the pkgsrc packages from source, either for
                    565:     installing them directly or for building binary packages themselves. For
                    566:     pkgsrc users Part I, "The pkgsrc user's guide" should provide all necessary
                    567:     documentation.
                    568: 
                    569: package maintainers
                    570: 
                    571:     A package maintainer creates packages as described in Part II, "The pkgsrc
                    572:     developer's guide".
                    573: 
                    574: infrastructure developers
                    575: 
                    576:     These people are involved in all those files that live in the mk/ directory
                    577:     and below. Only these people should need to read through Part III, "The
                    578:     pkgsrc infrastructure internals", though others might be curious, too.
                    579: 
                    580: 1.4. Typography
                    581: 
                    582: When giving examples for commands, shell prompts are used to show if the
                    583: command should/can be issued as root, or if "normal" user privileges are
1.115     sevan     584: sufficient. We use a # for root's shell prompt, a % for users' shell prompt,
1.229     gutterid  585: assuming they use the C-shell or tcsh and a $ for Bourne shell and derivatives.
1.1       dsieger   586: 
                    587: Part I. The pkgsrc user's guide
                    588: 
                    589: Table of Contents
                    590: 
1.154     rillig    591: 2. Getting help
                    592: 3. Where to get pkgsrc and how to keep it up-to-date
                    593:     3.1. Getting pkgsrc for the first time
                    594:         3.1.1. As tar archive
                    595:         3.1.2. Via anonymous CVS
                    596:     3.2. Keeping pkgsrc up-to-date
                    597:         3.2.1. Via tar files
                    598:         3.2.2. Via CVS
                    599: 4. Using pkgsrc on systems other than NetBSD
                    600:     4.1. Binary distribution
                    601:     4.2. Bootstrapping pkgsrc
                    602: 5. Using pkgsrc
                    603:     5.1. Using binary packages
                    604:         5.1.1. Finding binary packages
                    605:         5.1.2. Installing binary packages
1.202     nia       606:         5.1.3. Updating packages
                    607:         5.1.4. Deinstalling packages
                    608:         5.1.5. Getting information about installed packages
                    609:         5.1.6. Checking for security vulnerabilities in installed packages
                    610:         5.1.7. Finding if newer versions of your installed packages are in
1.232   ! gutterid  611:         pkgsrc
1.202     nia       612:         5.1.8. Other administrative functions
1.154     rillig    613:     5.2. Building packages from source
                    614:         5.2.1. Requirements
                    615:         5.2.2. Fetching distfiles
                    616:         5.2.3. How to build and install
                    617: 6. Configuring pkgsrc
                    618:     6.1. General configuration
                    619:     6.2. Variables affecting the build process
                    620:     6.3. Variables affecting the installation process
                    621:     6.4. Selecting and configuring the compiler
                    622:         6.4.1. Selecting the compiler
                    623:         6.4.2. Additional flags to the compiler (CFLAGS)
                    624:         6.4.3. Additional flags to the linker (LDFLAGS)
                    625:     6.5. Developer/advanced settings
                    626:     6.6. Selecting Build Options
                    627: 7. Creating binary packages
                    628:     7.1. Building a single binary package
                    629:     7.2. Settings for creation of binary packages
                    630: 8. Creating binary packages for everything in pkgsrc (bulk builds)
                    631:     8.1. Preparations
1.180     rillig    632:     8.2. Running a bulk build
1.154     rillig    633:         8.2.1. Configuration
                    634:     8.3. Requirements of a full bulk build
1.178     rillig    635:     8.4. Bulk build variants
1.179     rillig    636:         8.4.1. Detect unknown configure options
                    637:         8.4.2. Detect classes of bugs by forcing compiler warnings
1.181     rillig    638:         8.4.3. Force compiler options only in the build phase
                    639:         8.4.4. Use custom directories
                    640:         8.4.5. Turn warnings into errors
                    641:         8.4.6. Reject packages for which pkglint reports errors
                    642:         8.4.7. Reject packages that contain forbidden strings
                    643:         8.4.8. Reject packages whose self-test fails
                    644:         8.4.9. Reject packages that use undefined shell variables
                    645:         8.4.10. Turn off verbose logging
1.178     rillig    646:     8.5. Creating a multiple CD-ROM packages collection
                    647:         8.5.1. Example of cdpack
1.154     rillig    648: 9. Directory layout of the installed files
                    649:     9.1. File system layout in ${LOCALBASE}
                    650:     9.2. File system layout in ${VARBASE}
                    651: 10. Frequently Asked Questions
                    652:     10.1. Are there any mailing lists for pkg-related discussion?
                    653:     10.2. Utilities for package management (pkgtools)
                    654:     10.3. How to use pkgsrc as non-root
                    655:     10.4. How to resume transfers when fetching distfiles?
                    656:     10.5. How can I install/use modular X.org from pkgsrc?
                    657:     10.6. How to fetch files from behind a firewall
                    658:     10.7. How to fetch files from HTTPS sites
                    659:     10.8. How do I tell make fetch to do passive FTP?
                    660:     10.9. How to fetch all distfiles at once
                    661:     10.10. What does "Don't know how to make /usr/share/tmac/tmac.andoc" mean?
                    662:     10.11. What does "Could not find bsd.own.mk" mean?
1.221     nia       663:     10.12. Using 'sudo' or `priv` with pkgsrc
1.154     rillig    664:     10.13. How do I change the location of configuration files?
                    665:     10.14. Automated security checks
                    666:     10.15. Why do some packages ignore my CFLAGS?
                    667:     10.16. A package does not build. What shall I do?
                    668:     10.17. What does "Makefile appears to contain unresolved cvs/rcs/??? merge
1.232   ! gutterid  669:     conflicts" mean?
1.1       dsieger   670: 
1.154     rillig    671: Chapter 2. Getting help
                    672: 
                    673: To get help when using pkgsrc, the definitive source is this document, the
                    674: pkgsrc guide. If you don't find anything here, there are alternatives:
                    675: 
                    676:   * The built-in pkgsrc help, which is available after bootstrapping pkgsrc.
                    677:     Run bmake help topic=? to get help for any topic, such as a variable name
                    678:     like BUILD_DEFS, a make target like do-build, a missing C or C++ function
                    679:     like strcasecmp or any other topic.
                    680: 
1.207     leot      681:     The available help topics are listed in Appendix E, Help topics.
1.154     rillig    682: 
1.163     rillig    683:   * To see the value of a single variable, run bmake show-var VARNAME=X.
                    684: 
                    685:   * To see the values of the most common variables, run bmake show-all. These
                    686:     variables are grouped by topic. To see the variables for a single topic,
                    687:     run bmake show-all-topic, for example bmake show-all-fetch.
                    688: 
1.154     rillig    689:   * The pkgsrc-users mailing list, to which you can subscribe and then ask your
                    690:     questions.
                    691: 
                    692:   * The #pkgsrc IRC channel, which is accessible via a web browser or by using
                    693:     a specialized chat program such as XChat. Pick any user name and join the
                    694:     channel #pkgsrc.
                    695: 
                    696: Chapter 3. Where to get pkgsrc and how to keep it up-to-date
1.1       dsieger   697: 
                    698: Table of Contents
                    699: 
1.154     rillig    700: 3.1. Getting pkgsrc for the first time
                    701:     3.1.1. As tar archive
                    702:     3.1.2. Via anonymous CVS
                    703: 3.2. Keeping pkgsrc up-to-date
                    704:     3.2.1. Via tar files
                    705:     3.2.2. Via CVS
1.1       dsieger   706: 
                    707: Before you download and extract the files, you need to decide where you want to
                    708: extract them. When using pkgsrc as root user, pkgsrc is usually installed in /
                    709: usr/pkgsrc. You are though free to install the sources and binary packages
                    710: wherever you want in your filesystem, provided that the pathname does not
                    711: contain white-space or other characters that are interpreted specially by the
                    712: shell and some other programs. A safe bet is to use only letters, digits,
                    713: underscores and dashes.
                    714: 
1.154     rillig    715: 3.1. Getting pkgsrc for the first time
1.1       dsieger   716: 
1.25      wiz       717: Before you download any pkgsrc files, you should decide whether you want the 
1.1       dsieger   718: current branch or the stable branch. The latter is forked on a quarterly basis
                    719: from the current branch and only gets modified for security updates. The names
                    720: of the stable branches are built from the year and the quarter, for example
1.214     leot      721: 2021Q4.
1.1       dsieger   722: 
                    723: The second step is to decide how you want to download pkgsrc. You can get it as
1.24      wiz       724: a tar file or via CVS. Both ways are described here.
1.1       dsieger   725: 
1.52      asau      726: Note that tar archive contains CVS working copy. Thus you can switch to using
                    727: CVS at any later time.
1.1       dsieger   728: 
1.154     rillig    729: 3.1.1. As tar archive
1.52      asau      730: 
1.151     sevan     731: The primary download location for all pkgsrc files is https://cdn.NetBSD.org/
                    732: pub/pkgsrc/ or ftp://ftp.NetBSD.org/pub/pkgsrc/ (it points to the same
                    733: location). There are a number of subdirectories for different purposes, which
1.207     leot      734: are described in detail in Appendix D, Directory layout of the pkgsrc FTP
1.151     sevan     735: server.
1.1       dsieger   736: 
1.52      asau      737: The tar archive for the current branch is in the directory current and is
1.118     sevan     738: called pkgsrc.tar.gz. It is autogenerated weekly.
1.52      asau      739: 
                    740: To save download time we provide bzip2- and xz-compressed archives which are
                    741: published at pkgsrc.tar.bz2 and pkgsrc.tar.xz respectively.
                    742: 
                    743: You can fetch the same files using FTP.
1.1       dsieger   744: 
1.214     leot      745: The tar file for the stable branch 2021Q4 is in the directory pkgsrc-2021Q4 and
1.59      jnemeth   746: is also called pkgsrc.tar.gz.
1.1       dsieger   747: 
1.136     leot      748: To download the latest pkgsrc stable tarball, run:
1.12      weinem    749: 
1.214     leot      750: $ ftp ftp://ftp.NetBSD.org/pub/pkgsrc/pkgsrc-2021Q4/pkgsrc.tar.gz
1.12      weinem    751: 
1.78      snj       752: If you prefer, you can also fetch it using "wget", "curl", or your web browser.
1.52      asau      753: 
1.12      weinem    754: Then, extract it with:
                    755: 
1.78      snj       756: $ tar -xzf pkgsrc.tar.gz -C /usr
1.12      weinem    757: 
                    758: This will create the directory pkgsrc/ in /usr/ and all the package source will
                    759: be stored under /usr/pkgsrc/.
                    760: 
                    761: To download pkgsrc-current, run:
                    762: 
                    763: $ ftp ftp://ftp.NetBSD.org/pub/pkgsrc/current/pkgsrc.tar.gz
1.1       dsieger   764: 
1.154     rillig    765: 3.1.2. Via anonymous CVS
1.1       dsieger   766: 
1.24      wiz       767: To fetch a specific pkgsrc stable branch, run:
1.1       dsieger   768: 
1.214     leot      769: $ cd /usr && cvs -q -z2 -d anoncvs@anoncvs.NetBSD.org:/cvsroot checkout -r pkgsrc-2021Q4 -P pkgsrc
1.13      weinem    770: 
1.24      wiz       771: This will create the directory pkgsrc/ in your /usr/ directory and all the
                    772: package source will be stored under /usr/pkgsrc/.
                    773: 
                    774: To fetch the pkgsrc current branch, run:
1.1       dsieger   775: 
1.40      wiz       776: $ cd /usr && cvs -q -z2 -d anoncvs@anoncvs.NetBSD.org:/cvsroot checkout -P pkgsrc
1.1       dsieger   777: 
1.30      dholland  778: Refer to the list of available mirrors to choose a faster CVS mirror, if
                    779: needed.
1.1       dsieger   780: 
1.24      wiz       781: If you get error messages from rsh, you need to set CVS_RSH variable. E.g.:
1.1       dsieger   782: 
1.40      wiz       783: $ cd /usr && env CVS_RSH=ssh cvs -q -z2 -d anoncvs@anoncvs.NetBSD.org:/cvsroot checkout -P pkgsrc
1.1       dsieger   784: 
1.24      wiz       785: Refer to documentation on your command shell how to set CVS_RSH=ssh
                    786: permanently. For Bourne shells, you can set it in your .profile or better
                    787: globally in /etc/profile:
                    788: 
                    789: # set CVS remote shell command
                    790: CVS_RSH=ssh
                    791: export CVS_RSH
1.12      weinem    792: 
1.13      weinem    793: By default, CVS doesn't do things like most people would expect it to do. But
                    794: there is a way to convince CVS, by creating a file called .cvsrc in your home
1.12      weinem    795: directory and saving the following lines to it. This file will save you lots of
                    796: headache and some bug reports, so we strongly recommend it. You can find an
                    797: explanation of this file in the CVS documentation.
1.2       rillig    798: 
                    799: # recommended CVS configuration file from the pkgsrc guide
1.155     sevan     800: cvs -q
1.2       rillig    801: checkout -P
1.4       rillig    802: update -dP
                    803: diff -upN
1.2       rillig    804: rdiff -u
1.24      wiz       805: release -d
1.1       dsieger   806: 
1.154     rillig    807: 3.2. Keeping pkgsrc up-to-date
1.1       dsieger   808: 
                    809: The preferred way to keep pkgsrc up-to-date is via CVS (which also works if you
                    810: have first installed it via a tar file). It saves bandwidth and hard disk
                    811: activity, compared to downloading the tar file again.
                    812: 
1.154     rillig    813: 3.2.1. Via tar files
1.1       dsieger   814: 
                    815: Warning
                    816: 
                    817: When updating from a tar file, you first need to completely remove the old
                    818: pkgsrc directory. Otherwise those files that have been removed from pkgsrc in
                    819: the mean time will not be removed on your local disk, resulting in
                    820: inconsistencies. When removing the old files, any changes that you have done to
                    821: the pkgsrc files will be lost after updating. Therefore updating via CVS is
                    822: strongly recommended.
                    823: 
                    824: Note that by default the distfiles and the binary packages are saved in the
                    825: pkgsrc tree, so don't forget to rescue them before updating. You can also
1.78      snj       826: configure pkgsrc to store distfiles and packages in directories outside the
1.154     rillig    827: pkgsrc tree by setting the DISTDIR and PACKAGES variables. See Chapter 6, 
1.78      snj       828: Configuring pkgsrc for the details.
1.1       dsieger   829: 
                    830: To update pkgsrc from a tar file, download the tar file as explained above.
                    831: Then, make sure that you have not made any changes to the files in the pkgsrc
                    832: directory. Remove the pkgsrc directory and extract the new tar file. Done.
                    833: 
1.154     rillig    834: 3.2.2. Via CVS
1.1       dsieger   835: 
1.26      spz       836: To update pkgsrc via CVS, change to the pkgsrc directory and run cvs:
1.12      weinem    837: 
1.26      spz       838: $ cd /usr/pkgsrc && cvs update -dP
                    839: 
                    840: If you get error messages from rsh, you need to set CVS_RSH variable as
                    841: described above. E.g.:
                    842: 
                    843: $ cd /usr/pkgsrc && env CVS_RSH=ssh cvs up -dP
1.1       dsieger   844: 
1.154     rillig    845: 3.2.2.1. Switching between different pkgsrc branches
1.1       dsieger   846: 
                    847: When updating pkgsrc, the CVS program keeps track of the branch you selected.
                    848: But if you, for whatever reason, want to switch from the stable branch to the
                    849: current one, you can do it by adding the option "-A" after the "update"
1.25      wiz       850: keyword. To switch from the current branch back to the stable branch, add the "
1.214     leot      851: -rpkgsrc-2021Q4" option.
1.1       dsieger   852: 
1.154     rillig    853: 3.2.2.2. What happens to my changes when updating?
1.1       dsieger   854: 
                    855: When you update pkgsrc, the CVS program will only touch those files that are
                    856: registered in the CVS repository. That means that any packages that you created
                    857: on your own will stay unmodified. If you change files that are managed by CVS,
                    858: later updates will try to merge your changes with those that have been done by
                    859: others. See the CVS manual, chapter "update" for details.
                    860: 
1.154     rillig    861: Chapter 4. Using pkgsrc on systems other than NetBSD
1.1       dsieger   862: 
                    863: Table of Contents
                    864: 
1.154     rillig    865: 4.1. Binary distribution
                    866: 4.2. Bootstrapping pkgsrc
1.1       dsieger   867: 
1.154     rillig    868: 4.1. Binary distribution
1.1       dsieger   869: 
1.154     rillig    870: See Section 5.1, "Using binary packages".
1.1       dsieger   871: 
1.154     rillig    872: 4.2. Bootstrapping pkgsrc
1.1       dsieger   873: 
1.44      asau      874: pkgsrc can be bootstrapped for use in two different modes: privileged and
                    875: unprivileged one. In unprivileged mode in contrast to privileged one all
1.45      asau      876: programs are installed under one particular user and cannot utilise privileged
1.44      asau      877: operations (packages don't create special users and all special file
                    878: permissions like setuid are ignored).
                    879: 
1.1       dsieger   880: Installing the bootstrap kit from source should be as simple as:
                    881: 
1.60      asau      882: # env CVS_RSH=ssh cvs -d anoncvs@anoncvs.NetBSD.org:/cvsroot checkout -P pkgsrc
1.1       dsieger   883: # cd pkgsrc/bootstrap
                    884: # ./bootstrap
                    885: 
                    886: 
1.44      asau      887: To bootstrap in unprivileged mode pass "--unprivileged" flag to bootstrap
                    888: 
                    889: By default, in privileged mode pkgsrc uses /usr/pkg for prefix where programs
1.118     sevan     890: will be installed in, and /usr/pkg/pkgdb for the package database directory
                    891: where pkgsrc will do its internal bookkeeping, /var is used as varbase, where
1.44      asau      892: packages install their persistent data. In unprivileged mode pkgsrc uses ~/pkg
1.118     sevan     893: for prefix, ~/pkg/pkgdb for the package database, and ~/pkg/var for varbase.
1.44      asau      894: 
                    895: You can change default layout using command-line arguments. Run "./bootstrap
                    896: --help" to get details.
1.1       dsieger   897: 
                    898: Note
                    899: 
                    900: The bootstrap installs a bmake tool. Use this bmake when building via pkgsrc.
                    901: For examples in this guide, use bmake instead of "make".
                    902: 
1.44      asau      903: Note
                    904: 
                    905: It is possible to bootstrap multiple instances of pkgsrc using non-intersecting
                    906: directories. Use bmake corresponding to the installation you're working with to
                    907: build and install packages.
                    908: 
1.154     rillig    909: Chapter 5. Using pkgsrc
1.1       dsieger   910: 
                    911: Table of Contents
                    912: 
1.154     rillig    913: 5.1. Using binary packages
                    914:     5.1.1. Finding binary packages
                    915:     5.1.2. Installing binary packages
1.202     nia       916:     5.1.3. Updating packages
                    917:     5.1.4. Deinstalling packages
                    918:     5.1.5. Getting information about installed packages
                    919:     5.1.6. Checking for security vulnerabilities in installed packages
                    920:     5.1.7. Finding if newer versions of your installed packages are in pkgsrc
                    921:     5.1.8. Other administrative functions
1.154     rillig    922: 5.2. Building packages from source
                    923:     5.2.1. Requirements
                    924:     5.2.2. Fetching distfiles
                    925:     5.2.3. How to build and install
1.1       dsieger   926: 
                    927: Basically, there are two ways of using pkgsrc. The first is to only install the
                    928: package tools and to use binary packages that someone else has prepared. This
                    929: is the "pkg" in pkgsrc. The second way is to install the "src" of pkgsrc, too.
                    930: Then you are able to build your own packages, and you can still use binary
                    931: packages from someone else.
                    932: 
1.154     rillig    933: 5.1. Using binary packages
1.1       dsieger   934: 
1.151     sevan     935: On the cdn.NetBSD.org site and mirrors, there are collections of binary
1.9       rillig    936: packages, ready to be installed. These binary packages have been built using
                    937: the default settings for the directories, that is:
                    938: 
                    939:   * /usr/pkg for LOCALBASE, where most of the files are installed,
                    940: 
                    941:   * /usr/pkg/etc for configuration files,
                    942: 
                    943:   * /var for VARBASE, where those files are installed that may change after
                    944:     installation.
                    945: 
                    946: If you cannot use these directories for whatever reasons (maybe because you're
                    947: not root), you cannot use these binary packages, but have to build the packages
1.154     rillig    948: yourself, which is explained in Section 4.2, "Bootstrapping pkgsrc".
1.1       dsieger   949: 
1.154     rillig    950: 5.1.1. Finding binary packages
1.1       dsieger   951: 
1.5       weinem    952: To install binary packages, you first need to know from where to get them. The
1.202     nia       953: first place where you should look is on the main pkgsrc CDN in the directory /
                    954: pub/pkgsrc/packages.
1.5       weinem    955: 
                    956: This directory contains binary packages for multiple platforms. First, select
1.226     gutterid  957: your operating system. Then, select your hardware architecture, and in the
                    958: third step, the OS version and the "version" of pkgsrc.
1.9       rillig    959: 
1.226     gutterid  960: In this directory, you may find a file called bootstrap.tar.gz which contains
1.9       rillig    961: the package management tools. If the file is missing, it is likely that your
                    962: operating system already provides those tools. Download the file and extract it
                    963: in the / directory. It will create the directories /usr/pkg (containing the
1.118     sevan     964: tools for managing binary packages and the database of installed packages).
1.1       dsieger   965: 
1.154     rillig    966: 5.1.2. Installing binary packages
1.1       dsieger   967: 
1.85      wiz       968: In the directory from the last section, there is a subdirectory called All/,
1.9       rillig    969: which contains all the binary packages that are available for the platform,
1.202     nia       970: excluding those that may not be distributed via HTTP or FTP.
1.9       rillig    971: 
                    972: To install packages directly from an FTP or HTTP server, run the following
                    973: commands in a Bourne-compatible shell (be sure to su to root first):
                    974: 
1.202     nia       975: # PATH="/usr/pkg/sbin:/usr/pkg/bin:$PATH"
                    976: # PKG_PATH="https://cdn.NetBSD.org/pub/pkgsrc/packages"
1.169     rillig    977: # PKG_PATH="$PKG_PATH/OPSYS/ARCH/VERSIONS/All/"
1.9       rillig    978: # export PATH PKG_PATH
1.202     nia       979: # pkg_add pkgin
1.9       rillig    980: 
                    981: Instead of URLs, you can also use local paths, for example if you are
                    982: installing from a set of CDROMs, DVDs or an NFS-mounted repository. If you want
                    983: to install packages from multiple sources, you can separate them by a semicolon
                    984: in PKG_PATH.
                    985: 
                    986: After these preparations, installing a package is very easy:
                    987: 
1.202     nia       988: # pkgin search nginx
                    989: nginx-1.19.6         Lightweight HTTP server and mail proxy server
                    990: nginx-1.18.0nb8      Lightweight HTTP server and mail proxy server
                    991: # pkgin install zsh nginx-1.19.6 vim
1.1       dsieger   992: 
1.202     nia       993: Note that pkgin is a user-friendly frontend to the pkg_* tools.
1.1       dsieger   994: 
1.202     nia       995: Any prerequisite packages needed to run the package in question will be
                    996: installed, too, assuming they are present in the repository.
1.1       dsieger   997: 
                    998: After you've installed packages, be sure to have /usr/pkg/bin and /usr/pkg/sbin
                    999: in your PATH so you can actually start the just installed program.
                   1000: 
1.202     nia      1001: 5.1.3. Updating packages
1.1       dsieger  1002: 
1.202     nia      1003: To update binary packages, it is recommended that you use pkgin upgrade. This
                   1004: will compare the remote package repository to your locally installed packages
                   1005: and safely replace any older packages.
1.1       dsieger  1006: 
1.202     nia      1007: Note that pkgsrc is released as quarterly branches. If you are updating to a
                   1008: newer quarterly branch of pkgsrc, you may need to adjust the repository in /usr
                   1009: /pkg/etc/pkgin/repositories.conf.
1.1       dsieger  1010: 
1.202     nia      1011: 5.1.4. Deinstalling packages
1.1       dsieger  1012: 
1.202     nia      1013: To deinstall a package, it does not matter whether it was installed from source
                   1014: code or from a binary package. Neither the pkgin or the pkg_delete command need
                   1015: to know.
1.1       dsieger  1016: 
1.202     nia      1017: To delete a package, you can just run pkgin remove package-name. The package
                   1018: name can be given with or without version number.
1.1       dsieger  1019: 
1.202     nia      1020: 5.1.5. Getting information about installed packages
1.1       dsieger  1021: 
                   1022: The pkg_info shows information about installed packages or binary package
1.202     nia      1023: files. As with other management tools, it works with packages installed from
                   1024: source or binaries.
1.1       dsieger  1025: 
1.202     nia      1026: 5.1.6. Checking for security vulnerabilities in installed packages
1.1       dsieger  1027: 
1.202     nia      1028: The pkgsrc Security Team and Packages Groups maintain a list of known
1.164     leot     1029: vulnerabilities to packages which are (or have been) included in pkgsrc. The
1.202     nia      1030: list is available from the NetBSD CDN at https://cdn.NetBSD.org/pub/NetBSD/
1.179     rillig   1031: packages/vulns/pkg-vulnerabilities.
1.1       dsieger  1032: 
1.202     nia      1033: Please note that not every "vulnerability" with a CVE assignment is exploitable
                   1034: in every configuration. Some bugs are marked as active simply because an fix
                   1035: was not marked as such. Operating system specific hardening and mitigation
                   1036: features may also reduce the impact of bugs.
                   1037: 
1.23      jakllsch 1038: Through pkg_admin fetch-pkg-vulnerabilities, this list can be downloaded
                   1039: automatically, and a security audit of all packages installed on a system can
                   1040: take place.
                   1041: 
                   1042: There are two components to auditing. The first step, pkg_admin
                   1043: fetch-pkg-vulnerabilities, is for downloading the list of vulnerabilities from
                   1044: the NetBSD FTP site. The second step, pkg_admin audit, checks to see if any of
                   1045: your installed packages are vulnerable. If a package is vulnerable, you will
                   1046: see output similar to the following:
1.1       dsieger  1047: 
                   1048: Package samba-2.0.9 has a local-root-shell vulnerability, see
1.174     leot     1049:     https://www.samba.org/samba/whatsnew/macroexploit.html
1.1       dsieger  1050: 
1.23      jakllsch 1051: You may wish to have the vulnerabilities file downloaded daily so that it
                   1052: remains current. This may be done by adding an appropriate entry to the root
                   1053: users crontab(5) entry. For example the entry
                   1054: 
1.121     sevan    1055: # Download vulnerabilities file
1.118     sevan    1056: 0 3 * * * /usr/pkg/sbin/pkg_admin fetch-pkg-vulnerabilities >/dev/null 2>&1
1.121     sevan    1057: # Audit the installed packages and email results to root
                   1058: 9 3 * * * /usr/pkg/sbin/pkg_admin audit |mail -s "Installed package audit result" \
                   1059:             root >/dev/null 2>&1
1.118     sevan    1060: 
                   1061: 
                   1062: will update the vulnerability list every day at 3AM, followed by an audit at
                   1063: 3:09AM. The result of the audit are then emailed to root. On NetBSD this may be
                   1064: accomplished instead by adding the following line to /etc/daily.conf:
                   1065: 
                   1066: fetch_pkg_vulnerabilities=YES
                   1067: 
1.23      jakllsch 1068: 
1.118     sevan    1069: to fetch the vulnerability list from the daily security script. The system is
                   1070: set to audit the packages by default but can be set explicitly, if desired (not
1.123     wiz      1071: required), by adding the following line to /etc/security.conf:
1.23      jakllsch 1072: 
1.118     sevan    1073: check_pkg_vulnerabilities=YES
1.23      jakllsch 1074: 
                   1075: 
1.118     sevan    1076: see daily.conf(5) and security.conf(5) for more details.
1.1       dsieger  1077: 
1.202     nia      1078: 5.1.7. Finding if newer versions of your installed packages are in pkgsrc
1.1       dsieger  1079: 
1.12      weinem   1080: Install pkgtools/lintpkgsrc and run lintpkgsrc with the "-i" argument to check
1.202     nia      1081: if any packages are stale, e.g.
1.1       dsieger  1082: 
                   1083: % lintpkgsrc -i
                   1084: ...
                   1085: Version mismatch: 'tcsh' 6.09.00 vs 6.10.00
                   1086: 
                   1087: 
1.202     nia      1088: 5.1.8. Other administrative functions
1.1       dsieger  1089: 
                   1090: The pkg_admin executes various administrative functions on the package system.
                   1091: 
1.154     rillig   1092: 5.2. Building packages from source
1.1       dsieger  1093: 
                   1094: After obtaining pkgsrc, the pkgsrc directory now contains a set of packages,
1.25      wiz      1095: organized into categories. You can browse the online index of packages, or run 
1.1       dsieger  1096: make readme from the pkgsrc directory to build local README.html files for all
                   1097: packages, viewable with any web browser such as www/lynx or www/firefox.
                   1098: 
                   1099: The default prefix for installed packages is /usr/pkg. If you wish to change
                   1100: this, you should do so by setting LOCALBASE in mk.conf. You should not try to
                   1101: use multiple different LOCALBASE definitions on the same system (inside a
                   1102: chroot is an exception).
                   1103: 
                   1104: The rest of this chapter assumes that the package is already in pkgsrc. If it
                   1105: is not, see Part II, "The pkgsrc developer's guide" for instructions how to
                   1106: create your own packages.
                   1107: 
1.154     rillig   1108: 5.2.1. Requirements
1.1       dsieger  1109: 
                   1110: To build packages from source, you need a working C compiler. On NetBSD, you
                   1111: need to install the "comp" and the "text" distribution sets. If you want to
                   1112: build X11-related packages, the "xbase" and "xcomp" distribution sets are
                   1113: required, too.
                   1114: 
1.154     rillig   1115: 5.2.2. Fetching distfiles
1.1       dsieger  1116: 
                   1117: The first step for building a package is downloading the distfiles (i.e. the
                   1118: unmodified source). If they have not yet been downloaded, pkgsrc will fetch
                   1119: them automatically.
                   1120: 
                   1121: If you have all files that you need in the distfiles directory, you don't need
                   1122: to connect. If the distfiles are on CD-ROM, you can mount the CD-ROM on /cdrom
                   1123: and add:
                   1124: 
                   1125: DISTDIR=/cdrom/pkgsrc/distfiles
                   1126: 
                   1127: to your mk.conf.
                   1128: 
                   1129: By default a list of distribution sites will be randomly intermixed to prevent
                   1130: huge load on servers which holding popular packages (for example,
                   1131: SourceForge.net mirrors). Thus, every time when you need to fetch yet another
                   1132: distfile all the mirrors will be tried in new (random) order. You can turn this
                   1133: feature off by setting MASTER_SORT_RANDOM=NO (for PKG_DEVELOPERs it's already
                   1134: disabled).
                   1135: 
                   1136: You can overwrite some of the major distribution sites to fit to sites that are
                   1137: close to your own. By setting one or two variables you can modify the order in
                   1138: which the master sites are accessed. MASTER_SORT contains a whitespace
                   1139: delimited list of domain suffixes. MASTER_SORT_REGEX is even more flexible, it
                   1140: contains a whitespace delimited list of regular expressions. It has higher
                   1141: priority than MASTER_SORT. Have a look at pkgsrc/mk/defaults/mk.conf to find
                   1142: some examples. This may save some of your bandwidth and time.
                   1143: 
                   1144: You can change these settings either in your shell's environment, or, if you
1.4       rillig   1145: want to keep the settings, by editing the mk.conf file, and adding the
1.1       dsieger  1146: definitions there.
                   1147: 
1.132     wiz      1148: If a package depends on many other packages (such as meta-pkgs/kde4), the build
1.1       dsieger  1149: process may alternate between periods of downloading source, and compiling. To
                   1150: ensure you have all the source downloaded initially you can run the command:
                   1151: 
                   1152: % make fetch-list | sh
                   1153: 
                   1154: which will output and run a set of shell commands to fetch the necessary files
                   1155: into the distfiles directory. You can also choose to download the files
                   1156: manually.
                   1157: 
1.154     rillig   1158: 5.2.3. How to build and install
1.1       dsieger  1159: 
                   1160: Once the software has downloaded, any patches will be applied, then it will be
                   1161: compiled for you. This may take some time depending on your computer, and how
                   1162: many other packages the software depends on and their compile time.
                   1163: 
                   1164: Note
                   1165: 
                   1166: If using bootstrap or pkgsrc on a non-NetBSD system, use the pkgsrc bmake
                   1167: command instead of "make" in the examples in this guide.
                   1168: 
                   1169: For example, type
                   1170: 
                   1171: % cd misc/figlet
                   1172: % make
                   1173: 
                   1174: 
                   1175: at the shell prompt to build the various components of the package.
                   1176: 
                   1177: The next stage is to actually install the newly compiled program onto your
                   1178: system. Do this by entering:
                   1179: 
                   1180: % make install
                   1181: 
                   1182: 
                   1183: while you are still in the directory for whatever package you are installing.
                   1184: 
                   1185: Installing the package on your system may require you to be root. However,
                   1186: pkgsrc has a just-in-time-su feature, which allows you to only become root for
                   1187: the actual installation step.
                   1188: 
                   1189: That's it, the software should now be installed and setup for use. You can now
                   1190: enter:
                   1191: 
                   1192: % make clean
                   1193: 
                   1194: 
                   1195: to remove the compiled files in the work directory, as you shouldn't need them
                   1196: any more. If other packages were also added to your system (dependencies) to
                   1197: allow your program to compile, you can tidy these up also with the command:
                   1198: 
                   1199: % make clean-depends
                   1200: 
                   1201: 
                   1202: Taking the figlet utility as an example, we can install it on our system by
1.207     leot     1203: building as shown in Appendix C, Build logs.
1.1       dsieger  1204: 
                   1205: The program is installed under the default root of the packages tree - /usr/
                   1206: pkg. Should this not conform to your tastes, set the LOCALBASE variable in your
                   1207: environment, and it will use that value as the root of your packages tree. So,
                   1208: to use /usr/local, set LOCALBASE=/usr/local in your environment. Please note
                   1209: that you should use a directory which is dedicated to packages and not shared
                   1210: with other programs (i.e., do not try and use LOCALBASE=/usr). Also, you should
                   1211: not try to add any of your own files or directories (such as src/, obj/, or
                   1212: pkgsrc/) below the LOCALBASE tree. This is to prevent possible conflicts
                   1213: between programs and other files installed by the package system and whatever
                   1214: else may have been installed there.
                   1215: 
1.4       rillig   1216: Some packages look in mk.conf to alter some configuration options at build
1.1       dsieger  1217: time. Have a look at pkgsrc/mk/defaults/mk.conf to get an overview of what will
                   1218: be set there by default. Environment variables such as LOCALBASE can be set in
1.4       rillig   1219: mk.conf to save having to remember to set them each time you want to use
1.1       dsieger  1220: pkgsrc.
                   1221: 
                   1222: Occasionally, people want to "look under the covers" to see what is going on
                   1223: when a package is building or being installed. This may be for debugging
                   1224: purposes, or out of simple curiosity. A number of utility values have been
                   1225: added to help with this.
                   1226: 
                   1227:  1. If you invoke the make(1) command with PKG_DEBUG_LEVEL=2, then a huge
                   1228:     amount of information will be displayed. For example,
                   1229: 
                   1230:     make patch PKG_DEBUG_LEVEL=2
                   1231: 
1.25      wiz      1232:     will show all the commands that are invoked, up to and including the "patch
                   1233:     " stage.
1.1       dsieger  1234: 
                   1235:  2. If you want to know the value of a certain make(1) definition, then the
                   1236:     VARNAME definition should be used, in conjunction with the show-var target.
                   1237:     e.g. to show the expansion of the make(1) variable LOCALBASE:
                   1238: 
                   1239:     % make show-var VARNAME=LOCALBASE
                   1240:     /usr/pkg
                   1241:     %
                   1242: 
                   1243: 
                   1244: If you want to install a binary package that you've either created yourself
                   1245: (see next section), that you put into pkgsrc/packages manually or that is
                   1246: located on a remote FTP server, you can use the "bin-install" target. This
                   1247: target will install a binary package - if available - via pkg_add(1), else do a
                   1248: make package. The list of remote FTP sites searched is kept in the variable
                   1249: BINPKG_SITES, which defaults to ftp.NetBSD.org. Any flags that should be added
                   1250: to pkg_add(1) can be put into BIN_INSTALL_FLAGS. See pkgsrc/mk/defaults/mk.conf
                   1251: for more details.
                   1252: 
                   1253: A final word of warning: If you set up a system that has a non-standard setting
                   1254: for LOCALBASE, be sure to set that before any packages are installed, as you
                   1255: cannot use several directories for the same purpose. Doing so will result in
                   1256: pkgsrc not being able to properly detect your installed packages, and fail
                   1257: miserably. Note also that precompiled binary packages are usually built with
                   1258: the default LOCALBASE of /usr/pkg, and that you should not install any if you
                   1259: use a non-standard LOCALBASE.
                   1260: 
1.154     rillig   1261: Chapter 6. Configuring pkgsrc
1.1       dsieger  1262: 
                   1263: Table of Contents
                   1264: 
1.154     rillig   1265: 6.1. General configuration
                   1266: 6.2. Variables affecting the build process
                   1267: 6.3. Variables affecting the installation process
                   1268: 6.4. Selecting and configuring the compiler
                   1269:     6.4.1. Selecting the compiler
                   1270:     6.4.2. Additional flags to the compiler (CFLAGS)
                   1271:     6.4.3. Additional flags to the linker (LDFLAGS)
                   1272: 6.5. Developer/advanced settings
                   1273: 6.6. Selecting Build Options
1.1       dsieger  1274: 
                   1275: The whole pkgsrc system is configured in a single file, usually called mk.conf.
                   1276: In which directory pkgsrc looks for that file depends on the installation. On
                   1277: NetBSD, when you use make(1) from the base system, it is in the directory /etc
                   1278: /. In all other cases the default location is ${PREFIX}/etc/, depending on
                   1279: where you told the bootstrap program to install the binary packages.
                   1280: 
                   1281: The format of the configuration file is that of the usual BSD-style Makefiles.
                   1282: The whole pkgsrc configuration is done by setting variables in this file. Note
                   1283: that you can define all kinds of variables, and no special error checking (for
1.112     rillig   1284: example for spelling mistakes) takes place.
1.1       dsieger  1285: 
1.154     rillig   1286: 6.1. General configuration
1.1       dsieger  1287: 
1.112     rillig   1288: The following variables apply to all pkgsrc packages. A complete list of the
                   1289: variables that can be configured by the user is available in mk/defaults/
                   1290: mk.conf, together with some comments that describe each variable's intent.
1.1       dsieger  1291: 
                   1292:   * LOCALBASE: Where packages will be installed. The default is /usr/pkg. Do
                   1293:     not mix binary packages with different LOCALBASEs!
                   1294: 
                   1295:   * CROSSBASE: Where "cross" category packages will be installed. The default
                   1296:     is ${LOCALBASE}/cross.
                   1297: 
1.84      wiz      1298:   * X11BASE: Where X11 is installed on the system. The default is /usr/X11R7.
1.1       dsieger  1299: 
                   1300:   * DISTDIR: Where to store the downloaded copies of the original source
                   1301:     distributions used for building pkgsrc packages. The default is $
                   1302:     {PKGSRCDIR}/distfiles.
                   1303: 
                   1304:   * PKG_DBDIR: Where the database about installed packages is stored. The
1.118     sevan    1305:     default is /usr/pkg/pkgdb.
1.1       dsieger  1306: 
                   1307:   * MASTER_SITE_OVERRIDE: If set, override the packages' MASTER_SITES with this
                   1308:     value.
                   1309: 
                   1310:   * MASTER_SITE_BACKUP: Backup location(s) for distribution files and patch
                   1311:     files if not found locally or in ${MASTER_SITES} or ${PATCH_SITES}
1.118     sevan    1312:     respectively. The defaults is ftp://ftp.NetBSD.org/pub/pkgsrc/distfiles/$
1.1       dsieger  1313:     {DIST_SUBDIR}/.
                   1314: 
                   1315:   * BINPKG_SITES: List of sites carrying binary pkgs. rel and arch are replaced
                   1316:     with OS release ("2.0", etc.) and architecture ("mipsel", etc.).
                   1317: 
1.23      jakllsch 1318:   * ACCEPTABLE_LICENSES: List of acceptable licenses. License names are
                   1319:     case-sensitive. Whenever you try to build a package whose license is not in
                   1320:     this list, you will get an error message. If the license condition is
                   1321:     simple enough, the error message will include specific instructions on how
                   1322:     to change this variable.
1.1       dsieger  1323: 
1.154     rillig   1324: 6.2. Variables affecting the build process
1.1       dsieger  1325: 
                   1326:   * PACKAGES: The top level directory for the binary packages. The default is $
                   1327:     {PKGSRCDIR}/packages.
                   1328: 
                   1329:   * WRKOBJDIR: The top level directory where, if defined, the separate working
                   1330:     directories will get created, and symbolically linked to from ${WRKDIR}
                   1331:     (see below). This is useful for building packages on several architectures,
                   1332:     then ${PKGSRCDIR} can be NFS-mounted while ${WRKOBJDIR} is local to every
                   1333:     architecture. (It should be noted that PKGSRCDIR should not be set by the
1.198     leot     1334:     user -- it is an internal definition which refers to the root of the pkgsrc
1.1       dsieger  1335:     tree. It is possible to have many pkgsrc tree instances.)
                   1336: 
                   1337:   * LOCALPATCHES: Directory for local patches that aren't part of pkgsrc. See
1.184     rillig   1338:     Section 12.3, "patches/*" for more information.
1.1       dsieger  1339: 
                   1340:   * PKGMAKECONF: Location of the mk.conf file used by a package's BSD-style
                   1341:     Makefile. If this is not set, MAKECONF is set to /dev/null to avoid picking
                   1342:     up settings used by builds in /usr/src.
                   1343: 
1.154     rillig   1344: 6.3. Variables affecting the installation process
1.1       dsieger  1345: 
1.198     leot     1346:   * PKGSRC_KEEP_BIN_PKGS: By default, binary packages of built packages are
1.150     leot     1347:     preserved in ${PACKAGES}/All. Setting this variable to "no" prevents this.
1.1       dsieger  1348: 
1.107     jnemeth  1349: Packages have to support installation into a subdirectory of WRKDIR. This
                   1350: allows a package to be built, before the actual filesystem is touched. DESTDIR
                   1351: support exists in two variations:
1.4       rillig   1352: 
                   1353:   * Basic DESTDIR support means that the package installation and packaging is
                   1354:     still run as root.
                   1355: 
                   1356:   * Full DESTDIR support can run the complete build, installation and packaging
                   1357:     as normal user. Root privileges are only needed to add packages.
                   1358: 
                   1359: With basic DESTDIR support, make clean needs to be run as root.
                   1360: 
1.17      imil     1361: Considering the foo/bar package, DESTDIR full support can be tested using the
                   1362: following commands
                   1363: 
                   1364: $ id
                   1365: uid=1000(myusername) gid=100(users) groups=100(users),0(wheel)
                   1366: $ mkdir $HOME/packages
                   1367: $ cd $PKGSRCDIR/foo/bar
                   1368: 
                   1369: Verify DESTDIR full support, no root privileges should be needed
                   1370: 
1.66      asau     1371: $ make stage-install
1.17      imil     1372: 
                   1373: Create a package without root privileges
                   1374: 
1.66      asau     1375: $ make PACKAGES=$HOME/packages package
1.17      imil     1376: 
                   1377: For the following command, you must be able to gain root privileges using su(1)
                   1378: 
1.66      asau     1379: $ make PACKAGES=$HOME/packages install
1.17      imil     1380: 
                   1381: Then, as a simple user
                   1382: 
                   1383: $ make clean
                   1384: 
1.154     rillig   1385: 6.4. Selecting and configuring the compiler
1.4       rillig   1386: 
1.154     rillig   1387: 6.4.1. Selecting the compiler
1.1       dsieger  1388: 
                   1389: By default, pkgsrc will use GCC to build packages. This may be overridden by
                   1390: setting the following variables in /etc/mk.conf:
                   1391: 
                   1392: PKGSRC_COMPILER:
                   1393: 
                   1394:     This is a list of values specifying the chain of compilers to invoke when
                   1395:     building packages. Valid values are:
                   1396: 
1.232   ! gutterid 1397:       o ccc: Compaq C Compilers (Tru64)
1.66      asau     1398: 
1.232   ! gutterid 1399:       o ccache: compiler cache (chainable)
1.66      asau     1400: 
1.232   ! gutterid 1401:       o clang: Clang C and Objective-C compiler
1.66      asau     1402: 
1.232   ! gutterid 1403:       o distcc: distributed C/C++ (chainable)
1.1       dsieger  1404: 
1.232   ! gutterid 1405:       o f2c: Fortran 77 to C compiler (chainable)
1.66      asau     1406: 
1.232   ! gutterid 1407:       o icc: Intel C++ Compiler (Linux)
1.66      asau     1408: 
1.232   ! gutterid 1409:       o ido: SGI IRIS Development Option cc (IRIX 5)
1.1       dsieger  1410: 
1.232   ! gutterid 1411:       o gcc: GNU C/C++ Compiler
1.1       dsieger  1412: 
1.232   ! gutterid 1413:       o hp: HP-UX C/aC++ compilers
1.66      asau     1414: 
1.232   ! gutterid 1415:       o mipspro: Silicon Graphics, Inc. MIPSpro (n32/n64)
1.1       dsieger  1416: 
1.232   ! gutterid 1417:       o mipspro-ucode: Silicon Graphics, Inc. MIPSpro (o32)
1.1       dsieger  1418: 
1.232   ! gutterid 1419:       o sunpro: Sun Microsystems, Inc. WorkShip/Forte/Sun ONE Studio
1.1       dsieger  1420: 
1.232   ! gutterid 1421:       o xlc: IBM's XL C/C++ compiler suite
1.66      asau     1422: 
1.1       dsieger  1423:     The default is "gcc". You can use ccache and/or distcc with an appropriate
                   1424:     PKGSRC_COMPILER setting, e.g. "ccache gcc". This variable should always be
                   1425:     terminated with a value for a real compiler. Note that only one real
                   1426:     compiler should be listed (e.g. "sunpro gcc" is not allowed).
                   1427: 
                   1428: GCC_REQD:
                   1429: 
                   1430:     This specifies the minimum version of GCC to use when building packages. If
                   1431:     the system GCC doesn't satisfy this requirement, then pkgsrc will build and
                   1432:     install one of the GCC packages to use instead.
                   1433: 
1.153     leot     1434: PYTHON_VERSION_DEFAULT:
1.114     maya     1435: 
                   1436:     Specifies which version of python to use when several options are
                   1437:     available.
                   1438: 
                   1439: PKGSRC_FORTRAN:
                   1440: 
1.176     gutterid 1441:     Specifies the Fortran compiler to use. The default is gfortran.
1.114     maya     1442: 
                   1443: GFORTRAN_VERSION:
                   1444: 
                   1445:     If PKGSRC_FORTRAN= gfortran is used, this option specifies which version to
                   1446:     use.
                   1447: 
1.154     rillig   1448: 6.4.2. Additional flags to the compiler (CFLAGS)
1.1       dsieger  1449: 
                   1450: If you wish to set the CFLAGS variable, please make sure to use the += operator
                   1451: instead of the = operator:
                   1452: 
                   1453: CFLAGS+=        -your -flags
                   1454: 
                   1455: Using CFLAGS= (i.e. without the "+") may lead to problems with packages that
1.16      jnemeth  1456: need to add their own flags. You may want to take a look at the devel/cpuflags
1.24      wiz      1457: package if you're interested in optimization specifically for the current CPU.
1.1       dsieger  1458: 
1.154     rillig   1459: 6.4.3. Additional flags to the linker (LDFLAGS)
1.1       dsieger  1460: 
                   1461: If you want to pass flags to the linker, both in the configure step and the
                   1462: build step, you can do this in two ways. Either set LDFLAGS or LIBS. The
                   1463: difference between the two is that LIBS will be appended to the command line,
                   1464: while LDFLAGS come earlier. LDFLAGS is pre-loaded with rpath settings for ELF
                   1465: machines depending on the setting of USE_IMAKE or the inclusion of mk/
                   1466: x11.buildlink3.mk. As with CFLAGS, if you do not wish to override these
                   1467: settings, use the += operator:
                   1468: 
                   1469: LDFLAGS+=        -your -linkerflags
                   1470: 
1.154     rillig   1471: 6.5. Developer/advanced settings
1.1       dsieger  1472: 
                   1473:   * PKG_DEVELOPER: Run some sanity checks that package developers want:
                   1474: 
1.42      asau     1475:       + make sure patches apply with zero fuzz
1.1       dsieger  1476: 
1.42      asau     1477:       + run check-shlibs to see that all binaries will find their shared libs.
1.1       dsieger  1478: 
1.232   ! gutterid 1479:   * CHECK_FILES_STRICT: Also check VARBASE and PKG_SYSCONFDIR values in PLIST
        !          1480:     entries.
        !          1481: 
1.1       dsieger  1482:   * PKG_DEBUG_LEVEL: The level of debugging output which is displayed whilst
                   1483:     making and installing the package. The default value for this is 0, which
                   1484:     will not display the commands as they are executed (normal, default, quiet
                   1485:     operation); the value 1 will display all shell commands before their
                   1486:     invocation, and the value 2 will display both the shell commands before
1.112     rillig   1487:     their invocation, as well as their actual execution progress with set -x.
1.1       dsieger  1488: 
1.154     rillig   1489: 6.6. Selecting Build Options
1.1       dsieger  1490: 
                   1491: Some packages have build time options, usually to select between different
                   1492: dependencies, enable optional support for big dependencies or enable
                   1493: experimental features.
                   1494: 
                   1495: To see which options, if any, a package supports, and which options are
                   1496: mutually exclusive, run make show-options, for example:
                   1497: 
                   1498:     The following options are supported by this package:
                   1499:         ssl      Enable SSL support.
                   1500:     Exactly one of the following gecko options is required:
                   1501:         firefox  Use firefox as gecko rendering engine.
                   1502:         mozilla  Use mozilla as gecko rendering engine.
                   1503:     At most one of the following database options may be selected:
                   1504:         mysql    Enable support for MySQL database.
                   1505:         pgsql    Enable support for PostgreSQL database.
                   1506: 
                   1507:     These options are enabled by default: firefox
                   1508:     These options are currently enabled: mozilla ssl
                   1509: 
1.4       rillig   1510: The following variables can be defined in mk.conf to select which options to
                   1511: enable for a package: PKG_DEFAULT_OPTIONS, which can be used to select or
1.1       dsieger  1512: disable options for all packages that support them, and PKG_OPTIONS.pkgbase,
                   1513: which can be used to select or disable options specifically for package pkgbase
                   1514: . Options listed in these variables are selected, options preceded by "-" are
                   1515: disabled. A few examples:
                   1516: 
1.4       rillig   1517: $ grep "PKG.*OPTION" mk.conf
1.1       dsieger  1518: PKG_DEFAULT_OPTIONS=    -arts -dvdread -esound
                   1519: PKG_OPTIONS.kdebase=    debug -sasl
                   1520: PKG_OPTIONS.apache=     suexec
                   1521: 
1.11      rillig   1522: It is important to note that options that were specifically suggested by the
1.19      snj      1523: package maintainer must be explicitly removed if you do not wish to include the
                   1524: option. If you are unsure you can view the current state with make show-options
                   1525: .
1.11      rillig   1526: 
1.1       dsieger  1527: The following settings are consulted in the order given, and the last setting
                   1528: that selects or disables an option is used:
                   1529: 
                   1530:  1. the default options as suggested by the package maintainer
                   1531: 
                   1532:  2. the options implied by the settings of legacy variables (see below)
                   1533: 
                   1534:  3. PKG_DEFAULT_OPTIONS
                   1535: 
                   1536:  4. PKG_OPTIONS.pkgbase
                   1537: 
                   1538: For groups of mutually exclusive options, the last option selected is used, all
                   1539: others are automatically disabled. If an option of the group is explicitly
                   1540: disabled, the previously selected option, if any, is used. It is an error if no
                   1541: option from a required group of options is selected, and building the package
                   1542: will fail.
                   1543: 
                   1544: Before the options framework was introduced, build options were selected by
1.4       rillig   1545: setting a variable (often named USE_FOO) in mk.conf for each option. To ease
                   1546: transition to the options framework for the user, these legacy variables are
                   1547: converted to the appropriate options setting (PKG_OPTIONS.pkgbase)
                   1548: automatically. A warning is issued to prompt the user to update mk.conf to use
                   1549: the options framework directly. Support for the legacy variables will be
1.1       dsieger  1550: removed eventually.
                   1551: 
1.154     rillig   1552: Chapter 7. Creating binary packages
1.1       dsieger  1553: 
                   1554: Table of Contents
                   1555: 
1.154     rillig   1556: 7.1. Building a single binary package
                   1557: 7.2. Settings for creation of binary packages
1.1       dsieger  1558: 
1.154     rillig   1559: 7.1. Building a single binary package
1.1       dsieger  1560: 
                   1561: Once you have built and installed a package, you can create a binary package
                   1562: which can be installed on another system with pkg_add(1). This saves having to
                   1563: build the same package on a group of hosts and wasting CPU time. It also
                   1564: provides a simple means for others to install your package, should you
                   1565: distribute it.
                   1566: 
                   1567: To create a binary package, change into the appropriate directory in pkgsrc,
                   1568: and run make package:
                   1569: 
1.112     rillig   1570: $ cd misc/figlet
                   1571: $ make package
1.1       dsieger  1572: 
                   1573: This will build and install your package (if not already done), and then build
                   1574: a binary package from what was installed. You can then use the pkg_* tools to
                   1575: manipulate it. Binary packages are created by default in /usr/pkgsrc/packages,
1.207     leot     1576: in the form of a gzipped tar file. See Section C.2, "Packaging figlet" for a
1.1       dsieger  1577: continuation of the above misc/figlet example.
                   1578: 
1.154     rillig   1579: See Chapter 23, Submitting and Committing for information on how to submit such
1.1       dsieger  1580: a binary package.
                   1581: 
1.154     rillig   1582: 7.2. Settings for creation of binary packages
1.1       dsieger  1583: 
1.184     rillig   1584: See Section 13.17, "Other helpful targets".
1.6       rillig   1585: 
1.154     rillig   1586: Chapter 8. Creating binary packages for everything in pkgsrc (bulk builds)
1.6       rillig   1587: 
                   1588: Table of Contents
                   1589: 
1.154     rillig   1590: 8.1. Preparations
1.180     rillig   1591: 8.2. Running a bulk build
1.154     rillig   1592:     8.2.1. Configuration
                   1593: 8.3. Requirements of a full bulk build
1.178     rillig   1594: 8.4. Bulk build variants
1.179     rillig   1595:     8.4.1. Detect unknown configure options
                   1596:     8.4.2. Detect classes of bugs by forcing compiler warnings
1.181     rillig   1597:     8.4.3. Force compiler options only in the build phase
                   1598:     8.4.4. Use custom directories
                   1599:     8.4.5. Turn warnings into errors
                   1600:     8.4.6. Reject packages for which pkglint reports errors
                   1601:     8.4.7. Reject packages that contain forbidden strings
                   1602:     8.4.8. Reject packages whose self-test fails
                   1603:     8.4.9. Reject packages that use undefined shell variables
                   1604:     8.4.10. Turn off verbose logging
1.178     rillig   1605: 8.5. Creating a multiple CD-ROM packages collection
                   1606:     8.5.1. Example of cdpack
1.6       rillig   1607: 
1.175     gutterid 1608: For a number of reasons, you may want to build binary packages for a large
                   1609: selected set of packages in pkgsrc, or even for all pkgsrc packages. For
1.71      wiz      1610: instance, when you have multiple machines that should run the same software, it
                   1611: is wasted time if they all build their packages themselves from source. Or you
                   1612: may want to build a list of packages you want and check them before deploying
1.175     gutterid 1613: onto production systems. There is a way of getting a set of binary packages:
                   1614: the bulk build system, or pbulk ("p" stands for "parallel"). This chapter
                   1615: describes how to set it up.
1.71      wiz      1616: 
1.154     rillig   1617: 8.1. Preparations
1.71      wiz      1618: 
                   1619: First of all, you have to decide whether you build all packages or a limited
                   1620: set of them. Full bulk builds usually consume a lot more resources, both space
1.175     gutterid 1621: and time, than builds for some practical sets of packages. A number of
                   1622: particularly heavy packages exist that are not actually interesting to a wide
                   1623: audience. (The approximate resource consumption for a full bulk build is given
                   1624: in section Section 8.3, "Requirements of a full bulk build".) For limited bulk
                   1625: builds you need to make a list of packages you want to build. Note that all
                   1626: their dependencies will be built, so you don't need to track them manually.
1.71      wiz      1627: 
                   1628: During bulk builds various packages are installed and deinstalled in /usr/pkg
                   1629: (or whatever LOCALBASE is), so make sure that you don't need any package during
1.112     rillig   1630: the builds. Essentially, you should provide a fresh system, either a chroot
1.71      wiz      1631: environment or something even more restrictive, depending on what the operating
                   1632: system provides, or dedicate the whole physical machine. As a useful side
                   1633: effect this makes sure that bulk builds cannot break anything in your system.
                   1634: There have been numerous cases where certain packages tried to install files
                   1635: outside the LOCALBASE or wanted to edit some files in /etc.
1.6       rillig   1636: 
1.180     rillig   1637: 8.2. Running a bulk build
1.6       rillig   1638: 
1.180     rillig   1639: Running a bulk build works roughly as follows:
1.15      rillig   1640: 
                   1641:   * First, build the pbulk infrastructure in a fresh pkgsrc location.
                   1642: 
                   1643:   * Then, build each of the packages from a clean installation directory using
                   1644:     the infrastructure.
                   1645: 
1.154     rillig   1646: 8.2.1. Configuration
1.6       rillig   1647: 
1.112     rillig   1648: To simplify configuration, we provide the helper script mk/pbulk/pbulk.sh.
1.6       rillig   1649: 
1.68      asau     1650: In order to use it, prepare a clear system (real one, chroot environment, jail,
                   1651: zone, virtual machine). Configure network access to fetch distribution files.
1.112     rillig   1652: Create a user with name "pbulk".
1.68      asau     1653: 
                   1654: Fetch and extract pkgsrc. Use a command like one of these:
                   1655: 
1.151     sevan    1656: # (cd /usr && ftp -o - https://cdn.NetBSD.org/pub/pkgsrc/current/pkgsrc.tar.gz | tar -zxf-)
                   1657: # (cd /usr && fetch -o - https://cdn.NetBSD.org/pub/pkgsrc/current/pkgsrc.tar.gz | tar -zxf-)
1.72      wiz      1658: # (cd /usr && cvs -Q -z3 -d anoncvs@anoncvs.NetBSD.org:/cvsroot get -P pkgsrc)
1.68      asau     1659: 
                   1660: Or any other way that fits (e.g., curl, wget).
                   1661: 
                   1662: Deploy and configure pbulk tools, e.g.:
                   1663: 
1.118     sevan    1664: # sh pbulk.sh -n # use native make, no bootstrap kit needed (for use on NetBSD)
1.68      asau     1665: # sh pbulk.sh -n -c mk.conf.frag # native, apply settings from given mk.conf fragment
                   1666: # sh pbulk.sh -nlc mk.conf.frag # native, apply settings, configure for limited build
                   1667: 
                   1668: Note
                   1669: 
                   1670: mk.conf.frag is a fragment of mk.conf that contains settings you want to apply
                   1671: to packages you build. For instance,
                   1672: 
1.112     rillig   1673: PKG_DEVELOPER=          yes     # perform more checks
                   1674: X11_TYPE=               modular # use pkgsrc X11
                   1675: SKIP_LICENSE_CHECK=     yes     # accept all licences (useful
                   1676:                                 # when building all packages)
1.68      asau     1677: 
                   1678: If configured for limited list, replace the list in /usr/pbulk/etc/pbulk.list
1.112     rillig   1679: with your list of packages, one per line without empty lines or comments. E.g.:
1.68      asau     1680: 
                   1681: www/firefox
                   1682: mail/thunderbird
                   1683: misc/libreoffice4
                   1684: 
1.69      asau     1685: At this point you can also review configuration in /usr/pbulk/etc and make
                   1686: final amendments, if wanted.
                   1687: 
1.68      asau     1688: Start it:
                   1689: 
                   1690: # /usr/pbulk/bin/bulkbuild
                   1691: 
                   1692: After it finishes, you'll have /mnt filled with distribution files, binary
                   1693: packages, and reports, plain text summary in /mnt/bulklog/meta/report.txt
                   1694: 
                   1695: Note
                   1696: 
                   1697: The pbulk.sh script does not cover all possible use cases. While being ready to
                   1698: run, it serves as a good starting point to understand and build more complex
                   1699: setups. The script is kept small enough for better understanding.
                   1700: 
                   1701: Note
                   1702: 
                   1703: The pbulk.sh script supports running unprivileged bulk build and helps
1.205     wiz      1704: configuring distributed bulk builds. Distributed bulk builds support either
                   1705: building in worker chroots (each node is a path to a different chroot) that
                   1706: replicate the target system, including the pbulk prefix, or remote machines
                   1707: (each node is an IP address that must be accessible over SSH without a
                   1708: password).
1.15      rillig   1709: 
1.154     rillig   1710: 8.3. Requirements of a full bulk build
1.71      wiz      1711: 
                   1712: A complete bulk build requires lots of disk space. Some of the disk space can
                   1713: be read-only, some other must be writable. Some can be on remote filesystems
                   1714: (such as NFS) and some should be local. Some can be temporary filesystems,
                   1715: others must survive a sudden reboot.
                   1716: 
1.205     wiz      1717:   * 70 GB for the distfiles (read-write, remote, temporary)
1.71      wiz      1718: 
1.205     wiz      1719:   * 60 GB for the binary packages (read-write, remote, permanent)
1.71      wiz      1720: 
                   1721:   * 1 GB for the pkgsrc tree (read-only, remote, permanent)
                   1722: 
                   1723:   * 5 GB for LOCALBASE (read-write, local, temporary)
                   1724: 
                   1725:   * 10 GB for the log files (read-write, remote, permanent)
                   1726: 
                   1727:   * 5 GB for temporary files (read-write, local, temporary)
                   1728: 
1.178     rillig   1729: 8.4. Bulk build variants
                   1730: 
                   1731: To ensure that pkgsrc packages work in different configurations, it makes sense
                   1732: to run non-default bulk builds from time to time. This section lists some ideas
                   1733: for bulk builds that intentionally let packages fail if they don't follow the
                   1734: pkgsrc style.
                   1735: 
1.179     rillig   1736: 8.4.1. Detect unknown configure options
1.178     rillig   1737: 
                   1738: Add the following line to mk.conf.
                   1739: 
                   1740: GNU_CONFIGURE_STRICT=   yes
                   1741: 
                   1742: When a package fails this additional check, the most common cause is that the
                   1743: configure option was valid for an older version of the package but does not
                   1744: apply anymore. In that case, just remove it.
                   1745: 
1.179     rillig   1746: 8.4.2. Detect classes of bugs by forcing compiler warnings
1.178     rillig   1747: 
                   1748: The job of a compiler is not restricted to producing executable code, most
1.179     rillig   1749: compilers also detect typical programming mistakes. The pkgsrc compiler
                   1750: wrappers make it easy to force compiler options when the package is built. This
                   1751: can be used to find typical bugs across all packages that are in pkgsrc. By
                   1752: reporting these bugs upstream, the packages will be more reliable with the next
                   1753: updates.
1.178     rillig   1754: 
1.179     rillig   1755: Add some of the following lines to mk.conf:
1.178     rillig   1756: 
                   1757: CFLAGS+=        -Werror=char-subscripts
1.179     rillig   1758: CFLAGS+=        -Werror=implicit-function-declaration
1.178     rillig   1759: 
1.179     rillig   1760: When a package fails to build using these stricter compiler options, document
                   1761: the circumstances in which the compiler produced the error message. This
                   1762: includes:
1.178     rillig   1763: 
                   1764:   * The platform (MACHINE_PLATFORM)
                   1765: 
                   1766:   * The source file
                   1767: 
                   1768:   * An excerpt of the code. GCC and Clang already do this as part of the
                   1769:     diagnostic.
                   1770: 
1.179     rillig   1771:   * The exact error message from the compiler.
1.178     rillig   1772: 
1.179     rillig   1773: If a package produces these error messages, but the package is fine, record
                   1774: this in your local mk.conf, like this, to skip this check in the next builds:
1.178     rillig   1775: 
1.179     rillig   1776: .if ${PKGPATH} == category/package
1.178     rillig   1777: # Version ${VERSION} failed on ${MACHINE_PLATFORM}:
                   1778: # error message
                   1779: # code
1.179     rillig   1780: # Reason why the code does not need to be fixed.
1.178     rillig   1781: BUILDLINK_TRANSFORM+=   rm:-Werror=char-subscripts
1.179     rillig   1782: .endif
1.178     rillig   1783: 
                   1784: If the error messages from the compiler are valid and the code needs to be
1.179     rillig   1785: fixed, prepare a local patch (see LOCALPATCHES) and report the bug to the
                   1786: upstream authors of the package, providing them with the information you
                   1787: collected above.
1.178     rillig   1788: 
1.179     rillig   1789: Patches that are not essential for the package to work should only be reported
                   1790: upstream but not committed to pkgsrc, to make future updates easier.
                   1791: 
1.181     rillig   1792: 8.4.3. Force compiler options only in the build phase
                   1793: 
                   1794: When adding custom compiler flags via CFLAGS, these apply to all phases of the
                   1795: package build process. Especially in the configure phase, adding -Werror leads
                   1796: to wrong decisions. The GNU configure scripts feed many small test programs to
                   1797: the C compiler to see whether certain headers are available, functions are
                   1798: defined in a library and programs can be run. In many cases these programs
                   1799: would not survive a strict compiler run with -Wall -Wextra -Werror.
                   1800: 
                   1801: The pkgsrc infrastructure is flexible enough to support compiler options being
                   1802: added between the configure and build phases. It's a little more complicated
                   1803: than the other examples in this section but still easy enough.
                   1804: 
                   1805: The basic idea is to use the pkgsrc compiler wrapper to inject the desired
                   1806: compiler options. The compiler wrapper's original task is to hide unwanted
                   1807: directories of include files and to normalize compiler options. It does this by
                   1808: wrapping the compiler command and rewriting the command line. To see this in
                   1809: action, run bmake patch in a package directory and examine the work/.cwrappers/
                   1810: config directory. It contains individual configurations for the C compiler and
                   1811: the related tools. The plan is to find a hook between the configure and build
                   1812: phases, and to modify these configuration files at that point.
                   1813: 
                   1814: To find this hook, have a look at mk/build/build.mk, which contains among
                   1815: others the pre-build-checks-hook. The word checks doesn't quite fit, but the
                   1816: pre-build-hook sounds good enough.
                   1817: 
                   1818: The code to be included in mk.conf is:
                   1819: 
                   1820: # Just a few example options.
                   1821: BUILD_ONLY_CFLAGS=      -Wall -Werror -O2 -DTEMPDIR='"/tmp"'
                   1822: 
                   1823: .if ${BUILD_ONLY_CFLAGS:U:M*}
                   1824: pre-build-checks-hook: add-build-only-cflags
                   1825: 
                   1826: add-build-only-cflags: .PHONY
                   1827:         ${RUN} cd ${CWRAPPERS_CONFIG_DIR};      \
                   1828:         ${TEST} ! -f ${.TARGET} || exit 0;      \
                   1829:         for flag in ${BUILD_ONLY_CFLAGS}; do    \
                   1830:                 ${ECHO} "append=$$flag" >> cc;  \
                   1831:         done;                                   \
                   1832:         > ${.TARGET}
                   1833: .endif
                   1834: 
                   1835: (When editing the mk.conf, make sure that the commands of the
                   1836: add-build-only-cflags target are indented with a tab, not with spaces.)
                   1837: 
                   1838: The condition in the .if statement contains the :U modifier to prevent parse
                   1839: errors if the variable should be undefined, possibly because it is only defined
                   1840: for a subset of the packages. The :M* modifier ensures that there is at least
                   1841: one compiler option, to prevent a syntax error in the shell parser.
                   1842: 
                   1843: The code around the ${.TARGET} variable ensures that the additional compiler
                   1844: options are only appended once, even if bmake build is run multiple times. To
                   1845: do this, it creates a marker file.
                   1846: 
                   1847: To verify that this setup works, run bmake configure in a package directory. Up
                   1848: to now, everything works as usual. Examine the directory work/.cwrappers/config
                   1849: to see that the compiler options from BUILD_ONLY_CFLAGS are not yet added to
                   1850: the file cc. Examine the tail of the work/.work.log file to see that the normal
                   1851: compiler options are used.
                   1852: 
                   1853: Now run bmake build. This will append the options to the file cc and will
                   1854: create the marker file in the same directory. After that, the build starts as
                   1855: usual, but with the added compiler options. Examine the tail of the file work
                   1856: /.work.log to see that the lines starting with [*] don't contain the compiler
                   1857: options, but the corresponding lines starting with <.> do end with these
                   1858: options.
                   1859: 
                   1860: Building packages using this setup variant and fixing the resulting bugs is the
                   1861: same as in Section 8.4.2, "Detect classes of bugs by forcing compiler warnings"
                   1862: .
                   1863: 
                   1864: 8.4.4. Use custom directories
1.178     rillig   1865: 
                   1866: Some directories like PREFIX, VARBASE, PKG_SYSCONFDIR, PKGMANDIR, PKG_INFODIR
                   1867: can be configured in pkgsrc. Set these to arbitrary paths during bootstrap or
                   1868: afterwards in mk.conf.
                   1869: 
                   1870: PREFIX=         /a-random-uuid
                   1871: PKG_SYSCONFDIR= /a-random-uuid
                   1872: VARBASE=        /a-random-uuid
                   1873: PKGMANDIR=      a-random-uuid
                   1874: PKG_INFODIR=    a-random-uuid
                   1875: 
1.181     rillig   1876: 8.4.5. Turn warnings into errors
1.178     rillig   1877: 
                   1878: When building a package, warnings are typically ignored since they just flow by
                   1879: and do not cause the build to fail immediately. To find these warnings,
                   1880: redefine them to errors in mk.conf.
                   1881: 
                   1882: DELAYED_WARNING_MSG=    ${DELAYED_ERROR_MSG} "(was warning)"
                   1883: WARNING_MSG=            ${FAIL_MSG} "(was warning)"
                   1884: 
                   1885: (There are many more classes of warnings in pkgsrc, and most of them can be
                   1886: redefined with a simple definition like above.
                   1887: 
1.179     rillig   1888: If a package suggests to add USE_TOOLS+=perl to the package Makefile, research
1.178     rillig   1889: whether the package actually needs Perl. If it does, add USE_TOOLS+=perl to the
                   1890: package Makefile, and if it doesn't, add TOOLS_BROKEN+=perl.
                   1891: 
1.181     rillig   1892: 8.4.6. Reject packages for which pkglint reports errors
1.178     rillig   1893: 
                   1894: Using pkglint as part of the regular build process is mostly a waste of time.
                   1895: If you want to fix some of the warnings, just run pkglint recursively on the
                   1896: whole pkgsrc tree. This will take a few minutes (up to 10), which is much
                   1897: faster than a complete bulk build.
                   1898: 
1.181     rillig   1899: 8.4.7. Reject packages that contain forbidden strings
1.178     rillig   1900: 
                   1901: To ensure that the binary packages don't contain references to the build
                   1902: directory, there is already CHECK_WRKREF. If that variable includes the item
                   1903: extra, it is possible to define additional patterns that must not appear in any
                   1904: installed file. This is specified in mk.conf.
                   1905: 
                   1906: CHECK_WRKREF=                   extra
                   1907: CHECK_WRKREF_EXTRA_DIRS+=       /usr/local
                   1908: CHECK_WRKREF_EXTRA_DIRS+=       /usr/pkg
                   1909: CHECK_WRKREF_EXTRA_DIRS+=       @[A-Z][A-Z]*@
                   1910: 
                   1911: The above patterns will probably generate many false positives, therefore the
                   1912: results need to be taken with a grain of salt.
                   1913: 
1.181     rillig   1914: 8.4.8. Reject packages whose self-test fails
1.178     rillig   1915: 
                   1916: To run the test suites that come with each package, add this line to mk.conf.
                   1917: 
                   1918: PKGSRC_RUN_TEST=        yes
                   1919: 
                   1920: Be prepared that even the most basic packages fail this test. When doing a bulk
                   1921: build with this, it will often abort in the early phase where the packages are
                   1922: scanned for their dependencies since there are cyclic dependencies. There is
                   1923: still a lot to do in this area.
                   1924: 
1.181     rillig   1925: 8.4.9. Reject packages that use undefined shell variables
1.178     rillig   1926: 
                   1927: To catch typos in the shell snippets from the Makefile fragments, add the -u
                   1928: flag to most of the commands by adding this line to mk.conf.
                   1929: 
                   1930: RUN=    @set -eu;
                   1931: 
1.181     rillig   1932: After that, ensure that none of the bulk build log files (even those for
                   1933: successfully built packages) contains the string parameter not set or whatever
                   1934: error message the command sh -ceu '$undefined' outputs.
                   1935: 
1.178     rillig   1936: See mk/misc/common.mk for the existing definition.
                   1937: 
1.181     rillig   1938: 8.4.10. Turn off verbose logging
1.178     rillig   1939: 
                   1940: The build logs of a package are often quite long. This allows error messages or
                   1941: other interesting details to hide between the noise. To make the actual error
                   1942: message stand out more, add these lines to mk.conf.
                   1943: 
                   1944: GNU_CONFIGURE_QUIET=    yes
                   1945: MAKE_FLAGS+=            -s
                   1946: 
                   1947: The -s option works for both GNU Make and BSD Make. On exotic platforms with
                   1948: their own make, it may be a little different.
                   1949: 
                   1950: 8.5. Creating a multiple CD-ROM packages collection
1.1       dsieger  1951: 
                   1952: After your pkgsrc bulk-build has completed, you may wish to create a CD-ROM set
                   1953: of the resulting binary packages to assist in installing packages on other
                   1954: machines. The pkgtools/cdpack package provides a simple tool for creating the
                   1955: ISO 9660 images. cdpack arranges the packages on the CD-ROMs in a way that
                   1956: keeps all the dependencies for a given package on the same CD as that package.
                   1957: 
1.178     rillig   1958: 8.5.1. Example of cdpack
1.1       dsieger  1959: 
                   1960: Complete documentation for cdpack is found in the cdpack(1) man page. The
                   1961: following short example assumes that the binary packages are left in /usr/
                   1962: pkgsrc/packages/All and that sufficient disk space exists in /u2 to hold the
                   1963: ISO 9660 images.
                   1964: 
                   1965: # mkdir /u2/images
                   1966: # pkg_add /usr/pkgsrc/packages/All/cdpack
                   1967: # cdpack /usr/pkgsrc/packages/All /u2/images
                   1968: 
                   1969: 
                   1970: If you wish to include a common set of files (COPYRIGHT, README, etc.) on each
                   1971: CD in the collection, then you need to create a directory which contains these
1.175     gutterid 1972: files, e.g.:
1.1       dsieger  1973: 
                   1974: # mkdir /tmp/common
                   1975: # echo "This is a README" > /tmp/common/README
                   1976: # echo "Another file" > /tmp/common/COPYING
                   1977: # mkdir /tmp/common/bin
                   1978: # echo "#!/bin/sh" > /tmp/common/bin/myscript
                   1979: # echo "echo Hello world" >> /tmp/common/bin/myscript
                   1980: # chmod 755 /tmp/common/bin/myscript
                   1981: 
                   1982: 
                   1983: Now create the images:
                   1984: 
                   1985: # cdpack -x /tmp/common /usr/pkgsrc/packages/All /u2/images
                   1986: 
                   1987: Each image will contain README, COPYING, and bin/myscript in their root
                   1988: directories.
                   1989: 
1.154     rillig   1990: Chapter 9. Directory layout of the installed files
1.1       dsieger  1991: 
                   1992: Table of Contents
                   1993: 
1.154     rillig   1994: 9.1. File system layout in ${LOCALBASE}
                   1995: 9.2. File system layout in ${VARBASE}
1.1       dsieger  1996: 
                   1997: The files that are installed by pkgsrc are organized in a way that is similar
                   1998: to what you find in the /usr directory of the base system. But some details are
                   1999: different. This is because pkgsrc initially came from FreeBSD and had adopted
                   2000: its file system hierarchy. Later it was largely influenced by NetBSD. But no
                   2001: matter which operating system you are using pkgsrc with, you can expect the
                   2002: same layout for pkgsrc.
                   2003: 
                   2004: There are mainly four root directories for pkgsrc, which are all configurable
                   2005: in the bootstrap/bootstrap script. When pkgsrc has been installed as root, the
                   2006: default locations are:
                   2007: 
                   2008: LOCALBASE=              /usr/pkg
                   2009: PKG_SYSCONFBASE=        /usr/pkg/etc
                   2010: VARBASE=                /var
1.119     sevan    2011: PKG_DBDIR=              /usr/pkg/pkgdb
1.1       dsieger  2012: 
                   2013: In unprivileged mode (when pkgsrc has been installed as any other user), the
                   2014: default locations are:
                   2015: 
                   2016: LOCALBASE=              ${HOME}/pkg
                   2017: PKG_SYSCONFBASE=        ${HOME}/pkg/etc
                   2018: VARBASE=                ${HOME}/pkg/var
1.119     sevan    2019: PKG_DBDIR=              ${HOME}/pkg/pkgdb
1.1       dsieger  2020: 
                   2021: What these four directories are for, and what they look like is explained
                   2022: below.
                   2023: 
1.25      wiz      2024:   * LOCALBASE corresponds to the /usr directory in the base system. It is the "
                   2025:     main" directory where the files are installed and contains the well-known
1.1       dsieger  2026:     subdirectories like bin, include, lib, share and sbin.
                   2027: 
                   2028:   * VARBASE corresponds to /var in the base system. Some programs (especially
                   2029:     games, network daemons) need write access to it during normal operation.
                   2030: 
                   2031:   * PKG_SYSCONFDIR corresponds to /etc in the base system. It contains
                   2032:     configuration files of the packages, as well as pkgsrc's mk.conf itself.
                   2033: 
1.154     rillig   2034: 9.1. File system layout in ${LOCALBASE}
1.1       dsieger  2035: 
                   2036: The following directories exist in a typical pkgsrc installation in $
                   2037: {LOCALBASE}.
                   2038: 
                   2039: bin
                   2040: 
                   2041:     Contains executable programs that are intended to be directly used by the
                   2042:     end user.
                   2043: 
                   2044: emul
                   2045: 
                   2046:     Contains files for the emulation layers of various other operating systems,
                   2047:     especially for NetBSD.
                   2048: 
                   2049: etc (the usual location of ${PKG_SYSCONFDIR})
                   2050: 
                   2051:     Contains the configuration files.
                   2052: 
                   2053: include
                   2054: 
                   2055:     Contains headers for the C and C++ programming languages.
                   2056: 
                   2057: info
                   2058: 
                   2059:     Contains GNU info files of various packages.
                   2060: 
                   2061: lib
                   2062: 
                   2063:     Contains shared and static libraries.
                   2064: 
                   2065: libdata
                   2066: 
                   2067:     Contains data files that don't change after installation. Other data files
                   2068:     belong into ${VARBASE}.
                   2069: 
                   2070: libexec
                   2071: 
                   2072:     Contains programs that are not intended to be used by end users, such as
                   2073:     helper programs or network daemons.
                   2074: 
                   2075: libexec/cgi-bin
                   2076: 
                   2077:     Contains programs that are intended to be executed as CGI scripts by a web
                   2078:     server.
                   2079: 
                   2080: man (the usual value of ${PKGMANDIR})
                   2081: 
                   2082:     Contains brief documentation in form of manual pages.
                   2083: 
                   2084: sbin
                   2085: 
                   2086:     Contains programs that are intended to be used only by the super-user.
                   2087: 
                   2088: share
                   2089: 
                   2090:     Contains platform-independent data files that don't change after
                   2091:     installation.
                   2092: 
                   2093: share/doc
                   2094: 
                   2095:     Contains documentation files provided by the packages.
                   2096: 
                   2097: share/examples
                   2098: 
                   2099:     Contains example files provided by the packages. Among others, the original
                   2100:     configuration files are saved here and copied to ${PKG_SYSCONFDIR} during
                   2101:     installation.
                   2102: 
                   2103: share/examples/rc.d
                   2104: 
                   2105:     Contains the original files for rc.d scripts.
                   2106: 
                   2107: var (the usual location of ${VARBASE})
                   2108: 
                   2109:     Contains files that may be modified after installation.
                   2110: 
1.154     rillig   2111: 9.2. File system layout in ${VARBASE}
1.1       dsieger  2112: 
                   2113: db/pkg (the usual location of ${PKG_DBDIR})
                   2114: 
                   2115:     Contains information about the currently installed packages.
                   2116: 
                   2117: games
                   2118: 
                   2119:     Contains highscore files.
                   2120: 
                   2121: log
                   2122: 
                   2123:     Contains log files.
                   2124: 
                   2125: run
                   2126: 
                   2127:     Contains informational files about daemons that are currently running.
                   2128: 
1.154     rillig   2129: Chapter 10. Frequently Asked Questions
1.1       dsieger  2130: 
                   2131: Table of Contents
                   2132: 
1.154     rillig   2133: 10.1. Are there any mailing lists for pkg-related discussion?
                   2134: 10.2. Utilities for package management (pkgtools)
                   2135: 10.3. How to use pkgsrc as non-root
                   2136: 10.4. How to resume transfers when fetching distfiles?
                   2137: 10.5. How can I install/use modular X.org from pkgsrc?
                   2138: 10.6. How to fetch files from behind a firewall
                   2139: 10.7. How to fetch files from HTTPS sites
                   2140: 10.8. How do I tell make fetch to do passive FTP?
                   2141: 10.9. How to fetch all distfiles at once
                   2142: 10.10. What does "Don't know how to make /usr/share/tmac/tmac.andoc" mean?
                   2143: 10.11. What does "Could not find bsd.own.mk" mean?
1.221     nia      2144: 10.12. Using 'sudo' or `priv` with pkgsrc
1.154     rillig   2145: 10.13. How do I change the location of configuration files?
                   2146: 10.14. Automated security checks
                   2147: 10.15. Why do some packages ignore my CFLAGS?
                   2148: 10.16. A package does not build. What shall I do?
                   2149: 10.17. What does "Makefile appears to contain unresolved cvs/rcs/??? merge
1.232   ! gutterid 2150: conflicts" mean?
1.1       dsieger  2151: 
                   2152: This section contains hints, tips & tricks on special things in pkgsrc that we
                   2153: didn't find a better place for in the previous chapters, and it contains items
                   2154: for both pkgsrc users and developers.
                   2155: 
1.154     rillig   2156: 10.1. Are there any mailing lists for pkg-related discussion?
1.1       dsieger  2157: 
                   2158: The following mailing lists may be of interest to pkgsrc users:
                   2159: 
                   2160:   * pkgsrc-users: This is a general purpose list for most issues regarding
                   2161:     pkgsrc, regardless of platform, e.g. soliciting user help for pkgsrc
                   2162:     configuration, unexpected build failures, using particular packages,
                   2163:     upgrading pkgsrc installations, questions regarding the pkgsrc release
                   2164:     branches, etc. General announcements or proposals for changes that impact
                   2165:     the pkgsrc user community, e.g. major infrastructure changes, new features,
                   2166:     package removals, etc., may also be posted.
                   2167: 
                   2168:   * pkgsrc-bulk: A list where the results of pkgsrc bulk builds are sent and
                   2169:     discussed.
                   2170: 
                   2171:   * pkgsrc-changes: This list is for those who are interested in getting a
                   2172:     commit message for every change committed to pkgsrc. It is also available
                   2173:     in digest form, meaning one daily message containing all commit messages
                   2174:     for changes to the package source tree in that 24 hour period.
                   2175: 
                   2176: To subscribe, do:
                   2177: 
                   2178: % echo subscribe listname | mail majordomo@NetBSD.org
                   2179: 
1.174     leot     2180: Archives for all these mailing lists are available from https://
1.1       dsieger  2181: mail-index.NetBSD.org/.
                   2182: 
1.154     rillig   2183: 10.2. Utilities for package management (pkgtools)
1.1       dsieger  2184: 
                   2185: The directory pkgsrc/pkgtools contains a number of useful utilities for both
                   2186: users and developers of pkgsrc. This section attempts only to make the reader
1.121     sevan    2187: aware of some of the utilities and when they might be useful, and not to
                   2188: duplicate the documentation that comes with each package.
1.1       dsieger  2189: 
                   2190: Utilities used by pkgsrc (automatically installed when needed):
                   2191: 
                   2192:   * pkgtools/x11-links: Symlinks for use by buildlink.
                   2193: 
                   2194: OS tool augmentation (automatically installed when needed):
                   2195: 
1.121     sevan    2196:   * pkgtools/digest: Calculates various kinds of checksums (including SHA3).
1.1       dsieger  2197: 
                   2198:   * pkgtools/libnbcompat: Compatibility library for pkgsrc tools.
                   2199: 
                   2200:   * pkgtools/mtree: Installed on non-BSD systems due to lack of native mtree.
                   2201: 
                   2202:   * pkgtools/pkg_install: Up-to-date replacement for /usr/sbin/pkg_install, or
                   2203:     for use on operating systems where pkg_install is not present.
                   2204: 
                   2205: Utilities used by pkgsrc (not automatically installed):
                   2206: 
                   2207:   * pkgtools/pkg_tarup: Create a binary package from an already-installed
                   2208:     package. Used by make replace to save the old package.
                   2209: 
                   2210:   * pkgtools/dfdisk: Adds extra functionality to pkgsrc, allowing it to fetch
                   2211:     distfiles from multiple locations. It currently supports the following
                   2212:     methods: multiple CD-ROMs and network FTP/HTTP connections.
                   2213: 
                   2214:   * devel/cpuflags: Determine the best compiler flags to optimise code for your
1.24      wiz      2215:     current CPU and compiler.
1.1       dsieger  2216: 
                   2217: Utilities for keeping track of installed packages, being up to date, etc:
                   2218: 
1.65      wiz      2219:   * pkgtools/pkgin: A package update tool similar to apt(1). Download, install,
                   2220:     and upgrade binary packages easily.
                   2221: 
1.1       dsieger  2222:   * pkgtools/pkg_chk: Reports on packages whose installed versions do not match
                   2223:     the latest pkgsrc entries.
                   2224: 
                   2225:   * pkgtools/pkgdep: Makes dependency graphs of packages, to aid in choosing a
                   2226:     strategy for updating.
                   2227: 
                   2228:   * pkgtools/pkgdepgraph: Makes graphs from the output of pkgtools/pkgdep (uses
                   2229:     graphviz).
                   2230: 
1.12      weinem   2231:   * pkgtools/pkglint: The pkglint(1) program checks a pkgsrc entry for errors.
                   2232: 
                   2233:   * pkgtools/lintpkgsrc: The lintpkgsrc(1) program does various checks on the
                   2234:     complete pkgsrc system.
1.1       dsieger  2235: 
                   2236:   * pkgtools/pkgsurvey: Report what packages you have installed.
                   2237: 
                   2238: Utilities for people maintaining or creating individual packages:
                   2239: 
                   2240:   * pkgtools/pkgdiff: Automate making and maintaining patches for a package
                   2241:     (includes pkgdiff, pkgvi, mkpatches, etc.).
                   2242: 
1.65      wiz      2243:   * pkgtools/url2pkg: Aids in converting to pkgsrc.
1.1       dsieger  2244: 
                   2245: Utilities for people maintaining pkgsrc (or: more obscure pkg utilities)
                   2246: 
                   2247:   * pkgtools/pkg_comp: Build packages in a chrooted area.
                   2248: 
                   2249:   * pkgtools/libkver: Spoof kernel version for chrooted cross builds.
                   2250: 
1.154     rillig   2251: 10.3. How to use pkgsrc as non-root
1.1       dsieger  2252: 
1.108     rillig   2253: To install packages from source as a non-root user, download pkgsrc as
1.154     rillig   2254: described in Chapter 3, Where to get pkgsrc and how to keep it up-to-date, cd
1.108     rillig   2255: into that directory and run the command ./bootstrap/bootstrap --unprivileged.
                   2256: 
                   2257: This will install the binary part of pkgsrc to ~/pkg and put the pkgsrc
                   2258: configuration mk.conf into ~/pkg/etc.
                   2259: 
                   2260: For more details, see mk/unprivileged.mk.
1.1       dsieger  2261: 
1.154     rillig   2262: 10.4. How to resume transfers when fetching distfiles?
1.1       dsieger  2263: 
                   2264: By default, resuming transfers in pkgsrc is disabled, but you can enable this
1.4       rillig   2265: feature by adding the option PKG_RESUME_TRANSFERS=YES into mk.conf. If, during
                   2266: a fetch step, an incomplete distfile is found, pkgsrc will try to resume it.
1.1       dsieger  2267: 
1.61      wiz      2268: You can also use a different program than the platform default program by
                   2269: changing the FETCH_USING variable. You can specify the program by using of ftp,
                   2270: fetch, wget or curl. Alternatively, fetching can be disabled by using the value
                   2271: manual. A value of custom disables the system defaults and dependency tracking
                   2272: for the fetch program. In that case you have to provide FETCH_CMD,
                   2273: FETCH_BEFORE_ARGS, FETCH_RESUME_ARGS, FETCH_OUTPUT_ARGS, FETCH_AFTER_ARGS.
1.1       dsieger  2274: 
1.16      jnemeth  2275: For example, if you want to use wget to download, you'll have to use something
                   2276: like:
1.1       dsieger  2277: 
1.16      jnemeth  2278: FETCH_USING=    wget
1.1       dsieger  2279: 
1.154     rillig   2280: 10.5. How can I install/use modular X.org from pkgsrc?
1.1       dsieger  2281: 
1.4       rillig   2282: If you want to use modular X.org from pkgsrc instead of your system's own X11
                   2283: (/usr/X11R6, /usr/openwin, ...) you will have to add the following line into
1.1       dsieger  2284: mk.conf:
                   2285: 
1.4       rillig   2286: X11_TYPE=modular
1.1       dsieger  2287: 
1.154     rillig   2288: 10.6. How to fetch files from behind a firewall
1.1       dsieger  2289: 
                   2290: If you are sitting behind a firewall which does not allow direct connections to
                   2291: Internet hosts (i.e. non-NAT), you may specify the relevant proxy hosts. This
                   2292: is done using an environment variable in the form of a URL, e.g. in Amdahl, the
                   2293: machine "orpheus.amdahl.com" is one of the firewalls, and it uses port 80 as
                   2294: the proxy port number. So the proxy environment variables are:
                   2295: 
                   2296: ftp_proxy=ftp://orpheus.amdahl.com:80/
                   2297: http_proxy=http://orpheus.amdahl.com:80/
                   2298: 
1.154     rillig   2299: 10.7. How to fetch files from HTTPS sites
1.65      wiz      2300: 
                   2301: Some fetch tools are not prepared to support HTTPS by default (for example, the
                   2302: one in NetBSD 6.0), or the one installed by the pkgsrc bootstrap (to avoid an
                   2303: openssl dependency that low in the dependency graph).
                   2304: 
                   2305: Usually you won't notice, because distribution files are mirrored weekly to "
                   2306: ftp.NetBSD.org", but that might not be often enough if you are following
                   2307: pkgsrc-current. In that case, set FETCH_USING in your mk.conf file to "curl" or
                   2308: "wget", which are both compiled with HTTPS support by default. Of course, these
                   2309: tools need to be installed before you can use them this way.
                   2310: 
1.154     rillig   2311: 10.8. How do I tell make fetch to do passive FTP?
1.1       dsieger  2312: 
                   2313: This depends on which utility is used to retrieve distfiles. From bsd.pkg.mk,
                   2314: FETCH_CMD is assigned the first available command from the following list:
                   2315: 
                   2316:   * ${LOCALBASE}/bin/ftp
                   2317: 
                   2318:   * /usr/bin/ftp
                   2319: 
                   2320: On a default NetBSD installation, this will be /usr/bin/ftp, which
                   2321: automatically tries passive connections first, and falls back to active
                   2322: connections if the server refuses to do passive. For the other tools, add the
1.4       rillig   2323: following to your mk.conf file: PASSIVE_FETCH=1.
1.1       dsieger  2324: 
                   2325: Having that option present will prevent /usr/bin/ftp from falling back to
                   2326: active transfers.
                   2327: 
1.154     rillig   2328: 10.9. How to fetch all distfiles at once
1.1       dsieger  2329: 
                   2330: You would like to download all the distfiles in a single batch from work or
                   2331: university, where you can't run a make fetch. There is an archive of distfiles
                   2332: on ftp.NetBSD.org, but downloading the entire directory may not be appropriate.
                   2333: 
                   2334: The answer here is to do a make fetch-list in /usr/pkgsrc or one of its
                   2335: subdirectories, carry the resulting list to your machine at work/school and use
                   2336: it there. If you don't have a NetBSD-compatible ftp(1) (like tnftp) at work,
                   2337: don't forget to set FETCH_CMD to something that fetches a URL:
                   2338: 
                   2339: At home:
                   2340: 
                   2341: % cd /usr/pkgsrc
                   2342: % make fetch-list FETCH_CMD=wget DISTDIR=/tmp/distfiles >/tmp/fetch.sh
                   2343: % scp /tmp/fetch.sh work:/tmp
                   2344: 
                   2345: At work:
                   2346: 
                   2347: % sh /tmp/fetch.sh
                   2348: 
                   2349: then tar up /tmp/distfiles and take it home.
                   2350: 
                   2351: If you have a machine running NetBSD, and you want to get all distfiles (even
                   2352: ones that aren't for your machine architecture), you can do so by using the
                   2353: above-mentioned make fetch-list approach, or fetch the distfiles directly by
                   2354: running:
                   2355: 
                   2356: % make mirror-distfiles
                   2357: 
                   2358: If you even decide to ignore NO_{SRC,BIN}_ON_{FTP,CDROM}, then you can get
                   2359: everything by running:
                   2360: 
                   2361: % make fetch NO_SKIP=yes
                   2362: 
1.154     rillig   2363: 10.10. What does "Don't know how to make /usr/share/tmac/tmac.andoc" mean?
1.1       dsieger  2364: 
                   2365: When compiling the pkgtools/pkg_install package, you get the error from make
                   2366: that it doesn't know how to make /usr/share/tmac/tmac.andoc? This indicates
                   2367: that you don't have installed the "text" set (nroff, ...) from the NetBSD base
                   2368: distribution on your machine. It is recommended to do that to format man pages.
                   2369: 
                   2370: In the case of the pkgtools/pkg_install package, you can get away with setting
1.4       rillig   2371: NOMAN=YES either in the environment or in mk.conf.
1.1       dsieger  2372: 
1.154     rillig   2373: 10.11. What does "Could not find bsd.own.mk" mean?
1.1       dsieger  2374: 
                   2375: You didn't install the compiler set, comp.tgz, when you installed your NetBSD
                   2376: machine. Please get and install it, by extracting it in /:
                   2377: 
                   2378: # cd /
                   2379: # tar --unlink -zxvpf .../comp.tgz
                   2380: 
                   2381: comp.tgz is part of every NetBSD release. Get the one that corresponds to your
                   2382: release (determine via uname -r).
                   2383: 
1.221     nia      2384: 10.12. Using 'sudo' or `priv` with pkgsrc
1.1       dsieger  2385: 
                   2386: When installing packages as non-root user and using the just-in-time su(1)
                   2387: feature of pkgsrc, it can become annoying to type in the root password for each
                   2388: required package installed. To avoid this, the sudo package can be used, which
1.221     nia      2389: does password caching over a limited time. To use it, install sudo or priv
                   2390: (either as binary package, from security/priv, or security/sudo) and then put
                   2391: the following into your mk.conf, somewhere after the definition of the
                   2392: LOCALBASE variable:
1.1       dsieger  2393: 
                   2394: .if exists(${LOCALBASE}/bin/sudo)
                   2395: SU_CMD=        ${LOCALBASE}/bin/sudo /bin/sh -c
                   2396: .endif
                   2397: 
1.154     rillig   2398: 10.13. How do I change the location of configuration files?
1.1       dsieger  2399: 
                   2400: As the system administrator, you can choose where configuration files are
                   2401: installed. The default settings make all these files go into ${PREFIX}/etc or
                   2402: some of its subdirectories; this may be suboptimal depending on your
                   2403: expectations (e.g., a read-only, NFS-exported PREFIX with a need of per-machine
                   2404: configuration of the provided packages).
                   2405: 
                   2406: In order to change the defaults, you can modify the PKG_SYSCONFBASE variable
1.4       rillig   2407: (in mk.conf) to point to your preferred configuration directory; some common
                   2408: examples include /etc or /etc/pkg.
1.1       dsieger  2409: 
                   2410: Furthermore, you can change this value on a per-package basis by setting the
                   2411: PKG_SYSCONFDIR.${PKG_SYSCONFVAR} variable. PKG_SYSCONFVAR's value usually
                   2412: matches the name of the package you would like to modify, that is, the contents
                   2413: of PKGBASE.
                   2414: 
                   2415: Note that after changing these settings, you must rebuild and reinstall any
                   2416: affected packages.
                   2417: 
1.154     rillig   2418: 10.14. Automated security checks
1.1       dsieger  2419: 
                   2420: Please be aware that there can often be bugs in third-party software, and some
                   2421: of these bugs can leave a machine vulnerable to exploitation by attackers. In
                   2422: an effort to lessen the exposure, the NetBSD packages team maintains a database
                   2423: of known-exploits to packages which have at one time been included in pkgsrc.
                   2424: The database can be downloaded automatically, and a security audit of all
1.14      jmcneill 2425: packages installed on a system can take place. To do this, refer to the
                   2426: following two tools (installed as part of the pkgtools/pkg_install package):
1.1       dsieger  2427: 
1.21      snj      2428:  1. pkg_admin fetch-pkg-vulnerabilities, an easy way to download a list of the
                   2429:     security vulnerabilities information. This list is kept up to date by the
1.26      spz      2430:     pkgsrc security team, and is distributed from the NetBSD ftp server:
1.1       dsieger  2431: 
1.177     leot     2432:     https://ftp.NetBSD.org/pub/NetBSD/packages/vulns/pkg-vulnerabilities
1.1       dsieger  2433: 
1.21      snj      2434:  2. pkg_admin audit, an easy way to audit the current machine, checking each
1.24      wiz      2435:     known vulnerability. If a vulnerable package is installed, it will be shown
                   2436:     by output to stdout, including a description of the type of vulnerability,
                   2437:     and a URL containing more information.
1.1       dsieger  2438: 
1.202     nia      2439: Use of these tools is strongly recommended! See Section 5.1.6, "Checking for
1.121     sevan    2440: security vulnerabilities in installed packages" for instructions on how to
                   2441: automate checking and reporting.
                   2442: 
                   2443: If this database is installed, pkgsrc builds will use it to perform a security
                   2444: check before building any package.
1.1       dsieger  2445: 
1.154     rillig   2446: 10.15. Why do some packages ignore my CFLAGS?
1.1       dsieger  2447: 
                   2448: When you add your own preferences to the CFLAGS variable in your mk.conf, these
                   2449: flags are passed in environment variables to the ./configure scripts and to
                   2450: make(1). Some package authors ignore the CFLAGS from the environment variable
                   2451: by overriding them in the Makefiles of their package.
                   2452: 
                   2453: Currently there is no solution to this problem. If you really need the package
                   2454: to use your CFLAGS you should run make patch in the package directory and then
                   2455: inspect any Makefile and Makefile.in for whether they define CFLAGS explicitly.
                   2456: Usually you can remove these lines. But be aware that some "smart" programmers
                   2457: write so bad code that it only works for the specific combination of CFLAGS
                   2458: they have chosen.
                   2459: 
1.172     rillig   2460: To find out where the CFLAGS are ignored, add the following lines to mk.conf:
                   2461: 
                   2462: CPPFLAGS+=              -Dpkgsrc___CPPFLAGS
                   2463: CFLAGS+=                -Dpkgsrc___CFLAGS
                   2464: CXXFLAGS+=              -Dpkgsrc___CXXFLAGS
                   2465: 
                   2466: Then run bmake show-all-configure show-all-build to see whether the above flags
                   2467: are passed to the actual build commands in general.
                   2468: 
                   2469: To find out whether the flags are passed to individual compiler commands, have
                   2470: a look at the file work/.work.log. In most cases, the flags from the original
                   2471: command lines (the lines starting with [*]) are passed unmodified to the actual
                   2472: compiler (the lines starting with <.>). If the flag is missing from the actual
                   2473: compiler command, it must have been removed by the pkgsrc compiler wrappers.
                   2474: 
1.154     rillig   2475: 10.16. A package does not build. What shall I do?
1.1       dsieger  2476: 
                   2477:  1. Make sure that your copy of pkgsrc is consistent. A case that occurs often
                   2478:     is that people only update pkgsrc in parts, because of performance reasons.
                   2479:     Since pkgsrc is one large system, not a collection of many small systems,
                   2480:     there are sometimes changes that only work when the whole pkgsrc tree is
                   2481:     updated.
                   2482: 
1.25      wiz      2483:  2. Make sure that you don't have any CVS conflicts. Search for "<<<<<<" or "
                   2484:     >>>>>>" in all your pkgsrc files.
1.1       dsieger  2485: 
1.25      wiz      2486:  3. Make sure that you don't have old copies of the packages extracted. Run 
1.1       dsieger  2487:     make clean clean-depends to verify this.
                   2488: 
1.108     rillig   2489:  4. If you are a package developer who wants to invest some work, have a look
1.154     rillig   2490:     at Chapter 21, Making your package work.
1.108     rillig   2491: 
                   2492:  5. If the problem still exists, write a mail to the pkgsrc-users mailing list.
1.1       dsieger  2493: 
1.154     rillig   2494: 10.17. What does "Makefile appears to contain unresolved cvs/rcs/??? merge
1.1       dsieger  2495: conflicts" mean?
                   2496: 
                   2497: You have modified a file from pkgsrc, and someone else has modified that same
                   2498: file afterwards in the CVS repository. Both changes are in the same region of
                   2499: the file, so when you updated pkgsrc, the cvs command marked the conflicting
                   2500: changes in the file. Because of these markers, the file is no longer a valid
                   2501: Makefile.
                   2502: 
                   2503: Have a look at that file, and if you don't need your local changes anymore, you
                   2504: can remove that file and run cvs -q update -dP in that directory to download
                   2505: the current version.
                   2506: 
                   2507: Part II. The pkgsrc developer's guide
                   2508: 
                   2509: This part of the book deals with creating and modifying packages. It starts
                   2510: with a "HOWTO"-like guide on creating a new package. The remaining chapters are
                   2511: more like a reference manual for pkgsrc.
                   2512: 
                   2513: Table of Contents
                   2514: 
1.154     rillig   2515: 11. Getting help
1.184     rillig   2516: 12. Package components - files, directories and contents
                   2517:     12.1. Makefile
                   2518:     12.2. distinfo
                   2519:     12.3. patches/*
                   2520:         12.3.1. Structure of a single patch file
                   2521:         12.3.2. Creating patch files
                   2522:         12.3.3. Sources where the patch files come from
                   2523:         12.3.4. Patching guidelines
                   2524:         12.3.5. Feedback to the author
                   2525:     12.4. Other mandatory files
                   2526:     12.5. Optional files
                   2527:         12.5.1. Files affecting the binary package
                   2528:         12.5.2. Files affecting the build process
                   2529:         12.5.3. Files affecting nothing at all
                   2530:     12.6. work*
                   2531:     12.7. files/*
                   2532: 13. The build process
                   2533:     13.1. Introduction
                   2534:     13.2. Program location
                   2535:     13.3. Directories used during the build process
                   2536:     13.4. Running a phase
                   2537:     13.5. The fetch phase
                   2538:         13.5.1. What to fetch and where to get it from
                   2539:         13.5.2. How are the files fetched?
                   2540:     13.6. The checksum phase
                   2541:     13.7. The extract phase
                   2542:     13.8. The patch phase
                   2543:     13.9. The tools phase
                   2544:     13.10. The wrapper phase
                   2545:     13.11. The configure phase
                   2546:     13.12. The build phase
                   2547:     13.13. The test phase
                   2548:     13.14. The install phase
                   2549:     13.15. The package phase
                   2550:     13.16. Cleaning up
                   2551:     13.17. Other helpful targets
                   2552: 14. Creating a new pkgsrc package from scratch
                   2553:     14.1. Common types of packages
1.219     nia      2554:         14.1.1. Python modules and programs
                   2555:         14.1.2. R packages
                   2556:         14.1.3. TeXlive packages
1.184     rillig   2557:     14.2. Examples
                   2558:         14.2.1. How the www/nvu package came into pkgsrc
                   2559: 15. Programming in Makefiles
                   2560:     15.1. Caveats
                   2561:     15.2. Makefile variables
                   2562:         15.2.1. Naming conventions
                   2563:     15.3. Code snippets
                   2564:         15.3.1. Adding things to a list
                   2565:         15.3.2. Echoing a string exactly as-is
                   2566:         15.3.3. Passing CFLAGS to GNU configure scripts
                   2567:         15.3.4. Handling possibly empty variables
1.229     gutterid 2568:         15.3.5. Testing yes/no variables in conditions
1.184     rillig   2569: 16. Options handling
                   2570:     16.1. Global default options
                   2571:     16.2. Converting packages to use bsd.options.mk
                   2572:     16.3. Option Names
                   2573:     16.4. Determining the options of dependencies
                   2574: 17. Tools needed for building or running
                   2575:     17.1. Tools for pkgsrc builds
                   2576:     17.2. Tools needed by packages
                   2577:     17.3. Tools provided by platforms
                   2578: 18. Buildlink methodology
                   2579:     18.1. Converting packages to use buildlink3
                   2580:     18.2. Writing buildlink3.mk files
                   2581:         18.2.1. Anatomy of a buildlink3.mk file
                   2582:         18.2.2. Updating BUILDLINK_API_DEPENDS.pkg and BUILDLINK_ABI_DEPENDS.
1.232   ! gutterid 2583:         pkg in buildlink3.mk files
1.184     rillig   2584:     18.3. Writing builtin.mk files
                   2585:         18.3.1. Anatomy of a builtin.mk file
                   2586:         18.3.2. Global preferences for native or pkgsrc software
                   2587: 19. PLIST issues
                   2588:     19.1. RCS ID
                   2589:     19.2. Semi-automatic PLIST generation
                   2590:     19.3. Tweaking output of make print-PLIST
                   2591:     19.4. Variable substitution in PLIST
                   2592:     19.5. Man page compression
                   2593:     19.6. Changing PLIST source with PLIST_SRC
                   2594:     19.7. Platform-specific and differing PLISTs
                   2595:     19.8. Build-specific PLISTs
                   2596:     19.9. Sharing directories between packages
                   2597: 20. The pkginstall framework
                   2598:     20.1. Files and directories outside the installation prefix
                   2599:         20.1.1. Directory manipulation
                   2600:         20.1.2. File manipulation
                   2601:     20.2. Configuration files
                   2602:         20.2.1. How PKG_SYSCONFDIR is set
                   2603:         20.2.2. Telling the software where configuration files are
                   2604:         20.2.3. Patching installations
                   2605:         20.2.4. Disabling handling of configuration files
                   2606:     20.3. System startup scripts
                   2607:         20.3.1. Disabling handling of system startup scripts
                   2608:     20.4. System users and groups
                   2609:     20.5. System shells
                   2610:         20.5.1. Disabling shell registration
                   2611:     20.6. Fonts
                   2612:         20.6.1. Disabling automatic update of the fonts databases
1.154     rillig   2613: 21. Making your package work
                   2614:     21.1. General operation
                   2615:         21.1.1. How to pull in user-settable variables from mk.conf
                   2616:         21.1.2. User interaction
                   2617:         21.1.3. Handling licenses
                   2618:         21.1.4. Restricted packages
                   2619:         21.1.5. Handling dependencies
                   2620:         21.1.6. Handling conflicts with other packages
                   2621:         21.1.7. Packages that cannot or should not be built
                   2622:         21.1.8. Packages which should not be deleted, once installed
                   2623:         21.1.9. Handling packages with security problems
                   2624:         21.1.10. How to handle incrementing versions when fixing an existing
1.232   ! gutterid 2625:         package
1.154     rillig   2626:         21.1.11. Substituting variable text in the package files (the SUBST
1.232   ! gutterid 2627:         framework)
1.154     rillig   2628:     21.2. The fetch phase
                   2629:         21.2.1. Packages whose distfiles aren't available for plain downloading
                   2630:         21.2.2. How to handle modified distfiles with the 'old' name
                   2631:         21.2.3. Packages hosted on github.com
                   2632:     21.3. The configure phase
                   2633:         21.3.1. Shared libraries - libtool
                   2634:         21.3.2. Using libtool on GNU packages that already support libtool
                   2635:         21.3.3. GNU Autoconf/Automake
1.223     nia      2636:         21.3.4. Meson / ninja
1.154     rillig   2637:     21.4. Programming languages
                   2638:         21.4.1. C, C++, and Fortran
                   2639:         21.4.2. Java
1.205     wiz      2640:         21.4.3. Go
1.223     nia      2641:         21.4.4. Rust
                   2642:         21.4.5. Packages containing Perl scripts
                   2643:         21.4.6. Packages containing shell scripts
                   2644:         21.4.7. Other programming languages
1.154     rillig   2645:     21.5. The build phase
                   2646:         21.5.1. Compiling C and C++ code conditionally
                   2647:         21.5.2. How to handle compiler bugs
1.172     rillig   2648:         21.5.3. No such file or directory
                   2649:         21.5.4. Undefined reference to "..."
                   2650:         21.5.5. Running out of memory
1.154     rillig   2651:     21.6. The install phase
                   2652:         21.6.1. Creating needed directories
                   2653:         21.6.2. Where to install documentation
                   2654:         21.6.3. Installing highscore files
                   2655:         21.6.4. Adding DESTDIR support to packages
                   2656:         21.6.5. Packages with hardcoded paths to other interpreters
1.203     nia      2657:         21.6.6. Packages installing Perl modules
1.154     rillig   2658:         21.6.7. Packages installing info files
                   2659:         21.6.8. Packages installing man pages
1.203     nia      2660:         21.6.9. Packages installing X11 fonts
                   2661:         21.6.10. Packages installing SGML or XML data
                   2662:         21.6.11. Packages installing extensions to the MIME database
                   2663:         21.6.12. Packages using intltool
                   2664:         21.6.13. Packages installing startup scripts
                   2665:         21.6.14. Packages installing TeX modules
                   2666:         21.6.15. Packages supporting running binaries in emulation
                   2667:         21.6.16. Packages installing hicolor icons
                   2668:         21.6.17. Packages installing desktop files
1.154     rillig   2669:     21.7. Marking packages as having problems
1.184     rillig   2670: 22. GNOME packaging and porting
                   2671:     22.1. Meta packages
                   2672:     22.2. Packaging a GNOME application
                   2673:     22.3. Updating GNOME to a newer version
                   2674:     22.4. Patching guidelines
1.154     rillig   2675: 23. Submitting and Committing
                   2676:     23.1. Submitting binary packages
                   2677:     23.2. Submitting source packages (for non-NetBSD-developers)
                   2678:     23.3. General notes when adding, updating, or removing packages
                   2679:     23.4. Commit Messages
                   2680:     23.5. Committing: Adding a package to CVS
                   2681:     23.6. Updating a package to a newer version
                   2682:     23.7. Renaming a package in pkgsrc
                   2683:     23.8. Moving a package in pkgsrc
                   2684: 24. Frequently Asked Questions
                   2685: 
                   2686: Chapter 11. Getting help
                   2687: 
                   2688: To get help when developing pkgsrc, the definitive source is this document, the
                   2689: pkgsrc guide. If you don't find anything here, there are alternatives:
                   2690: 
                   2691:   * The built-in pkgsrc help, which is available after bootstrapping pkgsrc.
                   2692:     Run bmake help topic=? to get help for any topic, such as a variable name
                   2693:     like BUILD_DEFS, a make target like do-build, a missing C or C++ function
                   2694:     like strcasecmp or any other topic.
                   2695: 
1.207     leot     2696:     The available help topics are listed in Appendix E, Help topics.
1.154     rillig   2697: 
1.163     rillig   2698:   * To see the value of a single variable, run bmake show-var VARNAME=X.
                   2699: 
                   2700:   * To see the values of the most common variables, run bmake show-all. These
                   2701:     variables are grouped by topic. To see the variables for a single topic,
                   2702:     run bmake show-all-topic, for example bmake show-all-fetch.
                   2703: 
1.154     rillig   2704:   * The tech-pkg mailing list, to which you can subscribe and then ask your
                   2705:     questions.
                   2706: 
                   2707:   * The #pkgsrc IRC channel, which is accessible via a web browser or by using
                   2708:     a specialized chat program such as XChat. Pick any user name and join the
                   2709:     channel #pkgsrc.
1.1       dsieger  2710: 
1.184     rillig   2711: Chapter 12. Package components - files, directories and contents
1.1       dsieger  2712: 
                   2713: Table of Contents
                   2714: 
1.184     rillig   2715: 12.1. Makefile
                   2716: 12.2. distinfo
                   2717: 12.3. patches/*
                   2718:     12.3.1. Structure of a single patch file
                   2719:     12.3.2. Creating patch files
                   2720:     12.3.3. Sources where the patch files come from
                   2721:     12.3.4. Patching guidelines
                   2722:     12.3.5. Feedback to the author
                   2723: 12.4. Other mandatory files
                   2724: 12.5. Optional files
                   2725:     12.5.1. Files affecting the binary package
                   2726:     12.5.2. Files affecting the build process
                   2727:     12.5.3. Files affecting nothing at all
                   2728: 12.6. work*
                   2729: 12.7. files/*
1.1       dsieger  2730: 
1.184     rillig   2731: Whenever you're preparing a package, there are a number of files involved which
                   2732: are described in the following sections.
1.1       dsieger  2733: 
1.184     rillig   2734: 12.1. Makefile
1.1       dsieger  2735: 
1.184     rillig   2736: Building, installation and creation of a binary package are all controlled by
                   2737: the package's Makefile. The Makefile describes various things about a package,
                   2738: for example from where to get it, how to configure, build, and install it.
1.1       dsieger  2739: 
1.184     rillig   2740: A package Makefile contains several sections that describe the package.
1.1       dsieger  2741: 
1.184     rillig   2742: In the first section there are the following variables, which should appear
                   2743: exactly in the order given here. The order and grouping of the variables is
                   2744: mostly historical and has no further meaning.
1.1       dsieger  2745: 
1.184     rillig   2746:   * DISTNAME is the basename of the distribution file to be downloaded from the
                   2747:     package's website.
1.1       dsieger  2748: 
1.184     rillig   2749:   * PKGNAME is the name of the package, as used by pkgsrc. You need to provide
                   2750:     it if DISTNAME (which is the default) is not a good name for the package in
                   2751:     pkgsrc or DISTNAME is not provided (no distribution file is required).
                   2752:     Usually it is the pkgsrc directory name together with the version number.
                   2753:     It must match the regular expression ^[A-Za-z0-9][A-Za-z0-9-_.+]*$, that
                   2754:     is, it starts with a letter or digit, and contains only letters, digits,
1.204     nia      2755:     dashes, underscores, dots and plus signs. New packages should have entirely
                   2756:     lower-case names, with the exception of some that must follow pre-existing
                   2757:     conventions (e.g. R packages begin with R-). You can use the :tl variable
                   2758:     modifier to lower-case the package name.
1.26      spz      2759: 
1.184     rillig   2760:   * CATEGORIES is a list of categories which the package fits in. You can
                   2761:     choose any of the top-level directories of pkgsrc for it.
1.1       dsieger  2762: 
1.184     rillig   2763:     Currently the following values are available for CATEGORIES. If more than
                   2764:     one is used, they need to be separated by spaces:
1.1       dsieger  2765: 
1.184     rillig   2766:     archivers     cross         geography     meta-pkgs     security
                   2767:     audio         databases     graphics      misc          shells
                   2768:     benchmarks    devel         ham           multimedia    sysutils
                   2769:     biology       editors       inputmethod   net           textproc
                   2770:     cad           emulators     lang          news          time
                   2771:     chat          finance       mail          parallel      wm
                   2772:     comms         fonts         math          pkgtools      www
                   2773:     converters    games         mbone         print         x11
1.1       dsieger  2774: 
1.184     rillig   2775:   * MASTER_SITES, DYNAMIC_MASTER_SITES, DIST_SUBDIR, EXTRACT_SUFX and DISTFILES
                   2776:     are discussed in detail in Section 13.5, "The fetch phase".
1.1       dsieger  2777: 
1.184     rillig   2778: The second section contains information about separately downloaded patches, if
                   2779: any.
1.1       dsieger  2780: 
1.184     rillig   2781:   * PATCHFILES: Name(s) of additional files that contain distribution patches.
                   2782:     There is no default. pkgsrc will look for them at PATCH_SITES. They will
                   2783:     automatically be uncompressed before patching if the names end with .gz or
                   2784:     .Z.
1.1       dsieger  2785: 
1.184     rillig   2786:   * PATCH_SITES: Primary location(s) for distribution patch files (see
                   2787:     PATCHFILES above) if not found locally.
1.1       dsieger  2788: 
1.184     rillig   2789:   * PATCH_DIST_STRIP: an argument to patch(1) that sets the pathname strip
                   2790:     count to help find the correct files to patch. It defaults to -p0.
1.1       dsieger  2791: 
1.184     rillig   2792: The third section contains the following variables.
1.1       dsieger  2793: 
1.184     rillig   2794:   * MAINTAINER is the email address of the person who feels responsible for
                   2795:     this package, and who is most likely to look at problems or questions
                   2796:     regarding this package which have been reported with send-pr(1). Other
                   2797:     developers may contact the MAINTAINER before making changes to the package,
                   2798:     but are not required to do so. When packaging a new program, set MAINTAINER
                   2799:     to yourself. If you really can't maintain the package for future updates,
                   2800:     set it to <pkgsrc-users@NetBSD.org>.
1.1       dsieger  2801: 
1.184     rillig   2802:   * OWNER should be used instead of MAINTAINER when you do not want other
                   2803:     developers to update or change the package without contacting you first. A
                   2804:     package Makefile should contain one of MAINTAINER or OWNER, but not both.
1.1       dsieger  2805: 
1.184     rillig   2806:   * HOMEPAGE is a URL where users can find more information about the package.
1.1       dsieger  2807: 
1.184     rillig   2808:   * COMMENT is a one-line description of the package (should not include the
                   2809:     package name).
1.1       dsieger  2810: 
1.184     rillig   2811:   * LICENSE indicates the license(s) applicable for the package. See
                   2812:     Section 21.1.3, "Handling licenses" for further details.
1.1       dsieger  2813: 
1.184     rillig   2814: Other variables that affect the build:
1.1       dsieger  2815: 
1.184     rillig   2816:   * WRKSRC: The directory where the interesting distribution files of the
                   2817:     package are found. The default is ${WRKDIR}/${DISTNAME}, which works for
                   2818:     most packages.
1.1       dsieger  2819: 
1.184     rillig   2820:     If a package doesn't create a subdirectory for itself (most GNU software
                   2821:     does, for instance), but extracts itself in the current directory, you
                   2822:     should set WRKSRC=${WRKDIR}.
1.1       dsieger  2823: 
1.184     rillig   2824:     If a package doesn't create a subdirectory with the name of DISTNAME but
                   2825:     some different name, set WRKSRC to point to the proper name in ${WRKDIR},
                   2826:     for example WRKSRC=${WRKDIR}/${DISTNAME}/unix. See lang/tcl and x11/tk for
                   2827:     other examples.
1.17      imil     2828: 
1.184     rillig   2829:     The name of the working directory created by pkgsrc is taken from the
                   2830:     WRKDIR_BASENAME variable. By default, its value is work. If you want to use
                   2831:     the same pkgsrc tree for building different kinds of binary packages, you
                   2832:     can change the variable according to your needs. Two other variables handle
                   2833:     common cases of setting WRKDIR_BASENAME individually. If OBJHOSTNAME is
                   2834:     defined in mk.conf, the first component of the host's name is attached to
                   2835:     the directory name. If OBJMACHINE is defined, the platform name is
                   2836:     attached, which might look like work.i386 or work.sparc.
1.17      imil     2837: 
1.184     rillig   2838: Please pay attention to the following gotchas:
1.17      imil     2839: 
1.184     rillig   2840:   * Add MANCOMPRESSED if man pages are installed in compressed form by the
                   2841:     package. For packages using BSD-style makefiles which honor MANZ, there is
                   2842:     MANCOMPRESSED_IF_MANZ.
1.17      imil     2843: 
1.184     rillig   2844:   * Replace /usr/local with "${PREFIX}" in all files (see patches, below).
1.103     wiz      2845: 
1.184     rillig   2846:   * If the package installs any info files, see Section 21.6.7, "Packages
                   2847:     installing info files".
1.103     wiz      2848: 
1.184     rillig   2849: 12.2. distinfo
1.17      imil     2850: 
1.184     rillig   2851: The distinfo file contains the message digest, or checksum, of each distfile
                   2852: needed for the package. This ensures that the distfiles retrieved from the
                   2853: Internet have not been corrupted during transfer or altered by a malign force
                   2854: to introduce a security hole. To provide maximum security, all distfiles are
                   2855: protected using three different message digest algorithms (SHA1, RMD160,
                   2856: SHA512), as well as the file size.
1.17      imil     2857: 
1.184     rillig   2858: The distinfo file also contains the checksums for all the patches found in the
                   2859: patches directory (see Section 12.3, "patches/*"). These checksums ensure that
                   2860: patches are only applied intentionally and that they don't accidentally change,
                   2861: e.g. when merging different changes together. They also make sure that new
                   2862: patches are actually added to CVS and old ones are removed. Too see whether the
                   2863: patches and the distinfo file match, run pkglint after changing the patches.
1.17      imil     2864: 
1.184     rillig   2865: To regenerate the distinfo file, use the make distinfo command.
1.17      imil     2866: 
1.184     rillig   2867: Some packages have different sets of distfiles depending on the platform, for
                   2868: example lang/openjdk8. These are kept in the same distinfo file and care should
                   2869: be taken when upgrading such a package to ensure distfile information is not
                   2870: lost.
1.17      imil     2871: 
1.184     rillig   2872: 12.3. patches/*
1.63      wiz      2873: 
1.184     rillig   2874: Some packages don't work out-of-the box on the various platforms that are
                   2875: supported by pkgsrc. These packages need to be patched to make them work. The
                   2876: patch files can be found in the patches/ directory.
1.17      imil     2877: 
1.184     rillig   2878: In the patch phase, these patches are applied to the files in WRKSRC directory
                   2879: after extracting them, in alphabetic order.
1.160     brook    2880: 
1.184     rillig   2881: 12.3.1. Structure of a single patch file
1.160     brook    2882: 
1.184     rillig   2883: The patch-* files should be in diff -bu format, and apply without a fuzz to
                   2884: avoid problems. (To force patches to apply with fuzz you can set
                   2885: PATCH_FUZZ_FACTOR=-F2). Furthermore, each patch should contain only changes for
                   2886: a single file, and no file should be patched by more than one patch file. This
                   2887: helps to keep future modifications simple.
1.160     brook    2888: 
1.184     rillig   2889: Each patch file is structured as follows: In the first line, there is the RCS
                   2890: Id of the patch itself. The second line should be empty for aesthetic reasons.
                   2891: After that, there should be a comment for each change that the patch does.
                   2892: There are a number of standard cases:
1.160     brook    2893: 
1.184     rillig   2894:   * Patches for commonly known vulnerabilities should mention the vulnerability
                   2895:     ID (CAN, CVE).
1.160     brook    2896: 
1.184     rillig   2897:   * Patches that change source code should mention the platform and other
                   2898:     environment (for example, the compiler) that the patch is needed for.
1.160     brook    2899: 
1.184     rillig   2900: The patch should be commented so that any developer who knows the code of the
                   2901: application can make some use of the patch. Special care should be taken for
                   2902: the upstream developers, since we generally want that they accept our patches,
                   2903: so we have less work in the future.
1.160     brook    2904: 
1.184     rillig   2905: 12.3.2. Creating patch files
1.160     brook    2906: 
1.184     rillig   2907: One important thing to mention is to pay attention that no RCS IDs get stored
                   2908: in the patch files, as these will cause problems when later checked into the
                   2909: NetBSD CVS tree. Use the pkgdiff command from the pkgtools/pkgdiff package to
                   2910: avoid these problems.
1.160     brook    2911: 
1.184     rillig   2912: For even more automation, we recommend using mkpatches from the same package to
1.222     gutterid 2913: make a whole set of patches. You just have to back up files before you edit
                   2914: them to filename.orig, e.g., with cp -p filename filename.orig or, easier, by
                   2915: using pkgvi again from the same package. If you upgrade a package this way, you
                   2916: can easily compare the new set of patches with the previously existing one with
1.184     rillig   2917: patchdiff. The files in patches are replaced by new files, so carefully check
                   2918: if you want to take all the changes.
1.160     brook    2919: 
1.184     rillig   2920: When you have finished a package, remember to generate the checksums for the
                   2921: patch files by using the make makepatchsum command, see Section 12.2,
                   2922: "distinfo".
1.1       dsieger  2923: 
1.184     rillig   2924: When adding a patch that corrects a problem in the distfile (rather than e.g.
                   2925: enforcing pkgsrc's view of where man pages should go), send the patch as a bug
                   2926: report to the maintainer. This benefits non-pkgsrc users of the package, and
                   2927: usually makes it possible to remove the patch in future version.
1.1       dsieger  2928: 
1.184     rillig   2929: The file names of the patch files are usually of the form patch-
                   2930: path_to_file__with__underscores.c. Many packages still use the previous
                   2931: convention patch-[a-z][a-z], but new patches should be of the form containing
                   2932: the filename. mkpatches included in pkgtools/pkgdiff takes care of the name
                   2933: automatically.
1.1       dsieger  2934: 
1.222     gutterid 2935: When updating pre-existing patch files, if a file uses the old patch-[a-z][a-z]
                   2936: convention, it's best not to change it to the new form, as that will just cause
                   2937: churn that makes it harder to track changes to patching over time. Similarly,
                   2938: if a patch now applies at different line offsets, but still applies cleanly
                   2939: as-is, there's no need to update it, as that also unnecessarily complicates the
                   2940: patch history.
                   2941: 
1.184     rillig   2942: 12.3.3. Sources where the patch files come from
1.1       dsieger  2943: 
1.184     rillig   2944: If you want to share patches between multiple packages in pkgsrc, e.g. because
                   2945: they use the same distfiles, set PATCHDIR to the path where the patch files can
                   2946: be found, e.g.:
1.1       dsieger  2947: 
1.184     rillig   2948: PATCHDIR=       ../../editors/xemacs/patches
1.1       dsieger  2949: 
1.184     rillig   2950: Patch files that are distributed by the author or other maintainers can be
                   2951: listed in PATCHFILES.
1.1       dsieger  2952: 
1.184     rillig   2953: If it is desired to store any patches that should not be committed into pkgsrc,
                   2954: they can be kept outside the pkgsrc tree in the $LOCALPATCHES directory. The
                   2955: directory tree there is expected to have the same "category/package" structure
                   2956: as pkgsrc, and patches are expected to be stored inside these dirs (also known
                   2957: as $LOCALPATCHES/$PKGPATH). For example, if you want to keep a private patch
                   2958: for pkgsrc/graphics/png, keep it in $LOCALPATCHES/graphics/png/mypatch. All
                   2959: files in the named directory are expected to be patch files, and they are
                   2960: applied after pkgsrc patches are applied.
1.1       dsieger  2961: 
1.184     rillig   2962: 12.3.4. Patching guidelines
1.1       dsieger  2963: 
1.184     rillig   2964: When fixing a portability issue in the code do not use preprocessor magic to
                   2965: check for the current operating system nor platform. Doing so hurts portability
                   2966: to other platforms because the OS-specific details are not abstracted
                   2967: appropriately.
1.1       dsieger  2968: 
1.184     rillig   2969: The general rule to follow is: instead of checking for the operating system the
                   2970: application is being built on, check for the specific features you need. For
                   2971: example, instead of assuming that kqueue is available under NetBSD and using
                   2972: the __NetBSD__ macro to conditionalize kqueue support, add a check that detects
1.198     leot     2973: kqueue itself -- yes, this generally involves patching the configure script.
1.184     rillig   2974: There is absolutely nothing that prevents some OSes from adopting interfaces
                   2975: from other OSes (e.g. Linux implementing kqueue), something that the above
                   2976: checks cannot take into account.
1.1       dsieger  2977: 
1.184     rillig   2978: Of course, checking for features generally involves more work on the
                   2979: developer's side, but the resulting changes are cleaner and there are chances
                   2980: they will work on many other platforms. Not to mention that there are higher
                   2981: chances of being later integrated into the mainstream sources. Remember: It
                   2982: doesn't work unless it is right!
1.1       dsieger  2983: 
1.184     rillig   2984: Some typical examples:
1.121     sevan    2985: 
1.184     rillig   2986: Table 12.1. Patching examples
1.1       dsieger  2987: 
1.184     rillig   2988: +-------------------------------------------------------------------------------------------+
                   2989: |  Where  |        Incorrect         |                       Correct                        |
                   2990: |---------+--------------------------+------------------------------------------------------|
                   2991: |         |case ${target_os} in      |                                                      |
                   2992: |configure|netbsd*) have_kvm=yes ;;  |AC_CHECK_LIB(kvm, kvm_open, have_kvm=yes, have_kvm=no)|
                   2993: |script   |*)       have_kvm=no  ;;  |                                                      |
                   2994: |         |esac                      |                                                      |
                   2995: |---------+--------------------------+------------------------------------------------------|
                   2996: |C source |#if defined(__NetBSD__)   |#if defined(HAVE_SYS_EVENT_H)                         |
                   2997: |file     |#  include <sys/event.h>  |#  include <sys/event.h>                              |
                   2998: |         |#endif                    |#endif                                                |
                   2999: |---------+--------------------------+------------------------------------------------------|
                   3000: |         |int                       |int                                                   |
                   3001: |         |monitor_file(...)         |monitor_file(...)                                     |
                   3002: |         |{                         |{                                                     |
                   3003: |         |#if defined(__NetBSD__)   |#if defined(HAVE_KQUEUE)                              |
                   3004: |C source |        int fd = kqueue();|        int fd = kqueue();                            |
                   3005: |file     |        ...               |        ...                                           |
                   3006: |         |#else                     |#else                                                 |
                   3007: |         |        ...               |        ...                                           |
                   3008: |         |#endif                    |#endif                                                |
                   3009: |         |}                         |}                                                     |
                   3010: +-------------------------------------------------------------------------------------------+
1.1       dsieger  3011: 
                   3012: 
1.184     rillig   3013: 12.3.5. Feedback to the author
1.1       dsieger  3014: 
1.184     rillig   3015: Always, always, always feed back any portability fixes or improvements you do
                   3016: to a package to the mainstream developers. This is the only way to get their
                   3017: attention on portability issues and to ensure that future versions can be built
                   3018: out-of-the box on NetBSD. Furthermore, any user that gets newer distfiles will
                   3019: get the fixes straight from the packaged code.
1.1       dsieger  3020: 
1.184     rillig   3021: This generally involves cleaning up the patches (because sometimes the patches
                   3022: that are added to pkgsrc are quick hacks), filing bug reports in the
                   3023: appropriate trackers for the projects and working with the mainstream authors
                   3024: to accept your changes. It is extremely important that you do it so that the
                   3025: packages in pkgsrc are kept simple and thus further changes can be done without
                   3026: much hassle.
1.1       dsieger  3027: 
1.184     rillig   3028: When you have done this, please add a URL to the upstream bug report to the
                   3029: patch comment.
1.1       dsieger  3030: 
1.184     rillig   3031: Support the idea of free software!
1.1       dsieger  3032: 
1.184     rillig   3033: 12.4. Other mandatory files
1.1       dsieger  3034: 
1.184     rillig   3035: DESCR
1.1       dsieger  3036: 
1.184     rillig   3037:     A multi-line description of the piece of software. This should include any
                   3038:     credits where they are due. Please bear in mind that others do not share
                   3039:     your sense of humour (or spelling idiosyncrasies), and that others will
                   3040:     read everything that you write here.
1.1       dsieger  3041: 
1.184     rillig   3042: PLIST
1.1       dsieger  3043: 
1.184     rillig   3044:     This file governs the files that are installed on your system: all the
                   3045:     binaries, manual pages, etc. There are other directives which may be
                   3046:     entered in this file, to control the creation and deletion of directories,
                   3047:     and the location of inserted files. See Chapter 19, PLIST issues for more
                   3048:     information.
1.1       dsieger  3049: 
1.184     rillig   3050: 12.5. Optional files
1.1       dsieger  3051: 
1.184     rillig   3052: 12.5.1. Files affecting the binary package
1.1       dsieger  3053: 
1.184     rillig   3054: INSTALL
1.1       dsieger  3055: 
1.184     rillig   3056:     This shell script is invoked twice by pkg_add(1). First time after package
                   3057:     extraction and before files are moved in place, the second time after the
                   3058:     files to install are moved in place. This can be used to do any custom
                   3059:     procedures not possible with @exec commands in PLIST. See pkg_add(1) and
                   3060:     pkg_create(1) for more information. See also Section 20.1, "Files and
                   3061:     directories outside the installation prefix". Please note that you can
                   3062:     modify variables in it easily by using FILES_SUBST in the package's
                   3063:     Makefile:
1.1       dsieger  3064: 
1.184     rillig   3065:     FILES_SUBST+=  SOMEVAR="somevalue"
1.1       dsieger  3066: 
1.184     rillig   3067:     replaces "@SOMEVAR@" with "somevalue" in the INSTALL. By default,
                   3068:     substitution is performed for PREFIX, LOCALBASE, X11BASE, VARBASE, and a
                   3069:     few others, type make help topic=FILES_SUBST for a complete list.
1.1       dsieger  3070: 
1.184     rillig   3071: DEINSTALL
1.1       dsieger  3072: 
1.184     rillig   3073:     This script is executed before and after any files are removed. It is this
                   3074:     script's responsibility to clean up any additional messy details around the
                   3075:     package's installation, since all pkg_delete knows is how to delete the
                   3076:     files created in the original distribution. See pkg_delete(1) and
                   3077:     pkg_create(1) for more information. The same methods to replace variables
                   3078:     can be used as for the INSTALL file.
1.1       dsieger  3079: 
1.184     rillig   3080: MESSAGE
1.1       dsieger  3081: 
1.198     leot     3082:     This file is displayed after installation of the package. While this was
                   3083:     used often in the past, it has two problems: the display will be missed if
                   3084:     many packages are intalled at once, and the person installing the package
                   3085:     and the one using or configuring it may be different. It should therefore
                   3086:     be used only in exceptional circumstances where lasting negative
                   3087:     consequences would result from someone not reading it.
                   3088: 
                   3089:     MESSAGE should not be used for:
                   3090: 
1.232   ! gutterid 3091:       o exhortations to read the documentation
1.198     leot     3092: 
1.232   ! gutterid 3093:       o reminders to install rc.d files and set variables
1.198     leot     3094: 
1.232   ! gutterid 3095:       o anything that should be explained in the installation/configuration
1.198     leot     3096:         documentation that should come with the package
                   3097: 
                   3098:     If the documentation provided by upstream needs enhancing, create e.g.
                   3099:     files/README.pkgsrc and install it in the package's documentation
                   3100:     directory.
                   3101: 
                   3102:     Note that MESSAGE is shown for all operating systems and all init systems.
                   3103:     If a MESSAGE is necessary, it should be narrowed to only those operating
                   3104:     systems and init systems to which it applies.
                   3105: 
                   3106:     Note that you can modify variables in it easily by using MESSAGE_SUBST in
                   3107:     the package's Makefile:
1.1       dsieger  3108: 
1.184     rillig   3109:     MESSAGE_SUBST+=  SOMEVAR="somevalue"
1.1       dsieger  3110: 
1.184     rillig   3111:     replaces "${SOMEVAR}" with "somevalue" in MESSAGE. By default, substitution
                   3112:     is performed for PKGNAME, PKGBASE, PREFIX, LOCALBASE, X11BASE,
                   3113:     PKG_SYSCONFDIR, ROOT_GROUP, and ROOT_USER.
1.1       dsieger  3114: 
1.184     rillig   3115:     You can display a different or additional files by setting the MESSAGE_SRC
                   3116:     variable. Its default is MESSAGE, if the file exists.
1.1       dsieger  3117: 
1.184     rillig   3118: ALTERNATIVES
1.1       dsieger  3119: 
1.184     rillig   3120:     This file is used by the alternatives framework. It creates, configures,
                   3121:     and destroys generic wrappers used to run programs with similar interfaces.
                   3122:     See pkg_alternatives(8) from pkgtools/pkg_alternatives for more
                   3123:     information.
1.1       dsieger  3124: 
1.184     rillig   3125:     Each line of the file contains two filenames, first the wrapper and then
                   3126:     the alternative provided by the package. Both paths are relative to PREFIX.
1.1       dsieger  3127: 
1.184     rillig   3128: 12.5.2. Files affecting the build process
1.1       dsieger  3129: 
1.184     rillig   3130: Makefile.common
1.1       dsieger  3131: 
1.184     rillig   3132:     This file contains arbitrary things that could also go into a Makefile, but
                   3133:     its purpose is to be used by more than one package. This file should only
                   3134:     be used when the packages that will use the file are known in advance. For
                   3135:     other purposes it is often better to write a *.mk file and give it a good
                   3136:     name that describes what it does.
1.1       dsieger  3137: 
1.184     rillig   3138: buildlink3.mk
1.1       dsieger  3139: 
1.184     rillig   3140:     This file contains the dependency information for the buildlink3 framework
                   3141:     (see Chapter 18, Buildlink methodology).
1.1       dsieger  3142: 
1.184     rillig   3143: hacks.mk
1.1       dsieger  3144: 
1.184     rillig   3145:     This file contains workarounds for compiler bugs and similar things. It is
                   3146:     included automatically by the pkgsrc infrastructure, so you don't need an
                   3147:     extra .include line for it.
1.1       dsieger  3148: 
1.184     rillig   3149: options.mk
1.1       dsieger  3150: 
1.184     rillig   3151:     This file contains the code for the package-specific options (see
                   3152:     Chapter 16, Options handling) that can be selected by the user. If a
                   3153:     package has only one or two options, it is equally acceptable to put the
                   3154:     code directly into the Makefile.
1.1       dsieger  3155: 
1.184     rillig   3156: 12.5.3. Files affecting nothing at all
1.1       dsieger  3157: 
1.184     rillig   3158: README*
1.1       dsieger  3159: 
1.184     rillig   3160:     These files do not take place in the creation of a package and thus are
                   3161:     purely informative to the package developer.
1.1       dsieger  3162: 
1.184     rillig   3163: TODO
1.1       dsieger  3164: 
1.184     rillig   3165:     This file contains things that need to be done to make the package even
                   3166:     better.
1.1       dsieger  3167: 
1.184     rillig   3168: 12.6. work*
1.1       dsieger  3169: 
1.184     rillig   3170: When you type make, the distribution files are unpacked into the directory
                   3171: denoted by WRKDIR. It can be removed by running make clean. Besides the
                   3172: sources, this directory is also used to keep various timestamp files. The
                   3173: directory gets removed completely on clean. The default is ${.CURDIR}/work or $
                   3174: {.CURDIR}/work.${MACHINE_ARCH} if OBJMACHINE is set.
1.1       dsieger  3175: 
1.184     rillig   3176: 12.7. files/*
1.80      wiz      3177: 
1.184     rillig   3178: If you have any files that you wish to be placed in the package prior to
                   3179: configuration or building, you can place these files here and use a ${CP}
                   3180: command in the "post-extract" target to achieve this.
1.1       dsieger  3181: 
1.184     rillig   3182: If you want to share files in this way with other packages, set the FILESDIR
                   3183: variable to point to the other package's files directory, e.g.:
1.1       dsieger  3184: 
1.184     rillig   3185: FILESDIR=       ../../editors/xemacs/files
1.14      jmcneill 3186: 
1.184     rillig   3187: Chapter 13. The build process
1.1       dsieger  3188: 
1.184     rillig   3189: Table of Contents
1.1       dsieger  3190: 
1.184     rillig   3191: 13.1. Introduction
                   3192: 13.2. Program location
                   3193: 13.3. Directories used during the build process
                   3194: 13.4. Running a phase
                   3195: 13.5. The fetch phase
                   3196:     13.5.1. What to fetch and where to get it from
                   3197:     13.5.2. How are the files fetched?
                   3198: 13.6. The checksum phase
                   3199: 13.7. The extract phase
                   3200: 13.8. The patch phase
                   3201: 13.9. The tools phase
                   3202: 13.10. The wrapper phase
                   3203: 13.11. The configure phase
                   3204: 13.12. The build phase
                   3205: 13.13. The test phase
                   3206: 13.14. The install phase
                   3207: 13.15. The package phase
                   3208: 13.16. Cleaning up
                   3209: 13.17. Other helpful targets
1.1       dsieger  3210: 
1.184     rillig   3211: 13.1. Introduction
1.122     leot     3212: 
1.184     rillig   3213: This chapter gives a detailed description on how a package is built. Building a
                   3214: package is separated into different phases (for example fetch, build, install),
                   3215: all of which are described in the following sections. Each phase is split into
                   3216: so-called stages, which take the name of the containing phase, prefixed by one
                   3217: of pre-, do- or post-. (Examples are pre-configure, post-build.) Most of the
                   3218: actual work is done in the do-* stages.
1.1       dsieger  3219: 
1.184     rillig   3220: Never override the regular targets (like fetch), if you have to, override the
                   3221: do-* ones instead.
1.1       dsieger  3222: 
1.184     rillig   3223: The basic steps for building a program are always the same. First the program's
                   3224: source (distfile) must be brought to the local system and then extracted. After
                   3225: any pkgsrc-specific patches to compile properly are applied, the software can
                   3226: be configured, then built (usually by compiling), and finally the generated
                   3227: binaries, etc. can be put into place on the system.
1.1       dsieger  3228: 
1.184     rillig   3229: To get more details about what is happening at each step, you can set the
                   3230: PKG_VERBOSE variable, or the PATCH_DEBUG variable if you are just interested in
                   3231: more details about the patch step.
1.1       dsieger  3232: 
1.184     rillig   3233: 13.2. Program location
1.1       dsieger  3234: 
1.184     rillig   3235: Before outlining the process performed by the NetBSD package system in the next
                   3236: section, here's a brief discussion on where programs are installed, and which
                   3237: variables influence this.
1.1       dsieger  3238: 
1.184     rillig   3239: The automatic variable PREFIX indicates where all files of the final program
                   3240: shall be installed. It is usually set to LOCALBASE (/usr/pkg), or CROSSBASE for
                   3241: pkgs in the cross category. The value of PREFIX needs to be put into the
                   3242: various places in the program's source where paths to these files are encoded.
                   3243: See Section 12.3, "patches/*" and Section 21.3.1, "Shared libraries - libtool"
                   3244: for more details.
1.1       dsieger  3245: 
1.184     rillig   3246: When choosing which of these variables to use, follow the following rules:
1.1       dsieger  3247: 
1.184     rillig   3248:   * PREFIX always points to the location where the current pkg will be
                   3249:     installed. When referring to a pkg's own installation path, use "${PREFIX}"
                   3250:     .
1.1       dsieger  3251: 
1.223     nia      3252:   * LOCALBASE is where all pkgs are installed. If you need to construct a -I or
                   3253:     -L argument to the compiler to find includes and libraries installed by
                   3254:     another pkg, use "${LOCALBASE}". The name LOCALBASE stems from FreeBSD,
                   3255:     which installed all packages in /usr/local. As pkgsrc leaves /usr/local for
                   3256:     the system administrator, this variable is a misnomer.
1.1       dsieger  3257: 
1.184     rillig   3258:   * X11BASE is where the actual X11 distribution (from xsrc, etc.) is
                   3259:     installed. When looking for standard X11 includes (not those installed by a
                   3260:     package), use "${X11BASE}".
1.1       dsieger  3261: 
1.184     rillig   3262:   * X11-based packages using imake must set USE_IMAKE to be installed correctly
                   3263:     under LOCALBASE.
1.1       dsieger  3264: 
1.184     rillig   3265:   * Within ${PREFIX}, packages should install files according to hier(7), with
                   3266:     the exception that manual pages go into ${PREFIX}/man, not ${PREFIX}/share/
                   3267:     man.
1.1       dsieger  3268: 
1.184     rillig   3269: 13.3. Directories used during the build process
1.2       rillig   3270: 
1.184     rillig   3271: When building a package, various directories are used to store source files,
                   3272: temporary files, pkgsrc-internal files, and so on. These directories are
                   3273: explained here.
1.1       dsieger  3274: 
1.184     rillig   3275: Some of the directory variables contain relative pathnames. There are two
                   3276: common base directories for these relative directories: PKGSRCDIR/PKGPATH is
                   3277: used for directories that are pkgsrc-specific. WRKSRC is used for directories
                   3278: inside the package itself.
1.1       dsieger  3279: 
1.184     rillig   3280: PKGSRCDIR
1.1       dsieger  3281: 
1.184     rillig   3282:     This is an absolute pathname that points to the pkgsrc root directory.
                   3283:     Generally, you don't need it.
1.1       dsieger  3284: 
1.184     rillig   3285: PKGDIR
1.1       dsieger  3286: 
1.184     rillig   3287:     This is an absolute pathname that points to the current package.
1.1       dsieger  3288: 
1.184     rillig   3289: PKGPATH
1.1       dsieger  3290: 
1.184     rillig   3291:     This is a pathname relative to PKGSRCDIR that points to the current
1.228     gutterid 3292:     package. It is defined after including bsd.prefs.mk and can be used in
                   3293:     makefile fragments that are used by several packages to distinguish between
                   3294:     these packages. Other variables that would serve the same purpose are
                   3295:     PKGBASE and PKGNAME, but these are only defined after including bsd.pkg.mk,
                   3296:     which is too late.
                   3297: 
                   3298:     In mk.conf, the pkgsrc user can use PKGPATH to tweak variables like
                   3299:     MAKE_JOBS and CFLAGS.
1.1       dsieger  3300: 
1.184     rillig   3301: WRKDIR
1.1       dsieger  3302: 
1.184     rillig   3303:     This is an absolute pathname pointing to the directory where all work takes
                   3304:     place. The distfiles are extracted to this directory. It also contains
                   3305:     temporary directories and log files used by the various pkgsrc frameworks,
                   3306:     like buildlink or the wrappers.
1.1       dsieger  3307: 
1.184     rillig   3308: WRKSRC
1.1       dsieger  3309: 
1.184     rillig   3310:     This is an absolute pathname pointing to the directory where the distfiles
                   3311:     are extracted. It is usually a direct subdirectory of WRKDIR, and often
                   3312:     it's the only directory entry that isn't hidden. This variable may be
                   3313:     changed by a package Makefile.
1.1       dsieger  3314: 
1.184     rillig   3315: The CREATE_WRKDIR_SYMLINK definition takes either the value yes or no and
                   3316: defaults to no. It indicates whether a symbolic link to the WRKDIR is to be
                   3317: created in the pkgsrc entry's directory. If users would like to have their
                   3318: pkgsrc trees behave in a read-only manner, then the value of
                   3319: CREATE_WRKDIR_SYMLINK should be set to no.
1.1       dsieger  3320: 
1.184     rillig   3321: 13.4. Running a phase
1.1       dsieger  3322: 
1.184     rillig   3323: You can run a particular phase by typing make phase, where phase is the name of
                   3324: the phase. This will automatically run all phases that are required for this
                   3325: phase. The default phase is build, that is, when you run make without
                   3326: parameters in a package directory, the package will be built, but not
                   3327: installed.
1.1       dsieger  3328: 
1.184     rillig   3329: 13.5. The fetch phase
1.1       dsieger  3330: 
1.184     rillig   3331: The first step in building a package is to fetch the distribution files
                   3332: (distfiles) from the sites that are providing them. This is the task of the 
                   3333: fetch phase.
1.25      wiz      3334: 
1.184     rillig   3335: 13.5.1. What to fetch and where to get it from
1.1       dsieger  3336: 
1.184     rillig   3337: In simple cases, MASTER_SITES defines all URLs from where the distfile, whose
                   3338: name is derived from the DISTNAME variable, is fetched. The more complicated
                   3339: cases are described below.
1.1       dsieger  3340: 
1.184     rillig   3341: The variable DISTFILES specifies the list of distfiles that have to be fetched.
                   3342: Its value defaults to ${DEFAULT_DISTFILES} and its value is ${DISTNAME}$
                   3343: {EXTRACT_SUFX}, so that most packages don't need to define it at all.
                   3344: EXTRACT_SUFX is .tar.gz by default, but can be changed freely. Note that if
                   3345: your package requires additional distfiles to the default one, you cannot just
                   3346: append the additional filenames using the += operator, but you have write for
                   3347: example:
1.1       dsieger  3348: 
1.184     rillig   3349: DISTFILES=      ${DEFAULT_DISTFILES} additional-files.tar.gz
1.1       dsieger  3350: 
1.184     rillig   3351: Each distfile is fetched from a list of sites, usually MASTER_SITES. If the
                   3352: package has multiple DISTFILES or multiple PATCHFILES from different sites, you
                   3353: can set SITES.distfile to the list of URLs where the file distfile (including
                   3354: the suffix) can be found.
1.1       dsieger  3355: 
1.184     rillig   3356: DISTFILES=      ${DISTNAME}${EXTRACT_SUFX}
                   3357: DISTFILES+=     foo-file.tar.gz
                   3358: SITES.foo-file.tar.gz= \
                   3359: https://www.somewhere.com/somehow/ \
                   3360: https://www.somewhereelse.com/mirror/somehow/
1.1       dsieger  3361: 
1.184     rillig   3362: When actually fetching the distfiles, each item from MASTER_SITES or SITES.*
                   3363: gets the name of each distfile appended to it, without an intermediate slash.
                   3364: Therefore, all site values have to end with a slash or other separator
                   3365: character. This allows for example to set MASTER_SITES to a URL of a CGI script
                   3366: that gets the name of the distfile as a parameter. In this case, the definition
                   3367: would look like:
1.1       dsieger  3368: 
1.184     rillig   3369: MASTER_SITES=   https://www.example.com/download.cgi?file=
1.1       dsieger  3370: 
1.184     rillig   3371: The exception to this rule are URLs starting with a dash. In that case the URL
                   3372: is taken as is, fetched and the result stored under the name of the distfile.
                   3373: You can use this style for the case when the download URL style does not match
                   3374: the above common case. For example, if permanent download URL is a redirector
                   3375: to the real download URL, or the download file name is offered by an HTTP
                   3376: Content-Disposition header. In the following example, foo-1.0.0.tar.gz will be
                   3377: created instead of the default v1.0.0.tar.gz.
1.1       dsieger  3378: 
1.184     rillig   3379: DISTNAME=       foo-1.0.0
                   3380: MASTER_SITES=   -https://www.example.com/archive/v1.0.0.tar.gz
1.29      wiz      3381: 
1.184     rillig   3382: There are some predefined values for MASTER_SITES, which can be used in
                   3383: packages. The names of the variables should speak for themselves.
1.29      wiz      3384: 
1.225     gutterid 3385: MASTER_SITE_APACHE        MASTER_SITE_BACKUP
                   3386: MASTER_SITE_CRATESIO      MASTER_SITE_CYGWIN
                   3387: MASTER_SITE_DEBIAN        MASTER_SITE_FREEBSD
                   3388: MASTER_SITE_FREEBSD_LOCAL MASTER_SITE_GENTOO
                   3389: MASTER_SITE_GITHUB        MASTER_SITE_GITLAB
                   3390: MASTER_SITE_GNOME         MASTER_SITE_GNU
                   3391: MASTER_SITE_GNUSTEP       MASTER_SITE_HASKELL_HACKAGE
                   3392: MASTER_SITE_IFARCHIVE     MASTER_SITE_KDE
                   3393: MASTER_SITE_MOZILLA       MASTER_SITE_MOZILLA_ALL
                   3394: MASTER_SITE_MYSQL         MASTER_SITE_NETLIB
                   3395: MASTER_SITE_OPENBSD       MASTER_SITE_OPENOFFICE
                   3396: MASTER_SITE_OSDN          MASTER_SITE_PERL_CPAN
                   3397: MASTER_SITE_PGSQL         MASTER_SITE_PYPI
                   3398: MASTER_SITE_RUBYGEMS      MASTER_SITE_R_CRAN
                   3399: MASTER_SITE_SOURCEFORGE   MASTER_SITE_SUNSITE
                   3400: MASTER_SITE_SUSE          MASTER_SITE_TEX_CTAN
                   3401: MASTER_SITE_XCONTRIB      MASTER_SITE_XEMACS
                   3402: MASTER_SITE_XORG           
1.1       dsieger  3403: 
1.184     rillig   3404: Some explanations for the less self-explaining ones: MASTER_SITE_BACKUP
                   3405: contains backup sites for packages that are maintained in ftp://ftp.NetBSD.org/
                   3406: pub/pkgsrc/distfiles/${DIST_SUBDIR}. MASTER_SITE_LOCAL contains local package
                   3407: source distributions that are maintained in ftp://ftp.NetBSD.org/pub/pkgsrc/
                   3408: distfiles/LOCAL_PORTS/.
1.1       dsieger  3409: 
1.184     rillig   3410: If you choose one of these predefined sites, you may want to specify a
                   3411: subdirectory of that site. Since these macros may expand to more than one
                   3412: actual site, you must use the following construct to specify a subdirectory:
1.1       dsieger  3413: 
1.184     rillig   3414: MASTER_SITES=   ${MASTER_SITE_GNU:=subdirectory/name/}
                   3415: MASTER_SITES=   ${MASTER_SITE_SOURCEFORGE:=project_name/}
1.1       dsieger  3416: 
1.184     rillig   3417: Note the trailing slash after the subdirectory name.
1.1       dsieger  3418: 
1.184     rillig   3419: 13.5.2. How are the files fetched?
1.1       dsieger  3420: 
1.184     rillig   3421: The fetch phase makes sure that all the distfiles exist in a local directory
                   3422: (DISTDIR, which can be set by the pkgsrc user). If the files do not exist, they
                   3423: are fetched using commands of the form
1.1       dsieger  3424: 
1.184     rillig   3425: ${FETCH_CMD} ${FETCH_BEFORE_ARGS} ${site}${file} ${FETCH_AFTER_ARGS}
1.1       dsieger  3426: 
1.184     rillig   3427: where ${site} varies through several possibilities in turn: first,
                   3428: MASTER_SITE_OVERRIDE is tried, then the sites specified in either SITES.file if
                   3429: defined, else MASTER_SITES or PATCH_SITES, as applies, then finally the value
                   3430: of MASTER_SITE_BACKUP. The order of all except the first and the last can be
                   3431: optionally sorted by the user, via setting either MASTER_SORT_RANDOM, and
                   3432: MASTER_SORT_AWK or MASTER_SORT_REGEX.
1.1       dsieger  3433: 
1.184     rillig   3434: The specific command and arguments used depend on the FETCH_USING parameter.
                   3435: The example above is for FETCH_USING=custom.
1.66      asau     3436: 
1.184     rillig   3437: The distfiles mirror run by the NetBSD Foundation uses the mirror-distfiles
                   3438: target to mirror the distfiles, if they are freely distributable. Packages
                   3439: setting NO_SRC_ON_FTP (usually to "${RESTRICTED}") will not have their
                   3440: distfiles mirrored.
1.1       dsieger  3441: 
1.184     rillig   3442: 13.6. The checksum phase
1.1       dsieger  3443: 
1.184     rillig   3444: After the distfile(s) are fetched, their checksum is generated and compared
                   3445: with the checksums stored in the distinfo file. If the checksums don't match,
                   3446: the build is aborted. This is to ensure the same distfile is used for building,
                   3447: and that the distfile wasn't changed, e.g. by some malign force, deliberately
                   3448: changed distfiles on the master distribution site or network lossage.
1.1       dsieger  3449: 
1.184     rillig   3450: 13.7. The extract phase
1.1       dsieger  3451: 
1.184     rillig   3452: When the distfiles are present on the local system, they need to be extracted,
                   3453: as they usually come in the form of some compressed archive format.
1.1       dsieger  3454: 
1.184     rillig   3455: By default, all DISTFILES are extracted. If you only need some of them, you can
                   3456: set the EXTRACT_ONLY variable to the list of those files.
1.1       dsieger  3457: 
1.184     rillig   3458: Extracting the files is usually done by a little program, mk/extract/extract,
                   3459: which already knows how to extract various archive formats, so most likely you
                   3460: will not need to change anything here. But if you need, the following variables
                   3461: may help you:
1.1       dsieger  3462: 
1.184     rillig   3463: EXTRACT_OPTS_{BIN,LHA,PAX,RAR,TAR,ZIP,ZOO}
1.1       dsieger  3464: 
1.184     rillig   3465:     Use these variables to override the default options for an extract command,
                   3466:     which are defined in mk/extract/extract.
1.1       dsieger  3467: 
1.184     rillig   3468: EXTRACT_USING
1.1       dsieger  3469: 
1.184     rillig   3470:     This variable can be set to bsdtar, gtar, nbtar (which is the default
                   3471:     value), pax, or an absolute pathname pointing to the command with which tar
                   3472:     archives should be extracted. It is preferred to choose bsdtar over gtar if
                   3473:     NetBSD's pax-as-tar is not good enough.
1.1       dsieger  3474: 
1.184     rillig   3475: If the extract program doesn't serve your needs, you can also override the
                   3476: EXTRACT_CMD variable, which holds the command used for extracting the files.
                   3477: This command is executed in the ${WRKSRC} directory. During execution of this
                   3478: command, the shell variable extract_file holds the absolute pathname of the
                   3479: file that is going to be extracted.
1.1       dsieger  3480: 
1.184     rillig   3481: And if that still does not suffice, you can override the do-extract target in
                   3482: the package Makefile.
1.1       dsieger  3483: 
1.184     rillig   3484: 13.8. The patch phase
1.1       dsieger  3485: 
1.184     rillig   3486: After extraction, all the patches named by the PATCHFILES, those present in the
                   3487: patches subdirectory of the package as well as in $LOCALPATCHES/$PKGPATH (e.g.
                   3488: /usr/local/patches/graphics/png) are applied. Patchfiles ending in .Z or .gz
                   3489: are uncompressed before they are applied, files ending in .orig or .rej are
                   3490: ignored. Any special options to patch(1) can be handed in PATCH_DIST_ARGS. See
                   3491: Section 12.3, "patches/*" for more details.
1.1       dsieger  3492: 
1.184     rillig   3493: By default patch(1) is given special arguments to make it fail if the expected
                   3494: text from the patch context is not found in the patched file. If that happens,
                   3495: fix the patch file by comparing it with the actual text in the file to be
                   3496: patched.
1.1       dsieger  3497: 
1.184     rillig   3498: 13.9. The tools phase
1.1       dsieger  3499: 
1.184     rillig   3500: This is covered in Chapter 17, Tools needed for building or running.
1.1       dsieger  3501: 
1.184     rillig   3502: 13.10. The wrapper phase
1.1       dsieger  3503: 
1.184     rillig   3504: This phase creates wrapper programs for the compilers and linkers. The
                   3505: following variables can be used to tweak the wrappers.
1.1       dsieger  3506: 
1.184     rillig   3507: ECHO_WRAPPER_MSG
1.1       dsieger  3508: 
1.184     rillig   3509:     The command used to print progress messages. Does nothing by default. Set
                   3510:     to ${ECHO} to see the progress messages.
1.1       dsieger  3511: 
1.184     rillig   3512: WRAPPER_DEBUG
1.1       dsieger  3513: 
1.184     rillig   3514:     This variable can be set to yes (default) or no, depending on whether you
                   3515:     want additional information in the wrapper log file.
1.1       dsieger  3516: 
1.184     rillig   3517: WRAPPER_UPDATE_CACHE
1.1       dsieger  3518: 
1.184     rillig   3519:     This variable can be set to yes or no, depending on whether the wrapper
                   3520:     should use its cache, which will improve the speed. The default value is
                   3521:     yes, but is forced to no if the platform does not support it.
1.1       dsieger  3522: 
1.184     rillig   3523: WRAPPER_REORDER_CMDS
1.1       dsieger  3524: 
1.184     rillig   3525:     A list of reordering commands. A reordering command has the form reorder:l:
                   3526:     lib1:lib2. It ensures that that -llib1 occurs before -llib2.
1.1       dsieger  3527: 
1.184     rillig   3528: 13.11. The configure phase
1.1       dsieger  3529: 
1.184     rillig   3530: Most pieces of software need information on the header files, system calls, and
                   3531: library routines which are available on the platform they run on. The process
                   3532: of determining this information is known as configuration, and is usually
                   3533: automated. In most cases, a script is supplied with the distfiles, and its
                   3534: invocation results in generation of header files, Makefiles, etc.
1.1       dsieger  3535: 
1.184     rillig   3536: If the package contains a configure script, this can be invoked by setting
                   3537: HAS_CONFIGURE to "yes". If the configure script is a GNU autoconf script, you
1.187     rillig   3538: should set GNU_CONFIGURE to "yes" instead.
1.1       dsieger  3539: 
1.187     rillig   3540: In the do-configure stage, a rough equivalent of the following command is run.
                   3541: See mk/configure/configure.mk, target do-configure-script for the exact
                   3542: definition.
                   3543: 
                   3544: .for dir in ${CONFIGURE_DIRS}
                   3545:         cd ${WRKSRC} && cd ${dir} \
                   3546:         && env ${CONFIGURE_ENV} \
                   3547:             ${CONFIG_SHELL} ${CONFIGURE_SCRIPT} ${CONFIGURE_ARGS}
1.184     rillig   3548: .endfor
1.1       dsieger  3549: 
1.184     rillig   3550: CONFIGURE_DIRS (default: ".") is a list of pathnames relative to WRKSRC. In
                   3551: each of these directories, the configure script is run with the environment
                   3552: CONFIGURE_ENV and arguments CONFIGURE_ARGS. The variables CONFIGURE_ENV,
                   3553: CONFIGURE_SCRIPT (default: "./configure") and CONFIGURE_ARGS may all be changed
                   3554: by the package.
1.1       dsieger  3555: 
1.184     rillig   3556: If the program uses the Perl way of configuration (mainly Perl modules, but not
                   3557: only), i.e. a file called Makefile.PL, it should include ../../lang/perl5/
                   3558: module.mk. To set any parameter for Makefile.PL use the MAKE_PARAMS variable
                   3559: (e.g., MAKE_PARAMS+=foo=bar
1.1       dsieger  3560: 
1.184     rillig   3561: If the program uses an Imakefile for configuration, the appropriate steps can
                   3562: be invoked by setting USE_IMAKE to "yes". If you only need xmkmf, add it to
                   3563: USE_TOOLS. You can add variables to xmkmf's environment by adding them to the
                   3564: SCRIPTS_ENV variable.
1.1       dsieger  3565: 
1.184     rillig   3566: If the program uses cmake for configuration, the appropriate steps can be
                   3567: invoked by setting USE_CMAKE to "yes". You can add variables to cmake's
                   3568: environment by adding them to the CONFIGURE_ENV variable and arguments to cmake
                   3569: by adding them to the CMAKE_ARGS variable. The top directory argument is given
                   3570: by the CMAKE_ARG_PATH variable, that defaults to "." (relative to
                   3571: CONFIGURE_DIRS)
1.1       dsieger  3572: 
1.184     rillig   3573: If there is no configure step at all, set NO_CONFIGURE to "yes".
1.1       dsieger  3574: 
1.184     rillig   3575: 13.12. The build phase
1.1       dsieger  3576: 
1.187     rillig   3577: For building a package, a rough equivalent of the following code is executed;
                   3578: see mk/build/build.mk, target do-build for the exact definition.
1.154     rillig   3579: 
1.187     rillig   3580: .for dir in ${BUILD_DIRS}
                   3581:         cd ${WRKSRC} && cd ${dir} \
1.184     rillig   3582:         && env ${MAKE_ENV} \
1.187     rillig   3583:             ${MAKE_PROGRAM} ${MAKE_FLAGS} ${BUILD_MAKE_FLAGS} \
1.184     rillig   3584:                 -f ${MAKE_FILE} \
                   3585:                 ${BUILD_TARGET}
                   3586: .endfor
1.1       dsieger  3587: 
1.184     rillig   3588: BUILD_DIRS (default: ".") is a list of pathnames relative to WRKSRC. In each of
                   3589: these directories, MAKE_PROGRAM is run with the environment MAKE_ENV and
                   3590: arguments BUILD_MAKE_FLAGS. The variables MAKE_ENV, BUILD_MAKE_FLAGS, MAKE_FILE
                   3591: and BUILD_TARGET may all be changed by the package.
1.1       dsieger  3592: 
1.184     rillig   3593: The default value of MAKE_PROGRAM is "gmake" if USE_TOOLS contains "gmake", "
                   3594: make" otherwise. The default value of MAKE_FILE is "Makefile", and BUILD_TARGET
                   3595: defaults to "all".
1.1       dsieger  3596: 
1.184     rillig   3597: If there is no build step at all, set NO_BUILD to "yes".
1.1       dsieger  3598: 
1.184     rillig   3599: 13.13. The test phase
1.1       dsieger  3600: 
1.184     rillig   3601: [TODO]
1.1       dsieger  3602: 
1.184     rillig   3603: 13.14. The install phase
1.1       dsieger  3604: 
1.184     rillig   3605: Once the build stage has completed, the final step is to install the software
                   3606: in public directories, so users can access the programs and files.
1.1       dsieger  3607: 
1.187     rillig   3608: In the install phase, a rough equivalent of the following code is executed; see
                   3609: mk/install/install.mk, target do-install for the exact definition.
                   3610: Additionally, before and after this code, several consistency checks are run
                   3611: against the files-to-be-installed, see mk/check/*.mk for details.
                   3612: 
                   3613: .for dir in ${INSTALL_DIRS}
                   3614:         cd ${WRKSRC} && cd ${dir} \
                   3615:         && env ${INSTALL_ENV} ${MAKE_ENV} \
                   3616:             ${MAKE_PROGRAM} ${MAKE_FLAGS} ${INSTALL_MAKE_FLAGS} \
                   3617:                 -f ${MAKE_FILE} ${INSTALL_TARGET}
1.184     rillig   3618: .endfor
1.1       dsieger  3619: 
1.184     rillig   3620: The variable's meanings are analogous to the ones in the build phase.
                   3621: INSTALL_DIRS defaults to BUILD_DIRS. INSTALL_TARGET is "install" by default,
                   3622: plus "install.man" if USE_IMAKE is defined and NO_INSTALL_MANPAGES is not
                   3623: defined.
1.1       dsieger  3624: 
1.184     rillig   3625: In the install phase, the following variables are useful. They are all
                   3626: variations of the install(1) command that have the owner, group and permissions
                   3627: preset. INSTALL is the plain install command. The specialized variants,
                   3628: together with their intended use, are:
1.1       dsieger  3629: 
1.184     rillig   3630: INSTALL_PROGRAM_DIR
1.1       dsieger  3631: 
1.184     rillig   3632:     directories that contain binaries
1.1       dsieger  3633: 
1.184     rillig   3634: INSTALL_SCRIPT_DIR
1.1       dsieger  3635: 
1.184     rillig   3636:     directories that contain scripts
1.1       dsieger  3637: 
1.184     rillig   3638: INSTALL_LIB_DIR
1.1       dsieger  3639: 
1.184     rillig   3640:     directories that contain shared and static libraries
1.1       dsieger  3641: 
1.184     rillig   3642: INSTALL_DATA_DIR
1.108     rillig   3643: 
1.184     rillig   3644:     directories that contain data files
1.108     rillig   3645: 
1.184     rillig   3646: INSTALL_MAN_DIR
1.108     rillig   3647: 
1.184     rillig   3648:     directories that contain man pages
1.108     rillig   3649: 
1.184     rillig   3650: INSTALL_GAME_DIR
1.108     rillig   3651: 
1.184     rillig   3652:     directories that contain data files for games
1.108     rillig   3653: 
1.184     rillig   3654: INSTALL_PROGRAM
1.108     rillig   3655: 
1.184     rillig   3656:     binaries that can be stripped from debugging symbols
1.108     rillig   3657: 
1.184     rillig   3658: INSTALL_SCRIPT
1.108     rillig   3659: 
1.184     rillig   3660:     binaries that cannot be stripped
1.108     rillig   3661: 
1.184     rillig   3662: INSTALL_GAME
1.108     rillig   3663: 
1.184     rillig   3664:     game binaries
1.108     rillig   3665: 
1.184     rillig   3666: INSTALL_LIB
1.108     rillig   3667: 
1.184     rillig   3668:     shared and static libraries
1.108     rillig   3669: 
1.184     rillig   3670: INSTALL_DATA
1.108     rillig   3671: 
1.184     rillig   3672:     data files
1.1       dsieger  3673: 
1.184     rillig   3674: INSTALL_GAME_DATA
1.1       dsieger  3675: 
1.184     rillig   3676:     data files for games
1.108     rillig   3677: 
1.184     rillig   3678: INSTALL_MAN
1.108     rillig   3679: 
1.184     rillig   3680:     man pages
1.1       dsieger  3681: 
1.184     rillig   3682: Some other variables are:
1.1       dsieger  3683: 
1.184     rillig   3684: INSTALL_UNSTRIPPED
1.1       dsieger  3685: 
1.184     rillig   3686:     If set to yes, do not run strip(1) when installing binaries. Any debugging
                   3687:     sections and symbols present in binaries will be preserved.
1.1       dsieger  3688: 
1.184     rillig   3689: INSTALLATION_DIRS
1.1       dsieger  3690: 
1.184     rillig   3691:     A list of directories relative to PREFIX that are created by pkgsrc at the
                   3692:     beginning of the install phase. The package is supposed to create all
                   3693:     needed directories itself before installing files to it and list all other
                   3694:     directories here.
1.1       dsieger  3695: 
1.184     rillig   3696: In the rare cases that a package shouldn't install anything, set NO_INSTALL to 
                   3697: "yes". This is mostly relevant for packages in the regress category.
1.1       dsieger  3698: 
1.184     rillig   3699: 13.15. The package phase
1.121     sevan    3700: 
1.184     rillig   3701: Once the install stage has completed, a binary package of the installed files
                   3702: can be built. These binary packages can be used for quick installation without
                   3703: previous compilation, e.g. by the make bin-install or by using pkg_add.
1.1       dsieger  3704: 
1.184     rillig   3705: By default, the binary packages are created in ${PACKAGES}/All and symlinks are
                   3706: created in ${PACKAGES}/category, one for each category in the CATEGORIES
                   3707: variable. PACKAGES defaults to pkgsrc/packages.
1.1       dsieger  3708: 
1.184     rillig   3709: 13.16. Cleaning up
1.1       dsieger  3710: 
1.184     rillig   3711: Once you're finished with a package, you can clean the work directory by
                   3712: running make clean. If you want to clean the work directories of all
                   3713: dependencies too, use make clean-depends.
1.1       dsieger  3714: 
1.184     rillig   3715: 13.17. Other helpful targets
1.1       dsieger  3716: 
1.184     rillig   3717: pre/post-*
1.1       dsieger  3718: 
1.184     rillig   3719:     For any of the main targets described in the previous section (configure,
                   3720:     build, install, etc.), two auxiliary targets exist with "pre-" and "post-"
                   3721:     used as a prefix for the main target's name. These targets are invoked
                   3722:     before and after the main target is called, allowing extra configuration or
                   3723:     installation steps be performed from a package's Makefile, for example,
                   3724:     which a program's configure script or install target omitted.
                   3725: 
                   3726:     About 5% of the pkgsrc packages define their custom post-extract target,
                   3727:     another 5% define pre-configure, and 10% define post-install. The other pre
                   3728:     /post-* targets are defined even less often.
1.1       dsieger  3729: 
1.184     rillig   3730: do-*
1.182     leot     3731: 
1.184     rillig   3732:     Should one of the main targets do the wrong thing, and should there be no
                   3733:     variable to fix this, you can redefine it with the do-* target. (Note that
                   3734:     redefining the target itself instead of the do-* target is a bad idea, as
                   3735:     the pre-* and post-* targets won't be called anymore, etc.)
1.1       dsieger  3736: 
1.184     rillig   3737:     About 15% of the pkgsrc packages override the default do-install, the other
                   3738:     do-* targets are overridden even less often.
1.1       dsieger  3739: 
1.184     rillig   3740: reinstall
1.1       dsieger  3741: 
1.184     rillig   3742:     If you did a make install and you noticed some file was not installed
                   3743:     properly, you can repeat the installation with this target, which will
                   3744:     ignore the "already installed" flag.
1.1       dsieger  3745: 
1.184     rillig   3746:     This is the default value of DEPENDS_TARGET except in the case of make
                   3747:     update and make package, where the defaults are "package" and "update",
                   3748:     respectively.
1.1       dsieger  3749: 
1.184     rillig   3750: deinstall
1.1       dsieger  3751: 
1.184     rillig   3752:     This target does a pkg_delete(1) in the current directory, effectively
                   3753:     de-installing the package. The following variables can be used to tune the
                   3754:     behaviour:
1.1       dsieger  3755: 
1.184     rillig   3756:     PKG_VERBOSE
1.1       dsieger  3757: 
1.184     rillig   3758:         Add a "-v" to the pkg_delete(1) command.
1.1       dsieger  3759: 
1.184     rillig   3760:     DEINSTALLDEPENDS
1.1       dsieger  3761: 
1.184     rillig   3762:         Remove all packages that require (depend on) the given package. This
                   3763:         can be used to remove any packages that may have been pulled in by a
                   3764:         given package, e.g. if make deinstall DEINSTALLDEPENDS=1 is done in
                   3765:         pkgsrc/x11/kde, this is likely to remove whole KDE. Works by adding "-R
                   3766:         " to the pkg_delete(1) command line.
1.1       dsieger  3767: 
1.184     rillig   3768: bin-install
1.1       dsieger  3769: 
1.184     rillig   3770:     Install a binary package from local disk and via FTP from a list of sites
                   3771:     (see the BINPKG_SITES variable), and do a make package if no binary package
                   3772:     is available anywhere. The arguments given to pkg_add can be set via
                   3773:     BIN_INSTALL_FLAGS e.g., to do verbose operation, etc.
1.1       dsieger  3774: 
1.184     rillig   3775: install-clean
1.1       dsieger  3776: 
1.184     rillig   3777:     This target removes the state files for the "install" and later phases so
                   3778:     that the "install" target may be re-invoked. This can be used after editing
                   3779:     the PLIST to install the package without rebuilding it.
1.1       dsieger  3780: 
1.184     rillig   3781: build-clean
1.18      mishka   3782: 
1.184     rillig   3783:     This target removes the state files for the "build" and later phases so
                   3784:     that the "build" target may be re-invoked.
1.18      mishka   3785: 
1.184     rillig   3786: update
1.18      mishka   3787: 
1.184     rillig   3788:     This target causes the current package to be updated to the latest version.
                   3789:     The package and all depending packages first get de-installed, then current
                   3790:     versions of the corresponding packages get compiled and installed. This is
                   3791:     similar to manually noting which packages are currently installed, then
                   3792:     performing a series of make deinstall and make install (or whatever
                   3793:     UPDATE_TARGET is set to) for these packages.
1.18      mishka   3794: 
1.184     rillig   3795:     You can use the "update" target to resume package updating in case a
                   3796:     previous make update was interrupted for some reason. However, in this
                   3797:     case, make sure you don't call make clean or otherwise remove the list of
                   3798:     dependent packages in WRKDIR. Otherwise, you lose the ability to
                   3799:     automatically update the current package along with the dependent packages
                   3800:     you have installed.
1.121     sevan    3801: 
1.184     rillig   3802:     Resuming an interrupted make update will only work as long as the package
                   3803:     tree remains unchanged. If the source code for one of the packages to be
                   3804:     updated has been changed, resuming make update will most certainly fail!
1.1       dsieger  3805: 
1.184     rillig   3806:     The following variables can be used either on the command line or in
                   3807:     mk.conf to alter the behaviour of make update:
1.1       dsieger  3808: 
1.184     rillig   3809:     UPDATE_TARGET
1.1       dsieger  3810: 
1.184     rillig   3811:         Install target to recursively use for the updated package and the
                   3812:         dependent packages. Defaults to DEPENDS_TARGET if set, "install"
                   3813:         otherwise for make update. Other good targets are "package" or "
                   3814:         bin-install". Do not set this to "update" or you will get stuck in an
                   3815:         endless loop!
1.1       dsieger  3816: 
1.184     rillig   3817:     NOCLEAN
1.1       dsieger  3818: 
1.184     rillig   3819:         Don't clean up after updating. Useful if you want to leave the work
                   3820:         sources of the updated packages around for inspection or other
                   3821:         purposes. Be sure you eventually clean up the source tree (see the "
                   3822:         clean-update" target below) or you may run into troubles with old
                   3823:         source code still lying around on your next make or make update.
1.1       dsieger  3824: 
1.184     rillig   3825:     REINSTALL
1.1       dsieger  3826: 
1.184     rillig   3827:         Deinstall each package before installing (making DEPENDS_TARGET). This
                   3828:         may be necessary if the "clean-update" target (see below) was called
                   3829:         after interrupting a running make update.
1.1       dsieger  3830: 
1.184     rillig   3831:     DEPENDS_TARGET
1.1       dsieger  3832: 
1.184     rillig   3833:         Allows you to disable recursion and hardcode the target for packages.
                   3834:         The default is "update" for the update target, facilitating a recursive
                   3835:         update of prerequisite packages. Only set DEPENDS_TARGET if you want to
                   3836:         disable recursive updates. Use UPDATE_TARGET instead to just set a
                   3837:         specific target for each package to be installed during make update
                   3838:         (see above).
1.1       dsieger  3839: 
1.184     rillig   3840: clean-update
1.1       dsieger  3841: 
1.184     rillig   3842:     Clean the source tree for all packages that would get updated if make
                   3843:     update was called from the current directory. This target should not be
                   3844:     used if the current package (or any of its depending packages) have already
                   3845:     been de-installed (e.g., after calling make update) or you may lose some
                   3846:     packages you intended to update. As a rule of thumb: only use this target 
                   3847:     before the first time you run make update and only if you have a dirty
                   3848:     package tree (e.g., if you used NOCLEAN).
1.86      wiz      3849: 
1.184     rillig   3850:     If you are unsure about whether your tree is clean, you can either perform
                   3851:     a make clean at the top of the tree, or use the following sequence of
                   3852:     commands from the directory of the package you want to update (before
                   3853:     running make update for the first time, otherwise you lose all the packages
                   3854:     you wanted to update!):
1.86      wiz      3855: 
1.184     rillig   3856:     # make clean-update
                   3857:     # make clean CLEANDEPENDS=YES
                   3858:     # make update
1.86      wiz      3859: 
                   3860: 
1.184     rillig   3861:     The following variables can be used either on the command line or in
                   3862:     mk.conf to alter the behaviour of make clean-update:
1.86      wiz      3863: 
1.184     rillig   3864:     CLEAR_DIRLIST
1.86      wiz      3865: 
1.184     rillig   3866:         After make clean, do not reconstruct the list of directories to update
                   3867:         for this package. Only use this if make update successfully installed
                   3868:         all packages you wanted to update. Normally, this is done automatically
                   3869:         on make update, but may have been suppressed by the NOCLEAN variable
                   3870:         (see above).
1.1       dsieger  3871: 
1.184     rillig   3872: replace
1.1       dsieger  3873: 
1.184     rillig   3874:     Update the installation of the current package. This differs from update in
                   3875:     that it does not replace dependent packages. You will need to install
                   3876:     pkgtools/pkg_tarup for this target to work.
1.1       dsieger  3877: 
1.184     rillig   3878:     Be careful when using this target! There are no guarantees that dependent
                   3879:     packages will still work, in particular they will most certainly break if
                   3880:     you make replace a library package whose shared library major version
                   3881:     changed between your installed version and the new one. For this reason,
                   3882:     this target is not officially supported and only recommended for advanced
                   3883:     users.
1.1       dsieger  3884: 
1.184     rillig   3885: info
1.1       dsieger  3886: 
1.184     rillig   3887:     This target invokes pkg_info(1) for the current package. You can use this
                   3888:     to check which version of a package is installed.
1.86      wiz      3889: 
1.184     rillig   3890: index
1.1       dsieger  3891: 
1.184     rillig   3892:     This is a top-level command, i.e. it should be used in the pkgsrc
                   3893:     directory. It creates a database of all packages in the local pkgsrc tree,
                   3894:     including dependencies, comment, maintainer, and some other useful
                   3895:     information. Individual entries are created by running make describe in the
                   3896:     packages' directories. This index file is saved as pkgsrc/INDEX. It can be
                   3897:     displayed in verbose format by running make print-index. You can search in
                   3898:     it with make search key=something. You can extract a list of all packages
                   3899:     that depend on a particular one by running make show-deps PKG=somepackage.
1.1       dsieger  3900: 
1.184     rillig   3901:     Running this command takes a very long time, some hours even on fast
                   3902:     machines!
1.1       dsieger  3903: 
1.184     rillig   3904: readme
1.1       dsieger  3905: 
1.199     nia      3906:     This target generates a index.html file, which can be viewed using a
1.184     rillig   3907:     browser such as www/firefox or www/links. The generated files contain
                   3908:     references to any packages which are in the PACKAGES directory on the local
                   3909:     host. The generated files can be made to refer to URLs based on
                   3910:     FTP_PKG_URL_HOST and FTP_PKG_URL_DIR. For example, if I wanted to generate
1.199     nia      3911:     index.html files which pointed to binary packages on the local machine, in
1.184     rillig   3912:     the directory /usr/packages, set FTP_PKG_URL_HOST=file://localhost and
                   3913:     FTP_PKG_URL_DIR=/usr/packages. The ${PACKAGES} directory and its
                   3914:     subdirectories will be searched for all the binary packages.
1.1       dsieger  3915: 
1.184     rillig   3916:     The target can be run at the toplevel or in category directories, in which
                   3917:     case it descends recursively.
1.1       dsieger  3918: 
1.184     rillig   3919: readme-all
1.1       dsieger  3920: 
1.184     rillig   3921:     This is a top-level command, run it in pkgsrc. Use this target to create a
                   3922:     file README-all.html which contains a list of all packages currently
                   3923:     available in the NetBSD Packages Collection, together with the category
                   3924:     they belong to and a short description. This file is compiled from the
1.199     nia      3925:     pkgsrc/*/index.html files, so be sure to run this after a make readme.
1.1       dsieger  3926: 
1.184     rillig   3927: cdrom-readme
1.1       dsieger  3928: 
1.184     rillig   3929:     This is very much the same as the "readme" target (see above), but is to be
                   3930:     used when generating a pkgsrc tree to be written to a CD-ROM. This target
1.199     nia      3931:     also produces index.html files, and can be made to refer to URLs based on
1.184     rillig   3932:     CDROM_PKG_URL_HOST and CDROM_PKG_URL_DIR.
1.1       dsieger  3933: 
1.184     rillig   3934: show-distfiles
1.1       dsieger  3935: 
1.184     rillig   3936:     This target shows which distfiles and patchfiles are needed to build the
                   3937:     package (ALLFILES, which contains all DISTFILES and PATCHFILES, but not
                   3938:     patches/*).
1.1       dsieger  3939: 
1.184     rillig   3940: show-downlevel
1.1       dsieger  3941: 
1.184     rillig   3942:     This target shows nothing if the package is not installed. If a version of
                   3943:     this package is installed, but is not the version provided in this version
                   3944:     of pkgsrc, then a warning message is displayed. This target can be used to
                   3945:     show which of your installed packages are downlevel, and so the old
                   3946:     versions can be deleted, and the current ones added.
1.1       dsieger  3947: 
1.184     rillig   3948: show-pkgsrc-dir
1.1       dsieger  3949: 
1.184     rillig   3950:     This target shows the directory in the pkgsrc hierarchy from which the
                   3951:     package can be built and installed. This may not be the same directory as
                   3952:     the one from which the package was installed. This target is intended to be
                   3953:     used by people who may wish to upgrade many packages on a single host, and
                   3954:     can be invoked from the top-level pkgsrc Makefile by using the "
                   3955:     show-host-specific-pkgs" target.
1.1       dsieger  3956: 
1.184     rillig   3957: show-installed-depends
1.1       dsieger  3958: 
1.184     rillig   3959:     This target shows which installed packages match the current package's
                   3960:     DEPENDS. Useful if out of date dependencies are causing build problems.
1.1       dsieger  3961: 
1.184     rillig   3962: print-build-depends-list
1.1       dsieger  3963: 
1.184     rillig   3964:     This target shows the list of packages that the current package depends on
                   3965:     for building.
1.1       dsieger  3966: 
1.184     rillig   3967: print-run-depends-list
1.1       dsieger  3968: 
1.184     rillig   3969:     This target shows the list of packages that the current package depends on
                   3970:     for running.
1.1       dsieger  3971: 
1.184     rillig   3972: check-shlibs
1.1       dsieger  3973: 
1.184     rillig   3974:     After a package is installed, check all its binaries and (on ELF platforms)
                   3975:     shared libraries to see if they find the shared libs they need. Run by
                   3976:     default if PKG_DEVELOPER is set in mk.conf.
1.1       dsieger  3977: 
1.184     rillig   3978: print-PLIST
1.1       dsieger  3979: 
1.184     rillig   3980:     After a "make install" from a new or upgraded pkg, this prints out an
                   3981:     attempt to generate a new PLIST from a find -newer work/.extract_done. An
                   3982:     attempt is made to care for shared libs etc., but it is strongly
                   3983:     recommended to review the result before putting it into PLIST. On upgrades,
                   3984:     it's useful to diff the output of this command against an already existing
                   3985:     PLIST file.
1.1       dsieger  3986: 
1.184     rillig   3987:     If the package installs files via tar(1) or other methods that don't update
                   3988:     file access times, be sure to add these files manually to your PLIST, as
                   3989:     the "find -newer" command used by this target won't catch them!
1.56      ryoon    3990: 
1.184     rillig   3991:     See Section 19.3, "Tweaking output of make print-PLIST" for more
                   3992:     information on this target.
1.1       dsieger  3993: 
1.184     rillig   3994: Chapter 14. Creating a new pkgsrc package from scratch
1.1       dsieger  3995: 
1.184     rillig   3996: Table of Contents
1.1       dsieger  3997: 
1.184     rillig   3998: 14.1. Common types of packages
1.219     nia      3999:     14.1.1. Python modules and programs
                   4000:     14.1.2. R packages
                   4001:     14.1.3. TeXlive packages
1.184     rillig   4002: 14.2. Examples
                   4003:     14.2.1. How the www/nvu package came into pkgsrc
1.1       dsieger  4004: 
1.184     rillig   4005: When you find a package that is not yet in pkgsrc, you most likely have a URL
                   4006: from where you can download the source code. Starting with this URL, creating a
                   4007: package involves only a few steps.
1.1       dsieger  4008: 
1.184     rillig   4009:  1. In your mk.conf, set PKG_DEVELOPER=yes to enable the basic quality checks.
1.1       dsieger  4010: 
1.184     rillig   4011:  2. Install the package meta-pkgs/pkg_developer, which among others will
                   4012:     install the utilities url2pkg, pkglint, pkgvi and mkpatches:
1.1       dsieger  4013: 
1.184     rillig   4014:     $ cd /usr/pkgsrc
                   4015:     $ (cd meta-pkgs/pkg_developer && bmake update)
1.1       dsieger  4016: 
1.184     rillig   4017:  3. Choose one of the top-level directories as the category in which you want
                   4018:     to place your package. You can also create a directory of your own (maybe
1.219     nia      4019:     called local). Change into that category directory:
1.1       dsieger  4020: 
1.219     nia      4021:     $ cd category
1.1       dsieger  4022: 
1.219     nia      4023:  4. Run the program url2pkg, passing as argument the URL of the distribution
                   4024:     file (in most cases a .tar.gz file). This will download the distribution
                   4025:     file and create the necessary files of the package, based on what's in the
                   4026:     distribution file:
1.1       dsieger  4027: 
1.184     rillig   4028:     $ url2pkg https://www.example.org/packages/package-1.0.tar.gz
1.1       dsieger  4029: 
1.184     rillig   4030:  5. Examine the extracted files to determine the dependencies of your package.
                   4031:     Ideally, this is mentioned in some README file, but things may differ. For
                   4032:     each of these dependencies, look where it exists in pkgsrc, and if there is
                   4033:     a file called buildlink3.mk in that directory, add a line to your package
                   4034:     Makefile which includes that file just before the last line. If the
                   4035:     buildlink3.mk file does not exist, it must be created first. The
                   4036:     buildlink3.mk file makes sure that the package's include files and
                   4037:     libraries are provided.
1.1       dsieger  4038: 
1.219     nia      4039:     If you just need binaries from a dependent package, add a DEPENDS line to
                   4040:     the Makefile, which specifies the version of the dependency and where it
                   4041:     can be found in pkgsrc. This line should be placed in the third paragraph.
                   4042:     If the dependency is only needed for building the package, but not when
                   4043:     using it, use TOOL_DEPENDS or BUILD_DEPENDS instead of DEPENDS. The
                   4044:     difference between TOOL_DEPENDS and BUILD_DEPENDS occurs when
                   4045:     cross-compiling: TOOL_DEPENDS are native packages, i.e. packages for the
                   4046:     platform where the package is built; BUILD_DEPENDS are target packages,
                   4047:     i.e. packages for the platform for which the package is built. There is
                   4048:     also TEST_DEPENDS, which specifies a dependency used only for testing the
                   4049:     resulting package built, using the upstream project's included test suite,
                   4050:     on the native platform. Your package may then look like this:
1.1       dsieger  4051: 
1.184     rillig   4052:     [...]
1.1       dsieger  4053: 
1.184     rillig   4054:     TOOL_DEPENDS+=  libxslt-[0-9]*:../../textproc/libxslt
                   4055:     DEPENDS+=       screen-[0-9]*:../../misc/screen
                   4056:     DEPENDS+=       screen>=4.0:../../misc/screen
1.1       dsieger  4057: 
1.184     rillig   4058:     [...]
1.1       dsieger  4059: 
1.184     rillig   4060:     .include "../../category/package/buildlink3.mk"
                   4061:     .include "../../devel/glib2/buildlink3.mk"
                   4062:     .include "../../mk/bsd.pkg.mk"
1.1       dsieger  4063: 
1.184     rillig   4064:  6. Run pkglint to see what things still need to be done to make your package a
                   4065:     "good" one. If you don't know what pkglint's warnings want to tell you, try
                   4066:     pkglint --explain or pkglint -e, which outputs additional explanations.
1.1       dsieger  4067: 
1.184     rillig   4068:  7. In many cases the package is not yet ready to build. You can find
                   4069:     instructions for the most common cases in the next section, Section 14.1,
                   4070:     "Common types of packages". After you have followed the instructions over
                   4071:     there, you can hopefully continue here.
1.1       dsieger  4072: 
1.184     rillig   4073:  8. Run bmake clean to clean the working directory from the extracted files.
1.219     nia      4074:     Besides these files, a lot of cache files and other system information have
                   4075:     been saved in the working directory, which may have become outdated after
                   4076:     you edited the Makefile.
1.1       dsieger  4077: 
1.184     rillig   4078:  9. Now, run bmake to build the package. For the various things that can go
                   4079:     wrong in this phase, consult Chapter 21, Making your package work.
1.1       dsieger  4080: 
1.184     rillig   4081:     If the extracted files from the package need to be fixed, run multiple
                   4082:     rounds of these commands:
1.1       dsieger  4083: 
1.219     nia      4084:     $ bmake
1.184     rillig   4085:     $ pkgvi ${WRKSRC}/some/file/that/does/not/compile
                   4086:     $ mkpatches
1.219     nia      4087:     $ bmake mps
                   4088:     $ bmake clean
1.1       dsieger  4089: 
1.184     rillig   4090: 10. When the package builds fine, the next step is to install the package. Run 
                   4091:     bmake install and hope that everything works.
1.1       dsieger  4092: 
1.184     rillig   4093: 11. Up to now, the file PLIST, which contains a list of the files that are
                   4094:     installed by the package, is nearly empty. Run bmake print-PLIST >PLIST to
                   4095:     generate a probably correct list. Check the file using your preferred text
                   4096:     editor to see if the list of files looks plausible.
1.1       dsieger  4097: 
1.184     rillig   4098: 12. Run pkglint again to see if the generated PLIST contains garbage or not.
1.1       dsieger  4099: 
1.184     rillig   4100: 13. When you ran bmake install, the package had been registered in the database
                   4101:     of installed files, but with an empty list of files. To fix this, run bmake
                   4102:     deinstall and bmake install again. Now the package is registered with the
                   4103:     list of files from PLIST.
1.48      wiz      4104: 
1.219     nia      4105: 14. Run bmake clean update to run everything from above again in a single step,
1.184     rillig   4106:     making sure that the PLIST is correct and the whole package is created as
                   4107:     intended.
1.48      wiz      4108: 
1.219     nia      4109: 15. Run pkglint to see if there's anything left to do.
1.48      wiz      4110: 
1.219     nia      4111: 16. Commit the package to pkgsrc-wip or main pkgsrc; see Chapter 23, Submitting
1.184     rillig   4112:     and Committing.
1.50      wiz      4113: 
1.184     rillig   4114: 14.1. Common types of packages
1.1       dsieger  4115: 
1.219     nia      4116: 14.1.1. Python modules and programs
1.1       dsieger  4117: 
1.184     rillig   4118: Python modules and programs packages are easily created using a set of
                   4119: predefined variables.
1.1       dsieger  4120: 
1.184     rillig   4121: If some Python versions are not supported by the software, set the
                   4122: PYTHON_VERSIONS_INCOMPATIBLE variable to the Python versions that are not
                   4123: supported, e.g.
1.1       dsieger  4124: 
1.184     rillig   4125: PYTHON_VERSIONS_INCOMPATIBLE=       27
1.1       dsieger  4126: 
1.184     rillig   4127: If the packaged software is a Python module, include one of ../../lang/python/
1.215     wiz      4128: egg.mk or ../../lang/python/extension.mk.
1.1       dsieger  4129: 
1.215     wiz      4130: Most Python packages use setuptools ("eggs"). If the packaged software is using
                   4131: setuptools, you only need to include "../../lang/python/egg.mk".
1.1       dsieger  4132: 
1.184     rillig   4133: Either way, the package directory should be called "py-software" and PKGNAME
                   4134: should be set to "${PYPKGPREFIX}-${DISTNAME}", e.g.
1.1       dsieger  4135: 
1.184     rillig   4136: DISTNAME=   foopymodule-1.2.10
                   4137: PKGNAME=    ${PYPKGPREFIX}-${DISTNAME}
1.1       dsieger  4138: 
1.226     gutterid 4139: For software in PyPi, the name should match what PyPi specifies for "pip
                   4140: install software".
                   4141: 
1.184     rillig   4142: If it is an application, include "../../lang/python/application.mk". In order
                   4143: to correctly set the path to the Python interpreter, use the REPLACE_PYTHON
                   4144: variable and set it to the list of files (paths relative to WRKSRC) that must
                   4145: be corrected. For example:
1.1       dsieger  4146: 
1.184     rillig   4147: REPLACE_PYTHON=   *.py
1.1       dsieger  4148: 
1.184     rillig   4149: Some Python modules have separate distributions for Python-2.x and Python-3.x
                   4150: support. In pkgsrc this is handled by the versioned_dependencies.mk file. Set
                   4151: PYTHON_VERSIONED_DEPENDENCIES to the list of packages that should be depended
                   4152: upon and include "../../lang/python/versioned_dependencies.mk", then the pkgsrc
                   4153: infrastructure will depend on the appropriate package version. For example:
1.1       dsieger  4154: 
1.184     rillig   4155: PYTHON_VERSIONED_DEPENDENCIES=dialog
1.1       dsieger  4156: 
1.184     rillig   4157: Look inside versioned_dependencies.mk for a list of supported packages.
1.1       dsieger  4158: 
1.219     nia      4159: 14.1.2. R packages
1.1       dsieger  4160: 
1.184     rillig   4161: Simple R packages from CRAN are handled automatically by R2pkg, which is
                   4162: available in pkgtools/R2pkg. Individual packages (and optionally their
                   4163: dependencies) may be created and updated. R packages generally follow the same
                   4164: form, and most of the relevant information needed is contained in a DESCRIPTION
                   4165: file as part of each R package on CRAN. Consequently, R2pkg downloads that
                   4166: information and creates or updates a package in the canonical form. The
                   4167: resulting package should be reviewed for correctness.
1.1       dsieger  4168: 
1.219     nia      4169: 14.1.3. TeXlive packages
1.1       dsieger  4170: 
1.184     rillig   4171: TeXlive packages from CTAN are handled automatically by texlive2pkg, which is
                   4172: available in pkgtools/texlive2pkg.
1.1       dsieger  4173: 
1.184     rillig   4174: If the TeXlive package name is not known, it may be useful to search CTAN. A "
                   4175: Contained in" field on the package page typically identifies the basename of
                   4176: the package file in the TeXlive archive.
1.1       dsieger  4177: 
1.184     rillig   4178: If the TeXlive package name is known, download the files from the TeXlive
                   4179: archive. For package foo, you will need to download foo.tar.xz. Most TeXlive
                   4180: packages also have associated documentation packages, so download
                   4181: foo.doc.tar.xz at the same time. These files should be placed in the
                   4182: appropriate category directory, which is often but not always print. Then run
                   4183: the following command in the category directory.
1.1       dsieger  4184: 
1.184     rillig   4185: texlive2pkg foo.tar.xz foo.doc.tar.xz
1.1       dsieger  4186: 
1.184     rillig   4187: This will create two packages, tex-foo and tex-foo-doc. Be sure to check that
                   4188: both packages are correct.
1.1       dsieger  4189: 
1.184     rillig   4190: Finally, CTAN currently does not include version information in package
                   4191: filenames and changes their contents periodically when updates occur.
                   4192: Consequently, pkgsrc avoids downloading distfiles directly from CTAN and
                   4193: instead relies on the pkgsrc archives. For each new or updated TeXlive package,
                   4194: e.g., the main one and the corresponding documentation, upload the distfiles
                   4195: with the following command in each package directory.
1.1       dsieger  4196: 
1.184     rillig   4197: make upload-distfiles
1.117     sevan    4198: 
1.184     rillig   4199: 14.2. Examples
1.117     sevan    4200: 
1.184     rillig   4201: 14.2.1. How the www/nvu package came into pkgsrc
1.1       dsieger  4202: 
1.184     rillig   4203: 14.2.1.1. The initial package
1.1       dsieger  4204: 
1.184     rillig   4205: Looking at the file pkgsrc/doc/TODO, I saw that the "nvu" package has not yet
                   4206: been imported into pkgsrc. As the description says it has to do with the web,
                   4207: the obvious choice for the category is "www".
1.1       dsieger  4208: 
1.184     rillig   4209: $ mkdir www/nvu
                   4210: $ cd www/nvu
1.1       dsieger  4211: 
1.184     rillig   4212: The web site says that the sources are available as a tar file, so I fed that
                   4213: URL to the url2pkg program:
1.1       dsieger  4214: 
1.184     rillig   4215: $ url2pkg http://cvs.nvu.com/download/nvu-1.0-sources.tar.bz2
1.1       dsieger  4216: 
1.184     rillig   4217: My editor popped up, and I added a PKGNAME line below the DISTNAME line, as the
                   4218: package name should not have the word "sources" in it. I also filled in the
                   4219: MAINTAINER, HOMEPAGE and COMMENT fields. Then the package Makefile looked like
                   4220: that:
1.1       dsieger  4221: 
1.184     rillig   4222: # $NetBSD $
                   4223: #
1.1       dsieger  4224: 
1.184     rillig   4225: DISTNAME=       nvu-1.0-sources
                   4226: PKGNAME=        nvu-1.0
                   4227: CATEGORIES=     www
                   4228: MASTER_SITES=   http://cvs.nvu.com/download/
                   4229: EXTRACT_SUFX=   .tar.bz2
1.1       dsieger  4230: 
1.184     rillig   4231: MAINTAINER=     rillig@NetBSD.org
                   4232: HOMEPAGE=       http://cvs.nvu.com/
                   4233: COMMENT=        Web Authoring System
1.1       dsieger  4234: 
1.184     rillig   4235: # url2pkg-marker (please do not remove this line.)
                   4236: .include "../../mk/bsd.pkg.mk"
1.1       dsieger  4237: 
1.184     rillig   4238: On the first line of output above, an artificial space has been added between
                   4239: NetBSD and $, this is a workaround to prevent CVS expanding to the filename of
                   4240: the guide.
1.1       dsieger  4241: 
1.184     rillig   4242: Then, I quit the editor and watched pkgsrc downloading a large source archive:
1.1       dsieger  4243: 
1.184     rillig   4244: url2pkg> Running "make makesum" ...
                   4245: => Required installed package digest>=20010302: digest-20060826 found
                   4246: => Fetching nvu-1.0-sources.tar.bz2
                   4247: Requesting http://cvs.nvu.com/download/nvu-1.0-sources.tar.bz2
                   4248: 100% |*************************************| 28992 KB  150.77 KB/s00:00 ETA
                   4249: 29687976 bytes retrieved in 03:12 (150.77 KB/s)
                   4250: url2pkg> Running "make extract" ...
                   4251: => Required installed package digest>=20010302: digest-20060826 found
                   4252: => Checksum SHA1 OK for nvu-1.0-sources.tar.bz2
                   4253: => Checksum RMD160 OK for nvu-1.0-sources.tar.bz2
                   4254: work.bacc -> /tmp/roland/pkgsrc/www/nvu/work.bacc
                   4255: ===> Installing dependencies for nvu-1.0
                   4256: ===> Overriding tools for nvu-1.0
                   4257: ===> Extracting for nvu-1.0
                   4258: url2pkg> Adjusting the Makefile.
1.1       dsieger  4259: 
1.184     rillig   4260: Remember to correct CATEGORIES, HOMEPAGE, COMMENT, and DESCR when you're done!
1.1       dsieger  4261: 
1.184     rillig   4262: Good luck! (See pkgsrc/doc/pkgsrc.txt for some more help :-)
1.1       dsieger  4263: 
1.184     rillig   4264: 14.2.1.2. Fixing all kinds of problems to make the package work
1.1       dsieger  4265: 
1.184     rillig   4266: Now that the package has been extracted, let's see what's inside it. The
                   4267: package has a README.txt, but that only says something about mozilla, so it's
                   4268: probably useless for seeing what dependencies this package has. But since there
                   4269: is a GNU configure script in the package, let's hope that it will complain
                   4270: about everything it needs.
1.1       dsieger  4271: 
1.184     rillig   4272: $ bmake
                   4273: => Required installed package digest>=20010302: digest-20060826 found
                   4274: => Checksum SHA1 OK for nvu-1.0-sources.tar.bz2
                   4275: => Checksum RMD160 OK for nvu-1.0-sources.tar.bz2
                   4276: ===> Patching for nvu-1.0
                   4277: ===> Creating toolchain wrappers for nvu-1.0
                   4278: ===> Configuring for nvu-1.0
                   4279: [...]
                   4280: configure: error: Perl 5.004 or higher is required.
                   4281: [...]
                   4282: WARNING: Please add USE_TOOLS+=perl to the package Makefile.
                   4283: [...]
1.1       dsieger  4284: 
1.184     rillig   4285: That worked quite well. So I opened the package Makefile in my editor, and
                   4286: since it already has a USE_TOOLS line, I just appended "perl" to it. Since the
                   4287: dependencies of the package have changed now, and since a perl wrapper is
                   4288: automatically installed in the "tools" phase, I need to build the package from
                   4289: scratch.
1.1       dsieger  4290: 
1.184     rillig   4291: $ bmake clean
                   4292: ===> Cleaning for nvu-1.0
                   4293: $ bmake
                   4294: [...]
                   4295: *** /tmp/roland/pkgsrc/www/nvu/work.bacc/.tools/bin/make is not \
                   4296: GNU Make.  You will not be able to build Mozilla without GNU Make.
                   4297: [...]
1.1       dsieger  4298: 
1.184     rillig   4299: So I added "gmake" to the USE_TOOLS line and tried again (from scratch).
1.1       dsieger  4300: 
1.184     rillig   4301: [...]
                   4302: checking for GTK - version >= 1.2.0... no
                   4303: *** Could not run GTK test program, checking why...
                   4304: [...]
1.1       dsieger  4305: 
1.184     rillig   4306: Now to the other dependencies. The first question is: Where is the GTK package
                   4307: hidden in pkgsrc?
1.1       dsieger  4308: 
1.184     rillig   4309: $ echo ../../*/gtk*
                   4310: [many packages ...]
                   4311: $ echo ../../*/gtk
                   4312: ../../x11/gtk
                   4313: $ echo ../../*/gtk2
                   4314: ../../x11/gtk2
                   4315: $ echo ../../*/gtk2/bui*
                   4316: ../../x11/gtk2/buildlink3.mk
1.1       dsieger  4317: 
1.184     rillig   4318: The first try was definitely too broad. The second one had exactly one result,
                   4319: which is very good. But there is one pitfall with GNOME packages. Before GNOME
                   4320: 2 had been released, there were already many GNOME 1 packages in pkgsrc. To be
                   4321: able to continue to use these packages, the GNOME 2 packages were imported as
                   4322: separate packages, and their names usually have a "2" appended. So I checked
                   4323: whether this was the case here, and indeed it was.
1.1       dsieger  4324: 
1.184     rillig   4325: Since the GTK2 package has a buildlink3.mk file, adding the dependency is very
                   4326: easy. I just inserted an .include line before the last line of the package
                   4327: Makefile, so that it now looks like this:
1.1       dsieger  4328: 
1.184     rillig   4329: [...]
                   4330: .include "../../x11/gtk2/buildlink3.mk"
                   4331: .include "../../mk/bsd.pkg.mk
1.1       dsieger  4332: 
1.184     rillig   4333: After another bmake clean && bmake, the answer was:
1.108     rillig   4334: 
1.184     rillig   4335: [...]
                   4336: checking for gtk-config... /home/roland/pkg/bin/gtk-config
                   4337: checking for GTK - version >= 1.2.0... no
                   4338: *** Could not run GTK test program, checking why...
                   4339: *** The test program failed to compile or link. See the file config.log for the
                   4340: *** exact error that occured. This usually means GTK was incorrectly installed
                   4341: *** or that you have moved GTK since it was installed. In the latter case, you
                   4342: *** may want to edit the gtk-config script: /home/roland/pkg/bin/gtk-config
                   4343: configure: error: Test for GTK failed.
                   4344: [...]
1.1       dsieger  4345: 
1.184     rillig   4346: In this particular case, the assumption that "every package prefers GNOME 2"
                   4347: had been wrong. The first of the lines above told me that this package really
                   4348: wanted to have the GNOME 1 version of GTK. If the package had looked for GTK2,
                   4349: it would have looked for pkg-config instead of gtk-config. So I changed the x11
                   4350: /gtk2 to x11/gtk in the package Makefile, and tried again.
1.1       dsieger  4351: 
1.184     rillig   4352: [...]
                   4353: cc -o xpidl.o -c -DOSTYPE=\"NetBSD3\" -DOSARCH=\"NetBSD\"  [...]
                   4354: In file included from xpidl.c:42:
                   4355: xpidl.h:53:24: libIDL/IDL.h: No such file or directory
                   4356: In file included from xpidl.c:42:
                   4357: xpidl.h:132: error: parse error before "IDL_ns"
                   4358: [...]
1.1       dsieger  4359: 
1.184     rillig   4360: The package still does not find all of its dependencies. Now the question is:
                   4361: Which package provides the libIDL/IDL.h header file?
1.1       dsieger  4362: 
1.184     rillig   4363: $ echo ../../*/*idl*
                   4364: ../../devel/py-idle ../../wip/idled ../../x11/acidlaunch
                   4365: $ echo ../../*/*IDL*
                   4366: ../../net/libIDL
1.1       dsieger  4367: 
1.184     rillig   4368: Let's take the one from the second try. So I included the ../../net/libIDL/
                   4369: buildlink3.mk file and tried again. But the error didn't change. After digging
                   4370: through some of the code, I concluded that the build process of the package was
                   4371: broken and couldn't have ever worked, but since the Mozilla source tree is
                   4372: quite large, I didn't want to fix it. So I added the following to the package
                   4373: Makefile and tried again:
1.1       dsieger  4374: 
1.184     rillig   4375: CPPFLAGS+=              -I${BUILDLINK_PREFIX.libIDL}/include/libIDL-2.0
                   4376: BUILDLINK_TRANSFORM+=   l:IDL:IDL-2
1.1       dsieger  4377: 
1.184     rillig   4378: The latter line is needed because the package expects the library libIDL.so,
                   4379: but only libIDL-2.so is available. So I told the compiler wrapper to rewrite
                   4380: that on the fly.
1.1       dsieger  4381: 
1.184     rillig   4382: The next problem was related to a recent change of the FreeType interface. I
                   4383: looked up in www/seamonkey which patch files were relevant for this issue and
                   4384: copied them to the patches directory. Then I retried, fixed the patches so that
                   4385: they applied cleanly and retried again. This time, everything worked.
1.1       dsieger  4386: 
1.184     rillig   4387: 14.2.1.3. Installing the package
1.1       dsieger  4388: 
1.184     rillig   4389: $ bmake CHECK_FILES=no install
                   4390: [...]
                   4391: $ bmake print-PLIST >PLIST
                   4392: $ bmake deinstall
                   4393: $ bmake install
1.1       dsieger  4394: 
1.184     rillig   4395: Chapter 15. Programming in Makefiles
1.1       dsieger  4396: 
1.184     rillig   4397: Table of Contents
1.1       dsieger  4398: 
1.184     rillig   4399: 15.1. Caveats
                   4400: 15.2. Makefile variables
                   4401:     15.2.1. Naming conventions
                   4402: 15.3. Code snippets
                   4403:     15.3.1. Adding things to a list
                   4404:     15.3.2. Echoing a string exactly as-is
                   4405:     15.3.3. Passing CFLAGS to GNU configure scripts
                   4406:     15.3.4. Handling possibly empty variables
1.229     gutterid 4407:     15.3.5. Testing yes/no variables in conditions
1.1       dsieger  4408: 
1.184     rillig   4409: Pkgsrc consists of many Makefile fragments, each of which forms a well-defined
                   4410: part of the pkgsrc system. Using the make(1) system as a programming language
                   4411: for a big system like pkgsrc requires some discipline to keep the code correct
                   4412: and understandable.
1.1       dsieger  4413: 
1.184     rillig   4414: The basic ingredients for Makefile programming are variables and shell
                   4415: commands. Among these shell commands may even be more complex ones like awk(1)
                   4416: programs. To make sure that every shell command runs as intended it is
                   4417: necessary to quote all variables correctly when they are used.
1.1       dsieger  4418: 
1.184     rillig   4419: This chapter describes some patterns that appear quite often in Makefiles,
                   4420: including the pitfalls that come along with them.
1.1       dsieger  4421: 
1.184     rillig   4422: 15.1. Caveats
1.1       dsieger  4423: 
1.184     rillig   4424:   * When you are creating a file as a target of a rule, always write the data
                   4425:     to a temporary file first and finally rename that file. Otherwise there
                   4426:     might occur an error in the middle of generating the file, and when the
                   4427:     user runs make(1) for the second time, the file exists and will not be
                   4428:     regenerated properly. Example:
1.1       dsieger  4429: 
1.184     rillig   4430:     wrong:
                   4431:             @echo "line 1" > ${.TARGET}
                   4432:             @echo "line 2" >> ${.TARGET}
                   4433:             @false
1.1       dsieger  4434: 
1.184     rillig   4435:     correct:
                   4436:             @echo "line 1" > ${.TARGET}.tmp
                   4437:             @echo "line 2" >> ${.TARGET}.tmp
                   4438:             @false
                   4439:             @mv ${.TARGET}.tmp ${.TARGET}
1.1       dsieger  4440: 
1.184     rillig   4441:     When you run make wrong twice, the file wrong will exist, although there
                   4442:     was an error message in the first run. On the other hand, running make
                   4443:     correct gives an error message twice, as expected.
1.1       dsieger  4444: 
1.184     rillig   4445:     You might remember that make(1) sometimes removes ${.TARGET} in case of
                   4446:     error, but this only happens when it is interrupted, for example by
                   4447:     pressing Ctrl+C. This does not happen when one of the commands fails (like
                   4448:     false(1) above).
1.1       dsieger  4449: 
1.184     rillig   4450: 15.2. Makefile variables
1.1       dsieger  4451: 
1.184     rillig   4452: Makefile variables contain strings that can be processed using the five
                   4453: operators =, +=, ?=, := and !=, which are described in the make(1) man page.
1.1       dsieger  4454: 
1.184     rillig   4455: When a variable's value is parsed from a Makefile, the hash character # and the
                   4456: backslash character \ are handled specially. If a backslash is the last
                   4457: character in a line, that backslash is removed from the line and the line
                   4458: continues with the next line of the file.
1.1       dsieger  4459: 
1.184     rillig   4460: The # character starts a comment that reaches until the end of the line. To get
                   4461: an actual # character, such as in a URL, write \# instead.
1.1       dsieger  4462: 
1.184     rillig   4463: The evaluation of variables either happens immediately or lazy. It happens
                   4464: immediately when the variable occurs on the right-hand side of the := or the !=
                   4465: operator, in a .if condition or a .for loop. In the other cases, it is
                   4466: evaluated lazily.
1.1       dsieger  4467: 
1.184     rillig   4468: Some of the modifiers split the string into words and then operate on the
                   4469: words, others operate on the string as a whole. When a string is split into
                   4470: words, double quotes and single quotes are interpreted as delimiters, just like
                   4471: in sh(1).
1.1       dsieger  4472: 
1.184     rillig   4473: 15.2.1. Naming conventions
1.1       dsieger  4474: 
1.184     rillig   4475:   * All variable names starting with an underscore are reserved for use by the
                   4476:     pkgsrc infrastructure. They shall not be used by packages.
1.1       dsieger  4477: 
1.184     rillig   4478:   * In .for loops you should use lowercase variable names for the iteration
                   4479:     variables.
1.1       dsieger  4480: 
1.184     rillig   4481:   * All list variables should have a plural name, such as PKG_OPTIONS or
                   4482:     DISTFILES.
1.1       dsieger  4483: 
1.184     rillig   4484: 15.3. Code snippets
1.1       dsieger  4485: 
1.184     rillig   4486: 15.3.1. Adding things to a list
1.1       dsieger  4487: 
1.184     rillig   4488: When adding a string that possibly contains whitespace or quotes to a list
                   4489: (example 1), it must be quoted using the :Q modifier.
1.1       dsieger  4490: 
1.184     rillig   4491: When adding another list to a list (example 2), it must not be quoted, since
                   4492: its elements are already quoted.
1.1       dsieger  4493: 
1.184     rillig   4494: STRING=         foo * bar `date`
                   4495: LIST=           # empty
                   4496: ANOTHER_LIST=   a=b c=d
1.1       dsieger  4497: 
1.184     rillig   4498: LIST+=          ${STRING:Q}       # 1
                   4499: LIST+=          ${ANOTHER_LIST}   # 2
1.1       dsieger  4500: 
1.184     rillig   4501: 15.3.2. Echoing a string exactly as-is
1.1       dsieger  4502: 
1.184     rillig   4503: Echoing a string containing special characters needs special work.
1.1       dsieger  4504: 
1.184     rillig   4505: STRING=         foo bar <    > * `date` $$HOME ' "
                   4506: EXAMPLE_ENV=    string=${STRING:Q} x=multiple\ quoted\ words
1.1       dsieger  4507: 
1.184     rillig   4508: all:
                   4509:         echo ${STRING}                  # 1
                   4510:         echo ${STRING:Q}                # 2
                   4511:         printf '%s\n' ${STRING:Q}''     # 3
                   4512:         env ${EXAMPLE_ENV} sh -c 'echo "$$string"; echo "$$x"'   # 4
1.1       dsieger  4513: 
1.184     rillig   4514: Example 1 leads to a syntax error in the shell, as the characters are just
                   4515: copied.
1.1       dsieger  4516: 
1.184     rillig   4517: Example 2 quotes the string so that the shell interprets it correctly. But the
                   4518: echo command may additionally interpret strings with a leading dash or those
                   4519: containing backslashes.
1.1       dsieger  4520: 
1.184     rillig   4521: Example 3 can handle arbitrary strings, since printf(1) only interprets the
                   4522: format string, but not the next argument. The trailing single quotes handle the
                   4523: case when the string is empty. In that case, the :Q modifier would result in an
                   4524: empty string too, which would then be skipped by the shell. For printf(1) this
                   4525: doesn't make a difference, but other programs may care.
1.1       dsieger  4526: 
1.184     rillig   4527: In example 4, the EXAMPLE_ENV does not need to be quoted because the quoting
                   4528: has already been done when adding elements to the list.
1.1       dsieger  4529: 
1.184     rillig   4530: 15.3.3. Passing CFLAGS to GNU configure scripts
1.1       dsieger  4531: 
1.184     rillig   4532: When passing CFLAGS or similar variables to a GNU-style configure script
                   4533: (especially those that call other configure scripts), it must not have leading
                   4534: or trailing whitespace, since otherwise the configure script gets confused. To
                   4535: trim leading and trailing whitespace, use the :M modifier, as in the following
                   4536: example:
1.1       dsieger  4537: 
1.184     rillig   4538: CPPFLAGS=               # empty
                   4539: CPPFLAGS+=              -Wundef -DPREFIX=\"${PREFIX}\"
                   4540: CPPFLAGS+=              ${MY_CPPFLAGS}
1.1       dsieger  4541: 
1.184     rillig   4542: CONFIGURE_ARGS+=        CPPFLAGS=${CPPFLAGS:M*:Q}
1.1       dsieger  4543: 
1.184     rillig   4544: all:
                   4545:         echo x${CPPFLAGS:Q}x            # leading and trailing whitespace
                   4546:         echo x${CONFIGURE_ARGS:Q}x      # properly trimmed
1.1       dsieger  4547: 
1.184     rillig   4548: In this example, CPPFLAGS has both leading and trailing whitespace because the
                   4549: += operator always adds a space.
1.1       dsieger  4550: 
1.184     rillig   4551: 15.3.4. Handling possibly empty variables
1.1       dsieger  4552: 
1.184     rillig   4553: When a possibly empty variable is used in a shell program, it may lead to a
                   4554: syntax error.
1.1       dsieger  4555: 
1.184     rillig   4556: EGFILES=        # empty
1.1       dsieger  4557: 
1.184     rillig   4558: install-examples:   # produces a syntax error in the shell
                   4559:         for egfile in ${EGFILES}; do            \
                   4560:                 echo "Installing $$egfile";     \
                   4561:         done
1.1       dsieger  4562: 
1.184     rillig   4563: The shell only sees the text for egfile in ; do, since ${EGFILES} is replaced
                   4564: with an empty string by make(1). To fix this syntax error, use one of the
                   4565: snippets below.
1.1       dsieger  4566: 
1.229     gutterid 4567: EGFILES=        # empty
1.1       dsieger  4568: 
1.184     rillig   4569: install-examples:
                   4570:         for egfile in ${EGFILES} ""; do         \
                   4571:                 [ -n "$$egfile" ] || continue;  \
                   4572:                 echo "Installing $$egfile";     \
                   4573:         done
1.1       dsieger  4574: 
1.184     rillig   4575: In this case, an empty string is appended to the iteration list (to prevent the
                   4576: syntax error) and filtered out later.
1.1       dsieger  4577: 
1.184     rillig   4578: EGFILES=        # empty
1.1       dsieger  4579: 
1.184     rillig   4580: install-examples:
                   4581: .for egfile in ${EGFILES}
                   4582:         echo "Installing ${egfile}"
                   4583: .endfor
1.1       dsieger  4584: 
1.184     rillig   4585: If one of the filenames contains special characters, it should be enclosed in
                   4586: single or double quotes.
1.1       dsieger  4587: 
1.184     rillig   4588: To have a shell command test whether a make variable is empty, use the
                   4589: following code: ${TEST} -z ${POSSIBLY_EMPTY:Q}"".
1.1       dsieger  4590: 
1.229     gutterid 4591: 15.3.5. Testing yes/no variables in conditions
                   4592: 
                   4593: When a variable can have the values yes or no, use the following pattern to
                   4594: test the variable:
                   4595: 
                   4596: .if ${VAR:U:tl} == "yes"
                   4597: # do something
                   4598: .endif
                   4599: 
                   4600: The :U modifier is only necessary if the variable can be undefined. If the
                   4601: variable is guaranteed to be defined, the :U can be omitted.
                   4602: 
                   4603: The :tl modifier converts the variable value to lowercase, allowing for the
                   4604: values yes, Yes, YES.
                   4605: 
1.184     rillig   4606: Chapter 16. Options handling
1.1       dsieger  4607: 
                   4608: Table of Contents
                   4609: 
1.184     rillig   4610: 16.1. Global default options
                   4611: 16.2. Converting packages to use bsd.options.mk
                   4612: 16.3. Option Names
                   4613: 16.4. Determining the options of dependencies
1.1       dsieger  4614: 
                   4615: Many packages have the ability to be built to support different sets of
                   4616: features. bsd.options.mk is a framework in pkgsrc that provides generic
                   4617: handling of those options that determine different ways in which the packages
                   4618: can be built. It's possible for the user to specify exactly which sets of
                   4619: options will be built into a package or to allow a set of global default
                   4620: options apply.
                   4621: 
1.7       rillig   4622: There are two broad classes of behaviors that one might want to control via
                   4623: options. One is whether some particular feature is enabled in a program that
                   4624: will be built anyway, often by including or not including a dependency on some
                   4625: other package. The other is whether or not an additional program will be built
                   4626: as part of the package. Generally, it is better to make a split package for
                   4627: such additional programs instead of using options, because it enables binary
                   4628: packages to be built which can then be added separately. For example, the foo
                   4629: package might have minimal dependencies (those packages without which foo
                   4630: doesn't make sense), and then the foo-gfoo package might include the GTK
                   4631: frontend program gfoo. This is better than including a gtk option to foo that
                   4632: adds gfoo, because either that option is default, in which case binary users
                   4633: can't get foo without gfoo, or not default, in which case they can't get gfoo.
                   4634: With split packages, they can install foo without having GTK, and later decide
                   4635: to install gfoo (pulling in GTK at that time). This is an advantage to source
                   4636: users too, avoiding the need for rebuilds.
                   4637: 
                   4638: Plugins with widely varying dependencies should usually be split instead of
                   4639: options.
                   4640: 
                   4641: It is often more work to maintain split packages, especially if the upstream
                   4642: package does not support this. The decision of split vs. option should be made
                   4643: based on the likelihood that users will want or object to the various pieces,
                   4644: the size of the dependencies that are included, and the amount of work.
                   4645: 
                   4646: A further consideration is licensing. Non-free parts, or parts that depend on
                   4647: non-free dependencies (especially plugins) should almost always be split if
                   4648: feasible.
                   4649: 
1.184     rillig   4650: 16.1. Global default options
1.1       dsieger  4651: 
                   4652: Global default options are listed in PKG_DEFAULT_OPTIONS, which is a list of
                   4653: the options that should be built into every package if that option is
1.4       rillig   4654: supported. This variable should be set in mk.conf.
1.1       dsieger  4655: 
1.184     rillig   4656: 16.2. Converting packages to use bsd.options.mk
1.1       dsieger  4657: 
                   4658: The following example shows how bsd.options.mk should be used by the
                   4659: hypothetical ``wibble'' package, either in the package Makefile, or in a file,
                   4660: e.g. options.mk, that is included by the main package Makefile.
                   4661: 
                   4662: PKG_OPTIONS_VAR=                PKG_OPTIONS.wibble
                   4663: PKG_SUPPORTED_OPTIONS=          wibble-foo ldap
                   4664: PKG_OPTIONS_OPTIONAL_GROUPS=    database
                   4665: PKG_OPTIONS_GROUP.database=     mysql pgsql
                   4666: PKG_SUGGESTED_OPTIONS=          wibble-foo
                   4667: PKG_OPTIONS_LEGACY_VARS+=       WIBBLE_USE_OPENLDAP:ldap
                   4668: PKG_OPTIONS_LEGACY_OPTS+=       foo:wibble-foo
                   4669: 
                   4670: .include "../../mk/bsd.prefs.mk"
                   4671: 
                   4672: # this package was previously named wibble2
                   4673: .if defined(PKG_OPTIONS.wibble2)
                   4674: PKG_LEGACY_OPTIONS+=            ${PKG_OPTIONS.wibble2}
                   4675: PKG_OPTIONS_DEPRECATED_WARNINGS+= \
                   4676:         "Deprecated variable PKG_OPTIONS.wibble2 used, use ${PKG_OPTIONS_VAR} instead."
                   4677: .endif
                   4678: 
                   4679: .include "../../mk/bsd.options.mk"
                   4680: 
                   4681: # Package-specific option-handling
                   4682: 
                   4683: ###
                   4684: ### FOO support
                   4685: ###
                   4686: .if !empty(PKG_OPTIONS:Mwibble-foo)
                   4687: CONFIGURE_ARGS+=    --enable-foo
                   4688: .endif
                   4689: 
                   4690: ###
                   4691: ### LDAP support
                   4692: ###
                   4693: .if !empty(PKG_OPTIONS:Mldap)
                   4694: .  include "../../databases/openldap-client/buildlink3.mk"
                   4695: CONFIGURE_ARGS+=    --enable-ldap=${BUILDLINK_PREFIX.openldap-client}
                   4696: .endif
                   4697: 
                   4698: ###
                   4699: ### database support
                   4700: ###
                   4701: .if !empty(PKG_OPTIONS:Mmysql)
                   4702: .  include "../../mk/mysql.buildlink3.mk"
                   4703: .endif
                   4704: .if !empty(PKG_OPTIONS:Mpgsql)
                   4705: .  include "../../mk/pgsql.buildlink3.mk"
                   4706: .endif
                   4707: 
                   4708: The first section contains the information about which build options are
                   4709: supported by the package, and any default options settings if needed.
                   4710: 
                   4711:  1. PKG_OPTIONS_VAR is the name of the make(1) variable that the user can set
                   4712:     to override the default options. It should be set to PKG_OPTIONS.pkgbase.
                   4713:     Do not set it to PKG_OPTIONS.${PKGBASE}, since PKGBASE is not defined at
                   4714:     the point where the options are processed.
                   4715: 
                   4716:  2. PKG_SUPPORTED_OPTIONS is a list of build options supported by the package.
                   4717: 
                   4718:  3. PKG_OPTIONS_OPTIONAL_GROUPS is a list of names of groups of mutually
                   4719:     exclusive options. The options in each group are listed in
                   4720:     PKG_OPTIONS_GROUP.groupname. The most specific setting of any option from
                   4721:     the group takes precedence over all other options in the group. Options
                   4722:     from the groups will be automatically added to PKG_SUPPORTED_OPTIONS.
                   4723: 
                   4724:  4. PKG_OPTIONS_REQUIRED_GROUPS is like PKG_OPTIONS_OPTIONAL_GROUPS, but
                   4725:     building the packages will fail if no option from the group is selected.
                   4726: 
                   4727:  5. PKG_OPTIONS_NONEMPTY_SETS is a list of names of sets of options. At least
                   4728:     one option from each set must be selected. The options in each set are
                   4729:     listed in PKG_OPTIONS_SET.setname. Options from the sets will be
                   4730:     automatically added to PKG_SUPPORTED_OPTIONS. Building the package will
                   4731:     fail if no option from the set is selected.
                   4732: 
                   4733:  6. PKG_SUGGESTED_OPTIONS is a list of build options which are enabled by
                   4734:     default.
                   4735: 
                   4736:  7. PKG_OPTIONS_LEGACY_VARS is a list of "USE_VARIABLE:option" pairs that map
1.4       rillig   4737:     legacy mk.conf variables to their option counterparts. Pairs should be
1.1       dsieger  4738:     added with "+=" to keep the listing of global legacy variables. A warning
                   4739:     will be issued if the user uses a legacy variable.
                   4740: 
                   4741:  8. PKG_OPTIONS_LEGACY_OPTS is a list of "old-option:new-option" pairs that map
                   4742:     options that have been renamed to their new counterparts. Pairs should be
                   4743:     added with "+=" to keep the listing of global legacy options. A warning
                   4744:     will be issued if the user uses a legacy option.
                   4745: 
                   4746:  9. PKG_LEGACY_OPTIONS is a list of options implied by deprecated variables
                   4747:     used. This can be used for cases that neither PKG_OPTIONS_LEGACY_VARS nor
                   4748:     PKG_OPTIONS_LEGACY_OPTS can handle, e. g. when PKG_OPTIONS_VAR is renamed.
                   4749: 
                   4750: 10. PKG_OPTIONS_DEPRECATED_WARNINGS is a list of warnings about deprecated
                   4751:     variables or options used, and what to use instead.
                   4752: 
                   4753: A package should never modify PKG_DEFAULT_OPTIONS or the variable named in
                   4754: PKG_OPTIONS_VAR. These are strictly user-settable. To suggest a default set of
                   4755: options, use PKG_SUGGESTED_OPTIONS.
                   4756: 
                   4757: PKG_OPTIONS_VAR must be defined before including bsd.options.mk. If none of
                   4758: PKG_SUPPORTED_OPTIONS, PKG_OPTIONS_OPTIONAL_GROUPS, and
                   4759: PKG_OPTIONS_REQUIRED_GROUPS are defined (as can happen with platform-specific
                   4760: options if none of them is supported on the current platform), PKG_OPTIONS is
                   4761: set to the empty list and the package is otherwise treated as not using the
                   4762: options framework.
                   4763: 
                   4764: After the inclusion of bsd.options.mk, the variable PKG_OPTIONS contains the
                   4765: list of selected build options, properly filtered to remove unsupported and
                   4766: duplicate options.
                   4767: 
                   4768: The remaining sections contain the logic that is specific to each option. The
                   4769: correct way to check for an option is to check whether it is listed in
                   4770: PKG_OPTIONS:
                   4771: 
                   4772: .if !empty(PKG_OPTIONS:Moption)
                   4773: 
1.184     rillig   4774: 16.3. Option Names
1.1       dsieger  4775: 
                   4776: Options that enable similar features in different packages (like optional
                   4777: support for a library) should use a common name in all packages that support it
                   4778: (like the name of the library). If another package already has an option with
                   4779: the same meaning, use the same name.
                   4780: 
                   4781: Options that enable features specific to one package, where it's unlikely that
                   4782: another (unrelated) package has the same (or a similar) optional feature,
                   4783: should use a name prefixed with pkgname-.
                   4784: 
                   4785: If a group of related packages share an optional feature specific to that
                   4786: group, prefix it with the name of the "main" package (e. g.
                   4787: djbware-errno-hack).
                   4788: 
                   4789: For new options, add a line to mk/defaults/options.description. Lines have two
                   4790: fields, separated by tab. The first field is the option name, the second its
                   4791: description. The description should be a whole sentence (starting with an
                   4792: uppercase letter and ending with a period) that describes what enabling the
                   4793: option does. E. g. "Enable ispell support." The file is sorted by option names.
                   4794: 
1.184     rillig   4795: 16.4. Determining the options of dependencies
1.7       rillig   4796: 
                   4797: When writing buildlink3.mk files, it is often necessary to list different
                   4798: dependencies based on the options with which the package was built. For
                   4799: querying these options, the file pkgsrc/mk/pkg-build-options.mk should be used.
                   4800: A typical example looks like this:
                   4801: 
                   4802: pkgbase := libpurple
                   4803: .include "../../mk/pkg-build-options.mk"
                   4804: 
                   4805: .if !empty(PKG_BUILD_OPTIONS.libpurple:Mdbus)
                   4806: ...
                   4807: .endif
                   4808: 
                   4809: Including pkg-build-options.mk here will set the variable
                   4810: PKG_BUILD_OPTIONS.libpurple to the build options of the libpurple package,
                   4811: which can then be queried like PKG_OPTIONS in the options.mk file. See the file
                   4812: pkg-build-options.mk for more details.
                   4813: 
1.184     rillig   4814: Chapter 17. Tools needed for building or running
                   4815: 
                   4816: Table of Contents
                   4817: 
                   4818: 17.1. Tools for pkgsrc builds
                   4819: 17.2. Tools needed by packages
                   4820: 17.3. Tools provided by platforms
                   4821: 
                   4822: The USE_TOOLS definition is used both internally by pkgsrc and also for
                   4823: individual packages to define what commands are needed for building a package
                   4824: (like TOOL_DEPENDS) or for later run-time of an installed packaged (such as
                   4825: DEPENDS). If the native system provides an adequate tool, then in many cases, a
                   4826: pkgsrc package will not be used.
                   4827: 
                   4828: When building a package, the replacement tools are made available in a
                   4829: directory (as symlinks or wrapper scripts) that is early in the executable
                   4830: search path. Just like the buildlink system, this helps with consistent builds.
                   4831: 
                   4832: A tool may be needed to help build a specific package. For example, perl, GNU
                   4833: make (gmake) or yacc may be needed.
                   4834: 
                   4835: Also a tool may be needed, for example, because the native system's supplied
                   4836: tool may be inefficient for building a package with pkgsrc. For example, a
                   4837: package may need GNU awk, bison (instead of yacc) or a better sed.
                   4838: 
                   4839: The tools used by a package can be listed by running make show-tools.
                   4840: 
                   4841: 17.1. Tools for pkgsrc builds
                   4842: 
                   4843: The default set of tools used by pkgsrc is defined in bsd.pkg.mk. This includes
                   4844: standard Unix tools, such as: cat, awk, chmod, test, and so on. These can be
                   4845: seen by running: make show-var VARNAME=USE_TOOLS.
                   4846: 
                   4847: If a package needs a specific program to build then the USE_TOOLS variable can
                   4848: be used to define the tools needed.
                   4849: 
                   4850: 17.2. Tools needed by packages
                   4851: 
                   4852: In the following examples, the :run means that it is needed at run-time (and
                   4853: becomes a DEPENDS). The default is a build dependency which can be set with
                   4854: :build. (So in this example, it is the same as gmake:build and
                   4855: pkg-config:build.)
                   4856: 
                   4857: USE_TOOLS+=     gmake perl:run pkg-config
                   4858: 
                   4859: When using the tools framework, a TOOLS_PATH.foo variable is defined which
                   4860: contains the full path to the appropriate tool. For example, TOOLS_PATH.bash
                   4861: could be "/bin/bash" on Linux systems.
                   4862: 
                   4863: If you always need a pkgsrc version of the tool at run-time, then just use
                   4864: DEPENDS instead.
                   4865: 
                   4866: 17.3. Tools provided by platforms
                   4867: 
                   4868: When improving or porting pkgsrc to a new platform, have a look at (or create)
                   4869: the corresponding platform specific make file fragment under pkgsrc/mk/tools/
                   4870: tools.${OPSYS}.mk which defines the name of the common tools. For example:
                   4871: 
                   4872: .if exists(/usr/bin/bzcat)
                   4873: TOOLS_PLATFORM.bzcat?=          /usr/bin/bzcat
                   4874: .elif exists(/usr/bin/bzip2)
                   4875: TOOLS_PLATFORM.bzcat?=          /usr/bin/bzip2 -cd
                   4876: .endif
                   4877: 
                   4878: TOOLS_PLATFORM.true?=           true                    # shell builtin
                   4879: 
                   4880: Chapter 18. Buildlink methodology
1.1       dsieger  4881: 
                   4882: Table of Contents
                   4883: 
1.184     rillig   4884: 18.1. Converting packages to use buildlink3
                   4885: 18.2. Writing buildlink3.mk files
                   4886:     18.2.1. Anatomy of a buildlink3.mk file
                   4887:     18.2.2. Updating BUILDLINK_API_DEPENDS.pkg and BUILDLINK_ABI_DEPENDS.pkg in
1.232   ! gutterid 4888:     buildlink3.mk files
1.184     rillig   4889: 18.3. Writing builtin.mk files
                   4890:     18.3.1. Anatomy of a builtin.mk file
                   4891:     18.3.2. Global preferences for native or pkgsrc software
                   4892: 
                   4893: Buildlink is a framework in pkgsrc that controls what headers and libraries are
                   4894: seen by a package's configure and build processes. This is implemented in a two
                   4895: step process:
                   4896: 
                   4897:  1. Symlink headers and libraries for dependencies into BUILDLINK_DIR, which by
                   4898:     default is a subdirectory of WRKDIR.
                   4899: 
                   4900:  2. Create wrapper scripts that are used in place of the normal compiler tools
                   4901:     that translate -I${LOCALBASE}/include and -L${LOCALBASE}/lib into
                   4902:     references to BUILDLINK_DIR. The wrapper scripts also make native compiler
                   4903:     on some operating systems look like GCC, so that packages that expect GCC
                   4904:     won't require modifications to build with those native compilers.
                   4905: 
                   4906: This normalizes the environment in which a package is built so that the package
                   4907: may be built consistently despite what other software may be installed. Please
                   4908: note that the normal system header and library paths, e.g. /usr/include, /usr/
                   4909: lib, etc., are always searched -- buildlink3 is designed to insulate the
                   4910: package build from non-system-supplied software.
                   4911: 
                   4912: 18.1. Converting packages to use buildlink3
1.1       dsieger  4913: 
1.184     rillig   4914: The process of converting packages to use the buildlink3 framework ("bl3ifying"
                   4915: ) is fairly straightforward. The things to keep in mind are:
1.1       dsieger  4916: 
1.184     rillig   4917:  1. Ensure that the build always calls the wrapper scripts instead of the
                   4918:     actual toolchain. Some packages are tricky, and the only way to know for
                   4919:     sure is the check ${WRKDIR}/.work.log to see if the wrappers are being
                   4920:     invoked.
1.1       dsieger  4921: 
1.184     rillig   4922:  2. Don't override PREFIX from within the package Makefile, e.g. Java VMs,
                   4923:     standalone shells, etc., because the code to symlink files into $
                   4924:     {BUILDLINK_DIR} looks for files relative to "pkg_info -qp pkgname".
1.1       dsieger  4925: 
1.184     rillig   4926:  3. Remember that only the buildlink3.mk files that you list in a package's
                   4927:     Makefile are added as dependencies for that package.
1.1       dsieger  4928: 
1.184     rillig   4929: If a dependency on a particular package is required for its libraries and
                   4930: headers, then we replace:
1.1       dsieger  4931: 
1.184     rillig   4932: DEPENDS+=       foo>=1.1.0:../../category/foo
1.1       dsieger  4933: 
1.184     rillig   4934: with
1.1       dsieger  4935: 
1.184     rillig   4936: .include "../../category/foo/buildlink3.mk"
1.1       dsieger  4937: 
1.184     rillig   4938: The buildlink3.mk files usually define the required dependencies. If you need a
                   4939: newer version of the dependency when using buildlink3.mk files, then you can
                   4940: define it in your Makefile; for example:
1.1       dsieger  4941: 
1.184     rillig   4942: BUILDLINK_API_DEPENDS.foo+=   foo>=1.1.0
                   4943: .include "../../category/foo/buildlink3.mk"
1.1       dsieger  4944: 
1.184     rillig   4945: There are several buildlink3.mk files in pkgsrc/mk that handle special package
                   4946: issues:
1.1       dsieger  4947: 
1.184     rillig   4948:   * bdb.buildlink3.mk chooses either the native or a pkgsrc Berkeley DB
                   4949:     implementation based on the values of BDB_ACCEPTED and BDB_DEFAULT.
1.1       dsieger  4950: 
1.184     rillig   4951:   * curses.buildlink3.mk: If the system comes with neither Curses nor NCurses,
                   4952:     this will take care to install the devel/ncurses package.
1.1       dsieger  4953: 
1.184     rillig   4954:   * krb5.buildlink3.mk uses the value of KRB5_ACCEPTED to choose between adding
                   4955:     a dependency on Heimdal or MIT-krb5 for packages that require a Kerberos 5
                   4956:     implementation.
1.1       dsieger  4957: 
1.184     rillig   4958:   * motif.buildlink3.mk checks for a system-provided Motif installation or adds
                   4959:     a dependency on x11/lesstif or x11/motif. The user can set MOTIF_TYPE to "
                   4960:     dt", "lesstif" or "motif" to choose which Motif version will be used.
1.1       dsieger  4961: 
1.184     rillig   4962:   * readline.buildlink3.mk checks for a system-provided GNU readline or
                   4963:     editline (libedit) installation, or adds a dependency on devel/readline,
                   4964:     devel/editline. The user can set READLINE_DEFAULT to choose readline
                   4965:     implementation. If your package really needs GNU readline library, its
                   4966:     Makefile should include devel/readline/buildlink3.mk instead of
                   4967:     readline.buildlink3.mk.
1.1       dsieger  4968: 
1.184     rillig   4969:   * oss.buildlink3.mk defines several variables that may be used by packages
                   4970:     that use the Open Sound System (OSS) API.
1.1       dsieger  4971: 
1.184     rillig   4972:   * pgsql.buildlink3.mk will accept any of the Postgres versions in the
                   4973:     variable PGSQL_VERSIONS_ACCEPTED and default to the version
                   4974:     PGSQL_VERSION_DEFAULT. See the file for more information.
1.1       dsieger  4975: 
1.184     rillig   4976:   * pthread.buildlink3.mk uses the value of PTHREAD_OPTS and checks for native
                   4977:     pthreads or adds a dependency on devel/pth as needed.
1.1       dsieger  4978: 
1.184     rillig   4979:   * xaw.buildlink3.mk uses the value of XAW_TYPE to choose a particular Athena
                   4980:     widgets library.
1.1       dsieger  4981: 
1.184     rillig   4982: The comments in those buildlink3.mk files provide a more complete description
                   4983: of how to use them properly.
1.1       dsieger  4984: 
1.184     rillig   4985: 18.2. Writing buildlink3.mk files
1.1       dsieger  4986: 
1.184     rillig   4987: A package's buildlink3.mk file is included by Makefiles to indicate the need to
                   4988: compile and link against header files and libraries provided by the package. A
                   4989: buildlink3.mk file should always provide enough information to add the correct
                   4990: type of dependency relationship and include any other buildlink3.mk files that
                   4991: it needs to find headers and libraries that it needs in turn.
1.1       dsieger  4992: 
1.184     rillig   4993: To generate an initial buildlink3.mk file for further editing, Rene Hexel's
                   4994: pkgtools/createbuildlink package is highly recommended. For most packages, the
                   4995: following command will generate a good starting point for buildlink3.mk files:
1.1       dsieger  4996: 
1.184     rillig   4997: % cd pkgsrc/category/pkgdir
                   4998: % createbuildlink >buildlink3.mk
1.1       dsieger  4999: 
                   5000: 
1.184     rillig   5001: 18.2.1. Anatomy of a buildlink3.mk file
1.1       dsieger  5002: 
1.184     rillig   5003: The following real-life example buildlink3.mk is taken from pkgsrc/graphics/
                   5004: tiff:
1.14      jmcneill 5005: 
1.184     rillig   5006: BUILDLINK_TREE+=        tiff
1.1       dsieger  5007: 
1.184     rillig   5008: .if !defined(TIFF_BUILDLINK3_MK)
                   5009: TIFF_BUILDLINK3_MK:=
1.1       dsieger  5010: 
1.184     rillig   5011: BUILDLINK_API_DEPENDS.tiff+=    tiff>=3.6.1
                   5012: BUILDLINK_ABI_DEPENDS.tiff+=    tiff>=3.7.2nb1
                   5013: BUILDLINK_PKGSRCDIR.tiff?=      ../../graphics/tiff
1.1       dsieger  5014: 
1.184     rillig   5015: .include "../../devel/zlib/buildlink3.mk"
                   5016: .include "../../graphics/jpeg/buildlink3.mk"
                   5017: .endif # TIFF_BUILDLINK3_MK
1.1       dsieger  5018: 
1.184     rillig   5019: BUILDLINK_TREE+=        -tiff
1.1       dsieger  5020: 
1.184     rillig   5021: The header and footer manipulate BUILDLINK_TREE, which is common across all
                   5022: buildlink3.mk files and is used to track the dependency tree.
1.1       dsieger  5023: 
1.184     rillig   5024: The main section is protected from multiple inclusion and controls how the
                   5025: dependency on pkg is added. Several important variables are set in the section:
1.1       dsieger  5026: 
1.185     wiz      5027:   * BUILDLINK_API_DEPENDS.pkg is the dependency version recorded in the
1.184     rillig   5028:     installed package; this should always be set using += to ensure that we're
                   5029:     appending to any pre-existing list of values. This variable should be set
1.185     wiz      5030:     to the last version of the package that had an backwards-incompatible API
1.184     rillig   5031:     change.
1.1       dsieger  5032: 
1.184     rillig   5033:   * BUILDLINK_PKGSRCDIR.pkg is the location of the pkg pkgsrc directory.
1.1       dsieger  5034: 
1.184     rillig   5035:   * BUILDLINK_DEPMETHOD.pkg (not shown above) controls whether we use
                   5036:     BUILD_DEPENDS or DEPENDS to add the dependency on pkg. The build dependency
                   5037:     is selected by setting BUILDLINK_DEPMETHOD.pkg to "build". By default, the
                   5038:     full dependency is used.
1.1       dsieger  5039: 
1.184     rillig   5040:   * BUILDLINK_INCDIRS.pkg and BUILDLINK_LIBDIRS.pkg (not shown above) are lists
                   5041:     of subdirectories of ${BUILDLINK_PREFIX.pkg} to add to the header and
                   5042:     library search paths. These default to "include" and "lib" respectively.
1.1       dsieger  5043: 
1.184     rillig   5044:   * BUILDLINK_CPPFLAGS.pkg (not shown above) is the list of preprocessor flags
                   5045:     to add to CPPFLAGS, which are passed on to the configure and build phases.
                   5046:     The "-I" option should be avoided and instead be handled using
                   5047:     BUILDLINK_INCDIRS.pkg as above.
1.66      asau     5048: 
1.184     rillig   5049: The following variables are all optionally defined within this second section
                   5050: (protected against multiple inclusion) and control which package files are
                   5051: symlinked into ${BUILDLINK_DIR} and how their names are transformed during the
                   5052: symlinking:
1.23      jakllsch 5053: 
1.184     rillig   5054:   * BUILDLINK_FILES.pkg (not shown above) is a shell glob pattern relative to $
                   5055:     {BUILDLINK_PREFIX.pkg} to be symlinked into ${BUILDLINK_DIR}, e.g. include/
                   5056:     *.h.
1.1       dsieger  5057: 
1.184     rillig   5058:   * BUILDLINK_FILES_CMD.pkg (not shown above) is a shell pipeline that outputs
                   5059:     to stdout a list of files relative to ${BUILDLINK_PREFIX.pkg}. The
                   5060:     resulting files are to be symlinked into ${BUILDLINK_DIR}. By default, this
                   5061:     takes the +CONTENTS of a pkg and filters it through $
                   5062:     {BUILDLINK_CONTENTS_FILTER.pkg}.
1.1       dsieger  5063: 
1.184     rillig   5064:   * BUILDLINK_CONTENTS_FILTER.pkg (not shown above) is a filter command that
                   5065:     filters +CONTENTS input into a list of files relative to $
                   5066:     {BUILDLINK_PREFIX.pkg} on stdout. By default, BUILDLINK_CONTENTS_FILTER.pkg
                   5067:     outputs the contents of the include and lib directories in the package
                   5068:     +CONTENTS.
1.1       dsieger  5069: 
1.184     rillig   5070:   * BUILDLINK_FNAME_TRANSFORM.pkg (not shown above) is a list of sed arguments
                   5071:     used to transform the name of the source filename into a destination
                   5072:     filename, e.g. -e "s|/curses.h|/ncurses.h|g".
1.1       dsieger  5073: 
1.184     rillig   5074: This section can additionally include any buildlink3.mk needed for pkg's
                   5075: library dependencies. Including these buildlink3.mk files means that the
                   5076: headers and libraries for these dependencies are also symlinked into $
                   5077: {BUILDLINK_DIR} whenever the pkg buildlink3.mk file is included. Dependencies
                   5078: are only added for directly include buildlink3.mk files.
1.1       dsieger  5079: 
1.184     rillig   5080: When providing a buildlink3.mk and including other buildlink3.mk files in it,
                   5081: please only add necessary ones, i.e., those whose libraries or header files are
                   5082: automatically exposed when the package is use.
1.1       dsieger  5083: 
1.184     rillig   5084: In particular, if only an executable (bin/foo) is linked against a library,
                   5085: that library does not need to be propagated in the buildlink3.mk file.
1.1       dsieger  5086: 
1.184     rillig   5087: The following steps should help you decide if a buildlink3.mk file needs to be
                   5088: included:
1.1       dsieger  5089: 
1.184     rillig   5090:   * Look at the installed header files: What headers do they include? The
                   5091:     packages providing these files must be buildlinked.
1.1       dsieger  5092: 
1.184     rillig   5093:   * Run ldd on all installed libraries and look against what other libraries
                   5094:     they link. Some of the packages providing these probably need to be
                   5095:     buildlinked; however, it's not automatic, since e.g. GTK on some systems
                   5096:     pulls in the X libraries, so they will show up in the ldd output, while on
                   5097:     others (like OS X) it won't. ldd output can thus only be used as a hint.
1.1       dsieger  5098: 
1.184     rillig   5099: 18.2.2. Updating BUILDLINK_API_DEPENDS.pkg and BUILDLINK_ABI_DEPENDS.pkg in
                   5100: buildlink3.mk files
1.16      jnemeth  5101: 
1.185     wiz      5102: Both variables set lower bounds for a version of this package. The two
                   5103: variables differ in that one describes source compatibility (API) and the other
                   5104: binary compatibility (ABI). The difference is that a change in the API breaks
                   5105: compilation of programs while changes in the ABI stop compiled programs from
                   5106: running.
                   5107: 
                   5108: The BUILDLINK_API_DEPENDS.pkg variable in a buildlink3.mk should be changed
                   5109: very rarely. (One possible scenario: If all packages using this package need a
                   5110: higher version than defined in the buildlink3.mk, BUILDLINK_API_DEPENDS.pkg
                   5111: could be updated to that higher version.)
                   5112: 
                   5113: On the other hand, changes to BUILDLINK_ABI_DEPENDS.pkg are more common. The
                   5114: variable will need to be updated every time the major version of one of its
                   5115: shared libraries is changed, or any other change where a binary built against
                   5116: the previous version of the package will not run against the new version any
                   5117: longer.
                   5118: 
                   5119: In such a case, the package's BUILDLINK_ABI_DEPENDS.pkg must be increased to
                   5120: require the new package version. Then the PKGREVISION of all packages foo that
                   5121: depend on this package need to be increased, and if they have buildlink3.mk
                   5122: files, BUILDLINK_ABI_DEPENDS.foo in their buildlink3.mk files must be increased
                   5123: to the new version as well. This is required so that a package will pull in the
                   5124: versions of the packages that use the new ABI and that the packages'
                   5125: PKGREVISIONs uniquely identify the packages built against the new ABI. The
                   5126: pkgtools/revbump package can help with these updates.
1.1       dsieger  5127: 
1.184     rillig   5128: See Section 21.1.5, "Handling dependencies" for more information about
1.185     wiz      5129: dependencies on other packages, including the BUILDLINK_API_DEPENDS
                   5130: definitions.
1.1       dsieger  5131: 
1.184     rillig   5132: Please take careful consideration before adjusting BUILDLINK_API_DEPENDS.pkg or
1.185     wiz      5133: BUILDLINK_ABI_DEPENDS.pkg in a buildlink3.mk file as we don't want to cause
                   5134: unneeded package deletions and rebuilds. In many cases, new versions of
                   5135: packages work just fine with older dependencies.
1.1       dsieger  5136: 
1.211     gutterid 5137: Also, it is not needed to set BUILDLINK_ABI_DEPENDS.pkg when it is identical to
1.184     rillig   5138: BUILDLINK_API_DEPENDS.pkg.
1.1       dsieger  5139: 
1.211     gutterid 5140: Note there is also the distinction that users are able to disable enforcement
                   5141: of ABI dependencies using the USE_ABI_DEPENDS variable, but there is no
                   5142: equivalent option for API dependencies.
                   5143: 
1.184     rillig   5144: 18.3. Writing builtin.mk files
1.1       dsieger  5145: 
1.184     rillig   5146: Some packages in pkgsrc install headers and libraries that coincide with
                   5147: headers and libraries present in the base system. Aside from a buildlink3.mk
                   5148: file, these packages should also include a builtin.mk file that includes the
                   5149: necessary checks to decide whether using the built-in software or the pkgsrc
                   5150: software is appropriate.
1.1       dsieger  5151: 
1.184     rillig   5152: The only requirements of a builtin.mk file for pkg are:
1.1       dsieger  5153: 
1.184     rillig   5154:  1. It should set USE_BUILTIN.pkg to either "yes" or "no" after it is included.
1.1       dsieger  5155: 
1.184     rillig   5156:  2. It should not override any USE_BUILTIN.pkg which is already set before the
                   5157:     builtin.mk file is included.
1.1       dsieger  5158: 
1.184     rillig   5159:  3. It should be written to allow multiple inclusion. This is very important
                   5160:     and takes careful attention to Makefile coding.
1.1       dsieger  5161: 
1.184     rillig   5162: 18.3.1. Anatomy of a builtin.mk file
1.1       dsieger  5163: 
1.184     rillig   5164: The following is the recommended template for builtin.mk files:
1.1       dsieger  5165: 
1.184     rillig   5166: .if !defined(IS_BUILTIN.foo)
                   5167: #
                   5168: # IS_BUILTIN.foo is set to "yes" or "no" depending on whether "foo"
                   5169: # genuinely exists in the system or not.
                   5170: #
                   5171: IS_BUILTIN.foo?=        no
1.1       dsieger  5172: 
1.184     rillig   5173: # BUILTIN_PKG.foo should be set here if "foo" is built-in and its package
                   5174: # version can be determined.
                   5175: #
                   5176: .  if !empty(IS_BUILTIN.foo:M[yY][eE][sS])
                   5177: BUILTIN_PKG.foo?=       foo-1.0
                   5178: .  endif
                   5179: .endif  # IS_BUILTIN.foo
1.1       dsieger  5180: 
1.184     rillig   5181: .if !defined(USE_BUILTIN.foo)
                   5182: USE_BUILTIN.foo?=       ${IS_BUILTIN.foo}
                   5183: .  if defined(BUILTIN_PKG.foo)
                   5184: .    for _depend_ in ${BUILDLINK_API_DEPENDS.foo}
                   5185: .      if !empty(USE_BUILTIN.foo:M[yY][eE][sS])
                   5186: USE_BUILTIN.foo!=                                                       \
                   5187:         ${PKG_ADMIN} pmatch '${_depend_}' ${BUILTIN_PKG.foo}            \
                   5188:         && ${ECHO} "yes" || ${ECHO} "no"
                   5189: .      endif
                   5190: .    endfor
                   5191: .  endif
                   5192: .endif  # USE_BUILTIN.foo
1.1       dsieger  5193: 
1.184     rillig   5194: CHECK_BUILTIN.foo?=     no
                   5195: .if !empty(CHECK_BUILTIN.foo:M[nN][oO])
                   5196: #
                   5197: # Here we place code that depends on whether USE_BUILTIN.foo is set to
                   5198: # "yes" or "no".
                   5199: #
                   5200: .endif  # CHECK_BUILTIN.foo
1.1       dsieger  5201: 
1.184     rillig   5202: The first section sets IS_BUILTIN.pkg depending on if pkg really exists in the
                   5203: base system. This should not be a base system software with similar
                   5204: functionality to pkg; it should only be "yes" if the actual package is included
                   5205: as part of the base system. This variable is only used internally within the
                   5206: builtin.mk file.
1.1       dsieger  5207: 
1.184     rillig   5208: The second section sets BUILTIN_PKG.pkg to the version of pkg in the base
                   5209: system if it exists (if IS_BUILTIN.pkg is "yes"). This variable is only used
                   5210: internally within the builtin.mk file.
1.1       dsieger  5211: 
1.184     rillig   5212: The third section sets USE_BUILTIN.pkg and is required in all builtin.mk files.
                   5213: The code in this section must make the determination whether the built-in
                   5214: software is adequate to satisfy the dependencies listed in
                   5215: BUILDLINK_API_DEPENDS.pkg. This is typically done by comparing BUILTIN_PKG.pkg
                   5216: against each of the dependencies in BUILDLINK_API_DEPENDS.pkg. USE_BUILTIN.pkg 
                   5217: must be set to the correct value by the end of the builtin.mk file. Note that
                   5218: USE_BUILTIN.pkg may be "yes" even if IS_BUILTIN.pkg is "no" because we may make
                   5219: the determination that the built-in version of the software is similar enough
                   5220: to be used as a replacement.
1.1       dsieger  5221: 
1.184     rillig   5222: The last section is guarded by CHECK_BUILTIN.pkg, and includes code that uses
                   5223: the value of USE_BUILTIN.pkg set in the previous section. This typically
                   5224: includes, e.g., adding additional dependency restrictions and listing
                   5225: additional files to symlink into ${BUILDLINK_DIR} (via BUILDLINK_FILES.pkg).
1.1       dsieger  5226: 
1.184     rillig   5227: 18.3.2. Global preferences for native or pkgsrc software
1.1       dsieger  5228: 
1.184     rillig   5229: When building packages, it's possible to choose whether to set a global
                   5230: preference for using either the built-in (native) version or the pkgsrc version
                   5231: of software to satisfy a dependency. This is controlled by setting
                   5232: PREFER_PKGSRC and PREFER_NATIVE. These variables take values of either "yes", "
                   5233: no", or a list of packages. PREFER_PKGSRC tells pkgsrc to use the pkgsrc
                   5234: versions of software, while PREFER_NATIVE tells pkgsrc to use the built-in
                   5235: versions. Preferences are determined by the most specific instance of the
                   5236: package in either PREFER_PKGSRC or PREFER_NATIVE. If a package is specified in
                   5237: neither or in both variables, then PREFER_PKGSRC has precedence over
                   5238: PREFER_NATIVE. For example, to require using pkgsrc versions of software for
                   5239: all but the most basic bits on a NetBSD system, you can set:
1.1       dsieger  5240: 
1.184     rillig   5241: PREFER_PKGSRC=  yes
                   5242: PREFER_NATIVE=  getopt skey tcp_wrappers
1.1       dsieger  5243: 
1.184     rillig   5244: A package must have a builtin.mk file to be listed in PREFER_NATIVE, otherwise
                   5245: it is simply ignored in that list.
1.1       dsieger  5246: 
1.191     bacon    5247: PREFER_PKGSRC and PREFER_NATIVE should be set during bootstrap to ensure that
                   5248: the bootstrap process does not use inapropriate native tools as dependencies
                   5249: for core packages.
                   5250: 
                   5251: # ./bootstrap --prefer-pkgsrc yes --prefer-native openssl
                   5252: 
                   5253: Switching between settings globally at a later date can introduce complications
                   5254: with dependency resolution. This is caused by packages built with the opposite
                   5255: preference being installed alongside each other. Hence, any changes to these
                   5256: variables after bootstrap will necessitate rebuilding all packages depending on
                   5257: one whose preference has been changed. This is not trivial and should be
                   5258: avoided.
                   5259: 
                   5260: When using pkgsrc on Linux systems, there is high risk of "leakage", where
                   5261: programs installed by pkgsrc may inadvertently use a command or library not
                   5262: installed by pkgsrc, e.g. those installed by yum or apt. Such foreign
                   5263: dependencies may be installed, removed, or upgraded to a version incompatible
                   5264: with the pkgsrc package at any time, causing pkgsrc packages to subsequently
                   5265: malfunction. Pkgsrc cannot prevent this, as it has no control over other
                   5266: package managers. Another potential problem is that under Redhat Enterprise and
                   5267: related Linux systems, yum packages are only patched and never upgraded, so
                   5268: eventually they may become too outdated for use by pkgsrc. Even intentionally
                   5269: using foreign dependencies, not considered leakage, can lead to these problems,
                   5270: so it is generally discouraged. In order to minimize such problems,
                   5271: PREFER_PKGSRC defaults to "yes" on Linux systems. This ensures that pkgsrc is
                   5272: aware of any changes to dependency packages and can rebuild or upgrade the
                   5273: entire dependency tree as needed. This default can be overridden by setting
                   5274: --prefer-pkgsrc to "no" or a list of packages, or by setting --prefer-native to
                   5275: "yes".
1.1       dsieger  5276: 
1.184     rillig   5277: Chapter 19. PLIST issues
1.1       dsieger  5278: 
1.184     rillig   5279: Table of Contents
1.1       dsieger  5280: 
1.184     rillig   5281: 19.1. RCS ID
                   5282: 19.2. Semi-automatic PLIST generation
                   5283: 19.3. Tweaking output of make print-PLIST
                   5284: 19.4. Variable substitution in PLIST
                   5285: 19.5. Man page compression
                   5286: 19.6. Changing PLIST source with PLIST_SRC
                   5287: 19.7. Platform-specific and differing PLISTs
                   5288: 19.8. Build-specific PLISTs
                   5289: 19.9. Sharing directories between packages
1.1       dsieger  5290: 
1.184     rillig   5291: The PLIST file contains a package's "packing list", i.e. a list of files that
                   5292: belong to the package (relative to the ${PREFIX} directory it's been installed
                   5293: in) plus some additional statements - see the pkg_create(1) man page for a full
                   5294: list. This chapter addresses some issues that need attention when dealing with
                   5295: the PLIST file (or files, see below!).
1.1       dsieger  5296: 
1.184     rillig   5297: 19.1. RCS ID
1.1       dsieger  5298: 
1.184     rillig   5299: Be sure to add a RCS ID line as the first thing in any PLIST file you write:
1.1       dsieger  5300: 
1.184     rillig   5301: @comment $NetBSD $
1.1       dsieger  5302: 
1.184     rillig   5303: An artificial space has been added between NetBSD and $, this is a workaround
                   5304: here to prevent CVS expanding to the filename of the guide. When adding the RCS
                   5305: ID the space should be omitted.
1.38      wiz      5306: 
1.184     rillig   5307: 19.2. Semi-automatic PLIST generation
1.1       dsieger  5308: 
1.184     rillig   5309: You can use the make print-PLIST command to output a PLIST that matches any new
                   5310: files since the package was extracted. See Section 13.17, "Other helpful
                   5311: targets" for more information on this target.
1.11      rillig   5312: 
1.184     rillig   5313: 19.3. Tweaking output of make print-PLIST
1.1       dsieger  5314: 
1.184     rillig   5315: The PRINT_PLIST_AWK variable takes a set of AWK patterns and actions that are
                   5316: used to filter the output of print-PLIST. You can append any chunk of AWK
                   5317: scripting you like to it, but be careful with quoting.
1.1       dsieger  5318: 
1.184     rillig   5319: For example, to get all files inside the libdata/foo directory removed from the
                   5320: resulting PLIST:
1.1       dsieger  5321: 
1.184     rillig   5322: PRINT_PLIST_AWK+=       /^libdata\/foo/ { next; }
1.1       dsieger  5323: 
1.185     wiz      5324: The PRINT_PLIST_AWK transformations are evaluated after the file list and
                   5325: directory list are sorted. EARLY_PRINT_PLIST_AWK is like PRINT_PLIST_AWK except
                   5326: it operates before the file list and directory list are sorted.
                   5327: 
1.184     rillig   5328: 19.4. Variable substitution in PLIST
1.1       dsieger  5329: 
1.184     rillig   5330: A number of variables are substituted automatically in PLISTs when a package is
                   5331: installed on a system. This includes the following variables:
1.1       dsieger  5332: 
1.184     rillig   5333: ${MACHINE_ARCH}, ${MACHINE_GNU_ARCH}
1.1       dsieger  5334: 
1.184     rillig   5335:     Some packages like emacs and perl embed information about which
                   5336:     architecture they were built on into the pathnames where they install their
                   5337:     files. To handle this case, PLIST will be preprocessed before actually
                   5338:     used, and the symbol "${MACHINE_ARCH}" will be replaced by what uname -p
                   5339:     gives. The same is done if the string ${MACHINE_GNU_ARCH} is embedded in
                   5340:     PLIST somewhere - use this on packages that have GNU autoconf-created
                   5341:     configure scripts.
1.1       dsieger  5342: 
1.184     rillig   5343:     Legacy note
1.1       dsieger  5344: 
1.184     rillig   5345:     There used to be a symbol "$ARCH" that was replaced by the output of uname
                   5346:     -m, but that's no longer supported and has been removed.
1.1       dsieger  5347: 
1.184     rillig   5348: ${OPSYS}, ${LOWER_OPSYS}, ${OS_VERSION}
1.1       dsieger  5349: 
1.184     rillig   5350:     Some packages want to embed the OS name and version into some paths. To do
                   5351:     this, use these variables in the PLIST:
1.1       dsieger  5352: 
1.232   ! gutterid 5353:       o ${OPSYS} - output of "uname -s"
1.1       dsieger  5354: 
1.232   ! gutterid 5355:       o ${LOWER_OPSYS} - lowercase common name (eg. "solaris")
1.1       dsieger  5356: 
1.232   ! gutterid 5357:       o ${OS_VERSION} - "uname -r"
1.1       dsieger  5358: 
1.184     rillig   5359: For a list of values which are replaced by default, the output of make help
                   5360: topic=PLIST_SUBST as well as searching the pkgsrc/mk directory with grep for
                   5361: PLIST_SUBST should help.
1.1       dsieger  5362: 
1.184     rillig   5363: If you want to change other variables not listed above, you can add variables
                   5364: and their expansions to this variable in the following way, similar to
                   5365: MESSAGE_SUBST (see Section 12.5, "Optional files"):
1.1       dsieger  5366: 
1.184     rillig   5367: PLIST_SUBST+=   SOMEVAR="somevalue"
1.1       dsieger  5368: 
1.184     rillig   5369: This replaces all occurrences of "${SOMEVAR}" in the PLIST with "somevalue".
1.1       dsieger  5370: 
1.184     rillig   5371: The PLIST_VARS variable can be used to simplify the common case of
                   5372: conditionally including some PLIST entries. It can be done by adding
                   5373: PLIST_VARS+=foo and setting the corresponding PLIST.foo variable to yes if the
                   5374: entry should be included. This will substitute "${PLIST.foo}" in the PLIST with
                   5375: either """" or ""@comment "". For example, in Makefile:
1.1       dsieger  5376: 
1.184     rillig   5377: PLIST_VARS+=    foo
                   5378: .if condition
                   5379: PLIST.foo=      yes
                   5380: .else
1.1       dsieger  5381: 
1.184     rillig   5382: And then in PLIST:
1.1       dsieger  5383: 
1.184     rillig   5384: @comment $NetBSD $
                   5385: bin/bar
                   5386: man/man1/bar.1
                   5387: ${PLIST.foo}bin/foo
                   5388: ${PLIST.foo}man/man1/foo.1
                   5389: ${PLIST.foo}share/bar/foo.data
1.1       dsieger  5390: 
1.184     rillig   5391: An artificial space has been added between NetBSD and $, this is a workaround
                   5392: here to prevent CVS expanding to the filename of the guide. When adding the RCS
1.195     gutterid 5393: ID the space should be omitted.
1.1       dsieger  5394: 
1.184     rillig   5395: 19.5. Man page compression
1.1       dsieger  5396: 
1.184     rillig   5397: Man pages should be installed in compressed form if MANZ is set (in
                   5398: bsd.own.mk), and uncompressed otherwise. To handle this in the PLIST file, the
                   5399: suffix ".gz" is appended/removed automatically for man pages according to MANZ
                   5400: and MANCOMPRESSED being set or not, see above for details. This modification of
                   5401: the PLIST file is done on a copy of it, not PLIST itself.
1.100     leot     5402: 
1.184     rillig   5403: 19.6. Changing PLIST source with PLIST_SRC
1.100     leot     5404: 
1.184     rillig   5405: To use one or more files as source for the PLIST used in generating the binary
                   5406: package, set the variable PLIST_SRC to the names of that file(s). The files are
                   5407: later concatenated using cat(1), and the order of things is important. The
                   5408: default for PLIST_SRC is ${PKGDIR}/PLIST.
1.1       dsieger  5409: 
1.184     rillig   5410: 19.7. Platform-specific and differing PLISTs
1.1       dsieger  5411: 
1.184     rillig   5412: Some packages decide to install a different set of files based on the operating
                   5413: system being used. These differences can be automatically handled by using the
                   5414: following files:
1.1       dsieger  5415: 
1.184     rillig   5416:   * PLIST.common
1.1       dsieger  5417: 
1.184     rillig   5418:   * PLIST.${OPSYS}
1.1       dsieger  5419: 
1.184     rillig   5420:   * PLIST.${MACHINE_ARCH}
1.1       dsieger  5421: 
1.184     rillig   5422:   * PLIST.${OPSYS}-${MACHINE_ARCH}
1.1       dsieger  5423: 
1.184     rillig   5424:   * PLIST.common_end
1.1       dsieger  5425: 
1.184     rillig   5426: 19.8. Build-specific PLISTs
1.1       dsieger  5427: 
1.184     rillig   5428: Some packages decide to generate hard-to-guess file names during installation
                   5429: that are hard to wire down.
1.1       dsieger  5430: 
1.184     rillig   5431: In such cases, you can set the GENERATE_PLIST variable to shell code terminated
                   5432: (with a semicolon) that will output PLIST entries which will be appended to the
                   5433: PLIST
1.1       dsieger  5434: 
1.184     rillig   5435: You can find one example in editors/xemacs:
1.1       dsieger  5436: 
1.184     rillig   5437: GENERATE_PLIST+=        ${ECHO} bin/${DISTNAME}-`${WRKSRC}/src/xemacs -sd`.dmp ;
1.1       dsieger  5438: 
1.184     rillig   5439: which will append something like bin/xemacs-21.4.23-54e8ea71.dmp to the PLIST.
1.1       dsieger  5440: 
1.184     rillig   5441: 19.9. Sharing directories between packages
1.1       dsieger  5442: 
1.184     rillig   5443: A "shared directory" is a directory where multiple (and unrelated) packages
                   5444: install files. These directories were problematic because you had to add
                   5445: special tricks in the PLIST to conditionally remove them, or have some
                   5446: centralized package handle them.
1.106     tnn      5447: 
1.184     rillig   5448: In pkgsrc, it is now easy: Each package should create directories and install
                   5449: files as needed; pkg_delete will remove any directories left empty after
                   5450: uninstalling a package.
1.106     tnn      5451: 
1.184     rillig   5452: If a package needs an empty directory to work, create the directory during
                   5453: installation as usual, and also add an entry to the PLIST:
1.1       dsieger  5454: 
1.184     rillig   5455: @pkgdir path/to/empty/directory
1.1       dsieger  5456: 
1.184     rillig   5457: or take a look at MAKE_DIRS and OWN_DIRS.
1.1       dsieger  5458: 
1.184     rillig   5459: Chapter 20. The pkginstall framework
1.1       dsieger  5460: 
1.184     rillig   5461: Table of Contents
1.1       dsieger  5462: 
1.184     rillig   5463: 20.1. Files and directories outside the installation prefix
                   5464:     20.1.1. Directory manipulation
                   5465:     20.1.2. File manipulation
                   5466: 20.2. Configuration files
                   5467:     20.2.1. How PKG_SYSCONFDIR is set
                   5468:     20.2.2. Telling the software where configuration files are
                   5469:     20.2.3. Patching installations
                   5470:     20.2.4. Disabling handling of configuration files
                   5471: 20.3. System startup scripts
                   5472:     20.3.1. Disabling handling of system startup scripts
                   5473: 20.4. System users and groups
                   5474: 20.5. System shells
                   5475:     20.5.1. Disabling shell registration
                   5476: 20.6. Fonts
                   5477:     20.6.1. Disabling automatic update of the fonts databases
1.1       dsieger  5478: 
1.184     rillig   5479: This chapter describes the framework known as pkginstall, whose key features
                   5480: are:
1.1       dsieger  5481: 
1.184     rillig   5482:   * Generic installation and manipulation of directories and files outside the
                   5483:     pkgsrc-handled tree, LOCALBASE.
1.1       dsieger  5484: 
1.184     rillig   5485:   * Automatic handling of configuration files during installation, provided
                   5486:     that packages are correctly designed.
1.1       dsieger  5487: 
1.184     rillig   5488:   * Generation and installation of system startup scripts.
1.1       dsieger  5489: 
1.184     rillig   5490:   * Registration of system users and groups.
1.1       dsieger  5491: 
1.184     rillig   5492:   * Registration of system shells.
1.1       dsieger  5493: 
1.184     rillig   5494:   * Automatic updating of fonts databases.
1.1       dsieger  5495: 
1.184     rillig   5496: The following sections inspect each of the above points in detail.
1.1       dsieger  5497: 
1.184     rillig   5498: You may be thinking that many of the things described here could be easily done
                   5499: with simple code in the package's post-installation target (post-install). This
                   5500: is incorrect, as the code in them is only executed when building from source.
                   5501: Machines using binary packages could not benefit from it at all (as the code
                   5502: itself could be unavailable). Therefore, the only way to achieve any of the
                   5503: items described above is by means of the installation scripts, which are
                   5504: automatically generated by pkginstall.
1.1       dsieger  5505: 
1.184     rillig   5506: 20.1. Files and directories outside the installation prefix
1.95      wiz      5507: 
1.184     rillig   5508: As you already know, the PLIST file holds a list of files and directories that
                   5509: belong to a package. The names used in it are relative to the installation
                   5510: prefix (${PREFIX}), which means that it cannot register files outside this
                   5511: directory (absolute path names are not allowed). Despite this restriction, some
                   5512: packages need to install files outside this location; e.g., under ${VARBASE} or
                   5513: ${PKG_SYSCONFDIR}. The only way to achieve this is to create such files during
                   5514: installation time by using installation scripts.
1.95      wiz      5515: 
1.184     rillig   5516: The generic installation scripts are shell scripts that can contain arbitrary
                   5517: code. The list of scripts to execute is taken from the INSTALL_FILE variable,
                   5518: which defaults to INSTALL. A similar variable exists for package removal
                   5519: (DEINSTALL_FILE, whose default is DEINSTALL). These scripts can run arbitrary
                   5520: commands, so they have the potential to create and manage files anywhere in the
                   5521: file system.
1.95      wiz      5522: 
1.184     rillig   5523: Using these general installation files is not recommended, but may be needed in
                   5524: some special cases. One reason for avoiding them is that the user has to trust
                   5525: the packager that there is no unwanted or simply erroneous code included in the
                   5526: installation script. Also, previously there were many similar scripts for the
                   5527: same functionality, and fixing a common error involved finding and changing all
                   5528: of them.
1.95      wiz      5529: 
1.184     rillig   5530: The pkginstall framework offers another, standardized way. It provides generic
                   5531: scripts to abstract the manipulation of such files and directories based on
                   5532: variables set in the package's Makefile. The rest of this section describes
                   5533: these variables.
1.1       dsieger  5534: 
1.184     rillig   5535: 20.1.1. Directory manipulation
1.1       dsieger  5536: 
1.184     rillig   5537: The following variables can be set to request the creation of directories
                   5538: anywhere in the file system:
1.1       dsieger  5539: 
1.184     rillig   5540:   * MAKE_DIRS and OWN_DIRS contain a list of directories that should be created
                   5541:     and should attempt to be destroyed by the installation scripts. The
                   5542:     difference between the two is that the latter prompts the administrator to
                   5543:     remove any directories that may be left after deinstallation (because they
                   5544:     were not empty), while the former does not. Example:
1.1       dsieger  5545: 
1.184     rillig   5546:     MAKE_DIRS+=             ${VARBASE}/foo/private
1.1       dsieger  5547: 
1.184     rillig   5548:   * MAKE_DIRS_PERMS and OWN_DIRS_PERMS contain a list of tuples describing
                   5549:     which directories should be created and should attempt to be destroyed by
                   5550:     the installation scripts. Each tuple holds the following values, separated
                   5551:     by spaces: the directory name, its owner, its group and its numerical mode.
                   5552:     For example:
1.1       dsieger  5553: 
1.184     rillig   5554:     MAKE_DIRS_PERMS+=       ${VARBASE}/foo/private \
                   5555:                             ${REAL_ROOT_USER} ${REAL_ROOT_GROUP} 0700
1.1       dsieger  5556: 
1.184     rillig   5557:     The difference between the two is exactly the same as their non-PERMS
                   5558:     counterparts.
1.1       dsieger  5559: 
1.184     rillig   5560: 20.1.2. File manipulation
1.1       dsieger  5561: 
1.184     rillig   5562: Creating non-empty files outside the installation prefix is tricky because the
                   5563: PLIST forces all files to be inside it. To overcome this problem, the only
                   5564: solution is to extract the file in the known place (i.e., inside the
                   5565: installation prefix) and copy it to the appropriate location during
                   5566: installation (done by the installation scripts generated by pkginstall). We
                   5567: will call the former the master file in the following paragraphs, which
                   5568: describe the variables that can be used to automatically and consistently
                   5569: handle files outside the installation prefix:
1.1       dsieger  5570: 
1.184     rillig   5571:   * CONF_FILES and REQD_FILES are pairs of master and target files. During
                   5572:     installation time, the master file is copied to the target one if and only
                   5573:     if the latter does not exist. Upon deinstallation, the target file is
                   5574:     removed provided that it was not modified by the installation.
1.1       dsieger  5575: 
1.184     rillig   5576:     The difference between the two is that the latter prompts the administrator
                   5577:     to remove any files that may be left after deinstallation (because they
                   5578:     were not empty), while the former does not.
1.1       dsieger  5579: 
1.184     rillig   5580:   * CONF_FILES_PERMS and REQD_FILES_PERMS contain tuples describing master
                   5581:     files as well as their target locations. For each of them, it also
                   5582:     specifies their owner, their group and their numeric permissions, in this
                   5583:     order. For example:
1.1       dsieger  5584: 
1.184     rillig   5585:     REQD_FILES_PERMS+=      ${PREFIX}/share/somefile ${VARBASE}/somefile \
                   5586:                             ${REAL_ROOT_USER} ${REAL_ROOT_GROUP} 0700
1.1       dsieger  5587: 
1.184     rillig   5588:     The difference between the two is exactly the same as their non-PERMS
                   5589:     counterparts.
1.1       dsieger  5590: 
1.184     rillig   5591: 20.2. Configuration files
1.1       dsieger  5592: 
1.184     rillig   5593: Configuration files are special in the sense that they are installed in their
                   5594: own specific directory, PKG_SYSCONFDIR, and need special treatment during
                   5595: installation (most of which is automated by pkginstall). The main concept you
                   5596: must bear in mind is that files marked as configuration files are automatically
                   5597: copied to the right place (somewhere inside PKG_SYSCONFDIR) during installation
                   5598: if and only if they didn't exist before. Similarly, they will not be removed if
                   5599: they have local modifications. This ensures that administrators never lose any
                   5600: custom changes they may have made.
1.1       dsieger  5601: 
1.184     rillig   5602: 20.2.1. How PKG_SYSCONFDIR is set
1.1       dsieger  5603: 
1.184     rillig   5604: As said before, the PKG_SYSCONFDIR variable specifies where configuration files
                   5605: shall be installed. Its contents are set based upon the following variables:
1.1       dsieger  5606: 
1.184     rillig   5607:   * PKG_SYSCONFBASE: The configuration's root directory. Defaults to ${PREFIX}/
                   5608:     etc although it may be overridden by the user to point to his preferred
                   5609:     location (e.g., /etc, /etc/pkg, etc.). Packages must not use it directly.
1.1       dsieger  5610: 
1.184     rillig   5611:   * PKG_SYSCONFSUBDIR: A subdirectory of PKG_SYSCONFBASE under which the
                   5612:     configuration files for the package being built shall be installed. The
                   5613:     definition of this variable only makes sense in the package's Makefile
                   5614:     (i.e., it is not user-customizable).
1.1       dsieger  5615: 
1.184     rillig   5616:     As an example, consider the Apache package, www/apache24, which places its
                   5617:     configuration files under the httpd/ subdirectory of PKG_SYSCONFBASE. This
                   5618:     should be set in the package Makefile.
1.1       dsieger  5619: 
1.184     rillig   5620:   * PKG_SYSCONFVAR: Specifies the name of the variable that holds this
                   5621:     package's configuration directory (if different from PKG_SYSCONFBASE). It
                   5622:     defaults to PKGBASE's value, and is always prefixed with PKG_SYSCONFDIR.
1.1       dsieger  5623: 
1.184     rillig   5624:   * PKG_SYSCONFDIR.${PKG_SYSCONFVAR}: Holds the directory where the
                   5625:     configuration files for the package identified by PKG_SYSCONFVAR's shall be
                   5626:     placed.
1.1       dsieger  5627: 
1.184     rillig   5628: Based on the above variables, pkginstall determines the value of
                   5629: PKG_SYSCONFDIR, which is the only variable that can be used within a package to
                   5630: refer to its configuration directory. The algorithm used to set its value is
                   5631: basically the following:
1.1       dsieger  5632: 
1.184     rillig   5633:  1. If PKG_SYSCONFDIR.${PKG_SYSCONFVAR} is set, its value is used.
1.1       dsieger  5634: 
1.184     rillig   5635:  2. If the previous variable is not defined but PKG_SYSCONFSUBDIR is set in the
                   5636:     package's Makefile, the resulting value is ${PKG_SYSCONFBASE}/$
                   5637:     {PKG_SYSCONFSUBDIR}.
1.1       dsieger  5638: 
1.184     rillig   5639:  3. Otherwise, it is set to ${PKG_SYSCONFBASE}.
1.1       dsieger  5640: 
1.184     rillig   5641: It is worth mentioning that ${PKG_SYSCONFDIR} is automatically added to
                   5642: OWN_DIRS. See Section 20.1.1, "Directory manipulation" what this means. This
                   5643: does not apply to subdirectories of ${PKG_SYSCONFDIR}, they still have to be
                   5644: created with OWN_DIRS or MAKE_DIRS.
1.1       dsieger  5645: 
1.184     rillig   5646: 20.2.2. Telling the software where configuration files are
1.1       dsieger  5647: 
1.184     rillig   5648: Given that pkgsrc (and users!) expect configuration files to be in a known
                   5649: place, you need to teach each package where it shall install its files. In some
                   5650: cases you will have to patch the package Makefiles to achieve it. If you are
                   5651: lucky, though, it may be as easy as passing an extra flag to the configuration
                   5652: script; this is the case of GNU Autoconf- generated files:
1.1       dsieger  5653: 
1.184     rillig   5654: CONFIGURE_ARGS+= --sysconfdir=${PKG_SYSCONFDIR}
1.1       dsieger  5655: 
1.184     rillig   5656: Note that this specifies where the package has to look for its configuration
                   5657: files, not where they will be originally installed (although the difference is
                   5658: never explicit, unfortunately).
1.1       dsieger  5659: 
1.184     rillig   5660: 20.2.3. Patching installations
1.1       dsieger  5661: 
1.184     rillig   5662: As said before, pkginstall automatically handles configuration files. This
                   5663: means that the packages themselves must not touch the contents of $
                   5664: {PKG_SYSCONFDIR} directly. Bad news is that many software installation scripts
                   5665: will, out of the box, mess with the contents of that directory. So what is the
                   5666: correct procedure to fix this issue?
1.1       dsieger  5667: 
1.184     rillig   5668: You must teach the package (usually by manually patching it) to install any
                   5669: configuration files under the examples hierarchy, share/examples/${PKGBASE}/.
                   5670: This way, the PLIST registers them and the administrator always has the
                   5671: original copies available.
1.1       dsieger  5672: 
1.184     rillig   5673: Once the required configuration files are in place (i.e., under the examples
                   5674: hierarchy), the pkginstall framework can use them as master copies during the
                   5675: package installation to update what is in ${PKG_SYSCONFDIR}. To achieve this,
                   5676: the variables CONF_FILES and CONF_FILES_PERMS are used. Check out
                   5677: Section 20.1.2, "File manipulation" for information about their syntax and
                   5678: their purpose. Here is an example, taken from the mail/mutt package:
1.1       dsieger  5679: 
1.184     rillig   5680: EGDIR=        ${PREFIX}/share/doc/mutt/samples
                   5681: CONF_FILES=   ${EGDIR}/Muttrc ${PKG_SYSCONFDIR}/Muttrc
1.1       dsieger  5682: 
1.184     rillig   5683: Note that the EGDIR variable is specific to that package and has no meaning
                   5684: outside it.
1.1       dsieger  5685: 
1.184     rillig   5686: 20.2.4. Disabling handling of configuration files
1.1       dsieger  5687: 
1.184     rillig   5688: The automatic copying of config files can be toggled by setting the environment
                   5689: variable PKG_CONFIG prior to package installation.
1.1       dsieger  5690: 
1.184     rillig   5691: 20.3. System startup scripts
1.1       dsieger  5692: 
1.184     rillig   5693: System startup scripts are special files because they must be installed in a
                   5694: place known by the underlying OS, usually outside the installation prefix.
                   5695: Therefore, the same rules described in Section 20.1, "Files and directories
                   5696: outside the installation prefix" apply, and the same solutions can be used.
                   5697: However, pkginstall provides a special mechanism to handle these files.
1.1       dsieger  5698: 
1.184     rillig   5699: In order to provide system startup scripts, the package has to:
1.1       dsieger  5700: 
1.184     rillig   5701:  1. Store the script inside ${FILESDIR}, with the .sh suffix appended.
1.223     nia      5702:     Considering the print/cups-base package as an example, it has a cupsd.sh in
                   5703:     its files directory.
1.95      wiz      5704: 
1.184     rillig   5705:  2. Tell pkginstall to handle it, appending the name of the script, without its
                   5706:     extension, to the RCD_SCRIPTS variable. Continuing the previous example:
1.95      wiz      5707: 
1.184     rillig   5708:     RCD_SCRIPTS+=   cupsd
1.95      wiz      5709: 
1.184     rillig   5710: Once this is done, pkginstall will do the following steps for each script in an
                   5711: automated fashion:
1.95      wiz      5712: 
1.184     rillig   5713:  1. Process the file found in the files directory applying all the
                   5714:     substitutions described in the FILES_SUBST variable.
1.1       dsieger  5715: 
1.184     rillig   5716:  2. Copy the script from the files directory to the examples hierarchy, $
                   5717:     {PREFIX}/share/examples/rc.d/. Note that this master file must be
                   5718:     explicitly registered in the PLIST.
1.1       dsieger  5719: 
1.184     rillig   5720:  3. Add code to the installation scripts to copy the startup script from the
                   5721:     examples hierarchy into the system-wide startup scripts directory.
1.1       dsieger  5722: 
1.184     rillig   5723: 20.3.1. Disabling handling of system startup scripts
1.1       dsieger  5724: 
1.184     rillig   5725: The automatic copying of config files can be toggled by setting the environment
                   5726: variable PKG_RCD_SCRIPTS prior to package installation. Note that the scripts
                   5727: will be always copied inside the examples hierarchy, ${PREFIX}/share/examples/
                   5728: rc.d/, no matter what the value of this variable is.
1.1       dsieger  5729: 
1.184     rillig   5730: 20.4. System users and groups
1.1       dsieger  5731: 
1.184     rillig   5732: If a package needs to create special users and/or groups during installation,
                   5733: it can do so by using the pkginstall framework.
1.1       dsieger  5734: 
1.184     rillig   5735: Users can be created by adding entries to the PKG_USERS variable. Each entry
                   5736: has the following syntax:
1.1       dsieger  5737: 
1.184     rillig   5738: user:group
1.1       dsieger  5739: 
1.184     rillig   5740: Further specification of user details may be done by setting per-user
                   5741: variables. PKG_UID.user is the numeric UID for the user. PKG_GECOS.user is the
                   5742: user's description or comment. PKG_HOME.user is the user's home directory, and
                   5743: defaults to /nonexistent if not specified. PKG_SHELL.user is the user's shell,
                   5744: and defaults to /sbin/nologin if not specified.
1.1       dsieger  5745: 
1.184     rillig   5746: Similarly, groups can be created by adding entries to the PKG_GROUPS variable,
                   5747: whose syntax is:
1.1       dsieger  5748: 
1.184     rillig   5749: group
1.1       dsieger  5750: 
1.184     rillig   5751: The numeric GID of the group may be set by defining PKG_GID.group.
1.1       dsieger  5752: 
1.184     rillig   5753: If a package needs to create the users and groups at an earlier stage, then it
                   5754: can set USERGROUP_PHASE to either configure,build, or pre-install to indicate
                   5755: the phase before which the users and groups are created. In this case, the
                   5756: numeric UIDs and GIDs of the created users and groups are automatically
                   5757: hardcoded into the final installation scripts.
1.1       dsieger  5758: 
1.184     rillig   5759: 20.5. System shells
1.1       dsieger  5760: 
1.184     rillig   5761: Packages that install system shells should register them in the shell database,
                   5762: /etc/shells, to make things easier to the administrator. This must be done from
                   5763: the installation scripts to keep binary packages working on any system.
                   5764: pkginstall provides an easy way to accomplish this task.
1.1       dsieger  5765: 
1.184     rillig   5766: When a package provides a shell interpreter, it has to set the PKG_SHELL
                   5767: variable to its absolute file name. This will add some hooks to the
                   5768: installation scripts to handle it. Consider the following example, taken from
                   5769: shells/zsh:
1.1       dsieger  5770: 
1.184     rillig   5771: PKG_SHELL=      ${PREFIX}/bin/zsh
1.1       dsieger  5772: 
1.184     rillig   5773: 20.5.1. Disabling shell registration
1.1       dsieger  5774: 
1.184     rillig   5775: The automatic registration of shell interpreters can be disabled by the
                   5776: administrator by setting the PKG_REGISTER_SHELLS environment variable to NO.
1.1       dsieger  5777: 
1.184     rillig   5778: 20.6. Fonts
1.1       dsieger  5779: 
1.184     rillig   5780: Packages that install X11 fonts should update the database files that index the
                   5781: fonts within each fonts directory. This can easily be accomplished within the
                   5782: pkginstall framework.
1.1       dsieger  5783: 
1.184     rillig   5784: When a package installs X11 fonts, it must list the directories in which fonts
                   5785: are installed in the FONTS_DIRS.type variables, where type can be one of "ttf",
                   5786: "type1" or "x11". This will add hooks to the installation scripts to run the
                   5787: appropriate commands to update the fonts database files within each of those
                   5788: directories. For convenience, if the directory path is relative, it is taken to
                   5789: be relative to the package's installation prefix. Consider the following
                   5790: example, taken from fonts/dbz-ttf:
1.1       dsieger  5791: 
1.184     rillig   5792: FONTS_DIRS.ttf= ${PREFIX}/share/fonts/X11/TTF
1.1       dsieger  5793: 
1.184     rillig   5794: 20.6.1. Disabling automatic update of the fonts databases
1.1       dsieger  5795: 
1.184     rillig   5796: The automatic update of fonts databases can be disabled by the administrator by
                   5797: setting the PKG_UPDATE_FONTS_DB environment variable to NO.
1.1       dsieger  5798: 
1.154     rillig   5799: Chapter 21. Making your package work
1.1       dsieger  5800: 
                   5801: Table of Contents
                   5802: 
1.154     rillig   5803: 21.1. General operation
                   5804:     21.1.1. How to pull in user-settable variables from mk.conf
                   5805:     21.1.2. User interaction
                   5806:     21.1.3. Handling licenses
                   5807:     21.1.4. Restricted packages
                   5808:     21.1.5. Handling dependencies
                   5809:     21.1.6. Handling conflicts with other packages
                   5810:     21.1.7. Packages that cannot or should not be built
                   5811:     21.1.8. Packages which should not be deleted, once installed
                   5812:     21.1.9. Handling packages with security problems
                   5813:     21.1.10. How to handle incrementing versions when fixing an existing
1.232   ! gutterid 5814:     package
1.154     rillig   5815:     21.1.11. Substituting variable text in the package files (the SUBST
1.232   ! gutterid 5816:     framework)
1.154     rillig   5817: 21.2. The fetch phase
                   5818:     21.2.1. Packages whose distfiles aren't available for plain downloading
                   5819:     21.2.2. How to handle modified distfiles with the 'old' name
                   5820:     21.2.3. Packages hosted on github.com
                   5821: 21.3. The configure phase
                   5822:     21.3.1. Shared libraries - libtool
                   5823:     21.3.2. Using libtool on GNU packages that already support libtool
                   5824:     21.3.3. GNU Autoconf/Automake
1.223     nia      5825:     21.3.4. Meson / ninja
1.154     rillig   5826: 21.4. Programming languages
                   5827:     21.4.1. C, C++, and Fortran
                   5828:     21.4.2. Java
1.205     wiz      5829:     21.4.3. Go
1.223     nia      5830:     21.4.4. Rust
                   5831:     21.4.5. Packages containing Perl scripts
                   5832:     21.4.6. Packages containing shell scripts
                   5833:     21.4.7. Other programming languages
1.154     rillig   5834: 21.5. The build phase
                   5835:     21.5.1. Compiling C and C++ code conditionally
                   5836:     21.5.2. How to handle compiler bugs
1.172     rillig   5837:     21.5.3. No such file or directory
                   5838:     21.5.4. Undefined reference to "..."
                   5839:     21.5.5. Running out of memory
1.154     rillig   5840: 21.6. The install phase
                   5841:     21.6.1. Creating needed directories
                   5842:     21.6.2. Where to install documentation
                   5843:     21.6.3. Installing highscore files
                   5844:     21.6.4. Adding DESTDIR support to packages
                   5845:     21.6.5. Packages with hardcoded paths to other interpreters
1.203     nia      5846:     21.6.6. Packages installing Perl modules
1.154     rillig   5847:     21.6.7. Packages installing info files
                   5848:     21.6.8. Packages installing man pages
1.203     nia      5849:     21.6.9. Packages installing X11 fonts
                   5850:     21.6.10. Packages installing SGML or XML data
                   5851:     21.6.11. Packages installing extensions to the MIME database
                   5852:     21.6.12. Packages using intltool
                   5853:     21.6.13. Packages installing startup scripts
                   5854:     21.6.14. Packages installing TeX modules
                   5855:     21.6.15. Packages supporting running binaries in emulation
                   5856:     21.6.16. Packages installing hicolor icons
                   5857:     21.6.17. Packages installing desktop files
1.154     rillig   5858: 21.7. Marking packages as having problems
1.1       dsieger  5859: 
1.154     rillig   5860: 21.1. General operation
1.1       dsieger  5861: 
                   5862: One appealing feature of pkgsrc is that it runs on many different platforms. As
                   5863: a result, it is important to ensure, where possible, that packages in pkgsrc
                   5864: are portable. This chapter mentions some particular details you should pay
                   5865: attention to while working on pkgsrc.
                   5866: 
1.154     rillig   5867: 21.1.1. How to pull in user-settable variables from mk.conf
1.1       dsieger  5868: 
                   5869: The pkgsrc user can configure pkgsrc by overriding several variables in the
1.4       rillig   5870: file pointed to by MAKECONF, which is mk.conf by default. When you want to use
                   5871: those variables in the preprocessor directives of make(1) (for example .if or
                   5872: .for), you need to include the file ../../mk/bsd.prefs.mk before, which in turn
                   5873: loads the user preferences.
1.1       dsieger  5874: 
                   5875: But note that some variables may not be completely defined after ../../mk/
                   5876: bsd.prefs.mk has been included, as they may contain references to variables
1.108     rillig   5877: that are not yet defined. In shell commands (the lines in Makefile that are
                   5878: indented with a tab) this is no problem, since variables are only expanded when
                   5879: they are used. But in the preprocessor directives mentioned above and in
                   5880: dependency lines (of the form target: dependencies) the variables are expanded
                   5881: at load time.
1.1       dsieger  5882: 
                   5883: Note
                   5884: 
1.108     rillig   5885: To check whether a variable can be used at load time, run pkglint -Wall on your
                   5886: package.
1.1       dsieger  5887: 
1.154     rillig   5888: 21.1.2. User interaction
1.1       dsieger  5889: 
                   5890: Occasionally, packages require interaction from the user, and this can be in a
                   5891: number of ways:
                   5892: 
                   5893:   * When fetching the distfiles, some packages require user interaction such as
                   5894:     entering username/password or accepting a license on a web page.
                   5895: 
                   5896:   * When extracting the distfiles, some packages may ask for passwords.
                   5897: 
                   5898:   * help to configure the package before it is built
                   5899: 
                   5900:   * help during the build process
                   5901: 
                   5902:   * help during the installation of a package
                   5903: 
1.108     rillig   5904: A package can set the INTERACTIVE_STAGE variable to define which stages need
                   5905: interaction. This should be done in the package's Makefile, e.g.:
1.1       dsieger  5906: 
                   5907: INTERACTIVE_STAGE=      configure install
                   5908: 
                   5909: The user can then decide to skip this package by setting the BATCH variable.
1.108     rillig   5910: Packages that require interaction are also excluded from bulk builds.
1.1       dsieger  5911: 
1.154     rillig   5912: 21.1.3. Handling licenses
1.1       dsieger  5913: 
                   5914: Authors of software can choose the licence under which software can be copied.
1.111     sevan    5915: The Free Software Foundation has declared some licenses "Free", and the Open
                   5916: Source Initiative has a definition of "Open Source".
                   5917: 
                   5918: By default, pkgsrc allows packages with Free or Open Source licenses to be
                   5919: built. To allow packages with other licenses to be built as well, the pkgsrc
                   5920: user needs to add these licenses to the ACCEPTABLE_LICENSES variable in mk.conf
                   5921: . Note that this variable only affects which packages may be built, while the
                   5922: license terms often also restrict the actual use of the package and its
                   5923: redistribution.
1.1       dsieger  5924: 
                   5925: One might want to only install packages with a BSD license, or the GPL, and not
1.20      jnemeth  5926: the other. The free licenses are added to the default ACCEPTABLE_LICENSES
1.111     sevan    5927: variable. The pkgsrc user can override the default by setting the
                   5928: ACCEPTABLE_LICENSES variable with "=" instead of "+=". The licenses accepted by
                   5929: default are defined in the DEFAULT_ACCEPTABLE_LICENSES variable in the file
                   5930: pkgsrc/mk/license.mk.
1.1       dsieger  5931: 
                   5932: The license tag mechanism is intended to address copyright-related issues
                   5933: surrounding building, installing and using a package, and not to address
1.20      jnemeth  5934: redistribution issues (see RESTRICTED and NO_SRC_ON_FTP, etc.). Packages with
                   5935: redistribution restrictions should set these tags.
1.1       dsieger  5936: 
                   5937: Denoting that a package may be copied according to a particular license is done
                   5938: by placing the license in pkgsrc/licenses and setting the LICENSE variable to a
                   5939: string identifying the license, e.g. in graphics/xv:
                   5940: 
                   5941: LICENSE=        xv-license
                   5942: 
                   5943: When trying to build, the user will get a notice that the package is covered by
                   5944: a license which has not been placed in the ACCEPTABLE_LICENSES variable:
                   5945: 
                   5946: % make
                   5947: ===> xv-3.10anb9 has an unacceptable license: xv-license.
                   5948: ===>     To view the license, enter "/usr/bin/make show-license".
                   5949: ===>     To indicate acceptance, add this line to your /etc/mk.conf:
                   5950: ===>     ACCEPTABLE_LICENSES+=xv-license
                   5951: *** Error code 1
                   5952: 
                   5953: The license can be viewed with make show-license, and if the user so chooses,
1.4       rillig   5954: the line printed above can be added to mk.conf to convey to pkgsrc that it
1.1       dsieger  5955: should not in the future fail because of that license:
                   5956: 
                   5957: ACCEPTABLE_LICENSES+=xv-license
                   5958: 
1.111     sevan    5959: The use of LICENSE=shareware, LICENSE=no-commercial-use, and similar language
                   5960: is deprecated because it does not crisply refer to a particular license text.
                   5961: Another problem with such usage is that it does not enable a user to tell
                   5962: pkgsrc to proceed for a single package without also telling pkgsrc to proceed
                   5963: for all packages with that tag.
                   5964: 
1.154     rillig   5965: 21.1.3.1. Adding a package with a new license
1.1       dsieger  5966: 
1.49      rodent   5967: When adding a package with a new license, the following steps are required:
                   5968: 
1.111     sevan    5969:  1. Check whether the license qualifies as Free or Open Source by referencing
                   5970:     Various Licenses and Comments about Them and Licenses by Name | Open Source
                   5971:     Initiative. If this is the case, the filename in pkgsrc/licenses/ does not
                   5972:     need the -license suffix, and the license name should be added to:
1.49      rodent   5973: 
                   5974:       + DEFAULT_ACCEPTABLE_LICENSES in pkgsrc/mk/license.mk
                   5975: 
                   5976:       + default_acceptable_licenses in pkgsrc/pkgtools/pkg_install/files/lib/
                   5977:         license.c
                   5978: 
                   5979:  2. The license text should be added to pkgsrc/licenses for displaying. A list
                   5980:     of known licenses can be seen in this directory.
1.1       dsieger  5981: 
1.154     rillig   5982: 21.1.3.2. Change to the license
1.1       dsieger  5983: 
1.111     sevan    5984: When the license changes (in a way other than formatting), make sure that the
                   5985: new license has a different name (e.g., append the version number if it exists,
                   5986: or the date). Just because a user told pkgsrc to build programs under a
                   5987: previous version of a license does not mean that pkgsrc should build programs
                   5988: under the new licenses. The higher-level point is that pkgsrc does not evaluate
                   5989: licenses for reasonableness; the only test is a mechanistic test of whether a
                   5990: particular text has been approved by either of two bodies (FSF or OSI).
1.1       dsieger  5991: 
1.154     rillig   5992: 21.1.4. Restricted packages
1.1       dsieger  5993: 
1.111     sevan    5994: Some licenses restrict how software may be re-distributed. By declaring the
                   5995: restrictions, package tools can automatically refrain from e.g. placing binary
                   5996: packages on FTP sites.
                   5997: 
                   5998: There are four possible restrictions, which are the cross product of sources
                   5999: (distfiles) and binaries not being placed on FTP sites and CD-ROMs. Because
                   6000: this is rarely the exact language in any license, and because non-Free licenses
                   6001: tend to be different from each other, pkgsrc adopts a definition of FTP and
                   6002: CD-ROM. "FTP" means making the source or binary file available over the
                   6003: Internet at no charge. "CD-ROM" means making the source or binary available on
                   6004: some kind of media, together with other source and binary packages, which is
                   6005: sold for a distribution charge.
1.1       dsieger  6006: 
                   6007: In order to encode these restrictions, the package system defines five make
                   6008: variables that can be set to note these restrictions:
                   6009: 
                   6010:   * RESTRICTED
                   6011: 
                   6012:     This variable should be set whenever a restriction exists (regardless of
                   6013:     its kind). Set this variable to a string containing the reason for the
                   6014:     restriction. It should be understood that those wanting to understand the
                   6015:     restriction will have to read the license, and perhaps seek advice of
                   6016:     counsel.
                   6017: 
                   6018:   * NO_BIN_ON_CDROM
                   6019: 
                   6020:     Binaries may not be placed on CD-ROM containing other binary packages, for
                   6021:     which a distribution charge may be made. In this case, set this variable to
                   6022:     ${RESTRICTED}.
                   6023: 
                   6024:   * NO_BIN_ON_FTP
                   6025: 
                   6026:     Binaries may not made available on the Internet without charge. In this
                   6027:     case, set this variable to ${RESTRICTED}. If this variable is set, binary
                   6028:     packages will not be included on ftp.NetBSD.org.
                   6029: 
                   6030:   * NO_SRC_ON_CDROM
                   6031: 
                   6032:     Distfiles may not be placed on CD-ROM, together with other distfiles, for
                   6033:     which a fee may be charged. In this case, set this variable to $
                   6034:     {RESTRICTED}.
                   6035: 
                   6036:   * NO_SRC_ON_FTP
                   6037: 
                   6038:     Distfiles may not made available via FTP at no charge. In this case, set
                   6039:     this variable to ${RESTRICTED}. If this variable is set, the distfile(s)
                   6040:     will not be mirrored on ftp.NetBSD.org.
                   6041: 
1.111     sevan    6042: Please note that packages will be removed from pkgsrc when the distfiles are
1.33      wiz      6043: not distributable and cannot be obtained for a period of one full quarter
1.111     sevan    6044: branch. Packages with manual/interactive fetch must have a maintainer and it is
                   6045: his/her responsibility to ensure this.
1.33      wiz      6046: 
1.154     rillig   6047: 21.1.5. Handling dependencies
1.1       dsieger  6048: 
1.175     gutterid 6049: Your package may depend on some other package being present, and there are
                   6050: various ways of expressing this dependency. pkgsrc supports the DEPENDS,
                   6051: BUILD_DEPENDS, TOOL_DEPENDS, and TEST_DEPENDS definitions, the USE_TOOLS
                   6052: definition, as well as dependencies via buildlink3.mk, which is the preferred
                   6053: way to handle dependencies, and which uses the variables named above. See
1.184     rillig   6054: Chapter 18, Buildlink methodology for more information.
1.175     gutterid 6055: 
                   6056: The basic difference is that the DEPENDS definition registers that
                   6057: pre-requisite in the binary package so it will be pulled in when the binary
                   6058: package is later installed, whilst the BUILD_DEPENDS, TOOL_DEPENDS, and
                   6059: TEST_DEPENDS definitions do not, marking a dependency that is only needed for
1.184     rillig   6060: building or testing the resulting package. See also Chapter 14, Creating a new
1.175     gutterid 6061: pkgsrc package from scratch for more information.
                   6062: 
                   6063: This means that if you only need a package present whilst you are building or
                   6064: testing, it should be noted as a TOOL_DEPENDS, BUILD_DEPENDS, or TEST_DEPENDS.
                   6065: When cross-compiling, TOOL_DEPENDS are native packages, i.e. packages for the
                   6066: architecture where the package is built; BUILD_DEPENDS are target packages,
                   6067: i.e., packages for the architecture for which the package is built.
1.1       dsieger  6068: 
1.175     gutterid 6069: The format for a DEPENDS, BUILD_DEPENDS, TOOL_DEPENDS, and TEST_DEPENDS
                   6070: definition is:
1.1       dsieger  6071: 
                   6072: <pre-req-package-name>:../../<category>/<pre-req-package>
                   6073: 
                   6074: Please note that the "pre-req-package-name" may include any of the wildcard
                   6075: version numbers recognized by pkg_info(1).
                   6076: 
1.55      wiz      6077:  1. If your package needs another package's binaries or libraries to build and
1.1       dsieger  6078:     run, and if that package has a buildlink3.mk file available, use it:
                   6079: 
                   6080:     .include "../../graphics/jpeg/buildlink3.mk"
                   6081: 
1.55      wiz      6082:  2. If your package needs another package's binaries or libraries only for
                   6083:     building, and if that package has a buildlink3.mk file available, use it:
                   6084: 
                   6085:     .include "../../graphics/jpeg/buildlink3.mk"
                   6086: 
                   6087:     but set BUILDLINK_DEPMETHOD.jpeg?=build to make it a build dependency only.
                   6088:     This case is rather rare.
                   6089: 
                   6090:  3. If your package needs binaries from another package to build, use the
1.156     leot     6091:     TOOL_DEPENDS definition:
                   6092: 
                   6093:     TOOL_DEPENDS+= itstool-[0-9]*:../../textproc/itstool
1.1       dsieger  6094: 
1.156     leot     6095:  4. If your package needs static libraries to link against, header files to
                   6096:     include, etc. from another package to build, use the BUILD_DEPENDS
                   6097:     definition.
1.1       dsieger  6098: 
1.156     leot     6099:  5. If your package needs a library with which to link and there is no
1.26      spz      6100:     buildlink3.mk file available, create one. Using DEPENDS won't be sufficient
                   6101:     because the include files and libraries will be hidden from the compiler.
1.1       dsieger  6102: 
1.156     leot     6103:  6. If your package needs some executable to be able to run correctly and if
1.26      spz      6104:     there's no buildlink3.mk file, this is specified using the DEPENDS
                   6105:     variable. The print/lyx package needs to be able to execute the latex
1.129     wiz      6106:     binary from the tex-latex-bin package when it runs, and that is specified:
1.1       dsieger  6107: 
1.129     wiz      6108:     DEPENDS+=        tex-latex-bin-[0-9]*:../../print/tex-latex-bin
1.1       dsieger  6109: 
1.175     gutterid 6110:  7. If your package includes a test suite that has extra dependencies only
                   6111:     required for this purpose (frequently this can be run as a "make test"
                   6112:     target), use the TEST_DEPENDS variable.
                   6113: 
                   6114:  8. You can use wildcards in package dependencies. Note that such wildcard
1.26      spz      6115:     dependencies are retained when creating binary packages. The dependency is
                   6116:     checked when installing the binary package and any package which matches
                   6117:     the pattern will be used. Wildcard dependencies should be used with care.
1.1       dsieger  6118: 
                   6119:     The "-[0-9]*" should be used instead of "-*" to avoid potentially ambiguous
                   6120:     matches such as "tk-postgresql" matching a "tk-*" DEPENDS.
                   6121: 
                   6122:     Wildcards can also be used to specify that a package will only build
                   6123:     against a certain minimum version of a pre-requisite:
                   6124: 
1.26      spz      6125:     DEPENDS+=       ImageMagick>=6.0:../../graphics/ImageMagick
1.1       dsieger  6126: 
1.26      spz      6127:     This means that the package will build using version 6.0 of ImageMagick or
                   6128:     newer. Such a dependency may be warranted if, for example, the command line
                   6129:     options of an executable have changed.
                   6130: 
1.183     wiz      6131:     If you need to depend on minimum versions of libraries, set
                   6132:     BUILDLINK_API_DEPENDS.pkg to the appropriate pattern before including its
                   6133:     buildlink3.mk file, e.g.
                   6134: 
                   6135:     BUILDLINK_API_DEPENDS.jpeg+=    jpeg>=9.0
                   6136:     .include "../../graphics/jpeg/buildlink3.mk"
1.1       dsieger  6137: 
                   6138:     For security fixes, please update the package vulnerabilities file. See
1.154     rillig   6139:     Section 21.1.9, "Handling packages with security problems" for more
1.1       dsieger  6140:     information.
                   6141: 
                   6142: If your package needs files from another package to build, add the relevant
                   6143: distribution files to DISTFILES, so they will be extracted automatically. See
                   6144: the print/ghostscript package for an example. (It relies on the jpeg sources
                   6145: being present in source form during the build.)
                   6146: 
1.154     rillig   6147: 21.1.6. Handling conflicts with other packages
1.1       dsieger  6148: 
1.226     gutterid 6149: Your package may conflict with other packages users might already have
                   6150: installed on their system, e.g., if your package installs the same set of files
1.227     wiz      6151: as another package in the pkgsrc tree.
1.1       dsieger  6152: 
1.142     leot     6153: For example, x11/libXaw3d and x11/Xaw-Xpm install the same shared library, thus
                   6154: you set in pkgsrc/x11/libXaw3d/Makefile:
1.1       dsieger  6155: 
1.142     leot     6156: CONFLICTS=      Xaw-Xpm-[0-9]*
1.1       dsieger  6157: 
                   6158: 
1.142     leot     6159: and in pkgsrc/x11/Xaw-Xpm/Makefile:
1.1       dsieger  6160: 
1.142     leot     6161: CONFLICTS=      libXaw3d-[0-9]*
1.1       dsieger  6162: 
1.142     leot     6163: 
                   6164: pkg_add(1) is able to detect attempts to install packages that conflict with
                   6165: existing packages and abort. However, in many situations this is too late in
                   6166: the process. Binary package managers will not know about the conflict until
                   6167: they attempt to install the package after already downloading it and all its
                   6168: dependencies. Users may also waste time building a package and its dependencies
                   6169: only to find out at the end that it conflicts with another package they have
                   6170: installed.
                   6171: 
                   6172: To avoid these issues CONFLICTS entries should be added in all cases where it
                   6173: is known that packages conflict with each other. These CONFLICTS entries are
                   6174: exported in pkg_summary(5) files and consumed by binary package managers to
                   6175: inform users that packages cannot be installed onto the target system.
1.1       dsieger  6176: 
1.154     rillig   6177: 21.1.7. Packages that cannot or should not be built
1.1       dsieger  6178: 
                   6179: There are several reasons why a package might be instructed to not build under
                   6180: certain circumstances. If the package builds and runs on most platforms, the
1.83      dholland 6181: exceptions should be noted with BROKEN_ON_PLATFORM. If the package builds and
                   6182: runs on a small handful of platforms, set BROKEN_EXCEPT_ON_PLATFORM instead.
                   6183: Both BROKEN_ON_PLATFORM and BROKEN_EXCEPT_ON_PLATFORM are OS triples
                   6184: (OS-version-platform) that can use glob-style wildcards.
                   6185: 
1.114     maya     6186: If a package is not appropriate for some platforms (as opposed to merely
1.83      dholland 6187: broken), a different set of variables should be used as this affects failure
                   6188: reporting and statistics. If the package is appropriate for most platforms, the
                   6189: exceptions should be noted with NOT_FOR_PLATFORM. If the package is appropriate
                   6190: for only a small handful of platforms (often exactly one), set
                   6191: ONLY_FOR_PLATFORM instead. Both ONLY_FOR_PLATFORM and NOT_FOR_PLATFORM are OS
                   6192: triples (OS-version-platform) that can use glob-style wildcards.
1.1       dsieger  6193: 
                   6194: Some packages are tightly bound to a specific version of an operating system,
                   6195: e.g. LKMs or sysutils/lsof. Such binary packages are not backwards compatible
                   6196: with other versions of the OS, and should be uploaded to a version specific
                   6197: directory on the FTP server. Mark these packages by setting OSVERSION_SPECIFIC
                   6198: to "yes". This variable is not currently used by any of the package system
                   6199: internals, but may be used in the future.
                   6200: 
                   6201: If the package should be skipped (for example, because it provides
                   6202: functionality already provided by the system), set PKG_SKIP_REASON to a
                   6203: descriptive message. If the package should fail because some preconditions are
                   6204: not met, set PKG_FAIL_REASON to a descriptive message.
                   6205: 
1.154     rillig   6206: 21.1.8. Packages which should not be deleted, once installed
1.1       dsieger  6207: 
                   6208: To ensure that a package may not be deleted, once it has been installed, the
                   6209: PKG_PRESERVE definition should be set in the package Makefile. This will be
1.25      wiz      6210: carried into any binary package that is made from this pkgsrc entry. A "
                   6211: preserved" package will not be deleted using pkg_delete(1) unless the "-f"
1.1       dsieger  6212: option is used.
                   6213: 
1.154     rillig   6214: 21.1.9. Handling packages with security problems
1.1       dsieger  6215: 
                   6216: When a vulnerability is found, this should be noted in localsrc/security/
1.205     wiz      6217: advisories/pkg-vulnerabilities. Entries in that file consist of three parts:
                   6218: 
                   6219:   * package version pattern
                   6220: 
                   6221:   * type of vulnerability (please cut'n'paste an existing one where possible)
                   6222: 
                   6223:   * URL providing additional information about the issue
                   6224: 
                   6225: For the package version pattern please always use `<' to mark an upper bound
                   6226: (not `<='!). This will avoid possible problems due unrelated PKGREVISION bumps
                   6227: not related to security fixes. Lower bounds can be added too, using '>' or '>=
1.206     wiz      6228: '. For example, "foo>=1<1.2" would mark versions 1.0 (included) to 1.2
1.205     wiz      6229: (excluded) of "foo" as affected by the security issue.
                   6230: 
                   6231: Entries should always be added at the bottom of the file.
                   6232: 
                   6233: When fixing packages, please modify the upper bound of the corresponding entry.
                   6234: To continue the previous example, if a fix was backported to version 1.1nb2,
1.206     wiz      6235: change the previous pattern to "foo>=1<1.1nb2".
1.205     wiz      6236: 
                   6237: To locally test a package version pattern against a PKGNAME you can use the 
                   6238: pkg_admin pmatch command.
                   6239: 
                   6240: The URL should be as permanent as possible and provide as much information
                   6241: about the issue as possible. CVE entries are preferred.
                   6242: 
                   6243: After committing that file, ask pkgsrc-security@NetBSD.org to update the file
                   6244: on ftp.NetBSD.org.
1.1       dsieger  6245: 
                   6246: After fixing the vulnerability by a patch, its PKGREVISION should be increased
                   6247: (this is of course not necessary if the problem is fixed by using a newer
1.32      wiz      6248: release of the software), and the pattern in the pkg-vulnerabilities file must
                   6249: be updated.
1.1       dsieger  6250: 
                   6251: Also, if the fix should be applied to the stable pkgsrc branch, be sure to
                   6252: submit a pullup request!
                   6253: 
                   6254: Binary packages already on ftp.NetBSD.org will be handled semi-automatically by
                   6255: a weekly cron job.
                   6256: 
1.205     wiz      6257: In case a security issue is disputed, please contact
                   6258: pkgsrc-security@NetBSD.org.
                   6259: 
1.154     rillig   6260: 21.1.10. How to handle incrementing versions when fixing an existing package
1.1       dsieger  6261: 
                   6262: When making fixes to an existing package it can be useful to change the version
                   6263: number in PKGNAME. To avoid conflicting with future versions by the original
                   6264: author, a "nb1", "nb2", ... suffix can be used on package versions by setting
                   6265: PKGREVISION=1 (2, ...). The "nb" is treated like a "." by the package tools.
                   6266: e.g.
                   6267: 
                   6268: DISTNAME=       foo-17.42
                   6269: PKGREVISION=    9
                   6270: 
                   6271: will result in a PKGNAME of "foo-17.42nb9". If you want to use the original
                   6272: value of PKGNAME without the "nbX" suffix, e.g. for setting DIST_SUBDIR, use
                   6273: PKGNAME_NOREV.
                   6274: 
                   6275: When a new release of the package is released, the PKGREVISION should be
                   6276: removed, e.g. on a new minor release of the above package, things should be
                   6277: like:
                   6278: 
                   6279: DISTNAME=       foo-17.43
                   6280: 
                   6281: PKGREVISION should be incremented for any non-trivial change in the resulting
                   6282: binary package. Without a PKGREVISION bump, someone with the previous version
                   6283: installed has no way of knowing that their package is out of date. Thus,
                   6284: changes without increasing PKGREVISION are essentially labeled "this is so
                   6285: trivial that no reasonable person would want to upgrade", and this is the rough
                   6286: test for when increasing PKGREVISION is appropriate. Examples of changes that
                   6287: do not merit increasing PKGREVISION are:
                   6288: 
1.14      jmcneill 6289:   * Changing HOMEPAGE, MAINTAINER, OWNER, or comments in Makefile.
1.1       dsieger  6290: 
                   6291:   * Changing build variables if the resulting binary package is the same.
                   6292: 
                   6293:   * Changing DESCR.
                   6294: 
                   6295:   * Adding PKG_OPTIONS if the default options don't change.
                   6296: 
                   6297: Examples of changes that do merit an increase to PKGREVISION include:
                   6298: 
                   6299:   * Security fixes
                   6300: 
                   6301:   * Changes or additions to a patch file
                   6302: 
                   6303:   * Changes to the PLIST
                   6304: 
1.12      weinem   6305:   * A dependency is changed or renamed.
                   6306: 
1.1       dsieger  6307: PKGREVISION must also be incremented when dependencies have ABI changes.
                   6308: 
1.154     rillig   6309: 21.1.11. Substituting variable text in the package files (the SUBST framework)
1.1       dsieger  6310: 
1.180     rillig   6311: When you want to replace the same text in multiple files, or multiple times in
                   6312: the same file, it is cumbersome to maintain a patch file for this. This is
                   6313: where the SUBST framework steps in. It provides an easy-to-use interface for
                   6314: replacing text in files. It just needs the following information:
1.172     rillig   6315: 
1.180     rillig   6316:   * In which phase of the package build cycle should the replacement happen?
1.172     rillig   6317: 
1.180     rillig   6318:   * In which files should the replacement happen?
1.172     rillig   6319: 
                   6320:   * Which text should be replaced with what?
                   6321: 
1.180     rillig   6322: This information is encoded in a block of SUBST variables. A minimal example
                   6323: is:
                   6324: 
                   6325: SUBST_CLASSES+=         paths
                   6326: SUBST_STAGE.paths=      pre-configure
                   6327: SUBST_FILES.paths=      src/*.c
                   6328: SUBST_SED.paths=        -e 's,/usr/local,${PREFIX},g'
                   6329: 
                   6330: Translated into English, it means: In the pre-configure stage (that is, after
                   6331: applying the patches from the patches/ directory and before running the
                   6332: configure script and the portability check), replace the text /usr/local with
                   6333: the content of the variable PREFIX.
                   6334: 
                   6335: Each SUBST block starts by appending an identifier to SUBST_CLASSES (note the +
                   6336: =). This identifier can be chosen freely by the package. If there should ever
                   6337: be duplicate identifiers, the pkgsrc infrastructure will catch this and fail
                   6338: early, so don't worry about name collisions.
                   6339: 
                   6340: Except for SUBST_CLASSES, all variables in a SUBST block are parameterized
                   6341: using this identifier. In the remainder of this section, these parameterized
                   6342: variables are written as SUBST_STAGE.*.
                   6343: 
                   6344: SUBST_CLASSES+=         paths
                   6345: SUBST_STAGE.paths=      pre-configure
                   6346: SUBST_MESSAGE.paths=    Fixing absolute paths.
                   6347: SUBST_FILES.paths=      src/*.c
                   6348: SUBST_FILES.paths+=     scripts/*.sh
                   6349: SUBST_SED.paths=        -e 's,"/usr/local,"${PREFIX},g'
                   6350: SUBST_SED.paths+=       -e 's,"/var/log,"${VARBASE}/log,g'
                   6351: SUBST_VARS.paths=       LOCALBASE PREFIX PKGVERSION
                   6352: 
                   6353: To get a complete picture about the SUBST substitutions, run bmake
                   6354: show-all-subst. If something doesn't work as expected, run pkglint on the
                   6355: package, which detects several typical mistakes surrounding the SUBST blocks.
                   6356: For any questions that might remain after this, have a look at mk/subst.mk.
                   6357: 
                   6358: 21.1.11.1. Choosing the time where the substitutions happen
                   6359: 
                   6360: The SUBST_STAGE.* is one of {pre,do,post}-
                   6361: {extract,patch,configure,build,test,install}. Of these, pre-configure is used
                   6362: most often, by far. The most popular stages are, in chronological order:
                   6363: 
                   6364: post-extract
                   6365: 
                   6366:     The substitutions are applied immediately after the distfiles are
                   6367:     extracted. Running bmake extract on the package will leave no traces of the
                   6368:     original files.
                   6369: 
                   6370:     When the substitution applies to files for which there is also a patch in
                   6371:     the patches/ directory, this means that the patches will be computed based
                   6372:     on the result of the substitution. When these patches are sent to the
                   6373:     upstream maintainer later, to be fixed in the upstream package, these
                   6374:     patches may no longer match what the upstream author is used to. Because of
                   6375:     this, pre-configure is often a better choice.
                   6376: 
                   6377: pre-configure
                   6378: 
                   6379:     The substitutions are applied after the patches from the patches/
                   6380:     directory. This makes it possible to run bmake patch on the package, after
                   6381:     which the patches can be edited using the tools pkgvi and mkpatches from
                   6382:     the pkgtools/pkgdiff package.
                   6383: 
                   6384:     When updating the patches, it is helpful to explicitly separate the bmake
                   6385:     patch from the bmake configure, and to only edit the patches between these
                   6386:     commands. Otherwise the substitutions from the SUBST block will end up in
                   6387:     the patch file. When this happens in really obvious ways, pkglint will
                   6388:     complain about patches that contain a hard-coded /usr/pkg instead of the
                   6389:     correct and intended @PREFIX@, but it can only detect these really obvious
                   6390:     cases.
                   6391: 
                   6392: do-configure
                   6393: 
                   6394:     This stage should only be used if the package defines a pre-configure
                   6395:     action itself, and the substitution must happen after that. Typical
                   6396:     examples are packages that use the pre-configure stage to regenerate the
                   6397:     GNU configure script from configure.ac.
                   6398: 
                   6399: post-configure
                   6400: 
                   6401:     This stage is used to fix up any mistakes by the configure stage.
                   6402: 
                   6403: pre-build
                   6404: 
                   6405:     This stage should only be used for substitutions that are clearly related
                   6406:     to building the package, not for fixing the configuration. Substitutions
                   6407:     for pathnames (such as replacing /usr/local with ${PREFIX}) or user names
                   6408:     (such as replacing @MY_USER@ with the actual username) belong in
                   6409:     pre-configure or post-configure instead.
                   6410: 
                   6411: post-build
                   6412: 
                   6413:     Just as with pre-build, this stage should only be used for substitutions
                   6414:     that are clearly related to building the package, not for fixing the
                   6415:     configuration. Substitutions for pathnames (such as replacing /usr/local
                   6416:     with ${PREFIX}) or user names (such as replacing @MY_USER@ with the actual
                   6417:     username) belong in pre-configure or post-configure instead.
                   6418: 
                   6419:     A typical use is to update pkg-config files to include the rpath compiler
                   6420:     options.
                   6421: 
                   6422: pre-install
                   6423: 
                   6424:     In general, the install phase should be as simple as possible. As with the
                   6425:     pre-build and post-build stages, it should not be used to fix pathnames or
                   6426:     user names, these belong in pre-configure instead. There are only few
                   6427:     legitimate use cases for applying substitutions in this stage.
                   6428: 
1.181     rillig   6429: 21.1.11.2. Choosing the files where the substitutions happen
1.180     rillig   6430: 
                   6431: The SUBST_FILES.* variable contains a list of filename patterns. These patterns
                   6432: are relative to WRKSRC since that is where most substitutions happen. A typical
                   6433: example is:
                   6434: 
                   6435: SUBST_FILES.path=       Makefile */Makefile */*/Makefile *.[ch]
                   6436: 
                   6437: The above patterns, especially the last, are quite broad. The SUBST
                   6438: implementation checks that each filename pattern that is mentioned here has an
                   6439: effect. For example, if none of the */*/Makefile files contains the patterns to
                   6440: be found and substituted, that filename pattern is redundant and should be left
1.181     rillig   6441: out. By default, the SUBST framework will complain with an error message. If
                   6442: the text to be substituted occurs in some of the files from a single pattern,
                   6443: but not in all of them, that is totally ok, and the SUBST framework will only
                   6444: print an INFO message for those files.
1.180     rillig   6445: 
                   6446: If there is a good reason for having redundant filename patterns, set
1.181     rillig   6447: SUBST_NOOP_OK.* to yes.
1.180     rillig   6448: 
                   6449: Another popular way of choosing the files for the substitutions is via a shell
                   6450: command, like this:
                   6451: 
1.181     rillig   6452: C_FILES_CMD=            cd ${WRKSRC} && ${FIND} . -name '*.c'
1.180     rillig   6453: SUBST_FILES.path=       ${C_FILES_CMD:sh}
                   6454: 
                   6455: The variable name C_FILES_CMD in this example is freely chosen and independent
                   6456: of the SUBST framework.
                   6457: 
                   6458: In this variant, the SUBST_FILES.* variable lists each file individually.
                   6459: Thereby chances are higher that there are filename patterns in which no
                   6460: substitution happens. Since the SUBST framework cannot know whether the
                   6461: filename patterns in SUBST_FILES.* have been explicitly listed in the Makefile
                   6462: (where any redundant filename pattern would be suspicious) or been generated by
                   6463: a shell command (in which redundant filename patterns are more likely and to be
                   6464: expected), it will complain about these redundant filename patterns. Therefore,
                   6465: SUBST blocks that use a shell command to generate the list of filename patterns
                   6466: often need to set SUBST_NOOP_OK.* to yes.
                   6467: 
                   6468: 21.1.11.3. Choosing what to substitute
                   6469: 
                   6470: In most cases, the substitutions are given using one or more sed(1) commands,
                   6471: like this:
                   6472: 
                   6473: SUBST_SED.path=         -e 's|/usr/local|${PREFIX}|g'
                   6474: 
                   6475: Each of the sed commands needs to be preceded by the -e option and should be
                   6476: specified on a line of its own, to avoid hiding short sed commands at the end
                   6477: of a line.
                   6478: 
                   6479: Since the sed commands often contain shell metacharacters as the separator (the
                   6480: | in the above example), it is common to enclose them in single quotes.
                   6481: 
                   6482: A common substitution is to replace placeholders of the form @VARNAME@ with
                   6483: their pkgsrc counterpart variable ${VARNAME}. A typical example is:
                   6484: 
                   6485: SUBST_VARS.path=        PREFIX
                   6486: 
1.181     rillig   6487: This type of substitutions is typically done by the GNU configure scripts
                   6488: during the do-configure stage, but in some cases these need to be overridden.
                   6489: The same pattern is also used when a package defines patches that replace
                   6490: previously hard-coded paths like /usr/local with a @PREFIX@ placeholder first,
                   6491: which then gets substituted by the actual ${PREFIX} in the pre-configure stage.
                   6492: In many of these cases, it works equally well to just use the SUBST framework
                   6493: to directly replace /usr/local with ${PREFIX}, thereby omitting the
                   6494: intermediate patch file.
1.180     rillig   6495: 
                   6496: If the above is not flexible enough, it is possible to not use sed at all for
                   6497: the substitution but to specify an entirely different command, like this:
                   6498: 
                   6499: SUBST_FILTER_CMD.path=  LC_ALL=C ${TR} -d '\r'
1.1       dsieger  6500: 
1.180     rillig   6501: This is used for the few remaining packages in which the distributed files use
                   6502: Windows-style line endings that need to be converted to UNIX-style line
                   6503: endings.
1.1       dsieger  6504: 
1.180     rillig   6505: 21.1.11.4. Other SUBST variables
1.172     rillig   6506: 
1.180     rillig   6507: When a SUBST block is applied during a package build, a message is logged. The
                   6508: default message is fine for most purposes but can be overridden by setting
                   6509: SUBST_MESSAGE.* to an individual message.
1.1       dsieger  6510: 
1.154     rillig   6511: 21.2. The fetch phase
1.1       dsieger  6512: 
1.154     rillig   6513: 21.2.1. Packages whose distfiles aren't available for plain downloading
1.1       dsieger  6514: 
                   6515: If you need to download from a dynamic URL you can set DYNAMIC_MASTER_SITES and
                   6516: a make fetch will call files/getsite.sh with the name of each file to download
                   6517: as an argument, expecting it to output the URL of the directory from which to
                   6518: download it. graphics/ns-cult3d is an example of this usage.
                   6519: 
                   6520: If the download can't be automated, because the user must submit personal
                   6521: information to apply for a password, or must pay for the source, or whatever,
                   6522: you can set FETCH_MESSAGE to a list of lines that are displayed to the user
                   6523: before aborting the build. Example:
                   6524: 
                   6525: FETCH_MESSAGE=  "Please download the files"
                   6526: FETCH_MESSAGE+= "    "${DISTFILES:Q}
                   6527: FETCH_MESSAGE+= "manually from "${MASTER_SITES:Q}"."
                   6528: 
1.154     rillig   6529: 21.2.2. How to handle modified distfiles with the 'old' name
1.1       dsieger  6530: 
                   6531: Sometimes authors of a software package make some modifications after the
                   6532: software was released, and they put up a new distfile without changing the
                   6533: package's version number. If a package is already in pkgsrc at that time, the
                   6534: checksum will no longer match. The contents of the new distfile should be
                   6535: compared against the old one before changing anything, to make sure the
                   6536: distfile was really updated on purpose, and that no trojan horse or so crept
                   6537: in. Please mention that the distfiles were compared and what was found in your
1.54      rodent   6538: commit message.
                   6539: 
                   6540: Then, the correct way to work around this is to set DIST_SUBDIR to a unique
1.109     wiz      6541: directory name, usually based on PKGNAME_NOREV (but take care with python or
                   6542: ruby packages, where PKGNAME includes a variable prefix). All DISTFILES and
                   6543: PATCHFILES for this package will be put in that subdirectory of the local
1.154     rillig   6544: distfiles directory. (See Section 21.1.10, "How to handle incrementing versions
1.109     wiz      6545: when fixing an existing package" for more details.) In case this happens more
                   6546: often, PKGNAME can be used (thus including the nbX suffix) or a date stamp can
                   6547: be appended, like ${PKGNAME_NOREV}-YYYYMMDD.
1.54      rodent   6548: 
                   6549: DIST_SUBDIR is also used when a distfile's name does not contain a version and
                   6550: the distfile is apt to change. In cases where the likelihood of this is very
                   6551: small, DIST_SUBDIR might not be required. Additionally, DIST_SUBDIR must not be
                   6552: removed unless the distfile name changes, even if a package is being moved or
                   6553: renamed.
                   6554: 
                   6555: Do not forget regenerating the distinfo file after that, since it contains the
                   6556: DIST_SUBDIR path in the filenames. Also, increase the PKGREVISION if the
                   6557: installed package is different. Furthermore, a mail to the package's authors
                   6558: seems appropriate telling them that changing distfiles after releases without
                   6559: changing the file names is not good practice.
1.1       dsieger  6560: 
1.154     rillig   6561: 21.2.3. Packages hosted on github.com
1.88      tnn      6562: 
1.90      tnn      6563: Helper methods exist for packages hosted on github.com which will often have
                   6564: distfile names that clash with other packages, for example 1.0.tar.gz. Use one
                   6565: of the three recipes from below:
1.88      tnn      6566: 
1.154     rillig   6567: 21.2.3.1. Fetch based on a tagged release
1.88      tnn      6568: 
1.189     bacon    6569: If your distfile URL looks similar to https://github.com/username/example/
                   6570: archive/v1.0.zip, then you are packaging a tagged release.
1.88      tnn      6571: 
1.189     bacon    6572: DISTNAME=       example-1.0
1.90      tnn      6573: MASTER_SITES=   ${MASTER_SITE_GITHUB:=username/}
1.189     bacon    6574: #GITHUB_PROJECT= example    # can be omitted if same as DISTNAME
1.90      tnn      6575: GITHUB_TAG=     v${PKGVERSION_NOREV}
1.88      tnn      6576: EXTRACT_SUFX=   .zip
                   6577: 
1.230     gutterid 6578: Here, DISTNAME combined with use of GITHUB_TAG leads the file fetching
                   6579: infrastructure to save the resulting file locally as example-1.0.zip.
                   6580: 
1.189     bacon    6581: 21.2.3.2. Fetch based on a specific commit before the first release
                   6582: 
                   6583: If your distfile looks similar to https://github.com/username/example/archive/
                   6584: 988881adc9fc3655077dc2d4d757d480b5ea0e11 and is from a commit before the first
                   6585: release, then set the package version to 0.0.0.N, where N is the number of
                   6586: commits to the repository, and set GITHUB_TAG to the commit hash. This will
                   6587: (almost) ensure that the first tagged release will have a version greater than
                   6588: this one so that package upgrades will function properly.
                   6589: 
                   6590: DISTNAME=       example-0.0.0.347
                   6591: MASTER_SITES=   ${MASTER_SITE_GITHUB:=username/}
                   6592: #GITHUB_PROJECT= example    # can be omitted if same as DISTNAME
                   6593: GITHUB_TAG=     988881adc9fc3655077dc2d4d757d480b5ea0e11
                   6594: 
                   6595: 21.2.3.3. Fetch based on a specific commit after a release
1.88      tnn      6596: 
1.189     bacon    6597: If your distfile looks similar to https://github.com/username/example/archive/
                   6598: 988881adc9fc3655077dc2d4d757d480b5ea0e11 and is from a commit after a release,
                   6599: then include the last release version and the commit count since that release
                   6600: in the package version and set GITHUB_TAG to the commit hash. The latest
                   6601: release and commit count are shown in the output of "git describe --tags":
                   6602: 
                   6603: # git clone https://github.com/username/example
                   6604: # cd example
                   6605: # git describe --tags
                   6606: 1.2.3-5-g988881a
1.88      tnn      6607: 
1.189     bacon    6608: DISTNAME=       example-1.2.3.5
                   6609: MASTER_SITES=   ${MASTER_SITE_GITHUB:=username/}
                   6610: #GITHUB_PROJECT= example    # can be omitted if same as DISTNAME
1.90      tnn      6611: GITHUB_TAG=     988881adc9fc3655077dc2d4d757d480b5ea0e11
1.88      tnn      6612: 
1.189     bacon    6613: 21.2.3.4. Fetch based on release
1.88      tnn      6614: 
1.189     bacon    6615: If your distfile URL looks similar to https://github.com/username/example/
                   6616: releases/download/rel-1.6/offensive-1.6.zip, then you are packaging a release.
1.88      tnn      6617: 
1.90      tnn      6618: DISTNAME=       offensive-1.6
1.88      tnn      6619: PKGNAME=        ${DISTNAME:S/offensive/proper/}
1.90      tnn      6620: MASTER_SITES=   ${MASTER_SITE_GITHUB:=username/}
1.189     bacon    6621: GITHUB_PROJECT= example
1.90      tnn      6622: GITHUB_RELEASE= rel-${PKGVERSION_NOREV} # usually just set this to ${DISTNAME}
                   6623: EXTRACT_SUFX=   .zip
1.88      tnn      6624: 
1.154     rillig   6625: 21.3. The configure phase
1.1       dsieger  6626: 
1.154     rillig   6627: 21.3.1. Shared libraries - libtool
1.1       dsieger  6628: 
                   6629: pkgsrc supports many different machines, with different object formats like
                   6630: a.out and ELF, and varying abilities to do shared library and dynamic loading
                   6631: at all. To accompany this, varying commands and options have to be passed to
                   6632: the compiler, linker, etc. to get the Right Thing, which can be pretty annoying
                   6633: especially if you don't have all the machines at your hand to test things. The
                   6634: devel/libtool pkg can help here, as it just "knows" how to build both static
                   6635: and dynamic libraries from a set of source files, thus being
                   6636: platform-independent.
                   6637: 
                   6638: Here's how to use libtool in a package in seven simple steps:
                   6639: 
                   6640:  1. Add USE_LIBTOOL=yes to the package Makefile.
                   6641: 
                   6642:  2. For library objects, use "${LIBTOOL} --mode=compile ${CC}" in place of "$
                   6643:     {CC}". You could even add it to the definition of CC, if only libraries are
                   6644:     being built in a given Makefile. This one command will build both PIC and
                   6645:     non-PIC library objects, so you need not have separate shared and
                   6646:     non-shared library rules.
                   6647: 
                   6648:  3. For the linking of the library, remove any "ar", "ranlib", and "ld
                   6649:     -Bshareable" commands, and instead use:
                   6650: 
                   6651:     ${LIBTOOL} --mode=link \
                   6652:         ${CC} -o ${.TARGET:.a=.la} \
                   6653:             ${OBJS:.o=.lo} \
                   6654:             -rpath ${PREFIX}/lib \
                   6655:             -version-info major:minor
                   6656: 
                   6657:     Note that the library is changed to have a .la extension, and the objects
                   6658:     are changed to have a .lo extension. Change OBJS as necessary. This
                   6659:     automatically creates all of the .a, .so.major.minor, and ELF symlinks (if
                   6660:     necessary) in the build directory. Be sure to include "-version-info",
                   6661:     especially when major and minor are zero, as libtool will otherwise strip
                   6662:     off the shared library version.
                   6663: 
                   6664:     From the libtool manual:
                   6665: 
                   6666:     So, libtool library versions are described by three integers:
                   6667: 
                   6668:     CURRENT
                   6669:     The most recent interface number that this library implements.
                   6670: 
                   6671:     REVISION
                   6672:     The implementation number of the CURRENT interface.
                   6673: 
                   6674:     AGE
                   6675:     The difference between the newest and oldest interfaces that
                   6676:     this library implements.  In other words, the library implements
                   6677:     all the interface numbers in the range from number `CURRENT -
                   6678:     AGE' to `CURRENT'.
                   6679: 
                   6680:     If two libraries have identical CURRENT and AGE numbers, then the
                   6681:     dynamic linker chooses the library with the greater REVISION number.
                   6682: 
                   6683:     The "-release" option will produce different results for a.out and ELF
1.25      wiz      6684:     (excluding symlinks) in only one case. An ELF library of the form "
                   6685:     libfoo-release.so.x.y" will have a symlink of "libfoo.so.x.y" on an a.out
1.1       dsieger  6686:     platform. This is handled automatically.
                   6687: 
                   6688:     The "-rpath argument" is the install directory of the library being built.
                   6689: 
                   6690:     In the PLIST, include only the .la file, the other files will be added
                   6691:     automatically.
                   6692: 
                   6693:  4. When linking shared object (.so) files, i.e. files that are loaded via
                   6694:     dlopen(3), NOT shared libraries, use "-module -avoid-version" to prevent
                   6695:     them getting version tacked on.
                   6696: 
                   6697:     The PLIST file gets the foo.so entry.
                   6698: 
                   6699:  5. When linking programs that depend on these libraries before they are
                   6700:     installed, preface the cc(1) or ld(1) line with "${LIBTOOL} --mode=link",
                   6701:     and it will find the correct libraries (static or shared), but please be
                   6702:     aware that libtool will not allow you to specify a relative path in -L
                   6703:     (such as "-L../somelib"), because it expects you to change that argument to
                   6704:     be the .la file. e.g.
                   6705: 
                   6706:     ${LIBTOOL} --mode=link ${CC} -o someprog -L../somelib -lsomelib
                   6707: 
                   6708:     should be changed to:
                   6709: 
                   6710:     ${LIBTOOL} --mode=link ${CC} -o someprog ../somelib/somelib.la
                   6711: 
                   6712:     and it will do the right thing with the libraries.
                   6713: 
                   6714:  6. When installing libraries, preface the install(1) or cp(1) command with "$
                   6715:     {LIBTOOL} --mode=install", and change the library name to .la. e.g.
                   6716: 
1.23      jakllsch 6717:     ${LIBTOOL} --mode=install ${BSD_INSTALL_LIB} ${SOMELIB:.a=.la} ${PREFIX}/lib
1.1       dsieger  6718: 
                   6719:     This will install the static .a, shared library, any needed symlinks, and
                   6720:     run ldconfig(8).
                   6721: 
                   6722:  7. In your PLIST, include only the .la file (this is a change from previous
                   6723:     behaviour).
                   6724: 
1.154     rillig   6725: 21.3.2. Using libtool on GNU packages that already support libtool
1.1       dsieger  6726: 
                   6727: Add USE_LIBTOOL=yes to the package Makefile. This will override the package's
                   6728: own libtool in most cases. For older libtool using packages, libtool is made by
                   6729: ltconfig script during the do-configure step; you can check the libtool script
                   6730: location by doing make configure; find work*/ -name libtool.
                   6731: 
                   6732: LIBTOOL_OVERRIDE specifies which libtool scripts, relative to WRKSRC, to
                   6733: override. By default, it is set to "libtool */libtool */*/libtool". If this
                   6734: does not match the location of the package's libtool script(s), set it as
                   6735: appropriate.
                   6736: 
                   6737: If you do not need *.a static libraries built and installed, then use
                   6738: SHLIBTOOL_OVERRIDE instead.
                   6739: 
                   6740: If your package makes use of the platform-independent library for loading
                   6741: dynamic shared objects, that comes with libtool (libltdl), you should include
                   6742: devel/libltdl/buildlink3.mk.
                   6743: 
                   6744: Some packages use libtool incorrectly so that the package may not work or build
                   6745: in some circumstances. Some of the more common errors are:
                   6746: 
                   6747:   * The inclusion of a shared object (-module) as a dependent library in an
                   6748:     executable or library. This in itself isn't a problem if one of two things
                   6749:     has been done:
                   6750: 
                   6751:      1. The shared object is named correctly, i.e. libfoo.la, not foo.la
                   6752: 
                   6753:      2. The -dlopen option is used when linking an executable.
                   6754: 
                   6755:   * The use of libltdl without the correct calls to initialisation routines.
                   6756:     The function lt_dlinit() should be called and the macro
                   6757:     LTDL_SET_PRELOADED_SYMBOLS included in executables.
                   6758: 
1.154     rillig   6759: 21.3.3. GNU Autoconf/Automake
1.1       dsieger  6760: 
                   6761: If a package needs GNU autoconf or automake to be executed to regenerate the
1.223     nia      6762: configure script and Makefile.in makefile templates from configure.ac and
                   6763: Makefile.am, then they should be executed in a pre-configure target:
1.1       dsieger  6764: 
1.223     nia      6765: USE_TOOLS+=     autoconf automake autoreconf
                   6766: GNU_CONFIGURE=  yes
1.1       dsieger  6767: ...
                   6768: 
                   6769: pre-configure:
1.223     nia      6770:         set -e; cd ${WRKSRC} && autoreconf -fi
1.1       dsieger  6771: ...
                   6772: 
1.223     nia      6773: Packages which use GNU Automake will sometimes require GNU Make (gmake in
                   6774: USE_TOOLS), but not always. Note that autoreconf only needs to be executed if
                   6775: configure.ac or Makefiles are modified, or configure is not present.
1.1       dsieger  6776: 
                   6777: There are times when the configure process makes additional changes to the
                   6778: generated files, which then causes the build process to try to re-execute the
                   6779: automake sequence. This is prevented by touching various files in the configure
                   6780: stage. If this causes problems with your package you can set AUTOMAKE_OVERRIDE=
                   6781: NO in the package Makefile.
                   6782: 
1.223     nia      6783: 21.3.4. Meson / ninja
                   6784: 
                   6785: Packages using Meson to configure need to include:
                   6786: 
                   6787: .include "../../devel/meson/build.mk"
                   6788: 
                   6789: In nearly all cases (any program with dependencies), pkg-config needs to be
                   6790: added to USE_TOOLS. If the package installs translation files for non-English
                   6791: languages, also add msgfmt and xgettext:
                   6792: 
                   6793: USE_TOOLS+=     pkg-config msgfmt xgettext
                   6794: 
                   6795: If any options need to be passed to Meson, use MESON_ARGS instead of
                   6796: CONFIGURE_ARGS:
                   6797: 
                   6798: MESON_ARGS+=    -Dx11=false
                   6799: 
1.154     rillig   6800: 21.4. Programming languages
1.1       dsieger  6801: 
1.154     rillig   6802: 21.4.1. C, C++, and Fortran
1.1       dsieger  6803: 
1.223     nia      6804: Compilers for the C and C++ languages comes with the NetBSD base system. By
                   6805: default, pkgsrc assumes that a package is written in C and will hide all other
                   6806: compilers (via the wrapper framework, see Chapter 18, Buildlink methodology).
1.1       dsieger  6807: 
                   6808: To declare which language's compiler a package needs, set the USE_LANGUAGES
1.212     wiz      6809: variable. Allowed values currently are:
                   6810: 
                   6811:         c99, c++, c++03, gnu++03, c++0x, gnu++0x, c++11, gnu++11,
                   6812:         c++14, gnu++14, c++17, gnu++17, c++20, gnu++20, fortran,
                   6813:         fortran77, java, objc, obj-c++, and ada.
                   6814: 
                   6815: 
                   6816: (and any combination). The default is "c". Packages using GNU configure
                   6817: scripts, even if written in C++, usually need a C compiler for the configure
                   6818: phase.
1.1       dsieger  6819: 
1.223     nia      6820: To express a general requirement on a specific C or C++ version, normally only
                   6821: GCC_REQD needs to be set. For example, GCC 7 includes support for C++17, so if
                   6822: the package uses C++17 it should specify:
                   6823: 
                   6824:         GCC_REQD+=      7
                   6825: 
                   6826: 
                   6827: Language variants like c++11 for USE_LANGUAGES should only be specified if the
                   6828: package does not explicitly set -std=... when compiling (i.e. the package
                   6829: assumes the compiler defaults to C++11 or some other standard). This is usually
                   6830: a bug in the upstream build system.
                   6831: 
                   6832: GCC version 5 includes support for C++14, while GCC 4.7 includes more-or-less
                   6833: complete support for C++11. For more information, consult GCC's own
                   6834: documentation on programming language support.
                   6835: 
1.154     rillig   6836: 21.4.2. Java
1.1       dsieger  6837: 
                   6838: If a program is written in Java, use the Java framework in pkgsrc. The package
                   6839: must include ../../mk/java-vm.mk. This Makefile fragment provides the following
                   6840: variables:
                   6841: 
                   6842:   * USE_JAVA defines if a build dependency on the JDK is added. If USE_JAVA is
                   6843:     set to "run", then there is only a runtime dependency on the JDK. The
                   6844:     default is "yes", which also adds a build dependency on the JDK.
                   6845: 
                   6846:   * Set USE_JAVA2 to declare that a package needs a Java2 implementation. The
                   6847:     supported values are "yes", "1.4", and "1.5". "yes" accepts any Java2
                   6848:     implementation, "1.4" insists on versions 1.4 or above, and "1.5" only
                   6849:     accepts versions 1.5 or above. This variable is not set by default.
                   6850: 
1.25      wiz      6851:   * PKG_JAVA_HOME is automatically set to the runtime location of the used Java
                   6852:     implementation dependency. It may be used to set JAVA_HOME to a good value
                   6853:     if the program needs this variable to be defined.
                   6854: 
1.205     wiz      6855: 21.4.3. Go
                   6856: 
                   6857: If a program is written in Go and has any dependencies on other Go modules,
                   6858: have the package include ../../lang/go/go-module.mk.
                   6859: 
                   6860:  1. Generate a list of those dependencies with make clean && make patch && make
                   6861:     show-go-modules > go-modules.mk.
                   6862: 
1.223     nia      6863:  2. Prepend .include "go-modules.mk" to any other .includes.
                   6864: 
                   6865:  3. Incorporate these modules in distinfo with make makesum.
1.205     wiz      6866: 
1.223     nia      6867: 21.4.4. Rust
1.205     wiz      6868: 
1.223     nia      6869: If a program is written in Rust and uses Cargo to build, have the package
                   6870: include ../../lang/rust/cargo.mk.
1.205     wiz      6871: 
1.223     nia      6872:  1. Generate a list of those dependencies with make CARGO_ARGS="build
                   6873:     --release" build && make print-cargo-depends > cargo-depends.mk.
1.205     wiz      6874: 
1.223     nia      6875:  2. Prepend .include "cargo-depends.mk" to any other .includes.
1.205     wiz      6876: 
                   6877:  3. Incorporate these modules in distinfo with make makesum.
                   6878: 
1.223     nia      6879: 21.4.5. Packages containing Perl scripts
1.1       dsieger  6880: 
1.203     nia      6881: If your package contains interpreted Perl scripts, add "perl" to the USE_TOOLS
1.1       dsieger  6882: variable and set REPLACE_PERL to ensure that the proper interpreter path is
                   6883: set. REPLACE_PERL should contain a list of scripts, relative to WRKSRC, that
1.74      wiz      6884: you want adjusted. Every occurrence of */bin/perl in a she-bang line will be
1.210     gutterid 6885: replaced with the full path to the Perl executable.
1.1       dsieger  6886: 
1.210     gutterid 6887: If a particular version of Perl is needed, set the PERL5_REQD variable to the
1.1       dsieger  6888: version number. The default is "5.0".
                   6889: 
1.203     nia      6890: See Section 21.6.6, "Packages installing Perl modules" for information about
1.210     gutterid 6891: handling Perl modules.
                   6892: 
                   6893: There is also the REPLACE_PERL6 variable for the language now known as Raku.
1.1       dsieger  6894: 
1.223     nia      6895: 21.4.6. Packages containing shell scripts
1.41      wiz      6896: 
                   6897: REPLACE_SH, REPLACE_BASH, REPLACE_CSH, and REPLACE_KSH can be used to replace
1.225     gutterid 6898: shell she-bangs in files. Please use the appropriate one, preferring REPLACE_SH
                   6899: when this shell is sufficient. Each should contain a list of scripts, relative
                   6900: to WRKSRC, that you want adjusted. Every occurrence of the matching shell in a
                   6901: she-bang line will be replaced with the full path to the shell executable. When
                   6902: using REPLACE_BASH, don't forget to add bash to USE_TOOLS.
1.41      wiz      6903: 
1.223     nia      6904: 21.4.7. Other programming languages
1.1       dsieger  6905: 
1.210     gutterid 6906: There are further similar REPLACE variables available, e.g., REPLACE_AWK for
                   6907: packages containing awk scripts, and REPLACE_R for R. These two, like the
1.211     gutterid 6908: others noted above, have their actions defined centrally in mk/configure/
                   6909: replace-interpreter.mk. Other languages define the actions of these variables
                   6910: within their own dedicated part of the tree, e.g., REPLACE_PHP is actioned in
                   6911: lang/php/phpversion.mk, and REPLACE_PYTHON is actioned in lang/python/
                   6912: application.mk. For other languages, consult the mk files found within their
1.216     gutterid 6913: specific directories (the naming convention varies), or check the list found in
                   6914: Appendix E, Help topics.
1.210     gutterid 6915: 
                   6916: Currently, special handling for other languages varies in pkgsrc. If a compiler
                   6917: package provides a buildlink3.mk file, include that, otherwise just add a
                   6918: (build) dependency on the appropriate compiler package.
1.1       dsieger  6919: 
1.154     rillig   6920: 21.5. The build phase
1.1       dsieger  6921: 
                   6922: The most common failures when building a package are that some platforms do not
                   6923: provide certain header files, functions or libraries, or they provide the
                   6924: functions in a library that the original package author didn't know. To work
                   6925: around this, you can rewrite the source code in most cases so that it does not
                   6926: use the missing functions or provides a replacement function.
                   6927: 
1.154     rillig   6928: 21.5.1. Compiling C and C++ code conditionally
1.1       dsieger  6929: 
                   6930: If a package already comes with a GNU configure script, the preferred way to
                   6931: fix the build failure is to change the configure script, not the code. In the
                   6932: other cases, you can utilize the C preprocessor, which defines certain macros
                   6933: depending on the operating system and hardware architecture it compiles for.
                   6934: These macros can be queried using for example #if defined(__i386). Almost every
                   6935: operating system, hardware architecture and compiler has its own macro. For
                   6936: example, if the macros __GNUC__, __i386__ and __NetBSD__ are all defined, you
                   6937: know that you are using NetBSD on an i386 compatible CPU, and your compiler is
                   6938: GCC.
                   6939: 
                   6940: The list of the following macros for hardware and operating system depends on
                   6941: the compiler that is used. For example, if you want to conditionally compile
                   6942: code on Solaris, don't use __sun__, as the SunPro compiler does not define it.
                   6943: Use __sun instead.
                   6944: 
1.154     rillig   6945: 21.5.1.1. C preprocessor macros to identify the operating system
1.1       dsieger  6946: 
1.223     nia      6947: To distinguish between specific NetBSD versions, you should use the following
                   6948: code.
                   6949: 
                   6950: #ifdef __NetBSD__
                   6951: #include <sys/param.h>
                   6952: #if __NetBSD_Prereq__(9,99,17)
                   6953: /* use a newer feature */
                   6954: #else
                   6955: /* older code */
                   6956: #endif
                   6957: #endif
                   6958: 
                   6959: #ifndef _WIN32
                   6960: /* Unix-like specific code */
                   6961: #endif
                   6962: 
1.1       dsieger  6963: To distinguish between 4.4 BSD-derived systems and the rest of the world, you
                   6964: should use the following code.
                   6965: 
                   6966: #include <sys/param.h>
                   6967: #if (defined(BSD) && BSD >= 199306)
                   6968: /* BSD-specific code goes here */
                   6969: #else
                   6970: /* non-BSD-specific code goes here */
                   6971: #endif
                   6972: 
1.223     nia      6973: You can also test for the following macros:
1.1       dsieger  6974: 
1.46      obache   6975: Cygwin      __CYGWIN__
                   6976: DragonFly   __DragonFly__
1.1       dsieger  6977: FreeBSD     __FreeBSD__
1.46      obache   6978: Haiku       __HAIKU__
1.1       dsieger  6979: Interix     __INTERIX
                   6980: IRIX        __sgi (TODO: get a definite source for this)
1.223     nia      6981: Linux       __linux
1.83      dholland 6982: Mac OS X    __APPLE__
1.46      obache   6983: MirBSD      __MirBSD__ (__OpenBSD__ is also defined)
                   6984: Minix3      __minix
1.1       dsieger  6985: NetBSD      __NetBSD__
                   6986: OpenBSD     __OpenBSD__
                   6987: Solaris     sun, __sun
                   6988: 
1.154     rillig   6989: 21.5.1.2. C preprocessor macros to identify the hardware architecture
1.1       dsieger  6990: 
                   6991: i386        i386, __i386, __i386__
1.223     nia      6992: x86-64      __amd64__, __x86_64__
                   6993: ARM         __arm__
1.1       dsieger  6994: MIPS        __mips
                   6995: SPARC       sparc, __sparc
1.223     nia      6996: PowerPC     __powerpc
1.1       dsieger  6997: 
1.154     rillig   6998: 21.5.1.3. C preprocessor macros to identify the compiler
1.1       dsieger  6999: 
                   7000: GCC         __GNUC__ (major version), __GNUC_MINOR__
                   7001: MIPSpro     _COMPILER_VERSION (0x741 for MIPSpro 7.41)
                   7002: SunPro      __SUNPRO_C (0x570 for Sun C 5.7)
                   7003: SunPro C++  __SUNPRO_CC (0x580 for Sun C++ 5.8)
                   7004: 
1.154     rillig   7005: 21.5.2. How to handle compiler bugs
1.1       dsieger  7006: 
                   7007: Some source files trigger bugs in the compiler, based on combinations of
                   7008: compiler version and architecture and almost always relation to optimisation
                   7009: being enabled. Common symptoms are gcc internal errors or never finishing
                   7010: compiling a file.
                   7011: 
                   7012: Typically, a workaround involves testing the MACHINE_ARCH and compiler version,
1.87      tnn      7013: disabling optimisation for that combination of file, MACHINE_ARCH and compiler.
                   7014: 
                   7015: This used to be a big problem in the past, but is rarely needed now as compiler
                   7016: technology has matured. If you still need to add a compiler specific
                   7017: workaround, please do so in the file hacks.mk and describe the symptom and
                   7018: compiler version as detailed as possible.
1.1       dsieger  7019: 
1.172     rillig   7020: 21.5.3. No such file or directory
                   7021: 
                   7022: Compilation sometimes fails with an error message like this:
                   7023: 
                   7024: .../x11/gtk3/work/gtk+-3.24.12/gdk/gdktypes.h:35:10:
                   7025:     fatal error: pango/pango.h: No such file or directory
                   7026: 
                   7027: The proper way to fix this problem depends on the type of the header, which is
                   7028: described in the following sections.
                   7029: 
                   7030: 21.5.3.1. Headers from other packages
                   7031: 
                   7032: If the header name looks like it comes from a different package, that other
                   7033: package should be included via the buildlink3 framework.
                   7034: 
                   7035: First, look whether the header is somewhere in the buildlink3 directory below
                   7036: WRKDIR. In the above case of the missing Pango header:
                   7037: 
                   7038: $ find work/.buildlink/ -print | grep -F pango/pango.h
                   7039: 
                   7040: In the case of Pango, the output is:
                   7041: 
                   7042: work/.buildlink/include/pango-1.0/pango/pango.h
                   7043: 
                   7044: If the pango/pango.h file were placed directly in the .buildlink directory, it
                   7045: would have been found automatically. There is an extra pango-1.0 path component
                   7046: though, which means that the compiler command line must contain an option of
                   7047: the form -I${BUILDLINK3_PREFIX.pango}/include/pango-1.0. In most cases this
                   7048: option is generated by the configure script, which can be examined using:
                   7049: 
                   7050: $ $ grep -o '[-]I[^[:space:]]*/pango[^[:space:]]*' work/*/Makefile
                   7051: -I/usr/pkg/include/pango-1.0
                   7052: -I/usr/pkg/include/pango-1.0
                   7053: -I/usr/pkg/include/pango-1.0
                   7054: -I/usr/pkg/include/pango-1.0
                   7055: -I/usr/pkg/include/pango-1.0
                   7056: 
                   7057: This looks good. These options are transformed by the buildlink wrapper to
                   7058: refer to the correct path inside work/.buildlink.
                   7059: 
                   7060: Since the compilation fails though, examine the compiler command lines in work
                   7061: /.work.log to see whether the -I option is included in the particular command
                   7062: line.
                   7063: 
                   7064: To further analyze the situation, run bmake build-env, which sets up an
                   7065: interactive, realistic environment including all the pkgsrc wrapper commands
                   7066: and environment variables. From there, try to compile some simple example
                   7067: programs that use the header.
                   7068: 
                   7069: 21.5.3.2. Headers generated during the build
                   7070: 
                   7071: If the name of the header seems to come from the package itself, and if the
                   7072: build is run with parallel jobs, the package may have some undeclared
                   7073: dependencies between the .c and the .h files, and a C file is compiled before
                   7074: its required header is generated.
                   7075: 
                   7076: To see whether the build runs with parallel jobs, run bmake show-all-build |
                   7077: grep JOBS. Its output looks like this:
                   7078: 
                   7079:   usr   MAKE_JOBS=              7
                   7080:   pkg   MAKE_JOBS_SAFE          # undefined
                   7081:   def   _MAKE_JOBS_N=           7
                   7082: 
                   7083: In this case the pkgsrc user has asked pkgsrc to build packages with 7 jobs in
                   7084: parallel (MAKE_JOBS). The package could have disabled parallel builds by
                   7085: setting MAKE_JOBS_SAFE to no, but in this case it hasn't.
                   7086: 
                   7087: To see whether the build failure is caused by parallel builds, first save the
                   7088: exact error message and a bit of context, maybe you need it later for reporting
                   7089: a bug. Next, run:
                   7090: 
                   7091: MAKE_JOBS_SAFE=no bmake clean build
                   7092: 
                   7093: If that succeeds, file a bug report against the pkgsrc package, including the
                   7094: exact error message and the contents of your mk.conf file.
                   7095: 
1.173     rillig   7096: 21.5.3.3. Symlinks
                   7097: 
                   7098: Pkgsrc does not work reliably if any of LOCALBASE, VARBASE or WRKDIR contains a
                   7099: symlink. Since 2019Q2, the pkgsrc bootstrap program prevents installing pkgsrc
                   7100: in symlink-based directories. Existing pkgsrc installations are not checked for
                   7101: symlinks though.
                   7102: 
                   7103: The "No such file or directory" error messages are a typical symptom of
                   7104: symlinks, and it's quite difficult to find out that this is the actual cause.
                   7105: 
                   7106: 21.5.3.4. Stale working directories
                   7107: 
                   7108: When building a hierarchy of packages, it may happen that one package is built
                   7109: and then pkgsrc is updated. This situation can provoke various hard to diagnose
                   7110: build errors. To clean up the situation:
                   7111: 
1.223     nia      7112: $ (cd ../../ && cat mk/bsd.pkg.mk >/dev/null && rm -rf */*/work)
1.173     rillig   7113: 
1.223     nia      7114: (The only purpose of the bsd.pkg.mk is to prevent running this command in the
                   7115: wrong directory.)
1.173     rillig   7116: 
                   7117: If you have set WRKOBJDIR in mk.conf, remove that directory as well.
                   7118: 
                   7119: 21.5.3.5. Other possible reasons
                   7120: 
                   7121: On platforms other than BSD, third-party packages are installed in /usr/
                   7122: include, together with the base system. This means that pkgsrc cannot
                   7123: distinguish between headers provided by the base system (which it needs) and
                   7124: headers from third-party packages (which are often included in pkgsrc as well).
                   7125: This can lead to subtle version mismatches.
                   7126: 
                   7127: In pkgsrc installations that have been active for several years, it may happen
                   7128: that some files are manually deleted. To exclude this unlikely reason, run 
                   7129: pkg_admin check.
                   7130: 
                   7131: It may help to run pkg_admin rebuild-tree to check/fix dependencies.
                   7132: 
                   7133: If all of the above doesn't help, see Chapter 2, Getting help for contact
                   7134: information. Be prepared to describe what you have tried so far and what any
                   7135: error messages were.
                   7136: 
1.172     rillig   7137: 21.5.4. Undefined reference to "..."
1.1       dsieger  7138: 
                   7139: This error message often means that a package did not link to a shared library
                   7140: it needs. The following functions are known to cause this error message over
                   7141: and over.
                   7142: 
                   7143: +-----------------------------------------------------+
                   7144: |        Function         |Library |Affected platforms|
                   7145: |-------------------------+--------+------------------|
                   7146: |accept, bind, connect    |-lsocket|Solaris           |
                   7147: |-------------------------+--------+------------------|
                   7148: |crypt                    |-lcrypt |DragonFly, NetBSD |
                   7149: |-------------------------+--------+------------------|
                   7150: |dlopen, dlsym            |-ldl    |Linux             |
                   7151: |-------------------------+--------+------------------|
                   7152: |gethost*                 |-lnsl   |Solaris           |
                   7153: |-------------------------+--------+------------------|
                   7154: |inet_aton                |-lresolv|Solaris           |
                   7155: |-------------------------+--------+------------------|
                   7156: |nanosleep, sem_*, timer_*|-lrt    |Solaris           |
                   7157: |-------------------------+--------+------------------|
                   7158: |openpty                  |-lutil  |Linux             |
                   7159: +-----------------------------------------------------+
                   7160: 
1.223     nia      7161: To fix these linker errors, it is often sufficient to add LIBS.OperatingSystem+
                   7162: = -lfoo to the package Makefile and then run bmake clean; bmake.
1.1       dsieger  7163: 
1.223     nia      7164: 21.5.4.1. The SunPro compiler and inline functions
1.1       dsieger  7165: 
                   7166: When you are using the SunPro compiler, there is another possibility. That
                   7167: compiler cannot handle the following code:
                   7168: 
                   7169: extern int extern_func(int);
                   7170: 
                   7171: static inline int
                   7172: inline_func(int x)
                   7173: {
                   7174:         return extern_func(x);
                   7175: }
                   7176: 
                   7177: int main(void)
                   7178: {
                   7179:         return 0;
                   7180: }
                   7181: 
                   7182: It generates the code for inline_func even if that function is never used. This
                   7183: code then refers to extern_func, which can usually not be resolved. To solve
                   7184: this problem you can try to tell the package to disable inlining of functions.
                   7185: 
1.228     gutterid 7186: 21.5.4.2. Missing atomic functions
                   7187: 
                   7188: When building for older machine architectures (e.g., i386, PowerPC), builds may
                   7189: fail because the package expects modern 64-bit atomic functions which the
                   7190: underlying hardware either doesn't support, or will only support with specific
                   7191: compiler flags. This is generally handled via inclusion of mk/atomic64.mk.
                   7192: 
1.172     rillig   7193: 21.5.5. Running out of memory
1.1       dsieger  7194: 
                   7195: Sometimes packages fail to build because the compiler runs into an operating
                   7196: system specific soft limit. With the UNLIMIT_RESOURCES variable pkgsrc can be
1.223     nia      7197: told to unlimit the resources. The allowed values are any combination of "
                   7198: cputime", "datasize", "memorysize", "stacksize" and "virtualsize". Setting this
                   7199: variable is similar to running the shell builtin ulimit command to raise the
                   7200: maximum data segment size or maximum stack size of a process, respectively, to
                   7201: their hard limits.
1.1       dsieger  7202: 
1.154     rillig   7203: 21.6. The install phase
1.1       dsieger  7204: 
1.154     rillig   7205: 21.6.1. Creating needed directories
1.1       dsieger  7206: 
                   7207: The BSD-compatible install supplied with some operating systems cannot create
                   7208: more than one directory at a time. As such, you should call ${INSTALL_*_DIR}
                   7209: like this:
                   7210: 
                   7211: ${INSTALL_DATA_DIR} ${PREFIX}/dir1
                   7212: ${INSTALL_DATA_DIR} ${PREFIX}/dir2
                   7213: 
1.223     nia      7214: Instead of running the install commands directly, you can also append "dir1
                   7215: dir2" to the INSTALLATION_DIRS variable, which will automatically do the right
                   7216: thing.
1.1       dsieger  7217: 
1.154     rillig   7218: 21.6.2. Where to install documentation
1.1       dsieger  7219: 
                   7220: In general, documentation should be installed into ${PREFIX}/share/doc/$
1.223     nia      7221: {PKGBASE} or ${PREFIX}/share/doc/${PKGNAME_NOREV} (the latter includes the
                   7222: version number of the package).
1.1       dsieger  7223: 
                   7224: Many modern packages using GNU autoconf allow to set the directory where HTML
                   7225: documentation is installed with the "--with-html-dir" option. Sometimes using
                   7226: this flag is needed because otherwise the documentation ends up in ${PREFIX}/
1.223     nia      7227: share/doc/html or other places. In pkgsrc, the HTML documentation should go
                   7228: into the package-specific directory, just like any other documentation.
1.1       dsieger  7229: 
                   7230: An exception to the above is that library API documentation generated with the
                   7231: textproc/gtk-doc tools, for use by special browsers (devhelp) should be left at
                   7232: their default location, which is ${PREFIX}/share/gtk-doc. Such documentation
                   7233: can be recognized from files ending in .devhelp or .devhelp2. (It is also
                   7234: acceptable to install such files in ${PREFIX}/share/doc/${PKGBASE} or ${PREFIX}
                   7235: /share/doc/${PKGNAME}; the .devhelp* file must be directly in that directory
                   7236: then, no additional subdirectory level is allowed in this case. This is usually
                   7237: achieved by using "--with-html-dir=${PREFIX}/share/doc". ${PREFIX}/share/
                   7238: gtk-doc is preferred though.)
                   7239: 
1.154     rillig   7240: 21.6.3. Installing highscore files
1.1       dsieger  7241: 
                   7242: Certain packages, most of them in the games category, install a score file that
                   7243: allows all users on the system to record their highscores. In order for this to
                   7244: work, the binaries need to be installed setgid and the score files owned by the
1.36      wiz      7245: appropriate group and/or owner (traditionally the "games" user/group). Set
                   7246: USE_GAMESGROUP to yes to support this. The following variables, documented in
                   7247: more detail in mk/defaults/mk.conf, control this behaviour: GAMEDATAMODE,
1.100     leot     7248: GAMEDIRMODE, GAMES_GROUP, GAMEMODE, GAME_USER. Other useful variables are:
                   7249: GAMEDIR_PERMS, GAMEDATA_PERMS and SETGID_GAMES_PERMS.
                   7250: 
                   7251: An example that illustrates some of the variables described above is games/
                   7252: moon-buggy. OWN_DIRS_PERMS is used to properly set directory permissions of the
                   7253: directory where the scorefile is saved, REQD_FILES_PERMS is used to create a
                   7254: dummy scorefile (mbscore) with the proper permissions and SPECIAL_PERMS is used
                   7255: to install setgid the game binary:
                   7256: 
                   7257: USE_GAMESGROUP=         yes
                   7258: 
                   7259: BUILD_DEFS+=            VARBASE
                   7260: 
                   7261: OWN_DIRS_PERMS+=        ${VARBASE}/games/moon-buggy ${GAMEDIR_PERMS}
                   7262: REQD_FILES_PERMS+=      /dev/null ${VARBASE}/games/moon-buggy/mbscore ${GAMEDATA_PERMS}
                   7263: SPECIAL_PERMS+=         ${PREFIX}/bin/moon-buggy ${SETGID_GAMES_PERMS}
                   7264: 
                   7265: Various INSTALL_* variables are also available: INSTALL_GAME to install setgid
                   7266: game binaries, INSTALL_GAME_DIR to install game directories that are needed to
                   7267: be accessed by setgid games and INSTALL_GAME_DATA to install scorefiles.
1.1       dsieger  7268: 
1.14      jmcneill 7269: A package should therefore never hard code file ownership or access permissions
1.100     leot     7270: but rely on *_PERMS as described above or alternatively on INSTALL_GAME,
                   7271: INSTALL_GAME_DATA and INSTALL_GAME_DIR to set these correctly.
1.1       dsieger  7272: 
1.154     rillig   7273: 21.6.4. Adding DESTDIR support to packages
1.4       rillig   7274: 
1.14      jmcneill 7275: DESTDIR support means that a package installs into a staging directory, not the
                   7276: final location of the files. Then a binary package is created which can be used
                   7277: for installation as usual. There are two ways: Either the package must install
1.25      wiz      7278: as root ("destdir") or the package can install as non-root user ("user-destdir"
                   7279: ).
1.14      jmcneill 7280: 
1.113     leot     7281:   * PKG_DESTDIR_SUPPORT has to be set to "destdir" or "user-destdir". By
                   7282:     default PKG_DESTDIR_SUPPORT is set to "user-destdir" to help catching more
                   7283:     potential packaging problems. If bsd.prefs.mk is included in the Makefile,
                   7284:     PKG_DESTDIR_SUPPORT needs to be set before the inclusion.
1.14      jmcneill 7285: 
1.4       rillig   7286:   * All installation operations have to be prefixed with ${DESTDIR}.
                   7287: 
                   7288:   * automake gets this DESTDIR mostly right automatically. Many manual rules
                   7289:     and pre/post-install often are incorrect; fix them.
                   7290: 
1.17      imil     7291:   * If files are installed with special owner/group use SPECIAL_PERMS.
1.4       rillig   7292: 
                   7293:   * In general, packages should support UNPRIVILEGED to be able to use DESTDIR.
                   7294: 
1.154     rillig   7295: 21.6.5. Packages with hardcoded paths to other interpreters
1.1       dsieger  7296: 
                   7297: Your package may also contain scripts with hardcoded paths to other
1.203     nia      7298: interpreters besides (or as well as) Perl. To correct the full pathname to the
1.1       dsieger  7299: script interpreter, you need to set the following definitions in your Makefile
                   7300: (we shall use tclsh in this example):
                   7301: 
                   7302: REPLACE_INTERPRETER+=   tcl
                   7303: REPLACE.tcl.old=        .*/bin/tclsh
                   7304: REPLACE.tcl.new=        ${PREFIX}/bin/tclsh
                   7305: REPLACE_FILES.tcl=      # list of tcl scripts which need to be fixed,
                   7306: # relative to ${WRKSRC}, just as in REPLACE_PERL
                   7307: 
1.203     nia      7308: 21.6.6. Packages installing Perl modules
1.1       dsieger  7309: 
                   7310: Makefiles of packages providing perl5 modules should include the Makefile
                   7311: fragment ../../lang/perl5/module.mk. It provides a do-configure target for the
                   7312: standard perl configuration for such modules as well as various hooks to tune
                   7313: this configuration. See comments in this file for details.
                   7314: 
                   7315: Perl5 modules will install into different places depending on the version of
                   7316: perl used during the build process. To address this, pkgsrc will append lines
                   7317: to the PLIST corresponding to the files listed in the installed .packlist file
                   7318: generated by most perl5 modules. This is invoked by defining PERL5_PACKLIST to
1.48      wiz      7319: a space-separated list of packlist files relative to PERL5_PACKLIST_DIR
                   7320: (PERL5_INSTALLVENDORARCH by default), e.g.:
1.1       dsieger  7321: 
1.48      wiz      7322: PERL5_PACKLIST= auto/Pg/.packlist
1.1       dsieger  7323: 
1.48      wiz      7324: The perl5 config variables installarchlib, installscript, installvendorbin,
                   7325: installvendorscript, installvendorarch, installvendorlib, installvendorman1dir,
                   7326: and installvendorman3dir represent those locations in which components of perl5
                   7327: modules may be installed, provided as variable with uppercase and prefixed with
                   7328: PERL5_, e.g. PERL5_INSTALLARCHLIB and may be used by perl5 packages that don't
                   7329: have a packlist. These variables are also substituted for in the PLIST as
                   7330: uppercase prefixed with PERL5_SUB_.
1.1       dsieger  7331: 
1.154     rillig   7332: 21.6.7. Packages installing info files
1.1       dsieger  7333: 
                   7334: Some packages install info files or use the "makeinfo" or "install-info"
                   7335: commands. INFO_FILES should be defined in the package Makefile so that INSTALL
                   7336: and DEINSTALL scripts will be generated to handle registration of the info
                   7337: files in the Info directory file. The "install-info" command used for the info
                   7338: files registration is either provided by the system, or by a special purpose
                   7339: package automatically added as dependency if needed.
                   7340: 
                   7341: PKGINFODIR is the directory under ${PREFIX} where info files are primarily
                   7342: located. PKGINFODIR defaults to "info" and can be overridden by the user.
                   7343: 
                   7344: The info files for the package should be listed in the package PLIST; however
                   7345: any split info files need not be listed.
                   7346: 
                   7347: A package which needs the "makeinfo" command at build time must add "makeinfo"
                   7348: to USE_TOOLS in its Makefile. If a minimum version of the "makeinfo" command is
                   7349: needed it should be noted with the TEXINFO_REQD variable in the package
                   7350: Makefile. By default, a minimum version of 3.12 is required. If the system does
                   7351: not provide a makeinfo command or if it does not match the required minimum, a
                   7352: build dependency on the devel/gtexinfo package will be added automatically.
                   7353: 
                   7354: The build and installation process of the software provided by the package
                   7355: should not use the install-info command as the registration of info files is
1.25      wiz      7356: the task of the package INSTALL script, and it must use the appropriate 
1.1       dsieger  7357: makeinfo command.
                   7358: 
                   7359: To achieve this goal, the pkgsrc infrastructure creates overriding scripts for
                   7360: the install-info and makeinfo commands in a directory listed early in PATH.
                   7361: 
                   7362: The script overriding install-info has no effect except the logging of a
                   7363: message. The script overriding makeinfo logs a message and according to the
                   7364: value of TEXINFO_REQD either runs the appropriate makeinfo command or exit on
                   7365: error.
                   7366: 
1.154     rillig   7367: 21.6.8. Packages installing man pages
1.1       dsieger  7368: 
                   7369: All packages that install manual pages should install them into the same
                   7370: directory, so that there is one common place to look for them. In pkgsrc, this
                   7371: place is ${PREFIX}/${PKGMANDIR}, and this expression should be used in
1.25      wiz      7372: packages. The default for PKGMANDIR is "man". Another often-used value is "
                   7373: share/man".
1.1       dsieger  7374: 
                   7375: Note
                   7376: 
                   7377: The support for a custom PKGMANDIR is far from complete.
                   7378: 
                   7379: The PLIST files can just use man/ as the top level directory for the man page
                   7380: file entries, and the pkgsrc framework will convert as needed. In all other
                   7381: places, the correct PKGMANDIR must be used.
                   7382: 
                   7383: Packages that are configured with GNU_CONFIGURE set as "yes", by default will
                   7384: use the ./configure --mandir switch to set where the man pages should be
                   7385: installed. The path is GNU_CONFIGURE_MANDIR which defaults to ${PREFIX}/$
                   7386: {PKGMANDIR}.
                   7387: 
                   7388: Packages that use GNU_CONFIGURE but do not use --mandir, can set
                   7389: CONFIGURE_HAS_MANDIR to "no". Or if the ./configure script uses a non-standard
                   7390: use of --mandir, you can set GNU_CONFIGURE_MANDIR as needed.
                   7391: 
1.184     rillig   7392: See Section 19.5, "Man page compression" for information on installation of
1.1       dsieger  7393: compressed manual pages.
                   7394: 
1.203     nia      7395: 21.6.9. Packages installing X11 fonts
1.1       dsieger  7396: 
                   7397: If a package installs font files, you will need to rebuild the fonts database
                   7398: in the directory where they get installed at installation and deinstallation
                   7399: time. This can be automatically done by using the pkginstall framework.
                   7400: 
                   7401: You can list the directories where fonts are installed in the FONTS_DIRS.type
                   7402: variables, where type can be one of "ttf", "type1" or "x11". Also make sure
                   7403: that the database file fonts.dir is not listed in the PLIST.
                   7404: 
                   7405: Note that you should not create new directories for fonts; instead use the
                   7406: standard ones to avoid that the user needs to manually configure his X server
                   7407: to find them.
                   7408: 
1.203     nia      7409: 21.6.10. Packages installing SGML or XML data
1.1       dsieger  7410: 
                   7411: If a package installs SGML or XML data files that need to be registered in
                   7412: system-wide catalogs (like DTDs, sub-catalogs, etc.), you need to take some
                   7413: extra steps:
                   7414: 
                   7415:  1. Include ../../textproc/xmlcatmgr/catalogs.mk in your Makefile, which takes
                   7416:     care of registering those files in system-wide catalogs at installation and
                   7417:     deinstallation time.
                   7418: 
                   7419:  2. Set SGML_CATALOGS to the full path of any SGML catalogs installed by the
                   7420:     package.
                   7421: 
                   7422:  3. Set XML_CATALOGS to the full path of any XML catalogs installed by the
                   7423:     package.
                   7424: 
                   7425:  4. Set SGML_ENTRIES to individual entries to be added to the SGML catalog.
                   7426:     These come in groups of three strings; see xmlcatmgr(1) for more
                   7427:     information (specifically, arguments recognized by the 'add' action). Note
                   7428:     that you will normally not use this variable.
                   7429: 
                   7430:  5. Set XML_ENTRIES to individual entries to be added to the XML catalog. These
                   7431:     come in groups of three strings; see xmlcatmgr(1) for more information
                   7432:     (specifically, arguments recognized by the 'add' action). Note that you
                   7433:     will normally not use this variable.
                   7434: 
1.203     nia      7435: 21.6.11. Packages installing extensions to the MIME database
1.1       dsieger  7436: 
                   7437: If a package provides extensions to the MIME database by installing .xml files
                   7438: inside ${PREFIX}/share/mime/packages, you need to take some extra steps to
                   7439: ensure that the database is kept consistent with respect to these new files:
                   7440: 
                   7441:  1. Include ../../databases/shared-mime-info/mimedb.mk (avoid using the
                   7442:     buildlink3.mk file from this same directory, which is reserved for
                   7443:     inclusion from other buildlink3.mk files). It takes care of rebuilding the
                   7444:     MIME database at installation and deinstallation time, and disallows any
                   7445:     access to it directly from the package.
                   7446: 
1.25      wiz      7447:  2. Check the PLIST and remove any entries under the share/mime directory, 
1.1       dsieger  7448:     except for files saved under share/mime/packages. The former are handled
                   7449:     automatically by the update-mime-database program, but the latter are
                   7450:     package-dependent and must be removed by the package that installed them in
                   7451:     the first place.
                   7452: 
                   7453:  3. Remove any share/mime/* directories from the PLIST. They will be handled by
                   7454:     the shared-mime-info package.
                   7455: 
1.203     nia      7456: 21.6.12. Packages using intltool
1.1       dsieger  7457: 
                   7458: If a package uses intltool during its build, add intltool to the USE_TOOLS,
                   7459: which forces it to use the intltool package provided by pkgsrc, instead of the
                   7460: one bundled with the distribution file.
                   7461: 
                   7462: This tracks intltool's build-time dependencies and uses the latest available
                   7463: version; this way, the package benefits of any bug fixes that may have appeared
                   7464: since it was released.
                   7465: 
1.203     nia      7466: 21.6.13. Packages installing startup scripts
1.1       dsieger  7467: 
                   7468: If a package contains a rc.d script, it won't be copied into the startup
                   7469: directory by default, but you can enable it, by adding the option
1.4       rillig   7470: PKG_RCD_SCRIPTS=YES in mk.conf. This option will copy the scripts into /etc/
                   7471: rc.d when a package is installed, and it will automatically remove the scripts
                   7472: when the package is deinstalled.
1.1       dsieger  7473: 
1.203     nia      7474: 21.6.14. Packages installing TeX modules
1.1       dsieger  7475: 
                   7476: If a package installs TeX packages into the texmf tree, the ls-R database of
                   7477: the tree needs to be updated.
                   7478: 
                   7479: Note
                   7480: 
1.23      jakllsch 7481: Except the main TeX packages such as kpathsea, packages should install files
                   7482: into ${PREFIX}/share/texmf-dist, not ${PREFIX}/share/texmf.
1.1       dsieger  7483: 
1.23      jakllsch 7484:  1. Include ../../print/kpathsea/texmf.mk. This takes care of rebuilding the
                   7485:     ls-R database at installation and deinstallation time.
1.1       dsieger  7486: 
1.23      jakllsch 7487:  2. If your package installs files into a texmf tree other than the one at $
                   7488:     {PREFIX}/share/texmf-dist, set TEX_TEXMF_DIRS to the list of all texmf
                   7489:     trees that need database update.
1.1       dsieger  7490: 
                   7491:     If your package also installs font map files that need to be registered
1.30      dholland 7492:     using updmap, include ../../print/tex-tetex/map.mk and set TEX_MAP_FILES
                   7493:     and/or TEX_MIXEDMAP_FILES to the list of all such font map files. Then 
                   7494:     updmap will be run automatically at installation/deinstallation to enable/
                   7495:     disable font map files for TeX output drivers.
1.1       dsieger  7496: 
                   7497:  3. Make sure that none of ls-R databases are included in PLIST, as they will
1.30      dholland 7498:     be removed only by the kpathsea package.
1.1       dsieger  7499: 
1.203     nia      7500: 21.6.15. Packages supporting running binaries in emulation
1.1       dsieger  7501: 
                   7502: There are some packages that provide libraries and executables for running
                   7503: binaries from a one operating system on a different one (if the latter supports
                   7504: it). One example is running Linux binaries on NetBSD.
                   7505: 
                   7506: The pkgtools/rpm2pkg helps in extracting and packaging Linux rpm packages.
                   7507: 
                   7508: The CHECK_SHLIBS can be set to no to avoid the check-shlibs target, which tests
                   7509: if all libraries for each installed executable can be found by the dynamic
                   7510: linker. Since the standard dynamic linker is run, this fails for emulation
                   7511: packages, because the libraries used by the emulation are not in the standard
                   7512: directories.
                   7513: 
1.203     nia      7514: 21.6.16. Packages installing hicolor icons
1.1       dsieger  7515: 
                   7516: If a package installs images under the share/icons/hicolor and/or updates the
                   7517: share/icons/hicolor/icon-theme.cache database, you need to take some extra
                   7518: steps to make sure that the shared theme directory is handled appropriately and
                   7519: that the cache database is rebuilt:
                   7520: 
                   7521:  1. Include ../../graphics/hicolor-icon-theme/buildlink3.mk.
                   7522: 
                   7523:  2. Check the PLIST and remove the entry that refers to the theme cache.
                   7524: 
                   7525:  3. Ensure that the PLIST does not remove the shared icon directories from the
                   7526:     share/icons/hicolor hierarchy because they will be handled automatically.
                   7527: 
                   7528: The best way to verify that the PLIST is correct with respect to the last two
                   7529: points is to regenerate it using make print-PLIST.
                   7530: 
1.203     nia      7531: 21.6.17. Packages installing desktop files
1.1       dsieger  7532: 
                   7533: If a package installs .desktop files under share/applications and these include
1.54      rodent   7534: MIME information (MimeType key), you need to take extra steps to ensure that
                   7535: they are registered into the MIME database:
1.1       dsieger  7536: 
                   7537:  1. Include ../../sysutils/desktop-file-utils/desktopdb.mk.
                   7538: 
                   7539:  2. Check the PLIST and remove the entry that refers to the share/applications/
                   7540:     mimeinfo.cache file. It will be handled automatically.
                   7541: 
                   7542: The best way to verify that the PLIST is correct with respect to the last point
                   7543: is to regenerate it using make print-PLIST.
                   7544: 
1.154     rillig   7545: 21.7. Marking packages as having problems
1.1       dsieger  7546: 
1.23      jakllsch 7547: In some cases one does not have the time to solve a problem immediately. In
                   7548: this case, one can plainly mark a package as broken. For this, one just sets
                   7549: the variable BROKEN to the reason why the package is broken (similar to the
1.162     rillig   7550: PKG_FAIL_REASON variable). A user trying to build the package will immediately
                   7551: be shown this message, and the build will not be even tried.
1.1       dsieger  7552: 
1.23      jakllsch 7553: BROKEN packages are removed from pkgsrc in irregular intervals.
1.1       dsieger  7554: 
1.184     rillig   7555: Chapter 22. GNOME packaging and porting
                   7556: 
                   7557: Table of Contents
                   7558: 
                   7559: 22.1. Meta packages
                   7560: 22.2. Packaging a GNOME application
                   7561: 22.3. Updating GNOME to a newer version
                   7562: 22.4. Patching guidelines
                   7563: 
                   7564: Quoting GNOME's web site:
                   7565: 
                   7566:     The GNOME project provides two things: The GNOME desktop environment, an
                   7567:     intuitive and attractive desktop for users, and the GNOME development
                   7568:     platform, an extensive framework for building applications that integrate
                   7569:     into the rest of the desktop.
                   7570: 
                   7571: pkgsrc provides a seamless way to automatically build and install a complete
                   7572: GNOME environment under many different platforms. We can say with confidence
                   7573: that pkgsrc is one of the most advanced build and packaging systems for GNOME
                   7574: due to its included technologies buildlink3, the wrappers and tools framework
                   7575: and automatic configuration file management. Lots of efforts are put into
                   7576: achieving a completely clean deinstallation of installed software components.
                   7577: 
                   7578: Given that pkgsrc is NetBSD's official packaging system, the above also means
                   7579: that great efforts are put into making GNOME work under this operating system.
                   7580: 
                   7581: This chapter is aimed at pkgsrc developers and other people interested in
                   7582: helping our GNOME porting and packaging efforts. It provides instructions on
                   7583: how to manage the existing packages and some important information regarding
                   7584: their internals.
                   7585: 
                   7586: 22.1. Meta packages
                   7587: 
                   7588: pkgsrc includes three GNOME-related meta packages:
                   7589: 
                   7590:   * meta-pkgs/gnome-base: Provides the core GNOME desktop environment. It only
                   7591:     includes the necessary bits to get it to boot correctly, although it may
                   7592:     lack important functionality for daily operation. The idea behind this
                   7593:     package is to let end users build their own configurations on top of this
                   7594:     one, first installing this meta package to achieve a functional setup and
                   7595:     then adding individual applications.
                   7596: 
                   7597:   * meta-pkgs/gnome: Provides a complete installation of the GNOME platform and
                   7598:     desktop as defined by the GNOME project; this is based on the components
                   7599:     distributed in the platform/x.y/x.y.z/sources and desktop/x.y/x.y.z/sources
                   7600:     directories of the official FTP server. Developer-only tools found in those
                   7601:     directories are not installed unless required by some other component to
                   7602:     work properly. Similarly, packages from the bindings set (bindings/x.y/
                   7603:     x.y.z/sources) are not pulled in unless required as a dependency for an
                   7604:     end-user component. This package "extends" meta-pkgs/gnome-base.
                   7605: 
                   7606:   * meta-pkgs/gnome-devel: Installs all the tools required to build a GNOME
                   7607:     component when fetched from the CVS repository. These are required to let
                   7608:     the autogen.sh scripts work appropriately.
                   7609: 
                   7610: In all these packages, the DEPENDS lines are sorted in a way that eases
                   7611: updates: a package may depend on other packages listed before it but not on any
                   7612: listed after it. It is very important to keep this order to ease updates so... 
                   7613: do not change it to alphabetical sorting!
                   7614: 
                   7615: 22.2. Packaging a GNOME application
                   7616: 
                   7617: Almost all GNOME applications are written in C and use a common set of tools as
                   7618: their build system. Things get different with the new bindings to other
                   7619: languages (such as Python), but the following will give you a general idea on
                   7620: the minimum required tools:
                   7621: 
                   7622:   * Almost all GNOME applications use the GNU Autotools as their build system.
                   7623:     As a general rule you will need to tell this to your package:
                   7624: 
1.223     nia      7625:     GNU_CONFIGURE=  yes
                   7626:     USE_LIBTOOL=    yes
                   7627:     USE_TOOLS+=     gmake
1.184     rillig   7628: 
                   7629:   * If the package uses pkg-config to detect dependencies, add this tool to the
                   7630:     list of required utilities:
                   7631: 
1.223     nia      7632:     USE_TOOLS+=     pkg-config
1.184     rillig   7633: 
                   7634:     Also use pkgtools/verifypc at the end of the build process to ensure that
                   7635:     you did not miss to specify any dependency in your package and that the
                   7636:     version requirements are all correct.
                   7637: 
                   7638:   * If the package uses intltool, be sure to add intltool to the USE_TOOLS to
                   7639:     handle dependencies and to force the package to use the latest available
                   7640:     version.
                   7641: 
                   7642:   * If the package uses gtk-doc (a documentation generation utility), do not
                   7643:     add a dependency on it. The tool is rather big and the distfile should come
                   7644:     with pregenerated documentation anyway; if it does not, it is a bug that
                   7645:     you ought to report. For such packages you should disable gtk-doc (unless
                   7646:     it is the default):
                   7647: 
1.223     nia      7648:     CONFIGURE_ARGS+=        --disable-gtk-doc
1.184     rillig   7649: 
                   7650:     The default location of installed HTML files (share/gtk-doc/<package-name>)
                   7651:     is correct and should not be changed unless the package insists on
                   7652:     installing them somewhere else. Otherwise programs as devhelp will not be
                   7653:     able to open them. You can do that with an entry similar to:
1.1       dsieger  7654: 
1.223     nia      7655:     CONFIGURE_ARGS+=        --with-html-dir=${PREFIX}/share/gtk-doc/...
1.1       dsieger  7656: 
1.184     rillig   7657: GNOME uses multiple shared directories and files under the installation prefix
                   7658: to maintain databases. In this context, shared means that those exact same
                   7659: directories and files are used among several different packages, leading to
                   7660: conflicts in the PLIST. pkgsrc currently includes functionality to handle the
                   7661: most common cases, so you have to forget about using @unexec ${RMDIR} lines in
                   7662: your file lists and omitting shared files from them. If you find yourself doing
                   7663: those, your package is most likely incorrect.
1.1       dsieger  7664: 
1.184     rillig   7665: The following table lists the common situations that result in using shared
                   7666: directories or files. For each of them, the appropriate solution is given.
                   7667: After applying the solution be sure to regenerate the package's file list with 
                   7668: make print-PLIST and ensure it is correct.
1.1       dsieger  7669: 
1.184     rillig   7670: Table 22.1. PLIST handling for GNOME packages
1.1       dsieger  7671: 
1.184     rillig   7672: +-----------------------------------------------------------------------------+
                   7673: |             If the package...             |             Then...             |
                   7674: |-------------------------------------------+---------------------------------|
1.203     nia      7675: |Installs icons under the share/icons/      |See Section 21.6.16, "Packages   |
                   7676: |hicolor hierarchy or updates share/icons/  |installing hicolor icons".       |
1.184     rillig   7677: |hicolor/icon-theme.cache.                  |                                 |
                   7678: |-------------------------------------------+---------------------------------|
1.203     nia      7679: |                                           |See Section 21.6.11, "Packages   |
1.184     rillig   7680: |Installs files under share/mime/packages.  |installing extensions to the MIME|
                   7681: |                                           |database".                       |
                   7682: |-------------------------------------------+---------------------------------|
1.203     nia      7683: |Installs .desktop files under share/       |See Section 21.6.17, "Packages   |
1.184     rillig   7684: |applications and these include MIME        |installing desktop files".       |
                   7685: |information.                               |                                 |
                   7686: +-----------------------------------------------------------------------------+
1.1       dsieger  7687: 
                   7688: 
1.184     rillig   7689: 22.3. Updating GNOME to a newer version
1.1       dsieger  7690: 
1.184     rillig   7691: When seeing GNOME as a whole, there are two kinds of updates:
1.1       dsieger  7692: 
1.184     rillig   7693: Major update
1.1       dsieger  7694: 
1.184     rillig   7695:     Given that there is still a very long way for GNOME 3 (if it ever appears),
                   7696:     we consider a major update one that goes from a 2.X version to a 2.Y one,
                   7697:     where Y is even and greater than X. These are hard to achieve because they
                   7698:     introduce lots of changes in the components' code and almost all GNOME
                   7699:     distfiles are updated to newer versions. Some of them can even break API
                   7700:     and ABI compatibility with the previous major version series. As a result,
                   7701:     the update needs to be done all at once to minimize breakage.
1.1       dsieger  7702: 
1.184     rillig   7703:     A major update typically consists of around 80 package updates and the
                   7704:     addition of some new ones.
1.1       dsieger  7705: 
1.184     rillig   7706: Minor update
1.1       dsieger  7707: 
1.184     rillig   7708:     We consider a minor update one that goes from a 2.A.X version to a 2.A.Y
                   7709:     one where Y is greater than X. These are easy to achieve because they do
                   7710:     not update all GNOME components, can be done in an incremental way and do
                   7711:     not break API nor ABI compatibility.
1.1       dsieger  7712: 
1.184     rillig   7713:     A minor update typically consists of around 50 package updates, although
                   7714:     the numbers here may vary a lot.
1.1       dsieger  7715: 
1.184     rillig   7716: In order to update the GNOME components in pkgsrc to a new stable release
                   7717: (either major or minor), the following steps should be followed:
1.1       dsieger  7718: 
1.184     rillig   7719:  1. Get a list of all the tarballs that form the new release by using the
                   7720:     following commands. These will leave the full list of the components'
                   7721:     distfiles into the list.txt file:
1.1       dsieger  7722: 
1.184     rillig   7723:     % echo ls "*.tar.bz2" | \
                   7724:         ftp -V ftp://ftp.gnome.org/pub/gnome/platform/x.y/x.y.z/sources/ | \
                   7725:         awk '{ print $9 }' >list.txt
                   7726:     % echo ls "*.tar.bz2" | \
                   7727:         ftp -V ftp://ftp.gnome.org/pub/gnome/desktop/x.y/x.y.z/sources/ | \
                   7728:         awk '{ print $9 }' >>list.txt
1.1       dsieger  7729: 
1.184     rillig   7730:  2. Open each meta package's Makefile and bump their version to the release you
                   7731:     are updating them to. The three meta packages should be always consistent
                   7732:     with versioning. Obviously remove any PKGREVISIONs that might be in them.
1.1       dsieger  7733: 
1.184     rillig   7734:  3. For each meta package, update all its DEPENDS lines to match the latest
                   7735:     versions as shown by the above commands. Do not list any newer version
                   7736:     (even if found in the FTP) because the meta packages are supposed to list
                   7737:     the exact versions that form a specific GNOME release. Exceptions are
                   7738:     permitted here if a newer version solves a serious issue in the overall
                   7739:     desktop experience; these typically come in the form of a revision bump in
                   7740:     pkgsrc, not in newer versions from the developers.
1.1       dsieger  7741: 
1.184     rillig   7742:     Packages not listed in the list.txt file should be updated to the latest
                   7743:     version available (if found in pkgsrc). This is the case, for example, of
                   7744:     the dependencies on the GNU Autotools in the meta-pkgs/gnome-devel meta
                   7745:     package.
1.1       dsieger  7746: 
1.184     rillig   7747:  4. Generate a patch from the modified meta packages and extract the list of
                   7748:     "new" lines. This will provide you an outline on what packages need to be
                   7749:     updated in pkgsrc and in what order:
1.1       dsieger  7750: 
1.184     rillig   7751:     % cvs diff -u gnome-devel gnome-base gnome | grep '^+D' >todo.txt
1.1       dsieger  7752: 
1.184     rillig   7753:  5. For major desktop updates it is recommended to zap all your installed
                   7754:     packages and start over from scratch at this point.
1.1       dsieger  7755: 
1.184     rillig   7756:  6. Now comes the longest step by far: iterate over the contents of todo.txt
                   7757:     and update the packages listed in it in order. For major desktop updates
                   7758:     none of these should be committed until the entire set is completed because
                   7759:     there are chances of breaking not-yet-updated packages.
1.1       dsieger  7760: 
1.184     rillig   7761:  7. Once the packages are up to date and working, commit them to the tree one
                   7762:     by one with appropriate log messages. At the end, commit the three meta
                   7763:     package updates and all the corresponding changes to the doc/CHANGES-<YEAR>
                   7764:     and pkgsrc/doc/TODO files.
1.1       dsieger  7765: 
1.184     rillig   7766: 22.4. Patching guidelines
1.1       dsieger  7767: 
1.184     rillig   7768: GNOME is a very big component in pkgsrc which approaches 100 packages. Please,
                   7769: it is very important that you always, always, always feed back any portability
                   7770: fixes you do to a GNOME package to the mainstream developers (see
                   7771: Section 12.3.5, "Feedback to the author"). This is the only way to get their
                   7772: attention on portability issues and to ensure that future versions can be built
                   7773: out-of-the box on NetBSD. The less custom patches in pkgsrc, the easier further
                   7774: updates are. Those developers in charge of issuing major GNOME updates will be
                   7775: grateful if you do that.
1.1       dsieger  7776: 
1.200     cirnatda 7777: The most common places to report bugs are the GNOME's GitLab and the
                   7778: freedesktop.org's GitLab. Not all components use these to track bugs, but most
                   7779: of them do. Do not be short on your reports: always provide detailed
1.184     rillig   7780: explanations of the current failure, how it can be improved to achieve maximum
1.200     cirnatda 7781: portability and, if at all possible, provide a patch against the main Git
                   7782: branch. The more verbose you are, the higher chances of your patch being
                   7783: accepted.
1.1       dsieger  7784: 
1.184     rillig   7785: Also, please avoid using preprocessor magic to fix portability issues. While
                   7786: the FreeBSD GNOME people are doing a great job in porting GNOME to their
                   7787: operating system, the official GNOME sources are now plagued by conditionals
                   7788: that check for __FreeBSD__ and similar macros. This hurts portability. Please
                   7789: see our patching guidelines (Section 12.3.4, "Patching guidelines") for more
                   7790: details.
1.1       dsieger  7791: 
1.154     rillig   7792: Chapter 23. Submitting and Committing
1.1       dsieger  7793: 
                   7794: Table of Contents
                   7795: 
1.154     rillig   7796: 23.1. Submitting binary packages
                   7797: 23.2. Submitting source packages (for non-NetBSD-developers)
                   7798: 23.3. General notes when adding, updating, or removing packages
                   7799: 23.4. Commit Messages
                   7800: 23.5. Committing: Adding a package to CVS
                   7801: 23.6. Updating a package to a newer version
                   7802: 23.7. Renaming a package in pkgsrc
                   7803: 23.8. Moving a package in pkgsrc
1.1       dsieger  7804: 
1.154     rillig   7805: 23.1. Submitting binary packages
1.1       dsieger  7806: 
                   7807: Our policy is that we accept binaries only from pkgsrc developers to guarantee
                   7808: that the packages don't contain any trojan horses etc. This is not to annoy
                   7809: anyone but rather to protect our users! You're still free to put up your
                   7810: home-made binary packages and tell the world where to get them. NetBSD
1.154     rillig   7811: developers doing bulk builds and wanting to upload them please see Chapter 8, 
1.66      asau     7812: Creating binary packages for everything in pkgsrc (bulk builds).
1.1       dsieger  7813: 
1.154     rillig   7814: 23.2. Submitting source packages (for non-NetBSD-developers)
1.1       dsieger  7815: 
1.218     nia      7816: Firstly, you can import new packages into pkgsrc-wip ("pkgsrc work-in-progress"
                   7817: ); see the homepage at https://pkgsrc.org/wip/ for details.
                   7818: 
                   7819: Next, check that your package is complete, compiles and runs well; see
1.184     rillig   7820: Chapter 14, Creating a new pkgsrc package from scratch and the rest of this
1.218     nia      7821: document. Run the pkgtools/pkglint tool and fix any errors that appear.
                   7822: 
                   7823: Finally, send a report to the pkgsrc bug tracking system, either with the
                   7824: send-pr(1) command, or if you don't have that, go to the web page https://
                   7825: www.NetBSD.org/support/send-pr.html, which contains some instructions and a
                   7826: link to a form where you can submit packages. The sysutils/gtk-send-pr package
                   7827: is also available as a substitute for either of the above two tools.
1.1       dsieger  7828: 
                   7829: In the form of the problem report, the category should be "pkg", the synopsis
                   7830: should include the package name and version number, and the description field
                   7831: should contain a short description of your package (contents of the COMMENT
1.218     nia      7832: variable or DESCR file are OK).
1.1       dsieger  7833: 
1.154     rillig   7834: 23.3. General notes when adding, updating, or removing packages
1.1       dsieger  7835: 
                   7836: Please note all package additions, updates, moves, and removals in pkgsrc/doc/
                   7837: CHANGES-YYYY. It's very important to keep this file up to date and conforming
                   7838: to the existing format, because it will be used by scripts to automatically
                   7839: update pages on www.NetBSD.org and other sites. Additionally, check the pkgsrc/
                   7840: doc/TODO file and remove the entry for the package you updated or removed, in
                   7841: case it was mentioned there.
                   7842: 
                   7843: When the PKGREVISION of a package is bumped, the change should appear in pkgsrc
                   7844: /doc/CHANGES-YYYY if it is security related or otherwise relevant. Mass bumps
                   7845: that result from a dependency being updated should not be mentioned. In all
                   7846: other cases it's the developer's decision.
                   7847: 
                   7848: There is a make target that helps in creating proper CHANGES-YYYY entries: make
                   7849: changes-entry. It uses the optional CTYPE and NETBSD_LOGIN_NAME variables. The
                   7850: general usage is to first make sure that your CHANGES-YYYY file is up-to-date
                   7851: (to avoid having to resolve conflicts later-on) and then to cd to the package
                   7852: directory. For package updates, make changes-entry is enough. For new packages,
                   7853: or package moves or removals, set the CTYPE variable on the command line to
1.4       rillig   7854: "Added", "Moved", or "Removed". You can set NETBSD_LOGIN_NAME in mk.conf if
1.23      jakllsch 7855: your local login name is not the same as your NetBSD login name. The target
                   7856: also automatically removes possibly existing entries for the package in the
                   7857: TODO file. Don't forget to commit the changes, e.g. by using make
1.66      asau     7858: commit-changes-entry! If you are not using a checkout directly from
1.23      jakllsch 7859: cvs.NetBSD.org, but e.g. a local copy of the repository, you can set
                   7860: USE_NETBSD_REPO=yes. This makes the cvs commands use the main repository.
1.1       dsieger  7861: 
1.154     rillig   7862: 23.4. Commit Messages
1.130     wiz      7863: 
                   7864: For several years, there have been mirrors of pkgsrc in fossil, git, and hg.
                   7865: Standard practise when using these tools is to make the first line of a commit
                   7866: message function as a summary that can be read without the rest, such as is
                   7867: commonly done with "git log --oneline". For this reason, we have the following
                   7868: guidelines for pkgsrc commit messages:
                   7869: 
1.131     wiz      7870:   * Start the commit message with a line that explains the big picture in 65
1.130     wiz      7871:     characters or less. When a commit is for one package, include the name of
                   7872:     the package. For updates, include the version to which it is updated.
                   7873: 
                   7874:   * Leave the next line empty.
                   7875: 
                   7876:   * Then come the details for the commit (changes in that package, reason for a
                   7877:     change) and any relevant PRs. Wrap this section.
                   7878: 
                   7879: Here is an example:
                   7880: 
                   7881:   libxslt: update to 1.0.30
                   7882: 
                   7883:   Changes since 1.0.29:
                   7884:   ...
                   7885: 
                   7886: 
                   7887: Here is another example:
                   7888: 
                   7889:   mk/bsd.pkg.mk: enable SSP by default on NetBSD
                   7890: 
                   7891:   (rationale)
                   7892: 
                   7893: 
                   7894: Commit messages are final: no "cvs admin" is allowed on the pkgsrc repository
                   7895: to change commit messages.
                   7896: 
1.154     rillig   7897: 23.5. Committing: Adding a package to CVS
1.1       dsieger  7898: 
                   7899: This section is only of interest for pkgsrc developers with write access to the
1.34      wiz      7900: pkgsrc repository.
                   7901: 
                   7902: When the package is finished, "cvs add" the files. Start by adding the
                   7903: directory and then files in the directory. Don't forget to add the new package
                   7904: to the category's Makefile. Make sure you don't forget any files; you can check
                   7905: by running "cvs status". An example:
                   7906: 
                   7907: $ cd .../pkgsrc/category
                   7908: $ cvs add pkgname
                   7909: $ cd pkgname
                   7910: $ cvs add DESCR Makefile PLIST distinfo buildlink3.mk patches
                   7911: $ cvs add patches/p*
                   7912: $ cvs status | less
1.35      wiz      7913: $ cvs commit
1.34      wiz      7914: $ cd ..
                   7915: $ vi Makefile # add SUBDIRS+=pkgname line
1.35      wiz      7916: $ cvs commit Makefile
1.66      asau     7917: $ cd pkgname
1.73      jnemeth  7918: $ make CTYPE=Added commit-changes-entry
1.1       dsieger  7919: 
                   7920: The commit message of the initial import should include part of the DESCR file,
                   7921: so people reading the mailing lists know what the package is/does.
                   7922: 
1.34      wiz      7923: Also mention the new package in pkgsrc/doc/CHANGES-20xx.
                   7924: 
                   7925: Previously, "cvs import" was suggested, but it was much easier to get wrong
                   7926: than "cvs add".
1.1       dsieger  7927: 
1.154     rillig   7928: 23.6. Updating a package to a newer version
1.1       dsieger  7929: 
                   7930: Please always put a concise, appropriate and relevant summary of the changes
                   7931: between old and new versions into the commit log when updating a package. There
                   7932: are various reasons for this:
                   7933: 
                   7934:   * A URL is volatile, and can change over time. It may go away completely or
                   7935:     its information may be overwritten by newer information.
                   7936: 
                   7937:   * Having the change information between old and new versions in our CVS
                   7938:     repository is very useful for people who use either cvs or anoncvs.
                   7939: 
                   7940:   * Having the change information between old and new versions in our CVS
                   7941:     repository is very useful for people who read the pkgsrc-changes mailing
                   7942:     list, so that they can make tactical decisions about when to upgrade the
                   7943:     package.
                   7944: 
                   7945: Please also recognize that, just because a new version of a package has been
                   7946: released, it should not automatically be upgraded in the CVS repository. We
                   7947: prefer to be conservative in the packages that are included in pkgsrc -
                   7948: development or beta packages are not really the best thing for most places in
                   7949: which pkgsrc is used. Please use your judgement about what should go into
                   7950: pkgsrc, and bear in mind that stability is to be preferred above new and
                   7951: possibly untested features.
                   7952: 
1.154     rillig   7953: 23.7. Renaming a package in pkgsrc
1.21      snj      7954: 
                   7955: Renaming packages is not recommended.
                   7956: 
1.175     gutterid 7957: When renaming packages, be sure to fix any references to the old name in other
1.21      snj      7958: Makefiles, options, buildlink files, etc.
                   7959: 
1.175     gutterid 7960: Also, when renaming a package, please add the package name and version pattern
1.167     leot     7961: (s) of the previous package to SUPERSEDES. This may be repeated for multiple
                   7962: renames. The new package would be an exact replacement. Example:
                   7963: 
                   7964: SUPERSEDES+=    p5-IO-Compress-Zlib<2.017
                   7965: SUPERSEDES+=    optcomp-[0-9]*
1.21      snj      7966: 
                   7967: Note that "successor" in the CHANGES-YYYY file doesn't necessarily mean that it
                   7968: supersedes, as that successor may not be an exact replacement but is a
                   7969: suggestion for the replaced functionality.
                   7970: 
1.154     rillig   7971: 23.8. Moving a package in pkgsrc
1.21      snj      7972: 
                   7973: It is preferred that packages are not renamed or moved, but if needed please
                   7974: follow these steps.
1.1       dsieger  7975: 
                   7976:  1. Make a copy of the directory somewhere else.
                   7977: 
                   7978:  2. Remove all CVS dirs.
                   7979: 
                   7980:     Alternatively to the first two steps you can also do:
                   7981: 
                   7982:     % cvs -d user@cvs.NetBSD.org:/cvsroot export -D today pkgsrc/category/package
                   7983: 
                   7984:     and use that for further work.
                   7985: 
1.25      wiz      7986:  3. Fix CATEGORIES and any DEPENDS paths that just did "../package" instead of 
1.1       dsieger  7987:     "../../category/package".
                   7988: 
1.21      snj      7989:  4. In the modified package's Makefile, consider setting PREV_PKGPATH to the
                   7990:     previous category/package pathname. The PREV_PKGPATH can be used by tools
                   7991:     for doing an update using pkgsrc building; for example, it can search the
                   7992:     pkg_summary(5) database for PREV_PKGPATH (if no SUPERSEDES) and then use
                   7993:     the corresponding new PKGPATH for that moved package. Note that it may have
                   7994:     multiple matches, so the tool should also check on the PKGBASE too. The
                   7995:     PREV_PKGPATH probably has no value unless SUPERSEDES is not set, i.e.
                   7996:     PKGBASE stays the same.
                   7997: 
                   7998:  5. cvs import the modified package in the new place.
1.1       dsieger  7999: 
1.21      snj      8000:  6. Check if any package depends on it:
1.1       dsieger  8001: 
                   8002:     % cd /usr/pkgsrc
                   8003:     % grep /package */*/Makefile* */*/buildlink*
                   8004: 
1.21      snj      8005:  7. Fix paths in packages from step 5 to point to new location.
1.1       dsieger  8006: 
1.21      snj      8007:  8. cvs rm (-f) the package at the old location.
1.1       dsieger  8008: 
1.21      snj      8009:  9. Remove from oldcategory/Makefile.
1.1       dsieger  8010: 
1.21      snj      8011: 10. Add to newcategory/Makefile.
1.1       dsieger  8012: 
1.21      snj      8013: 11. Commit the changed and removed files:
1.1       dsieger  8014: 
                   8015:     % cvs commit oldcategory/package oldcategory/Makefile newcategory/Makefile
                   8016: 
                   8017:     (and any packages from step 5, of course).
                   8018: 
1.154     rillig   8019: Chapter 24. Frequently Asked Questions
1.1       dsieger  8020: 
                   8021: This section contains the answers to questions that may arise when you are
                   8022: writing a package. If you don't find your question answered here, first have a
                   8023: look in the other chapters, and if you still don't have the answer, ask on the
                   8024: pkgsrc-users mailing list.
                   8025: 
1.154     rillig   8026: 24.1. What is the difference between MAKEFLAGS, .MAKEFLAGS and MAKE_FLAGS?
                   8027: 24.2. What is the difference between MAKE, GMAKE and MAKE_PROGRAM?
                   8028: 24.3. What is the difference between CC, PKG_CC and PKGSRC_COMPILER?
1.223     nia      8029: 24.4. Why does make show-var VARNAME=BUILDLINK_PREFIX.foo say it's empty?
                   8030: 24.5. What does ${MASTER_SITE_SOURCEFORGE:=package/} mean? I don't understand
1.232   ! gutterid 8031: the := inside it.
1.223     nia      8032: 24.6. Which mailing lists are there for package developers?
                   8033: 24.7. Where is the pkgsrc documentation?
                   8034: 24.8. I have a little time to kill. What shall I do?
1.1       dsieger  8035: 
1.154     rillig   8036: 24.1. What is the difference between MAKEFLAGS, .MAKEFLAGS and MAKE_FLAGS?
1.1       dsieger  8037: 
                   8038:       MAKEFLAGS are the flags passed to the pkgsrc-internal invocations of make
1.223     nia      8039:       (1).
                   8040: 
                   8041:       MAKE_FLAGS are the flags that are passed to the MAKE_PROGRAM when
                   8042:       building the package.
                   8043: 
                   8044:       .MAKEFLAGS is an internal variable of bmake and should not be used by
                   8045:       packages.
1.1       dsieger  8046: 
1.154     rillig   8047: 24.2. What is the difference between MAKE, GMAKE and MAKE_PROGRAM?
1.1       dsieger  8048: 
                   8049:       MAKE is the path to the make(1) program that is used in the pkgsrc
1.223     nia      8050:       infrastructure.
                   8051: 
                   8052:       GMAKE is the path to GNU Make, but you need to say USE_TOOLS+=gmake to
                   8053:       use that.
                   8054: 
                   8055:       MAKE_PROGRAM is the path to the Make program that is used for building
                   8056:       the package.
1.1       dsieger  8057: 
1.154     rillig   8058: 24.3. What is the difference between CC, PKG_CC and PKGSRC_COMPILER?
1.1       dsieger  8059: 
                   8060:       CC is the path to the real C compiler, which can be configured by the
1.223     nia      8061:       pkgsrc user.
1.1       dsieger  8062: 
1.223     nia      8063:       PKG_CC is the path to the compiler wrapper.
1.1       dsieger  8064: 
1.223     nia      8065:       PKGSRC_COMPILER is not a path to a compiler, but the type of compiler
                   8066:       that should be used. See mk/compiler.mk for more information about the
                   8067:       latter variable.
1.1       dsieger  8068: 
1.223     nia      8069: 24.4. Why does make show-var VARNAME=BUILDLINK_PREFIX.foo say it's empty?
1.1       dsieger  8070: 
1.25      wiz      8071:       For optimization reasons, some variables are only available in the "
                   8072:       wrapper" phase and later. To "simulate" the wrapper phase, append 
1.1       dsieger  8073:       PKG_PHASE=wrapper to the above command.
                   8074: 
1.223     nia      8075: 24.5. What does ${MASTER_SITE_SOURCEFORGE:=package/} mean? I don't understand
1.1       dsieger  8076:       the := inside it.
                   8077: 
1.223     nia      8078:       The := is not an assignment operator, even though it may look like one.
1.108     rillig   8079:       Instead, it is a degenerate form of ${LIST:old_string=new_string}, which
                   8080:       is documented in the make(1) man page and which is commonly used in the
                   8081:       form ${SRCS:.c=.o}. In the case of MASTER_SITE_*, old_string is the empty
                   8082:       string and new_string is package/. That's where the : and the = fall
                   8083:       together.
1.1       dsieger  8084: 
1.223     nia      8085: 24.6. Which mailing lists are there for package developers?
1.1       dsieger  8086: 
                   8087:       tech-pkg
                   8088: 
                   8089:           This is a list for technical discussions related to pkgsrc
                   8090:           development, e.g. soliciting feedback for changes to pkgsrc
                   8091:           infrastructure, proposed new features, questions related to porting
                   8092:           pkgsrc to a new platform, advice for maintaining a package, patches
                   8093:           that affect many packages, help requests moved from pkgsrc-users when
                   8094:           an infrastructure bug is found, etc.
                   8095: 
                   8096:       pkgsrc-bugs
                   8097: 
                   8098:           All bug reports in category "pkg" sent with send-pr(1) appear here.
                   8099:           Please do not report your bugs here directly; use one of the other
                   8100:           mailing lists.
                   8101: 
1.223     nia      8102: 24.7. Where is the pkgsrc documentation?
1.1       dsieger  8103: 
                   8104:       There are many places where you can find documentation about pkgsrc:
                   8105: 
                   8106:         * The pkgsrc guide (this document) is a collection of chapters that
                   8107:           explain large parts of pkgsrc, but some chapters tend to be outdated.
                   8108:           Which ones they are is hard to say.
                   8109: 
1.174     leot     8110:         * On the mailing list archives (see https://mail-index.NetBSD.org/),
                   8111:           you can find discussions about certain features, announcements of new
1.1       dsieger  8112:           parts of the pkgsrc infrastructure and sometimes even announcements
                   8113:           that a certain feature has been marked as obsolete. The benefit here
                   8114:           is that each message has a date appended to it.
                   8115: 
                   8116:         * Many of the files in the mk/ directory start with a comment that
                   8117:           describes the purpose of the file and how it can be used by the
                   8118:           pkgsrc user and package authors. An easy way to find this
                   8119:           documentation is to run bmake help.
                   8120: 
                   8121:         * The CVS log messages are a rich source of information, but they tend
                   8122:           to be highly abbreviated, especially for actions that occur often.
                   8123:           Some contain a detailed description of what has changed, but they are
                   8124:           geared towards the other pkgsrc developers, not towards an average
                   8125:           pkgsrc user. They also only document changes, so if you don't know
                   8126:           what has been before, these messages may not be worth too much to
                   8127:           you.
                   8128: 
                   8129:         * Some parts of pkgsrc are only "implicitly documented", that is the
                   8130:           documentation exists only in the mind of the developer who wrote the
                   8131:           code. To get this information, use the cvs annotate command to see
                   8132:           who has written it and ask on the tech-pkg mailing list, so that
                   8133:           others can find your questions later (see above). To be sure that the
                   8134:           developer in charge reads the mail, you may CC him or her.
                   8135: 
1.223     nia      8136: 24.8. I have a little time to kill. What shall I do?
1.1       dsieger  8137: 
                   8138:       This is not really an FAQ yet, but here's the answer anyway.
                   8139: 
                   8140:         * Run pkg_chk -N (from the pkgtools/pkg_chk package). It will tell you
                   8141:           about newer versions of installed packages that are available, but
                   8142:           not yet updated in pkgsrc.
                   8143: 
1.198     leot     8144:         * Browse pkgsrc/doc/TODO -- it contains a list of suggested new
                   8145:           packages and a list of cleanups and enhancements for pkgsrc that
                   8146:           would be nice to have.
1.1       dsieger  8147: 
1.71      wiz      8148:         * Review packages for which review was requested on the tech-pkg
                   8149:           mailing list.
1.1       dsieger  8150: 
                   8151: Part III. The pkgsrc infrastructure internals
                   8152: 
                   8153: This part of the guide deals with everything from the infrastructure that is
                   8154: behind the interfaces described in the developer's guide. A casual package
                   8155: maintainer should not need anything from this part.
                   8156: 
                   8157: Table of Contents
                   8158: 
1.184     rillig   8159: 25. Design of the pkgsrc infrastructure
                   8160:     25.1. The meaning of variable definitions
                   8161:     25.2. Avoiding problems before they arise
                   8162:     25.3. Variable evaluation
                   8163:         25.3.1. At load time
                   8164:         25.3.2. At runtime
                   8165:     25.4. How can variables be specified?
                   8166:     25.5. Designing interfaces for Makefile fragments
                   8167:         25.5.1. Procedures with parameters
                   8168:         25.5.2. Actions taken on behalf of parameters
                   8169:     25.6. The order in which files are loaded
                   8170:         25.6.1. The order in bsd.prefs.mk
                   8171:         25.6.2. The order in bsd.pkg.mk
                   8172: 26. Regression tests
                   8173:     26.1. Running the regression tests
                   8174:     26.2. Adding a new regression test
                   8175:         26.2.1. Overridable functions
                   8176:         26.2.2. Helper functions
                   8177: 27. Porting pkgsrc
                   8178:     27.1. Porting pkgsrc to a new operating system
1.1       dsieger  8179: 
1.184     rillig   8180: Chapter 25. Design of the pkgsrc infrastructure
1.1       dsieger  8181: 
                   8182: Table of Contents
                   8183: 
1.184     rillig   8184: 25.1. The meaning of variable definitions
                   8185: 25.2. Avoiding problems before they arise
                   8186: 25.3. Variable evaluation
                   8187:     25.3.1. At load time
                   8188:     25.3.2. At runtime
                   8189: 25.4. How can variables be specified?
                   8190: 25.5. Designing interfaces for Makefile fragments
                   8191:     25.5.1. Procedures with parameters
                   8192:     25.5.2. Actions taken on behalf of parameters
                   8193: 25.6. The order in which files are loaded
                   8194:     25.6.1. The order in bsd.prefs.mk
                   8195:     25.6.2. The order in bsd.pkg.mk
1.1       dsieger  8196: 
                   8197: The pkgsrc infrastructure consists of many small Makefile fragments. Each such
                   8198: fragment needs a properly specified interface. This chapter explains how such
                   8199: an interface looks like.
                   8200: 
1.184     rillig   8201: 25.1. The meaning of variable definitions
1.1       dsieger  8202: 
                   8203: Whenever a variable is defined in the pkgsrc infrastructure, the location and
                   8204: the way of definition provide much information about the intended use of that
                   8205: variable. Additionally, more documentation may be found in a header comment or
                   8206: in this pkgsrc guide.
                   8207: 
                   8208: A special file is mk/defaults/mk.conf, which lists all variables that are
                   8209: intended to be user-defined. They are either defined using the ?= operator or
                   8210: they are left undefined because defining them to anything would effectively
                   8211: mean "yes". All these variables may be overridden by the pkgsrc user in the
                   8212: MAKECONF file.
                   8213: 
                   8214: Outside this file, the following conventions apply: Variables that are defined
                   8215: using the ?= operator may be overridden by a package.
                   8216: 
                   8217: Variables that are defined using the = operator may be used read-only at
                   8218: run-time.
                   8219: 
                   8220: Variables whose name starts with an underscore must not be accessed outside the
                   8221: pkgsrc infrastructure at all. They may change without further notice.
                   8222: 
                   8223: Note
                   8224: 
                   8225: These conventions are currently not applied consistently to the complete pkgsrc
                   8226: infrastructure.
                   8227: 
1.184     rillig   8228: 25.2. Avoiding problems before they arise
1.1       dsieger  8229: 
                   8230: All variables that contain lists of things should default to being empty. Two
                   8231: examples that do not follow this rule are USE_LANGUAGES and DISTFILES. These
                   8232: variables cannot simply be modified using the += operator in package Makefiles
                   8233: (or other files included by them), since there is no guarantee whether the
                   8234: variable is already set or not, and what its value is. In the case of
                   8235: DISTFILES, the packages "know" the default value and just define it as in the
                   8236: following example.
                   8237: 
                   8238: DISTFILES=      ${DISTNAME}${EXTRACT_SUFX} additional-files.tar.gz
                   8239: 
                   8240: Because of the selection of this default value, the same value appears in many
                   8241: package Makefiles. Similarly for USE_LANGUAGES, but in this case the default
                   8242: value ("c") is so short that it doesn't stand out. Nevertheless it is mentioned
                   8243: in many files.
                   8244: 
1.184     rillig   8245: 25.3. Variable evaluation
1.1       dsieger  8246: 
1.184     rillig   8247: 25.3.1. At load time
1.1       dsieger  8248: 
                   8249: Variable evaluation takes place either at load time or at runtime, depending on
                   8250: the context in which they occur. The contexts where variables are evaluated at
                   8251: load time are:
                   8252: 
                   8253:   * The right hand side of the := and != operators,
                   8254: 
                   8255:   * Make directives like .if or .for,
                   8256: 
                   8257:   * Dependency lines.
                   8258: 
                   8259: A special exception are references to the iteration variables of .for loops,
                   8260: which are expanded inline, no matter in which context they appear.
                   8261: 
                   8262: As the values of variables may change during load time, care must be taken not
                   8263: to evaluate them by accident. Typical examples for variables that should not be
                   8264: evaluated at load time are DEPENDS and CONFIGURE_ARGS. To make the effect more
                   8265: clear, here is an example:
                   8266: 
                   8267: CONFIGURE_ARGS=         # none
                   8268: CFLAGS=                 -O
                   8269: CONFIGURE_ARGS+=        CFLAGS=${CFLAGS:Q}
                   8270: 
                   8271: CONFIGURE_ARGS:=        ${CONFIGURE_ARGS}
                   8272: 
                   8273: CFLAGS+=                -Wall
                   8274: 
                   8275: This code shows how the use of the := operator can quickly lead to unexpected
                   8276: results. The first paragraph is fairly common code. The second paragraph
                   8277: evaluates the CONFIGURE_ARGS variable, which results in CFLAGS=-O. In the third
                   8278: paragraph, the -Wall is appended to the CFLAGS, but this addition will not
                   8279: appear in CONFIGURE_ARGS. In actual code, the three paragraphs from above
                   8280: typically occur in completely unrelated files.
                   8281: 
1.184     rillig   8282: 25.3.2. At runtime
1.1       dsieger  8283: 
                   8284: After all the files have been loaded, the values of the variables cannot be
                   8285: changed anymore. Variables that are used in the shell commands are expanded at
                   8286: this point.
                   8287: 
1.184     rillig   8288: 25.4. How can variables be specified?
1.1       dsieger  8289: 
                   8290: There are many ways in which the definition and use of a variable can be
                   8291: restricted in order to detect bugs and violations of the (mostly unwritten)
1.108     rillig   8292: policies. A package can be checked with pkglint -Wall to see whether it meets
                   8293: these rules.
1.1       dsieger  8294: 
1.184     rillig   8295: 25.5. Designing interfaces for Makefile fragments
1.1       dsieger  8296: 
                   8297: Most of the .mk files fall into one of the following classes. Cases where a
                   8298: file falls into more than one class should be avoided as it often leads to
                   8299: subtle bugs.
                   8300: 
1.184     rillig   8301: 25.5.1. Procedures with parameters
1.1       dsieger  8302: 
                   8303: In a traditional imperative programming language some of the .mk files could be
1.198     leot     8304: described as procedures. They take some input parameters and--after
                   8305: inclusion--provide a result in output parameters. Since all variables in
1.23      jakllsch 8306: Makefiles have global scope care must be taken not to use parameter names that
                   8307: have already another meaning. For example, PKGNAME is a bad choice for a
                   8308: parameter name.
1.1       dsieger  8309: 
                   8310: Procedures are completely evaluated at preprocessing time. That is, when
                   8311: calling a procedure all input parameters must be completely resolvable. For
                   8312: example, CONFIGURE_ARGS should never be an input parameter since it is very
                   8313: likely that further text will be added after calling the procedure, which would
                   8314: effectively apply the procedure to only a part of the variable. Also,
1.108     rillig   8315: references to other variables will be modified after calling the procedure.
1.1       dsieger  8316: 
                   8317: A procedure can declare its output parameters either as suitable for use in
                   8318: preprocessing directives or as only available at runtime. The latter
                   8319: alternative is for variables that contain references to other runtime
                   8320: variables.
                   8321: 
                   8322: Procedures shall be written such that it is possible to call the procedure more
                   8323: than once. That is, the file must not contain multiple-inclusion guards.
                   8324: 
                   8325: Examples for procedures are mk/bsd.options.mk and mk/buildlink3/bsd.builtin.mk.
                   8326: To express that the parameters are evaluated at load time, they should be
                   8327: assigned using the := operator, which should be used only for this purpose.
                   8328: 
1.184     rillig   8329: 25.5.2. Actions taken on behalf of parameters
1.1       dsieger  8330: 
                   8331: Action files take some input parameters and may define runtime variables. They
                   8332: shall not define loadtime variables. There are action files that are included
                   8333: implicitly by the pkgsrc infrastructure, while other must be included
                   8334: explicitly.
                   8335: 
                   8336: An example for action files is mk/subst.mk.
                   8337: 
1.184     rillig   8338: 25.6. The order in which files are loaded
1.1       dsieger  8339: 
                   8340: Package Makefiles usually consist of a set of variable definitions, and include
                   8341: the file ../../mk/bsd.pkg.mk in the very last line. Before that, they may also
                   8342: include various other *.mk files if they need to query the availability of
                   8343: certain features like the type of compiler or the X11 implementation. Due to
                   8344: the heavy use of preprocessor directives like .if and .for, the order in which
                   8345: the files are loaded matters.
                   8346: 
                   8347: This section describes at which point the various files are loaded and gives
                   8348: reasons for that order.
                   8349: 
1.184     rillig   8350: 25.6.1. The order in bsd.prefs.mk
1.1       dsieger  8351: 
                   8352: The very first action in bsd.prefs.mk is to define some essential variables
                   8353: like OPSYS, OS_VERSION and MACHINE_ARCH.
                   8354: 
1.4       rillig   8355: Then, the user settings are loaded from the file specified in MAKECONF, which
                   8356: is usually mk.conf. After that, those variables that have not been overridden
                   8357: by the user are loaded from mk/defaults/mk.conf.
1.1       dsieger  8358: 
                   8359: After the user settings, the system settings and platform settings are loaded,
                   8360: which may override the user settings.
                   8361: 
                   8362: Then, the tool definitions are loaded. The tool wrappers are not yet in effect.
                   8363: This only happens when building a package, so the proper variables must be used
                   8364: instead of the direct tool names.
                   8365: 
                   8366: As the last steps, some essential variables from the wrapper and the package
                   8367: system flavor are loaded, as well as the variables that have been cached in
                   8368: earlier phases of a package build.
                   8369: 
1.184     rillig   8370: 25.6.2. The order in bsd.pkg.mk
1.1       dsieger  8371: 
                   8372: First, bsd.prefs.mk is loaded.
                   8373: 
                   8374: Then, the various *-vars.mk files are loaded, which fill default values for
                   8375: those variables that have not been defined by the package. These variables may
                   8376: later be used even in unrelated files.
                   8377: 
                   8378: Then, the file bsd.pkg.error.mk provides the target error-check that is added
                   8379: as a special dependency to all other targets that use DELAYED_ERROR_MSG or
                   8380: DELAYED_WARNING_MSG.
                   8381: 
                   8382: Then, the package-specific hacks from hacks.mk are included.
                   8383: 
                   8384: Then, various other files follow. Most of them don't have any dependencies on
                   8385: what they need to have included before or after them, though some do.
                   8386: 
                   8387: The code to check PKG_FAIL_REASON and PKG_SKIP_REASON is then executed, which
                   8388: restricts the use of these variables to all the files that have been included
                   8389: before. Appearances in later files will be silently ignored.
                   8390: 
                   8391: Then, the files for the main targets are included, in the order of later
                   8392: execution, though the actual order should not matter.
                   8393: 
                   8394: At last, some more files are included that don't set any interesting variables
                   8395: but rather just define make targets to be executed.
                   8396: 
1.184     rillig   8397: Chapter 26. Regression tests
1.1       dsieger  8398: 
                   8399: Table of Contents
                   8400: 
1.184     rillig   8401: 26.1. Running the regression tests
                   8402: 26.2. Adding a new regression test
                   8403:     26.2.1. Overridable functions
                   8404:     26.2.2. Helper functions
1.1       dsieger  8405: 
                   8406: The pkgsrc infrastructure consists of a large codebase, and there are many
                   8407: corners where every little bit of a file is well thought out, making pkgsrc
                   8408: likely to fail as soon as anything is changed near those parts. To prevent most
                   8409: changes from breaking anything, a suite of regression tests should go along
                   8410: with every important part of the pkgsrc infrastructure. This chapter describes
                   8411: how regression tests work in pkgsrc and how you can add new tests.
                   8412: 
1.184     rillig   8413: 26.1. Running the regression tests
1.1       dsieger  8414: 
1.25      wiz      8415: You first need to install the pkgtools/pkg_regress package, which provides the 
1.1       dsieger  8416: pkg_regress command. Then you can simply run that command, which will run all
1.168     rillig   8417: tests in the regress/ directory.
1.1       dsieger  8418: 
1.184     rillig   8419: 26.2. Adding a new regression test
1.1       dsieger  8420: 
1.168     rillig   8421: Every directory in the regress/ directory that contains a file called spec is
1.1       dsieger  8422: considered a regression test. This file is a shell program that is included by
                   8423: the pkg_regress command. The following functions can be overridden to suit your
                   8424: needs.
                   8425: 
1.184     rillig   8426: 26.2.1. Overridable functions
1.1       dsieger  8427: 
1.108     rillig   8428: These functions do not take any parameters. Although they are called in "set -e
1.168     rillig   8429: " mode, they don't stop at the first failing command. See this Stack Overflow
1.108     rillig   8430: question for details.
1.1       dsieger  8431: 
1.108     rillig   8432: do_setup
1.1       dsieger  8433: 
                   8434:     This function prepares the environment for the test. By default it does
                   8435:     nothing.
                   8436: 
1.108     rillig   8437: do_test
1.1       dsieger  8438: 
                   8439:     This function runs the actual test. By default, it calls TEST_MAKE with the
                   8440:     arguments MAKEARGS_TEST and writes its output including error messages into
                   8441:     the file TEST_OUTFILE.
                   8442: 
1.108     rillig   8443:     When defining this function, make sure that all output that needs to be
                   8444:     checked is written to the correct output file. Example:
                   8445: 
                   8446:     do_test() {
                   8447:             echo "Example output"
                   8448:     } 1>$TEST_OUTFILE 2>&1
                   8449: 
                   8450: check_result
1.1       dsieger  8451: 
                   8452:     This function is run after the test and is typically used to compare the
                   8453:     actual output from the one that is expected. It can make use of the various
1.108     rillig   8454:     helper functions from the next section. Example:
                   8455: 
                   8456:     check_result() {
                   8457:             exit_status 0
                   8458:             output_require "Example"
                   8459:             output_require "^[[:alpha:]+[[:space:]][[:alpha:]]{6}$"
                   8460:             output_prohibit "no such file or directory"
1.169     rillig   8461:             regress_fail "expected $expected but got $actual for input $input"
1.108     rillig   8462:     }
1.1       dsieger  8463: 
1.108     rillig   8464: do_cleanup
1.1       dsieger  8465: 
                   8466:     This function cleans everything up after the test has been run. By default
                   8467:     it does nothing.
                   8468: 
1.184     rillig   8469: 26.2.2. Helper functions
1.1       dsieger  8470: 
1.168     rillig   8471: regress_fail message...
                   8472: 
                   8473:     This function makes the test fail with the given error message.
                   8474: 
1.108     rillig   8475: exit_status expected
1.1       dsieger  8476: 
1.108     rillig   8477:     This function compares the exitcode of the do_test function with its first
                   8478:     parameter. If they differ, the test will fail.
1.1       dsieger  8479: 
1.108     rillig   8480: output_require regex...
1.1       dsieger  8481: 
                   8482:     This function checks for each of its parameters if the output from do_test
1.108     rillig   8483:     matches the extended regular expression. If it does not, the test will
                   8484:     fail. Example:
                   8485: 
                   8486:     output_require "looks fine"
                   8487:     output_require "^[[:alpha:]+[[:space:]][[:alpha:]]{6}$"
1.1       dsieger  8488: 
1.177     leot     8489: output_prohibit regex...
1.1       dsieger  8490: 
                   8491:     This function checks for each of its parameters if the output from do_test
                   8492:     () does not match the extended regular expression. If any of the regular
                   8493:     expressions matches, the test will fail.
                   8494: 
1.184     rillig   8495: Chapter 27. Porting pkgsrc
1.1       dsieger  8496: 
                   8497: Table of Contents
                   8498: 
1.184     rillig   8499: 27.1. Porting pkgsrc to a new operating system
1.1       dsieger  8500: 
                   8501: The pkgsrc system has already been ported to many operating systems, hardware
                   8502: architectures and compilers. This chapter explains the necessary steps to make
                   8503: pkgsrc even more portable.
                   8504: 
1.184     rillig   8505: 27.1. Porting pkgsrc to a new operating system
1.1       dsieger  8506: 
                   8507: To port pkgsrc to a new operating system (called MyOS in this example), you
                   8508: need to touch the following files:
                   8509: 
                   8510: pkgtools/bootstrap-mk-files/files/mods/MyOS.sys.mk
                   8511: 
                   8512:     This file contains some basic definitions, for example the name of the C
                   8513:     compiler.
                   8514: 
                   8515: mk/bsd.prefs.mk
                   8516: 
1.212     wiz      8517:     Insert code that defines the variables OPSYS, OS_VERSION, OPSYS_VERSION,
1.1       dsieger  8518:     LOWER_VENDOR, MACHINE_ARCH, OBJECT_FMT, APPEND_ELF, and the other variables
                   8519:     that appear in this file.
                   8520: 
                   8521: mk/platform/MyOS.mk
                   8522: 
                   8523:     This file contains the platform-specific definitions that are used by
                   8524:     pkgsrc. Start by copying one of the other files and edit it to your needs.
                   8525: 
                   8526: mk/tools/tools.MyOS.mk
                   8527: 
                   8528:     This file defines the paths to all the tools that are needed by one or the
                   8529:     other package in pkgsrc, as well as by pkgsrc itself. Find out where these
                   8530:     tools are on your platform and add them.
                   8531: 
                   8532: Now, you should be able to build some basic packages, like lang/perl5, shells/
                   8533: bash.
                   8534: 
                   8535: Appendix A. A simple example package: bison
                   8536: 
                   8537: Table of Contents
                   8538: 
                   8539: A.1. files
                   8540:     A.1.1. Makefile
                   8541:     A.1.2. DESCR
                   8542:     A.1.3. PLIST
                   8543:     A.1.4. Checking a package with pkglint
                   8544: A.2. Steps for building, installing, packaging
                   8545: 
                   8546: We checked to find a piece of software that wasn't in the packages collection,
1.25      wiz      8547: and picked GNU bison. Quite why someone would want to have bison when Berkeley 
1.1       dsieger  8548: yacc is already present in the tree is beyond us, but it's useful for the
                   8549: purposes of this exercise.
                   8550: 
                   8551: A.1. files
                   8552: 
                   8553: A.1.1. Makefile
                   8554: 
1.2       rillig   8555: # $NetBSD$
1.1       dsieger  8556: #
                   8557: 
                   8558: DISTNAME=       bison-1.25
                   8559: CATEGORIES=     devel
1.171     rillig   8560: MASTER_SITES=   ${MASTER_SITE_GNU:=bison/}
1.1       dsieger  8561: 
1.30      dholland 8562: MAINTAINER=     pkgsrc-users@NetBSD.org
1.174     leot     8563: HOMEPAGE=       https://www.gnu.org/software/bison/bison.html
1.1       dsieger  8564: COMMENT=        GNU yacc clone
                   8565: 
                   8566: GNU_CONFIGURE=  yes
1.47      wiz      8567: INFO_FILES=     yes
1.1       dsieger  8568: 
                   8569: .include "../../mk/bsd.pkg.mk"
                   8570: 
                   8571: A.1.2. DESCR
                   8572: 
                   8573: GNU version of yacc.  Can make re-entrant parsers, and numerous other
                   8574: improvements.  Why you would want this when Berkeley yacc(1) is part
                   8575: of the NetBSD source tree is beyond me.
                   8576: 
                   8577: A.1.3. PLIST
                   8578: 
1.2       rillig   8579: @comment $NetBSD$
1.1       dsieger  8580: bin/bison
                   8581: man/man1/bison.1.gz
                   8582: share/bison.simple
                   8583: share/bison.hairy
                   8584: 
                   8585: A.1.4. Checking a package with pkglint
                   8586: 
                   8587: The NetBSD package system comes with pkgtools/pkglint which helps to check the
                   8588: contents of these files. After installation it is quite easy to use, just
1.171     rillig   8589: change to the directory of the package you wish to examine and run pkglint:
1.1       dsieger  8590: 
                   8591: $ pkglint
1.171     rillig   8592: ERROR: Makefile: Each package must define its LICENSE.
                   8593: WARN: Makefile:9: HOMEPAGE should migrate from http to https.
                   8594: NOTE: PLIST:3: The .gz extension is unnecessary for manual pages.
                   8595: WARN: PLIST:5: "share/bison.hairy" should be sorted before "share/bison.simple".
                   8596: 1 error, 2 warnings and 1 note found.
                   8597: (Run "pkglint -e" to show explanations.)
                   8598: (Run "pkglint -fs" to show what can be fixed automatically.)
1.172     rillig   8599: (Run "pkglint -F" to automatically fix some issues.)
1.1       dsieger  8600: 
                   8601: Depending on the supplied command line arguments (see pkglint(1)), more checks
1.170     rillig   8602: will be performed. Use e.g. pkglint -Wall for a very thorough check.
1.1       dsieger  8603: 
                   8604: A.2. Steps for building, installing, packaging
                   8605: 
                   8606: Create the directory where the package lives, plus any auxiliary directories:
                   8607: 
                   8608: # cd /usr/pkgsrc/lang
                   8609: # mkdir bison
                   8610: # cd bison
                   8611: # mkdir patches
                   8612: 
1.184     rillig   8613: Create Makefile, DESCR and PLIST (see Chapter 12, Package components - files,
1.1       dsieger  8614: directories and contents) then continue with fetching the distfile:
                   8615: 
                   8616: # make fetch
                   8617: >> bison-1.25.tar.gz doesn't seem to exist on this system.
                   8618: >> Attempting to fetch from ftp://prep.ai.mit.edu/pub/gnu//.
                   8619: Requesting ftp://prep.ai.mit.edu/pub/gnu//bison-1.25.tar.gz (via ftp://orpheus.amdahl.com:80/)
                   8620: ftp: Error retrieving file: 500 Internal error
                   8621: 
                   8622: >> Attempting to fetch from ftp://wuarchive.wustl.edu/systems/gnu//.
                   8623: Requesting ftp://wuarchive.wustl.edu/systems/gnu//bison-1.25.tar.gz (via ftp://orpheus.amdahl.com:80/)
                   8624: ftp: Error retrieving file: 500 Internal error
                   8625: 
                   8626: >> Attempting to fetch from ftp://ftp.freebsd.org/pub/FreeBSD/distfiles//.
                   8627: Requesting ftp://ftp.freebsd.org/pub/FreeBSD/distfiles//bison-1.25.tar.gz (via ftp://orpheus.amdahl.com:80/)
                   8628: Successfully retrieved file.
                   8629: 
                   8630: Generate the checksum of the distfile into distinfo:
                   8631: 
                   8632: # make makedistinfo
                   8633: 
                   8634: Now compile:
                   8635: 
                   8636: # make
                   8637: >> Checksum OK for bison-1.25.tar.gz.
                   8638: ===>  Extracting for bison-1.25
                   8639: ===>  Patching for bison-1.25
                   8640: ===>   Ignoring empty patch directory
                   8641: ===>  Configuring for bison-1.25
                   8642: creating cache ./config.cache
                   8643: checking for gcc... cc
                   8644: checking whether we are using GNU C... yes
                   8645: checking for a BSD compatible install... /usr/bin/install -c -o bin -g bin
                   8646: checking how to run the C preprocessor... cc -E
                   8647: checking for minix/config.h... no
                   8648: checking for POSIXized ISC... no
                   8649: checking whether cross-compiling... no
                   8650: checking for ANSI C header files... yes
                   8651: checking for string.h... yes
                   8652: checking for stdlib.h... yes
                   8653: checking for memory.h... yes
                   8654: checking for working const... yes
                   8655: checking for working alloca.h... no
                   8656: checking for alloca... yes
                   8657: checking for strerror... yes
                   8658: updating cache ./config.cache
                   8659: creating ./config.status
                   8660: creating Makefile
                   8661: ===>  Building for bison-1.25
                   8662: cc -c -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MEMORY_H=1 -DHAVE_ALLOCA=1 -DHAVE_STRERROR=1 -I./../include  -g LR0.c
                   8663: cc -c -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MEMORY_H=1 -DHAVE_ALLOCA=1 -DHAVE_STRERROR=1 -I./../include  -g allocate.c
                   8664: cc -c -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MEMORY_H=1 -DHAVE_ALLOCA=1 -DHAVE_STRERROR=1 -I./../include  -g closure.c
                   8665: cc -c -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MEMORY_H=1 -DHAVE_ALLOCA=1 -DHAVE_STRERROR=1 -I./../include  -g conflicts.c
                   8666: cc -c -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MEMORY_H=1 -DHAVE_ALLOCA=1 -DHAVE_STRERROR=1 -I./../include  -g derives.c
                   8667: cc -c -DXPFILE=\"/usr/pkg/share/bison.simple\"  -DXPFILE1=\"/usr/pkg/share/bison.hairy\" -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MEMORY_H=1 -DHAVE_ALLOCA=1 -DHAVE_STRERROR=1  -g  ./files.c
                   8668: cc -c -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MEMORY_H=1 -DHAVE_ALLOCA=1 -DHAVE_STRERROR=1 -I./../include  -g getargs.c
                   8669: cc -c -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MEMORY_H=1 -DHAVE_ALLOCA=1 -DHAVE_STRERROR=1 -I./../include  -g gram.c
                   8670: cc -c -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MEMORY_H=1 -DHAVE_ALLOCA=1 -DHAVE_STRERROR=1 -I./../include  -g lalr.c
                   8671: cc -c -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MEMORY_H=1 -DHAVE_ALLOCA=1 -DHAVE_STRERROR=1 -I./../include  -g lex.c
                   8672: cc -c -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MEMORY_H=1 -DHAVE_ALLOCA=1 -DHAVE_STRERROR=1 -I./../include  -g main.c
                   8673: cc -c -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MEMORY_H=1 -DHAVE_ALLOCA=1 -DHAVE_STRERROR=1 -I./../include  -g nullable.c
                   8674: cc -c -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MEMORY_H=1 -DHAVE_ALLOCA=1 -DHAVE_STRERROR=1 -I./../include  -g output.c
                   8675: cc -c -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MEMORY_H=1 -DHAVE_ALLOCA=1 -DHAVE_STRERROR=1 -I./../include  -g print.c
                   8676: cc -c -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MEMORY_H=1 -DHAVE_ALLOCA=1 -DHAVE_STRERROR=1 -I./../include  -g reader.c
                   8677: cc -c -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MEMORY_H=1 -DHAVE_ALLOCA=1 -DHAVE_STRERROR=1 -I./../include  -g reduce.c
                   8678: cc -c -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MEMORY_H=1 -DHAVE_ALLOCA=1 -DHAVE_STRERROR=1 -I./../include  -g symtab.c
                   8679: cc -c -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MEMORY_H=1 -DHAVE_ALLOCA=1 -DHAVE_STRERROR=1 -I./../include  -g warshall.c
                   8680: cc -c -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MEMORY_H=1 -DHAVE_ALLOCA=1 -DHAVE_STRERROR=1 -I./../include  -g version.c
                   8681: cc -c -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MEMORY_H=1 -DHAVE_ALLOCA=1 -DHAVE_STRERROR=1 -I./../include  -g getopt.c
                   8682: cc -c -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MEMORY_H=1 -DHAVE_ALLOCA=1 -DHAVE_STRERROR=1 -I./../include  -g getopt1.c
                   8683: cc  -g -o bison LR0.o allocate.o closure.o conflicts.o derives.o files.o         getargs.o gram.o lalr.o lex.o                                   main.o nullable.o output.o print.o reader.o reduce.o symtab.o   warshall.o version.o getopt.o getopt1.o
                   8684: ./files.c:240: warning: mktemp() possibly used unsafely, consider using mkstemp()
                   8685: rm -f bison.s1
                   8686: sed -e "/^#line/ s|bison|/usr/pkg/share/bison|" < ./bison.simple > bison.s1
                   8687: 
                   8688: Everything seems OK, so install the files:
                   8689: 
                   8690: # make install
                   8691: >> Checksum OK for bison-1.25.tar.gz.
                   8692: ===>  Installing for bison-1.25
                   8693: sh ./mkinstalldirs /usr/pkg/bin /usr/pkg/share  /usr/pkg/info /usr/pkg/man/man1
                   8694: rm -f /usr/pkg/bin/bison
                   8695: cd /usr/pkg/share; rm -f bison.simple bison.hairy
                   8696: rm -f /usr/pkg/man/man1/bison.1 /usr/pkg/info/bison.info*
                   8697: install -c  -o bin -g bin -m 555 bison /usr/pkg/bin/bison
                   8698: /usr/bin/install -c -o bin -g bin -m 644 bison.s1 /usr/pkg/share/bison.simple
                   8699: /usr/bin/install -c -o bin -g bin -m 644 ./bison.hairy /usr/pkg/share/bison.hairy
                   8700: cd .; for f in bison.info*;  do /usr/bin/install -c -o bin -g bin -m 644 $f /usr/pkg/info/$f; done
                   8701: /usr/bin/install -c -o bin -g bin -m 644 ./bison.1 /usr/pkg/man/man1/bison.1
                   8702: ===>  Registering installation for bison-1.25
                   8703: 
                   8704: You can now use bison, and also - if you decide so - remove it with pkg_delete
                   8705: bison. Should you decide that you want a binary package, do this now:
                   8706: 
                   8707: # make package
                   8708: >> Checksum OK for bison-1.25.tar.gz.
                   8709: ===>  Building package for bison-1.25
                   8710: Creating package bison-1.25.tgz
                   8711: Registering depends:.
                   8712: Creating gzip'd tar ball in '/u/pkgsrc/lang/bison/bison-1.25.tgz'
                   8713: 
                   8714: Now that you don't need the source and object files any more, clean up:
                   8715: 
                   8716: # make clean
                   8717: ===>  Cleaning for bison-1.25
                   8718: 
1.207     leot     8719: Appendix B. Security hardening
                   8720: 
                   8721: Table of Contents
                   8722: 
                   8723: B.1. Mechanisms
                   8724:     B.1.1. Enabled by default
                   8725:     B.1.2. Not enabled by default
                   8726: B.2. Caveats
                   8727:     B.2.1. Problems with PKGSRC_MKPIE
                   8728:     B.2.2. Problems with PKGSRC_USE_FORTIFY
                   8729:     B.2.3. Problems with PKGSRC_USE_RELRO
                   8730:     B.2.4. Problems with PKGSRC_USE_SSP
                   8731: B.3. Auditing the system
                   8732:     B.3.1. Checking for PIE
                   8733:     B.3.2. Checking for partial RELRO
                   8734:     B.3.3. Checking for full RELRO
                   8735:     B.3.4. Checking for SSP
                   8736: 
                   8737: A number of mechanisms are available in pkgsrc to improve the security of the
                   8738: resulting system. This page describes the mechanisms, and gives hints about
                   8739: detecting and fixing problems.
                   8740: 
                   8741: Mechanisms can be enabled individually in mk.conf, and are individually
                   8742: described below.
                   8743: 
                   8744: Typically, a feature will cause some programs to fail to build or work when
                   8745: first enabled. This can be due to latent problems in the program, and can be
                   8746: due to other reasons. After enough testing to have confidence that user
                   8747: problems will be quite rare, individual mechanisms will be enabled by default.
                   8748: 
                   8749: For each mechanism, see the Caveats section below for an explanation of what
                   8750: might go wrong at compile time and at run time, and how to notice and address
                   8751: these problems.
                   8752: 
                   8753: B.1. Mechanisms
                   8754: 
                   8755: B.1.1. Enabled by default
                   8756: 
                   8757: B.1.1.1. PKGSRC_USE_FORTIFY
                   8758: 
                   8759: This allows substitute wrappers to be used for some commonly used library
                   8760: functions that do not have built-in bounds checking - but could in some cases.
                   8761: 
                   8762: Two mitigation levels are available:
                   8763: 
                   8764:   * "weak" only enables checks at compile-time.
                   8765: 
                   8766:   * "strong" enables checks at compile-time and runtime.
                   8767: 
                   8768: "strong" has been enabled by default since pkgsrc-2017Q3.
                   8769: 
                   8770: B.1.1.2. PKGSRC_USE_SSP
                   8771: 
                   8772: This enables a stack-smashing protection mitigation. It is done by adding a
                   8773: guard variable to functions with vulnerable objects. The guards are initialized
                   8774: when a function is entered and then checked when the function exits. The guard
                   8775: check will fail and the program forcibly exited if the variable was modified in
                   8776: the meantime. This can happen in case of buffer overflows or memory corruption,
                   8777: and therefore exposing these bugs.
                   8778: 
                   8779: Different mitigation levels are available:
                   8780: 
                   8781:   * "yes", which will only protect functions considered vulnerable by the
                   8782:     compiler;
                   8783: 
                   8784:   * "all", which will protect every function;
                   8785: 
                   8786:   * "strong", the default, which will apply a better balance between the two
                   8787:     settings above.
                   8788: 
                   8789: This mitigation is supported by both GCC and clang. It may be supported in
                   8790: additional compilers, possibly under a different name. It is particularly
                   8791: useful for unsafe programming languages, such as C/C++.
                   8792: 
                   8793:   * "yes" is enabled by default where known supported since pkgsrc-2017Q3.
                   8794: 
                   8795:   * "strong" is enabled by default where known supported since pkgsrc-2021Q4.
                   8796: 
                   8797: More details can be found here:
                   8798: 
                   8799:   * Buffer overflow protection on Wikipedia
                   8800: 
                   8801: B.1.1.3. PKGSRC_MKPIE
                   8802: 
                   8803: This requests the creation of PIE (Position Independent Executables) for all
                   8804: executables. The PIE mechanism is normally used for shared libraries, so that
                   8805: they can be loaded at differing addresses at runtime. PIE itself does not have
                   8806: useful security properties; however, it is necessary to fully leverage some,
                   8807: such as ASLR. Some operating systems support Address Space Layout Randomization
                   8808: (ASLR), which causes different addresses to be used each time a program is run.
                   8809: This makes it more difficult for an attacker to guess addresses and thus makes
                   8810: exploits harder to construct. With PIE, ASLR can really be applied to the
                   8811: entire program, instead of the stack and heap only.
                   8812: 
                   8813: PIE executables will only be built for toolchains that are known to support
                   8814: PIE. Currently, this means NetBSD on x86, ARM, SPARC64, m68k, and MIPS.
                   8815: 
                   8816: PKGSRC_MKPIE was enabled by default after the pkgsrc-2021Q3 branch.
                   8817: 
1.219     nia      8818: B.1.1.4. PKGSRC_USE_RELRO
1.207     leot     8819: 
                   8820: This also makes the exploitation of some security vulnerabilities more
                   8821: difficult in some cases.
                   8822: 
                   8823: Two different mitigation levels are available:
                   8824: 
1.219     nia      8825:   * partial (the default): the ELF sections are reordered so that internal data
                   8826:     sections precede the program's own data sections, and non-PLT GOT is
                   8827:     read-only;
1.207     leot     8828: 
                   8829:   * full: in addition to partial RELRO, every relocation is performed
1.218     nia      8830:     immediately when starting the program, allowing the entire GOT to be
                   8831:     read-only. This can greatly slow down startup of large programs.
1.207     leot     8832: 
                   8833: This is currently supported by GCC. Many software distributions now enable this
1.220     nia      8834: feature by default, at the "partial" level.
1.207     leot     8835: 
                   8836: More details can be found here:
                   8837: 
                   8838:   * Hardening ELF binaries using Relocation Read-Only (RELRO)
                   8839: 
1.219     nia      8840: B.1.2. Not enabled by default
                   8841: 
                   8842: B.1.2.1. PKGSRC_MKREPRO
                   8843: 
                   8844: With this option, pkgsrc will try to build packages reproducibly. This allows
                   8845: packages built from the same tree and with the same options, to produce
                   8846: identical results bit by bit. This option should be combined with ASLR and
                   8847: PKGSRC_MKPIE to avoid predictable address offsets for attackers attempting to
                   8848: exploit security vulnerabilities.
                   8849: 
                   8850: More details can be found here:
                   8851: 
                   8852:   * Reproducible Builds - a set of software development practices that create
                   8853:     an independently-verifiable path from source to binary code
                   8854: 
                   8855: More work likely needs to be done before pkgsrc is fully reproducible.
                   8856: 
                   8857: B.1.2.2. PKGSRC_USE_STACK_CHECK
1.207     leot     8858: 
                   8859: This uses -fstack-check with GCC for another stack protection mitigation.
                   8860: 
                   8861: It asks the compiler to generate code verifying that it does not corrupt the
                   8862: stack. According to GCC's manual page, this is really only useful for
                   8863: multi-threaded programs.
                   8864: 
                   8865: B.2. Caveats
                   8866: 
                   8867: B.2.1. Problems with PKGSRC_MKPIE
                   8868: 
                   8869: B.2.1.1. Packages failing to build
                   8870: 
                   8871: A number of packages may fail to build with this option enabled. The failures
                   8872: are often related to the absence of the -fPIC compilation flag when building
                   8873: libraries or executables (or ideally -fPIE in the latter case). This flag is
                   8874: added to the CFLAGS already, but requires the package to actually support it.
                   8875: 
                   8876: B.2.1.1.1. How to fix
                   8877: 
                   8878: These instructions are meant as a reference only; they likely need to be
                   8879: adapted for many packages individually.
                   8880: 
                   8881: For packages using Makefiles:
                   8882: 
                   8883: MAKE_FLAGS+=    CFLAGS=${CFLAGS:Q}
                   8884: MAKE_FLAGS+=    LDFLAGS=${LDFLAGS:Q}
                   8885: 
                   8886: For packages using Imakefiles:
                   8887: 
                   8888: MAKE_FLAGS+=    CCOPTIONS=${CFLAGS:Q}
                   8889: MAKE_FLAGS+=    LOCAL_LDFLAGS=${LDFLAGS:Q}
                   8890: 
                   8891: B.2.1.2. Run-time crashes
                   8892: 
                   8893: Some programs may fail to run, or crash at random times once built as PIE. Two
                   8894: scenarios are essentially possible. This is nearly always due to a bug in the
                   8895: program being exposed due to ASLR.
                   8896: 
                   8897: B.2.1.3. Disabling PKGSRC_MKPIE on a per-package basis
                   8898: 
                   8899: Ideally, packages should be fixed for compatibility with MKPIE. However, in
                   8900: some cases this is very difficult, due to complex build systems, packages using
                   8901: non-standard toolchains, or programming languages with odd bootstrapping
                   8902: mechanisms.
                   8903: 
                   8904: To disable PKGSRC_MKPIE on a per-package basis, set MKPIE_SUPPORTED= no in the
                   8905: package's Makefile before bsd.prefs.mk is included.
                   8906: 
                   8907: B.2.2. Problems with PKGSRC_USE_FORTIFY
                   8908: 
                   8909: B.2.2.1. Packages failing to build
                   8910: 
                   8911: This feature makes use of pre-processing directives to look for hardened,
                   8912: alternative implementations of essential library calls. Some programs may fail
                   8913: to build as a result; this usually happens for those trying too hard to be
                   8914: portable, or otherwise abusing definitions in the standard library.
                   8915: 
                   8916: B.2.2.2. Run-time crashes
                   8917: 
                   8918: This feature may cause some programs to crash, usually indicating an actual bug
                   8919: in the program. The fix will typically involve patching the original program's
                   8920: source code.
                   8921: 
                   8922: B.2.2.3. Optimization is required
                   8923: 
                   8924: At least in the case of GCC, FORTIFY will only be applied if optimization is
                   8925: applied while compiling. This means that the CFLAGS should also contain -O, -O2
                   8926: or another optimization level. This cannot easily be applied globally, as some
                   8927: packages may require specific optimization levels.
                   8928: 
                   8929: B.2.2.4. Disabling FORTIFY on a per-package basis
                   8930: 
                   8931: Note
                   8932: 
                   8933: FORTIFY should not be disabled to work around runtime crashes in the program!
                   8934: This is a very bad idea and will expose you to security vulnerabilities.
                   8935: 
                   8936: To disable FORTIFY on a per-package basis, set the following in the package's
                   8937: Makefile before bsd.prefs.mk is included:
                   8938: 
                   8939: FORTIFY_SUPPORTED=      no
                   8940: 
                   8941: B.2.3. Problems with PKGSRC_USE_RELRO
                   8942: 
                   8943: B.2.3.1. Performance impact
                   8944: 
                   8945: For better protection, full RELRO requires every symbol to be resolved when the
                   8946: program starts, rather than simply when required at run-time. This will have
                   8947: more impact on programs using a lot of symbols, or linked to libraries exposing
                   8948: a lot of symbols. Therefore, daemons or programs otherwise running in
                   8949: background are affected only when started. Programs loading plug-ins at
                   8950: run-time are affected when loading the plug-ins.
                   8951: 
                   8952: The impact is not expected to be noticeable on modern hardware, except in some
                   8953: cases for big programs.
                   8954: 
                   8955: B.2.3.2. Run-time crashes
                   8956: 
                   8957: Some programs handle plug-ins and dependencies in a way that conflicts with
                   8958: RELRO: for instance, with an initialization routine listing any other plug-in
                   8959: required. With full RELRO, the missing symbols are resolved before the
                   8960: initialization routine can run, and the dynamic loader will not be able to find
                   8961: them directly and abort as a result. Unfortunately, this is how Xorg loads its
                   8962: drivers. Partial RELRO can be applied instead in this case.
                   8963: 
                   8964: B.2.3.3. Disabling RELRO on a per-package basis
                   8965: 
                   8966: To disable RELRO on a per-package basis, set the following in the package's
                   8967: Makefile before bsd.prefs.mk is included:
                   8968: 
                   8969: RELRO_SUPPORTED=        no
                   8970: 
1.209     nia      8971: It is also possible to at most enable partial RELRO, by setting RELRO_SUPPORTED
                   8972: to partial.
                   8973: 
1.207     leot     8974: B.2.4. Problems with PKGSRC_USE_SSP
                   8975: 
                   8976: B.2.4.1. Packages failing to build
                   8977: 
                   8978: The stack-smashing protection provided by this option does not work for some
                   8979: programs. The most common situation in which this happens is when the program
                   8980: allocates variables on the stack, with the size determined at run-time.
                   8981: 
                   8982: B.2.4.2. Run-time crashes
                   8983: 
                   8984: Again, this feature may cause some programs to crash via a SIGABRT, usually
                   8985: indicating an actual bug in the program.
                   8986: 
                   8987: On NetBSD LOG_CRIT level syslog messages are sent and - by default - appended
                   8988: to /var/log/messages, e.g.:
                   8989: 
                   8990: Jan  6 15:42:51 hostname -: hostname program - - - buffer overflow detected; terminated
                   8991: 
                   8992: (where hostname is the hostname(1) and program is the basename(1) of the
                   8993: program crashed).
                   8994: 
                   8995: Patching the original program is then required.
                   8996: 
                   8997: Rebuilding the package via:
                   8998: 
                   8999: % env CFLAGS=-g INSTALL_UNSTRIPPED=yes make replace
                   9000: 
                   9001: and inspecting the backtrace of the coredump via the debugger should point out
                   9002: the problematic call by inspecting the frame calling the _chk() (SSP) function.
                   9003: 
                   9004: B.2.4.3. Performance impact
                   9005: 
                   9006: The compiler emits extra code when using this feature: a check for buffer
                   9007: overflows is performed when entering and exiting functions, requiring an extra
                   9008: variable on the stack. The level of protection can otherwise be adjusted to
                   9009: affect only those functions considered more sensitive by the compiler (with
                   9010: -fstack-protector instead of -fstack-protector-all).
                   9011: 
                   9012: The impact is not expected to be noticeable on modern hardware. However,
                   9013: programs with a hard requirement to run at the fastest possible speed should
                   9014: avoid using this feature, or using libraries built with this feature.
                   9015: 
                   9016: B.2.4.4. Disabling SSP on a per-package basis
                   9017: 
                   9018: Note
                   9019: 
                   9020: SSP should not be disabled to work around runtime crashes in the program! This
                   9021: is a very bad idea and will expose you to security vulnerabilities.
                   9022: 
                   9023: To disable SSP on a per-package basis, set the following in the package's
                   9024: Makefile before bsd.prefs.mk is included:
                   9025: 
                   9026: SSP_SUPPORTED=  no
                   9027: 
                   9028: B.3. Auditing the system
                   9029: 
                   9030: The illusion of security is worse than having no security at all. This section
                   9031: lists a number of ways to ensure the security features requested are actually
                   9032: effective.
                   9033: 
                   9034: These instructions were obtained and tested on a system derived from NetBSD 7
                   9035: (amd64). YMMV.
                   9036: 
                   9037: B.3.1. Checking for PIE
                   9038: 
                   9039: The ELF executable type in use changes for binaries built as PIE; without:
                   9040: 
                   9041: $ file /path/to/bin/ary
                   9042: /path/to/bin/ary: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for NetBSD 7.0, not stripped
                   9043: 
                   9044: as opposed to the following binary, built as PIE:
                   9045: 
                   9046: $ file /path/to/pie/bin/ary
                   9047: /path/to/pie/bin/ary: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for NetBSD 7.0, not stripped
                   9048: 
                   9049: The latter result is then what is expected.
                   9050: 
                   9051: B.3.2. Checking for partial RELRO
                   9052: 
                   9053: The following command should list a section called RELRO:
                   9054: 
                   9055: $ objdump -p /path/to/bin/ary
                   9056: 
                   9057: /path/to/bin/ary:     file format elf64-x86-64
                   9058: 
                   9059: Program Header:
                   9060: [...]
                   9061:    RELRO off    0x0000000000000d78 vaddr 0x0000000000600d78 paddr 0x0000000000600d78 align 2**0
                   9062: 
                   9063: This check is now performed automatically if PKG_DEVELOPER is set and RELRO is
                   9064: enabled.
                   9065: 
                   9066: B.3.3. Checking for full RELRO
                   9067: 
                   9068: The dynamic loader will apply RELRO immediately when detecting the presence of
                   9069: the BIND_NOW flag:
                   9070: 
                   9071: $ objdump -x /path/to/bin/ary
                   9072: 
                   9073: /path/to/bin/ary:     file format elf64-x86-64
                   9074: 
                   9075: Dynamic Section:
                   9076: [...]
                   9077:   BIND_NOW             0x0000000000000000
                   9078: 
                   9079: This has to be combined with partial RELRO (see above) to be fully efficient.
                   9080: 
                   9081: This check is now performed automatically (where supported) if PKG_DEVELOPER is
                   9082: set.
                   9083: 
                   9084: B.3.4. Checking for SSP
                   9085: 
1.208     nia      9086: Note
                   9087: 
                   9088: Checking for SSP using this method only works where the operating system uses
                   9089: libssp. libssp is not used on recent NetBSD/FreeBSD/Linux versions.
                   9090: 
1.207     leot     9091: Building objects, binaries and libraries with SSP will affect the presence of
                   9092: additional symbols in the resulting file:
                   9093: 
                   9094: $ nm /path/to/bin/ary
                   9095: [...]
                   9096:                  U __stack_chk_fail
                   9097: 0000000000600ea0 B __stack_chk_guard
                   9098: 
                   9099: This is an indicator that the program was indeed built with support for SSP.
                   9100: 
                   9101: This check is now performed automatically (where supported) if PKG_DEVELOPER is
                   9102: set and SSP is enabled.
                   9103: 
                   9104: Appendix C. Build logs
1.1       dsieger  9105: 
                   9106: Table of Contents
                   9107: 
1.207     leot     9108: C.1. Building figlet
                   9109: C.2. Packaging figlet
1.1       dsieger  9110: 
1.207     leot     9111: C.1. Building figlet
1.1       dsieger  9112: 
                   9113: # make
                   9114: ===> Checking for vulnerabilities in figlet-2.2.1nb2
                   9115: => figlet221.tar.gz doesn't seem to exist on this system.
                   9116: => Attempting to fetch figlet221.tar.gz from ftp://ftp.figlet.org/pub/figlet/program/unix/.
                   9117: => [172219 bytes]
                   9118: Connected to ftp.plig.net.
                   9119: 220 ftp.plig.org NcFTPd Server (licensed copy) ready.
                   9120: 331 Guest login ok, send your complete e-mail address as password.
                   9121: 230-You are user #5 of 500 simultaneous users allowed.
                   9122: 230-
                   9123: 230-  ___ _             _ _
                   9124: 230- |  _| |_ ___   ___| |_|___   ___ ___ ___
                   9125: 230- |  _|  _| . |_| . | | | . |_| . |  _| . |
                   9126: 230- |_| |_| |  _|_|  _|_|_|_  |_|___|_| |_  |
                   9127: 230-         |_|   |_|     |___|         |___|
                   9128: 230-
                   9129: 230-** Welcome to ftp.plig.org **
                   9130: 230-
                   9131: 230-Please note that all transfers from this FTP site are logged. If you
                   9132: 230-do not like this, please disconnect now.
                   9133: 230-
1.19      snj      9134: 230-This archive is available via
1.1       dsieger  9135: 230-
                   9136: 230-HTTP:  http://ftp.plig.org/
                   9137: 230-FTP:   ftp://ftp.plig.org/     (max 500 connections)
                   9138: 230-RSYNC: rsync://ftp.plig.org/   (max  30 connections)
                   9139: 230-
                   9140: 230-Please email comments, bug reports and requests for packages to be
                   9141: 230-mirrored to ftp-admin@plig.org.
                   9142: 230-
                   9143: 230-
                   9144: 230 Logged in anonymously.
                   9145: Remote system type is UNIX.
                   9146: Using binary mode to transfer files.
                   9147: 200 Type okay.
                   9148: 250 "/pub" is new cwd.
                   9149: 250-"/pub/figlet" is new cwd.
                   9150: 250-
                   9151: 250-Welcome to the figlet archive at ftp.figlet.org
                   9152: 250-
                   9153: 250-    ftp://ftp.figlet.org/pub/figlet/
                   9154: 250-
                   9155: 250-The official FIGlet web page is:
                   9156: 250-    http://www.figlet.org/
                   9157: 250-
                   9158: 250-If you have questions, please mailto:info@figlet.org. If you want to
                   9159: 250-contribute a font or something else, you can email us.
                   9160: 250
                   9161: 250 "/pub/figlet/program" is new cwd.
                   9162: 250 "/pub/figlet/program/unix" is new cwd.
                   9163: local: figlet221.tar.gz remote: figlet221.tar.gz
                   9164: 502 Unimplemented command.
                   9165: 227 Entering Passive Mode (195,40,6,41,246,104)
                   9166: 150 Data connection accepted from 84.128.86.72:65131; transfer starting for figlet221.tar.gz (172219 bytes).
                   9167: 38% |**************                       | 65800      64.16 KB/s    00:01 ETA
                   9168: 226 Transfer completed.
                   9169: 172219 bytes received in 00:02 (75.99 KB/s)
                   9170: 221 Goodbye.
                   9171: => Checksum OK for figlet221.tar.gz.
                   9172: ===> Extracting for figlet-2.2.1nb2
                   9173: ===> Required installed package ccache-[0-9]*: ccache-2.3nb1 found
                   9174: ===> Patching for figlet-2.2.1nb2
                   9175: ===> Applying pkgsrc patches for figlet-2.2.1nb2
                   9176: ===> Overriding tools for figlet-2.2.1nb2
                   9177: ===> Creating toolchain wrappers for figlet-2.2.1nb2
                   9178: ===> Configuring for figlet-2.2.1nb2
                   9179: ===> Building for figlet-2.2.1nb2
                   9180: gcc -O2 -DDEFAULTFONTDIR=\"/usr/pkg/share/figlet\"  -DDEFAULTFONTFILE=\"standard.flf\"  figlet.c zipio.c crc.c inflate.c -o figlet
                   9181: chmod a+x figlet
                   9182: gcc -O2 -o chkfont chkfont.c
                   9183: => Unwrapping files-to-be-installed.
                   9184: #
                   9185: # make install
                   9186: ===> Checking for vulnerabilities in figlet-2.2.1nb2
                   9187: ===> Installing for figlet-2.2.1nb2
                   9188: install -d -o root -g wheel -m 755 /usr/pkg/bin
                   9189: install -d -o root -g wheel -m 755 /usr/pkg/man/man6
                   9190: mkdir -p /usr/pkg/share/figlet
                   9191: cp figlet /usr/pkg/bin
                   9192: cp chkfont /usr/pkg/bin
                   9193: chmod 555 figlist showfigfonts
                   9194: cp figlist /usr/pkg/bin
                   9195: cp showfigfonts /usr/pkg/bin
                   9196: cp fonts/*.flf /usr/pkg/share/figlet
                   9197: cp fonts/*.flc /usr/pkg/share/figlet
                   9198: cp figlet.6 /usr/pkg/man/man6
                   9199: ===> Registering installation for figlet-2.2.1nb2
                   9200: #
                   9201: 
1.207     leot     9202: C.2. Packaging figlet
1.1       dsieger  9203: 
                   9204: # make package
                   9205: ===> Checking for vulnerabilities in figlet-2.2.1nb2
                   9206: ===> Packaging figlet-2.2.1nb2
                   9207: ===> Building binary package for figlet-2.2.1nb2
                   9208: Creating package /home/cvs/pkgsrc/packages/i386/All/figlet-2.2.1nb2.tgz
                   9209: Using SrcDir value of /usr/pkg
                   9210: Registering depends:.
                   9211: #
                   9212: 
1.207     leot     9213: Appendix D. Directory layout of the pkgsrc FTP server
1.1       dsieger  9214: 
                   9215: Table of Contents
                   9216: 
1.207     leot     9217: D.1. distfiles: The distributed source files
                   9218: D.2. misc: Miscellaneous things
                   9219: D.3. packages: Binary packages
                   9220: D.4. reports: Bulk build reports
                   9221: D.5. current, stable, pkgsrc-20xxQy: source packages
1.1       dsieger  9222: 
                   9223: As in other big projects, the directory layout of pkgsrc is quite complex for
                   9224: newbies. This chapter explains where you find things on the FTP server. The
                   9225: base directory on ftp.NetBSD.org is /pub/pkgsrc/. On other servers it may be
                   9226: different, but inside this directory, everything should look the same, no
                   9227: matter on which server you are. This directory contains some subdirectories,
                   9228: which are explained below.
                   9229: 
1.207     leot     9230: D.1. distfiles: The distributed source files
1.1       dsieger  9231: 
                   9232: The directory distfiles contains lots of archive files from all pkgsrc
                   9233: packages, which are mirrored here. The subdirectories are called after their
                   9234: package names and are used when the distributed files have names that don't
                   9235: explicitly contain a version number or are otherwise too generic (for example
                   9236: release.tar.gz).
                   9237: 
1.207     leot     9238: D.2. misc: Miscellaneous things
1.1       dsieger  9239: 
                   9240: This directory contains things that individual pkgsrc developers find worth
                   9241: publishing.
                   9242: 
1.207     leot     9243: D.3. packages: Binary packages
1.1       dsieger  9244: 
1.3       rillig   9245: This directory contains binary packages for the various platforms that are
                   9246: supported by pkgsrc. Each subdirectory is of the form OPSYS/ARCH/OSVERSION_TAG.
                   9247: The meaning of these variables is:
                   9248: 
                   9249:   * OPSYS is the name of the operating system for which the packages have been
1.9       rillig   9250:     built. The name is taken from the output of the uname command, so it may
                   9251:     differ from the one you are used to hear.
1.3       rillig   9252: 
1.8       rillig   9253:   * ARCH is the hardware architecture of the platform for which the packages
1.10      hubertf  9254:     have been built. It also includes the ABI (Application Binary Interface)
                   9255:     for platforms that have several of them.
1.3       rillig   9256: 
1.8       rillig   9257:   * OSVERSION is the version of the operating system. For version numbers that
                   9258:     change often (for example NetBSD-current), the often-changing part should
                   9259:     be replaced with an x, for example 4.99.x.
1.3       rillig   9260: 
1.23      jakllsch 9261:   * TAG is either 20xxQy for a stable branch, or head for packages built from
1.8       rillig   9262:     the HEAD branch. The latter should only be used when the packages are
                   9263:     updated on a regular basis. Otherwise the date from checking out pkgsrc
                   9264:     should be appended, for example head_20071015.
1.3       rillig   9265: 
                   9266: The rationale for exactly this scheme is that the pkgsrc users looking for
                   9267: binary packages can quickly click through the directories on the server and
                   9268: find the best binary packages for their machines. Since they usually know the
                   9269: operating system and the hardware architecture, OPSYS and ARCH are placed
                   9270: first. After these choices, they can select the best combination of OSVERSION
                   9271: and TAG together, since it is usually the case that packages stay compatible
                   9272: between different version of the operating system.
                   9273: 
                   9274: In each of these directories, there is a whole binary packages collection for a
                   9275: specific platform. It has a directory called All which contains all binary
                   9276: packages. Besides that, there are various category directories that contain
                   9277: symbolic links to the real binary packages.
1.1       dsieger  9278: 
1.207     leot     9279: D.4. reports: Bulk build reports
1.8       rillig   9280: 
                   9281: Here are the reports from bulk builds, for those who want to fix packages that
                   9282: didn't build on some of the platforms. The structure of subdirectories should
1.207     leot     9283: look like the one in Section D.3, "packages: Binary packages".
1.8       rillig   9284: 
1.207     leot     9285: D.5. current, stable, pkgsrc-20xxQy: source packages
1.1       dsieger  9286: 
                   9287: These directories contain the "real" pkgsrc, that is the files that define how
                   9288: to create binary packages from source archives.
                   9289: 
1.149     leot     9290: Each of the current, stable and pkgsrc-20xxQy directories share the same
                   9291: structure. They each contain a pkgsrc directory and pkgsrc.tar.{bz,gz,xz} file.
                   9292: 
1.1       dsieger  9293: The directory pkgsrc contains a snapshot of the CVS repository, which is
1.149     leot     9294: updated regularly. The file pkgsrc.tar.{bz,gz,xz} contains the same as the
                   9295: directory, ready to be downloaded as a whole.
1.1       dsieger  9296: 
1.149     leot     9297: The current directory contains files related to the HEAD branch of the CVS
                   9298: repository. In this directory there is an additional file called
                   9299: pkgsrc-readmes.tar.{bz,gz,xz} that contains all pkgsrc READMEs with information
                   9300: about categories and packages.
                   9301: 
                   9302: The stable directory is a symlink to the latest pkgsrc-20xxQy.
                   9303: 
                   9304: The pkgsrc-20xxQy. directories contain files related to the -20xxQy stable
                   9305: branch of the CVS repository. In these directories there is an additional file
                   9306: called pkgsrc-20xxQy.tar.{bz,gz,xz}, which contains the state of pkgsrc when it
                   9307: was branched.
1.148     leot     9308: 
1.207     leot     9309: Appendix E. Help topics
1.154     rillig   9310: 
                   9311: The following list contains all help topics that are available when running 
                   9312: bmake help topic=:index.
                   9313: 
1.232   ! gutterid 9314: #!                                   -lintl
        !          9315: 32bit                                64bit
        !          9316: ABI                                  ACCEPTABLE_LICENSES
        !          9317: ACROREAD_FONTPATH                    ADDITIONAL
        !          9318: AFAIK                                AIX
        !          9319: ALLOW_VULNERABLE_PACKAGES            ALL_ENV
        !          9320: ALTERNATIVES_SRC                     AMANDA_TMP
        !          9321: AMANDA_USER                          AMANDA_VAR
        !          9322: APACHE_GROUP                         APACHE_MODULE_NAME
        !          9323: APACHE_MODULE_SRC                    APACHE_MODULE_SRCDIR
        !          9324: APACHE_PKG_PREFIX                    APACHE_SUEXEC_CONFIGURE_ARGS
        !          9325: APACHE_SUEXEC_DOCROOT                APACHE_USER
        !          9326: APPEND_ABI                           APPEND_ELF
        !          9327: ARLA_CACHE                           AUDIT_PACKAGES_FLAGS
        !          9328: AUTOCONF_REQD                        AUTOMAKE_OVERRIDE
        !          9329: AUTOMAKE_REQD                        AUTO_MKDIRS
        !          9330: BDB185_DEFAULT                       BDBBASE
        !          9331: BDB_ACCEPTED                         BDB_DEFAULT
        !          9332: BDB_LIBS                             BDB_TYPE
        !          9333: BINCIMAP_GROUP                       BINCIMAP_USER
        !          9334: BIND_DIR                             BIND_GROUP
        !          9335: BIND_USER                            BINOWN
        !          9336: BINPKG_SITES                         BIN_INSTALL_FLAGS
        !          9337: BISON_PKGDATADIR                     BLAS
        !          9338: BLAS_ACCEPTED                        BLAS_C_INTERFACE
        !          9339: BLAS_INCLUDES                        BLAS_INDEX64
        !          9340: BLAS_LIBS                            BLAS_PC
        !          9341: BLAS_TYPE                            BOOTSTRAP_DEPENDS
        !          9342: BROKEN                               BROKEN_EXCEPT_ON_PLATFORM
        !          9343: BROKEN_ON_PLATFORM                   BSDSRCDIR
        !          9344: BSDXSRCDIR                           BSD_MAKE_ENV
        !          9345: BUILDLINK_AUTO_DIRS                  BUILDLINK_AUTO_VARS
        !          9346: BUILDLINK_CFLAGS                     BUILDLINK_CONTENTS_FILTER
        !          9347: BUILDLINK_CPPFLAGS                   BUILDLINK_FILES
        !          9348: BUILDLINK_FILES_CMD                  BUILDLINK_FNAME_TRANSFORM
        !          9349: BUILDLINK_LDFLAGS                    BUILDLINK_LIBS
        !          9350: BUILDLINK_OPSYS_SUPPORT_PTHREAD      BUILDLINK_PKGNAME
        !          9351: BUILDLINK_PREFIX                     BUILDLINK_RPATHDIRS
        !          9352: BUILDLINK_TREE                       BUILD_DEFS
        !          9353: BUILD_DEFS_EFFECTS                   BUILD_DEPENDS
        !          9354: BUILD_DIRS                           BUILD_ENV_SHELL
        !          9355: BUILD_MAKE_CMD                       BUILD_MAKE_FLAGS
        !          9356: BUILD_TARGET                         BUILTIN_FIND_FILES
        !          9357: BUILTIN_FIND_FILES_VAR               BUILTIN_FIND_GREP
        !          9358: BUILTIN_FIND_HEADERS                 BUILTIN_FIND_HEADERS_VAR
        !          9359: BUILTIN_FIND_PKGCONFIG               BUILTIN_FIND_PKGCONFIG_VAR
        !          9360: BUILTIN_PKG                          BUILTIN_TEST_CURSES_DEFINES
        !          9361: BUILTIN_TEST_CURSES_FUNCS            BUILTIN_VERSION_SCRIPT
        !          9362: BUILTIN_X11_TYPE                     BUILTIN_X11_VERSION
        !          9363: CACTI_GROUP                          CACTI_USER
        !          9364: CANNA_GROUP                          CANNA_USER
        !          9365: CAT                                  CBLAS_LIBS
        !          9366: CBLAS_PC                             CCACHE_BASE
        !          9367: CCACHE_DIR                           CCACHE_LOGFILE
        !          9368: CC_VERSION                           CC_VERSION_STRING
        !          9369: CDRECORD_CONF                        CDROM_PKG_URL_DIR
        !          9370: CDROM_PKG_URL_HOST                   CHANGES
        !          9371: CHECK_COMPILER                       CHECK_FAKEHOME
        !          9372: CHECK_FILES                          CHECK_FILES_SKIP
        !          9373: CHECK_FILES_STRICT                   CHECK_HEADERS
        !          9374: CHECK_HEADERS_SKIP                   CHECK_INTERPRETER
        !          9375: CHECK_INTERPRETER_SKIP               CHECK_PERMS
        !          9376: CHECK_PERMS_AUTOFIX                  CHECK_PERMS_SKIP
        !          9377: CHECK_PIE                            CHECK_PIE_SKIP
        !          9378: CHECK_PIE_SUPPORTED                  CHECK_PORTABILITY
        !          9379: CHECK_PORTABILITY_EXPERIMENTAL       CHECK_PORTABILITY_SKIP
        !          9380: CHECK_RELRO                          CHECK_RELRO_SKIP
        !          9381: CHECK_RELRO_SUPPORTED                CHECK_SHLIBS
        !          9382: CHECK_SHLIBS_SKIP                    CHECK_SHLIBS_SUPPORTED
        !          9383: CHECK_SHLIBS_TOXIC                   CHECK_SSP
        !          9384: CHECK_SSP_SKIP                       CHECK_SSP_SUPPORTED
        !          9385: CHECK_STRIPPED                       CHECK_STRIPPED_SKIP
        !          9386: CHECK_WRKREF                         CHECK_WRKREF_EXTRA_DIRS
        !          9387: CHECK_WRKREF_SKIP                    CLAMAV_DBDIR
        !          9388: CLAMAV_GROUP                         CLAMAV_USER
        !          9389: CLANGBASE                            CLEANDEPENDS
        !          9390: CMAKE_DEPENDENCIES_REWRITE           CMAKE_INSTALL_NAME_DIR
        !          9391: CMAKE_INSTALL_PREFIX                 CMAKE_MODULE_PATH_OVERRIDE
        !          9392: CMAKE_PKGSRC_BUILD_FLAGS             CMAKE_PREFIX_PATH
        !          9393: CMAKE_USE_GNU_INSTALL_DIRS           COMPILER_RPATH_FLAG
        !          9394: COMPILER_USE_SYMLINKS                CONFIGURE_ARGS
        !          9395: CONFIGURE_DIRS                       CONFIGURE_ENV
        !          9396: CONFIGURE_ENV_SHELL                  CONFIGURE_HAS_INFODIR
        !          9397: CONFIGURE_HAS_MANDIR                 CONFIGURE_SCRIPT
        !          9398: CONFIG_SHELL                         CONFIG_SHELL_FLAGS
        !          9399: CONF_FILES                           CONF_FILES_MODE
        !          9400: CONF_FILES_PERMS                     CONSERVER_DEFAULTHOST
        !          9401: CONSERVER_DEFAULTPORT                CP
        !          9402: CPE                                  CPE_EDITION
        !          9403: CPE_LANG                             CPE_OTHER
        !          9404: CPE_PART                             CPE_PRODUCT
        !          9405: CPE_SW_EDITION                       CPE_TARGET_HW
        !          9406: CPE_TARGET_SW                        CPE_UPDATE
        !          9407: CPE_URI                              CPE_VENDOR
        !          9408: CPE_VERSION                          CPP
        !          9409: CPP_PRECOMP_FLAGS                    CREATE_WRKDIR_SYMLINK
        !          9410: CROSSBASE                            CTFCONVERT
        !          9411: CTF_FILES_SKIP                       CTF_SUPPORTED
        !          9412: CTYPE                                CUPS_GROUP
        !          9413: CUPS_SYSTEM_GROUPS                   CUPS_USER
        !          9414: CURSES_DEFAULT                       CURSES_TYPE
        !          9415: CXX                                  CYRUS_GROUP
        !          9416: CYRUS_IDLE                           CYRUS_USER
        !          9417: DAEMONTOOLS_GROUP                    DAEMONTOOLS_LOG_USER
        !          9418: DARWIN_NO_SYSTEM_LIBS                DARWIN_REQUIRES_FILTER
        !          9419: DBUS_GROUP                           DBUS_USER
        !          9420: DEFANG_GROUP                         DEFANG_USER
        !          9421: DEFAULT_ACCEPTABLE_LICENSES          DEFAULT_DISTFILES
        !          9422: DEFAULT_IRC_SERVER                   DEFAULT_SERIAL_DEVICE
        !          9423: DEF_UMASK                            DEINSTALLDEPENDS
        !          9424: DEINSTALL_SRC                        DEINSTALL_TEMPLATES
        !          9425: DELAYED_ERROR_MSG                    DELAYED_WARNING_MSG
        !          9426: DEPENDS                              DEPENDS_TARGET
        !          9427: DEPENDS_TYPE                         DESTDIR
        !          9428: DESTDIR_VARNAME                      DIALER_GROUP
        !          9429: DIGEST_REQD                          DISTDIR
        !          9430: DISTFILES                            DISTINFO_FILE
        !          9431: DISTNAME                             DIST_PATH
        !          9432: DIST_SUBDIR                          DJBDNS_AXFR_USER
        !          9433: DJBDNS_CACHE_USER                    DJBDNS_DJBDNS_GROUP
        !          9434: DJBDNS_LOG_USER                      DJBDNS_RBL_USER
        !          9435: DJBDNS_TINY_USER                     DLOPEN_REQUIRE_PTHREADS
        !          9436: DL_AUTO_VARS                         DL_CFLAGS
        !          9437: DL_LDFLAGS                           DL_LIBS
        !          9438: DNS                                  DOCOWN
        !          9439: DOWNLOADED_DISTFILE                  DQCACHE_GROUP
        !          9440: DQCACHE_USER                         DT_LAYOUT
        !          9441: DYNAMIC_SITES_CMD                    DYNAMIC_SITES_SCRIPT
        !          9442: ECHO                                 ECHO_N
        !          9443: ELK_GUI                              EMACS_TYPE
        !          9444: EMULDIR                              EMULSUBDIR
        !          9445: EMULSUBDIRSLASH                      EMUL_ARCH
        !          9446: EMUL_DISTRO                          EMUL_EXEC_FMT
        !          9447: EMUL_IS_NATIVE                       EMUL_MODULES
        !          9448: EMUL_OPSYS                           EMUL_PKG_FMT
        !          9449: EMUL_PLATFORM                        EMUL_PLATFORMS
        !          9450: EMUL_PREFER                          EMUL_REQD
        !          9451: EMUL_TYPE                            ERROR_MSG
        !          9452: EXIM_GROUP                           EXIM_USER
        !          9453: EXPORT_SYMBOLS_LDFLAGS               EXTRACTOR
        !          9454: EXTRACT_CMD                          EXTRACT_CMD_DEFAULT
        !          9455: EXTRACT_DIR                          EXTRACT_ELEMENTS
        !          9456: EXTRACT_ENV                          EXTRACT_ONLY
        !          9457: EXTRACT_OPTS                         EXTRACT_SUFX
        !          9458: EXTRACT_USING                        FAIL
        !          9459: FAILOVER_FETCH                       FAIL_MSG
        !          9460: FAKE_NCURSES                         FAM
        !          9461: FAM_ACCEPTED                         FAM_DEFAULT
        !          9462: FAM_SERVER                           FCPATH
        !          9463: FEATURE_CPPFLAGS                     FEATURE_LDFLAGS
        !          9464: FEATURE_LIBS                         FETCH_AFTER_ARGS
        !          9465: FETCH_BEFORE_ARGS                    FETCH_CMD
        !          9466: FETCH_OUTPUT_ARGS                    FETCH_PROXY
        !          9467: FETCH_RESUME_ARGS                    FETCH_TIMEOUT
        !          9468: FETCH_USE_IPV4_ONLY                  FETCH_USING
        !          9469: FILES_SUBST                          FILES_SUBST_SED
        !          9470: FIX_SYSTEM_HEADERS                   FONTS_DIRS
        !          9471: FONTS_VERBOSE                        FOO_HACKS_MK
        !          9472: FOX_USE_XUNICODE                     FREEWNN_GROUP
        !          9473: FREEWNN_USER                         FTP_PKG_URL_DIR
        !          9474: FTP_PKG_URL_HOST                     GAMEDATAMODE
        !          9475: GAMEDATA_PERMS                       GAMEDIRMODE
        !          9476: GAMEDIR_PERMS                        GAMEGRP
        !          9477: GAMEMODE                             GAMEOWN
        !          9478: GAMES_GROUP                          GAMES_USER
        !          9479: GCC                                  GCCBASE
        !          9480: GCC_REQD                             GCC_VERSION_SUFFIX
        !          9481: GEM_BUILD                            GEM_CLEANBUILD
        !          9482: GEM_CLEANBUILD_EXTENSIONS            GEM_DOCDIR
        !          9483: GEM_EXTSDIR                          GEM_HOME
        !          9484: GEM_KEEPBUILD                        GEM_LIBDIR
        !          9485: GEM_NAME                             GEM_PATH
        !          9486: GEM_PLUGINSDIR                       GEM_SPECFILE
        !          9487: GENERATE_PLIST                       GHC
        !          9488: GHOSTSCRIPT_REQD                     GITHUB_PROJECT
        !          9489: GITHUB_RELEASE                       GITHUB_SUBMODULES
        !          9490: GITHUB_TAG                           GITHUB_TYPE
        !          9491: GITLAB_PROJECT                       GITLAB_RELEASE
        !          9492: GITLAB_SUBMODULES                    GITLAB_TAG
        !          9493: GITLAB_TYPE                          GNU
        !          9494: GNU_CONFIGURE                        GNU_CONFIGURE_INFODIR
        !          9495: GNU_CONFIGURE_MANDIR                 GNU_CONFIGURE_QUIET
        !          9496: GNU_CONFIGURE_STRICT                 GODEP_REDIRECTS
        !          9497: GO_BUILD_PATTERN                     GO_DEPS
        !          9498: GO_DIST_BASE                         GO_EXTRA_MOD_DIRS
        !          9499: GO_MODULE_FILES                      GO_SRCPATH
        !          9500: GROUP_SPECIFIC_PKGS                  GRUB_NETWORK_CARDS
        !          9501: GRUB_PRESET_COMMAND                  GRUB_SCAN_ARGS
        !          9502: GZIP                                 HASKELL_ENABLE_DYNAMIC_EXECUTABLE
        !          9503: HASKELL_ENABLE_HADDOCK_DOCUMENTATION HASKELL_ENABLE_LIBRARY_PROFILING
        !          9504: HASKELL_ENABLE_SHARED_LIBRARY        HASKELL_OPTIMIZATION_LEVEL
        !          9505: HASKELL_PKG_NAME                     HASKELL_UNRESTRICT_DEPENDENCIES
        !          9506: HAS_CONFIGURE                        HEADER_TEMPLATES
        !          9507: HOMEPAGE                             HOST_PKGTOOLS_ARGS
        !          9508: HOST_SPECIFIC_PKGS                   HOWL_GROUP
        !          9509: HOWL_USER                            ICCBASE
        !          9510: ICECAST_CHROOTDIR                    ICON_THEMES
        !          9511: IDOBASE                              IGNORE_CCACHE
        !          9512: IGNORE_INFO_DIRS                     IGNORE_INTERACTIVE_FETCH
        !          9513: IMAKE                                IMAKEOPTS
        !          9514: IMAKE_MAKE                           IMAKE_MANINSTALL
        !          9515: IMAP_UW_CCLIENT_MBOX_FMT             IMDICTDIR
        !          9516: INCOMPAT_CURSES                      INFO_DIR
        !          9517: INFO_FILES                           INFO_FILES_VERBOSE
        !          9518: INFO_MSG                             INIT_SYSTEM
        !          9519: INN_DATA_DIR                         INN_GROUP
        !          9520: INN_USER                             INSTALLATION_DIRS
        !          9521: INSTALLATION_DIRS_FROM_PLIST         INSTALL_ENV
        !          9522: INSTALL_SH_OVERRIDE                  INSTALL_SRC
        !          9523: INSTALL_TEMPLATES                    INSTALL_UNSTRIPPED
        !          9524: IRCD_HYBRID_IRC_GROUP                IRCD_HYBRID_IRC_USER
        !          9525: IRCD_HYBRID_MAXCONN                  IRCD_HYBRID_NICLEN
        !          9526: IRCD_HYBRID_SYSLOG_EVENTS            IRCD_HYBRID_SYSLOG_FACILITY
        !          9527: IRCD_HYBRID_TOPICLEN                 IRIX
        !          9528: IRRD_USE_PGP                         JABBERD_GROUP
        !          9529: JABBERD_LOGDIR                       JABBERD_PIDDIR
        !          9530: JABBERD_SPOOLDIR                     JABBERD_USER
        !          9531: JAVA_BINPREFIX                       JAVA_CLASSPATH
        !          9532: JAVA_HOME                            JAVA_LD_LIBRARY_PATH
        !          9533: JAVA_NAME                            JAVA_UNLIMIT
        !          9534: JAVA_WRAPPERS                        JPEG_ACCEPTED
        !          9535: JPEG_DEFAULT                         KERBEROS
        !          9536: KERMIT_SUID_UUCP                     KJS_USE_PCRE
        !          9537: KNEWS_DOMAIN_FILE                    KNEWS_DOMAIN_NAME
        !          9538: KRB5_ACCEPTED                        KRB5_DEFAULT
        !          9539: LANGUAGES                            LAPACKE_LIBS
        !          9540: LAPACKE_PC                           LAPACK_LIBS
        !          9541: LAPACK_PC                            LATEX2HTML_ICONPATH
        !          9542: LDCONFIG_ADD_CMD                     LDCONFIG_REMOVE_CMD
        !          9543: LDD                                  LEAFNODE_DATA_DIR
        !          9544: LEAFNODE_GROUP                       LEAFNODE_USER
        !          9545: LIBDVDCSS_HOMEPAGE                   LIBDVDCSS_MASTER_SITES
        !          9546: LIBRSVG_TYPE                         LIBTOOL
        !          9547: LIBTOOLIZE_PLIST                     LIBTOOL_M4_OVERRIDE
        !          9548: LIBUSB_TYPE                          LICENSE
        !          9549: LINKER_RPATH_FLAG                    LINK_RPATH_FLAG
        !          9550: LINUX_LOCALES                        LOCALBASE
        !          9551: LOCALBASE_LOCKTYPE                   LOCALPATCHES
        !          9552: LOVE_DATA                            LOVE_GAME
        !          9553: LOVE_VERSION                         LP32PLATFORMS
        !          9554: LP64PLATFORMS                        LUA_BUSTED_ARGS
        !          9555: LUA_CDIR                             LUA_COMPILER
        !          9556: LUA_DOCDIR                           LUA_EXAMPLESDIR
        !          9557: LUA_INCDIR                           LUA_INTERPRETER
        !          9558: LUA_LDIR                             LUA_LINKER_MAGIC
        !          9559: LUA_PKGPREFIX                        LUA_SELF_CONFLICT
        !          9560: LUA_USE_BUSTED                       LUA_VERSIONS_ACCEPTED
        !          9561: LUA_VERSIONS_INCOMPATIBLE            LUA_VERSION_DEFAULT
        !          9562: LUA_VERSION_REQD                     Lua
        !          9563: MACHINE_PLATFORM                     MAILAGENT_DOMAIN
        !          9564: MAILAGENT_EMAIL                      MAILAGENT_FQDN
        !          9565: MAILAGENT_ORGANIZATION               MAJORDOMO_HOMEDIR
        !          9566: MAKEINFO_ARGS                        MAKE_DIRS
        !          9567: MAKE_DIRS_PERMS                      MAKE_ENV
        !          9568: MAKE_FILE                            MAKE_FLAGS
        !          9569: MAKE_JOBS                            MAKE_JOBS_SAFE
        !          9570: MAKE_PROGRAM                         MANCOMPRESSED_IF_MANZ
        !          9571: MANINSTALL                           MANZ
        !          9572: MASTER_SITES                         MASTER_SITE_BACKUP
        !          9573: MASTER_SITE_LOCAL                    MASTER_SITE_MOZILLA
        !          9574: MASTER_SITE_OVERRIDE                 MASTER_SITE_PERL_CPAN
        !          9575: MASTER_SORT                          MASTER_SORT_RANDOM
        !          9576: MASTER_SORT_REGEX                    MECAB_CHARSET
        !          9577: MEDIATOMB_GROUP                      MEDIATOMB_USER
        !          9578: MIPSPROBASE                          MIREDO_GROUP
        !          9579: MIREDO_USER                          MISSING_FEATURES
        !          9580: MKDIR                                MKPIE_SUPPORTED
        !          9581: MLDONKEY_GROUP                       MLDONKEY_HOME
        !          9582: MLDONKEY_USER                        MONOTONE_GROUP
        !          9583: MONOTONE_USER                        MOTIFBASE
        !          9584: MOTIF_TYPE                           MOTIF_TYPE_DEFAULT
        !          9585: MPI_TYPE                             MSGFMT_STRIP_MSGCTXT
        !          9586: MSGFMT_STRIP_MSGID_PLURAL            MTOOLS_ENABLE_FLOPPYD
        !          9587: MV                                   MYSQL_CHARSET
        !          9588: MYSQL_DATADIR                        MYSQL_EXTRA_CHARSET
        !          9589: MYSQL_GROUP                          MYSQL_USER
        !          9590: MYSQL_VERSION                        MYSQL_VERSIONS_ACCEPTED
        !          9591: MYSQL_VERSIONS_ALL                   MYSQL_VERSION_DEFAULT
        !          9592: NAGIOSCMD_GROUP                      NAGIOSDIR
        !          9593: NAGIOS_GROUP                         NAGIOS_USER
        !          9594: NATIVE_APPEND_ABI                    NATIVE_APPEND_ELF
        !          9595: NATIVE_EXEC_FMT                      NATIVE_MACHINE_PLATFORM
        !          9596: NATIVE_OBJECT_FMT                    NBPAX_PROGRAM_PREFIX
        !          9597: NETBSD_LOGIN_NAME                    NMH_EDITOR
        !          9598: NMH_MTA                              NMH_PAGER
        !          9599: NODE_VERSIONS_ACCEPTED               NODE_VERSIONS_INCOMPATIBLE
        !          9600: NODE_VERSION_DEFAULT                 NODE_VERSION_REQD
        !          9601: NOLOGIN                              NOTE
        !          9602: NOT_FOR_PLATFORM                     NOT_PAX_ASLR_SAFE
        !          9603: NOT_PAX_MPROTECT_SAFE                NO_BUILD
        !          9604: NO_CHECKSUM                          NO_CONFIGURE
        !          9605: NO_SKIP                              NS_PREFERRED
        !          9606: NULLMAILER_GROUP                     NULLMAILER_USER
        !          9607: OASIS                                OASIS_BUILD_ARGS
        !          9608: OBJHOSTNAME                          OBJMACHINE
        !          9609: OCAML_FINDLIB_DIRS                   OCAML_FINDLIB_REGISTER
        !          9610: OCAML_FINDLIB_REGISTER_VERBOSE       OCAML_SITELIBDIR
        !          9611: OCAML_TOPKG_DOCDIR                   OCAML_USE_DUNE
        !          9612: OCAML_USE_FINDLIB                    OCAML_USE_OASIS
        !          9613: OCAML_USE_OASIS_DYNRUN               OCAML_USE_OPAM
        !          9614: OCAML_USE_TOPKG                      OMF
        !          9615: ONLY_FOR_COMPILER                    ONLY_FOR_PLATFORM
        !          9616: OPENSSH_CHROOT                       OPENSSH_GROUP
        !          9617: OPENSSH_USER                         OPSYS
        !          9618: OPSYS_EMULDIR                        OPSYS_VERSION
        !          9619: OS                                   OSS_TYPE
        !          9620: OSX                                  OSX_TOLERATE_SDK_SKEW
        !          9621: OS_VARIANT                           OS_VERSION
        !          9622: OTF_FONTS_DIR                        OVERRIDE_DIRDEPTH
        !          9623: OVERRIDE_GEMSPEC                     OVERRIDE_GNU_CONFIG_SCRIPTS
        !          9624: OWN_DIRS                             OWN_DIRS_PERMS
        !          9625: P4GROUP                              P4PORT
        !          9626: P4ROOT                               P4USER
        !          9627: PACKAGES                             PALMOS_DEFAULT_SDK
        !          9628: PAMBASE                              PAM_DEFAULT
        !          9629: PAPERSIZE                            PASSIVE_FETCH
        !          9630: PATCHDIR                             PATCHFILES
        !          9631: PATCH_ARGS                           PATCH_DEBUG
        !          9632: PATCH_DIST_ARGS                      PATCH_DIST_CAT
        !          9633: PATCH_DIST_STRIP                     PATCH_FUZZ_FACTOR
        !          9634: PATCH_STRIP                          PATH
        !          9635: PCCBASE                              PEAR_CMD
        !          9636: PEAR_LIB                             PEAR_PACKAGE_XML
        !          9637: PERL5                                PERL5_CONFIGURE
        !          9638: PERL5_CONFIGURE_DIRS                 PERL5_LDFLAGS
        !          9639: PERL5_LICENSE                        PERL5_MODULE_TYPE
        !          9640: PERL5_PACKLIST                       PERL5_PACKLIST_DIR
        !          9641: PERL5_PERLBASE                       PERL5_SITEBASE
        !          9642: PERL5_USE_PACKLIST                   PERL5_VENDORBASE
        !          9643: PFCTL                                PFVAR_H
        !          9644: PF_VERSION                           PGGROUP
        !          9645: PGHOME                               PGPKGSRCDIR
        !          9646: PGSQL_TYPE                           PGSQL_VERSION
        !          9647: PGSQL_VERSIONS_ACCEPTED              PGSQL_VERSION_DEFAULT
        !          9648: PGUSER                               PG_LIB_EXT
        !          9649: PHP                                  PHPCOMMON_MK
        !          9650: PHPPKGSRCDIR                         PHP_BASE_VERS
        !          9651: PHP_CHECK_INSTALLED                  PHP_EXTENSION_DIR
        !          9652: PHP_INITIAL_TEENY                    PHP_PKG_PREFIX
        !          9653: PHP_VERSION                          PHP_VERSIONS_ACCEPTED
        !          9654: PHP_VERSIONS_INCOMPATIBLE            PHP_VERSION_DEFAULT
        !          9655: PHP_VERSION_REQD                     PILRC_USE_GTK
        !          9656: PKGCONFIG_BASE                       PKGCONFIG_FILE
        !          9657: PKGCONFIG_OVERRIDE                   PKGCONFIG_OVERRIDE_STAGE
        !          9658: PKGDIR                               PKGGNUDIR
        !          9659: PKGINFODIR                           PKGLOCALEDIR
        !          9660: PKGMANDIR                            PKGNAME
        !          9661: PKGNAME_REQD                         PKGPATH
        !          9662: PKGREVISION                          PKGSRC_BLAS_TYPES
        !          9663: PKGSRC_CHANGES                       PKGSRC_COMPILER
        !          9664: PKGSRC_KEEP_BIN_PKGS                 PKGSRC_LOCKTYPE
        !          9665: PKGSRC_MAKE_ENV                      PKGSRC_MESSAGE_RECIPIENTS
        !          9666: PKGSRC_MKPIE                         PKGSRC_MKREPRO
        !          9667: PKGSRC_OVERRIDE_MKPIE                PKGSRC_RUN_TEST
        !          9668: PKGSRC_SETENV                        PKGSRC_SLEEPSECS
        !          9669: PKGSRC_TODO                          PKGSRC_USE_CTF
        !          9670: PKGSRC_USE_FORTIFY                   PKGSRC_USE_MKTOOLS
        !          9671: PKGSRC_USE_RELRO                     PKGSRC_USE_SSP
        !          9672: PKGSRC_USE_STACK_CHECK               PKGTASKS_DATAFILE
        !          9673: PKGTOOLS_ARGS                        PKGTOOLS_ENV
        !          9674: PKG_ALTERNATIVES                     PKG_APACHE
        !          9675: PKG_APACHE_ACCEPTED                  PKG_APACHE_DEFAULT
        !          9676: PKG_BEST_EXISTS                      PKG_BUILD_OPTIONS
        !          9677: PKG_COMPRESSION                      PKG_CONFIG
        !          9678: PKG_CONFIG_PERMS                     PKG_CREATE_USERGROUP
        !          9679: PKG_DB_TMPDIR                        PKG_DEBUG_LEVEL
        !          9680: PKG_DEFAULT_OPTIONS                  PKG_DESTDIR_SUPPORT
        !          9681: PKG_DEVELOPER                        PKG_DISABLED_OPTIONS
        !          9682: PKG_FATAL_ERRORS                     PKG_FC
        !          9683: PKG_FILELIST_CMD                     PKG_GECOS
        !          9684: PKG_GID                              PKG_GROUPS
        !          9685: PKG_GROUPS_VARS                      PKG_HOME
        !          9686: PKG_INIT_SCRIPTS                     PKG_JAVA_HOME
        !          9687: PKG_JVM                              PKG_JVMS_ACCEPTED
        !          9688: PKG_JVM_DEFAULT                      PKG_LEGACY_OPTIONS
        !          9689: PKG_LIBTOOL                          PKG_MKSYMLINKS
        !          9690: PKG_OPTIONS                          PKG_OPTIONS_DEPRECATED_WARNINGS
        !          9691: PKG_OPTIONS_LEGACY_OPTS              PKG_OPTIONS_LEGACY_VARS
        !          9692: PKG_OPTIONS_NONEMPTY_SETS            PKG_OPTIONS_OPTIONAL_GROUPS
        !          9693: PKG_OPTIONS_REQUIRED_GROUPS          PKG_OPTIONS_VAR
        !          9694: PKG_PHP                              PKG_PHP_MAJOR_VERS
        !          9695: PKG_PHP_VERSION                      PKG_RCD_SCRIPTS
        !          9696: PKG_REFCOUNT_DBDIR                   PKG_REGISTER_SHELLS
        !          9697: PKG_RESUME_TRANSFERS                 PKG_SHELL
        !          9698: PKG_SUGGESTED_OPTIONS                PKG_SUPPORTED_OPTIONS
        !          9699: PKG_SYSCONFBASE                      PKG_SYSCONFBASEDIR
        !          9700: PKG_SYSCONFDIR                       PKG_SYSCONFDIR_PERMS
        !          9701: PKG_SYSCONFSUBDIR                    PKG_SYSCONFVAR
        !          9702: PKG_TOOLS_BIN                        PKG_UID
        !          9703: PKG_UPDATE_FONTS_DB                  PKG_USERS
        !          9704: PKG_USERS_VARS                       PKG_VERBOSE
        !          9705: PLEASE                               PLIST
        !          9706: PLIST_AWK                            PLIST_AWK_ENV
        !          9707: PLIST_SRC                            PLIST_SUBST
        !          9708: PLIST_TYPE                           PLIST_VARS
        !          9709: POPTOP_USE_MPPE                      POSSIBLE_GFORTRAN_VERSION
        !          9710: POST_FETCH_HOOK                      PREFER
        !          9711: PREFER_NATIVE                        PREFER_NATIVE_PTHREADS
        !          9712: PREFER_PKGSRC                        PREFIX
        !          9713: PREPEND_PATH                         PRE_ROOT_CMD
        !          9714: PRIVILEGED_STAGES                    PS
        !          9715: PTHREAD_AUTO_VARS                    PTHREAD_CFLAGS
        !          9716: PTHREAD_LDFLAGS                      PTHREAD_LIBS
        !          9717: PTHREAD_OPTS                         PTHREAD_TYPE
        !          9718: PVM_SSH                              PYPKGPREFIX
        !          9719: PYTHON_FOR_BUILD_ONLY                PYTHON_SELF_CONFLICT
        !          9720: PYTHON_VERSIONED_DEPENDENCIES        PYTHON_VERSIONS_ACCEPTED
        !          9721: PYTHON_VERSIONS_INCOMPATIBLE         PYTHON_VERSION_DEFAULT
        !          9722: PYTHON_VERSION_REQD                  PYVERSSUFFIX
        !          9723: QMAILDIR                             QMAIL_ALIAS_USER
        !          9724: QMAIL_DAEMON_USER                    QMAIL_LOG_USER
        !          9725: QMAIL_NOFILES_GROUP                  QMAIL_PASSWD_USER
        !          9726: QMAIL_QMAIL_GROUP                    QMAIL_QUEUE_DIR
        !          9727: QMAIL_QUEUE_EXTRA                    QMAIL_QUEUE_USER
        !          9728: QMAIL_REMOTE_USER                    QMAIL_ROOT_USER
        !          9729: QMAIL_SEND_USER                      QORE_LATEST_MODULE_API
        !          9730: QORE_MODULE_API                      QORE_MODULE_DIR
        !          9731: QORE_USER_MODULE_DIR                 QORE_VERSION
        !          9732: QPOPPER_FAC                          QPOPPER_SPOOL_DIR
        !          9733: QPOPPER_USER                         RAKE_NAME
        !          9734: RASMOL_DEPTH                         RCD_SCRIPTS
        !          9735: RCD_SCRIPTS_DIR                      RCD_SCRIPTS_EXAMPLEDIR
        !          9736: RCD_SCRIPTS_MODE                     RCD_SCRIPTS_SHELL
        !          9737: RCD_SCRIPT_SRC                       RDOC
        !          9738: READLINE_DEFAULT                     READLINE_TYPE
        !          9739: REAL_ROOT_GROUP                      REAL_ROOT_USER
        !          9740: RECURSIVE_MAKE                       RELAY_CTRL_DIR
        !          9741: RELRO_SUPPORTED                      REPLACE_AWK
        !          9742: REPLACE_BASH                         REPLACE_CSH
        !          9743: REPLACE_KSH                          REPLACE_LUA
        !          9744: REPLACE_NODEJS                       REPLACE_OCTAVE
        !          9745: REPLACE_PERL                         REPLACE_PERL6
        !          9746: REPLACE_PHP                          REPLACE_PYTHON
        !          9747: REPLACE_QORE                         REPLACE_R
        !          9748: REPLACE_RUBY                         REPLACE_RUBY_DIRS
        !          9749: REPLACE_RUBY_PAT                     REPLACE_SH
        !          9750: REPLACE_TEXLUA                       REPLACE_WISH
        !          9751: REQD_DIRS                            REQD_DIRS_PERMS
        !          9752: REQD_FILES                           REQD_FILES_MODE
        !          9753: REQD_FILES_PERMS                     RESOLV_AUTO_VARS
        !          9754: RESOLV_LDFLAGS                       RESOLV_LIBS
        !          9755: RM                                   ROOT_CMD
        !          9756: ROOT_GROUP                           ROOT_USER
        !          9757: RPCGEN                               RPM
        !          9758: RPM2PKG_PLIST                        RPM2PKG_PREFIX
        !          9759: RPM2PKG_STAGE                        RPM2PKG_STRIP
        !          9760: RPM2PKG_SUBPREFIX                    RPMFILES
        !          9761: RPMIGNOREPATH                        RPM_DB_PREFIX
        !          9762: RSSH_CVS_PATH                        RSSH_RDIST_PATH
        !          9763: RSSH_RSYNC_PATH                      RSSH_SCP_PATH
        !          9764: RSSH_SFTP_SERVER_PATH                RUBY
        !          9765: RUBYGEM                              RUBYGEM_MANPAGES
        !          9766: RUBYGEM_NAME                         RUBYGEM_OPTIONS
        !          9767: RUBYGEM_USE_MANPAGES                 RUBYGEM_VERBOSE
        !          9768: RUBY_ABI_VERSION                     RUBY_ARCH
        !          9769: RUBY_ARCHINC                         RUBY_ARCHLIB
        !          9770: RUBY_BASE                            RUBY_BASERIDIR
        !          9771: RUBY_BUILD_DOCUMENT                  RUBY_DLEXT
        !          9772: RUBY_DOC                             RUBY_DYNAMIC_DIRS
        !          9773: RUBY_EG                              RUBY_ENCODING_ARG
        !          9774: RUBY_EXTCONF                         RUBY_EXTCONF_CHECK
        !          9775: RUBY_EXTCONF_DEBUG                   RUBY_EXTCONF_MAKEFILE
        !          9776: RUBY_GEM_ARCH                        RUBY_GEM_BASE
        !          9777: RUBY_INC                             RUBY_LIB
        !          9778: RUBY_LIB_BASE                        RUBY_NAME
        !          9779: RUBY_NOVERSION                       RUBY_PKGPREFIX
        !          9780: RUBY_RAILS                           RUBY_RAILS52_VERSION
        !          9781: RUBY_RAILS60_VERSION                 RUBY_RAILS61_VERSION
        !          9782: RUBY_RAILS70_VERSION                 RUBY_RAILS_ACCEPTED
        !          9783: RUBY_RAILS_DEFAULT                   RUBY_RAILS_REQD
        !          9784: RUBY_RAILS_STRICT_DEP                RUBY_RIDIR
        !          9785: RUBY_SETUP                           RUBY_SHLIB
        !          9786: RUBY_SHLIBALIAS                      RUBY_SHLIBVER
        !          9787: RUBY_SIMPLE_INSTALL                  RUBY_SITEARCHLIB
        !          9788: RUBY_SITELIB                         RUBY_SITELIB_BASE
        !          9789: RUBY_SITERIDIR                       RUBY_SLEXT
        !          9790: RUBY_SRCDIR                          RUBY_STATICLIB
        !          9791: RUBY_SUFFIX                          RUBY_SYSRIDIR
        !          9792: RUBY_USE_PTHREAD                     RUBY_VENDORARCHLIB
        !          9793: RUBY_VENDORLIB                       RUBY_VENDORLIB_BASE
        !          9794: RUBY_VER                             RUBY_VERSION
        !          9795: RUBY_VERSIONS_ACCEPTED               RUBY_VERSIONS_INCOMPATIBLE
        !          9796: RUBY_VERSION_DEFAULT                 RUBY_VERSION_REQD
        !          9797: RUBY_VER_DIR                         RUN
        !          9798: RUN_LDCONFIG                         RUST_TYPE
        !          9799: SCO                                  SCREWS_GROUP
        !          9800: SCREWS_USER                          SCRIPTS_ENV
        !          9801: SCROLLKEEPER_DATADIR                 SCROLLKEEPER_REBUILDDB
        !          9802: SCROLLKEEPER_UPDATEDB                SDIST_PAWD
        !          9803: SDL12_TYPE                           SERIAL_DEVICES
        !          9804: SETGIDGAME                           SETGID_GAMES_PERMS
        !          9805: SETUID_ROOT_PERMS                    SH
        !          9806: SHLIB                                SIGN_PACKAGES
        !          9807: SILC_CLIENT_WITH_PERL                SITE_SPECIFIC_PKGS
        !          9808: SKIP_DEPENDS                         SMF_INSTANCES
        !          9809: SMF_MANIFEST                         SMF_METHODS
        !          9810: SMF_METHOD_SHELL                     SMF_METHOD_SRC
        !          9811: SMF_NAME                             SMF_PREFIX
        !          9812: SMF_SRCDIR                           SNIPROXY_GROUP
        !          9813: SNIPROXY_USER                        SOURCE_BUFFSIZE
        !          9814: SPECIAL_PERMS                        SPECIFIC_PKGS
        !          9815: SSH_SUID                             SSP_SUPPORTED
        !          9816: SSYNC_PAWD                           STEP_MSG
        !          9817: STRIP                                STRIP_DBG
        !          9818: STRIP_DEBUG                          STRIP_DEBUG_SUPPORTED
        !          9819: STRIP_FILES_SKIP                     SU
        !          9820: SUBDIR                               SUBST
        !          9821: SUBST_CLASSES                        SUBST_FILES
        !          9822: SUBST_FILTER_CMD                     SUBST_MESSAGE
        !          9823: SUBST_NOOP_OK                        SUBST_SED
        !          9824: SUBST_SHOW_DIFF                      SUBST_SKIP_TEXT_CHECK
        !          9825: SUBST_STAGE                          SUBST_VARS
        !          9826: SUNWSPROBASE                         SUSE_PREFER
        !          9827: SU_CMD                               SYSCONFBASE
        !          9828: TARGET_ARCH                          TBL
        !          9829: TERMCAP_TYPE                         TERMINFO_DEFAULT
        !          9830: TERMINFO_TYPE                        TEST
        !          9831: TEST_DEPENDS                         TEST_DIRS
        !          9832: TEST_ENV                             TEST_ENV_SHELL
        !          9833: TEST_MAKE_CMD                        TEST_MAKE_FLAGS
        !          9834: TEST_TARGET                          TEXLIVE_IGNORE_PATTERNS
        !          9835: TEXLIVE_REV                          TEXLIVE_UNVERSIONED
        !          9836: TEXMFSITE                            TEX_FORMATS
        !          9837: TEX_HYPHEN_DAT                       TEX_HYPHEN_DEF
        !          9838: TEX_TEXMF_DIRS                       THTTPD_LOG_FACILITY
        !          9839: TINYDYN_USER                         TLSWRAPPER_CHROOT
        !          9840: TO                                   TOOLS_ALIASES
        !          9841: TOOLS_ALWAYS_WRAP                    TOOLS_ARGS
        !          9842: TOOLS_BROKEN                         TOOLS_CMD
        !          9843: TOOLS_CMDLINE_SED                    TOOLS_CREATE
        !          9844: TOOLS_CROSS_DESTDIR                  TOOLS_DIR
        !          9845: TOOLS_FAIL                           TOOLS_GNU_MISSING
        !          9846: TOOLS_LDCONFIG                       TOOLS_NOOP
        !          9847: TOOLS_PATH                           TOOLS_SCRIPT
        !          9848: TOOLS_USE_CROSS_COMPILE              TOOL_DEPENDS
        !          9849: TTF_FONTS_DIR                        TYPE
        !          9850: UAC_REQD_EXECS                       UCSPI_SSL_GROUP
        !          9851: UCSPI_SSL_USER                       UNLIMIT_RESOURCES
        !          9852: UNPRIVILEGED                         UNPRIVILEGED_GROUP
        !          9853: UNPRIVILEGED_GROUPS                  UNPRIVILEGED_USER
        !          9854: UNWRAP_FILES                         UNWRAP_PATTERNS
        !          9855: UPDATE_GEMSPEC                       UPDATE_TARGET
        !          9856: URI                                  USERGROUP_PHASE
        !          9857: USERPPP_GROUP                        USER_SPECIFIC_PKGS
        !          9858: USE_ABI_DEPENDS                      USE_APR
        !          9859: USE_BSD_MAKEFILE                     USE_BUILTIN
        !          9860: USE_CROSS_COMPILE                    USE_CURSES
        !          9861: USE_CWRAPPERS                        USE_DB185
        !          9862: USE_FEATURES                         USE_GAMESGROUP
        !          9863: USE_GCC_RUNTIME                      USE_IMAKE
        !          9864: USE_JAVA                             USE_JAVA2
        !          9865: USE_LANGUAGES                        USE_LIBTOOL
        !          9866: USE_NATIVE_GCC                       USE_NETBSD_REPO
        !          9867: USE_PKGSRC_GCC                       USE_PKGSRC_GCC_RUNTIME
        !          9868: USE_PKGTASKS                         USE_PKG_ADMIN_DIGEST
        !          9869: USE_RUBY_EXTCONF                     USE_RUBY_INSTALL
        !          9870: USE_RUBY_SETUP                       USE_RUBY_SETUP_PKG
        !          9871: USE_TOOLS                            UUCP_GROUP
        !          9872: UUCP_USER                            VARBASE
        !          9873: VARNAME                              VIM_EXTRA_OPTS
        !          9874: WARNING_MSG                          WCALC_CGIDIR
        !          9875: WCALC_CGIPATH                        WCALC_HTMLDIR
        !          9876: WCALC_HTMLPATH                       WDM_MANAGERS
        !          9877: WRAPPER_CC                           WRAPPER_REORDER_CMDS
        !          9878: WRKDIR                               WRKDIR_BASENAME
        !          9879: WRKDIR_LOCKTYPE                      WRKLOG
        !          9880: WRKOBJDIR                            WRKSRC
        !          9881: X10_PORT                             X11
        !          9882: X11BASE                              X11_PKGSRCDIR
        !          9883: X11_TYPE                             X509_CERTIFICATE
        !          9884: X509_KEY                             XAW_TYPE
        !          9885: XLOCK_DEFAULT_MODE                   XMKMF
        !          9886: XMKMF_FLAGS                          XXX
        !          9887: YES                                  ZSH_STATIC
        !          9888: __stdc__                             _vargroups
        !          9889: accept                               acquire-localbase-lock
        !          9890: acquire-lock                         add
        !          9891: added                                administrator
        !          9892: alloca                               alternatives
        !          9893: aslr                                 asprintf
        !          9894: atlas                                autoconf
        !          9895: automake                             autoreconf
        !          9896: awk                                  bash
        !          9897: big-endian                           bin-install
        !          9898: bind                                 binpkg-list
        !          9899: blas                                 bootstrap-depends
        !          9900: broken                               broken_on_platform
        !          9901: bsd                                  bsd.prog.mk
        !          9902: build                                build-env
        !          9903: buildlink-directories                buildlink-oss-soundcard-h
        !          9904: c                                    c++
        !          9905: ccache                               cce
        !          9906: cdefs                                ceil
        !          9907: changes                              changes-entry
        !          9908: changes-entry-noupdate               check
        !          9909: check-clean                          check-files
        !          9910: check-files-clean                    check-vulnerable
        !          9911: checksum                             checksum-phase
        !          9912: clean                                clean-depends
        !          9913: cleandir                             commit
        !          9914: commit-changes-entry                 compact
        !          9915: compiler                             conf
        !          9916: config.guess                         config.sub
        !          9917: configuration                        configure
        !          9918: configure-env                        configure-help
        !          9919: configure_args                       connect
        !          9920: cos                                  cpe
        !          9921: cputime                              create-usergroup
        !          9922: csh                                  ctf
        !          9923: debug                                declaration
        !          9924: declare                              defined
        !          9925: depend                               dependencies
        !          9926: depends                              depends-checksum
        !          9927: depends-fetch                        deps
        !          9928: describe                             destdir
        !          9929: disable                              distclean
        !          9930: distinfo                             dl
        !          9931: dlopen                               do-buildlink
        !          9932: do-clean                             do-configure
        !          9933: do-configure-post-hook               do-extract
        !          9934: do-fetch                             do-install
        !          9935: emul                                 emul-distinfo
        !          9936: emul-fetch                           emulation
        !          9937: emulator                             enable
        !          9938: endian                               enomem
        !          9939: ensurepip                            err
        !          9940: errx                                 etc
        !          9941: exp                                  extract-rpm
        !          9942: fabs                                 feature
        !          9943: features                             fetch
        !          9944: fetch-list                           follows
        !          9945: forbids                              form
        !          9946: format                               fortify
        !          9947: fortify_source                       friend
        !          9948: fts                                  fts_close
        !          9949: fts_open                             fts_read
        !          9950: fts_set                              gcc
        !          9951: gethostbyaddr                        gethostbyname
        !          9952: gethostbyname2                       getopt_long
        !          9953: getprogname                          getservbyname
        !          9954: getservbyport                        getservent
        !          9955: gettext                              github
        !          9956: gitlab                               glob
        !          9957: gnu                                  gnu_configure_strict
        !          9958: go                                   go-deps
        !          9959: golang                               guess-license
        !          9960: hashbang                             heimdal
        !          9961: help                                 imake
        !          9962: increment                            indirect
        !          9963: inet_aton                            interp
        !          9964: interpreter                          intl
        !          9965: ip4                                  ip6
        !          9966: ipv4                                 ipv6
        !          9967: iso                                  kerberos
        !          9968: krb                                  krb5
        !          9969: ksh                                  lapack
        !          9970: latex                                libintl_bindtextdomain
        !          9971: libintl_gettext                      libintl_textdomain
        !          9972: libnbcompat                          libs
        !          9973: libtool                              licence
        !          9974: license                              lintl
        !          9975: little-endian                        lock
        !          9976: locking                              lua
        !          9977: lvalue                               make
        !          9978: makesum                              memory
        !          9979: meta                                 meta-package
        !          9980: meta_package                         mit-krb5
        !          9981: mk.conf                              mkl
        !          9982: mount                                move
        !          9983: moved                                mprotect
        !          9984: mremap                               nb
        !          9985: nbcompat                             netlib
        !          9986: node                                 node.js
        !          9987: nodejs                               obstack
        !          9988: obstack_ptr_grow                     occurs
        !          9989: only                                 openblas
        !          9990: options                              options.mk
        !          9991: order                                override
        !          9992: override-intltool                    override-message-intltool
        !          9993: package                              parallel
        !          9994: path                                 pax
        !          9995: paxctl                               pbulk-index
        !          9996: pc                                   perl
        !          9997: perl5                                perms
        !          9998: php                                  pkg-build-options
        !          9999: pkg-config                           pkg_build_options
        !          10000: platform                             plist
        !          10001: post-extract                         post-fetch
        !          10002: post-wrapper                         pre-build-checks-hook
        !          10003: pre-configure                        pre-configure-checks-hook
        !          10004: pre-extract                          pre-fetch
        !          10005: print-go-deps                        print-plist
        !          10006: print-summary-data                   privileged-install-hook
        !          10007: pypi                                 python
        !          10008: r                                    readme-all
        !          10009: recursive                            recv
        !          10010: recvfrom                             regcomp
        !          10011: release-localbase-lock               release-lock
        !          10012: relro                                remove
        !          10013: removed                              rename
        !          10014: renamed                              reorder
        !          10015: replace                              replace_interpreter
        !          10016: reproducible                         resolv
        !          10017: root                                 ruby
        !          10018: send                                 sendfile
        !          10019: sendto                               setenv
        !          10020: setgid                               setprogname
        !          10021: setuid                               sh
        !          10022: shebang                              show
        !          10023: show-all                             show-build-defs
        !          10024: show-depends                         show-depends-dirs
        !          10025: show-depends-pkgpaths                show-depends-recursive
        !          10026: show-deps                            show-distfiles
        !          10027: show-downlevel                       show-subdir-var
        !          10028: show-tools                           show-var
        !          10029: show-vars                            snprintf
        !          10030: socket                               ssp
        !          10031: st_mode                              stage-install
        !          10032: strcasestr                           strict
        !          10033: strip                                strndup
        !          10034: strnlen                              strsep
        !          10035: subst                                substitutions
        !          10036: sun                                  sunpro
        !          10037: sunwspro                             symlink
        !          10038: test                                 test-env
        !          10039: tex                                  texlive
        !          10040: tmp                                  todo
        !          10041: tool                                 tools
        !          10042: tools-libtool-m4-override            transitive
        !          10043: type                                 ulimit
        !          10044: undefined                            undo-replace
        !          10045: unlimit                              unprivileged
        !          10046: unprivileged-install-hook            unstripped
        !          10047: update                               updated
        !          10048: upload                               upload-distfiles
        !          10049: use_tools                            user
        !          10050: utimes                               vasprintf
        !          10051: verbose                              vsnprintf
        !          10052: warn                                 warning
        !          10053: warnings                             warnx
        !          10054: wattr_off                            wattr_on
        !          10055: work                                 wrapper
        !          10056: wrkdir                                
1.154     rillig   10057: 
1.207     leot     10058: Appendix F. Editing guidelines for the pkgsrc guide
1.1       dsieger  10059: 
                   10060: Table of Contents
                   10061: 
1.207     leot     10062: F.1. Make targets
                   10063: F.2. Procedure
1.1       dsieger  10064: 
                   10065: This section contains information on editing the pkgsrc guide itself.
                   10066: 
1.207     leot     10067: F.1. Make targets
1.1       dsieger  10068: 
                   10069: The pkgsrc guide's source code is stored in pkgsrc/doc/guide/files, and several
                   10070: files are created from it:
                   10071: 
                   10072:   * pkgsrc/doc/pkgsrc.txt
                   10073: 
                   10074:   * pkgsrc/doc/pkgsrc.html
                   10075: 
1.174     leot     10076:   * https://www.NetBSD.org/docs/pkgsrc/
1.1       dsieger  10077: 
1.174     leot     10078:   * https://www.NetBSD.org/docs/pkgsrc/pkgsrc.pdf: The PDF version of the
                   10079:     pkgsrc guide.
1.1       dsieger  10080: 
1.174     leot     10081:   * https://www.NetBSD.org/docs/pkgsrc/pkgsrc.ps: PostScript version of the
1.2       rillig   10082:     pkgsrc guide.
1.1       dsieger  10083: 
1.207     leot     10084: F.2. Procedure
1.1       dsieger  10085: 
                   10086: The procedure to edit the pkgsrc guide is:
                   10087: 
1.190     bacon    10088:  1. Make sure you have checked out the htdocs repository into a sibling
                   10089:     directory of your pkgsrc directory. You will need the ability to commit
                   10090:     from both pkgsrc and htdocs.
                   10091: 
                   10092:  2. Make sure you have the packages needed to regenerate the pkgsrc guide (and
1.46      obache   10093:     other XML-based NetBSD documentation) installed. These are automatically
                   10094:     installed when you install the meta-pkgs/pkgsrc-guide-tools package.
1.1       dsieger  10095: 
1.190     bacon    10096:  3. Run cd doc/guide to get to the right directory. All further steps will take
1.1       dsieger  10097:     place here.
                   10098: 
1.190     bacon    10099:  4. Edit the XML file(s) in files/.
1.1       dsieger  10100: 
1.190     bacon    10101:  5. Run bmake to check the pkgsrc guide for valid XML and to build the final
1.1       dsieger  10102:     output files. If you get any errors at this stage, you can just edit the
                   10103:     files, as there are only symbolic links in the working directory, pointing
                   10104:     to the files in files/.
                   10105: 
1.190     bacon    10106:  6. (cd files && cvs commit)
1.1       dsieger  10107: 
1.190     bacon    10108:  7. Run bmake clean && bmake to regenerate the output files with the proper RCS
1.1       dsieger  10109:     Ids.
                   10110: 
1.190     bacon    10111:  8. Run bmake regen to install and commit the files in both pkgsrc/doc and
1.1       dsieger  10112:     htdocs.
                   10113: 
                   10114:     Note
                   10115: 
                   10116:     If you have added, removed or renamed some chapters, you need to
                   10117:     synchronize them using cvs add or cvs delete in the htdocs directory.
                   10118: 

CVSweb <webmaster@jp.NetBSD.org>