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

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.213     jnemeth    15: Copyright   1994-2022 The NetBSD Foundation, Inc
1.1       dsieger    16: 
1.213     jnemeth    17: $NetBSD: pkgsrc.xml,v 1.41 2022/01/01 06:45:38 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: 
                     32:     1.1. Introduction
                     33: 
                     34:         1.1.1. Why pkgsrc?
                     35:         1.1.2. Supported platforms
                     36: 
                     37:     1.2. Overview
                     38:     1.3. Terminology
                     39: 
                     40:         1.3.1. Roles involved in pkgsrc
                     41: 
                     42:     1.4. Typography
                     43: 
                     44: I. The pkgsrc user's guide
                     45: 
1.154     rillig     46:     2. Getting help
                     47:     3. Where to get pkgsrc and how to keep it up-to-date
1.1       dsieger    48: 
1.154     rillig     49:         3.1. Getting pkgsrc for the first time
1.1       dsieger    50: 
1.154     rillig     51:             3.1.1. As tar archive
                     52:             3.1.2. Via anonymous CVS
1.1       dsieger    53: 
1.154     rillig     54:         3.2. Keeping pkgsrc up-to-date
1.1       dsieger    55: 
1.154     rillig     56:             3.2.1. Via tar files
                     57:             3.2.2. Via CVS
1.1       dsieger    58: 
1.154     rillig     59:     4. Using pkgsrc on systems other than NetBSD
1.1       dsieger    60: 
1.154     rillig     61:         4.1. Binary distribution
                     62:         4.2. Bootstrapping pkgsrc
1.1       dsieger    63: 
1.154     rillig     64:     5. Using pkgsrc
1.1       dsieger    65: 
1.154     rillig     66:         5.1. Using binary packages
1.1       dsieger    67: 
1.154     rillig     68:             5.1.1. Finding binary packages
                     69:             5.1.2. Installing binary packages
1.202     nia        70:             5.1.3. Updating packages
                     71:             5.1.4. Deinstalling packages
                     72:             5.1.5. Getting information about installed packages
                     73:             5.1.6. Checking for security vulnerabilities in installed packages
                     74:             5.1.7. Finding if newer versions of your installed packages are in
1.1       dsieger    75:                 pkgsrc
1.202     nia        76:             5.1.8. Other administrative functions
1.1       dsieger    77: 
1.154     rillig     78:         5.2. Building packages from source
1.1       dsieger    79: 
1.154     rillig     80:             5.2.1. Requirements
                     81:             5.2.2. Fetching distfiles
                     82:             5.2.3. How to build and install
1.1       dsieger    83: 
1.154     rillig     84:     6. Configuring pkgsrc
1.1       dsieger    85: 
1.154     rillig     86:         6.1. General configuration
                     87:         6.2. Variables affecting the build process
                     88:         6.3. Variables affecting the installation process
                     89:         6.4. Selecting and configuring the compiler
1.1       dsieger    90: 
1.154     rillig     91:             6.4.1. Selecting the compiler
                     92:             6.4.2. Additional flags to the compiler (CFLAGS)
                     93:             6.4.3. Additional flags to the linker (LDFLAGS)
1.1       dsieger    94: 
1.154     rillig     95:         6.5. Developer/advanced settings
                     96:         6.6. Selecting Build Options
1.1       dsieger    97: 
1.154     rillig     98:     7. Creating binary packages
1.1       dsieger    99: 
1.154     rillig    100:         7.1. Building a single binary package
                    101:         7.2. Settings for creation of binary packages
1.1       dsieger   102: 
1.154     rillig    103:     8. Creating binary packages for everything in pkgsrc (bulk builds)
1.6       rillig    104: 
1.154     rillig    105:         8.1. Preparations
1.180     rillig    106:         8.2. Running a bulk build
1.6       rillig    107: 
1.154     rillig    108:             8.2.1. Configuration
1.6       rillig    109: 
1.154     rillig    110:         8.3. Requirements of a full bulk build
1.178     rillig    111:         8.4. Bulk build variants
1.6       rillig    112: 
1.179     rillig    113:             8.4.1. Detect unknown configure options
                    114:             8.4.2. Detect classes of bugs by forcing compiler warnings
1.181     rillig    115:             8.4.3. Force compiler options only in the build phase
                    116:             8.4.4. Use custom directories
                    117:             8.4.5. Turn warnings into errors
                    118:             8.4.6. Reject packages for which pkglint reports errors
                    119:             8.4.7. Reject packages that contain forbidden strings
                    120:             8.4.8. Reject packages whose self-test fails
                    121:             8.4.9. Reject packages that use undefined shell variables
                    122:             8.4.10. Turn off verbose logging
1.178     rillig    123: 
                    124:         8.5. Creating a multiple CD-ROM packages collection
                    125: 
                    126:             8.5.1. Example of cdpack
1.6       rillig    127: 
1.154     rillig    128:     9. Directory layout of the installed files
1.6       rillig    129: 
1.154     rillig    130:         9.1. File system layout in ${LOCALBASE}
                    131:         9.2. File system layout in ${VARBASE}
1.6       rillig    132: 
1.154     rillig    133:     10. Frequently Asked Questions
1.6       rillig    134: 
1.154     rillig    135:         10.1. Are there any mailing lists for pkg-related discussion?
                    136:         10.2. Utilities for package management (pkgtools)
                    137:         10.3. How to use pkgsrc as non-root
                    138:         10.4. How to resume transfers when fetching distfiles?
                    139:         10.5. How can I install/use modular X.org from pkgsrc?
                    140:         10.6. How to fetch files from behind a firewall
                    141:         10.7. How to fetch files from HTTPS sites
                    142:         10.8. How do I tell make fetch to do passive FTP?
                    143:         10.9. How to fetch all distfiles at once
                    144:         10.10. What does "Don't know how to make /usr/share/tmac/tmac.andoc"
1.24      wiz       145:             mean?
1.154     rillig    146:         10.11. What does "Could not find bsd.own.mk" mean?
1.221     nia       147:         10.12. Using 'sudo' or `priv` with pkgsrc
1.154     rillig    148:         10.13. How do I change the location of configuration files?
                    149:         10.14. Automated security checks
                    150:         10.15. Why do some packages ignore my CFLAGS?
                    151:         10.16. A package does not build. What shall I do?
                    152:         10.17. What does "Makefile appears to contain unresolved cvs/rcs/???
1.24      wiz       153:             merge conflicts" mean?
1.1       dsieger   154: 
                    155: II. The pkgsrc developer's guide
                    156: 
1.154     rillig    157:     11. Getting help
1.184     rillig    158:     12. Package components - files, directories and contents
1.1       dsieger   159: 
1.184     rillig    160:         12.1. Makefile
                    161:         12.2. distinfo
                    162:         12.3. patches/*
1.1       dsieger   163: 
1.184     rillig    164:             12.3.1. Structure of a single patch file
                    165:             12.3.2. Creating patch files
                    166:             12.3.3. Sources where the patch files come from
                    167:             12.3.4. Patching guidelines
                    168:             12.3.5. Feedback to the author
1.1       dsieger   169: 
1.184     rillig    170:         12.4. Other mandatory files
                    171:         12.5. Optional files
1.1       dsieger   172: 
1.184     rillig    173:             12.5.1. Files affecting the binary package
                    174:             12.5.2. Files affecting the build process
                    175:             12.5.3. Files affecting nothing at all
1.1       dsieger   176: 
1.184     rillig    177:         12.6. work*
                    178:         12.7. files/*
1.1       dsieger   179: 
1.184     rillig    180:     13. The build process
1.1       dsieger   181: 
1.184     rillig    182:         13.1. Introduction
                    183:         13.2. Program location
                    184:         13.3. Directories used during the build process
                    185:         13.4. Running a phase
                    186:         13.5. The fetch phase
1.1       dsieger   187: 
1.184     rillig    188:             13.5.1. What to fetch and where to get it from
                    189:             13.5.2. How are the files fetched?
1.1       dsieger   190: 
1.184     rillig    191:         13.6. The checksum phase
                    192:         13.7. The extract phase
                    193:         13.8. The patch phase
                    194:         13.9. The tools phase
                    195:         13.10. The wrapper phase
                    196:         13.11. The configure phase
                    197:         13.12. The build phase
                    198:         13.13. The test phase
                    199:         13.14. The install phase
                    200:         13.15. The package phase
                    201:         13.16. Cleaning up
                    202:         13.17. Other helpful targets
1.1       dsieger   203: 
1.184     rillig    204:     14. Creating a new pkgsrc package from scratch
1.1       dsieger   205: 
1.184     rillig    206:         14.1. Common types of packages
1.1       dsieger   207: 
1.219     nia       208:             14.1.1. Python modules and programs
                    209:             14.1.2. R packages
                    210:             14.1.3. TeXlive packages
1.1       dsieger   211: 
1.184     rillig    212:         14.2. Examples
1.1       dsieger   213: 
1.184     rillig    214:             14.2.1. How the www/nvu package came into pkgsrc
1.1       dsieger   215: 
1.184     rillig    216:     15. Programming in Makefiles
1.1       dsieger   217: 
1.184     rillig    218:         15.1. Caveats
                    219:         15.2. Makefile variables
1.1       dsieger   220: 
1.184     rillig    221:             15.2.1. Naming conventions
1.1       dsieger   222: 
1.184     rillig    223:         15.3. Code snippets
1.1       dsieger   224: 
1.184     rillig    225:             15.3.1. Adding things to a list
                    226:             15.3.2. Echoing a string exactly as-is
                    227:             15.3.3. Passing CFLAGS to GNU configure scripts
                    228:             15.3.4. Handling possibly empty variables
1.229   ! gutterid  229:             15.3.5. Testing yes/no variables in conditions
1.1       dsieger   230: 
1.184     rillig    231:     16. Options handling
1.1       dsieger   232: 
1.184     rillig    233:         16.1. Global default options
                    234:         16.2. Converting packages to use bsd.options.mk
                    235:         16.3. Option Names
                    236:         16.4. Determining the options of dependencies
1.1       dsieger   237: 
1.184     rillig    238:     17. Tools needed for building or running
1.1       dsieger   239: 
1.184     rillig    240:         17.1. Tools for pkgsrc builds
                    241:         17.2. Tools needed by packages
                    242:         17.3. Tools provided by platforms
1.1       dsieger   243: 
1.184     rillig    244:     18. Buildlink methodology
1.1       dsieger   245: 
1.184     rillig    246:         18.1. Converting packages to use buildlink3
                    247:         18.2. Writing buildlink3.mk files
1.1       dsieger   248: 
1.184     rillig    249:             18.2.1. Anatomy of a buildlink3.mk file
                    250:             18.2.2. Updating BUILDLINK_API_DEPENDS.pkg and
                    251:                 BUILDLINK_ABI_DEPENDS.pkg in buildlink3.mk files
1.1       dsieger   252: 
1.184     rillig    253:         18.3. Writing builtin.mk files
1.1       dsieger   254: 
1.184     rillig    255:             18.3.1. Anatomy of a builtin.mk file
                    256:             18.3.2. Global preferences for native or pkgsrc software
1.1       dsieger   257: 
1.184     rillig    258:     19. PLIST issues
1.1       dsieger   259: 
1.184     rillig    260:         19.1. RCS ID
                    261:         19.2. Semi-automatic PLIST generation
                    262:         19.3. Tweaking output of make print-PLIST
                    263:         19.4. Variable substitution in PLIST
                    264:         19.5. Man page compression
                    265:         19.6. Changing PLIST source with PLIST_SRC
                    266:         19.7. Platform-specific and differing PLISTs
                    267:         19.8. Build-specific PLISTs
                    268:         19.9. Sharing directories between packages
1.1       dsieger   269: 
1.184     rillig    270:     20. The pkginstall framework
1.1       dsieger   271: 
1.184     rillig    272:         20.1. Files and directories outside the installation prefix
1.1       dsieger   273: 
1.184     rillig    274:             20.1.1. Directory manipulation
                    275:             20.1.2. File manipulation
1.1       dsieger   276: 
1.184     rillig    277:         20.2. Configuration files
1.1       dsieger   278: 
1.184     rillig    279:             20.2.1. How PKG_SYSCONFDIR is set
                    280:             20.2.2. Telling the software where configuration files are
                    281:             20.2.3. Patching installations
                    282:             20.2.4. Disabling handling of configuration files
1.1       dsieger   283: 
1.184     rillig    284:         20.3. System startup scripts
1.1       dsieger   285: 
1.184     rillig    286:             20.3.1. Disabling handling of system startup scripts
1.1       dsieger   287: 
1.184     rillig    288:         20.4. System users and groups
                    289:         20.5. System shells
1.1       dsieger   290: 
1.184     rillig    291:             20.5.1. Disabling shell registration
1.1       dsieger   292: 
1.184     rillig    293:         20.6. Fonts
1.1       dsieger   294: 
1.184     rillig    295:             20.6.1. Disabling automatic update of the fonts databases
1.1       dsieger   296: 
1.154     rillig    297:     21. Making your package work
1.1       dsieger   298: 
1.154     rillig    299:         21.1. General operation
1.1       dsieger   300: 
1.154     rillig    301:             21.1.1. How to pull in user-settable variables from mk.conf
                    302:             21.1.2. User interaction
                    303:             21.1.3. Handling licenses
                    304:             21.1.4. Restricted packages
                    305:             21.1.5. Handling dependencies
                    306:             21.1.6. Handling conflicts with other packages
                    307:             21.1.7. Packages that cannot or should not be built
                    308:             21.1.8. Packages which should not be deleted, once installed
                    309:             21.1.9. Handling packages with security problems
                    310:             21.1.10. How to handle incrementing versions when fixing an
1.1       dsieger   311:                 existing package
1.154     rillig    312:             21.1.11. Substituting variable text in the package files (the SUBST
1.1       dsieger   313:                 framework)
                    314: 
1.154     rillig    315:         21.2. The fetch phase
1.1       dsieger   316: 
1.154     rillig    317:             21.2.1. Packages whose distfiles aren't available for plain
1.1       dsieger   318:                 downloading
1.154     rillig    319:             21.2.2. How to handle modified distfiles with the 'old' name
                    320:             21.2.3. Packages hosted on github.com
1.1       dsieger   321: 
1.154     rillig    322:         21.3. The configure phase
1.1       dsieger   323: 
1.154     rillig    324:             21.3.1. Shared libraries - libtool
                    325:             21.3.2. Using libtool on GNU packages that already support libtool
                    326:             21.3.3. GNU Autoconf/Automake
1.223     nia       327:             21.3.4. Meson / ninja
1.154     rillig    328: 
                    329:         21.4. Programming languages
                    330: 
                    331:             21.4.1. C, C++, and Fortran
                    332:             21.4.2. Java
1.205     wiz       333:             21.4.3. Go
1.223     nia       334:             21.4.4. Rust
                    335:             21.4.5. Packages containing Perl scripts
                    336:             21.4.6. Packages containing shell scripts
                    337:             21.4.7. Other programming languages
1.154     rillig    338: 
                    339:         21.5. The build phase
                    340: 
                    341:             21.5.1. Compiling C and C++ code conditionally
                    342:             21.5.2. How to handle compiler bugs
1.172     rillig    343:             21.5.3. No such file or directory
                    344:             21.5.4. Undefined reference to "..."
                    345:             21.5.5. Running out of memory
1.154     rillig    346: 
                    347:         21.6. The install phase
                    348: 
                    349:             21.6.1. Creating needed directories
                    350:             21.6.2. Where to install documentation
                    351:             21.6.3. Installing highscore files
                    352:             21.6.4. Adding DESTDIR support to packages
                    353:             21.6.5. Packages with hardcoded paths to other interpreters
1.203     nia       354:             21.6.6. Packages installing Perl modules
1.154     rillig    355:             21.6.7. Packages installing info files
                    356:             21.6.8. Packages installing man pages
1.203     nia       357:             21.6.9. Packages installing X11 fonts
                    358:             21.6.10. Packages installing SGML or XML data
                    359:             21.6.11. Packages installing extensions to the MIME database
                    360:             21.6.12. Packages using intltool
                    361:             21.6.13. Packages installing startup scripts
                    362:             21.6.14. Packages installing TeX modules
                    363:             21.6.15. Packages supporting running binaries in emulation
                    364:             21.6.16. Packages installing hicolor icons
                    365:             21.6.17. Packages installing desktop files
1.154     rillig    366: 
                    367:         21.7. Marking packages as having problems
                    368: 
1.184     rillig    369:     22. GNOME packaging and porting
                    370: 
                    371:         22.1. Meta packages
                    372:         22.2. Packaging a GNOME application
                    373:         22.3. Updating GNOME to a newer version
                    374:         22.4. Patching guidelines
                    375: 
1.154     rillig    376:     23. Submitting and Committing
                    377: 
                    378:         23.1. Submitting binary packages
                    379:         23.2. Submitting source packages (for non-NetBSD-developers)
                    380:         23.3. General notes when adding, updating, or removing packages
                    381:         23.4. Commit Messages
                    382:         23.5. Committing: Adding a package to CVS
                    383:         23.6. Updating a package to a newer version
                    384:         23.7. Renaming a package in pkgsrc
                    385:         23.8. Moving a package in pkgsrc
                    386: 
                    387:     24. Frequently Asked Questions
1.1       dsieger   388: 
                    389: III. The pkgsrc infrastructure internals
                    390: 
1.184     rillig    391:     25. Design of the pkgsrc infrastructure
1.1       dsieger   392: 
1.184     rillig    393:         25.1. The meaning of variable definitions
                    394:         25.2. Avoiding problems before they arise
                    395:         25.3. Variable evaluation
1.1       dsieger   396: 
1.184     rillig    397:             25.3.1. At load time
                    398:             25.3.2. At runtime
1.1       dsieger   399: 
1.184     rillig    400:         25.4. How can variables be specified?
                    401:         25.5. Designing interfaces for Makefile fragments
1.1       dsieger   402: 
1.184     rillig    403:             25.5.1. Procedures with parameters
                    404:             25.5.2. Actions taken on behalf of parameters
1.1       dsieger   405: 
1.184     rillig    406:         25.6. The order in which files are loaded
1.1       dsieger   407: 
1.184     rillig    408:             25.6.1. The order in bsd.prefs.mk
                    409:             25.6.2. The order in bsd.pkg.mk
1.1       dsieger   410: 
1.184     rillig    411:     26. Regression tests
1.1       dsieger   412: 
1.184     rillig    413:         26.1. Running the regression tests
                    414:         26.2. Adding a new regression test
1.1       dsieger   415: 
1.184     rillig    416:             26.2.1. Overridable functions
                    417:             26.2.2. Helper functions
1.1       dsieger   418: 
1.184     rillig    419:     27. Porting pkgsrc
1.1       dsieger   420: 
1.184     rillig    421:         27.1. Porting pkgsrc to a new operating system
1.1       dsieger   422: 
                    423: A. A simple example package: bison
                    424: 
                    425:     A.1. files
                    426: 
                    427:         A.1.1. Makefile
                    428:         A.1.2. DESCR
                    429:         A.1.3. PLIST
                    430:         A.1.4. Checking a package with pkglint
                    431: 
                    432:     A.2. Steps for building, installing, packaging
                    433: 
1.207     leot      434: B. Security hardening
1.1       dsieger   435: 
1.207     leot      436:     B.1. Mechanisms
1.1       dsieger   437: 
1.207     leot      438:         B.1.1. Enabled by default
                    439:         B.1.2. Not enabled by default
1.1       dsieger   440: 
1.207     leot      441:     B.2. Caveats
1.1       dsieger   442: 
1.207     leot      443:         B.2.1. Problems with PKGSRC_MKPIE
                    444:         B.2.2. Problems with PKGSRC_USE_FORTIFY
                    445:         B.2.3. Problems with PKGSRC_USE_RELRO
                    446:         B.2.4. Problems with PKGSRC_USE_SSP
1.1       dsieger   447: 
1.207     leot      448:     B.3. Auditing the system
                    449: 
                    450:         B.3.1. Checking for PIE
                    451:         B.3.2. Checking for partial RELRO
                    452:         B.3.3. Checking for full RELRO
                    453:         B.3.4. Checking for SSP
                    454: 
                    455: C. Build logs
                    456: 
                    457:     C.1. Building figlet
                    458:     C.2. Packaging figlet
                    459: 
                    460: D. Directory layout of the pkgsrc FTP server
                    461: 
                    462:     D.1. distfiles: The distributed source files
                    463:     D.2. misc: Miscellaneous things
                    464:     D.3. packages: Binary packages
                    465:     D.4. reports: Bulk build reports
                    466:     D.5. current, stable, pkgsrc-20xxQy: source packages
                    467: 
                    468: E. Help topics
                    469: F. Editing guidelines for the pkgsrc guide
                    470: 
                    471:     F.1. Make targets
                    472:     F.2. Procedure
1.1       dsieger   473: 
                    474: List of Tables
                    475: 
                    476: 1.1. Platforms supported by pkgsrc
1.184     rillig    477: 12.1. Patching examples
                    478: 22.1. PLIST handling for GNOME packages
1.1       dsieger   479: 
                    480: Chapter 1. What is pkgsrc?
                    481: 
                    482: Table of Contents
                    483: 
                    484: 1.1. Introduction
                    485: 
                    486:     1.1.1. Why pkgsrc?
                    487:     1.1.2. Supported platforms
                    488: 
                    489: 1.2. Overview
                    490: 1.3. Terminology
                    491: 
                    492:     1.3.1. Roles involved in pkgsrc
                    493: 
                    494: 1.4. Typography
                    495: 
                    496: 1.1. Introduction
                    497: 
                    498: There is a lot of software freely available for Unix-based systems, which is
                    499: usually available in form of the source code. Before such software can be used,
                    500: it needs to be configured to the local system, compiled and installed, and this
                    501: is exactly what The NetBSD Packages Collection (pkgsrc) does. pkgsrc also has
                    502: some basic commands to handle binary packages, so that not every user has to
                    503: build the packages for himself, which is a time-costly task.
                    504: 
                    505: pkgsrc currently contains several thousand packages, including:
                    506: 
1.104     sevan     507:   * www/apache24 - The Apache web server
1.1       dsieger   508: 
                    509:   * www/firefox - The Firefox web browser
                    510: 
                    511:   * meta-pkgs/gnome - The GNOME Desktop Environment
                    512: 
1.102     ryoon     513:   * meta-pkgs/kde4 - The K Desktop Environment
1.1       dsieger   514: 
1.108     rillig    515: ? just to name a few.
1.1       dsieger   516: 
                    517: pkgsrc has built-in support for handling varying dependencies, such as pthreads
                    518: and X11, and extended features such as IPv6 support on a range of platforms.
                    519: 
                    520: 1.1.1. Why pkgsrc?
                    521: 
                    522: pkgsrc provides the following key features:
                    523: 
                    524:   * Easy building of software from source as well as the creation and
                    525:     installation of binary packages. The source and latest patches are
                    526:     retrieved from a master or mirror download site, checksum verified, then
                    527:     built on your system. Support for binary-only distributions is available
                    528:     for both native platforms and NetBSD emulated platforms.
                    529: 
                    530:   * All packages are installed in a consistent directory tree, including
                    531:     binaries, libraries, man pages and other documentation.
                    532: 
1.104     sevan     533:   * Tracking of package dependencies automatically, including when performing
                    534:     updates, to ensure required packages are installed. The configuration files
                    535:     of various packages are handled automatically during updates, so local
                    536:     changes are preserved.
1.1       dsieger   537: 
                    538:   * Like NetBSD, pkgsrc is designed with portability in mind and consists of
                    539:     highly portable code. This allows the greatest speed of development when
1.26      spz       540:     porting to a new platform. This portability also ensures that pkgsrc is 
1.1       dsieger   541:     consistent across all platforms.
                    542: 
                    543:   * The installation prefix, acceptable software licenses, international
                    544:     encryption requirements and build-time options for a large number of
                    545:     packages are all set in a simple, central configuration file.
                    546: 
                    547:   * The entire source (not including the distribution files) is freely
                    548:     available under a BSD license, so you may extend and adapt pkgsrc to your
                    549:     needs. Support for local packages and patches is available right out of the
                    550:     box, so you can configure it specifically for your environment.
                    551: 
                    552: The following principles are basic to pkgsrc:
                    553: 
1.198     leot      554:   * "It should only work if it's right." -- That means, if a package contains
1.1       dsieger   555:     bugs, it's better to find them and to complain about them rather than to
                    556:     just install the package and hope that it works. There are numerous checks
1.175     gutterid  557:     in pkgsrc that try to find such bugs: static analysis tools (pkgtools/
1.1       dsieger   558:     pkglint), build-time checks (portability of shell scripts), and
                    559:     post-installation checks (installed files, references to shared libraries,
                    560:     script interpreters).
                    561: 
1.198     leot      562:   * "If it works, it should work everywhere" -- Like NetBSD has been ported to
1.1       dsieger   563:     many hardware architectures, pkgsrc has been ported to many operating
                    564:     systems. Care is taken that packages behave the same on all platforms.
                    565: 
                    566: 1.1.2. Supported platforms
                    567: 
                    568: pkgsrc consists of both a source distribution and a binary distribution for
                    569: these operating systems. After retrieving the required source or binaries, you
                    570: can be up and running with pkgsrc in just minutes!
                    571: 
                    572: pkgsrc was derived from FreeBSD's ports system, and initially developed for
                    573: NetBSD only. Since then, pkgsrc has grown a lot, and now supports the following
                    574: platforms:
                    575: 
                    576: Table 1.1. Platforms supported by pkgsrc
                    577: 
1.92      sevan     578: +-----------------------------------------------------------------------------+
1.229   ! gutterid  579: |              Platform               | Date Support  |         Notes         |
        !           580: |                                     |     Added     |                       |
        !           581: |-------------------------------------+---------------+-----------------------|
        !           582: |NetBSD                               |   Aug 1997    |                       |
        !           583: |-------------------------------------+---------------+-----------------------|
        !           584: |Solaris                              |   Mar 1999    |README.Solaris         |
        !           585: |-------------------------------------+---------------+-----------------------|
        !           586: |Linux                                |   Jun 1999    |README.Linux           |
        !           587: |-------------------------------------+---------------+-----------------------|
        !           588: |Darwin / Mac OS X / OS X / macOS     |   Oct 2001    |README.macOS           |
        !           589: |-------------------------------------+---------------+-----------------------|
        !           590: |FreeBSD                              |   Nov 2002    |README.FreeBSD         |
        !           591: |-------------------------------------+---------------+-----------------------|
        !           592: |OpenBSD                              |   Nov 2002    |README.OpenBSD         |
        !           593: |-------------------------------------+---------------+-----------------------|
        !           594: |IRIX                                 |   Dec 2002    |README.IRIX            |
        !           595: |-------------------------------------+---------------+-----------------------|
        !           596: |BSD/OS                               |   Dec 2003    |                       |
        !           597: |-------------------------------------+---------------+-----------------------|
        !           598: |AIX                                  |   Dec 2003    |README.AIX             |
        !           599: |-------------------------------------+---------------+-----------------------|
        !           600: |Interix (Microsoft Windows Services  |   Mar 2004    |README.Interix         |
        !           601: |for Unix)                            |               |                       |
        !           602: |-------------------------------------+---------------+-----------------------|
        !           603: |DragonFlyBSD                         |   Oct 2004    |                       |
        !           604: |-------------------------------------+---------------+-----------------------|
        !           605: |OSF/1                                |   Nov 2004    |README.OSF1            |
        !           606: |-------------------------------------+---------------+-----------------------|
        !           607: |HP-UX                                |   Apr 2007    |README.HPUX            |
        !           608: |-------------------------------------+---------------+-----------------------|
        !           609: |Haiku                                |   Sep 2010    |README.Haiku           |
        !           610: |-------------------------------------+---------------+-----------------------|
        !           611: |MirBSD                               |   Jan 2011    |                       |
        !           612: |-------------------------------------+---------------+-----------------------|
        !           613: |Minix3                               |   Nov 2011    |README.Minix3          |
        !           614: |-------------------------------------+---------------+-----------------------|
        !           615: |Cygwin                               |   Mar 2013    |README.Cygwin          |
        !           616: |-------------------------------------+---------------+-----------------------|
        !           617: |GNU/kFreeBSD                         |   Jul 2013    |README.GNUkFreeBSD     |
        !           618: |-------------------------------------+---------------+-----------------------|
        !           619: |Bitrig                               |   Jun 2014    |Removed from pkgsrc Sep|
        !           620: |                                     |               |2022                   |
1.92      sevan     621: +-----------------------------------------------------------------------------+
1.1       dsieger   622: 
                    623: 
                    624: 1.2. Overview
                    625: 
                    626: This document is divided into three parts. The first, The pkgsrc user's guide,
                    627: describes how one can use one of the packages in the Package Collection, either
                    628: by installing a precompiled binary package, or by building one's own copy using
                    629: the NetBSD package system. The second part, The pkgsrc developer's guide,
                    630: explains how to prepare a package so it can be easily built by other NetBSD
                    631: users without knowing about the package's building details. The third part, The
                    632: pkgsrc infrastructure internals is intended for those who want to understand
                    633: how pkgsrc is implemented.
                    634: 
                    635: This document is available in various formats: HTML, PDF, PS, TXT.
                    636: 
                    637: 1.3. Terminology
                    638: 
                    639: There has been a lot of talk about "ports", "packages", etc. so far. Here is a
                    640: description of all the terminology used within this document.
                    641: 
                    642: Package
                    643: 
                    644:     A set of files and building instructions that describe what's necessary to
                    645:     build a certain piece of software using pkgsrc. Packages are traditionally
1.123     wiz       646:     stored under /usr/pkgsrc, but may be stored in any location, referred to as
                    647:     PKGSRCDIR.
1.1       dsieger   648: 
                    649: The NetBSD package system
                    650: 
                    651:     This is the former name of "pkgsrc". It is part of the NetBSD operating
                    652:     system and can be bootstrapped to run on non-NetBSD operating systems as
                    653:     well. It handles building (compiling), installing, and removing of
                    654:     packages.
                    655: 
                    656: Distfile
                    657: 
                    658:     This term describes the file or files that are provided by the author of
                    659:     the piece of software to distribute his work. All the changes necessary to
                    660:     build on NetBSD are reflected in the corresponding package. Usually the
                    661:     distfile is in the form of a compressed tar-archive, but other types are
                    662:     possible, too. Distfiles are usually stored below /usr/pkgsrc/distfiles.
                    663: 
                    664: Port
                    665: 
                    666:     This is the term used by FreeBSD and OpenBSD people for what we call a
                    667:     package. In NetBSD terminology, "port" refers to a different architecture.
                    668: 
                    669: Precompiled/binary package
                    670: 
                    671:     A set of binaries built with pkgsrc from a distfile and stuffed together in
                    672:     a single .tgz file so it can be installed on machines of the same machine
                    673:     architecture without the need to recompile. Packages are usually generated
                    674:     in /usr/pkgsrc/packages; there is also an archive on ftp.NetBSD.org.
                    675: 
                    676:     Sometimes, this is referred to by the term "package" too, especially in the
                    677:     context of precompiled packages.
                    678: 
                    679: Program
                    680: 
                    681:     The piece of software to be installed which will be constructed from all
                    682:     the files in the distfile by the actions defined in the corresponding
                    683:     package.
                    684: 
                    685: 1.3.1. Roles involved in pkgsrc
                    686: 
                    687: pkgsrc users
                    688: 
                    689:     The pkgsrc users are people who use the packages provided by pkgsrc.
                    690:     Typically they are system administrators. The people using the software
                    691:     that is inside the packages (maybe called "end users") are not covered by
                    692:     the pkgsrc guide.
                    693: 
                    694:     There are two kinds of pkgsrc users: Some only want to install pre-built
                    695:     binary packages. Others build the pkgsrc packages from source, either for
                    696:     installing them directly or for building binary packages themselves. For
                    697:     pkgsrc users Part I, "The pkgsrc user's guide" should provide all necessary
                    698:     documentation.
                    699: 
                    700: package maintainers
                    701: 
                    702:     A package maintainer creates packages as described in Part II, "The pkgsrc
                    703:     developer's guide".
                    704: 
                    705: infrastructure developers
                    706: 
                    707:     These people are involved in all those files that live in the mk/ directory
                    708:     and below. Only these people should need to read through Part III, "The
                    709:     pkgsrc infrastructure internals", though others might be curious, too.
                    710: 
                    711: 1.4. Typography
                    712: 
                    713: When giving examples for commands, shell prompts are used to show if the
                    714: command should/can be issued as root, or if "normal" user privileges are
1.115     sevan     715: sufficient. We use a # for root's shell prompt, a % for users' shell prompt,
1.229   ! gutterid  716: assuming they use the C-shell or tcsh and a $ for Bourne shell and derivatives.
1.1       dsieger   717: 
                    718: Part I. The pkgsrc user's guide
                    719: 
                    720: Table of Contents
                    721: 
1.154     rillig    722: 2. Getting help
                    723: 3. Where to get pkgsrc and how to keep it up-to-date
1.1       dsieger   724: 
1.154     rillig    725:     3.1. Getting pkgsrc for the first time
1.1       dsieger   726: 
1.154     rillig    727:         3.1.1. As tar archive
                    728:         3.1.2. Via anonymous CVS
1.1       dsieger   729: 
1.154     rillig    730:     3.2. Keeping pkgsrc up-to-date
1.1       dsieger   731: 
1.154     rillig    732:         3.2.1. Via tar files
                    733:         3.2.2. Via CVS
1.1       dsieger   734: 
1.154     rillig    735: 4. Using pkgsrc on systems other than NetBSD
1.1       dsieger   736: 
1.154     rillig    737:     4.1. Binary distribution
                    738:     4.2. Bootstrapping pkgsrc
1.1       dsieger   739: 
1.154     rillig    740: 5. Using pkgsrc
1.1       dsieger   741: 
1.154     rillig    742:     5.1. Using binary packages
1.1       dsieger   743: 
1.154     rillig    744:         5.1.1. Finding binary packages
                    745:         5.1.2. Installing binary packages
1.202     nia       746:         5.1.3. Updating packages
                    747:         5.1.4. Deinstalling packages
                    748:         5.1.5. Getting information about installed packages
                    749:         5.1.6. Checking for security vulnerabilities in installed packages
                    750:         5.1.7. Finding if newer versions of your installed packages are in
1.1       dsieger   751:             pkgsrc
1.202     nia       752:         5.1.8. Other administrative functions
1.1       dsieger   753: 
1.154     rillig    754:     5.2. Building packages from source
1.1       dsieger   755: 
1.154     rillig    756:         5.2.1. Requirements
                    757:         5.2.2. Fetching distfiles
                    758:         5.2.3. How to build and install
1.1       dsieger   759: 
1.154     rillig    760: 6. Configuring pkgsrc
1.1       dsieger   761: 
1.154     rillig    762:     6.1. General configuration
                    763:     6.2. Variables affecting the build process
                    764:     6.3. Variables affecting the installation process
                    765:     6.4. Selecting and configuring the compiler
1.1       dsieger   766: 
1.154     rillig    767:         6.4.1. Selecting the compiler
                    768:         6.4.2. Additional flags to the compiler (CFLAGS)
                    769:         6.4.3. Additional flags to the linker (LDFLAGS)
1.1       dsieger   770: 
1.154     rillig    771:     6.5. Developer/advanced settings
                    772:     6.6. Selecting Build Options
1.1       dsieger   773: 
1.154     rillig    774: 7. Creating binary packages
1.1       dsieger   775: 
1.154     rillig    776:     7.1. Building a single binary package
                    777:     7.2. Settings for creation of binary packages
1.1       dsieger   778: 
1.154     rillig    779: 8. Creating binary packages for everything in pkgsrc (bulk builds)
1.6       rillig    780: 
1.154     rillig    781:     8.1. Preparations
1.180     rillig    782:     8.2. Running a bulk build
1.6       rillig    783: 
1.154     rillig    784:         8.2.1. Configuration
1.6       rillig    785: 
1.154     rillig    786:     8.3. Requirements of a full bulk build
1.178     rillig    787:     8.4. Bulk build variants
                    788: 
1.179     rillig    789:         8.4.1. Detect unknown configure options
                    790:         8.4.2. Detect classes of bugs by forcing compiler warnings
1.181     rillig    791:         8.4.3. Force compiler options only in the build phase
                    792:         8.4.4. Use custom directories
                    793:         8.4.5. Turn warnings into errors
                    794:         8.4.6. Reject packages for which pkglint reports errors
                    795:         8.4.7. Reject packages that contain forbidden strings
                    796:         8.4.8. Reject packages whose self-test fails
                    797:         8.4.9. Reject packages that use undefined shell variables
                    798:         8.4.10. Turn off verbose logging
1.6       rillig    799: 
1.178     rillig    800:     8.5. Creating a multiple CD-ROM packages collection
                    801: 
                    802:         8.5.1. Example of cdpack
1.6       rillig    803: 
1.154     rillig    804: 9. Directory layout of the installed files
1.6       rillig    805: 
1.154     rillig    806:     9.1. File system layout in ${LOCALBASE}
                    807:     9.2. File system layout in ${VARBASE}
1.6       rillig    808: 
1.154     rillig    809: 10. Frequently Asked Questions
1.6       rillig    810: 
1.154     rillig    811:     10.1. Are there any mailing lists for pkg-related discussion?
                    812:     10.2. Utilities for package management (pkgtools)
                    813:     10.3. How to use pkgsrc as non-root
                    814:     10.4. How to resume transfers when fetching distfiles?
                    815:     10.5. How can I install/use modular X.org from pkgsrc?
                    816:     10.6. How to fetch files from behind a firewall
                    817:     10.7. How to fetch files from HTTPS sites
                    818:     10.8. How do I tell make fetch to do passive FTP?
                    819:     10.9. How to fetch all distfiles at once
                    820:     10.10. What does "Don't know how to make /usr/share/tmac/tmac.andoc" mean?
                    821:     10.11. What does "Could not find bsd.own.mk" mean?
1.221     nia       822:     10.12. Using 'sudo' or `priv` with pkgsrc
1.154     rillig    823:     10.13. How do I change the location of configuration files?
                    824:     10.14. Automated security checks
                    825:     10.15. Why do some packages ignore my CFLAGS?
                    826:     10.16. A package does not build. What shall I do?
                    827:     10.17. What does "Makefile appears to contain unresolved cvs/rcs/??? merge
1.24      wiz       828:         conflicts" mean?
1.1       dsieger   829: 
1.154     rillig    830: Chapter 2. Getting help
                    831: 
                    832: To get help when using pkgsrc, the definitive source is this document, the
                    833: pkgsrc guide. If you don't find anything here, there are alternatives:
                    834: 
                    835:   * The built-in pkgsrc help, which is available after bootstrapping pkgsrc.
                    836:     Run bmake help topic=? to get help for any topic, such as a variable name
                    837:     like BUILD_DEFS, a make target like do-build, a missing C or C++ function
                    838:     like strcasecmp or any other topic.
                    839: 
1.207     leot      840:     The available help topics are listed in Appendix E, Help topics.
1.154     rillig    841: 
1.163     rillig    842:   * To see the value of a single variable, run bmake show-var VARNAME=X.
                    843: 
                    844:   * To see the values of the most common variables, run bmake show-all. These
                    845:     variables are grouped by topic. To see the variables for a single topic,
                    846:     run bmake show-all-topic, for example bmake show-all-fetch.
                    847: 
1.154     rillig    848:   * The pkgsrc-users mailing list, to which you can subscribe and then ask your
                    849:     questions.
                    850: 
                    851:   * The #pkgsrc IRC channel, which is accessible via a web browser or by using
                    852:     a specialized chat program such as XChat. Pick any user name and join the
                    853:     channel #pkgsrc.
                    854: 
                    855: Chapter 3. Where to get pkgsrc and how to keep it up-to-date
1.1       dsieger   856: 
                    857: Table of Contents
                    858: 
1.154     rillig    859: 3.1. Getting pkgsrc for the first time
1.1       dsieger   860: 
1.154     rillig    861:     3.1.1. As tar archive
                    862:     3.1.2. Via anonymous CVS
1.1       dsieger   863: 
1.154     rillig    864: 3.2. Keeping pkgsrc up-to-date
1.1       dsieger   865: 
1.154     rillig    866:     3.2.1. Via tar files
                    867:     3.2.2. Via CVS
1.1       dsieger   868: 
                    869: Before you download and extract the files, you need to decide where you want to
                    870: extract them. When using pkgsrc as root user, pkgsrc is usually installed in /
                    871: usr/pkgsrc. You are though free to install the sources and binary packages
                    872: wherever you want in your filesystem, provided that the pathname does not
                    873: contain white-space or other characters that are interpreted specially by the
                    874: shell and some other programs. A safe bet is to use only letters, digits,
                    875: underscores and dashes.
                    876: 
1.154     rillig    877: 3.1. Getting pkgsrc for the first time
1.1       dsieger   878: 
1.25      wiz       879: Before you download any pkgsrc files, you should decide whether you want the 
1.1       dsieger   880: current branch or the stable branch. The latter is forked on a quarterly basis
                    881: from the current branch and only gets modified for security updates. The names
                    882: of the stable branches are built from the year and the quarter, for example
1.214     leot      883: 2021Q4.
1.1       dsieger   884: 
                    885: The second step is to decide how you want to download pkgsrc. You can get it as
1.24      wiz       886: a tar file or via CVS. Both ways are described here.
1.1       dsieger   887: 
1.52      asau      888: Note that tar archive contains CVS working copy. Thus you can switch to using
                    889: CVS at any later time.
1.1       dsieger   890: 
1.154     rillig    891: 3.1.1. As tar archive
1.52      asau      892: 
1.151     sevan     893: The primary download location for all pkgsrc files is https://cdn.NetBSD.org/
                    894: pub/pkgsrc/ or ftp://ftp.NetBSD.org/pub/pkgsrc/ (it points to the same
                    895: location). There are a number of subdirectories for different purposes, which
1.207     leot      896: are described in detail in Appendix D, Directory layout of the pkgsrc FTP
1.151     sevan     897: server.
1.1       dsieger   898: 
1.52      asau      899: The tar archive for the current branch is in the directory current and is
1.118     sevan     900: called pkgsrc.tar.gz. It is autogenerated weekly.
1.52      asau      901: 
                    902: To save download time we provide bzip2- and xz-compressed archives which are
                    903: published at pkgsrc.tar.bz2 and pkgsrc.tar.xz respectively.
                    904: 
                    905: You can fetch the same files using FTP.
1.1       dsieger   906: 
1.214     leot      907: The tar file for the stable branch 2021Q4 is in the directory pkgsrc-2021Q4 and
1.59      jnemeth   908: is also called pkgsrc.tar.gz.
1.1       dsieger   909: 
1.136     leot      910: To download the latest pkgsrc stable tarball, run:
1.12      weinem    911: 
1.214     leot      912: $ ftp ftp://ftp.NetBSD.org/pub/pkgsrc/pkgsrc-2021Q4/pkgsrc.tar.gz
1.12      weinem    913: 
1.78      snj       914: If you prefer, you can also fetch it using "wget", "curl", or your web browser.
1.52      asau      915: 
1.12      weinem    916: Then, extract it with:
                    917: 
1.78      snj       918: $ tar -xzf pkgsrc.tar.gz -C /usr
1.12      weinem    919: 
                    920: This will create the directory pkgsrc/ in /usr/ and all the package source will
                    921: be stored under /usr/pkgsrc/.
                    922: 
                    923: To download pkgsrc-current, run:
                    924: 
                    925: $ ftp ftp://ftp.NetBSD.org/pub/pkgsrc/current/pkgsrc.tar.gz
1.1       dsieger   926: 
1.154     rillig    927: 3.1.2. Via anonymous CVS
1.1       dsieger   928: 
1.24      wiz       929: To fetch a specific pkgsrc stable branch, run:
1.1       dsieger   930: 
1.214     leot      931: $ cd /usr && cvs -q -z2 -d anoncvs@anoncvs.NetBSD.org:/cvsroot checkout -r pkgsrc-2021Q4 -P pkgsrc
1.13      weinem    932: 
1.24      wiz       933: This will create the directory pkgsrc/ in your /usr/ directory and all the
                    934: package source will be stored under /usr/pkgsrc/.
                    935: 
                    936: To fetch the pkgsrc current branch, run:
1.1       dsieger   937: 
1.40      wiz       938: $ cd /usr && cvs -q -z2 -d anoncvs@anoncvs.NetBSD.org:/cvsroot checkout -P pkgsrc
1.1       dsieger   939: 
1.30      dholland  940: Refer to the list of available mirrors to choose a faster CVS mirror, if
                    941: needed.
1.1       dsieger   942: 
1.24      wiz       943: If you get error messages from rsh, you need to set CVS_RSH variable. E.g.:
1.1       dsieger   944: 
1.40      wiz       945: $ cd /usr && env CVS_RSH=ssh cvs -q -z2 -d anoncvs@anoncvs.NetBSD.org:/cvsroot checkout -P pkgsrc
1.1       dsieger   946: 
1.24      wiz       947: Refer to documentation on your command shell how to set CVS_RSH=ssh
                    948: permanently. For Bourne shells, you can set it in your .profile or better
                    949: globally in /etc/profile:
                    950: 
                    951: # set CVS remote shell command
                    952: CVS_RSH=ssh
                    953: export CVS_RSH
1.12      weinem    954: 
1.13      weinem    955: By default, CVS doesn't do things like most people would expect it to do. But
                    956: there is a way to convince CVS, by creating a file called .cvsrc in your home
1.12      weinem    957: directory and saving the following lines to it. This file will save you lots of
                    958: headache and some bug reports, so we strongly recommend it. You can find an
                    959: explanation of this file in the CVS documentation.
1.2       rillig    960: 
                    961: # recommended CVS configuration file from the pkgsrc guide
1.155     sevan     962: cvs -q
1.2       rillig    963: checkout -P
1.4       rillig    964: update -dP
                    965: diff -upN
1.2       rillig    966: rdiff -u
1.24      wiz       967: release -d
1.1       dsieger   968: 
1.154     rillig    969: 3.2. Keeping pkgsrc up-to-date
1.1       dsieger   970: 
                    971: The preferred way to keep pkgsrc up-to-date is via CVS (which also works if you
                    972: have first installed it via a tar file). It saves bandwidth and hard disk
                    973: activity, compared to downloading the tar file again.
                    974: 
1.154     rillig    975: 3.2.1. Via tar files
1.1       dsieger   976: 
                    977: Warning
                    978: 
                    979: When updating from a tar file, you first need to completely remove the old
                    980: pkgsrc directory. Otherwise those files that have been removed from pkgsrc in
                    981: the mean time will not be removed on your local disk, resulting in
                    982: inconsistencies. When removing the old files, any changes that you have done to
                    983: the pkgsrc files will be lost after updating. Therefore updating via CVS is
                    984: strongly recommended.
                    985: 
                    986: Note that by default the distfiles and the binary packages are saved in the
                    987: pkgsrc tree, so don't forget to rescue them before updating. You can also
1.78      snj       988: configure pkgsrc to store distfiles and packages in directories outside the
1.154     rillig    989: pkgsrc tree by setting the DISTDIR and PACKAGES variables. See Chapter 6, 
1.78      snj       990: Configuring pkgsrc for the details.
1.1       dsieger   991: 
                    992: To update pkgsrc from a tar file, download the tar file as explained above.
                    993: Then, make sure that you have not made any changes to the files in the pkgsrc
                    994: directory. Remove the pkgsrc directory and extract the new tar file. Done.
                    995: 
1.154     rillig    996: 3.2.2. Via CVS
1.1       dsieger   997: 
1.26      spz       998: To update pkgsrc via CVS, change to the pkgsrc directory and run cvs:
1.12      weinem    999: 
1.26      spz      1000: $ cd /usr/pkgsrc && cvs update -dP
                   1001: 
                   1002: If you get error messages from rsh, you need to set CVS_RSH variable as
                   1003: described above. E.g.:
                   1004: 
                   1005: $ cd /usr/pkgsrc && env CVS_RSH=ssh cvs up -dP
1.1       dsieger  1006: 
1.154     rillig   1007: 3.2.2.1. Switching between different pkgsrc branches
1.1       dsieger  1008: 
                   1009: When updating pkgsrc, the CVS program keeps track of the branch you selected.
                   1010: But if you, for whatever reason, want to switch from the stable branch to the
                   1011: current one, you can do it by adding the option "-A" after the "update"
1.25      wiz      1012: keyword. To switch from the current branch back to the stable branch, add the "
1.214     leot     1013: -rpkgsrc-2021Q4" option.
1.1       dsieger  1014: 
1.154     rillig   1015: 3.2.2.2. What happens to my changes when updating?
1.1       dsieger  1016: 
                   1017: When you update pkgsrc, the CVS program will only touch those files that are
                   1018: registered in the CVS repository. That means that any packages that you created
                   1019: on your own will stay unmodified. If you change files that are managed by CVS,
                   1020: later updates will try to merge your changes with those that have been done by
                   1021: others. See the CVS manual, chapter "update" for details.
                   1022: 
1.154     rillig   1023: Chapter 4. Using pkgsrc on systems other than NetBSD
1.1       dsieger  1024: 
                   1025: Table of Contents
                   1026: 
1.154     rillig   1027: 4.1. Binary distribution
                   1028: 4.2. Bootstrapping pkgsrc
1.1       dsieger  1029: 
1.154     rillig   1030: 4.1. Binary distribution
1.1       dsieger  1031: 
1.154     rillig   1032: See Section 5.1, "Using binary packages".
1.1       dsieger  1033: 
1.154     rillig   1034: 4.2. Bootstrapping pkgsrc
1.1       dsieger  1035: 
1.44      asau     1036: pkgsrc can be bootstrapped for use in two different modes: privileged and
                   1037: unprivileged one. In unprivileged mode in contrast to privileged one all
1.45      asau     1038: programs are installed under one particular user and cannot utilise privileged
1.44      asau     1039: operations (packages don't create special users and all special file
                   1040: permissions like setuid are ignored).
                   1041: 
1.1       dsieger  1042: Installing the bootstrap kit from source should be as simple as:
                   1043: 
1.60      asau     1044: # env CVS_RSH=ssh cvs -d anoncvs@anoncvs.NetBSD.org:/cvsroot checkout -P pkgsrc
1.1       dsieger  1045: # cd pkgsrc/bootstrap
                   1046: # ./bootstrap
                   1047: 
                   1048: 
1.44      asau     1049: To bootstrap in unprivileged mode pass "--unprivileged" flag to bootstrap
                   1050: 
                   1051: By default, in privileged mode pkgsrc uses /usr/pkg for prefix where programs
1.118     sevan    1052: will be installed in, and /usr/pkg/pkgdb for the package database directory
                   1053: where pkgsrc will do its internal bookkeeping, /var is used as varbase, where
1.44      asau     1054: packages install their persistent data. In unprivileged mode pkgsrc uses ~/pkg
1.118     sevan    1055: for prefix, ~/pkg/pkgdb for the package database, and ~/pkg/var for varbase.
1.44      asau     1056: 
                   1057: You can change default layout using command-line arguments. Run "./bootstrap
                   1058: --help" to get details.
1.1       dsieger  1059: 
                   1060: Note
                   1061: 
                   1062: The bootstrap installs a bmake tool. Use this bmake when building via pkgsrc.
                   1063: For examples in this guide, use bmake instead of "make".
                   1064: 
1.44      asau     1065: Note
                   1066: 
                   1067: It is possible to bootstrap multiple instances of pkgsrc using non-intersecting
                   1068: directories. Use bmake corresponding to the installation you're working with to
                   1069: build and install packages.
                   1070: 
1.154     rillig   1071: Chapter 5. Using pkgsrc
1.1       dsieger  1072: 
                   1073: Table of Contents
                   1074: 
1.154     rillig   1075: 5.1. Using binary packages
1.1       dsieger  1076: 
1.154     rillig   1077:     5.1.1. Finding binary packages
                   1078:     5.1.2. Installing binary packages
1.202     nia      1079:     5.1.3. Updating packages
                   1080:     5.1.4. Deinstalling packages
                   1081:     5.1.5. Getting information about installed packages
                   1082:     5.1.6. Checking for security vulnerabilities in installed packages
                   1083:     5.1.7. Finding if newer versions of your installed packages are in pkgsrc
                   1084:     5.1.8. Other administrative functions
1.154     rillig   1085: 
                   1086: 5.2. Building packages from source
                   1087: 
                   1088:     5.2.1. Requirements
                   1089:     5.2.2. Fetching distfiles
                   1090:     5.2.3. How to build and install
1.1       dsieger  1091: 
                   1092: Basically, there are two ways of using pkgsrc. The first is to only install the
                   1093: package tools and to use binary packages that someone else has prepared. This
                   1094: is the "pkg" in pkgsrc. The second way is to install the "src" of pkgsrc, too.
                   1095: Then you are able to build your own packages, and you can still use binary
                   1096: packages from someone else.
                   1097: 
1.154     rillig   1098: 5.1. Using binary packages
1.1       dsieger  1099: 
1.151     sevan    1100: On the cdn.NetBSD.org site and mirrors, there are collections of binary
1.9       rillig   1101: packages, ready to be installed. These binary packages have been built using
                   1102: the default settings for the directories, that is:
                   1103: 
                   1104:   * /usr/pkg for LOCALBASE, where most of the files are installed,
                   1105: 
                   1106:   * /usr/pkg/etc for configuration files,
                   1107: 
                   1108:   * /var for VARBASE, where those files are installed that may change after
                   1109:     installation.
                   1110: 
                   1111: If you cannot use these directories for whatever reasons (maybe because you're
                   1112: not root), you cannot use these binary packages, but have to build the packages
1.154     rillig   1113: yourself, which is explained in Section 4.2, "Bootstrapping pkgsrc".
1.1       dsieger  1114: 
1.154     rillig   1115: 5.1.1. Finding binary packages
1.1       dsieger  1116: 
1.5       weinem   1117: To install binary packages, you first need to know from where to get them. The
1.202     nia      1118: first place where you should look is on the main pkgsrc CDN in the directory /
                   1119: pub/pkgsrc/packages.
1.5       weinem   1120: 
                   1121: This directory contains binary packages for multiple platforms. First, select
1.226     gutterid 1122: your operating system. Then, select your hardware architecture, and in the
                   1123: third step, the OS version and the "version" of pkgsrc.
1.9       rillig   1124: 
1.226     gutterid 1125: In this directory, you may find a file called bootstrap.tar.gz which contains
1.9       rillig   1126: the package management tools. If the file is missing, it is likely that your
                   1127: operating system already provides those tools. Download the file and extract it
                   1128: in the / directory. It will create the directories /usr/pkg (containing the
1.118     sevan    1129: tools for managing binary packages and the database of installed packages).
1.1       dsieger  1130: 
1.154     rillig   1131: 5.1.2. Installing binary packages
1.1       dsieger  1132: 
1.85      wiz      1133: In the directory from the last section, there is a subdirectory called All/,
1.9       rillig   1134: which contains all the binary packages that are available for the platform,
1.202     nia      1135: excluding those that may not be distributed via HTTP or FTP.
1.9       rillig   1136: 
                   1137: To install packages directly from an FTP or HTTP server, run the following
                   1138: commands in a Bourne-compatible shell (be sure to su to root first):
                   1139: 
1.202     nia      1140: # PATH="/usr/pkg/sbin:/usr/pkg/bin:$PATH"
                   1141: # PKG_PATH="https://cdn.NetBSD.org/pub/pkgsrc/packages"
1.169     rillig   1142: # PKG_PATH="$PKG_PATH/OPSYS/ARCH/VERSIONS/All/"
1.9       rillig   1143: # export PATH PKG_PATH
1.202     nia      1144: # pkg_add pkgin
1.9       rillig   1145: 
                   1146: Instead of URLs, you can also use local paths, for example if you are
                   1147: installing from a set of CDROMs, DVDs or an NFS-mounted repository. If you want
                   1148: to install packages from multiple sources, you can separate them by a semicolon
                   1149: in PKG_PATH.
                   1150: 
                   1151: After these preparations, installing a package is very easy:
                   1152: 
1.202     nia      1153: # pkgin search nginx
                   1154: nginx-1.19.6         Lightweight HTTP server and mail proxy server
                   1155: nginx-1.18.0nb8      Lightweight HTTP server and mail proxy server
                   1156: # pkgin install zsh nginx-1.19.6 vim
1.1       dsieger  1157: 
1.202     nia      1158: Note that pkgin is a user-friendly frontend to the pkg_* tools.
1.1       dsieger  1159: 
1.202     nia      1160: Any prerequisite packages needed to run the package in question will be
                   1161: installed, too, assuming they are present in the repository.
1.1       dsieger  1162: 
                   1163: After you've installed packages, be sure to have /usr/pkg/bin and /usr/pkg/sbin
                   1164: in your PATH so you can actually start the just installed program.
                   1165: 
1.202     nia      1166: 5.1.3. Updating packages
1.1       dsieger  1167: 
1.202     nia      1168: To update binary packages, it is recommended that you use pkgin upgrade. This
                   1169: will compare the remote package repository to your locally installed packages
                   1170: and safely replace any older packages.
1.1       dsieger  1171: 
1.202     nia      1172: Note that pkgsrc is released as quarterly branches. If you are updating to a
                   1173: newer quarterly branch of pkgsrc, you may need to adjust the repository in /usr
                   1174: /pkg/etc/pkgin/repositories.conf.
1.1       dsieger  1175: 
1.202     nia      1176: 5.1.4. Deinstalling packages
1.1       dsieger  1177: 
1.202     nia      1178: To deinstall a package, it does not matter whether it was installed from source
                   1179: code or from a binary package. Neither the pkgin or the pkg_delete command need
                   1180: to know.
1.1       dsieger  1181: 
1.202     nia      1182: To delete a package, you can just run pkgin remove package-name. The package
                   1183: name can be given with or without version number.
1.1       dsieger  1184: 
1.202     nia      1185: 5.1.5. Getting information about installed packages
1.1       dsieger  1186: 
                   1187: The pkg_info shows information about installed packages or binary package
1.202     nia      1188: files. As with other management tools, it works with packages installed from
                   1189: source or binaries.
1.1       dsieger  1190: 
1.202     nia      1191: 5.1.6. Checking for security vulnerabilities in installed packages
1.1       dsieger  1192: 
1.202     nia      1193: The pkgsrc Security Team and Packages Groups maintain a list of known
1.164     leot     1194: vulnerabilities to packages which are (or have been) included in pkgsrc. The
1.202     nia      1195: list is available from the NetBSD CDN at https://cdn.NetBSD.org/pub/NetBSD/
1.179     rillig   1196: packages/vulns/pkg-vulnerabilities.
1.1       dsieger  1197: 
1.202     nia      1198: Please note that not every "vulnerability" with a CVE assignment is exploitable
                   1199: in every configuration. Some bugs are marked as active simply because an fix
                   1200: was not marked as such. Operating system specific hardening and mitigation
                   1201: features may also reduce the impact of bugs.
                   1202: 
1.23      jakllsch 1203: Through pkg_admin fetch-pkg-vulnerabilities, this list can be downloaded
                   1204: automatically, and a security audit of all packages installed on a system can
                   1205: take place.
                   1206: 
                   1207: There are two components to auditing. The first step, pkg_admin
                   1208: fetch-pkg-vulnerabilities, is for downloading the list of vulnerabilities from
                   1209: the NetBSD FTP site. The second step, pkg_admin audit, checks to see if any of
                   1210: your installed packages are vulnerable. If a package is vulnerable, you will
                   1211: see output similar to the following:
1.1       dsieger  1212: 
                   1213: Package samba-2.0.9 has a local-root-shell vulnerability, see
1.174     leot     1214:     https://www.samba.org/samba/whatsnew/macroexploit.html
1.1       dsieger  1215: 
1.23      jakllsch 1216: You may wish to have the vulnerabilities file downloaded daily so that it
                   1217: remains current. This may be done by adding an appropriate entry to the root
                   1218: users crontab(5) entry. For example the entry
                   1219: 
1.121     sevan    1220: # Download vulnerabilities file
1.118     sevan    1221: 0 3 * * * /usr/pkg/sbin/pkg_admin fetch-pkg-vulnerabilities >/dev/null 2>&1
1.121     sevan    1222: # Audit the installed packages and email results to root
                   1223: 9 3 * * * /usr/pkg/sbin/pkg_admin audit |mail -s "Installed package audit result" \
                   1224:             root >/dev/null 2>&1
1.118     sevan    1225: 
                   1226: 
                   1227: will update the vulnerability list every day at 3AM, followed by an audit at
                   1228: 3:09AM. The result of the audit are then emailed to root. On NetBSD this may be
                   1229: accomplished instead by adding the following line to /etc/daily.conf:
                   1230: 
                   1231: fetch_pkg_vulnerabilities=YES
                   1232: 
1.23      jakllsch 1233: 
1.118     sevan    1234: to fetch the vulnerability list from the daily security script. The system is
                   1235: set to audit the packages by default but can be set explicitly, if desired (not
1.123     wiz      1236: required), by adding the following line to /etc/security.conf:
1.23      jakllsch 1237: 
1.118     sevan    1238: check_pkg_vulnerabilities=YES
1.23      jakllsch 1239: 
                   1240: 
1.118     sevan    1241: see daily.conf(5) and security.conf(5) for more details.
1.1       dsieger  1242: 
1.202     nia      1243: 5.1.7. Finding if newer versions of your installed packages are in pkgsrc
1.1       dsieger  1244: 
1.12      weinem   1245: Install pkgtools/lintpkgsrc and run lintpkgsrc with the "-i" argument to check
1.202     nia      1246: if any packages are stale, e.g.
1.1       dsieger  1247: 
                   1248: % lintpkgsrc -i
                   1249: ...
                   1250: Version mismatch: 'tcsh' 6.09.00 vs 6.10.00
                   1251: 
                   1252: 
1.202     nia      1253: 5.1.8. Other administrative functions
1.1       dsieger  1254: 
                   1255: The pkg_admin executes various administrative functions on the package system.
                   1256: 
1.154     rillig   1257: 5.2. Building packages from source
1.1       dsieger  1258: 
                   1259: After obtaining pkgsrc, the pkgsrc directory now contains a set of packages,
1.25      wiz      1260: organized into categories. You can browse the online index of packages, or run 
1.1       dsieger  1261: make readme from the pkgsrc directory to build local README.html files for all
                   1262: packages, viewable with any web browser such as www/lynx or www/firefox.
                   1263: 
                   1264: The default prefix for installed packages is /usr/pkg. If you wish to change
                   1265: this, you should do so by setting LOCALBASE in mk.conf. You should not try to
                   1266: use multiple different LOCALBASE definitions on the same system (inside a
                   1267: chroot is an exception).
                   1268: 
                   1269: The rest of this chapter assumes that the package is already in pkgsrc. If it
                   1270: is not, see Part II, "The pkgsrc developer's guide" for instructions how to
                   1271: create your own packages.
                   1272: 
1.154     rillig   1273: 5.2.1. Requirements
1.1       dsieger  1274: 
                   1275: To build packages from source, you need a working C compiler. On NetBSD, you
                   1276: need to install the "comp" and the "text" distribution sets. If you want to
                   1277: build X11-related packages, the "xbase" and "xcomp" distribution sets are
                   1278: required, too.
                   1279: 
1.154     rillig   1280: 5.2.2. Fetching distfiles
1.1       dsieger  1281: 
                   1282: The first step for building a package is downloading the distfiles (i.e. the
                   1283: unmodified source). If they have not yet been downloaded, pkgsrc will fetch
                   1284: them automatically.
                   1285: 
                   1286: If you have all files that you need in the distfiles directory, you don't need
                   1287: to connect. If the distfiles are on CD-ROM, you can mount the CD-ROM on /cdrom
                   1288: and add:
                   1289: 
                   1290: DISTDIR=/cdrom/pkgsrc/distfiles
                   1291: 
                   1292: to your mk.conf.
                   1293: 
                   1294: By default a list of distribution sites will be randomly intermixed to prevent
                   1295: huge load on servers which holding popular packages (for example,
                   1296: SourceForge.net mirrors). Thus, every time when you need to fetch yet another
                   1297: distfile all the mirrors will be tried in new (random) order. You can turn this
                   1298: feature off by setting MASTER_SORT_RANDOM=NO (for PKG_DEVELOPERs it's already
                   1299: disabled).
                   1300: 
                   1301: You can overwrite some of the major distribution sites to fit to sites that are
                   1302: close to your own. By setting one or two variables you can modify the order in
                   1303: which the master sites are accessed. MASTER_SORT contains a whitespace
                   1304: delimited list of domain suffixes. MASTER_SORT_REGEX is even more flexible, it
                   1305: contains a whitespace delimited list of regular expressions. It has higher
                   1306: priority than MASTER_SORT. Have a look at pkgsrc/mk/defaults/mk.conf to find
                   1307: some examples. This may save some of your bandwidth and time.
                   1308: 
                   1309: You can change these settings either in your shell's environment, or, if you
1.4       rillig   1310: want to keep the settings, by editing the mk.conf file, and adding the
1.1       dsieger  1311: definitions there.
                   1312: 
1.132     wiz      1313: If a package depends on many other packages (such as meta-pkgs/kde4), the build
1.1       dsieger  1314: process may alternate between periods of downloading source, and compiling. To
                   1315: ensure you have all the source downloaded initially you can run the command:
                   1316: 
                   1317: % make fetch-list | sh
                   1318: 
                   1319: which will output and run a set of shell commands to fetch the necessary files
                   1320: into the distfiles directory. You can also choose to download the files
                   1321: manually.
                   1322: 
1.154     rillig   1323: 5.2.3. How to build and install
1.1       dsieger  1324: 
                   1325: Once the software has downloaded, any patches will be applied, then it will be
                   1326: compiled for you. This may take some time depending on your computer, and how
                   1327: many other packages the software depends on and their compile time.
                   1328: 
                   1329: Note
                   1330: 
                   1331: If using bootstrap or pkgsrc on a non-NetBSD system, use the pkgsrc bmake
                   1332: command instead of "make" in the examples in this guide.
                   1333: 
                   1334: For example, type
                   1335: 
                   1336: % cd misc/figlet
                   1337: % make
                   1338: 
                   1339: 
                   1340: at the shell prompt to build the various components of the package.
                   1341: 
                   1342: The next stage is to actually install the newly compiled program onto your
                   1343: system. Do this by entering:
                   1344: 
                   1345: % make install
                   1346: 
                   1347: 
                   1348: while you are still in the directory for whatever package you are installing.
                   1349: 
                   1350: Installing the package on your system may require you to be root. However,
                   1351: pkgsrc has a just-in-time-su feature, which allows you to only become root for
                   1352: the actual installation step.
                   1353: 
                   1354: That's it, the software should now be installed and setup for use. You can now
                   1355: enter:
                   1356: 
                   1357: % make clean
                   1358: 
                   1359: 
                   1360: to remove the compiled files in the work directory, as you shouldn't need them
                   1361: any more. If other packages were also added to your system (dependencies) to
                   1362: allow your program to compile, you can tidy these up also with the command:
                   1363: 
                   1364: % make clean-depends
                   1365: 
                   1366: 
                   1367: Taking the figlet utility as an example, we can install it on our system by
1.207     leot     1368: building as shown in Appendix C, Build logs.
1.1       dsieger  1369: 
                   1370: The program is installed under the default root of the packages tree - /usr/
                   1371: pkg. Should this not conform to your tastes, set the LOCALBASE variable in your
                   1372: environment, and it will use that value as the root of your packages tree. So,
                   1373: to use /usr/local, set LOCALBASE=/usr/local in your environment. Please note
                   1374: that you should use a directory which is dedicated to packages and not shared
                   1375: with other programs (i.e., do not try and use LOCALBASE=/usr). Also, you should
                   1376: not try to add any of your own files or directories (such as src/, obj/, or
                   1377: pkgsrc/) below the LOCALBASE tree. This is to prevent possible conflicts
                   1378: between programs and other files installed by the package system and whatever
                   1379: else may have been installed there.
                   1380: 
1.4       rillig   1381: Some packages look in mk.conf to alter some configuration options at build
1.1       dsieger  1382: time. Have a look at pkgsrc/mk/defaults/mk.conf to get an overview of what will
                   1383: be set there by default. Environment variables such as LOCALBASE can be set in
1.4       rillig   1384: mk.conf to save having to remember to set them each time you want to use
1.1       dsieger  1385: pkgsrc.
                   1386: 
                   1387: Occasionally, people want to "look under the covers" to see what is going on
                   1388: when a package is building or being installed. This may be for debugging
                   1389: purposes, or out of simple curiosity. A number of utility values have been
                   1390: added to help with this.
                   1391: 
                   1392:  1. If you invoke the make(1) command with PKG_DEBUG_LEVEL=2, then a huge
                   1393:     amount of information will be displayed. For example,
                   1394: 
                   1395:     make patch PKG_DEBUG_LEVEL=2
                   1396: 
1.25      wiz      1397:     will show all the commands that are invoked, up to and including the "patch
                   1398:     " stage.
1.1       dsieger  1399: 
                   1400:  2. If you want to know the value of a certain make(1) definition, then the
                   1401:     VARNAME definition should be used, in conjunction with the show-var target.
                   1402:     e.g. to show the expansion of the make(1) variable LOCALBASE:
                   1403: 
                   1404:     % make show-var VARNAME=LOCALBASE
                   1405:     /usr/pkg
                   1406:     %
                   1407: 
                   1408: 
                   1409: If you want to install a binary package that you've either created yourself
                   1410: (see next section), that you put into pkgsrc/packages manually or that is
                   1411: located on a remote FTP server, you can use the "bin-install" target. This
                   1412: target will install a binary package - if available - via pkg_add(1), else do a
                   1413: make package. The list of remote FTP sites searched is kept in the variable
                   1414: BINPKG_SITES, which defaults to ftp.NetBSD.org. Any flags that should be added
                   1415: to pkg_add(1) can be put into BIN_INSTALL_FLAGS. See pkgsrc/mk/defaults/mk.conf
                   1416: for more details.
                   1417: 
                   1418: A final word of warning: If you set up a system that has a non-standard setting
                   1419: for LOCALBASE, be sure to set that before any packages are installed, as you
                   1420: cannot use several directories for the same purpose. Doing so will result in
                   1421: pkgsrc not being able to properly detect your installed packages, and fail
                   1422: miserably. Note also that precompiled binary packages are usually built with
                   1423: the default LOCALBASE of /usr/pkg, and that you should not install any if you
                   1424: use a non-standard LOCALBASE.
                   1425: 
1.154     rillig   1426: Chapter 6. Configuring pkgsrc
1.1       dsieger  1427: 
                   1428: Table of Contents
                   1429: 
1.154     rillig   1430: 6.1. General configuration
                   1431: 6.2. Variables affecting the build process
                   1432: 6.3. Variables affecting the installation process
                   1433: 6.4. Selecting and configuring the compiler
                   1434: 
                   1435:     6.4.1. Selecting the compiler
                   1436:     6.4.2. Additional flags to the compiler (CFLAGS)
                   1437:     6.4.3. Additional flags to the linker (LDFLAGS)
1.1       dsieger  1438: 
1.154     rillig   1439: 6.5. Developer/advanced settings
                   1440: 6.6. Selecting Build Options
1.1       dsieger  1441: 
                   1442: The whole pkgsrc system is configured in a single file, usually called mk.conf.
                   1443: In which directory pkgsrc looks for that file depends on the installation. On
                   1444: NetBSD, when you use make(1) from the base system, it is in the directory /etc
                   1445: /. In all other cases the default location is ${PREFIX}/etc/, depending on
                   1446: where you told the bootstrap program to install the binary packages.
                   1447: 
                   1448: The format of the configuration file is that of the usual BSD-style Makefiles.
                   1449: The whole pkgsrc configuration is done by setting variables in this file. Note
                   1450: that you can define all kinds of variables, and no special error checking (for
1.112     rillig   1451: example for spelling mistakes) takes place.
1.1       dsieger  1452: 
1.154     rillig   1453: 6.1. General configuration
1.1       dsieger  1454: 
1.112     rillig   1455: The following variables apply to all pkgsrc packages. A complete list of the
                   1456: variables that can be configured by the user is available in mk/defaults/
                   1457: mk.conf, together with some comments that describe each variable's intent.
1.1       dsieger  1458: 
                   1459:   * LOCALBASE: Where packages will be installed. The default is /usr/pkg. Do
                   1460:     not mix binary packages with different LOCALBASEs!
                   1461: 
                   1462:   * CROSSBASE: Where "cross" category packages will be installed. The default
                   1463:     is ${LOCALBASE}/cross.
                   1464: 
1.84      wiz      1465:   * X11BASE: Where X11 is installed on the system. The default is /usr/X11R7.
1.1       dsieger  1466: 
                   1467:   * DISTDIR: Where to store the downloaded copies of the original source
                   1468:     distributions used for building pkgsrc packages. The default is $
                   1469:     {PKGSRCDIR}/distfiles.
                   1470: 
                   1471:   * PKG_DBDIR: Where the database about installed packages is stored. The
1.118     sevan    1472:     default is /usr/pkg/pkgdb.
1.1       dsieger  1473: 
                   1474:   * MASTER_SITE_OVERRIDE: If set, override the packages' MASTER_SITES with this
                   1475:     value.
                   1476: 
                   1477:   * MASTER_SITE_BACKUP: Backup location(s) for distribution files and patch
                   1478:     files if not found locally or in ${MASTER_SITES} or ${PATCH_SITES}
1.118     sevan    1479:     respectively. The defaults is ftp://ftp.NetBSD.org/pub/pkgsrc/distfiles/$
1.1       dsieger  1480:     {DIST_SUBDIR}/.
                   1481: 
                   1482:   * BINPKG_SITES: List of sites carrying binary pkgs. rel and arch are replaced
                   1483:     with OS release ("2.0", etc.) and architecture ("mipsel", etc.).
                   1484: 
1.23      jakllsch 1485:   * ACCEPTABLE_LICENSES: List of acceptable licenses. License names are
                   1486:     case-sensitive. Whenever you try to build a package whose license is not in
                   1487:     this list, you will get an error message. If the license condition is
                   1488:     simple enough, the error message will include specific instructions on how
                   1489:     to change this variable.
1.1       dsieger  1490: 
1.154     rillig   1491: 6.2. Variables affecting the build process
1.1       dsieger  1492: 
                   1493:   * PACKAGES: The top level directory for the binary packages. The default is $
                   1494:     {PKGSRCDIR}/packages.
                   1495: 
                   1496:   * WRKOBJDIR: The top level directory where, if defined, the separate working
                   1497:     directories will get created, and symbolically linked to from ${WRKDIR}
                   1498:     (see below). This is useful for building packages on several architectures,
                   1499:     then ${PKGSRCDIR} can be NFS-mounted while ${WRKOBJDIR} is local to every
                   1500:     architecture. (It should be noted that PKGSRCDIR should not be set by the
1.198     leot     1501:     user -- it is an internal definition which refers to the root of the pkgsrc
1.1       dsieger  1502:     tree. It is possible to have many pkgsrc tree instances.)
                   1503: 
                   1504:   * LOCALPATCHES: Directory for local patches that aren't part of pkgsrc. See
1.184     rillig   1505:     Section 12.3, "patches/*" for more information.
1.1       dsieger  1506: 
                   1507:   * PKGMAKECONF: Location of the mk.conf file used by a package's BSD-style
                   1508:     Makefile. If this is not set, MAKECONF is set to /dev/null to avoid picking
                   1509:     up settings used by builds in /usr/src.
                   1510: 
1.154     rillig   1511: 6.3. Variables affecting the installation process
1.1       dsieger  1512: 
1.198     leot     1513:   * PKGSRC_KEEP_BIN_PKGS: By default, binary packages of built packages are
1.150     leot     1514:     preserved in ${PACKAGES}/All. Setting this variable to "no" prevents this.
1.1       dsieger  1515: 
1.107     jnemeth  1516: Packages have to support installation into a subdirectory of WRKDIR. This
                   1517: allows a package to be built, before the actual filesystem is touched. DESTDIR
                   1518: support exists in two variations:
1.4       rillig   1519: 
                   1520:   * Basic DESTDIR support means that the package installation and packaging is
                   1521:     still run as root.
                   1522: 
                   1523:   * Full DESTDIR support can run the complete build, installation and packaging
                   1524:     as normal user. Root privileges are only needed to add packages.
                   1525: 
                   1526: With basic DESTDIR support, make clean needs to be run as root.
                   1527: 
1.17      imil     1528: Considering the foo/bar package, DESTDIR full support can be tested using the
                   1529: following commands
                   1530: 
                   1531: $ id
                   1532: uid=1000(myusername) gid=100(users) groups=100(users),0(wheel)
                   1533: $ mkdir $HOME/packages
                   1534: $ cd $PKGSRCDIR/foo/bar
                   1535: 
                   1536: Verify DESTDIR full support, no root privileges should be needed
                   1537: 
1.66      asau     1538: $ make stage-install
1.17      imil     1539: 
                   1540: Create a package without root privileges
                   1541: 
1.66      asau     1542: $ make PACKAGES=$HOME/packages package
1.17      imil     1543: 
                   1544: For the following command, you must be able to gain root privileges using su(1)
                   1545: 
1.66      asau     1546: $ make PACKAGES=$HOME/packages install
1.17      imil     1547: 
                   1548: Then, as a simple user
                   1549: 
                   1550: $ make clean
                   1551: 
1.154     rillig   1552: 6.4. Selecting and configuring the compiler
1.4       rillig   1553: 
1.154     rillig   1554: 6.4.1. Selecting the compiler
1.1       dsieger  1555: 
                   1556: By default, pkgsrc will use GCC to build packages. This may be overridden by
                   1557: setting the following variables in /etc/mk.conf:
                   1558: 
                   1559: PKGSRC_COMPILER:
                   1560: 
                   1561:     This is a list of values specifying the chain of compilers to invoke when
                   1562:     building packages. Valid values are:
                   1563: 
1.66      asau     1564:       + ccc: Compaq C Compilers (Tru64)
                   1565: 
                   1566:       + ccache: compiler cache (chainable)
                   1567: 
                   1568:       + clang: Clang C and Objective-C compiler
                   1569: 
1.42      asau     1570:       + distcc: distributed C/C++ (chainable)
1.1       dsieger  1571: 
1.66      asau     1572:       + f2c: Fortran 77 to C compiler (chainable)
                   1573: 
                   1574:       + icc: Intel C++ Compiler (Linux)
                   1575: 
                   1576:       + ido: SGI IRIS Development Option cc (IRIX 5)
1.1       dsieger  1577: 
1.42      asau     1578:       + gcc: GNU C/C++ Compiler
1.1       dsieger  1579: 
1.66      asau     1580:       + hp: HP-UX C/aC++ compilers
                   1581: 
1.42      asau     1582:       + mipspro: Silicon Graphics, Inc. MIPSpro (n32/n64)
1.1       dsieger  1583: 
1.66      asau     1584:       + mipspro-ucode: Silicon Graphics, Inc. MIPSpro (o32)
1.1       dsieger  1585: 
1.42      asau     1586:       + sunpro: Sun Microsystems, Inc. WorkShip/Forte/Sun ONE Studio
1.1       dsieger  1587: 
1.118     sevan    1588:       + xlc: IBM's XL C/C++ compiler suite
1.66      asau     1589: 
1.1       dsieger  1590:     The default is "gcc". You can use ccache and/or distcc with an appropriate
                   1591:     PKGSRC_COMPILER setting, e.g. "ccache gcc". This variable should always be
                   1592:     terminated with a value for a real compiler. Note that only one real
                   1593:     compiler should be listed (e.g. "sunpro gcc" is not allowed).
                   1594: 
                   1595: GCC_REQD:
                   1596: 
                   1597:     This specifies the minimum version of GCC to use when building packages. If
                   1598:     the system GCC doesn't satisfy this requirement, then pkgsrc will build and
                   1599:     install one of the GCC packages to use instead.
                   1600: 
1.153     leot     1601: PYTHON_VERSION_DEFAULT:
1.114     maya     1602: 
                   1603:     Specifies which version of python to use when several options are
                   1604:     available.
                   1605: 
                   1606: PKGSRC_FORTRAN:
                   1607: 
1.176     gutterid 1608:     Specifies the Fortran compiler to use. The default is gfortran.
1.114     maya     1609: 
                   1610: GFORTRAN_VERSION:
                   1611: 
                   1612:     If PKGSRC_FORTRAN= gfortran is used, this option specifies which version to
                   1613:     use.
                   1614: 
1.154     rillig   1615: 6.4.2. Additional flags to the compiler (CFLAGS)
1.1       dsieger  1616: 
                   1617: If you wish to set the CFLAGS variable, please make sure to use the += operator
                   1618: instead of the = operator:
                   1619: 
                   1620: CFLAGS+=        -your -flags
                   1621: 
                   1622: Using CFLAGS= (i.e. without the "+") may lead to problems with packages that
1.16      jnemeth  1623: need to add their own flags. You may want to take a look at the devel/cpuflags
1.24      wiz      1624: package if you're interested in optimization specifically for the current CPU.
1.1       dsieger  1625: 
1.154     rillig   1626: 6.4.3. Additional flags to the linker (LDFLAGS)
1.1       dsieger  1627: 
                   1628: If you want to pass flags to the linker, both in the configure step and the
                   1629: build step, you can do this in two ways. Either set LDFLAGS or LIBS. The
                   1630: difference between the two is that LIBS will be appended to the command line,
                   1631: while LDFLAGS come earlier. LDFLAGS is pre-loaded with rpath settings for ELF
                   1632: machines depending on the setting of USE_IMAKE or the inclusion of mk/
                   1633: x11.buildlink3.mk. As with CFLAGS, if you do not wish to override these
                   1634: settings, use the += operator:
                   1635: 
                   1636: LDFLAGS+=        -your -linkerflags
                   1637: 
1.154     rillig   1638: 6.5. Developer/advanced settings
1.1       dsieger  1639: 
                   1640:   * PKG_DEVELOPER: Run some sanity checks that package developers want:
                   1641: 
1.42      asau     1642:       + make sure patches apply with zero fuzz
1.1       dsieger  1643: 
1.42      asau     1644:       + run check-shlibs to see that all binaries will find their shared libs.
1.1       dsieger  1645: 
                   1646:   * PKG_DEBUG_LEVEL: The level of debugging output which is displayed whilst
                   1647:     making and installing the package. The default value for this is 0, which
                   1648:     will not display the commands as they are executed (normal, default, quiet
                   1649:     operation); the value 1 will display all shell commands before their
                   1650:     invocation, and the value 2 will display both the shell commands before
1.112     rillig   1651:     their invocation, as well as their actual execution progress with set -x.
1.1       dsieger  1652: 
1.154     rillig   1653: 6.6. Selecting Build Options
1.1       dsieger  1654: 
                   1655: Some packages have build time options, usually to select between different
                   1656: dependencies, enable optional support for big dependencies or enable
                   1657: experimental features.
                   1658: 
                   1659: To see which options, if any, a package supports, and which options are
                   1660: mutually exclusive, run make show-options, for example:
                   1661: 
                   1662:     The following options are supported by this package:
                   1663:         ssl      Enable SSL support.
                   1664:     Exactly one of the following gecko options is required:
                   1665:         firefox  Use firefox as gecko rendering engine.
                   1666:         mozilla  Use mozilla as gecko rendering engine.
                   1667:     At most one of the following database options may be selected:
                   1668:         mysql    Enable support for MySQL database.
                   1669:         pgsql    Enable support for PostgreSQL database.
                   1670: 
                   1671:     These options are enabled by default: firefox
                   1672:     These options are currently enabled: mozilla ssl
                   1673: 
1.4       rillig   1674: The following variables can be defined in mk.conf to select which options to
                   1675: enable for a package: PKG_DEFAULT_OPTIONS, which can be used to select or
1.1       dsieger  1676: disable options for all packages that support them, and PKG_OPTIONS.pkgbase,
                   1677: which can be used to select or disable options specifically for package pkgbase
                   1678: . Options listed in these variables are selected, options preceded by "-" are
                   1679: disabled. A few examples:
                   1680: 
1.4       rillig   1681: $ grep "PKG.*OPTION" mk.conf
1.1       dsieger  1682: PKG_DEFAULT_OPTIONS=    -arts -dvdread -esound
                   1683: PKG_OPTIONS.kdebase=    debug -sasl
                   1684: PKG_OPTIONS.apache=     suexec
                   1685: 
1.11      rillig   1686: It is important to note that options that were specifically suggested by the
1.19      snj      1687: package maintainer must be explicitly removed if you do not wish to include the
                   1688: option. If you are unsure you can view the current state with make show-options
                   1689: .
1.11      rillig   1690: 
1.1       dsieger  1691: The following settings are consulted in the order given, and the last setting
                   1692: that selects or disables an option is used:
                   1693: 
                   1694:  1. the default options as suggested by the package maintainer
                   1695: 
                   1696:  2. the options implied by the settings of legacy variables (see below)
                   1697: 
                   1698:  3. PKG_DEFAULT_OPTIONS
                   1699: 
                   1700:  4. PKG_OPTIONS.pkgbase
                   1701: 
                   1702: For groups of mutually exclusive options, the last option selected is used, all
                   1703: others are automatically disabled. If an option of the group is explicitly
                   1704: disabled, the previously selected option, if any, is used. It is an error if no
                   1705: option from a required group of options is selected, and building the package
                   1706: will fail.
                   1707: 
                   1708: Before the options framework was introduced, build options were selected by
1.4       rillig   1709: setting a variable (often named USE_FOO) in mk.conf for each option. To ease
                   1710: transition to the options framework for the user, these legacy variables are
                   1711: converted to the appropriate options setting (PKG_OPTIONS.pkgbase)
                   1712: automatically. A warning is issued to prompt the user to update mk.conf to use
                   1713: the options framework directly. Support for the legacy variables will be
1.1       dsieger  1714: removed eventually.
                   1715: 
1.154     rillig   1716: Chapter 7. Creating binary packages
1.1       dsieger  1717: 
                   1718: Table of Contents
                   1719: 
1.154     rillig   1720: 7.1. Building a single binary package
                   1721: 7.2. Settings for creation of binary packages
1.1       dsieger  1722: 
1.154     rillig   1723: 7.1. Building a single binary package
1.1       dsieger  1724: 
                   1725: Once you have built and installed a package, you can create a binary package
                   1726: which can be installed on another system with pkg_add(1). This saves having to
                   1727: build the same package on a group of hosts and wasting CPU time. It also
                   1728: provides a simple means for others to install your package, should you
                   1729: distribute it.
                   1730: 
                   1731: To create a binary package, change into the appropriate directory in pkgsrc,
                   1732: and run make package:
                   1733: 
1.112     rillig   1734: $ cd misc/figlet
                   1735: $ make package
1.1       dsieger  1736: 
                   1737: This will build and install your package (if not already done), and then build
                   1738: a binary package from what was installed. You can then use the pkg_* tools to
                   1739: manipulate it. Binary packages are created by default in /usr/pkgsrc/packages,
1.207     leot     1740: in the form of a gzipped tar file. See Section C.2, "Packaging figlet" for a
1.1       dsieger  1741: continuation of the above misc/figlet example.
                   1742: 
1.154     rillig   1743: See Chapter 23, Submitting and Committing for information on how to submit such
1.1       dsieger  1744: a binary package.
                   1745: 
1.154     rillig   1746: 7.2. Settings for creation of binary packages
1.1       dsieger  1747: 
1.184     rillig   1748: See Section 13.17, "Other helpful targets".
1.6       rillig   1749: 
1.154     rillig   1750: Chapter 8. Creating binary packages for everything in pkgsrc (bulk builds)
1.6       rillig   1751: 
                   1752: Table of Contents
                   1753: 
1.154     rillig   1754: 8.1. Preparations
1.180     rillig   1755: 8.2. Running a bulk build
1.6       rillig   1756: 
1.154     rillig   1757:     8.2.1. Configuration
1.6       rillig   1758: 
1.154     rillig   1759: 8.3. Requirements of a full bulk build
1.178     rillig   1760: 8.4. Bulk build variants
                   1761: 
1.179     rillig   1762:     8.4.1. Detect unknown configure options
                   1763:     8.4.2. Detect classes of bugs by forcing compiler warnings
1.181     rillig   1764:     8.4.3. Force compiler options only in the build phase
                   1765:     8.4.4. Use custom directories
                   1766:     8.4.5. Turn warnings into errors
                   1767:     8.4.6. Reject packages for which pkglint reports errors
                   1768:     8.4.7. Reject packages that contain forbidden strings
                   1769:     8.4.8. Reject packages whose self-test fails
                   1770:     8.4.9. Reject packages that use undefined shell variables
                   1771:     8.4.10. Turn off verbose logging
1.6       rillig   1772: 
1.178     rillig   1773: 8.5. Creating a multiple CD-ROM packages collection
                   1774: 
                   1775:     8.5.1. Example of cdpack
1.6       rillig   1776: 
1.175     gutterid 1777: For a number of reasons, you may want to build binary packages for a large
                   1778: selected set of packages in pkgsrc, or even for all pkgsrc packages. For
1.71      wiz      1779: instance, when you have multiple machines that should run the same software, it
                   1780: is wasted time if they all build their packages themselves from source. Or you
                   1781: may want to build a list of packages you want and check them before deploying
1.175     gutterid 1782: onto production systems. There is a way of getting a set of binary packages:
                   1783: the bulk build system, or pbulk ("p" stands for "parallel"). This chapter
                   1784: describes how to set it up.
1.71      wiz      1785: 
1.154     rillig   1786: 8.1. Preparations
1.71      wiz      1787: 
                   1788: First of all, you have to decide whether you build all packages or a limited
                   1789: set of them. Full bulk builds usually consume a lot more resources, both space
1.175     gutterid 1790: and time, than builds for some practical sets of packages. A number of
                   1791: particularly heavy packages exist that are not actually interesting to a wide
                   1792: audience. (The approximate resource consumption for a full bulk build is given
                   1793: in section Section 8.3, "Requirements of a full bulk build".) For limited bulk
                   1794: builds you need to make a list of packages you want to build. Note that all
                   1795: their dependencies will be built, so you don't need to track them manually.
1.71      wiz      1796: 
                   1797: During bulk builds various packages are installed and deinstalled in /usr/pkg
                   1798: (or whatever LOCALBASE is), so make sure that you don't need any package during
1.112     rillig   1799: the builds. Essentially, you should provide a fresh system, either a chroot
1.71      wiz      1800: environment or something even more restrictive, depending on what the operating
                   1801: system provides, or dedicate the whole physical machine. As a useful side
                   1802: effect this makes sure that bulk builds cannot break anything in your system.
                   1803: There have been numerous cases where certain packages tried to install files
                   1804: outside the LOCALBASE or wanted to edit some files in /etc.
1.6       rillig   1805: 
1.180     rillig   1806: 8.2. Running a bulk build
1.6       rillig   1807: 
1.180     rillig   1808: Running a bulk build works roughly as follows:
1.15      rillig   1809: 
                   1810:   * First, build the pbulk infrastructure in a fresh pkgsrc location.
                   1811: 
                   1812:   * Then, build each of the packages from a clean installation directory using
                   1813:     the infrastructure.
                   1814: 
1.154     rillig   1815: 8.2.1. Configuration
1.6       rillig   1816: 
1.112     rillig   1817: To simplify configuration, we provide the helper script mk/pbulk/pbulk.sh.
1.6       rillig   1818: 
1.68      asau     1819: In order to use it, prepare a clear system (real one, chroot environment, jail,
                   1820: zone, virtual machine). Configure network access to fetch distribution files.
1.112     rillig   1821: Create a user with name "pbulk".
1.68      asau     1822: 
                   1823: Fetch and extract pkgsrc. Use a command like one of these:
                   1824: 
1.151     sevan    1825: # (cd /usr && ftp -o - https://cdn.NetBSD.org/pub/pkgsrc/current/pkgsrc.tar.gz | tar -zxf-)
                   1826: # (cd /usr && fetch -o - https://cdn.NetBSD.org/pub/pkgsrc/current/pkgsrc.tar.gz | tar -zxf-)
1.72      wiz      1827: # (cd /usr && cvs -Q -z3 -d anoncvs@anoncvs.NetBSD.org:/cvsroot get -P pkgsrc)
1.68      asau     1828: 
                   1829: Or any other way that fits (e.g., curl, wget).
                   1830: 
                   1831: Deploy and configure pbulk tools, e.g.:
                   1832: 
1.118     sevan    1833: # sh pbulk.sh -n # use native make, no bootstrap kit needed (for use on NetBSD)
1.68      asau     1834: # sh pbulk.sh -n -c mk.conf.frag # native, apply settings from given mk.conf fragment
                   1835: # sh pbulk.sh -nlc mk.conf.frag # native, apply settings, configure for limited build
                   1836: 
                   1837: Note
                   1838: 
                   1839: mk.conf.frag is a fragment of mk.conf that contains settings you want to apply
                   1840: to packages you build. For instance,
                   1841: 
1.112     rillig   1842: PKG_DEVELOPER=          yes     # perform more checks
                   1843: X11_TYPE=               modular # use pkgsrc X11
                   1844: SKIP_LICENSE_CHECK=     yes     # accept all licences (useful
                   1845:                                 # when building all packages)
1.68      asau     1846: 
                   1847: If configured for limited list, replace the list in /usr/pbulk/etc/pbulk.list
1.112     rillig   1848: with your list of packages, one per line without empty lines or comments. E.g.:
1.68      asau     1849: 
                   1850: www/firefox
                   1851: mail/thunderbird
                   1852: misc/libreoffice4
                   1853: 
1.69      asau     1854: At this point you can also review configuration in /usr/pbulk/etc and make
                   1855: final amendments, if wanted.
                   1856: 
1.68      asau     1857: Start it:
                   1858: 
                   1859: # /usr/pbulk/bin/bulkbuild
                   1860: 
                   1861: After it finishes, you'll have /mnt filled with distribution files, binary
                   1862: packages, and reports, plain text summary in /mnt/bulklog/meta/report.txt
                   1863: 
                   1864: Note
                   1865: 
                   1866: The pbulk.sh script does not cover all possible use cases. While being ready to
                   1867: run, it serves as a good starting point to understand and build more complex
                   1868: setups. The script is kept small enough for better understanding.
                   1869: 
                   1870: Note
                   1871: 
                   1872: The pbulk.sh script supports running unprivileged bulk build and helps
1.205     wiz      1873: configuring distributed bulk builds. Distributed bulk builds support either
                   1874: building in worker chroots (each node is a path to a different chroot) that
                   1875: replicate the target system, including the pbulk prefix, or remote machines
                   1876: (each node is an IP address that must be accessible over SSH without a
                   1877: password).
1.15      rillig   1878: 
1.154     rillig   1879: 8.3. Requirements of a full bulk build
1.71      wiz      1880: 
                   1881: A complete bulk build requires lots of disk space. Some of the disk space can
                   1882: be read-only, some other must be writable. Some can be on remote filesystems
                   1883: (such as NFS) and some should be local. Some can be temporary filesystems,
                   1884: others must survive a sudden reboot.
                   1885: 
1.205     wiz      1886:   * 70 GB for the distfiles (read-write, remote, temporary)
1.71      wiz      1887: 
1.205     wiz      1888:   * 60 GB for the binary packages (read-write, remote, permanent)
1.71      wiz      1889: 
                   1890:   * 1 GB for the pkgsrc tree (read-only, remote, permanent)
                   1891: 
                   1892:   * 5 GB for LOCALBASE (read-write, local, temporary)
                   1893: 
                   1894:   * 10 GB for the log files (read-write, remote, permanent)
                   1895: 
                   1896:   * 5 GB for temporary files (read-write, local, temporary)
                   1897: 
1.178     rillig   1898: 8.4. Bulk build variants
                   1899: 
                   1900: To ensure that pkgsrc packages work in different configurations, it makes sense
                   1901: to run non-default bulk builds from time to time. This section lists some ideas
                   1902: for bulk builds that intentionally let packages fail if they don't follow the
                   1903: pkgsrc style.
                   1904: 
1.179     rillig   1905: 8.4.1. Detect unknown configure options
1.178     rillig   1906: 
                   1907: Add the following line to mk.conf.
                   1908: 
                   1909: GNU_CONFIGURE_STRICT=   yes
                   1910: 
                   1911: When a package fails this additional check, the most common cause is that the
                   1912: configure option was valid for an older version of the package but does not
                   1913: apply anymore. In that case, just remove it.
                   1914: 
1.179     rillig   1915: 8.4.2. Detect classes of bugs by forcing compiler warnings
1.178     rillig   1916: 
                   1917: The job of a compiler is not restricted to producing executable code, most
1.179     rillig   1918: compilers also detect typical programming mistakes. The pkgsrc compiler
                   1919: wrappers make it easy to force compiler options when the package is built. This
                   1920: can be used to find typical bugs across all packages that are in pkgsrc. By
                   1921: reporting these bugs upstream, the packages will be more reliable with the next
                   1922: updates.
1.178     rillig   1923: 
1.179     rillig   1924: Add some of the following lines to mk.conf:
1.178     rillig   1925: 
                   1926: CFLAGS+=        -Werror=char-subscripts
1.179     rillig   1927: CFLAGS+=        -Werror=implicit-function-declaration
1.178     rillig   1928: 
1.179     rillig   1929: When a package fails to build using these stricter compiler options, document
                   1930: the circumstances in which the compiler produced the error message. This
                   1931: includes:
1.178     rillig   1932: 
                   1933:   * The platform (MACHINE_PLATFORM)
                   1934: 
                   1935:   * The source file
                   1936: 
                   1937:   * An excerpt of the code. GCC and Clang already do this as part of the
                   1938:     diagnostic.
                   1939: 
1.179     rillig   1940:   * The exact error message from the compiler.
1.178     rillig   1941: 
1.179     rillig   1942: If a package produces these error messages, but the package is fine, record
                   1943: this in your local mk.conf, like this, to skip this check in the next builds:
1.178     rillig   1944: 
1.179     rillig   1945: .if ${PKGPATH} == category/package
1.178     rillig   1946: # Version ${VERSION} failed on ${MACHINE_PLATFORM}:
                   1947: # error message
                   1948: # code
1.179     rillig   1949: # Reason why the code does not need to be fixed.
1.178     rillig   1950: BUILDLINK_TRANSFORM+=   rm:-Werror=char-subscripts
1.179     rillig   1951: .endif
1.178     rillig   1952: 
                   1953: If the error messages from the compiler are valid and the code needs to be
1.179     rillig   1954: fixed, prepare a local patch (see LOCALPATCHES) and report the bug to the
                   1955: upstream authors of the package, providing them with the information you
                   1956: collected above.
1.178     rillig   1957: 
1.179     rillig   1958: Patches that are not essential for the package to work should only be reported
                   1959: upstream but not committed to pkgsrc, to make future updates easier.
                   1960: 
1.181     rillig   1961: 8.4.3. Force compiler options only in the build phase
                   1962: 
                   1963: When adding custom compiler flags via CFLAGS, these apply to all phases of the
                   1964: package build process. Especially in the configure phase, adding -Werror leads
                   1965: to wrong decisions. The GNU configure scripts feed many small test programs to
                   1966: the C compiler to see whether certain headers are available, functions are
                   1967: defined in a library and programs can be run. In many cases these programs
                   1968: would not survive a strict compiler run with -Wall -Wextra -Werror.
                   1969: 
                   1970: The pkgsrc infrastructure is flexible enough to support compiler options being
                   1971: added between the configure and build phases. It's a little more complicated
                   1972: than the other examples in this section but still easy enough.
                   1973: 
                   1974: The basic idea is to use the pkgsrc compiler wrapper to inject the desired
                   1975: compiler options. The compiler wrapper's original task is to hide unwanted
                   1976: directories of include files and to normalize compiler options. It does this by
                   1977: wrapping the compiler command and rewriting the command line. To see this in
                   1978: action, run bmake patch in a package directory and examine the work/.cwrappers/
                   1979: config directory. It contains individual configurations for the C compiler and
                   1980: the related tools. The plan is to find a hook between the configure and build
                   1981: phases, and to modify these configuration files at that point.
                   1982: 
                   1983: To find this hook, have a look at mk/build/build.mk, which contains among
                   1984: others the pre-build-checks-hook. The word checks doesn't quite fit, but the
                   1985: pre-build-hook sounds good enough.
                   1986: 
                   1987: The code to be included in mk.conf is:
                   1988: 
                   1989: # Just a few example options.
                   1990: BUILD_ONLY_CFLAGS=      -Wall -Werror -O2 -DTEMPDIR='"/tmp"'
                   1991: 
                   1992: .if ${BUILD_ONLY_CFLAGS:U:M*}
                   1993: pre-build-checks-hook: add-build-only-cflags
                   1994: 
                   1995: add-build-only-cflags: .PHONY
                   1996:         ${RUN} cd ${CWRAPPERS_CONFIG_DIR};      \
                   1997:         ${TEST} ! -f ${.TARGET} || exit 0;      \
                   1998:         for flag in ${BUILD_ONLY_CFLAGS}; do    \
                   1999:                 ${ECHO} "append=$$flag" >> cc;  \
                   2000:         done;                                   \
                   2001:         > ${.TARGET}
                   2002: .endif
                   2003: 
                   2004: (When editing the mk.conf, make sure that the commands of the
                   2005: add-build-only-cflags target are indented with a tab, not with spaces.)
                   2006: 
                   2007: The condition in the .if statement contains the :U modifier to prevent parse
                   2008: errors if the variable should be undefined, possibly because it is only defined
                   2009: for a subset of the packages. The :M* modifier ensures that there is at least
                   2010: one compiler option, to prevent a syntax error in the shell parser.
                   2011: 
                   2012: The code around the ${.TARGET} variable ensures that the additional compiler
                   2013: options are only appended once, even if bmake build is run multiple times. To
                   2014: do this, it creates a marker file.
                   2015: 
                   2016: To verify that this setup works, run bmake configure in a package directory. Up
                   2017: to now, everything works as usual. Examine the directory work/.cwrappers/config
                   2018: to see that the compiler options from BUILD_ONLY_CFLAGS are not yet added to
                   2019: the file cc. Examine the tail of the work/.work.log file to see that the normal
                   2020: compiler options are used.
                   2021: 
                   2022: Now run bmake build. This will append the options to the file cc and will
                   2023: create the marker file in the same directory. After that, the build starts as
                   2024: usual, but with the added compiler options. Examine the tail of the file work
                   2025: /.work.log to see that the lines starting with [*] don't contain the compiler
                   2026: options, but the corresponding lines starting with <.> do end with these
                   2027: options.
                   2028: 
                   2029: Building packages using this setup variant and fixing the resulting bugs is the
                   2030: same as in Section 8.4.2, "Detect classes of bugs by forcing compiler warnings"
                   2031: .
                   2032: 
                   2033: 8.4.4. Use custom directories
1.178     rillig   2034: 
                   2035: Some directories like PREFIX, VARBASE, PKG_SYSCONFDIR, PKGMANDIR, PKG_INFODIR
                   2036: can be configured in pkgsrc. Set these to arbitrary paths during bootstrap or
                   2037: afterwards in mk.conf.
                   2038: 
                   2039: PREFIX=         /a-random-uuid
                   2040: PKG_SYSCONFDIR= /a-random-uuid
                   2041: VARBASE=        /a-random-uuid
                   2042: PKGMANDIR=      a-random-uuid
                   2043: PKG_INFODIR=    a-random-uuid
                   2044: 
1.181     rillig   2045: 8.4.5. Turn warnings into errors
1.178     rillig   2046: 
                   2047: When building a package, warnings are typically ignored since they just flow by
                   2048: and do not cause the build to fail immediately. To find these warnings,
                   2049: redefine them to errors in mk.conf.
                   2050: 
                   2051: DELAYED_WARNING_MSG=    ${DELAYED_ERROR_MSG} "(was warning)"
                   2052: WARNING_MSG=            ${FAIL_MSG} "(was warning)"
                   2053: 
                   2054: (There are many more classes of warnings in pkgsrc, and most of them can be
                   2055: redefined with a simple definition like above.
                   2056: 
1.179     rillig   2057: If a package suggests to add USE_TOOLS+=perl to the package Makefile, research
1.178     rillig   2058: whether the package actually needs Perl. If it does, add USE_TOOLS+=perl to the
                   2059: package Makefile, and if it doesn't, add TOOLS_BROKEN+=perl.
                   2060: 
1.181     rillig   2061: 8.4.6. Reject packages for which pkglint reports errors
1.178     rillig   2062: 
                   2063: Using pkglint as part of the regular build process is mostly a waste of time.
                   2064: If you want to fix some of the warnings, just run pkglint recursively on the
                   2065: whole pkgsrc tree. This will take a few minutes (up to 10), which is much
                   2066: faster than a complete bulk build.
                   2067: 
1.181     rillig   2068: 8.4.7. Reject packages that contain forbidden strings
1.178     rillig   2069: 
                   2070: To ensure that the binary packages don't contain references to the build
                   2071: directory, there is already CHECK_WRKREF. If that variable includes the item
                   2072: extra, it is possible to define additional patterns that must not appear in any
                   2073: installed file. This is specified in mk.conf.
                   2074: 
                   2075: CHECK_WRKREF=                   extra
                   2076: CHECK_WRKREF_EXTRA_DIRS+=       /usr/local
                   2077: CHECK_WRKREF_EXTRA_DIRS+=       /usr/pkg
                   2078: CHECK_WRKREF_EXTRA_DIRS+=       @[A-Z][A-Z]*@
                   2079: 
                   2080: The above patterns will probably generate many false positives, therefore the
                   2081: results need to be taken with a grain of salt.
                   2082: 
1.181     rillig   2083: 8.4.8. Reject packages whose self-test fails
1.178     rillig   2084: 
                   2085: To run the test suites that come with each package, add this line to mk.conf.
                   2086: 
                   2087: PKGSRC_RUN_TEST=        yes
                   2088: 
                   2089: Be prepared that even the most basic packages fail this test. When doing a bulk
                   2090: build with this, it will often abort in the early phase where the packages are
                   2091: scanned for their dependencies since there are cyclic dependencies. There is
                   2092: still a lot to do in this area.
                   2093: 
1.181     rillig   2094: 8.4.9. Reject packages that use undefined shell variables
1.178     rillig   2095: 
                   2096: To catch typos in the shell snippets from the Makefile fragments, add the -u
                   2097: flag to most of the commands by adding this line to mk.conf.
                   2098: 
                   2099: RUN=    @set -eu;
                   2100: 
1.181     rillig   2101: After that, ensure that none of the bulk build log files (even those for
                   2102: successfully built packages) contains the string parameter not set or whatever
                   2103: error message the command sh -ceu '$undefined' outputs.
                   2104: 
1.178     rillig   2105: See mk/misc/common.mk for the existing definition.
                   2106: 
1.181     rillig   2107: 8.4.10. Turn off verbose logging
1.178     rillig   2108: 
                   2109: The build logs of a package are often quite long. This allows error messages or
                   2110: other interesting details to hide between the noise. To make the actual error
                   2111: message stand out more, add these lines to mk.conf.
                   2112: 
                   2113: GNU_CONFIGURE_QUIET=    yes
                   2114: MAKE_FLAGS+=            -s
                   2115: 
                   2116: The -s option works for both GNU Make and BSD Make. On exotic platforms with
                   2117: their own make, it may be a little different.
                   2118: 
                   2119: 8.5. Creating a multiple CD-ROM packages collection
1.1       dsieger  2120: 
                   2121: After your pkgsrc bulk-build has completed, you may wish to create a CD-ROM set
                   2122: of the resulting binary packages to assist in installing packages on other
                   2123: machines. The pkgtools/cdpack package provides a simple tool for creating the
                   2124: ISO 9660 images. cdpack arranges the packages on the CD-ROMs in a way that
                   2125: keeps all the dependencies for a given package on the same CD as that package.
                   2126: 
1.178     rillig   2127: 8.5.1. Example of cdpack
1.1       dsieger  2128: 
                   2129: Complete documentation for cdpack is found in the cdpack(1) man page. The
                   2130: following short example assumes that the binary packages are left in /usr/
                   2131: pkgsrc/packages/All and that sufficient disk space exists in /u2 to hold the
                   2132: ISO 9660 images.
                   2133: 
                   2134: # mkdir /u2/images
                   2135: # pkg_add /usr/pkgsrc/packages/All/cdpack
                   2136: # cdpack /usr/pkgsrc/packages/All /u2/images
                   2137: 
                   2138: 
                   2139: If you wish to include a common set of files (COPYRIGHT, README, etc.) on each
                   2140: CD in the collection, then you need to create a directory which contains these
1.175     gutterid 2141: files, e.g.:
1.1       dsieger  2142: 
                   2143: # mkdir /tmp/common
                   2144: # echo "This is a README" > /tmp/common/README
                   2145: # echo "Another file" > /tmp/common/COPYING
                   2146: # mkdir /tmp/common/bin
                   2147: # echo "#!/bin/sh" > /tmp/common/bin/myscript
                   2148: # echo "echo Hello world" >> /tmp/common/bin/myscript
                   2149: # chmod 755 /tmp/common/bin/myscript
                   2150: 
                   2151: 
                   2152: Now create the images:
                   2153: 
                   2154: # cdpack -x /tmp/common /usr/pkgsrc/packages/All /u2/images
                   2155: 
                   2156: Each image will contain README, COPYING, and bin/myscript in their root
                   2157: directories.
                   2158: 
1.154     rillig   2159: Chapter 9. Directory layout of the installed files
1.1       dsieger  2160: 
                   2161: Table of Contents
                   2162: 
1.154     rillig   2163: 9.1. File system layout in ${LOCALBASE}
                   2164: 9.2. File system layout in ${VARBASE}
1.1       dsieger  2165: 
                   2166: The files that are installed by pkgsrc are organized in a way that is similar
                   2167: to what you find in the /usr directory of the base system. But some details are
                   2168: different. This is because pkgsrc initially came from FreeBSD and had adopted
                   2169: its file system hierarchy. Later it was largely influenced by NetBSD. But no
                   2170: matter which operating system you are using pkgsrc with, you can expect the
                   2171: same layout for pkgsrc.
                   2172: 
                   2173: There are mainly four root directories for pkgsrc, which are all configurable
                   2174: in the bootstrap/bootstrap script. When pkgsrc has been installed as root, the
                   2175: default locations are:
                   2176: 
                   2177: LOCALBASE=              /usr/pkg
                   2178: PKG_SYSCONFBASE=        /usr/pkg/etc
                   2179: VARBASE=                /var
1.119     sevan    2180: PKG_DBDIR=              /usr/pkg/pkgdb
1.1       dsieger  2181: 
                   2182: In unprivileged mode (when pkgsrc has been installed as any other user), the
                   2183: default locations are:
                   2184: 
                   2185: LOCALBASE=              ${HOME}/pkg
                   2186: PKG_SYSCONFBASE=        ${HOME}/pkg/etc
                   2187: VARBASE=                ${HOME}/pkg/var
1.119     sevan    2188: PKG_DBDIR=              ${HOME}/pkg/pkgdb
1.1       dsieger  2189: 
                   2190: What these four directories are for, and what they look like is explained
                   2191: below.
                   2192: 
1.25      wiz      2193:   * LOCALBASE corresponds to the /usr directory in the base system. It is the "
                   2194:     main" directory where the files are installed and contains the well-known
1.1       dsieger  2195:     subdirectories like bin, include, lib, share and sbin.
                   2196: 
                   2197:   * VARBASE corresponds to /var in the base system. Some programs (especially
                   2198:     games, network daemons) need write access to it during normal operation.
                   2199: 
                   2200:   * PKG_SYSCONFDIR corresponds to /etc in the base system. It contains
                   2201:     configuration files of the packages, as well as pkgsrc's mk.conf itself.
                   2202: 
1.154     rillig   2203: 9.1. File system layout in ${LOCALBASE}
1.1       dsieger  2204: 
                   2205: The following directories exist in a typical pkgsrc installation in $
                   2206: {LOCALBASE}.
                   2207: 
                   2208: bin
                   2209: 
                   2210:     Contains executable programs that are intended to be directly used by the
                   2211:     end user.
                   2212: 
                   2213: emul
                   2214: 
                   2215:     Contains files for the emulation layers of various other operating systems,
                   2216:     especially for NetBSD.
                   2217: 
                   2218: etc (the usual location of ${PKG_SYSCONFDIR})
                   2219: 
                   2220:     Contains the configuration files.
                   2221: 
                   2222: include
                   2223: 
                   2224:     Contains headers for the C and C++ programming languages.
                   2225: 
                   2226: info
                   2227: 
                   2228:     Contains GNU info files of various packages.
                   2229: 
                   2230: lib
                   2231: 
                   2232:     Contains shared and static libraries.
                   2233: 
                   2234: libdata
                   2235: 
                   2236:     Contains data files that don't change after installation. Other data files
                   2237:     belong into ${VARBASE}.
                   2238: 
                   2239: libexec
                   2240: 
                   2241:     Contains programs that are not intended to be used by end users, such as
                   2242:     helper programs or network daemons.
                   2243: 
                   2244: libexec/cgi-bin
                   2245: 
                   2246:     Contains programs that are intended to be executed as CGI scripts by a web
                   2247:     server.
                   2248: 
                   2249: man (the usual value of ${PKGMANDIR})
                   2250: 
                   2251:     Contains brief documentation in form of manual pages.
                   2252: 
                   2253: sbin
                   2254: 
                   2255:     Contains programs that are intended to be used only by the super-user.
                   2256: 
                   2257: share
                   2258: 
                   2259:     Contains platform-independent data files that don't change after
                   2260:     installation.
                   2261: 
                   2262: share/doc
                   2263: 
                   2264:     Contains documentation files provided by the packages.
                   2265: 
                   2266: share/examples
                   2267: 
                   2268:     Contains example files provided by the packages. Among others, the original
                   2269:     configuration files are saved here and copied to ${PKG_SYSCONFDIR} during
                   2270:     installation.
                   2271: 
                   2272: share/examples/rc.d
                   2273: 
                   2274:     Contains the original files for rc.d scripts.
                   2275: 
                   2276: var (the usual location of ${VARBASE})
                   2277: 
                   2278:     Contains files that may be modified after installation.
                   2279: 
1.154     rillig   2280: 9.2. File system layout in ${VARBASE}
1.1       dsieger  2281: 
                   2282: db/pkg (the usual location of ${PKG_DBDIR})
                   2283: 
                   2284:     Contains information about the currently installed packages.
                   2285: 
                   2286: games
                   2287: 
                   2288:     Contains highscore files.
                   2289: 
                   2290: log
                   2291: 
                   2292:     Contains log files.
                   2293: 
                   2294: run
                   2295: 
                   2296:     Contains informational files about daemons that are currently running.
                   2297: 
1.154     rillig   2298: Chapter 10. Frequently Asked Questions
1.1       dsieger  2299: 
                   2300: Table of Contents
                   2301: 
1.154     rillig   2302: 10.1. Are there any mailing lists for pkg-related discussion?
                   2303: 10.2. Utilities for package management (pkgtools)
                   2304: 10.3. How to use pkgsrc as non-root
                   2305: 10.4. How to resume transfers when fetching distfiles?
                   2306: 10.5. How can I install/use modular X.org from pkgsrc?
                   2307: 10.6. How to fetch files from behind a firewall
                   2308: 10.7. How to fetch files from HTTPS sites
                   2309: 10.8. How do I tell make fetch to do passive FTP?
                   2310: 10.9. How to fetch all distfiles at once
                   2311: 10.10. What does "Don't know how to make /usr/share/tmac/tmac.andoc" mean?
                   2312: 10.11. What does "Could not find bsd.own.mk" mean?
1.221     nia      2313: 10.12. Using 'sudo' or `priv` with pkgsrc
1.154     rillig   2314: 10.13. How do I change the location of configuration files?
                   2315: 10.14. Automated security checks
                   2316: 10.15. Why do some packages ignore my CFLAGS?
                   2317: 10.16. A package does not build. What shall I do?
                   2318: 10.17. What does "Makefile appears to contain unresolved cvs/rcs/??? merge
1.24      wiz      2319:     conflicts" mean?
1.1       dsieger  2320: 
                   2321: This section contains hints, tips & tricks on special things in pkgsrc that we
                   2322: didn't find a better place for in the previous chapters, and it contains items
                   2323: for both pkgsrc users and developers.
                   2324: 
1.154     rillig   2325: 10.1. Are there any mailing lists for pkg-related discussion?
1.1       dsieger  2326: 
                   2327: The following mailing lists may be of interest to pkgsrc users:
                   2328: 
                   2329:   * pkgsrc-users: This is a general purpose list for most issues regarding
                   2330:     pkgsrc, regardless of platform, e.g. soliciting user help for pkgsrc
                   2331:     configuration, unexpected build failures, using particular packages,
                   2332:     upgrading pkgsrc installations, questions regarding the pkgsrc release
                   2333:     branches, etc. General announcements or proposals for changes that impact
                   2334:     the pkgsrc user community, e.g. major infrastructure changes, new features,
                   2335:     package removals, etc., may also be posted.
                   2336: 
                   2337:   * pkgsrc-bulk: A list where the results of pkgsrc bulk builds are sent and
                   2338:     discussed.
                   2339: 
                   2340:   * pkgsrc-changes: This list is for those who are interested in getting a
                   2341:     commit message for every change committed to pkgsrc. It is also available
                   2342:     in digest form, meaning one daily message containing all commit messages
                   2343:     for changes to the package source tree in that 24 hour period.
                   2344: 
                   2345: To subscribe, do:
                   2346: 
                   2347: % echo subscribe listname | mail majordomo@NetBSD.org
                   2348: 
1.174     leot     2349: Archives for all these mailing lists are available from https://
1.1       dsieger  2350: mail-index.NetBSD.org/.
                   2351: 
1.154     rillig   2352: 10.2. Utilities for package management (pkgtools)
1.1       dsieger  2353: 
                   2354: The directory pkgsrc/pkgtools contains a number of useful utilities for both
                   2355: users and developers of pkgsrc. This section attempts only to make the reader
1.121     sevan    2356: aware of some of the utilities and when they might be useful, and not to
                   2357: duplicate the documentation that comes with each package.
1.1       dsieger  2358: 
                   2359: Utilities used by pkgsrc (automatically installed when needed):
                   2360: 
                   2361:   * pkgtools/x11-links: Symlinks for use by buildlink.
                   2362: 
                   2363: OS tool augmentation (automatically installed when needed):
                   2364: 
1.121     sevan    2365:   * pkgtools/digest: Calculates various kinds of checksums (including SHA3).
1.1       dsieger  2366: 
                   2367:   * pkgtools/libnbcompat: Compatibility library for pkgsrc tools.
                   2368: 
                   2369:   * pkgtools/mtree: Installed on non-BSD systems due to lack of native mtree.
                   2370: 
                   2371:   * pkgtools/pkg_install: Up-to-date replacement for /usr/sbin/pkg_install, or
                   2372:     for use on operating systems where pkg_install is not present.
                   2373: 
                   2374: Utilities used by pkgsrc (not automatically installed):
                   2375: 
                   2376:   * pkgtools/pkg_tarup: Create a binary package from an already-installed
                   2377:     package. Used by make replace to save the old package.
                   2378: 
                   2379:   * pkgtools/dfdisk: Adds extra functionality to pkgsrc, allowing it to fetch
                   2380:     distfiles from multiple locations. It currently supports the following
                   2381:     methods: multiple CD-ROMs and network FTP/HTTP connections.
                   2382: 
                   2383:   * devel/cpuflags: Determine the best compiler flags to optimise code for your
1.24      wiz      2384:     current CPU and compiler.
1.1       dsieger  2385: 
                   2386: Utilities for keeping track of installed packages, being up to date, etc:
                   2387: 
1.65      wiz      2388:   * pkgtools/pkgin: A package update tool similar to apt(1). Download, install,
                   2389:     and upgrade binary packages easily.
                   2390: 
1.1       dsieger  2391:   * pkgtools/pkg_chk: Reports on packages whose installed versions do not match
                   2392:     the latest pkgsrc entries.
                   2393: 
                   2394:   * pkgtools/pkgdep: Makes dependency graphs of packages, to aid in choosing a
                   2395:     strategy for updating.
                   2396: 
                   2397:   * pkgtools/pkgdepgraph: Makes graphs from the output of pkgtools/pkgdep (uses
                   2398:     graphviz).
                   2399: 
1.12      weinem   2400:   * pkgtools/pkglint: The pkglint(1) program checks a pkgsrc entry for errors.
                   2401: 
                   2402:   * pkgtools/lintpkgsrc: The lintpkgsrc(1) program does various checks on the
                   2403:     complete pkgsrc system.
1.1       dsieger  2404: 
                   2405:   * pkgtools/pkgsurvey: Report what packages you have installed.
                   2406: 
                   2407: Utilities for people maintaining or creating individual packages:
                   2408: 
                   2409:   * pkgtools/pkgdiff: Automate making and maintaining patches for a package
                   2410:     (includes pkgdiff, pkgvi, mkpatches, etc.).
                   2411: 
1.65      wiz      2412:   * pkgtools/url2pkg: Aids in converting to pkgsrc.
1.1       dsieger  2413: 
                   2414: Utilities for people maintaining pkgsrc (or: more obscure pkg utilities)
                   2415: 
                   2416:   * pkgtools/pkg_comp: Build packages in a chrooted area.
                   2417: 
                   2418:   * pkgtools/libkver: Spoof kernel version for chrooted cross builds.
                   2419: 
1.154     rillig   2420: 10.3. How to use pkgsrc as non-root
1.1       dsieger  2421: 
1.108     rillig   2422: To install packages from source as a non-root user, download pkgsrc as
1.154     rillig   2423: described in Chapter 3, Where to get pkgsrc and how to keep it up-to-date, cd
1.108     rillig   2424: into that directory and run the command ./bootstrap/bootstrap --unprivileged.
                   2425: 
                   2426: This will install the binary part of pkgsrc to ~/pkg and put the pkgsrc
                   2427: configuration mk.conf into ~/pkg/etc.
                   2428: 
                   2429: For more details, see mk/unprivileged.mk.
1.1       dsieger  2430: 
1.154     rillig   2431: 10.4. How to resume transfers when fetching distfiles?
1.1       dsieger  2432: 
                   2433: By default, resuming transfers in pkgsrc is disabled, but you can enable this
1.4       rillig   2434: feature by adding the option PKG_RESUME_TRANSFERS=YES into mk.conf. If, during
                   2435: a fetch step, an incomplete distfile is found, pkgsrc will try to resume it.
1.1       dsieger  2436: 
1.61      wiz      2437: You can also use a different program than the platform default program by
                   2438: changing the FETCH_USING variable. You can specify the program by using of ftp,
                   2439: fetch, wget or curl. Alternatively, fetching can be disabled by using the value
                   2440: manual. A value of custom disables the system defaults and dependency tracking
                   2441: for the fetch program. In that case you have to provide FETCH_CMD,
                   2442: FETCH_BEFORE_ARGS, FETCH_RESUME_ARGS, FETCH_OUTPUT_ARGS, FETCH_AFTER_ARGS.
1.1       dsieger  2443: 
1.16      jnemeth  2444: For example, if you want to use wget to download, you'll have to use something
                   2445: like:
1.1       dsieger  2446: 
1.16      jnemeth  2447: FETCH_USING=    wget
1.1       dsieger  2448: 
1.154     rillig   2449: 10.5. How can I install/use modular X.org from pkgsrc?
1.1       dsieger  2450: 
1.4       rillig   2451: If you want to use modular X.org from pkgsrc instead of your system's own X11
                   2452: (/usr/X11R6, /usr/openwin, ...) you will have to add the following line into
1.1       dsieger  2453: mk.conf:
                   2454: 
1.4       rillig   2455: X11_TYPE=modular
1.1       dsieger  2456: 
1.154     rillig   2457: 10.6. How to fetch files from behind a firewall
1.1       dsieger  2458: 
                   2459: If you are sitting behind a firewall which does not allow direct connections to
                   2460: Internet hosts (i.e. non-NAT), you may specify the relevant proxy hosts. This
                   2461: is done using an environment variable in the form of a URL, e.g. in Amdahl, the
                   2462: machine "orpheus.amdahl.com" is one of the firewalls, and it uses port 80 as
                   2463: the proxy port number. So the proxy environment variables are:
                   2464: 
                   2465: ftp_proxy=ftp://orpheus.amdahl.com:80/
                   2466: http_proxy=http://orpheus.amdahl.com:80/
                   2467: 
1.154     rillig   2468: 10.7. How to fetch files from HTTPS sites
1.65      wiz      2469: 
                   2470: Some fetch tools are not prepared to support HTTPS by default (for example, the
                   2471: one in NetBSD 6.0), or the one installed by the pkgsrc bootstrap (to avoid an
                   2472: openssl dependency that low in the dependency graph).
                   2473: 
                   2474: Usually you won't notice, because distribution files are mirrored weekly to "
                   2475: ftp.NetBSD.org", but that might not be often enough if you are following
                   2476: pkgsrc-current. In that case, set FETCH_USING in your mk.conf file to "curl" or
                   2477: "wget", which are both compiled with HTTPS support by default. Of course, these
                   2478: tools need to be installed before you can use them this way.
                   2479: 
1.154     rillig   2480: 10.8. How do I tell make fetch to do passive FTP?
1.1       dsieger  2481: 
                   2482: This depends on which utility is used to retrieve distfiles. From bsd.pkg.mk,
                   2483: FETCH_CMD is assigned the first available command from the following list:
                   2484: 
                   2485:   * ${LOCALBASE}/bin/ftp
                   2486: 
                   2487:   * /usr/bin/ftp
                   2488: 
                   2489: On a default NetBSD installation, this will be /usr/bin/ftp, which
                   2490: automatically tries passive connections first, and falls back to active
                   2491: connections if the server refuses to do passive. For the other tools, add the
1.4       rillig   2492: following to your mk.conf file: PASSIVE_FETCH=1.
1.1       dsieger  2493: 
                   2494: Having that option present will prevent /usr/bin/ftp from falling back to
                   2495: active transfers.
                   2496: 
1.154     rillig   2497: 10.9. How to fetch all distfiles at once
1.1       dsieger  2498: 
                   2499: You would like to download all the distfiles in a single batch from work or
                   2500: university, where you can't run a make fetch. There is an archive of distfiles
                   2501: on ftp.NetBSD.org, but downloading the entire directory may not be appropriate.
                   2502: 
                   2503: The answer here is to do a make fetch-list in /usr/pkgsrc or one of its
                   2504: subdirectories, carry the resulting list to your machine at work/school and use
                   2505: it there. If you don't have a NetBSD-compatible ftp(1) (like tnftp) at work,
                   2506: don't forget to set FETCH_CMD to something that fetches a URL:
                   2507: 
                   2508: At home:
                   2509: 
                   2510: % cd /usr/pkgsrc
                   2511: % make fetch-list FETCH_CMD=wget DISTDIR=/tmp/distfiles >/tmp/fetch.sh
                   2512: % scp /tmp/fetch.sh work:/tmp
                   2513: 
                   2514: At work:
                   2515: 
                   2516: % sh /tmp/fetch.sh
                   2517: 
                   2518: then tar up /tmp/distfiles and take it home.
                   2519: 
                   2520: If you have a machine running NetBSD, and you want to get all distfiles (even
                   2521: ones that aren't for your machine architecture), you can do so by using the
                   2522: above-mentioned make fetch-list approach, or fetch the distfiles directly by
                   2523: running:
                   2524: 
                   2525: % make mirror-distfiles
                   2526: 
                   2527: If you even decide to ignore NO_{SRC,BIN}_ON_{FTP,CDROM}, then you can get
                   2528: everything by running:
                   2529: 
                   2530: % make fetch NO_SKIP=yes
                   2531: 
1.154     rillig   2532: 10.10. What does "Don't know how to make /usr/share/tmac/tmac.andoc" mean?
1.1       dsieger  2533: 
                   2534: When compiling the pkgtools/pkg_install package, you get the error from make
                   2535: that it doesn't know how to make /usr/share/tmac/tmac.andoc? This indicates
                   2536: that you don't have installed the "text" set (nroff, ...) from the NetBSD base
                   2537: distribution on your machine. It is recommended to do that to format man pages.
                   2538: 
                   2539: In the case of the pkgtools/pkg_install package, you can get away with setting
1.4       rillig   2540: NOMAN=YES either in the environment or in mk.conf.
1.1       dsieger  2541: 
1.154     rillig   2542: 10.11. What does "Could not find bsd.own.mk" mean?
1.1       dsieger  2543: 
                   2544: You didn't install the compiler set, comp.tgz, when you installed your NetBSD
                   2545: machine. Please get and install it, by extracting it in /:
                   2546: 
                   2547: # cd /
                   2548: # tar --unlink -zxvpf .../comp.tgz
                   2549: 
                   2550: comp.tgz is part of every NetBSD release. Get the one that corresponds to your
                   2551: release (determine via uname -r).
                   2552: 
1.221     nia      2553: 10.12. Using 'sudo' or `priv` with pkgsrc
1.1       dsieger  2554: 
                   2555: When installing packages as non-root user and using the just-in-time su(1)
                   2556: feature of pkgsrc, it can become annoying to type in the root password for each
                   2557: required package installed. To avoid this, the sudo package can be used, which
1.221     nia      2558: does password caching over a limited time. To use it, install sudo or priv
                   2559: (either as binary package, from security/priv, or security/sudo) and then put
                   2560: the following into your mk.conf, somewhere after the definition of the
                   2561: LOCALBASE variable:
1.1       dsieger  2562: 
                   2563: .if exists(${LOCALBASE}/bin/sudo)
                   2564: SU_CMD=        ${LOCALBASE}/bin/sudo /bin/sh -c
                   2565: .endif
                   2566: 
1.154     rillig   2567: 10.13. How do I change the location of configuration files?
1.1       dsieger  2568: 
                   2569: As the system administrator, you can choose where configuration files are
                   2570: installed. The default settings make all these files go into ${PREFIX}/etc or
                   2571: some of its subdirectories; this may be suboptimal depending on your
                   2572: expectations (e.g., a read-only, NFS-exported PREFIX with a need of per-machine
                   2573: configuration of the provided packages).
                   2574: 
                   2575: In order to change the defaults, you can modify the PKG_SYSCONFBASE variable
1.4       rillig   2576: (in mk.conf) to point to your preferred configuration directory; some common
                   2577: examples include /etc or /etc/pkg.
1.1       dsieger  2578: 
                   2579: Furthermore, you can change this value on a per-package basis by setting the
                   2580: PKG_SYSCONFDIR.${PKG_SYSCONFVAR} variable. PKG_SYSCONFVAR's value usually
                   2581: matches the name of the package you would like to modify, that is, the contents
                   2582: of PKGBASE.
                   2583: 
                   2584: Note that after changing these settings, you must rebuild and reinstall any
                   2585: affected packages.
                   2586: 
1.154     rillig   2587: 10.14. Automated security checks
1.1       dsieger  2588: 
                   2589: Please be aware that there can often be bugs in third-party software, and some
                   2590: of these bugs can leave a machine vulnerable to exploitation by attackers. In
                   2591: an effort to lessen the exposure, the NetBSD packages team maintains a database
                   2592: of known-exploits to packages which have at one time been included in pkgsrc.
                   2593: The database can be downloaded automatically, and a security audit of all
1.14      jmcneill 2594: packages installed on a system can take place. To do this, refer to the
                   2595: following two tools (installed as part of the pkgtools/pkg_install package):
1.1       dsieger  2596: 
1.21      snj      2597:  1. pkg_admin fetch-pkg-vulnerabilities, an easy way to download a list of the
                   2598:     security vulnerabilities information. This list is kept up to date by the
1.26      spz      2599:     pkgsrc security team, and is distributed from the NetBSD ftp server:
1.1       dsieger  2600: 
1.177     leot     2601:     https://ftp.NetBSD.org/pub/NetBSD/packages/vulns/pkg-vulnerabilities
1.1       dsieger  2602: 
1.21      snj      2603:  2. pkg_admin audit, an easy way to audit the current machine, checking each
1.24      wiz      2604:     known vulnerability. If a vulnerable package is installed, it will be shown
                   2605:     by output to stdout, including a description of the type of vulnerability,
                   2606:     and a URL containing more information.
1.1       dsieger  2607: 
1.202     nia      2608: Use of these tools is strongly recommended! See Section 5.1.6, "Checking for
1.121     sevan    2609: security vulnerabilities in installed packages" for instructions on how to
                   2610: automate checking and reporting.
                   2611: 
                   2612: If this database is installed, pkgsrc builds will use it to perform a security
                   2613: check before building any package.
1.1       dsieger  2614: 
1.154     rillig   2615: 10.15. Why do some packages ignore my CFLAGS?
1.1       dsieger  2616: 
                   2617: When you add your own preferences to the CFLAGS variable in your mk.conf, these
                   2618: flags are passed in environment variables to the ./configure scripts and to
                   2619: make(1). Some package authors ignore the CFLAGS from the environment variable
                   2620: by overriding them in the Makefiles of their package.
                   2621: 
                   2622: Currently there is no solution to this problem. If you really need the package
                   2623: to use your CFLAGS you should run make patch in the package directory and then
                   2624: inspect any Makefile and Makefile.in for whether they define CFLAGS explicitly.
                   2625: Usually you can remove these lines. But be aware that some "smart" programmers
                   2626: write so bad code that it only works for the specific combination of CFLAGS
                   2627: they have chosen.
                   2628: 
1.172     rillig   2629: To find out where the CFLAGS are ignored, add the following lines to mk.conf:
                   2630: 
                   2631: CPPFLAGS+=              -Dpkgsrc___CPPFLAGS
                   2632: CFLAGS+=                -Dpkgsrc___CFLAGS
                   2633: CXXFLAGS+=              -Dpkgsrc___CXXFLAGS
                   2634: 
                   2635: Then run bmake show-all-configure show-all-build to see whether the above flags
                   2636: are passed to the actual build commands in general.
                   2637: 
                   2638: To find out whether the flags are passed to individual compiler commands, have
                   2639: a look at the file work/.work.log. In most cases, the flags from the original
                   2640: command lines (the lines starting with [*]) are passed unmodified to the actual
                   2641: compiler (the lines starting with <.>). If the flag is missing from the actual
                   2642: compiler command, it must have been removed by the pkgsrc compiler wrappers.
                   2643: 
1.154     rillig   2644: 10.16. A package does not build. What shall I do?
1.1       dsieger  2645: 
                   2646:  1. Make sure that your copy of pkgsrc is consistent. A case that occurs often
                   2647:     is that people only update pkgsrc in parts, because of performance reasons.
                   2648:     Since pkgsrc is one large system, not a collection of many small systems,
                   2649:     there are sometimes changes that only work when the whole pkgsrc tree is
                   2650:     updated.
                   2651: 
1.25      wiz      2652:  2. Make sure that you don't have any CVS conflicts. Search for "<<<<<<" or "
                   2653:     >>>>>>" in all your pkgsrc files.
1.1       dsieger  2654: 
1.25      wiz      2655:  3. Make sure that you don't have old copies of the packages extracted. Run 
1.1       dsieger  2656:     make clean clean-depends to verify this.
                   2657: 
1.108     rillig   2658:  4. If you are a package developer who wants to invest some work, have a look
1.154     rillig   2659:     at Chapter 21, Making your package work.
1.108     rillig   2660: 
                   2661:  5. If the problem still exists, write a mail to the pkgsrc-users mailing list.
1.1       dsieger  2662: 
1.154     rillig   2663: 10.17. What does "Makefile appears to contain unresolved cvs/rcs/??? merge
1.1       dsieger  2664: conflicts" mean?
                   2665: 
                   2666: You have modified a file from pkgsrc, and someone else has modified that same
                   2667: file afterwards in the CVS repository. Both changes are in the same region of
                   2668: the file, so when you updated pkgsrc, the cvs command marked the conflicting
                   2669: changes in the file. Because of these markers, the file is no longer a valid
                   2670: Makefile.
                   2671: 
                   2672: Have a look at that file, and if you don't need your local changes anymore, you
                   2673: can remove that file and run cvs -q update -dP in that directory to download
                   2674: the current version.
                   2675: 
                   2676: Part II. The pkgsrc developer's guide
                   2677: 
                   2678: This part of the book deals with creating and modifying packages. It starts
                   2679: with a "HOWTO"-like guide on creating a new package. The remaining chapters are
                   2680: more like a reference manual for pkgsrc.
                   2681: 
                   2682: Table of Contents
                   2683: 
1.154     rillig   2684: 11. Getting help
1.184     rillig   2685: 12. Package components - files, directories and contents
1.1       dsieger  2686: 
1.184     rillig   2687:     12.1. Makefile
                   2688:     12.2. distinfo
                   2689:     12.3. patches/*
1.1       dsieger  2690: 
1.184     rillig   2691:         12.3.1. Structure of a single patch file
                   2692:         12.3.2. Creating patch files
                   2693:         12.3.3. Sources where the patch files come from
                   2694:         12.3.4. Patching guidelines
                   2695:         12.3.5. Feedback to the author
1.1       dsieger  2696: 
1.184     rillig   2697:     12.4. Other mandatory files
                   2698:     12.5. Optional files
1.1       dsieger  2699: 
1.184     rillig   2700:         12.5.1. Files affecting the binary package
                   2701:         12.5.2. Files affecting the build process
                   2702:         12.5.3. Files affecting nothing at all
1.1       dsieger  2703: 
1.184     rillig   2704:     12.6. work*
                   2705:     12.7. files/*
1.1       dsieger  2706: 
1.184     rillig   2707: 13. The build process
1.1       dsieger  2708: 
1.184     rillig   2709:     13.1. Introduction
                   2710:     13.2. Program location
                   2711:     13.3. Directories used during the build process
                   2712:     13.4. Running a phase
                   2713:     13.5. The fetch phase
1.1       dsieger  2714: 
1.184     rillig   2715:         13.5.1. What to fetch and where to get it from
                   2716:         13.5.2. How are the files fetched?
1.1       dsieger  2717: 
1.184     rillig   2718:     13.6. The checksum phase
                   2719:     13.7. The extract phase
                   2720:     13.8. The patch phase
                   2721:     13.9. The tools phase
                   2722:     13.10. The wrapper phase
                   2723:     13.11. The configure phase
                   2724:     13.12. The build phase
                   2725:     13.13. The test phase
                   2726:     13.14. The install phase
                   2727:     13.15. The package phase
                   2728:     13.16. Cleaning up
                   2729:     13.17. Other helpful targets
1.1       dsieger  2730: 
1.184     rillig   2731: 14. Creating a new pkgsrc package from scratch
1.1       dsieger  2732: 
1.184     rillig   2733:     14.1. Common types of packages
1.1       dsieger  2734: 
1.219     nia      2735:         14.1.1. Python modules and programs
                   2736:         14.1.2. R packages
                   2737:         14.1.3. TeXlive packages
1.1       dsieger  2738: 
1.184     rillig   2739:     14.2. Examples
1.1       dsieger  2740: 
1.184     rillig   2741:         14.2.1. How the www/nvu package came into pkgsrc
1.1       dsieger  2742: 
1.184     rillig   2743: 15. Programming in Makefiles
1.1       dsieger  2744: 
1.184     rillig   2745:     15.1. Caveats
                   2746:     15.2. Makefile variables
1.1       dsieger  2747: 
1.184     rillig   2748:         15.2.1. Naming conventions
1.1       dsieger  2749: 
1.184     rillig   2750:     15.3. Code snippets
1.1       dsieger  2751: 
1.184     rillig   2752:         15.3.1. Adding things to a list
                   2753:         15.3.2. Echoing a string exactly as-is
                   2754:         15.3.3. Passing CFLAGS to GNU configure scripts
                   2755:         15.3.4. Handling possibly empty variables
1.229   ! gutterid 2756:         15.3.5. Testing yes/no variables in conditions
1.1       dsieger  2757: 
1.184     rillig   2758: 16. Options handling
1.1       dsieger  2759: 
1.184     rillig   2760:     16.1. Global default options
                   2761:     16.2. Converting packages to use bsd.options.mk
                   2762:     16.3. Option Names
                   2763:     16.4. Determining the options of dependencies
1.1       dsieger  2764: 
1.184     rillig   2765: 17. Tools needed for building or running
1.1       dsieger  2766: 
1.184     rillig   2767:     17.1. Tools for pkgsrc builds
                   2768:     17.2. Tools needed by packages
                   2769:     17.3. Tools provided by platforms
1.1       dsieger  2770: 
1.184     rillig   2771: 18. Buildlink methodology
1.1       dsieger  2772: 
1.184     rillig   2773:     18.1. Converting packages to use buildlink3
                   2774:     18.2. Writing buildlink3.mk files
1.1       dsieger  2775: 
1.184     rillig   2776:         18.2.1. Anatomy of a buildlink3.mk file
                   2777:         18.2.2. Updating BUILDLINK_API_DEPENDS.pkg and BUILDLINK_ABI_DEPENDS.
                   2778:             pkg in buildlink3.mk files
1.1       dsieger  2779: 
1.184     rillig   2780:     18.3. Writing builtin.mk files
1.1       dsieger  2781: 
1.184     rillig   2782:         18.3.1. Anatomy of a builtin.mk file
                   2783:         18.3.2. Global preferences for native or pkgsrc software
1.1       dsieger  2784: 
1.184     rillig   2785: 19. PLIST issues
1.1       dsieger  2786: 
1.184     rillig   2787:     19.1. RCS ID
                   2788:     19.2. Semi-automatic PLIST generation
                   2789:     19.3. Tweaking output of make print-PLIST
                   2790:     19.4. Variable substitution in PLIST
                   2791:     19.5. Man page compression
                   2792:     19.6. Changing PLIST source with PLIST_SRC
                   2793:     19.7. Platform-specific and differing PLISTs
                   2794:     19.8. Build-specific PLISTs
                   2795:     19.9. Sharing directories between packages
1.1       dsieger  2796: 
1.184     rillig   2797: 20. The pkginstall framework
1.1       dsieger  2798: 
1.184     rillig   2799:     20.1. Files and directories outside the installation prefix
1.1       dsieger  2800: 
1.184     rillig   2801:         20.1.1. Directory manipulation
                   2802:         20.1.2. File manipulation
1.1       dsieger  2803: 
1.184     rillig   2804:     20.2. Configuration files
1.1       dsieger  2805: 
1.184     rillig   2806:         20.2.1. How PKG_SYSCONFDIR is set
                   2807:         20.2.2. Telling the software where configuration files are
                   2808:         20.2.3. Patching installations
                   2809:         20.2.4. Disabling handling of configuration files
1.1       dsieger  2810: 
1.184     rillig   2811:     20.3. System startup scripts
1.1       dsieger  2812: 
1.184     rillig   2813:         20.3.1. Disabling handling of system startup scripts
1.1       dsieger  2814: 
1.184     rillig   2815:     20.4. System users and groups
                   2816:     20.5. System shells
1.1       dsieger  2817: 
1.184     rillig   2818:         20.5.1. Disabling shell registration
1.1       dsieger  2819: 
1.184     rillig   2820:     20.6. Fonts
1.1       dsieger  2821: 
1.184     rillig   2822:         20.6.1. Disabling automatic update of the fonts databases
1.1       dsieger  2823: 
1.154     rillig   2824: 21. Making your package work
1.1       dsieger  2825: 
1.154     rillig   2826:     21.1. General operation
1.1       dsieger  2827: 
1.154     rillig   2828:         21.1.1. How to pull in user-settable variables from mk.conf
                   2829:         21.1.2. User interaction
                   2830:         21.1.3. Handling licenses
                   2831:         21.1.4. Restricted packages
                   2832:         21.1.5. Handling dependencies
                   2833:         21.1.6. Handling conflicts with other packages
                   2834:         21.1.7. Packages that cannot or should not be built
                   2835:         21.1.8. Packages which should not be deleted, once installed
                   2836:         21.1.9. Handling packages with security problems
                   2837:         21.1.10. How to handle incrementing versions when fixing an existing
1.1       dsieger  2838:             package
1.154     rillig   2839:         21.1.11. Substituting variable text in the package files (the SUBST
1.1       dsieger  2840:             framework)
                   2841: 
1.154     rillig   2842:     21.2. The fetch phase
1.1       dsieger  2843: 
1.154     rillig   2844:         21.2.1. Packages whose distfiles aren't available for plain downloading
                   2845:         21.2.2. How to handle modified distfiles with the 'old' name
                   2846:         21.2.3. Packages hosted on github.com
                   2847: 
                   2848:     21.3. The configure phase
                   2849: 
                   2850:         21.3.1. Shared libraries - libtool
                   2851:         21.3.2. Using libtool on GNU packages that already support libtool
                   2852:         21.3.3. GNU Autoconf/Automake
1.223     nia      2853:         21.3.4. Meson / ninja
1.154     rillig   2854: 
                   2855:     21.4. Programming languages
                   2856: 
                   2857:         21.4.1. C, C++, and Fortran
                   2858:         21.4.2. Java
1.205     wiz      2859:         21.4.3. Go
1.223     nia      2860:         21.4.4. Rust
                   2861:         21.4.5. Packages containing Perl scripts
                   2862:         21.4.6. Packages containing shell scripts
                   2863:         21.4.7. Other programming languages
1.154     rillig   2864: 
                   2865:     21.5. The build phase
                   2866: 
                   2867:         21.5.1. Compiling C and C++ code conditionally
                   2868:         21.5.2. How to handle compiler bugs
1.172     rillig   2869:         21.5.3. No such file or directory
                   2870:         21.5.4. Undefined reference to "..."
                   2871:         21.5.5. Running out of memory
1.154     rillig   2872: 
                   2873:     21.6. The install phase
                   2874: 
                   2875:         21.6.1. Creating needed directories
                   2876:         21.6.2. Where to install documentation
                   2877:         21.6.3. Installing highscore files
                   2878:         21.6.4. Adding DESTDIR support to packages
                   2879:         21.6.5. Packages with hardcoded paths to other interpreters
1.203     nia      2880:         21.6.6. Packages installing Perl modules
1.154     rillig   2881:         21.6.7. Packages installing info files
                   2882:         21.6.8. Packages installing man pages
1.203     nia      2883:         21.6.9. Packages installing X11 fonts
                   2884:         21.6.10. Packages installing SGML or XML data
                   2885:         21.6.11. Packages installing extensions to the MIME database
                   2886:         21.6.12. Packages using intltool
                   2887:         21.6.13. Packages installing startup scripts
                   2888:         21.6.14. Packages installing TeX modules
                   2889:         21.6.15. Packages supporting running binaries in emulation
                   2890:         21.6.16. Packages installing hicolor icons
                   2891:         21.6.17. Packages installing desktop files
1.154     rillig   2892: 
                   2893:     21.7. Marking packages as having problems
                   2894: 
1.184     rillig   2895: 22. GNOME packaging and porting
                   2896: 
                   2897:     22.1. Meta packages
                   2898:     22.2. Packaging a GNOME application
                   2899:     22.3. Updating GNOME to a newer version
                   2900:     22.4. Patching guidelines
                   2901: 
1.154     rillig   2902: 23. Submitting and Committing
                   2903: 
                   2904:     23.1. Submitting binary packages
                   2905:     23.2. Submitting source packages (for non-NetBSD-developers)
                   2906:     23.3. General notes when adding, updating, or removing packages
                   2907:     23.4. Commit Messages
                   2908:     23.5. Committing: Adding a package to CVS
                   2909:     23.6. Updating a package to a newer version
                   2910:     23.7. Renaming a package in pkgsrc
                   2911:     23.8. Moving a package in pkgsrc
                   2912: 
                   2913: 24. Frequently Asked Questions
                   2914: 
                   2915: Chapter 11. Getting help
                   2916: 
                   2917: To get help when developing pkgsrc, the definitive source is this document, the
                   2918: pkgsrc guide. If you don't find anything here, there are alternatives:
                   2919: 
                   2920:   * The built-in pkgsrc help, which is available after bootstrapping pkgsrc.
                   2921:     Run bmake help topic=? to get help for any topic, such as a variable name
                   2922:     like BUILD_DEFS, a make target like do-build, a missing C or C++ function
                   2923:     like strcasecmp or any other topic.
                   2924: 
1.207     leot     2925:     The available help topics are listed in Appendix E, Help topics.
1.154     rillig   2926: 
1.163     rillig   2927:   * To see the value of a single variable, run bmake show-var VARNAME=X.
                   2928: 
                   2929:   * To see the values of the most common variables, run bmake show-all. These
                   2930:     variables are grouped by topic. To see the variables for a single topic,
                   2931:     run bmake show-all-topic, for example bmake show-all-fetch.
                   2932: 
1.154     rillig   2933:   * The tech-pkg mailing list, to which you can subscribe and then ask your
                   2934:     questions.
                   2935: 
                   2936:   * The #pkgsrc IRC channel, which is accessible via a web browser or by using
                   2937:     a specialized chat program such as XChat. Pick any user name and join the
                   2938:     channel #pkgsrc.
1.1       dsieger  2939: 
1.184     rillig   2940: Chapter 12. Package components - files, directories and contents
1.1       dsieger  2941: 
                   2942: Table of Contents
                   2943: 
1.184     rillig   2944: 12.1. Makefile
                   2945: 12.2. distinfo
                   2946: 12.3. patches/*
                   2947: 
                   2948:     12.3.1. Structure of a single patch file
                   2949:     12.3.2. Creating patch files
                   2950:     12.3.3. Sources where the patch files come from
                   2951:     12.3.4. Patching guidelines
                   2952:     12.3.5. Feedback to the author
                   2953: 
                   2954: 12.4. Other mandatory files
                   2955: 12.5. Optional files
                   2956: 
                   2957:     12.5.1. Files affecting the binary package
                   2958:     12.5.2. Files affecting the build process
                   2959:     12.5.3. Files affecting nothing at all
1.1       dsieger  2960: 
1.184     rillig   2961: 12.6. work*
                   2962: 12.7. files/*
1.1       dsieger  2963: 
1.184     rillig   2964: Whenever you're preparing a package, there are a number of files involved which
                   2965: are described in the following sections.
1.1       dsieger  2966: 
1.184     rillig   2967: 12.1. Makefile
1.1       dsieger  2968: 
1.184     rillig   2969: Building, installation and creation of a binary package are all controlled by
                   2970: the package's Makefile. The Makefile describes various things about a package,
                   2971: for example from where to get it, how to configure, build, and install it.
1.1       dsieger  2972: 
1.184     rillig   2973: A package Makefile contains several sections that describe the package.
1.1       dsieger  2974: 
1.184     rillig   2975: In the first section there are the following variables, which should appear
                   2976: exactly in the order given here. The order and grouping of the variables is
                   2977: mostly historical and has no further meaning.
1.1       dsieger  2978: 
1.184     rillig   2979:   * DISTNAME is the basename of the distribution file to be downloaded from the
                   2980:     package's website.
1.1       dsieger  2981: 
1.184     rillig   2982:   * PKGNAME is the name of the package, as used by pkgsrc. You need to provide
                   2983:     it if DISTNAME (which is the default) is not a good name for the package in
                   2984:     pkgsrc or DISTNAME is not provided (no distribution file is required).
                   2985:     Usually it is the pkgsrc directory name together with the version number.
                   2986:     It must match the regular expression ^[A-Za-z0-9][A-Za-z0-9-_.+]*$, that
                   2987:     is, it starts with a letter or digit, and contains only letters, digits,
1.204     nia      2988:     dashes, underscores, dots and plus signs. New packages should have entirely
                   2989:     lower-case names, with the exception of some that must follow pre-existing
                   2990:     conventions (e.g. R packages begin with R-). You can use the :tl variable
                   2991:     modifier to lower-case the package name.
1.26      spz      2992: 
1.184     rillig   2993:   * CATEGORIES is a list of categories which the package fits in. You can
                   2994:     choose any of the top-level directories of pkgsrc for it.
1.1       dsieger  2995: 
1.184     rillig   2996:     Currently the following values are available for CATEGORIES. If more than
                   2997:     one is used, they need to be separated by spaces:
1.1       dsieger  2998: 
1.184     rillig   2999:     archivers     cross         geography     meta-pkgs     security
                   3000:     audio         databases     graphics      misc          shells
                   3001:     benchmarks    devel         ham           multimedia    sysutils
                   3002:     biology       editors       inputmethod   net           textproc
                   3003:     cad           emulators     lang          news          time
                   3004:     chat          finance       mail          parallel      wm
                   3005:     comms         fonts         math          pkgtools      www
                   3006:     converters    games         mbone         print         x11
1.1       dsieger  3007: 
1.184     rillig   3008:   * MASTER_SITES, DYNAMIC_MASTER_SITES, DIST_SUBDIR, EXTRACT_SUFX and DISTFILES
                   3009:     are discussed in detail in Section 13.5, "The fetch phase".
1.1       dsieger  3010: 
1.184     rillig   3011: The second section contains information about separately downloaded patches, if
                   3012: any.
1.1       dsieger  3013: 
1.184     rillig   3014:   * PATCHFILES: Name(s) of additional files that contain distribution patches.
                   3015:     There is no default. pkgsrc will look for them at PATCH_SITES. They will
                   3016:     automatically be uncompressed before patching if the names end with .gz or
                   3017:     .Z.
1.1       dsieger  3018: 
1.184     rillig   3019:   * PATCH_SITES: Primary location(s) for distribution patch files (see
                   3020:     PATCHFILES above) if not found locally.
1.1       dsieger  3021: 
1.184     rillig   3022:   * PATCH_DIST_STRIP: an argument to patch(1) that sets the pathname strip
                   3023:     count to help find the correct files to patch. It defaults to -p0.
1.1       dsieger  3024: 
1.184     rillig   3025: The third section contains the following variables.
1.1       dsieger  3026: 
1.184     rillig   3027:   * MAINTAINER is the email address of the person who feels responsible for
                   3028:     this package, and who is most likely to look at problems or questions
                   3029:     regarding this package which have been reported with send-pr(1). Other
                   3030:     developers may contact the MAINTAINER before making changes to the package,
                   3031:     but are not required to do so. When packaging a new program, set MAINTAINER
                   3032:     to yourself. If you really can't maintain the package for future updates,
                   3033:     set it to <pkgsrc-users@NetBSD.org>.
1.1       dsieger  3034: 
1.184     rillig   3035:   * OWNER should be used instead of MAINTAINER when you do not want other
                   3036:     developers to update or change the package without contacting you first. A
                   3037:     package Makefile should contain one of MAINTAINER or OWNER, but not both.
1.1       dsieger  3038: 
1.184     rillig   3039:   * HOMEPAGE is a URL where users can find more information about the package.
1.1       dsieger  3040: 
1.184     rillig   3041:   * COMMENT is a one-line description of the package (should not include the
                   3042:     package name).
1.1       dsieger  3043: 
1.184     rillig   3044:   * LICENSE indicates the license(s) applicable for the package. See
                   3045:     Section 21.1.3, "Handling licenses" for further details.
1.1       dsieger  3046: 
1.184     rillig   3047: Other variables that affect the build:
1.1       dsieger  3048: 
1.184     rillig   3049:   * WRKSRC: The directory where the interesting distribution files of the
                   3050:     package are found. The default is ${WRKDIR}/${DISTNAME}, which works for
                   3051:     most packages.
1.1       dsieger  3052: 
1.184     rillig   3053:     If a package doesn't create a subdirectory for itself (most GNU software
                   3054:     does, for instance), but extracts itself in the current directory, you
                   3055:     should set WRKSRC=${WRKDIR}.
1.1       dsieger  3056: 
1.184     rillig   3057:     If a package doesn't create a subdirectory with the name of DISTNAME but
                   3058:     some different name, set WRKSRC to point to the proper name in ${WRKDIR},
                   3059:     for example WRKSRC=${WRKDIR}/${DISTNAME}/unix. See lang/tcl and x11/tk for
                   3060:     other examples.
1.17      imil     3061: 
1.184     rillig   3062:     The name of the working directory created by pkgsrc is taken from the
                   3063:     WRKDIR_BASENAME variable. By default, its value is work. If you want to use
                   3064:     the same pkgsrc tree for building different kinds of binary packages, you
                   3065:     can change the variable according to your needs. Two other variables handle
                   3066:     common cases of setting WRKDIR_BASENAME individually. If OBJHOSTNAME is
                   3067:     defined in mk.conf, the first component of the host's name is attached to
                   3068:     the directory name. If OBJMACHINE is defined, the platform name is
                   3069:     attached, which might look like work.i386 or work.sparc.
1.17      imil     3070: 
1.184     rillig   3071: Please pay attention to the following gotchas:
1.17      imil     3072: 
1.184     rillig   3073:   * Add MANCOMPRESSED if man pages are installed in compressed form by the
                   3074:     package. For packages using BSD-style makefiles which honor MANZ, there is
                   3075:     MANCOMPRESSED_IF_MANZ.
1.17      imil     3076: 
1.184     rillig   3077:   * Replace /usr/local with "${PREFIX}" in all files (see patches, below).
1.103     wiz      3078: 
1.184     rillig   3079:   * If the package installs any info files, see Section 21.6.7, "Packages
                   3080:     installing info files".
1.103     wiz      3081: 
1.184     rillig   3082: 12.2. distinfo
1.17      imil     3083: 
1.184     rillig   3084: The distinfo file contains the message digest, or checksum, of each distfile
                   3085: needed for the package. This ensures that the distfiles retrieved from the
                   3086: Internet have not been corrupted during transfer or altered by a malign force
                   3087: to introduce a security hole. To provide maximum security, all distfiles are
                   3088: protected using three different message digest algorithms (SHA1, RMD160,
                   3089: SHA512), as well as the file size.
1.17      imil     3090: 
1.184     rillig   3091: The distinfo file also contains the checksums for all the patches found in the
                   3092: patches directory (see Section 12.3, "patches/*"). These checksums ensure that
                   3093: patches are only applied intentionally and that they don't accidentally change,
                   3094: e.g. when merging different changes together. They also make sure that new
                   3095: patches are actually added to CVS and old ones are removed. Too see whether the
                   3096: patches and the distinfo file match, run pkglint after changing the patches.
1.17      imil     3097: 
1.184     rillig   3098: To regenerate the distinfo file, use the make distinfo command.
1.17      imil     3099: 
1.184     rillig   3100: Some packages have different sets of distfiles depending on the platform, for
                   3101: example lang/openjdk8. These are kept in the same distinfo file and care should
                   3102: be taken when upgrading such a package to ensure distfile information is not
                   3103: lost.
1.17      imil     3104: 
1.184     rillig   3105: 12.3. patches/*
1.63      wiz      3106: 
1.184     rillig   3107: Some packages don't work out-of-the box on the various platforms that are
                   3108: supported by pkgsrc. These packages need to be patched to make them work. The
                   3109: patch files can be found in the patches/ directory.
1.17      imil     3110: 
1.184     rillig   3111: In the patch phase, these patches are applied to the files in WRKSRC directory
                   3112: after extracting them, in alphabetic order.
1.160     brook    3113: 
1.184     rillig   3114: 12.3.1. Structure of a single patch file
1.160     brook    3115: 
1.184     rillig   3116: The patch-* files should be in diff -bu format, and apply without a fuzz to
                   3117: avoid problems. (To force patches to apply with fuzz you can set
                   3118: PATCH_FUZZ_FACTOR=-F2). Furthermore, each patch should contain only changes for
                   3119: a single file, and no file should be patched by more than one patch file. This
                   3120: helps to keep future modifications simple.
1.160     brook    3121: 
1.184     rillig   3122: Each patch file is structured as follows: In the first line, there is the RCS
                   3123: Id of the patch itself. The second line should be empty for aesthetic reasons.
                   3124: After that, there should be a comment for each change that the patch does.
                   3125: There are a number of standard cases:
1.160     brook    3126: 
1.184     rillig   3127:   * Patches for commonly known vulnerabilities should mention the vulnerability
                   3128:     ID (CAN, CVE).
1.160     brook    3129: 
1.184     rillig   3130:   * Patches that change source code should mention the platform and other
                   3131:     environment (for example, the compiler) that the patch is needed for.
1.160     brook    3132: 
1.184     rillig   3133: The patch should be commented so that any developer who knows the code of the
                   3134: application can make some use of the patch. Special care should be taken for
                   3135: the upstream developers, since we generally want that they accept our patches,
                   3136: so we have less work in the future.
1.160     brook    3137: 
1.184     rillig   3138: 12.3.2. Creating patch files
1.160     brook    3139: 
1.184     rillig   3140: One important thing to mention is to pay attention that no RCS IDs get stored
                   3141: in the patch files, as these will cause problems when later checked into the
                   3142: NetBSD CVS tree. Use the pkgdiff command from the pkgtools/pkgdiff package to
                   3143: avoid these problems.
1.160     brook    3144: 
1.184     rillig   3145: For even more automation, we recommend using mkpatches from the same package to
1.222     gutterid 3146: make a whole set of patches. You just have to back up files before you edit
                   3147: them to filename.orig, e.g., with cp -p filename filename.orig or, easier, by
                   3148: using pkgvi again from the same package. If you upgrade a package this way, you
                   3149: can easily compare the new set of patches with the previously existing one with
1.184     rillig   3150: patchdiff. The files in patches are replaced by new files, so carefully check
                   3151: if you want to take all the changes.
1.160     brook    3152: 
1.184     rillig   3153: When you have finished a package, remember to generate the checksums for the
                   3154: patch files by using the make makepatchsum command, see Section 12.2,
                   3155: "distinfo".
1.1       dsieger  3156: 
1.184     rillig   3157: When adding a patch that corrects a problem in the distfile (rather than e.g.
                   3158: enforcing pkgsrc's view of where man pages should go), send the patch as a bug
                   3159: report to the maintainer. This benefits non-pkgsrc users of the package, and
                   3160: usually makes it possible to remove the patch in future version.
1.1       dsieger  3161: 
1.184     rillig   3162: The file names of the patch files are usually of the form patch-
                   3163: path_to_file__with__underscores.c. Many packages still use the previous
                   3164: convention patch-[a-z][a-z], but new patches should be of the form containing
                   3165: the filename. mkpatches included in pkgtools/pkgdiff takes care of the name
                   3166: automatically.
1.1       dsieger  3167: 
1.222     gutterid 3168: When updating pre-existing patch files, if a file uses the old patch-[a-z][a-z]
                   3169: convention, it's best not to change it to the new form, as that will just cause
                   3170: churn that makes it harder to track changes to patching over time. Similarly,
                   3171: if a patch now applies at different line offsets, but still applies cleanly
                   3172: as-is, there's no need to update it, as that also unnecessarily complicates the
                   3173: patch history.
                   3174: 
1.184     rillig   3175: 12.3.3. Sources where the patch files come from
1.1       dsieger  3176: 
1.184     rillig   3177: If you want to share patches between multiple packages in pkgsrc, e.g. because
                   3178: they use the same distfiles, set PATCHDIR to the path where the patch files can
                   3179: be found, e.g.:
1.1       dsieger  3180: 
1.184     rillig   3181: PATCHDIR=       ../../editors/xemacs/patches
1.1       dsieger  3182: 
1.184     rillig   3183: Patch files that are distributed by the author or other maintainers can be
                   3184: listed in PATCHFILES.
1.1       dsieger  3185: 
1.184     rillig   3186: If it is desired to store any patches that should not be committed into pkgsrc,
                   3187: they can be kept outside the pkgsrc tree in the $LOCALPATCHES directory. The
                   3188: directory tree there is expected to have the same "category/package" structure
                   3189: as pkgsrc, and patches are expected to be stored inside these dirs (also known
                   3190: as $LOCALPATCHES/$PKGPATH). For example, if you want to keep a private patch
                   3191: for pkgsrc/graphics/png, keep it in $LOCALPATCHES/graphics/png/mypatch. All
                   3192: files in the named directory are expected to be patch files, and they are
                   3193: applied after pkgsrc patches are applied.
1.1       dsieger  3194: 
1.184     rillig   3195: 12.3.4. Patching guidelines
1.1       dsieger  3196: 
1.184     rillig   3197: When fixing a portability issue in the code do not use preprocessor magic to
                   3198: check for the current operating system nor platform. Doing so hurts portability
                   3199: to other platforms because the OS-specific details are not abstracted
                   3200: appropriately.
1.1       dsieger  3201: 
1.184     rillig   3202: The general rule to follow is: instead of checking for the operating system the
                   3203: application is being built on, check for the specific features you need. For
                   3204: example, instead of assuming that kqueue is available under NetBSD and using
                   3205: the __NetBSD__ macro to conditionalize kqueue support, add a check that detects
1.198     leot     3206: kqueue itself -- yes, this generally involves patching the configure script.
1.184     rillig   3207: There is absolutely nothing that prevents some OSes from adopting interfaces
                   3208: from other OSes (e.g. Linux implementing kqueue), something that the above
                   3209: checks cannot take into account.
1.1       dsieger  3210: 
1.184     rillig   3211: Of course, checking for features generally involves more work on the
                   3212: developer's side, but the resulting changes are cleaner and there are chances
                   3213: they will work on many other platforms. Not to mention that there are higher
                   3214: chances of being later integrated into the mainstream sources. Remember: It
                   3215: doesn't work unless it is right!
1.1       dsieger  3216: 
1.184     rillig   3217: Some typical examples:
1.121     sevan    3218: 
1.184     rillig   3219: Table 12.1. Patching examples
1.1       dsieger  3220: 
1.184     rillig   3221: +-------------------------------------------------------------------------------------------+
                   3222: |  Where  |        Incorrect         |                       Correct                        |
                   3223: |---------+--------------------------+------------------------------------------------------|
                   3224: |         |case ${target_os} in      |                                                      |
                   3225: |configure|netbsd*) have_kvm=yes ;;  |AC_CHECK_LIB(kvm, kvm_open, have_kvm=yes, have_kvm=no)|
                   3226: |script   |*)       have_kvm=no  ;;  |                                                      |
                   3227: |         |esac                      |                                                      |
                   3228: |---------+--------------------------+------------------------------------------------------|
                   3229: |C source |#if defined(__NetBSD__)   |#if defined(HAVE_SYS_EVENT_H)                         |
                   3230: |file     |#  include <sys/event.h>  |#  include <sys/event.h>                              |
                   3231: |         |#endif                    |#endif                                                |
                   3232: |---------+--------------------------+------------------------------------------------------|
                   3233: |         |int                       |int                                                   |
                   3234: |         |monitor_file(...)         |monitor_file(...)                                     |
                   3235: |         |{                         |{                                                     |
                   3236: |         |#if defined(__NetBSD__)   |#if defined(HAVE_KQUEUE)                              |
                   3237: |C source |        int fd = kqueue();|        int fd = kqueue();                            |
                   3238: |file     |        ...               |        ...                                           |
                   3239: |         |#else                     |#else                                                 |
                   3240: |         |        ...               |        ...                                           |
                   3241: |         |#endif                    |#endif                                                |
                   3242: |         |}                         |}                                                     |
                   3243: +-------------------------------------------------------------------------------------------+
1.1       dsieger  3244: 
                   3245: 
1.184     rillig   3246: 12.3.5. Feedback to the author
1.1       dsieger  3247: 
1.184     rillig   3248: Always, always, always feed back any portability fixes or improvements you do
                   3249: to a package to the mainstream developers. This is the only way to get their
                   3250: attention on portability issues and to ensure that future versions can be built
                   3251: out-of-the box on NetBSD. Furthermore, any user that gets newer distfiles will
                   3252: get the fixes straight from the packaged code.
1.1       dsieger  3253: 
1.184     rillig   3254: This generally involves cleaning up the patches (because sometimes the patches
                   3255: that are added to pkgsrc are quick hacks), filing bug reports in the
                   3256: appropriate trackers for the projects and working with the mainstream authors
                   3257: to accept your changes. It is extremely important that you do it so that the
                   3258: packages in pkgsrc are kept simple and thus further changes can be done without
                   3259: much hassle.
1.1       dsieger  3260: 
1.184     rillig   3261: When you have done this, please add a URL to the upstream bug report to the
                   3262: patch comment.
1.1       dsieger  3263: 
1.184     rillig   3264: Support the idea of free software!
1.1       dsieger  3265: 
1.184     rillig   3266: 12.4. Other mandatory files
1.1       dsieger  3267: 
1.184     rillig   3268: DESCR
1.1       dsieger  3269: 
1.184     rillig   3270:     A multi-line description of the piece of software. This should include any
                   3271:     credits where they are due. Please bear in mind that others do not share
                   3272:     your sense of humour (or spelling idiosyncrasies), and that others will
                   3273:     read everything that you write here.
1.1       dsieger  3274: 
1.184     rillig   3275: PLIST
1.1       dsieger  3276: 
1.184     rillig   3277:     This file governs the files that are installed on your system: all the
                   3278:     binaries, manual pages, etc. There are other directives which may be
                   3279:     entered in this file, to control the creation and deletion of directories,
                   3280:     and the location of inserted files. See Chapter 19, PLIST issues for more
                   3281:     information.
1.1       dsieger  3282: 
1.184     rillig   3283: 12.5. Optional files
1.1       dsieger  3284: 
1.184     rillig   3285: 12.5.1. Files affecting the binary package
1.1       dsieger  3286: 
1.184     rillig   3287: INSTALL
1.1       dsieger  3288: 
1.184     rillig   3289:     This shell script is invoked twice by pkg_add(1). First time after package
                   3290:     extraction and before files are moved in place, the second time after the
                   3291:     files to install are moved in place. This can be used to do any custom
                   3292:     procedures not possible with @exec commands in PLIST. See pkg_add(1) and
                   3293:     pkg_create(1) for more information. See also Section 20.1, "Files and
                   3294:     directories outside the installation prefix". Please note that you can
                   3295:     modify variables in it easily by using FILES_SUBST in the package's
                   3296:     Makefile:
1.1       dsieger  3297: 
1.184     rillig   3298:     FILES_SUBST+=  SOMEVAR="somevalue"
1.1       dsieger  3299: 
1.184     rillig   3300:     replaces "@SOMEVAR@" with "somevalue" in the INSTALL. By default,
                   3301:     substitution is performed for PREFIX, LOCALBASE, X11BASE, VARBASE, and a
                   3302:     few others, type make help topic=FILES_SUBST for a complete list.
1.1       dsieger  3303: 
1.184     rillig   3304: DEINSTALL
1.1       dsieger  3305: 
1.184     rillig   3306:     This script is executed before and after any files are removed. It is this
                   3307:     script's responsibility to clean up any additional messy details around the
                   3308:     package's installation, since all pkg_delete knows is how to delete the
                   3309:     files created in the original distribution. See pkg_delete(1) and
                   3310:     pkg_create(1) for more information. The same methods to replace variables
                   3311:     can be used as for the INSTALL file.
1.1       dsieger  3312: 
1.184     rillig   3313: MESSAGE
1.1       dsieger  3314: 
1.198     leot     3315:     This file is displayed after installation of the package. While this was
                   3316:     used often in the past, it has two problems: the display will be missed if
                   3317:     many packages are intalled at once, and the person installing the package
                   3318:     and the one using or configuring it may be different. It should therefore
                   3319:     be used only in exceptional circumstances where lasting negative
                   3320:     consequences would result from someone not reading it.
                   3321: 
                   3322:     MESSAGE should not be used for:
                   3323: 
                   3324:       + exhortations to read the documentation
                   3325: 
                   3326:       + reminders to install rc.d files and set variables
                   3327: 
                   3328:       + anything that should be explained in the installation/configuration
                   3329:         documentation that should come with the package
                   3330: 
                   3331:     If the documentation provided by upstream needs enhancing, create e.g.
                   3332:     files/README.pkgsrc and install it in the package's documentation
                   3333:     directory.
                   3334: 
                   3335:     Note that MESSAGE is shown for all operating systems and all init systems.
                   3336:     If a MESSAGE is necessary, it should be narrowed to only those operating
                   3337:     systems and init systems to which it applies.
                   3338: 
                   3339:     Note that you can modify variables in it easily by using MESSAGE_SUBST in
                   3340:     the package's Makefile:
1.1       dsieger  3341: 
1.184     rillig   3342:     MESSAGE_SUBST+=  SOMEVAR="somevalue"
1.1       dsieger  3343: 
1.184     rillig   3344:     replaces "${SOMEVAR}" with "somevalue" in MESSAGE. By default, substitution
                   3345:     is performed for PKGNAME, PKGBASE, PREFIX, LOCALBASE, X11BASE,
                   3346:     PKG_SYSCONFDIR, ROOT_GROUP, and ROOT_USER.
1.1       dsieger  3347: 
1.184     rillig   3348:     You can display a different or additional files by setting the MESSAGE_SRC
                   3349:     variable. Its default is MESSAGE, if the file exists.
1.1       dsieger  3350: 
1.184     rillig   3351: ALTERNATIVES
1.1       dsieger  3352: 
1.184     rillig   3353:     This file is used by the alternatives framework. It creates, configures,
                   3354:     and destroys generic wrappers used to run programs with similar interfaces.
                   3355:     See pkg_alternatives(8) from pkgtools/pkg_alternatives for more
                   3356:     information.
1.1       dsieger  3357: 
1.184     rillig   3358:     Each line of the file contains two filenames, first the wrapper and then
                   3359:     the alternative provided by the package. Both paths are relative to PREFIX.
1.1       dsieger  3360: 
1.184     rillig   3361: 12.5.2. Files affecting the build process
1.1       dsieger  3362: 
1.184     rillig   3363: Makefile.common
1.1       dsieger  3364: 
1.184     rillig   3365:     This file contains arbitrary things that could also go into a Makefile, but
                   3366:     its purpose is to be used by more than one package. This file should only
                   3367:     be used when the packages that will use the file are known in advance. For
                   3368:     other purposes it is often better to write a *.mk file and give it a good
                   3369:     name that describes what it does.
1.1       dsieger  3370: 
1.184     rillig   3371: buildlink3.mk
1.1       dsieger  3372: 
1.184     rillig   3373:     This file contains the dependency information for the buildlink3 framework
                   3374:     (see Chapter 18, Buildlink methodology).
1.1       dsieger  3375: 
1.184     rillig   3376: hacks.mk
1.1       dsieger  3377: 
1.184     rillig   3378:     This file contains workarounds for compiler bugs and similar things. It is
                   3379:     included automatically by the pkgsrc infrastructure, so you don't need an
                   3380:     extra .include line for it.
1.1       dsieger  3381: 
1.184     rillig   3382: options.mk
1.1       dsieger  3383: 
1.184     rillig   3384:     This file contains the code for the package-specific options (see
                   3385:     Chapter 16, Options handling) that can be selected by the user. If a
                   3386:     package has only one or two options, it is equally acceptable to put the
                   3387:     code directly into the Makefile.
1.1       dsieger  3388: 
1.184     rillig   3389: 12.5.3. Files affecting nothing at all
1.1       dsieger  3390: 
1.184     rillig   3391: README*
1.1       dsieger  3392: 
1.184     rillig   3393:     These files do not take place in the creation of a package and thus are
                   3394:     purely informative to the package developer.
1.1       dsieger  3395: 
1.184     rillig   3396: TODO
1.1       dsieger  3397: 
1.184     rillig   3398:     This file contains things that need to be done to make the package even
                   3399:     better.
1.1       dsieger  3400: 
1.184     rillig   3401: 12.6. work*
1.1       dsieger  3402: 
1.184     rillig   3403: When you type make, the distribution files are unpacked into the directory
                   3404: denoted by WRKDIR. It can be removed by running make clean. Besides the
                   3405: sources, this directory is also used to keep various timestamp files. The
                   3406: directory gets removed completely on clean. The default is ${.CURDIR}/work or $
                   3407: {.CURDIR}/work.${MACHINE_ARCH} if OBJMACHINE is set.
1.1       dsieger  3408: 
1.184     rillig   3409: 12.7. files/*
1.80      wiz      3410: 
1.184     rillig   3411: If you have any files that you wish to be placed in the package prior to
                   3412: configuration or building, you can place these files here and use a ${CP}
                   3413: command in the "post-extract" target to achieve this.
1.1       dsieger  3414: 
1.184     rillig   3415: If you want to share files in this way with other packages, set the FILESDIR
                   3416: variable to point to the other package's files directory, e.g.:
1.1       dsieger  3417: 
1.184     rillig   3418: FILESDIR=       ../../editors/xemacs/files
1.14      jmcneill 3419: 
1.184     rillig   3420: Chapter 13. The build process
1.1       dsieger  3421: 
1.184     rillig   3422: Table of Contents
1.1       dsieger  3423: 
1.184     rillig   3424: 13.1. Introduction
                   3425: 13.2. Program location
                   3426: 13.3. Directories used during the build process
                   3427: 13.4. Running a phase
                   3428: 13.5. The fetch phase
                   3429: 
                   3430:     13.5.1. What to fetch and where to get it from
                   3431:     13.5.2. How are the files fetched?
                   3432: 
                   3433: 13.6. The checksum phase
                   3434: 13.7. The extract phase
                   3435: 13.8. The patch phase
                   3436: 13.9. The tools phase
                   3437: 13.10. The wrapper phase
                   3438: 13.11. The configure phase
                   3439: 13.12. The build phase
                   3440: 13.13. The test phase
                   3441: 13.14. The install phase
                   3442: 13.15. The package phase
                   3443: 13.16. Cleaning up
                   3444: 13.17. Other helpful targets
1.1       dsieger  3445: 
1.184     rillig   3446: 13.1. Introduction
1.122     leot     3447: 
1.184     rillig   3448: This chapter gives a detailed description on how a package is built. Building a
                   3449: package is separated into different phases (for example fetch, build, install),
                   3450: all of which are described in the following sections. Each phase is split into
                   3451: so-called stages, which take the name of the containing phase, prefixed by one
                   3452: of pre-, do- or post-. (Examples are pre-configure, post-build.) Most of the
                   3453: actual work is done in the do-* stages.
1.1       dsieger  3454: 
1.184     rillig   3455: Never override the regular targets (like fetch), if you have to, override the
                   3456: do-* ones instead.
1.1       dsieger  3457: 
1.184     rillig   3458: The basic steps for building a program are always the same. First the program's
                   3459: source (distfile) must be brought to the local system and then extracted. After
                   3460: any pkgsrc-specific patches to compile properly are applied, the software can
                   3461: be configured, then built (usually by compiling), and finally the generated
                   3462: binaries, etc. can be put into place on the system.
1.1       dsieger  3463: 
1.184     rillig   3464: To get more details about what is happening at each step, you can set the
                   3465: PKG_VERBOSE variable, or the PATCH_DEBUG variable if you are just interested in
                   3466: more details about the patch step.
1.1       dsieger  3467: 
1.184     rillig   3468: 13.2. Program location
1.1       dsieger  3469: 
1.184     rillig   3470: Before outlining the process performed by the NetBSD package system in the next
                   3471: section, here's a brief discussion on where programs are installed, and which
                   3472: variables influence this.
1.1       dsieger  3473: 
1.184     rillig   3474: The automatic variable PREFIX indicates where all files of the final program
                   3475: shall be installed. It is usually set to LOCALBASE (/usr/pkg), or CROSSBASE for
                   3476: pkgs in the cross category. The value of PREFIX needs to be put into the
                   3477: various places in the program's source where paths to these files are encoded.
                   3478: See Section 12.3, "patches/*" and Section 21.3.1, "Shared libraries - libtool"
                   3479: for more details.
1.1       dsieger  3480: 
1.184     rillig   3481: When choosing which of these variables to use, follow the following rules:
1.1       dsieger  3482: 
1.184     rillig   3483:   * PREFIX always points to the location where the current pkg will be
                   3484:     installed. When referring to a pkg's own installation path, use "${PREFIX}"
                   3485:     .
1.1       dsieger  3486: 
1.223     nia      3487:   * LOCALBASE is where all pkgs are installed. If you need to construct a -I or
                   3488:     -L argument to the compiler to find includes and libraries installed by
                   3489:     another pkg, use "${LOCALBASE}". The name LOCALBASE stems from FreeBSD,
                   3490:     which installed all packages in /usr/local. As pkgsrc leaves /usr/local for
                   3491:     the system administrator, this variable is a misnomer.
1.1       dsieger  3492: 
1.184     rillig   3493:   * X11BASE is where the actual X11 distribution (from xsrc, etc.) is
                   3494:     installed. When looking for standard X11 includes (not those installed by a
                   3495:     package), use "${X11BASE}".
1.1       dsieger  3496: 
1.184     rillig   3497:   * X11-based packages using imake must set USE_IMAKE to be installed correctly
                   3498:     under LOCALBASE.
1.1       dsieger  3499: 
1.184     rillig   3500:   * Within ${PREFIX}, packages should install files according to hier(7), with
                   3501:     the exception that manual pages go into ${PREFIX}/man, not ${PREFIX}/share/
                   3502:     man.
1.1       dsieger  3503: 
1.184     rillig   3504: 13.3. Directories used during the build process
1.2       rillig   3505: 
1.184     rillig   3506: When building a package, various directories are used to store source files,
                   3507: temporary files, pkgsrc-internal files, and so on. These directories are
                   3508: explained here.
1.1       dsieger  3509: 
1.184     rillig   3510: Some of the directory variables contain relative pathnames. There are two
                   3511: common base directories for these relative directories: PKGSRCDIR/PKGPATH is
                   3512: used for directories that are pkgsrc-specific. WRKSRC is used for directories
                   3513: inside the package itself.
1.1       dsieger  3514: 
1.184     rillig   3515: PKGSRCDIR
1.1       dsieger  3516: 
1.184     rillig   3517:     This is an absolute pathname that points to the pkgsrc root directory.
                   3518:     Generally, you don't need it.
1.1       dsieger  3519: 
1.184     rillig   3520: PKGDIR
1.1       dsieger  3521: 
1.184     rillig   3522:     This is an absolute pathname that points to the current package.
1.1       dsieger  3523: 
1.184     rillig   3524: PKGPATH
1.1       dsieger  3525: 
1.184     rillig   3526:     This is a pathname relative to PKGSRCDIR that points to the current
1.228     gutterid 3527:     package. It is defined after including bsd.prefs.mk and can be used in
                   3528:     makefile fragments that are used by several packages to distinguish between
                   3529:     these packages. Other variables that would serve the same purpose are
                   3530:     PKGBASE and PKGNAME, but these are only defined after including bsd.pkg.mk,
                   3531:     which is too late.
                   3532: 
                   3533:     In mk.conf, the pkgsrc user can use PKGPATH to tweak variables like
                   3534:     MAKE_JOBS and CFLAGS.
1.1       dsieger  3535: 
1.184     rillig   3536: WRKDIR
1.1       dsieger  3537: 
1.184     rillig   3538:     This is an absolute pathname pointing to the directory where all work takes
                   3539:     place. The distfiles are extracted to this directory. It also contains
                   3540:     temporary directories and log files used by the various pkgsrc frameworks,
                   3541:     like buildlink or the wrappers.
1.1       dsieger  3542: 
1.184     rillig   3543: WRKSRC
1.1       dsieger  3544: 
1.184     rillig   3545:     This is an absolute pathname pointing to the directory where the distfiles
                   3546:     are extracted. It is usually a direct subdirectory of WRKDIR, and often
                   3547:     it's the only directory entry that isn't hidden. This variable may be
                   3548:     changed by a package Makefile.
1.1       dsieger  3549: 
1.184     rillig   3550: The CREATE_WRKDIR_SYMLINK definition takes either the value yes or no and
                   3551: defaults to no. It indicates whether a symbolic link to the WRKDIR is to be
                   3552: created in the pkgsrc entry's directory. If users would like to have their
                   3553: pkgsrc trees behave in a read-only manner, then the value of
                   3554: CREATE_WRKDIR_SYMLINK should be set to no.
1.1       dsieger  3555: 
1.184     rillig   3556: 13.4. Running a phase
1.1       dsieger  3557: 
1.184     rillig   3558: You can run a particular phase by typing make phase, where phase is the name of
                   3559: the phase. This will automatically run all phases that are required for this
                   3560: phase. The default phase is build, that is, when you run make without
                   3561: parameters in a package directory, the package will be built, but not
                   3562: installed.
1.1       dsieger  3563: 
1.184     rillig   3564: 13.5. The fetch phase
1.1       dsieger  3565: 
1.184     rillig   3566: The first step in building a package is to fetch the distribution files
                   3567: (distfiles) from the sites that are providing them. This is the task of the 
                   3568: fetch phase.
1.25      wiz      3569: 
1.184     rillig   3570: 13.5.1. What to fetch and where to get it from
1.1       dsieger  3571: 
1.184     rillig   3572: In simple cases, MASTER_SITES defines all URLs from where the distfile, whose
                   3573: name is derived from the DISTNAME variable, is fetched. The more complicated
                   3574: cases are described below.
1.1       dsieger  3575: 
1.184     rillig   3576: The variable DISTFILES specifies the list of distfiles that have to be fetched.
                   3577: Its value defaults to ${DEFAULT_DISTFILES} and its value is ${DISTNAME}$
                   3578: {EXTRACT_SUFX}, so that most packages don't need to define it at all.
                   3579: EXTRACT_SUFX is .tar.gz by default, but can be changed freely. Note that if
                   3580: your package requires additional distfiles to the default one, you cannot just
                   3581: append the additional filenames using the += operator, but you have write for
                   3582: example:
1.1       dsieger  3583: 
1.184     rillig   3584: DISTFILES=      ${DEFAULT_DISTFILES} additional-files.tar.gz
1.1       dsieger  3585: 
1.184     rillig   3586: Each distfile is fetched from a list of sites, usually MASTER_SITES. If the
                   3587: package has multiple DISTFILES or multiple PATCHFILES from different sites, you
                   3588: can set SITES.distfile to the list of URLs where the file distfile (including
                   3589: the suffix) can be found.
1.1       dsieger  3590: 
1.184     rillig   3591: DISTFILES=      ${DISTNAME}${EXTRACT_SUFX}
                   3592: DISTFILES+=     foo-file.tar.gz
                   3593: SITES.foo-file.tar.gz= \
                   3594: https://www.somewhere.com/somehow/ \
                   3595: https://www.somewhereelse.com/mirror/somehow/
1.1       dsieger  3596: 
1.184     rillig   3597: When actually fetching the distfiles, each item from MASTER_SITES or SITES.*
                   3598: gets the name of each distfile appended to it, without an intermediate slash.
                   3599: Therefore, all site values have to end with a slash or other separator
                   3600: character. This allows for example to set MASTER_SITES to a URL of a CGI script
                   3601: that gets the name of the distfile as a parameter. In this case, the definition
                   3602: would look like:
1.1       dsieger  3603: 
1.184     rillig   3604: MASTER_SITES=   https://www.example.com/download.cgi?file=
1.1       dsieger  3605: 
1.184     rillig   3606: The exception to this rule are URLs starting with a dash. In that case the URL
                   3607: is taken as is, fetched and the result stored under the name of the distfile.
                   3608: You can use this style for the case when the download URL style does not match
                   3609: the above common case. For example, if permanent download URL is a redirector
                   3610: to the real download URL, or the download file name is offered by an HTTP
                   3611: Content-Disposition header. In the following example, foo-1.0.0.tar.gz will be
                   3612: created instead of the default v1.0.0.tar.gz.
1.1       dsieger  3613: 
1.184     rillig   3614: DISTNAME=       foo-1.0.0
                   3615: MASTER_SITES=   -https://www.example.com/archive/v1.0.0.tar.gz
1.29      wiz      3616: 
1.184     rillig   3617: There are some predefined values for MASTER_SITES, which can be used in
                   3618: packages. The names of the variables should speak for themselves.
1.29      wiz      3619: 
1.225     gutterid 3620: MASTER_SITE_APACHE        MASTER_SITE_BACKUP
                   3621: MASTER_SITE_CRATESIO      MASTER_SITE_CYGWIN
                   3622: MASTER_SITE_DEBIAN        MASTER_SITE_FREEBSD
                   3623: MASTER_SITE_FREEBSD_LOCAL MASTER_SITE_GENTOO
                   3624: MASTER_SITE_GITHUB        MASTER_SITE_GITLAB
                   3625: MASTER_SITE_GNOME         MASTER_SITE_GNU
                   3626: MASTER_SITE_GNUSTEP       MASTER_SITE_HASKELL_HACKAGE
                   3627: MASTER_SITE_IFARCHIVE     MASTER_SITE_KDE
                   3628: MASTER_SITE_MOZILLA       MASTER_SITE_MOZILLA_ALL
                   3629: MASTER_SITE_MYSQL         MASTER_SITE_NETLIB
                   3630: MASTER_SITE_OPENBSD       MASTER_SITE_OPENOFFICE
                   3631: MASTER_SITE_OSDN          MASTER_SITE_PERL_CPAN
                   3632: MASTER_SITE_PGSQL         MASTER_SITE_PYPI
                   3633: MASTER_SITE_RUBYGEMS      MASTER_SITE_R_CRAN
                   3634: MASTER_SITE_SOURCEFORGE   MASTER_SITE_SUNSITE
                   3635: MASTER_SITE_SUSE          MASTER_SITE_TEX_CTAN
                   3636: MASTER_SITE_XCONTRIB      MASTER_SITE_XEMACS
                   3637: MASTER_SITE_XORG           
1.1       dsieger  3638: 
1.184     rillig   3639: Some explanations for the less self-explaining ones: MASTER_SITE_BACKUP
                   3640: contains backup sites for packages that are maintained in ftp://ftp.NetBSD.org/
                   3641: pub/pkgsrc/distfiles/${DIST_SUBDIR}. MASTER_SITE_LOCAL contains local package
                   3642: source distributions that are maintained in ftp://ftp.NetBSD.org/pub/pkgsrc/
                   3643: distfiles/LOCAL_PORTS/.
1.1       dsieger  3644: 
1.184     rillig   3645: If you choose one of these predefined sites, you may want to specify a
                   3646: subdirectory of that site. Since these macros may expand to more than one
                   3647: actual site, you must use the following construct to specify a subdirectory:
1.1       dsieger  3648: 
1.184     rillig   3649: MASTER_SITES=   ${MASTER_SITE_GNU:=subdirectory/name/}
                   3650: MASTER_SITES=   ${MASTER_SITE_SOURCEFORGE:=project_name/}
1.1       dsieger  3651: 
1.184     rillig   3652: Note the trailing slash after the subdirectory name.
1.1       dsieger  3653: 
1.184     rillig   3654: 13.5.2. How are the files fetched?
1.1       dsieger  3655: 
1.184     rillig   3656: The fetch phase makes sure that all the distfiles exist in a local directory
                   3657: (DISTDIR, which can be set by the pkgsrc user). If the files do not exist, they
                   3658: are fetched using commands of the form
1.1       dsieger  3659: 
1.184     rillig   3660: ${FETCH_CMD} ${FETCH_BEFORE_ARGS} ${site}${file} ${FETCH_AFTER_ARGS}
1.1       dsieger  3661: 
1.184     rillig   3662: where ${site} varies through several possibilities in turn: first,
                   3663: MASTER_SITE_OVERRIDE is tried, then the sites specified in either SITES.file if
                   3664: defined, else MASTER_SITES or PATCH_SITES, as applies, then finally the value
                   3665: of MASTER_SITE_BACKUP. The order of all except the first and the last can be
                   3666: optionally sorted by the user, via setting either MASTER_SORT_RANDOM, and
                   3667: MASTER_SORT_AWK or MASTER_SORT_REGEX.
1.1       dsieger  3668: 
1.184     rillig   3669: The specific command and arguments used depend on the FETCH_USING parameter.
                   3670: The example above is for FETCH_USING=custom.
1.66      asau     3671: 
1.184     rillig   3672: The distfiles mirror run by the NetBSD Foundation uses the mirror-distfiles
                   3673: target to mirror the distfiles, if they are freely distributable. Packages
                   3674: setting NO_SRC_ON_FTP (usually to "${RESTRICTED}") will not have their
                   3675: distfiles mirrored.
1.1       dsieger  3676: 
1.184     rillig   3677: 13.6. The checksum phase
1.1       dsieger  3678: 
1.184     rillig   3679: After the distfile(s) are fetched, their checksum is generated and compared
                   3680: with the checksums stored in the distinfo file. If the checksums don't match,
                   3681: the build is aborted. This is to ensure the same distfile is used for building,
                   3682: and that the distfile wasn't changed, e.g. by some malign force, deliberately
                   3683: changed distfiles on the master distribution site or network lossage.
1.1       dsieger  3684: 
1.184     rillig   3685: 13.7. The extract phase
1.1       dsieger  3686: 
1.184     rillig   3687: When the distfiles are present on the local system, they need to be extracted,
                   3688: as they usually come in the form of some compressed archive format.
1.1       dsieger  3689: 
1.184     rillig   3690: By default, all DISTFILES are extracted. If you only need some of them, you can
                   3691: set the EXTRACT_ONLY variable to the list of those files.
1.1       dsieger  3692: 
1.184     rillig   3693: Extracting the files is usually done by a little program, mk/extract/extract,
                   3694: which already knows how to extract various archive formats, so most likely you
                   3695: will not need to change anything here. But if you need, the following variables
                   3696: may help you:
1.1       dsieger  3697: 
1.184     rillig   3698: EXTRACT_OPTS_{BIN,LHA,PAX,RAR,TAR,ZIP,ZOO}
1.1       dsieger  3699: 
1.184     rillig   3700:     Use these variables to override the default options for an extract command,
                   3701:     which are defined in mk/extract/extract.
1.1       dsieger  3702: 
1.184     rillig   3703: EXTRACT_USING
1.1       dsieger  3704: 
1.184     rillig   3705:     This variable can be set to bsdtar, gtar, nbtar (which is the default
                   3706:     value), pax, or an absolute pathname pointing to the command with which tar
                   3707:     archives should be extracted. It is preferred to choose bsdtar over gtar if
                   3708:     NetBSD's pax-as-tar is not good enough.
1.1       dsieger  3709: 
1.184     rillig   3710: If the extract program doesn't serve your needs, you can also override the
                   3711: EXTRACT_CMD variable, which holds the command used for extracting the files.
                   3712: This command is executed in the ${WRKSRC} directory. During execution of this
                   3713: command, the shell variable extract_file holds the absolute pathname of the
                   3714: file that is going to be extracted.
1.1       dsieger  3715: 
1.184     rillig   3716: And if that still does not suffice, you can override the do-extract target in
                   3717: the package Makefile.
1.1       dsieger  3718: 
1.184     rillig   3719: 13.8. The patch phase
1.1       dsieger  3720: 
1.184     rillig   3721: After extraction, all the patches named by the PATCHFILES, those present in the
                   3722: patches subdirectory of the package as well as in $LOCALPATCHES/$PKGPATH (e.g.
                   3723: /usr/local/patches/graphics/png) are applied. Patchfiles ending in .Z or .gz
                   3724: are uncompressed before they are applied, files ending in .orig or .rej are
                   3725: ignored. Any special options to patch(1) can be handed in PATCH_DIST_ARGS. See
                   3726: Section 12.3, "patches/*" for more details.
1.1       dsieger  3727: 
1.184     rillig   3728: By default patch(1) is given special arguments to make it fail if the expected
                   3729: text from the patch context is not found in the patched file. If that happens,
                   3730: fix the patch file by comparing it with the actual text in the file to be
                   3731: patched.
1.1       dsieger  3732: 
1.184     rillig   3733: 13.9. The tools phase
1.1       dsieger  3734: 
1.184     rillig   3735: This is covered in Chapter 17, Tools needed for building or running.
1.1       dsieger  3736: 
1.184     rillig   3737: 13.10. The wrapper phase
1.1       dsieger  3738: 
1.184     rillig   3739: This phase creates wrapper programs for the compilers and linkers. The
                   3740: following variables can be used to tweak the wrappers.
1.1       dsieger  3741: 
1.184     rillig   3742: ECHO_WRAPPER_MSG
1.1       dsieger  3743: 
1.184     rillig   3744:     The command used to print progress messages. Does nothing by default. Set
                   3745:     to ${ECHO} to see the progress messages.
1.1       dsieger  3746: 
1.184     rillig   3747: WRAPPER_DEBUG
1.1       dsieger  3748: 
1.184     rillig   3749:     This variable can be set to yes (default) or no, depending on whether you
                   3750:     want additional information in the wrapper log file.
1.1       dsieger  3751: 
1.184     rillig   3752: WRAPPER_UPDATE_CACHE
1.1       dsieger  3753: 
1.184     rillig   3754:     This variable can be set to yes or no, depending on whether the wrapper
                   3755:     should use its cache, which will improve the speed. The default value is
                   3756:     yes, but is forced to no if the platform does not support it.
1.1       dsieger  3757: 
1.184     rillig   3758: WRAPPER_REORDER_CMDS
1.1       dsieger  3759: 
1.184     rillig   3760:     A list of reordering commands. A reordering command has the form reorder:l:
                   3761:     lib1:lib2. It ensures that that -llib1 occurs before -llib2.
1.1       dsieger  3762: 
1.184     rillig   3763: 13.11. The configure phase
1.1       dsieger  3764: 
1.184     rillig   3765: Most pieces of software need information on the header files, system calls, and
                   3766: library routines which are available on the platform they run on. The process
                   3767: of determining this information is known as configuration, and is usually
                   3768: automated. In most cases, a script is supplied with the distfiles, and its
                   3769: invocation results in generation of header files, Makefiles, etc.
1.1       dsieger  3770: 
1.184     rillig   3771: If the package contains a configure script, this can be invoked by setting
                   3772: HAS_CONFIGURE to "yes". If the configure script is a GNU autoconf script, you
1.187     rillig   3773: should set GNU_CONFIGURE to "yes" instead.
1.1       dsieger  3774: 
1.187     rillig   3775: In the do-configure stage, a rough equivalent of the following command is run.
                   3776: See mk/configure/configure.mk, target do-configure-script for the exact
                   3777: definition.
                   3778: 
                   3779: .for dir in ${CONFIGURE_DIRS}
                   3780:         cd ${WRKSRC} && cd ${dir} \
                   3781:         && env ${CONFIGURE_ENV} \
                   3782:             ${CONFIG_SHELL} ${CONFIGURE_SCRIPT} ${CONFIGURE_ARGS}
1.184     rillig   3783: .endfor
1.1       dsieger  3784: 
1.184     rillig   3785: CONFIGURE_DIRS (default: ".") is a list of pathnames relative to WRKSRC. In
                   3786: each of these directories, the configure script is run with the environment
                   3787: CONFIGURE_ENV and arguments CONFIGURE_ARGS. The variables CONFIGURE_ENV,
                   3788: CONFIGURE_SCRIPT (default: "./configure") and CONFIGURE_ARGS may all be changed
                   3789: by the package.
1.1       dsieger  3790: 
1.184     rillig   3791: If the program uses the Perl way of configuration (mainly Perl modules, but not
                   3792: only), i.e. a file called Makefile.PL, it should include ../../lang/perl5/
                   3793: module.mk. To set any parameter for Makefile.PL use the MAKE_PARAMS variable
                   3794: (e.g., MAKE_PARAMS+=foo=bar
1.1       dsieger  3795: 
1.184     rillig   3796: If the program uses an Imakefile for configuration, the appropriate steps can
                   3797: be invoked by setting USE_IMAKE to "yes". If you only need xmkmf, add it to
                   3798: USE_TOOLS. You can add variables to xmkmf's environment by adding them to the
                   3799: SCRIPTS_ENV variable.
1.1       dsieger  3800: 
1.184     rillig   3801: If the program uses cmake for configuration, the appropriate steps can be
                   3802: invoked by setting USE_CMAKE to "yes". You can add variables to cmake's
                   3803: environment by adding them to the CONFIGURE_ENV variable and arguments to cmake
                   3804: by adding them to the CMAKE_ARGS variable. The top directory argument is given
                   3805: by the CMAKE_ARG_PATH variable, that defaults to "." (relative to
                   3806: CONFIGURE_DIRS)
1.1       dsieger  3807: 
1.184     rillig   3808: If there is no configure step at all, set NO_CONFIGURE to "yes".
1.1       dsieger  3809: 
1.184     rillig   3810: 13.12. The build phase
1.1       dsieger  3811: 
1.187     rillig   3812: For building a package, a rough equivalent of the following code is executed;
                   3813: see mk/build/build.mk, target do-build for the exact definition.
1.154     rillig   3814: 
1.187     rillig   3815: .for dir in ${BUILD_DIRS}
                   3816:         cd ${WRKSRC} && cd ${dir} \
1.184     rillig   3817:         && env ${MAKE_ENV} \
1.187     rillig   3818:             ${MAKE_PROGRAM} ${MAKE_FLAGS} ${BUILD_MAKE_FLAGS} \
1.184     rillig   3819:                 -f ${MAKE_FILE} \
                   3820:                 ${BUILD_TARGET}
                   3821: .endfor
1.1       dsieger  3822: 
1.184     rillig   3823: BUILD_DIRS (default: ".") is a list of pathnames relative to WRKSRC. In each of
                   3824: these directories, MAKE_PROGRAM is run with the environment MAKE_ENV and
                   3825: arguments BUILD_MAKE_FLAGS. The variables MAKE_ENV, BUILD_MAKE_FLAGS, MAKE_FILE
                   3826: and BUILD_TARGET may all be changed by the package.
1.1       dsieger  3827: 
1.184     rillig   3828: The default value of MAKE_PROGRAM is "gmake" if USE_TOOLS contains "gmake", "
                   3829: make" otherwise. The default value of MAKE_FILE is "Makefile", and BUILD_TARGET
                   3830: defaults to "all".
1.1       dsieger  3831: 
1.184     rillig   3832: If there is no build step at all, set NO_BUILD to "yes".
1.1       dsieger  3833: 
1.184     rillig   3834: 13.13. The test phase
1.1       dsieger  3835: 
1.184     rillig   3836: [TODO]
1.1       dsieger  3837: 
1.184     rillig   3838: 13.14. The install phase
1.1       dsieger  3839: 
1.184     rillig   3840: Once the build stage has completed, the final step is to install the software
                   3841: in public directories, so users can access the programs and files.
1.1       dsieger  3842: 
1.187     rillig   3843: In the install phase, a rough equivalent of the following code is executed; see
                   3844: mk/install/install.mk, target do-install for the exact definition.
                   3845: Additionally, before and after this code, several consistency checks are run
                   3846: against the files-to-be-installed, see mk/check/*.mk for details.
                   3847: 
                   3848: .for dir in ${INSTALL_DIRS}
                   3849:         cd ${WRKSRC} && cd ${dir} \
                   3850:         && env ${INSTALL_ENV} ${MAKE_ENV} \
                   3851:             ${MAKE_PROGRAM} ${MAKE_FLAGS} ${INSTALL_MAKE_FLAGS} \
                   3852:                 -f ${MAKE_FILE} ${INSTALL_TARGET}
1.184     rillig   3853: .endfor
1.1       dsieger  3854: 
1.184     rillig   3855: The variable's meanings are analogous to the ones in the build phase.
                   3856: INSTALL_DIRS defaults to BUILD_DIRS. INSTALL_TARGET is "install" by default,
                   3857: plus "install.man" if USE_IMAKE is defined and NO_INSTALL_MANPAGES is not
                   3858: defined.
1.1       dsieger  3859: 
1.184     rillig   3860: In the install phase, the following variables are useful. They are all
                   3861: variations of the install(1) command that have the owner, group and permissions
                   3862: preset. INSTALL is the plain install command. The specialized variants,
                   3863: together with their intended use, are:
1.1       dsieger  3864: 
1.184     rillig   3865: INSTALL_PROGRAM_DIR
1.1       dsieger  3866: 
1.184     rillig   3867:     directories that contain binaries
1.1       dsieger  3868: 
1.184     rillig   3869: INSTALL_SCRIPT_DIR
1.1       dsieger  3870: 
1.184     rillig   3871:     directories that contain scripts
1.1       dsieger  3872: 
1.184     rillig   3873: INSTALL_LIB_DIR
1.1       dsieger  3874: 
1.184     rillig   3875:     directories that contain shared and static libraries
1.1       dsieger  3876: 
1.184     rillig   3877: INSTALL_DATA_DIR
1.108     rillig   3878: 
1.184     rillig   3879:     directories that contain data files
1.108     rillig   3880: 
1.184     rillig   3881: INSTALL_MAN_DIR
1.108     rillig   3882: 
1.184     rillig   3883:     directories that contain man pages
1.108     rillig   3884: 
1.184     rillig   3885: INSTALL_GAME_DIR
1.108     rillig   3886: 
1.184     rillig   3887:     directories that contain data files for games
1.108     rillig   3888: 
1.184     rillig   3889: INSTALL_PROGRAM
1.108     rillig   3890: 
1.184     rillig   3891:     binaries that can be stripped from debugging symbols
1.108     rillig   3892: 
1.184     rillig   3893: INSTALL_SCRIPT
1.108     rillig   3894: 
1.184     rillig   3895:     binaries that cannot be stripped
1.108     rillig   3896: 
1.184     rillig   3897: INSTALL_GAME
1.108     rillig   3898: 
1.184     rillig   3899:     game binaries
1.108     rillig   3900: 
1.184     rillig   3901: INSTALL_LIB
1.108     rillig   3902: 
1.184     rillig   3903:     shared and static libraries
1.108     rillig   3904: 
1.184     rillig   3905: INSTALL_DATA
1.108     rillig   3906: 
1.184     rillig   3907:     data files
1.1       dsieger  3908: 
1.184     rillig   3909: INSTALL_GAME_DATA
1.1       dsieger  3910: 
1.184     rillig   3911:     data files for games
1.108     rillig   3912: 
1.184     rillig   3913: INSTALL_MAN
1.108     rillig   3914: 
1.184     rillig   3915:     man pages
1.1       dsieger  3916: 
1.184     rillig   3917: Some other variables are:
1.1       dsieger  3918: 
1.184     rillig   3919: INSTALL_UNSTRIPPED
1.1       dsieger  3920: 
1.184     rillig   3921:     If set to yes, do not run strip(1) when installing binaries. Any debugging
                   3922:     sections and symbols present in binaries will be preserved.
1.1       dsieger  3923: 
1.184     rillig   3924: INSTALLATION_DIRS
1.1       dsieger  3925: 
1.184     rillig   3926:     A list of directories relative to PREFIX that are created by pkgsrc at the
                   3927:     beginning of the install phase. The package is supposed to create all
                   3928:     needed directories itself before installing files to it and list all other
                   3929:     directories here.
1.1       dsieger  3930: 
1.184     rillig   3931: In the rare cases that a package shouldn't install anything, set NO_INSTALL to 
                   3932: "yes". This is mostly relevant for packages in the regress category.
1.1       dsieger  3933: 
1.184     rillig   3934: 13.15. The package phase
1.121     sevan    3935: 
1.184     rillig   3936: Once the install stage has completed, a binary package of the installed files
                   3937: can be built. These binary packages can be used for quick installation without
                   3938: previous compilation, e.g. by the make bin-install or by using pkg_add.
1.1       dsieger  3939: 
1.184     rillig   3940: By default, the binary packages are created in ${PACKAGES}/All and symlinks are
                   3941: created in ${PACKAGES}/category, one for each category in the CATEGORIES
                   3942: variable. PACKAGES defaults to pkgsrc/packages.
1.1       dsieger  3943: 
1.184     rillig   3944: 13.16. Cleaning up
1.1       dsieger  3945: 
1.184     rillig   3946: Once you're finished with a package, you can clean the work directory by
                   3947: running make clean. If you want to clean the work directories of all
                   3948: dependencies too, use make clean-depends.
1.1       dsieger  3949: 
1.184     rillig   3950: 13.17. Other helpful targets
1.1       dsieger  3951: 
1.184     rillig   3952: pre/post-*
1.1       dsieger  3953: 
1.184     rillig   3954:     For any of the main targets described in the previous section (configure,
                   3955:     build, install, etc.), two auxiliary targets exist with "pre-" and "post-"
                   3956:     used as a prefix for the main target's name. These targets are invoked
                   3957:     before and after the main target is called, allowing extra configuration or
                   3958:     installation steps be performed from a package's Makefile, for example,
                   3959:     which a program's configure script or install target omitted.
                   3960: 
                   3961:     About 5% of the pkgsrc packages define their custom post-extract target,
                   3962:     another 5% define pre-configure, and 10% define post-install. The other pre
                   3963:     /post-* targets are defined even less often.
1.1       dsieger  3964: 
1.184     rillig   3965: do-*
1.182     leot     3966: 
1.184     rillig   3967:     Should one of the main targets do the wrong thing, and should there be no
                   3968:     variable to fix this, you can redefine it with the do-* target. (Note that
                   3969:     redefining the target itself instead of the do-* target is a bad idea, as
                   3970:     the pre-* and post-* targets won't be called anymore, etc.)
1.1       dsieger  3971: 
1.184     rillig   3972:     About 15% of the pkgsrc packages override the default do-install, the other
                   3973:     do-* targets are overridden even less often.
1.1       dsieger  3974: 
1.184     rillig   3975: reinstall
1.1       dsieger  3976: 
1.184     rillig   3977:     If you did a make install and you noticed some file was not installed
                   3978:     properly, you can repeat the installation with this target, which will
                   3979:     ignore the "already installed" flag.
1.1       dsieger  3980: 
1.184     rillig   3981:     This is the default value of DEPENDS_TARGET except in the case of make
                   3982:     update and make package, where the defaults are "package" and "update",
                   3983:     respectively.
1.1       dsieger  3984: 
1.184     rillig   3985: deinstall
1.1       dsieger  3986: 
1.184     rillig   3987:     This target does a pkg_delete(1) in the current directory, effectively
                   3988:     de-installing the package. The following variables can be used to tune the
                   3989:     behaviour:
1.1       dsieger  3990: 
1.184     rillig   3991:     PKG_VERBOSE
1.1       dsieger  3992: 
1.184     rillig   3993:         Add a "-v" to the pkg_delete(1) command.
1.1       dsieger  3994: 
1.184     rillig   3995:     DEINSTALLDEPENDS
1.1       dsieger  3996: 
1.184     rillig   3997:         Remove all packages that require (depend on) the given package. This
                   3998:         can be used to remove any packages that may have been pulled in by a
                   3999:         given package, e.g. if make deinstall DEINSTALLDEPENDS=1 is done in
                   4000:         pkgsrc/x11/kde, this is likely to remove whole KDE. Works by adding "-R
                   4001:         " to the pkg_delete(1) command line.
1.1       dsieger  4002: 
1.184     rillig   4003: bin-install
1.1       dsieger  4004: 
1.184     rillig   4005:     Install a binary package from local disk and via FTP from a list of sites
                   4006:     (see the BINPKG_SITES variable), and do a make package if no binary package
                   4007:     is available anywhere. The arguments given to pkg_add can be set via
                   4008:     BIN_INSTALL_FLAGS e.g., to do verbose operation, etc.
1.1       dsieger  4009: 
1.184     rillig   4010: install-clean
1.1       dsieger  4011: 
1.184     rillig   4012:     This target removes the state files for the "install" and later phases so
                   4013:     that the "install" target may be re-invoked. This can be used after editing
                   4014:     the PLIST to install the package without rebuilding it.
1.1       dsieger  4015: 
1.184     rillig   4016: build-clean
1.18      mishka   4017: 
1.184     rillig   4018:     This target removes the state files for the "build" and later phases so
                   4019:     that the "build" target may be re-invoked.
1.18      mishka   4020: 
1.184     rillig   4021: update
1.18      mishka   4022: 
1.184     rillig   4023:     This target causes the current package to be updated to the latest version.
                   4024:     The package and all depending packages first get de-installed, then current
                   4025:     versions of the corresponding packages get compiled and installed. This is
                   4026:     similar to manually noting which packages are currently installed, then
                   4027:     performing a series of make deinstall and make install (or whatever
                   4028:     UPDATE_TARGET is set to) for these packages.
1.18      mishka   4029: 
1.184     rillig   4030:     You can use the "update" target to resume package updating in case a
                   4031:     previous make update was interrupted for some reason. However, in this
                   4032:     case, make sure you don't call make clean or otherwise remove the list of
                   4033:     dependent packages in WRKDIR. Otherwise, you lose the ability to
                   4034:     automatically update the current package along with the dependent packages
                   4035:     you have installed.
1.121     sevan    4036: 
1.184     rillig   4037:     Resuming an interrupted make update will only work as long as the package
                   4038:     tree remains unchanged. If the source code for one of the packages to be
                   4039:     updated has been changed, resuming make update will most certainly fail!
1.1       dsieger  4040: 
1.184     rillig   4041:     The following variables can be used either on the command line or in
                   4042:     mk.conf to alter the behaviour of make update:
1.1       dsieger  4043: 
1.184     rillig   4044:     UPDATE_TARGET
1.1       dsieger  4045: 
1.184     rillig   4046:         Install target to recursively use for the updated package and the
                   4047:         dependent packages. Defaults to DEPENDS_TARGET if set, "install"
                   4048:         otherwise for make update. Other good targets are "package" or "
                   4049:         bin-install". Do not set this to "update" or you will get stuck in an
                   4050:         endless loop!
1.1       dsieger  4051: 
1.184     rillig   4052:     NOCLEAN
1.1       dsieger  4053: 
1.184     rillig   4054:         Don't clean up after updating. Useful if you want to leave the work
                   4055:         sources of the updated packages around for inspection or other
                   4056:         purposes. Be sure you eventually clean up the source tree (see the "
                   4057:         clean-update" target below) or you may run into troubles with old
                   4058:         source code still lying around on your next make or make update.
1.1       dsieger  4059: 
1.184     rillig   4060:     REINSTALL
1.1       dsieger  4061: 
1.184     rillig   4062:         Deinstall each package before installing (making DEPENDS_TARGET). This
                   4063:         may be necessary if the "clean-update" target (see below) was called
                   4064:         after interrupting a running make update.
1.1       dsieger  4065: 
1.184     rillig   4066:     DEPENDS_TARGET
1.1       dsieger  4067: 
1.184     rillig   4068:         Allows you to disable recursion and hardcode the target for packages.
                   4069:         The default is "update" for the update target, facilitating a recursive
                   4070:         update of prerequisite packages. Only set DEPENDS_TARGET if you want to
                   4071:         disable recursive updates. Use UPDATE_TARGET instead to just set a
                   4072:         specific target for each package to be installed during make update
                   4073:         (see above).
1.1       dsieger  4074: 
1.184     rillig   4075: clean-update
1.1       dsieger  4076: 
1.184     rillig   4077:     Clean the source tree for all packages that would get updated if make
                   4078:     update was called from the current directory. This target should not be
                   4079:     used if the current package (or any of its depending packages) have already
                   4080:     been de-installed (e.g., after calling make update) or you may lose some
                   4081:     packages you intended to update. As a rule of thumb: only use this target 
                   4082:     before the first time you run make update and only if you have a dirty
                   4083:     package tree (e.g., if you used NOCLEAN).
1.86      wiz      4084: 
1.184     rillig   4085:     If you are unsure about whether your tree is clean, you can either perform
                   4086:     a make clean at the top of the tree, or use the following sequence of
                   4087:     commands from the directory of the package you want to update (before
                   4088:     running make update for the first time, otherwise you lose all the packages
                   4089:     you wanted to update!):
1.86      wiz      4090: 
1.184     rillig   4091:     # make clean-update
                   4092:     # make clean CLEANDEPENDS=YES
                   4093:     # make update
1.86      wiz      4094: 
                   4095: 
1.184     rillig   4096:     The following variables can be used either on the command line or in
                   4097:     mk.conf to alter the behaviour of make clean-update:
1.86      wiz      4098: 
1.184     rillig   4099:     CLEAR_DIRLIST
1.86      wiz      4100: 
1.184     rillig   4101:         After make clean, do not reconstruct the list of directories to update
                   4102:         for this package. Only use this if make update successfully installed
                   4103:         all packages you wanted to update. Normally, this is done automatically
                   4104:         on make update, but may have been suppressed by the NOCLEAN variable
                   4105:         (see above).
1.1       dsieger  4106: 
1.184     rillig   4107: replace
1.1       dsieger  4108: 
1.184     rillig   4109:     Update the installation of the current package. This differs from update in
                   4110:     that it does not replace dependent packages. You will need to install
                   4111:     pkgtools/pkg_tarup for this target to work.
1.1       dsieger  4112: 
1.184     rillig   4113:     Be careful when using this target! There are no guarantees that dependent
                   4114:     packages will still work, in particular they will most certainly break if
                   4115:     you make replace a library package whose shared library major version
                   4116:     changed between your installed version and the new one. For this reason,
                   4117:     this target is not officially supported and only recommended for advanced
                   4118:     users.
1.1       dsieger  4119: 
1.184     rillig   4120: info
1.1       dsieger  4121: 
1.184     rillig   4122:     This target invokes pkg_info(1) for the current package. You can use this
                   4123:     to check which version of a package is installed.
1.86      wiz      4124: 
1.184     rillig   4125: index
1.1       dsieger  4126: 
1.184     rillig   4127:     This is a top-level command, i.e. it should be used in the pkgsrc
                   4128:     directory. It creates a database of all packages in the local pkgsrc tree,
                   4129:     including dependencies, comment, maintainer, and some other useful
                   4130:     information. Individual entries are created by running make describe in the
                   4131:     packages' directories. This index file is saved as pkgsrc/INDEX. It can be
                   4132:     displayed in verbose format by running make print-index. You can search in
                   4133:     it with make search key=something. You can extract a list of all packages
                   4134:     that depend on a particular one by running make show-deps PKG=somepackage.
1.1       dsieger  4135: 
1.184     rillig   4136:     Running this command takes a very long time, some hours even on fast
                   4137:     machines!
1.1       dsieger  4138: 
1.184     rillig   4139: readme
1.1       dsieger  4140: 
1.199     nia      4141:     This target generates a index.html file, which can be viewed using a
1.184     rillig   4142:     browser such as www/firefox or www/links. The generated files contain
                   4143:     references to any packages which are in the PACKAGES directory on the local
                   4144:     host. The generated files can be made to refer to URLs based on
                   4145:     FTP_PKG_URL_HOST and FTP_PKG_URL_DIR. For example, if I wanted to generate
1.199     nia      4146:     index.html files which pointed to binary packages on the local machine, in
1.184     rillig   4147:     the directory /usr/packages, set FTP_PKG_URL_HOST=file://localhost and
                   4148:     FTP_PKG_URL_DIR=/usr/packages. The ${PACKAGES} directory and its
                   4149:     subdirectories will be searched for all the binary packages.
1.1       dsieger  4150: 
1.184     rillig   4151:     The target can be run at the toplevel or in category directories, in which
                   4152:     case it descends recursively.
1.1       dsieger  4153: 
1.184     rillig   4154: readme-all
1.1       dsieger  4155: 
1.184     rillig   4156:     This is a top-level command, run it in pkgsrc. Use this target to create a
                   4157:     file README-all.html which contains a list of all packages currently
                   4158:     available in the NetBSD Packages Collection, together with the category
                   4159:     they belong to and a short description. This file is compiled from the
1.199     nia      4160:     pkgsrc/*/index.html files, so be sure to run this after a make readme.
1.1       dsieger  4161: 
1.184     rillig   4162: cdrom-readme
1.1       dsieger  4163: 
1.184     rillig   4164:     This is very much the same as the "readme" target (see above), but is to be
                   4165:     used when generating a pkgsrc tree to be written to a CD-ROM. This target
1.199     nia      4166:     also produces index.html files, and can be made to refer to URLs based on
1.184     rillig   4167:     CDROM_PKG_URL_HOST and CDROM_PKG_URL_DIR.
1.1       dsieger  4168: 
1.184     rillig   4169: show-distfiles
1.1       dsieger  4170: 
1.184     rillig   4171:     This target shows which distfiles and patchfiles are needed to build the
                   4172:     package (ALLFILES, which contains all DISTFILES and PATCHFILES, but not
                   4173:     patches/*).
1.1       dsieger  4174: 
1.184     rillig   4175: show-downlevel
1.1       dsieger  4176: 
1.184     rillig   4177:     This target shows nothing if the package is not installed. If a version of
                   4178:     this package is installed, but is not the version provided in this version
                   4179:     of pkgsrc, then a warning message is displayed. This target can be used to
                   4180:     show which of your installed packages are downlevel, and so the old
                   4181:     versions can be deleted, and the current ones added.
1.1       dsieger  4182: 
1.184     rillig   4183: show-pkgsrc-dir
1.1       dsieger  4184: 
1.184     rillig   4185:     This target shows the directory in the pkgsrc hierarchy from which the
                   4186:     package can be built and installed. This may not be the same directory as
                   4187:     the one from which the package was installed. This target is intended to be
                   4188:     used by people who may wish to upgrade many packages on a single host, and
                   4189:     can be invoked from the top-level pkgsrc Makefile by using the "
                   4190:     show-host-specific-pkgs" target.
1.1       dsieger  4191: 
1.184     rillig   4192: show-installed-depends
1.1       dsieger  4193: 
1.184     rillig   4194:     This target shows which installed packages match the current package's
                   4195:     DEPENDS. Useful if out of date dependencies are causing build problems.
1.1       dsieger  4196: 
1.184     rillig   4197: print-build-depends-list
1.1       dsieger  4198: 
1.184     rillig   4199:     This target shows the list of packages that the current package depends on
                   4200:     for building.
1.1       dsieger  4201: 
1.184     rillig   4202: print-run-depends-list
1.1       dsieger  4203: 
1.184     rillig   4204:     This target shows the list of packages that the current package depends on
                   4205:     for running.
1.1       dsieger  4206: 
1.184     rillig   4207: check-shlibs
1.1       dsieger  4208: 
1.184     rillig   4209:     After a package is installed, check all its binaries and (on ELF platforms)
                   4210:     shared libraries to see if they find the shared libs they need. Run by
                   4211:     default if PKG_DEVELOPER is set in mk.conf.
1.1       dsieger  4212: 
1.184     rillig   4213: print-PLIST
1.1       dsieger  4214: 
1.184     rillig   4215:     After a "make install" from a new or upgraded pkg, this prints out an
                   4216:     attempt to generate a new PLIST from a find -newer work/.extract_done. An
                   4217:     attempt is made to care for shared libs etc., but it is strongly
                   4218:     recommended to review the result before putting it into PLIST. On upgrades,
                   4219:     it's useful to diff the output of this command against an already existing
                   4220:     PLIST file.
1.1       dsieger  4221: 
1.184     rillig   4222:     If the package installs files via tar(1) or other methods that don't update
                   4223:     file access times, be sure to add these files manually to your PLIST, as
                   4224:     the "find -newer" command used by this target won't catch them!
1.56      ryoon    4225: 
1.184     rillig   4226:     See Section 19.3, "Tweaking output of make print-PLIST" for more
                   4227:     information on this target.
1.1       dsieger  4228: 
1.184     rillig   4229: Chapter 14. Creating a new pkgsrc package from scratch
1.1       dsieger  4230: 
1.184     rillig   4231: Table of Contents
1.1       dsieger  4232: 
1.184     rillig   4233: 14.1. Common types of packages
1.1       dsieger  4234: 
1.219     nia      4235:     14.1.1. Python modules and programs
                   4236:     14.1.2. R packages
                   4237:     14.1.3. TeXlive packages
1.1       dsieger  4238: 
1.184     rillig   4239: 14.2. Examples
1.1       dsieger  4240: 
1.184     rillig   4241:     14.2.1. How the www/nvu package came into pkgsrc
1.1       dsieger  4242: 
1.184     rillig   4243: When you find a package that is not yet in pkgsrc, you most likely have a URL
                   4244: from where you can download the source code. Starting with this URL, creating a
                   4245: package involves only a few steps.
1.1       dsieger  4246: 
1.184     rillig   4247:  1. In your mk.conf, set PKG_DEVELOPER=yes to enable the basic quality checks.
1.1       dsieger  4248: 
1.184     rillig   4249:  2. Install the package meta-pkgs/pkg_developer, which among others will
                   4250:     install the utilities url2pkg, pkglint, pkgvi and mkpatches:
1.1       dsieger  4251: 
1.184     rillig   4252:     $ cd /usr/pkgsrc
                   4253:     $ (cd meta-pkgs/pkg_developer && bmake update)
1.1       dsieger  4254: 
1.184     rillig   4255:  3. Choose one of the top-level directories as the category in which you want
                   4256:     to place your package. You can also create a directory of your own (maybe
1.219     nia      4257:     called local). Change into that category directory:
1.1       dsieger  4258: 
1.219     nia      4259:     $ cd category
1.1       dsieger  4260: 
1.219     nia      4261:  4. Run the program url2pkg, passing as argument the URL of the distribution
                   4262:     file (in most cases a .tar.gz file). This will download the distribution
                   4263:     file and create the necessary files of the package, based on what's in the
                   4264:     distribution file:
1.1       dsieger  4265: 
1.184     rillig   4266:     $ url2pkg https://www.example.org/packages/package-1.0.tar.gz
1.1       dsieger  4267: 
1.184     rillig   4268:  5. Examine the extracted files to determine the dependencies of your package.
                   4269:     Ideally, this is mentioned in some README file, but things may differ. For
                   4270:     each of these dependencies, look where it exists in pkgsrc, and if there is
                   4271:     a file called buildlink3.mk in that directory, add a line to your package
                   4272:     Makefile which includes that file just before the last line. If the
                   4273:     buildlink3.mk file does not exist, it must be created first. The
                   4274:     buildlink3.mk file makes sure that the package's include files and
                   4275:     libraries are provided.
1.1       dsieger  4276: 
1.219     nia      4277:     If you just need binaries from a dependent package, add a DEPENDS line to
                   4278:     the Makefile, which specifies the version of the dependency and where it
                   4279:     can be found in pkgsrc. This line should be placed in the third paragraph.
                   4280:     If the dependency is only needed for building the package, but not when
                   4281:     using it, use TOOL_DEPENDS or BUILD_DEPENDS instead of DEPENDS. The
                   4282:     difference between TOOL_DEPENDS and BUILD_DEPENDS occurs when
                   4283:     cross-compiling: TOOL_DEPENDS are native packages, i.e. packages for the
                   4284:     platform where the package is built; BUILD_DEPENDS are target packages,
                   4285:     i.e. packages for the platform for which the package is built. There is
                   4286:     also TEST_DEPENDS, which specifies a dependency used only for testing the
                   4287:     resulting package built, using the upstream project's included test suite,
                   4288:     on the native platform. Your package may then look like this:
1.1       dsieger  4289: 
1.184     rillig   4290:     [...]
1.1       dsieger  4291: 
1.184     rillig   4292:     TOOL_DEPENDS+=  libxslt-[0-9]*:../../textproc/libxslt
                   4293:     DEPENDS+=       screen-[0-9]*:../../misc/screen
                   4294:     DEPENDS+=       screen>=4.0:../../misc/screen
1.1       dsieger  4295: 
1.184     rillig   4296:     [...]
1.1       dsieger  4297: 
1.184     rillig   4298:     .include "../../category/package/buildlink3.mk"
                   4299:     .include "../../devel/glib2/buildlink3.mk"
                   4300:     .include "../../mk/bsd.pkg.mk"
1.1       dsieger  4301: 
1.184     rillig   4302:  6. Run pkglint to see what things still need to be done to make your package a
                   4303:     "good" one. If you don't know what pkglint's warnings want to tell you, try
                   4304:     pkglint --explain or pkglint -e, which outputs additional explanations.
1.1       dsieger  4305: 
1.184     rillig   4306:  7. In many cases the package is not yet ready to build. You can find
                   4307:     instructions for the most common cases in the next section, Section 14.1,
                   4308:     "Common types of packages". After you have followed the instructions over
                   4309:     there, you can hopefully continue here.
1.1       dsieger  4310: 
1.184     rillig   4311:  8. Run bmake clean to clean the working directory from the extracted files.
1.219     nia      4312:     Besides these files, a lot of cache files and other system information have
                   4313:     been saved in the working directory, which may have become outdated after
                   4314:     you edited the Makefile.
1.1       dsieger  4315: 
1.184     rillig   4316:  9. Now, run bmake to build the package. For the various things that can go
                   4317:     wrong in this phase, consult Chapter 21, Making your package work.
1.1       dsieger  4318: 
1.184     rillig   4319:     If the extracted files from the package need to be fixed, run multiple
                   4320:     rounds of these commands:
1.1       dsieger  4321: 
1.219     nia      4322:     $ bmake
1.184     rillig   4323:     $ pkgvi ${WRKSRC}/some/file/that/does/not/compile
                   4324:     $ mkpatches
1.219     nia      4325:     $ bmake mps
                   4326:     $ bmake clean
1.1       dsieger  4327: 
1.184     rillig   4328: 10. When the package builds fine, the next step is to install the package. Run 
                   4329:     bmake install and hope that everything works.
1.1       dsieger  4330: 
1.184     rillig   4331: 11. Up to now, the file PLIST, which contains a list of the files that are
                   4332:     installed by the package, is nearly empty. Run bmake print-PLIST >PLIST to
                   4333:     generate a probably correct list. Check the file using your preferred text
                   4334:     editor to see if the list of files looks plausible.
1.1       dsieger  4335: 
1.184     rillig   4336: 12. Run pkglint again to see if the generated PLIST contains garbage or not.
1.1       dsieger  4337: 
1.184     rillig   4338: 13. When you ran bmake install, the package had been registered in the database
                   4339:     of installed files, but with an empty list of files. To fix this, run bmake
                   4340:     deinstall and bmake install again. Now the package is registered with the
                   4341:     list of files from PLIST.
1.48      wiz      4342: 
1.219     nia      4343: 14. Run bmake clean update to run everything from above again in a single step,
1.184     rillig   4344:     making sure that the PLIST is correct and the whole package is created as
                   4345:     intended.
1.48      wiz      4346: 
1.219     nia      4347: 15. Run pkglint to see if there's anything left to do.
1.48      wiz      4348: 
1.219     nia      4349: 16. Commit the package to pkgsrc-wip or main pkgsrc; see Chapter 23, Submitting
1.184     rillig   4350:     and Committing.
1.50      wiz      4351: 
1.184     rillig   4352: 14.1. Common types of packages
1.1       dsieger  4353: 
1.219     nia      4354: 14.1.1. Python modules and programs
1.1       dsieger  4355: 
1.184     rillig   4356: Python modules and programs packages are easily created using a set of
                   4357: predefined variables.
1.1       dsieger  4358: 
1.184     rillig   4359: If some Python versions are not supported by the software, set the
                   4360: PYTHON_VERSIONS_INCOMPATIBLE variable to the Python versions that are not
                   4361: supported, e.g.
1.1       dsieger  4362: 
1.184     rillig   4363: PYTHON_VERSIONS_INCOMPATIBLE=       27
1.1       dsieger  4364: 
1.184     rillig   4365: If the packaged software is a Python module, include one of ../../lang/python/
1.215     wiz      4366: egg.mk or ../../lang/python/extension.mk.
1.1       dsieger  4367: 
1.215     wiz      4368: Most Python packages use setuptools ("eggs"). If the packaged software is using
                   4369: setuptools, you only need to include "../../lang/python/egg.mk".
1.1       dsieger  4370: 
1.184     rillig   4371: Either way, the package directory should be called "py-software" and PKGNAME
                   4372: should be set to "${PYPKGPREFIX}-${DISTNAME}", e.g.
1.1       dsieger  4373: 
1.184     rillig   4374: DISTNAME=   foopymodule-1.2.10
                   4375: PKGNAME=    ${PYPKGPREFIX}-${DISTNAME}
1.1       dsieger  4376: 
1.226     gutterid 4377: For software in PyPi, the name should match what PyPi specifies for "pip
                   4378: install software".
                   4379: 
1.184     rillig   4380: If it is an application, include "../../lang/python/application.mk". In order
                   4381: to correctly set the path to the Python interpreter, use the REPLACE_PYTHON
                   4382: variable and set it to the list of files (paths relative to WRKSRC) that must
                   4383: be corrected. For example:
1.1       dsieger  4384: 
1.184     rillig   4385: REPLACE_PYTHON=   *.py
1.1       dsieger  4386: 
1.184     rillig   4387: Some Python modules have separate distributions for Python-2.x and Python-3.x
                   4388: support. In pkgsrc this is handled by the versioned_dependencies.mk file. Set
                   4389: PYTHON_VERSIONED_DEPENDENCIES to the list of packages that should be depended
                   4390: upon and include "../../lang/python/versioned_dependencies.mk", then the pkgsrc
                   4391: infrastructure will depend on the appropriate package version. For example:
1.1       dsieger  4392: 
1.184     rillig   4393: PYTHON_VERSIONED_DEPENDENCIES=dialog
1.1       dsieger  4394: 
1.184     rillig   4395: Look inside versioned_dependencies.mk for a list of supported packages.
1.1       dsieger  4396: 
1.219     nia      4397: 14.1.2. R packages
1.1       dsieger  4398: 
1.184     rillig   4399: Simple R packages from CRAN are handled automatically by R2pkg, which is
                   4400: available in pkgtools/R2pkg. Individual packages (and optionally their
                   4401: dependencies) may be created and updated. R packages generally follow the same
                   4402: form, and most of the relevant information needed is contained in a DESCRIPTION
                   4403: file as part of each R package on CRAN. Consequently, R2pkg downloads that
                   4404: information and creates or updates a package in the canonical form. The
                   4405: resulting package should be reviewed for correctness.
1.1       dsieger  4406: 
1.219     nia      4407: 14.1.3. TeXlive packages
1.1       dsieger  4408: 
1.184     rillig   4409: TeXlive packages from CTAN are handled automatically by texlive2pkg, which is
                   4410: available in pkgtools/texlive2pkg.
1.1       dsieger  4411: 
1.184     rillig   4412: If the TeXlive package name is not known, it may be useful to search CTAN. A "
                   4413: Contained in" field on the package page typically identifies the basename of
                   4414: the package file in the TeXlive archive.
1.1       dsieger  4415: 
1.184     rillig   4416: If the TeXlive package name is known, download the files from the TeXlive
                   4417: archive. For package foo, you will need to download foo.tar.xz. Most TeXlive
                   4418: packages also have associated documentation packages, so download
                   4419: foo.doc.tar.xz at the same time. These files should be placed in the
                   4420: appropriate category directory, which is often but not always print. Then run
                   4421: the following command in the category directory.
1.1       dsieger  4422: 
1.184     rillig   4423: texlive2pkg foo.tar.xz foo.doc.tar.xz
1.1       dsieger  4424: 
1.184     rillig   4425: This will create two packages, tex-foo and tex-foo-doc. Be sure to check that
                   4426: both packages are correct.
1.1       dsieger  4427: 
1.184     rillig   4428: Finally, CTAN currently does not include version information in package
                   4429: filenames and changes their contents periodically when updates occur.
                   4430: Consequently, pkgsrc avoids downloading distfiles directly from CTAN and
                   4431: instead relies on the pkgsrc archives. For each new or updated TeXlive package,
                   4432: e.g., the main one and the corresponding documentation, upload the distfiles
                   4433: with the following command in each package directory.
1.1       dsieger  4434: 
1.184     rillig   4435: make upload-distfiles
1.117     sevan    4436: 
1.184     rillig   4437: 14.2. Examples
1.117     sevan    4438: 
1.184     rillig   4439: 14.2.1. How the www/nvu package came into pkgsrc
1.1       dsieger  4440: 
1.184     rillig   4441: 14.2.1.1. The initial package
1.1       dsieger  4442: 
1.184     rillig   4443: Looking at the file pkgsrc/doc/TODO, I saw that the "nvu" package has not yet
                   4444: been imported into pkgsrc. As the description says it has to do with the web,
                   4445: the obvious choice for the category is "www".
1.1       dsieger  4446: 
1.184     rillig   4447: $ mkdir www/nvu
                   4448: $ cd www/nvu
1.1       dsieger  4449: 
1.184     rillig   4450: The web site says that the sources are available as a tar file, so I fed that
                   4451: URL to the url2pkg program:
1.1       dsieger  4452: 
1.184     rillig   4453: $ url2pkg http://cvs.nvu.com/download/nvu-1.0-sources.tar.bz2
1.1       dsieger  4454: 
1.184     rillig   4455: My editor popped up, and I added a PKGNAME line below the DISTNAME line, as the
                   4456: package name should not have the word "sources" in it. I also filled in the
                   4457: MAINTAINER, HOMEPAGE and COMMENT fields. Then the package Makefile looked like
                   4458: that:
1.1       dsieger  4459: 
1.184     rillig   4460: # $NetBSD $
                   4461: #
1.1       dsieger  4462: 
1.184     rillig   4463: DISTNAME=       nvu-1.0-sources
                   4464: PKGNAME=        nvu-1.0
                   4465: CATEGORIES=     www
                   4466: MASTER_SITES=   http://cvs.nvu.com/download/
                   4467: EXTRACT_SUFX=   .tar.bz2
1.1       dsieger  4468: 
1.184     rillig   4469: MAINTAINER=     rillig@NetBSD.org
                   4470: HOMEPAGE=       http://cvs.nvu.com/
                   4471: COMMENT=        Web Authoring System
1.1       dsieger  4472: 
1.184     rillig   4473: # url2pkg-marker (please do not remove this line.)
                   4474: .include "../../mk/bsd.pkg.mk"
1.1       dsieger  4475: 
1.184     rillig   4476: On the first line of output above, an artificial space has been added between
                   4477: NetBSD and $, this is a workaround to prevent CVS expanding to the filename of
                   4478: the guide.
1.1       dsieger  4479: 
1.184     rillig   4480: Then, I quit the editor and watched pkgsrc downloading a large source archive:
1.1       dsieger  4481: 
1.184     rillig   4482: url2pkg> Running "make makesum" ...
                   4483: => Required installed package digest>=20010302: digest-20060826 found
                   4484: => Fetching nvu-1.0-sources.tar.bz2
                   4485: Requesting http://cvs.nvu.com/download/nvu-1.0-sources.tar.bz2
                   4486: 100% |*************************************| 28992 KB  150.77 KB/s00:00 ETA
                   4487: 29687976 bytes retrieved in 03:12 (150.77 KB/s)
                   4488: url2pkg> Running "make extract" ...
                   4489: => Required installed package digest>=20010302: digest-20060826 found
                   4490: => Checksum SHA1 OK for nvu-1.0-sources.tar.bz2
                   4491: => Checksum RMD160 OK for nvu-1.0-sources.tar.bz2
                   4492: work.bacc -> /tmp/roland/pkgsrc/www/nvu/work.bacc
                   4493: ===> Installing dependencies for nvu-1.0
                   4494: ===> Overriding tools for nvu-1.0
                   4495: ===> Extracting for nvu-1.0
                   4496: url2pkg> Adjusting the Makefile.
1.1       dsieger  4497: 
1.184     rillig   4498: Remember to correct CATEGORIES, HOMEPAGE, COMMENT, and DESCR when you're done!
1.1       dsieger  4499: 
1.184     rillig   4500: Good luck! (See pkgsrc/doc/pkgsrc.txt for some more help :-)
1.1       dsieger  4501: 
1.184     rillig   4502: 14.2.1.2. Fixing all kinds of problems to make the package work
1.1       dsieger  4503: 
1.184     rillig   4504: Now that the package has been extracted, let's see what's inside it. The
                   4505: package has a README.txt, but that only says something about mozilla, so it's
                   4506: probably useless for seeing what dependencies this package has. But since there
                   4507: is a GNU configure script in the package, let's hope that it will complain
                   4508: about everything it needs.
1.1       dsieger  4509: 
1.184     rillig   4510: $ bmake
                   4511: => Required installed package digest>=20010302: digest-20060826 found
                   4512: => Checksum SHA1 OK for nvu-1.0-sources.tar.bz2
                   4513: => Checksum RMD160 OK for nvu-1.0-sources.tar.bz2
                   4514: ===> Patching for nvu-1.0
                   4515: ===> Creating toolchain wrappers for nvu-1.0
                   4516: ===> Configuring for nvu-1.0
                   4517: [...]
                   4518: configure: error: Perl 5.004 or higher is required.
                   4519: [...]
                   4520: WARNING: Please add USE_TOOLS+=perl to the package Makefile.
                   4521: [...]
1.1       dsieger  4522: 
1.184     rillig   4523: That worked quite well. So I opened the package Makefile in my editor, and
                   4524: since it already has a USE_TOOLS line, I just appended "perl" to it. Since the
                   4525: dependencies of the package have changed now, and since a perl wrapper is
                   4526: automatically installed in the "tools" phase, I need to build the package from
                   4527: scratch.
1.1       dsieger  4528: 
1.184     rillig   4529: $ bmake clean
                   4530: ===> Cleaning for nvu-1.0
                   4531: $ bmake
                   4532: [...]
                   4533: *** /tmp/roland/pkgsrc/www/nvu/work.bacc/.tools/bin/make is not \
                   4534: GNU Make.  You will not be able to build Mozilla without GNU Make.
                   4535: [...]
1.1       dsieger  4536: 
1.184     rillig   4537: So I added "gmake" to the USE_TOOLS line and tried again (from scratch).
1.1       dsieger  4538: 
1.184     rillig   4539: [...]
                   4540: checking for GTK - version >= 1.2.0... no
                   4541: *** Could not run GTK test program, checking why...
                   4542: [...]
1.1       dsieger  4543: 
1.184     rillig   4544: Now to the other dependencies. The first question is: Where is the GTK package
                   4545: hidden in pkgsrc?
1.1       dsieger  4546: 
1.184     rillig   4547: $ echo ../../*/gtk*
                   4548: [many packages ...]
                   4549: $ echo ../../*/gtk
                   4550: ../../x11/gtk
                   4551: $ echo ../../*/gtk2
                   4552: ../../x11/gtk2
                   4553: $ echo ../../*/gtk2/bui*
                   4554: ../../x11/gtk2/buildlink3.mk
1.1       dsieger  4555: 
1.184     rillig   4556: The first try was definitely too broad. The second one had exactly one result,
                   4557: which is very good. But there is one pitfall with GNOME packages. Before GNOME
                   4558: 2 had been released, there were already many GNOME 1 packages in pkgsrc. To be
                   4559: able to continue to use these packages, the GNOME 2 packages were imported as
                   4560: separate packages, and their names usually have a "2" appended. So I checked
                   4561: whether this was the case here, and indeed it was.
1.1       dsieger  4562: 
1.184     rillig   4563: Since the GTK2 package has a buildlink3.mk file, adding the dependency is very
                   4564: easy. I just inserted an .include line before the last line of the package
                   4565: Makefile, so that it now looks like this:
1.1       dsieger  4566: 
1.184     rillig   4567: [...]
                   4568: .include "../../x11/gtk2/buildlink3.mk"
                   4569: .include "../../mk/bsd.pkg.mk
1.1       dsieger  4570: 
1.184     rillig   4571: After another bmake clean && bmake, the answer was:
1.108     rillig   4572: 
1.184     rillig   4573: [...]
                   4574: checking for gtk-config... /home/roland/pkg/bin/gtk-config
                   4575: checking for GTK - version >= 1.2.0... no
                   4576: *** Could not run GTK test program, checking why...
                   4577: *** The test program failed to compile or link. See the file config.log for the
                   4578: *** exact error that occured. This usually means GTK was incorrectly installed
                   4579: *** or that you have moved GTK since it was installed. In the latter case, you
                   4580: *** may want to edit the gtk-config script: /home/roland/pkg/bin/gtk-config
                   4581: configure: error: Test for GTK failed.
                   4582: [...]
1.1       dsieger  4583: 
1.184     rillig   4584: In this particular case, the assumption that "every package prefers GNOME 2"
                   4585: had been wrong. The first of the lines above told me that this package really
                   4586: wanted to have the GNOME 1 version of GTK. If the package had looked for GTK2,
                   4587: it would have looked for pkg-config instead of gtk-config. So I changed the x11
                   4588: /gtk2 to x11/gtk in the package Makefile, and tried again.
1.1       dsieger  4589: 
1.184     rillig   4590: [...]
                   4591: cc -o xpidl.o -c -DOSTYPE=\"NetBSD3\" -DOSARCH=\"NetBSD\"  [...]
                   4592: In file included from xpidl.c:42:
                   4593: xpidl.h:53:24: libIDL/IDL.h: No such file or directory
                   4594: In file included from xpidl.c:42:
                   4595: xpidl.h:132: error: parse error before "IDL_ns"
                   4596: [...]
1.1       dsieger  4597: 
1.184     rillig   4598: The package still does not find all of its dependencies. Now the question is:
                   4599: Which package provides the libIDL/IDL.h header file?
1.1       dsieger  4600: 
1.184     rillig   4601: $ echo ../../*/*idl*
                   4602: ../../devel/py-idle ../../wip/idled ../../x11/acidlaunch
                   4603: $ echo ../../*/*IDL*
                   4604: ../../net/libIDL
1.1       dsieger  4605: 
1.184     rillig   4606: Let's take the one from the second try. So I included the ../../net/libIDL/
                   4607: buildlink3.mk file and tried again. But the error didn't change. After digging
                   4608: through some of the code, I concluded that the build process of the package was
                   4609: broken and couldn't have ever worked, but since the Mozilla source tree is
                   4610: quite large, I didn't want to fix it. So I added the following to the package
                   4611: Makefile and tried again:
1.1       dsieger  4612: 
1.184     rillig   4613: CPPFLAGS+=              -I${BUILDLINK_PREFIX.libIDL}/include/libIDL-2.0
                   4614: BUILDLINK_TRANSFORM+=   l:IDL:IDL-2
1.1       dsieger  4615: 
1.184     rillig   4616: The latter line is needed because the package expects the library libIDL.so,
                   4617: but only libIDL-2.so is available. So I told the compiler wrapper to rewrite
                   4618: that on the fly.
1.1       dsieger  4619: 
1.184     rillig   4620: The next problem was related to a recent change of the FreeType interface. I
                   4621: looked up in www/seamonkey which patch files were relevant for this issue and
                   4622: copied them to the patches directory. Then I retried, fixed the patches so that
                   4623: they applied cleanly and retried again. This time, everything worked.
1.1       dsieger  4624: 
1.184     rillig   4625: 14.2.1.3. Installing the package
1.1       dsieger  4626: 
1.184     rillig   4627: $ bmake CHECK_FILES=no install
                   4628: [...]
                   4629: $ bmake print-PLIST >PLIST
                   4630: $ bmake deinstall
                   4631: $ bmake install
1.1       dsieger  4632: 
1.184     rillig   4633: Chapter 15. Programming in Makefiles
1.1       dsieger  4634: 
1.184     rillig   4635: Table of Contents
1.1       dsieger  4636: 
1.184     rillig   4637: 15.1. Caveats
                   4638: 15.2. Makefile variables
1.1       dsieger  4639: 
1.184     rillig   4640:     15.2.1. Naming conventions
1.1       dsieger  4641: 
1.184     rillig   4642: 15.3. Code snippets
1.1       dsieger  4643: 
1.184     rillig   4644:     15.3.1. Adding things to a list
                   4645:     15.3.2. Echoing a string exactly as-is
                   4646:     15.3.3. Passing CFLAGS to GNU configure scripts
                   4647:     15.3.4. Handling possibly empty variables
1.229   ! gutterid 4648:     15.3.5. Testing yes/no variables in conditions
1.1       dsieger  4649: 
1.184     rillig   4650: Pkgsrc consists of many Makefile fragments, each of which forms a well-defined
                   4651: part of the pkgsrc system. Using the make(1) system as a programming language
                   4652: for a big system like pkgsrc requires some discipline to keep the code correct
                   4653: and understandable.
1.1       dsieger  4654: 
1.184     rillig   4655: The basic ingredients for Makefile programming are variables and shell
                   4656: commands. Among these shell commands may even be more complex ones like awk(1)
                   4657: programs. To make sure that every shell command runs as intended it is
                   4658: necessary to quote all variables correctly when they are used.
1.1       dsieger  4659: 
1.184     rillig   4660: This chapter describes some patterns that appear quite often in Makefiles,
                   4661: including the pitfalls that come along with them.
1.1       dsieger  4662: 
1.184     rillig   4663: 15.1. Caveats
1.1       dsieger  4664: 
1.184     rillig   4665:   * When you are creating a file as a target of a rule, always write the data
                   4666:     to a temporary file first and finally rename that file. Otherwise there
                   4667:     might occur an error in the middle of generating the file, and when the
                   4668:     user runs make(1) for the second time, the file exists and will not be
                   4669:     regenerated properly. Example:
1.1       dsieger  4670: 
1.184     rillig   4671:     wrong:
                   4672:             @echo "line 1" > ${.TARGET}
                   4673:             @echo "line 2" >> ${.TARGET}
                   4674:             @false
1.1       dsieger  4675: 
1.184     rillig   4676:     correct:
                   4677:             @echo "line 1" > ${.TARGET}.tmp
                   4678:             @echo "line 2" >> ${.TARGET}.tmp
                   4679:             @false
                   4680:             @mv ${.TARGET}.tmp ${.TARGET}
1.1       dsieger  4681: 
1.184     rillig   4682:     When you run make wrong twice, the file wrong will exist, although there
                   4683:     was an error message in the first run. On the other hand, running make
                   4684:     correct gives an error message twice, as expected.
1.1       dsieger  4685: 
1.184     rillig   4686:     You might remember that make(1) sometimes removes ${.TARGET} in case of
                   4687:     error, but this only happens when it is interrupted, for example by
                   4688:     pressing Ctrl+C. This does not happen when one of the commands fails (like
                   4689:     false(1) above).
1.1       dsieger  4690: 
1.184     rillig   4691: 15.2. Makefile variables
1.1       dsieger  4692: 
1.184     rillig   4693: Makefile variables contain strings that can be processed using the five
                   4694: operators =, +=, ?=, := and !=, which are described in the make(1) man page.
1.1       dsieger  4695: 
1.184     rillig   4696: When a variable's value is parsed from a Makefile, the hash character # and the
                   4697: backslash character \ are handled specially. If a backslash is the last
                   4698: character in a line, that backslash is removed from the line and the line
                   4699: continues with the next line of the file.
1.1       dsieger  4700: 
1.184     rillig   4701: The # character starts a comment that reaches until the end of the line. To get
                   4702: an actual # character, such as in a URL, write \# instead.
1.1       dsieger  4703: 
1.184     rillig   4704: The evaluation of variables either happens immediately or lazy. It happens
                   4705: immediately when the variable occurs on the right-hand side of the := or the !=
                   4706: operator, in a .if condition or a .for loop. In the other cases, it is
                   4707: evaluated lazily.
1.1       dsieger  4708: 
1.184     rillig   4709: Some of the modifiers split the string into words and then operate on the
                   4710: words, others operate on the string as a whole. When a string is split into
                   4711: words, double quotes and single quotes are interpreted as delimiters, just like
                   4712: in sh(1).
1.1       dsieger  4713: 
1.184     rillig   4714: 15.2.1. Naming conventions
1.1       dsieger  4715: 
1.184     rillig   4716:   * All variable names starting with an underscore are reserved for use by the
                   4717:     pkgsrc infrastructure. They shall not be used by packages.
1.1       dsieger  4718: 
1.184     rillig   4719:   * In .for loops you should use lowercase variable names for the iteration
                   4720:     variables.
1.1       dsieger  4721: 
1.184     rillig   4722:   * All list variables should have a plural name, such as PKG_OPTIONS or
                   4723:     DISTFILES.
1.1       dsieger  4724: 
1.184     rillig   4725: 15.3. Code snippets
1.1       dsieger  4726: 
1.184     rillig   4727: 15.3.1. Adding things to a list
1.1       dsieger  4728: 
1.184     rillig   4729: When adding a string that possibly contains whitespace or quotes to a list
                   4730: (example 1), it must be quoted using the :Q modifier.
1.1       dsieger  4731: 
1.184     rillig   4732: When adding another list to a list (example 2), it must not be quoted, since
                   4733: its elements are already quoted.
1.1       dsieger  4734: 
1.184     rillig   4735: STRING=         foo * bar `date`
                   4736: LIST=           # empty
                   4737: ANOTHER_LIST=   a=b c=d
1.1       dsieger  4738: 
1.184     rillig   4739: LIST+=          ${STRING:Q}       # 1
                   4740: LIST+=          ${ANOTHER_LIST}   # 2
1.1       dsieger  4741: 
1.184     rillig   4742: 15.3.2. Echoing a string exactly as-is
1.1       dsieger  4743: 
1.184     rillig   4744: Echoing a string containing special characters needs special work.
1.1       dsieger  4745: 
1.184     rillig   4746: STRING=         foo bar <    > * `date` $$HOME ' "
                   4747: EXAMPLE_ENV=    string=${STRING:Q} x=multiple\ quoted\ words
1.1       dsieger  4748: 
1.184     rillig   4749: all:
                   4750:         echo ${STRING}                  # 1
                   4751:         echo ${STRING:Q}                # 2
                   4752:         printf '%s\n' ${STRING:Q}''     # 3
                   4753:         env ${EXAMPLE_ENV} sh -c 'echo "$$string"; echo "$$x"'   # 4
1.1       dsieger  4754: 
1.184     rillig   4755: Example 1 leads to a syntax error in the shell, as the characters are just
                   4756: copied.
1.1       dsieger  4757: 
1.184     rillig   4758: Example 2 quotes the string so that the shell interprets it correctly. But the
                   4759: echo command may additionally interpret strings with a leading dash or those
                   4760: containing backslashes.
1.1       dsieger  4761: 
1.184     rillig   4762: Example 3 can handle arbitrary strings, since printf(1) only interprets the
                   4763: format string, but not the next argument. The trailing single quotes handle the
                   4764: case when the string is empty. In that case, the :Q modifier would result in an
                   4765: empty string too, which would then be skipped by the shell. For printf(1) this
                   4766: doesn't make a difference, but other programs may care.
1.1       dsieger  4767: 
1.184     rillig   4768: In example 4, the EXAMPLE_ENV does not need to be quoted because the quoting
                   4769: has already been done when adding elements to the list.
1.1       dsieger  4770: 
1.184     rillig   4771: 15.3.3. Passing CFLAGS to GNU configure scripts
1.1       dsieger  4772: 
1.184     rillig   4773: When passing CFLAGS or similar variables to a GNU-style configure script
                   4774: (especially those that call other configure scripts), it must not have leading
                   4775: or trailing whitespace, since otherwise the configure script gets confused. To
                   4776: trim leading and trailing whitespace, use the :M modifier, as in the following
                   4777: example:
1.1       dsieger  4778: 
1.184     rillig   4779: CPPFLAGS=               # empty
                   4780: CPPFLAGS+=              -Wundef -DPREFIX=\"${PREFIX}\"
                   4781: CPPFLAGS+=              ${MY_CPPFLAGS}
1.1       dsieger  4782: 
1.184     rillig   4783: CONFIGURE_ARGS+=        CPPFLAGS=${CPPFLAGS:M*:Q}
1.1       dsieger  4784: 
1.184     rillig   4785: all:
                   4786:         echo x${CPPFLAGS:Q}x            # leading and trailing whitespace
                   4787:         echo x${CONFIGURE_ARGS:Q}x      # properly trimmed
1.1       dsieger  4788: 
1.184     rillig   4789: In this example, CPPFLAGS has both leading and trailing whitespace because the
                   4790: += operator always adds a space.
1.1       dsieger  4791: 
1.184     rillig   4792: 15.3.4. Handling possibly empty variables
1.1       dsieger  4793: 
1.184     rillig   4794: When a possibly empty variable is used in a shell program, it may lead to a
                   4795: syntax error.
1.1       dsieger  4796: 
1.184     rillig   4797: EGFILES=        # empty
1.1       dsieger  4798: 
1.184     rillig   4799: install-examples:   # produces a syntax error in the shell
                   4800:         for egfile in ${EGFILES}; do            \
                   4801:                 echo "Installing $$egfile";     \
                   4802:         done
1.1       dsieger  4803: 
1.184     rillig   4804: The shell only sees the text for egfile in ; do, since ${EGFILES} is replaced
                   4805: with an empty string by make(1). To fix this syntax error, use one of the
                   4806: snippets below.
1.1       dsieger  4807: 
1.229   ! gutterid 4808: EGFILES=        # empty
1.1       dsieger  4809: 
1.184     rillig   4810: install-examples:
                   4811:         for egfile in ${EGFILES} ""; do         \
                   4812:                 [ -n "$$egfile" ] || continue;  \
                   4813:                 echo "Installing $$egfile";     \
                   4814:         done
1.1       dsieger  4815: 
1.184     rillig   4816: In this case, an empty string is appended to the iteration list (to prevent the
                   4817: syntax error) and filtered out later.
1.1       dsieger  4818: 
1.184     rillig   4819: EGFILES=        # empty
1.1       dsieger  4820: 
1.184     rillig   4821: install-examples:
                   4822: .for egfile in ${EGFILES}
                   4823:         echo "Installing ${egfile}"
                   4824: .endfor
1.1       dsieger  4825: 
1.184     rillig   4826: If one of the filenames contains special characters, it should be enclosed in
                   4827: single or double quotes.
1.1       dsieger  4828: 
1.184     rillig   4829: To have a shell command test whether a make variable is empty, use the
                   4830: following code: ${TEST} -z ${POSSIBLY_EMPTY:Q}"".
1.1       dsieger  4831: 
1.229   ! gutterid 4832: 15.3.5. Testing yes/no variables in conditions
        !          4833: 
        !          4834: When a variable can have the values yes or no, use the following pattern to
        !          4835: test the variable:
        !          4836: 
        !          4837: .if ${VAR:U:tl} == "yes"
        !          4838: # do something
        !          4839: .endif
        !          4840: 
        !          4841: The :U modifier is only necessary if the variable can be undefined. If the
        !          4842: variable is guaranteed to be defined, the :U can be omitted.
        !          4843: 
        !          4844: The :tl modifier converts the variable value to lowercase, allowing for the
        !          4845: values yes, Yes, YES.
        !          4846: 
1.184     rillig   4847: Chapter 16. Options handling
1.1       dsieger  4848: 
                   4849: Table of Contents
                   4850: 
1.184     rillig   4851: 16.1. Global default options
                   4852: 16.2. Converting packages to use bsd.options.mk
                   4853: 16.3. Option Names
                   4854: 16.4. Determining the options of dependencies
1.1       dsieger  4855: 
                   4856: Many packages have the ability to be built to support different sets of
                   4857: features. bsd.options.mk is a framework in pkgsrc that provides generic
                   4858: handling of those options that determine different ways in which the packages
                   4859: can be built. It's possible for the user to specify exactly which sets of
                   4860: options will be built into a package or to allow a set of global default
                   4861: options apply.
                   4862: 
1.7       rillig   4863: There are two broad classes of behaviors that one might want to control via
                   4864: options. One is whether some particular feature is enabled in a program that
                   4865: will be built anyway, often by including or not including a dependency on some
                   4866: other package. The other is whether or not an additional program will be built
                   4867: as part of the package. Generally, it is better to make a split package for
                   4868: such additional programs instead of using options, because it enables binary
                   4869: packages to be built which can then be added separately. For example, the foo
                   4870: package might have minimal dependencies (those packages without which foo
                   4871: doesn't make sense), and then the foo-gfoo package might include the GTK
                   4872: frontend program gfoo. This is better than including a gtk option to foo that
                   4873: adds gfoo, because either that option is default, in which case binary users
                   4874: can't get foo without gfoo, or not default, in which case they can't get gfoo.
                   4875: With split packages, they can install foo without having GTK, and later decide
                   4876: to install gfoo (pulling in GTK at that time). This is an advantage to source
                   4877: users too, avoiding the need for rebuilds.
                   4878: 
                   4879: Plugins with widely varying dependencies should usually be split instead of
                   4880: options.
                   4881: 
                   4882: It is often more work to maintain split packages, especially if the upstream
                   4883: package does not support this. The decision of split vs. option should be made
                   4884: based on the likelihood that users will want or object to the various pieces,
                   4885: the size of the dependencies that are included, and the amount of work.
                   4886: 
                   4887: A further consideration is licensing. Non-free parts, or parts that depend on
                   4888: non-free dependencies (especially plugins) should almost always be split if
                   4889: feasible.
                   4890: 
1.184     rillig   4891: 16.1. Global default options
1.1       dsieger  4892: 
                   4893: Global default options are listed in PKG_DEFAULT_OPTIONS, which is a list of
                   4894: the options that should be built into every package if that option is
1.4       rillig   4895: supported. This variable should be set in mk.conf.
1.1       dsieger  4896: 
1.184     rillig   4897: 16.2. Converting packages to use bsd.options.mk
1.1       dsieger  4898: 
                   4899: The following example shows how bsd.options.mk should be used by the
                   4900: hypothetical ``wibble'' package, either in the package Makefile, or in a file,
                   4901: e.g. options.mk, that is included by the main package Makefile.
                   4902: 
                   4903: PKG_OPTIONS_VAR=                PKG_OPTIONS.wibble
                   4904: PKG_SUPPORTED_OPTIONS=          wibble-foo ldap
                   4905: PKG_OPTIONS_OPTIONAL_GROUPS=    database
                   4906: PKG_OPTIONS_GROUP.database=     mysql pgsql
                   4907: PKG_SUGGESTED_OPTIONS=          wibble-foo
                   4908: PKG_OPTIONS_LEGACY_VARS+=       WIBBLE_USE_OPENLDAP:ldap
                   4909: PKG_OPTIONS_LEGACY_OPTS+=       foo:wibble-foo
                   4910: 
                   4911: .include "../../mk/bsd.prefs.mk"
                   4912: 
                   4913: # this package was previously named wibble2
                   4914: .if defined(PKG_OPTIONS.wibble2)
                   4915: PKG_LEGACY_OPTIONS+=            ${PKG_OPTIONS.wibble2}
                   4916: PKG_OPTIONS_DEPRECATED_WARNINGS+= \
                   4917:         "Deprecated variable PKG_OPTIONS.wibble2 used, use ${PKG_OPTIONS_VAR} instead."
                   4918: .endif
                   4919: 
                   4920: .include "../../mk/bsd.options.mk"
                   4921: 
                   4922: # Package-specific option-handling
                   4923: 
                   4924: ###
                   4925: ### FOO support
                   4926: ###
                   4927: .if !empty(PKG_OPTIONS:Mwibble-foo)
                   4928: CONFIGURE_ARGS+=    --enable-foo
                   4929: .endif
                   4930: 
                   4931: ###
                   4932: ### LDAP support
                   4933: ###
                   4934: .if !empty(PKG_OPTIONS:Mldap)
                   4935: .  include "../../databases/openldap-client/buildlink3.mk"
                   4936: CONFIGURE_ARGS+=    --enable-ldap=${BUILDLINK_PREFIX.openldap-client}
                   4937: .endif
                   4938: 
                   4939: ###
                   4940: ### database support
                   4941: ###
                   4942: .if !empty(PKG_OPTIONS:Mmysql)
                   4943: .  include "../../mk/mysql.buildlink3.mk"
                   4944: .endif
                   4945: .if !empty(PKG_OPTIONS:Mpgsql)
                   4946: .  include "../../mk/pgsql.buildlink3.mk"
                   4947: .endif
                   4948: 
                   4949: The first section contains the information about which build options are
                   4950: supported by the package, and any default options settings if needed.
                   4951: 
                   4952:  1. PKG_OPTIONS_VAR is the name of the make(1) variable that the user can set
                   4953:     to override the default options. It should be set to PKG_OPTIONS.pkgbase.
                   4954:     Do not set it to PKG_OPTIONS.${PKGBASE}, since PKGBASE is not defined at
                   4955:     the point where the options are processed.
                   4956: 
                   4957:  2. PKG_SUPPORTED_OPTIONS is a list of build options supported by the package.
                   4958: 
                   4959:  3. PKG_OPTIONS_OPTIONAL_GROUPS is a list of names of groups of mutually
                   4960:     exclusive options. The options in each group are listed in
                   4961:     PKG_OPTIONS_GROUP.groupname. The most specific setting of any option from
                   4962:     the group takes precedence over all other options in the group. Options
                   4963:     from the groups will be automatically added to PKG_SUPPORTED_OPTIONS.
                   4964: 
                   4965:  4. PKG_OPTIONS_REQUIRED_GROUPS is like PKG_OPTIONS_OPTIONAL_GROUPS, but
                   4966:     building the packages will fail if no option from the group is selected.
                   4967: 
                   4968:  5. PKG_OPTIONS_NONEMPTY_SETS is a list of names of sets of options. At least
                   4969:     one option from each set must be selected. The options in each set are
                   4970:     listed in PKG_OPTIONS_SET.setname. Options from the sets will be
                   4971:     automatically added to PKG_SUPPORTED_OPTIONS. Building the package will
                   4972:     fail if no option from the set is selected.
                   4973: 
                   4974:  6. PKG_SUGGESTED_OPTIONS is a list of build options which are enabled by
                   4975:     default.
                   4976: 
                   4977:  7. PKG_OPTIONS_LEGACY_VARS is a list of "USE_VARIABLE:option" pairs that map
1.4       rillig   4978:     legacy mk.conf variables to their option counterparts. Pairs should be
1.1       dsieger  4979:     added with "+=" to keep the listing of global legacy variables. A warning
                   4980:     will be issued if the user uses a legacy variable.
                   4981: 
                   4982:  8. PKG_OPTIONS_LEGACY_OPTS is a list of "old-option:new-option" pairs that map
                   4983:     options that have been renamed to their new counterparts. Pairs should be
                   4984:     added with "+=" to keep the listing of global legacy options. A warning
                   4985:     will be issued if the user uses a legacy option.
                   4986: 
                   4987:  9. PKG_LEGACY_OPTIONS is a list of options implied by deprecated variables
                   4988:     used. This can be used for cases that neither PKG_OPTIONS_LEGACY_VARS nor
                   4989:     PKG_OPTIONS_LEGACY_OPTS can handle, e. g. when PKG_OPTIONS_VAR is renamed.
                   4990: 
                   4991: 10. PKG_OPTIONS_DEPRECATED_WARNINGS is a list of warnings about deprecated
                   4992:     variables or options used, and what to use instead.
                   4993: 
                   4994: A package should never modify PKG_DEFAULT_OPTIONS or the variable named in
                   4995: PKG_OPTIONS_VAR. These are strictly user-settable. To suggest a default set of
                   4996: options, use PKG_SUGGESTED_OPTIONS.
                   4997: 
                   4998: PKG_OPTIONS_VAR must be defined before including bsd.options.mk. If none of
                   4999: PKG_SUPPORTED_OPTIONS, PKG_OPTIONS_OPTIONAL_GROUPS, and
                   5000: PKG_OPTIONS_REQUIRED_GROUPS are defined (as can happen with platform-specific
                   5001: options if none of them is supported on the current platform), PKG_OPTIONS is
                   5002: set to the empty list and the package is otherwise treated as not using the
                   5003: options framework.
                   5004: 
                   5005: After the inclusion of bsd.options.mk, the variable PKG_OPTIONS contains the
                   5006: list of selected build options, properly filtered to remove unsupported and
                   5007: duplicate options.
                   5008: 
                   5009: The remaining sections contain the logic that is specific to each option. The
                   5010: correct way to check for an option is to check whether it is listed in
                   5011: PKG_OPTIONS:
                   5012: 
                   5013: .if !empty(PKG_OPTIONS:Moption)
                   5014: 
1.184     rillig   5015: 16.3. Option Names
1.1       dsieger  5016: 
                   5017: Options that enable similar features in different packages (like optional
                   5018: support for a library) should use a common name in all packages that support it
                   5019: (like the name of the library). If another package already has an option with
                   5020: the same meaning, use the same name.
                   5021: 
                   5022: Options that enable features specific to one package, where it's unlikely that
                   5023: another (unrelated) package has the same (or a similar) optional feature,
                   5024: should use a name prefixed with pkgname-.
                   5025: 
                   5026: If a group of related packages share an optional feature specific to that
                   5027: group, prefix it with the name of the "main" package (e. g.
                   5028: djbware-errno-hack).
                   5029: 
                   5030: For new options, add a line to mk/defaults/options.description. Lines have two
                   5031: fields, separated by tab. The first field is the option name, the second its
                   5032: description. The description should be a whole sentence (starting with an
                   5033: uppercase letter and ending with a period) that describes what enabling the
                   5034: option does. E. g. "Enable ispell support." The file is sorted by option names.
                   5035: 
1.184     rillig   5036: 16.4. Determining the options of dependencies
1.7       rillig   5037: 
                   5038: When writing buildlink3.mk files, it is often necessary to list different
                   5039: dependencies based on the options with which the package was built. For
                   5040: querying these options, the file pkgsrc/mk/pkg-build-options.mk should be used.
                   5041: A typical example looks like this:
                   5042: 
                   5043: pkgbase := libpurple
                   5044: .include "../../mk/pkg-build-options.mk"
                   5045: 
                   5046: .if !empty(PKG_BUILD_OPTIONS.libpurple:Mdbus)
                   5047: ...
                   5048: .endif
                   5049: 
                   5050: Including pkg-build-options.mk here will set the variable
                   5051: PKG_BUILD_OPTIONS.libpurple to the build options of the libpurple package,
                   5052: which can then be queried like PKG_OPTIONS in the options.mk file. See the file
                   5053: pkg-build-options.mk for more details.
                   5054: 
1.184     rillig   5055: Chapter 17. Tools needed for building or running
                   5056: 
                   5057: Table of Contents
                   5058: 
                   5059: 17.1. Tools for pkgsrc builds
                   5060: 17.2. Tools needed by packages
                   5061: 17.3. Tools provided by platforms
                   5062: 
                   5063: The USE_TOOLS definition is used both internally by pkgsrc and also for
                   5064: individual packages to define what commands are needed for building a package
                   5065: (like TOOL_DEPENDS) or for later run-time of an installed packaged (such as
                   5066: DEPENDS). If the native system provides an adequate tool, then in many cases, a
                   5067: pkgsrc package will not be used.
                   5068: 
                   5069: When building a package, the replacement tools are made available in a
                   5070: directory (as symlinks or wrapper scripts) that is early in the executable
                   5071: search path. Just like the buildlink system, this helps with consistent builds.
                   5072: 
                   5073: A tool may be needed to help build a specific package. For example, perl, GNU
                   5074: make (gmake) or yacc may be needed.
                   5075: 
                   5076: Also a tool may be needed, for example, because the native system's supplied
                   5077: tool may be inefficient for building a package with pkgsrc. For example, a
                   5078: package may need GNU awk, bison (instead of yacc) or a better sed.
                   5079: 
                   5080: The tools used by a package can be listed by running make show-tools.
                   5081: 
                   5082: 17.1. Tools for pkgsrc builds
                   5083: 
                   5084: The default set of tools used by pkgsrc is defined in bsd.pkg.mk. This includes
                   5085: standard Unix tools, such as: cat, awk, chmod, test, and so on. These can be
                   5086: seen by running: make show-var VARNAME=USE_TOOLS.
                   5087: 
                   5088: If a package needs a specific program to build then the USE_TOOLS variable can
                   5089: be used to define the tools needed.
                   5090: 
                   5091: 17.2. Tools needed by packages
                   5092: 
                   5093: In the following examples, the :run means that it is needed at run-time (and
                   5094: becomes a DEPENDS). The default is a build dependency which can be set with
                   5095: :build. (So in this example, it is the same as gmake:build and
                   5096: pkg-config:build.)
                   5097: 
                   5098: USE_TOOLS+=     gmake perl:run pkg-config
                   5099: 
                   5100: When using the tools framework, a TOOLS_PATH.foo variable is defined which
                   5101: contains the full path to the appropriate tool. For example, TOOLS_PATH.bash
                   5102: could be "/bin/bash" on Linux systems.
                   5103: 
                   5104: If you always need a pkgsrc version of the tool at run-time, then just use
                   5105: DEPENDS instead.
                   5106: 
                   5107: 17.3. Tools provided by platforms
                   5108: 
                   5109: When improving or porting pkgsrc to a new platform, have a look at (or create)
                   5110: the corresponding platform specific make file fragment under pkgsrc/mk/tools/
                   5111: tools.${OPSYS}.mk which defines the name of the common tools. For example:
                   5112: 
                   5113: .if exists(/usr/bin/bzcat)
                   5114: TOOLS_PLATFORM.bzcat?=          /usr/bin/bzcat
                   5115: .elif exists(/usr/bin/bzip2)
                   5116: TOOLS_PLATFORM.bzcat?=          /usr/bin/bzip2 -cd
                   5117: .endif
                   5118: 
                   5119: TOOLS_PLATFORM.true?=           true                    # shell builtin
                   5120: 
                   5121: Chapter 18. Buildlink methodology
1.1       dsieger  5122: 
                   5123: Table of Contents
                   5124: 
1.184     rillig   5125: 18.1. Converting packages to use buildlink3
                   5126: 18.2. Writing buildlink3.mk files
                   5127: 
                   5128:     18.2.1. Anatomy of a buildlink3.mk file
                   5129:     18.2.2. Updating BUILDLINK_API_DEPENDS.pkg and BUILDLINK_ABI_DEPENDS.pkg in
                   5130:         buildlink3.mk files
                   5131: 
                   5132: 18.3. Writing builtin.mk files
                   5133: 
                   5134:     18.3.1. Anatomy of a builtin.mk file
                   5135:     18.3.2. Global preferences for native or pkgsrc software
                   5136: 
                   5137: Buildlink is a framework in pkgsrc that controls what headers and libraries are
                   5138: seen by a package's configure and build processes. This is implemented in a two
                   5139: step process:
                   5140: 
                   5141:  1. Symlink headers and libraries for dependencies into BUILDLINK_DIR, which by
                   5142:     default is a subdirectory of WRKDIR.
                   5143: 
                   5144:  2. Create wrapper scripts that are used in place of the normal compiler tools
                   5145:     that translate -I${LOCALBASE}/include and -L${LOCALBASE}/lib into
                   5146:     references to BUILDLINK_DIR. The wrapper scripts also make native compiler
                   5147:     on some operating systems look like GCC, so that packages that expect GCC
                   5148:     won't require modifications to build with those native compilers.
                   5149: 
                   5150: This normalizes the environment in which a package is built so that the package
                   5151: may be built consistently despite what other software may be installed. Please
                   5152: note that the normal system header and library paths, e.g. /usr/include, /usr/
                   5153: lib, etc., are always searched -- buildlink3 is designed to insulate the
                   5154: package build from non-system-supplied software.
                   5155: 
                   5156: 18.1. Converting packages to use buildlink3
1.1       dsieger  5157: 
1.184     rillig   5158: The process of converting packages to use the buildlink3 framework ("bl3ifying"
                   5159: ) is fairly straightforward. The things to keep in mind are:
1.1       dsieger  5160: 
1.184     rillig   5161:  1. Ensure that the build always calls the wrapper scripts instead of the
                   5162:     actual toolchain. Some packages are tricky, and the only way to know for
                   5163:     sure is the check ${WRKDIR}/.work.log to see if the wrappers are being
                   5164:     invoked.
1.1       dsieger  5165: 
1.184     rillig   5166:  2. Don't override PREFIX from within the package Makefile, e.g. Java VMs,
                   5167:     standalone shells, etc., because the code to symlink files into $
                   5168:     {BUILDLINK_DIR} looks for files relative to "pkg_info -qp pkgname".
1.1       dsieger  5169: 
1.184     rillig   5170:  3. Remember that only the buildlink3.mk files that you list in a package's
                   5171:     Makefile are added as dependencies for that package.
1.1       dsieger  5172: 
1.184     rillig   5173: If a dependency on a particular package is required for its libraries and
                   5174: headers, then we replace:
1.1       dsieger  5175: 
1.184     rillig   5176: DEPENDS+=       foo>=1.1.0:../../category/foo
1.1       dsieger  5177: 
1.184     rillig   5178: with
1.1       dsieger  5179: 
1.184     rillig   5180: .include "../../category/foo/buildlink3.mk"
1.1       dsieger  5181: 
1.184     rillig   5182: The buildlink3.mk files usually define the required dependencies. If you need a
                   5183: newer version of the dependency when using buildlink3.mk files, then you can
                   5184: define it in your Makefile; for example:
1.1       dsieger  5185: 
1.184     rillig   5186: BUILDLINK_API_DEPENDS.foo+=   foo>=1.1.0
                   5187: .include "../../category/foo/buildlink3.mk"
1.1       dsieger  5188: 
1.184     rillig   5189: There are several buildlink3.mk files in pkgsrc/mk that handle special package
                   5190: issues:
1.1       dsieger  5191: 
1.184     rillig   5192:   * bdb.buildlink3.mk chooses either the native or a pkgsrc Berkeley DB
                   5193:     implementation based on the values of BDB_ACCEPTED and BDB_DEFAULT.
1.1       dsieger  5194: 
1.184     rillig   5195:   * curses.buildlink3.mk: If the system comes with neither Curses nor NCurses,
                   5196:     this will take care to install the devel/ncurses package.
1.1       dsieger  5197: 
1.184     rillig   5198:   * krb5.buildlink3.mk uses the value of KRB5_ACCEPTED to choose between adding
                   5199:     a dependency on Heimdal or MIT-krb5 for packages that require a Kerberos 5
                   5200:     implementation.
1.1       dsieger  5201: 
1.184     rillig   5202:   * motif.buildlink3.mk checks for a system-provided Motif installation or adds
                   5203:     a dependency on x11/lesstif or x11/motif. The user can set MOTIF_TYPE to "
                   5204:     dt", "lesstif" or "motif" to choose which Motif version will be used.
1.1       dsieger  5205: 
1.184     rillig   5206:   * readline.buildlink3.mk checks for a system-provided GNU readline or
                   5207:     editline (libedit) installation, or adds a dependency on devel/readline,
                   5208:     devel/editline. The user can set READLINE_DEFAULT to choose readline
                   5209:     implementation. If your package really needs GNU readline library, its
                   5210:     Makefile should include devel/readline/buildlink3.mk instead of
                   5211:     readline.buildlink3.mk.
1.1       dsieger  5212: 
1.184     rillig   5213:   * oss.buildlink3.mk defines several variables that may be used by packages
                   5214:     that use the Open Sound System (OSS) API.
1.1       dsieger  5215: 
1.184     rillig   5216:   * pgsql.buildlink3.mk will accept any of the Postgres versions in the
                   5217:     variable PGSQL_VERSIONS_ACCEPTED and default to the version
                   5218:     PGSQL_VERSION_DEFAULT. See the file for more information.
1.1       dsieger  5219: 
1.184     rillig   5220:   * pthread.buildlink3.mk uses the value of PTHREAD_OPTS and checks for native
                   5221:     pthreads or adds a dependency on devel/pth as needed.
1.1       dsieger  5222: 
1.184     rillig   5223:   * xaw.buildlink3.mk uses the value of XAW_TYPE to choose a particular Athena
                   5224:     widgets library.
1.1       dsieger  5225: 
1.184     rillig   5226: The comments in those buildlink3.mk files provide a more complete description
                   5227: of how to use them properly.
1.1       dsieger  5228: 
1.184     rillig   5229: 18.2. Writing buildlink3.mk files
1.1       dsieger  5230: 
1.184     rillig   5231: A package's buildlink3.mk file is included by Makefiles to indicate the need to
                   5232: compile and link against header files and libraries provided by the package. A
                   5233: buildlink3.mk file should always provide enough information to add the correct
                   5234: type of dependency relationship and include any other buildlink3.mk files that
                   5235: it needs to find headers and libraries that it needs in turn.
1.1       dsieger  5236: 
1.184     rillig   5237: To generate an initial buildlink3.mk file for further editing, Rene Hexel's
                   5238: pkgtools/createbuildlink package is highly recommended. For most packages, the
                   5239: following command will generate a good starting point for buildlink3.mk files:
1.1       dsieger  5240: 
1.184     rillig   5241: % cd pkgsrc/category/pkgdir
                   5242: % createbuildlink >buildlink3.mk
1.1       dsieger  5243: 
                   5244: 
1.184     rillig   5245: 18.2.1. Anatomy of a buildlink3.mk file
1.1       dsieger  5246: 
1.184     rillig   5247: The following real-life example buildlink3.mk is taken from pkgsrc/graphics/
                   5248: tiff:
1.14      jmcneill 5249: 
1.184     rillig   5250: # $NetBSD: buildlink3.mk,v 1.16 2009/03/20 19:24:45 joerg Exp $
1.1       dsieger  5251: 
1.184     rillig   5252: BUILDLINK_TREE+=        tiff
1.1       dsieger  5253: 
1.184     rillig   5254: .if !defined(TIFF_BUILDLINK3_MK)
                   5255: TIFF_BUILDLINK3_MK:=
1.1       dsieger  5256: 
1.184     rillig   5257: BUILDLINK_API_DEPENDS.tiff+=    tiff>=3.6.1
                   5258: BUILDLINK_ABI_DEPENDS.tiff+=    tiff>=3.7.2nb1
                   5259: BUILDLINK_PKGSRCDIR.tiff?=      ../../graphics/tiff
1.1       dsieger  5260: 
1.184     rillig   5261: .include "../../devel/zlib/buildlink3.mk"
                   5262: .include "../../graphics/jpeg/buildlink3.mk"
                   5263: .endif # TIFF_BUILDLINK3_MK
1.1       dsieger  5264: 
1.184     rillig   5265: BUILDLINK_TREE+=        -tiff
1.1       dsieger  5266: 
1.184     rillig   5267: The header and footer manipulate BUILDLINK_TREE, which is common across all
                   5268: buildlink3.mk files and is used to track the dependency tree.
1.1       dsieger  5269: 
1.184     rillig   5270: The main section is protected from multiple inclusion and controls how the
                   5271: dependency on pkg is added. Several important variables are set in the section:
1.1       dsieger  5272: 
1.185     wiz      5273:   * BUILDLINK_API_DEPENDS.pkg is the dependency version recorded in the
1.184     rillig   5274:     installed package; this should always be set using += to ensure that we're
                   5275:     appending to any pre-existing list of values. This variable should be set
1.185     wiz      5276:     to the last version of the package that had an backwards-incompatible API
1.184     rillig   5277:     change.
1.1       dsieger  5278: 
1.184     rillig   5279:   * BUILDLINK_PKGSRCDIR.pkg is the location of the pkg pkgsrc directory.
1.1       dsieger  5280: 
1.184     rillig   5281:   * BUILDLINK_DEPMETHOD.pkg (not shown above) controls whether we use
                   5282:     BUILD_DEPENDS or DEPENDS to add the dependency on pkg. The build dependency
                   5283:     is selected by setting BUILDLINK_DEPMETHOD.pkg to "build". By default, the
                   5284:     full dependency is used.
1.1       dsieger  5285: 
1.184     rillig   5286:   * BUILDLINK_INCDIRS.pkg and BUILDLINK_LIBDIRS.pkg (not shown above) are lists
                   5287:     of subdirectories of ${BUILDLINK_PREFIX.pkg} to add to the header and
                   5288:     library search paths. These default to "include" and "lib" respectively.
1.1       dsieger  5289: 
1.184     rillig   5290:   * BUILDLINK_CPPFLAGS.pkg (not shown above) is the list of preprocessor flags
                   5291:     to add to CPPFLAGS, which are passed on to the configure and build phases.
                   5292:     The "-I" option should be avoided and instead be handled using
                   5293:     BUILDLINK_INCDIRS.pkg as above.
1.66      asau     5294: 
1.184     rillig   5295: The following variables are all optionally defined within this second section
                   5296: (protected against multiple inclusion) and control which package files are
                   5297: symlinked into ${BUILDLINK_DIR} and how their names are transformed during the
                   5298: symlinking:
1.23      jakllsch 5299: 
1.184     rillig   5300:   * BUILDLINK_FILES.pkg (not shown above) is a shell glob pattern relative to $
                   5301:     {BUILDLINK_PREFIX.pkg} to be symlinked into ${BUILDLINK_DIR}, e.g. include/
                   5302:     *.h.
1.1       dsieger  5303: 
1.184     rillig   5304:   * BUILDLINK_FILES_CMD.pkg (not shown above) is a shell pipeline that outputs
                   5305:     to stdout a list of files relative to ${BUILDLINK_PREFIX.pkg}. The
                   5306:     resulting files are to be symlinked into ${BUILDLINK_DIR}. By default, this
                   5307:     takes the +CONTENTS of a pkg and filters it through $
                   5308:     {BUILDLINK_CONTENTS_FILTER.pkg}.
1.1       dsieger  5309: 
1.184     rillig   5310:   * BUILDLINK_CONTENTS_FILTER.pkg (not shown above) is a filter command that
                   5311:     filters +CONTENTS input into a list of files relative to $
                   5312:     {BUILDLINK_PREFIX.pkg} on stdout. By default, BUILDLINK_CONTENTS_FILTER.pkg
                   5313:     outputs the contents of the include and lib directories in the package
                   5314:     +CONTENTS.
1.1       dsieger  5315: 
1.184     rillig   5316:   * BUILDLINK_FNAME_TRANSFORM.pkg (not shown above) is a list of sed arguments
                   5317:     used to transform the name of the source filename into a destination
                   5318:     filename, e.g. -e "s|/curses.h|/ncurses.h|g".
1.1       dsieger  5319: 
1.184     rillig   5320: This section can additionally include any buildlink3.mk needed for pkg's
                   5321: library dependencies. Including these buildlink3.mk files means that the
                   5322: headers and libraries for these dependencies are also symlinked into $
                   5323: {BUILDLINK_DIR} whenever the pkg buildlink3.mk file is included. Dependencies
                   5324: are only added for directly include buildlink3.mk files.
1.1       dsieger  5325: 
1.184     rillig   5326: When providing a buildlink3.mk and including other buildlink3.mk files in it,
                   5327: please only add necessary ones, i.e., those whose libraries or header files are
                   5328: automatically exposed when the package is use.
1.1       dsieger  5329: 
1.184     rillig   5330: In particular, if only an executable (bin/foo) is linked against a library,
                   5331: that library does not need to be propagated in the buildlink3.mk file.
1.1       dsieger  5332: 
1.184     rillig   5333: The following steps should help you decide if a buildlink3.mk file needs to be
                   5334: included:
1.1       dsieger  5335: 
1.184     rillig   5336:   * Look at the installed header files: What headers do they include? The
                   5337:     packages providing these files must be buildlinked.
1.1       dsieger  5338: 
1.184     rillig   5339:   * Run ldd on all installed libraries and look against what other libraries
                   5340:     they link. Some of the packages providing these probably need to be
                   5341:     buildlinked; however, it's not automatic, since e.g. GTK on some systems
                   5342:     pulls in the X libraries, so they will show up in the ldd output, while on
                   5343:     others (like OS X) it won't. ldd output can thus only be used as a hint.
1.1       dsieger  5344: 
1.184     rillig   5345: 18.2.2. Updating BUILDLINK_API_DEPENDS.pkg and BUILDLINK_ABI_DEPENDS.pkg in
                   5346: buildlink3.mk files
1.16      jnemeth  5347: 
1.185     wiz      5348: Both variables set lower bounds for a version of this package. The two
                   5349: variables differ in that one describes source compatibility (API) and the other
                   5350: binary compatibility (ABI). The difference is that a change in the API breaks
                   5351: compilation of programs while changes in the ABI stop compiled programs from
                   5352: running.
                   5353: 
                   5354: The BUILDLINK_API_DEPENDS.pkg variable in a buildlink3.mk should be changed
                   5355: very rarely. (One possible scenario: If all packages using this package need a
                   5356: higher version than defined in the buildlink3.mk, BUILDLINK_API_DEPENDS.pkg
                   5357: could be updated to that higher version.)
                   5358: 
                   5359: On the other hand, changes to BUILDLINK_ABI_DEPENDS.pkg are more common. The
                   5360: variable will need to be updated every time the major version of one of its
                   5361: shared libraries is changed, or any other change where a binary built against
                   5362: the previous version of the package will not run against the new version any
                   5363: longer.
                   5364: 
                   5365: In such a case, the package's BUILDLINK_ABI_DEPENDS.pkg must be increased to
                   5366: require the new package version. Then the PKGREVISION of all packages foo that
                   5367: depend on this package need to be increased, and if they have buildlink3.mk
                   5368: files, BUILDLINK_ABI_DEPENDS.foo in their buildlink3.mk files must be increased
                   5369: to the new version as well. This is required so that a package will pull in the
                   5370: versions of the packages that use the new ABI and that the packages'
                   5371: PKGREVISIONs uniquely identify the packages built against the new ABI. The
                   5372: pkgtools/revbump package can help with these updates.
1.1       dsieger  5373: 
1.184     rillig   5374: See Section 21.1.5, "Handling dependencies" for more information about
1.185     wiz      5375: dependencies on other packages, including the BUILDLINK_API_DEPENDS
                   5376: definitions.
1.1       dsieger  5377: 
1.184     rillig   5378: Please take careful consideration before adjusting BUILDLINK_API_DEPENDS.pkg or
1.185     wiz      5379: BUILDLINK_ABI_DEPENDS.pkg in a buildlink3.mk file as we don't want to cause
                   5380: unneeded package deletions and rebuilds. In many cases, new versions of
                   5381: packages work just fine with older dependencies.
1.1       dsieger  5382: 
1.211     gutterid 5383: Also, it is not needed to set BUILDLINK_ABI_DEPENDS.pkg when it is identical to
1.184     rillig   5384: BUILDLINK_API_DEPENDS.pkg.
1.1       dsieger  5385: 
1.211     gutterid 5386: Note there is also the distinction that users are able to disable enforcement
                   5387: of ABI dependencies using the USE_ABI_DEPENDS variable, but there is no
                   5388: equivalent option for API dependencies.
                   5389: 
1.184     rillig   5390: 18.3. Writing builtin.mk files
1.1       dsieger  5391: 
1.184     rillig   5392: Some packages in pkgsrc install headers and libraries that coincide with
                   5393: headers and libraries present in the base system. Aside from a buildlink3.mk
                   5394: file, these packages should also include a builtin.mk file that includes the
                   5395: necessary checks to decide whether using the built-in software or the pkgsrc
                   5396: software is appropriate.
1.1       dsieger  5397: 
1.184     rillig   5398: The only requirements of a builtin.mk file for pkg are:
1.1       dsieger  5399: 
1.184     rillig   5400:  1. It should set USE_BUILTIN.pkg to either "yes" or "no" after it is included.
1.1       dsieger  5401: 
1.184     rillig   5402:  2. It should not override any USE_BUILTIN.pkg which is already set before the
                   5403:     builtin.mk file is included.
1.1       dsieger  5404: 
1.184     rillig   5405:  3. It should be written to allow multiple inclusion. This is very important
                   5406:     and takes careful attention to Makefile coding.
1.1       dsieger  5407: 
1.184     rillig   5408: 18.3.1. Anatomy of a builtin.mk file
1.1       dsieger  5409: 
1.184     rillig   5410: The following is the recommended template for builtin.mk files:
1.1       dsieger  5411: 
1.184     rillig   5412: .if !defined(IS_BUILTIN.foo)
                   5413: #
                   5414: # IS_BUILTIN.foo is set to "yes" or "no" depending on whether "foo"
                   5415: # genuinely exists in the system or not.
                   5416: #
                   5417: IS_BUILTIN.foo?=        no
1.1       dsieger  5418: 
1.184     rillig   5419: # BUILTIN_PKG.foo should be set here if "foo" is built-in and its package
                   5420: # version can be determined.
                   5421: #
                   5422: .  if !empty(IS_BUILTIN.foo:M[yY][eE][sS])
                   5423: BUILTIN_PKG.foo?=       foo-1.0
                   5424: .  endif
                   5425: .endif  # IS_BUILTIN.foo
1.1       dsieger  5426: 
1.184     rillig   5427: .if !defined(USE_BUILTIN.foo)
                   5428: USE_BUILTIN.foo?=       ${IS_BUILTIN.foo}
                   5429: .  if defined(BUILTIN_PKG.foo)
                   5430: .    for _depend_ in ${BUILDLINK_API_DEPENDS.foo}
                   5431: .      if !empty(USE_BUILTIN.foo:M[yY][eE][sS])
                   5432: USE_BUILTIN.foo!=                                                       \
                   5433:         ${PKG_ADMIN} pmatch '${_depend_}' ${BUILTIN_PKG.foo}            \
                   5434:         && ${ECHO} "yes" || ${ECHO} "no"
                   5435: .      endif
                   5436: .    endfor
                   5437: .  endif
                   5438: .endif  # USE_BUILTIN.foo
1.1       dsieger  5439: 
1.184     rillig   5440: CHECK_BUILTIN.foo?=     no
                   5441: .if !empty(CHECK_BUILTIN.foo:M[nN][oO])
                   5442: #
                   5443: # Here we place code that depends on whether USE_BUILTIN.foo is set to
                   5444: # "yes" or "no".
                   5445: #
                   5446: .endif  # CHECK_BUILTIN.foo
1.1       dsieger  5447: 
1.184     rillig   5448: The first section sets IS_BUILTIN.pkg depending on if pkg really exists in the
                   5449: base system. This should not be a base system software with similar
                   5450: functionality to pkg; it should only be "yes" if the actual package is included
                   5451: as part of the base system. This variable is only used internally within the
                   5452: builtin.mk file.
1.1       dsieger  5453: 
1.184     rillig   5454: The second section sets BUILTIN_PKG.pkg to the version of pkg in the base
                   5455: system if it exists (if IS_BUILTIN.pkg is "yes"). This variable is only used
                   5456: internally within the builtin.mk file.
1.1       dsieger  5457: 
1.184     rillig   5458: The third section sets USE_BUILTIN.pkg and is required in all builtin.mk files.
                   5459: The code in this section must make the determination whether the built-in
                   5460: software is adequate to satisfy the dependencies listed in
                   5461: BUILDLINK_API_DEPENDS.pkg. This is typically done by comparing BUILTIN_PKG.pkg
                   5462: against each of the dependencies in BUILDLINK_API_DEPENDS.pkg. USE_BUILTIN.pkg 
                   5463: must be set to the correct value by the end of the builtin.mk file. Note that
                   5464: USE_BUILTIN.pkg may be "yes" even if IS_BUILTIN.pkg is "no" because we may make
                   5465: the determination that the built-in version of the software is similar enough
                   5466: to be used as a replacement.
1.1       dsieger  5467: 
1.184     rillig   5468: The last section is guarded by CHECK_BUILTIN.pkg, and includes code that uses
                   5469: the value of USE_BUILTIN.pkg set in the previous section. This typically
                   5470: includes, e.g., adding additional dependency restrictions and listing
                   5471: additional files to symlink into ${BUILDLINK_DIR} (via BUILDLINK_FILES.pkg).
1.1       dsieger  5472: 
1.184     rillig   5473: 18.3.2. Global preferences for native or pkgsrc software
1.1       dsieger  5474: 
1.184     rillig   5475: When building packages, it's possible to choose whether to set a global
                   5476: preference for using either the built-in (native) version or the pkgsrc version
                   5477: of software to satisfy a dependency. This is controlled by setting
                   5478: PREFER_PKGSRC and PREFER_NATIVE. These variables take values of either "yes", "
                   5479: no", or a list of packages. PREFER_PKGSRC tells pkgsrc to use the pkgsrc
                   5480: versions of software, while PREFER_NATIVE tells pkgsrc to use the built-in
                   5481: versions. Preferences are determined by the most specific instance of the
                   5482: package in either PREFER_PKGSRC or PREFER_NATIVE. If a package is specified in
                   5483: neither or in both variables, then PREFER_PKGSRC has precedence over
                   5484: PREFER_NATIVE. For example, to require using pkgsrc versions of software for
                   5485: all but the most basic bits on a NetBSD system, you can set:
1.1       dsieger  5486: 
1.184     rillig   5487: PREFER_PKGSRC=  yes
                   5488: PREFER_NATIVE=  getopt skey tcp_wrappers
1.1       dsieger  5489: 
1.184     rillig   5490: A package must have a builtin.mk file to be listed in PREFER_NATIVE, otherwise
                   5491: it is simply ignored in that list.
1.1       dsieger  5492: 
1.191     bacon    5493: PREFER_PKGSRC and PREFER_NATIVE should be set during bootstrap to ensure that
                   5494: the bootstrap process does not use inapropriate native tools as dependencies
                   5495: for core packages.
                   5496: 
                   5497: # ./bootstrap --prefer-pkgsrc yes --prefer-native openssl
                   5498: 
                   5499: Switching between settings globally at a later date can introduce complications
                   5500: with dependency resolution. This is caused by packages built with the opposite
                   5501: preference being installed alongside each other. Hence, any changes to these
                   5502: variables after bootstrap will necessitate rebuilding all packages depending on
                   5503: one whose preference has been changed. This is not trivial and should be
                   5504: avoided.
                   5505: 
                   5506: When using pkgsrc on Linux systems, there is high risk of "leakage", where
                   5507: programs installed by pkgsrc may inadvertently use a command or library not
                   5508: installed by pkgsrc, e.g. those installed by yum or apt. Such foreign
                   5509: dependencies may be installed, removed, or upgraded to a version incompatible
                   5510: with the pkgsrc package at any time, causing pkgsrc packages to subsequently
                   5511: malfunction. Pkgsrc cannot prevent this, as it has no control over other
                   5512: package managers. Another potential problem is that under Redhat Enterprise and
                   5513: related Linux systems, yum packages are only patched and never upgraded, so
                   5514: eventually they may become too outdated for use by pkgsrc. Even intentionally
                   5515: using foreign dependencies, not considered leakage, can lead to these problems,
                   5516: so it is generally discouraged. In order to minimize such problems,
                   5517: PREFER_PKGSRC defaults to "yes" on Linux systems. This ensures that pkgsrc is
                   5518: aware of any changes to dependency packages and can rebuild or upgrade the
                   5519: entire dependency tree as needed. This default can be overridden by setting
                   5520: --prefer-pkgsrc to "no" or a list of packages, or by setting --prefer-native to
                   5521: "yes".
1.1       dsieger  5522: 
1.184     rillig   5523: Chapter 19. PLIST issues
1.1       dsieger  5524: 
1.184     rillig   5525: Table of Contents
1.1       dsieger  5526: 
1.184     rillig   5527: 19.1. RCS ID
                   5528: 19.2. Semi-automatic PLIST generation
                   5529: 19.3. Tweaking output of make print-PLIST
                   5530: 19.4. Variable substitution in PLIST
                   5531: 19.5. Man page compression
                   5532: 19.6. Changing PLIST source with PLIST_SRC
                   5533: 19.7. Platform-specific and differing PLISTs
                   5534: 19.8. Build-specific PLISTs
                   5535: 19.9. Sharing directories between packages
1.1       dsieger  5536: 
1.184     rillig   5537: The PLIST file contains a package's "packing list", i.e. a list of files that
                   5538: belong to the package (relative to the ${PREFIX} directory it's been installed
                   5539: in) plus some additional statements - see the pkg_create(1) man page for a full
                   5540: list. This chapter addresses some issues that need attention when dealing with
                   5541: the PLIST file (or files, see below!).
1.1       dsieger  5542: 
1.184     rillig   5543: 19.1. RCS ID
1.1       dsieger  5544: 
1.184     rillig   5545: Be sure to add a RCS ID line as the first thing in any PLIST file you write:
1.1       dsieger  5546: 
1.184     rillig   5547: @comment $NetBSD $
1.1       dsieger  5548: 
1.184     rillig   5549: An artificial space has been added between NetBSD and $, this is a workaround
                   5550: here to prevent CVS expanding to the filename of the guide. When adding the RCS
                   5551: ID the space should be omitted.
1.38      wiz      5552: 
1.184     rillig   5553: 19.2. Semi-automatic PLIST generation
1.1       dsieger  5554: 
1.184     rillig   5555: You can use the make print-PLIST command to output a PLIST that matches any new
                   5556: files since the package was extracted. See Section 13.17, "Other helpful
                   5557: targets" for more information on this target.
1.11      rillig   5558: 
1.184     rillig   5559: 19.3. Tweaking output of make print-PLIST
1.1       dsieger  5560: 
1.184     rillig   5561: The PRINT_PLIST_AWK variable takes a set of AWK patterns and actions that are
                   5562: used to filter the output of print-PLIST. You can append any chunk of AWK
                   5563: scripting you like to it, but be careful with quoting.
1.1       dsieger  5564: 
1.184     rillig   5565: For example, to get all files inside the libdata/foo directory removed from the
                   5566: resulting PLIST:
1.1       dsieger  5567: 
1.184     rillig   5568: PRINT_PLIST_AWK+=       /^libdata\/foo/ { next; }
1.1       dsieger  5569: 
1.185     wiz      5570: The PRINT_PLIST_AWK transformations are evaluated after the file list and
                   5571: directory list are sorted. EARLY_PRINT_PLIST_AWK is like PRINT_PLIST_AWK except
                   5572: it operates before the file list and directory list are sorted.
                   5573: 
1.184     rillig   5574: 19.4. Variable substitution in PLIST
1.1       dsieger  5575: 
1.184     rillig   5576: A number of variables are substituted automatically in PLISTs when a package is
                   5577: installed on a system. This includes the following variables:
1.1       dsieger  5578: 
1.184     rillig   5579: ${MACHINE_ARCH}, ${MACHINE_GNU_ARCH}
1.1       dsieger  5580: 
1.184     rillig   5581:     Some packages like emacs and perl embed information about which
                   5582:     architecture they were built on into the pathnames where they install their
                   5583:     files. To handle this case, PLIST will be preprocessed before actually
                   5584:     used, and the symbol "${MACHINE_ARCH}" will be replaced by what uname -p
                   5585:     gives. The same is done if the string ${MACHINE_GNU_ARCH} is embedded in
                   5586:     PLIST somewhere - use this on packages that have GNU autoconf-created
                   5587:     configure scripts.
1.1       dsieger  5588: 
1.184     rillig   5589:     Legacy note
1.1       dsieger  5590: 
1.184     rillig   5591:     There used to be a symbol "$ARCH" that was replaced by the output of uname
                   5592:     -m, but that's no longer supported and has been removed.
1.1       dsieger  5593: 
1.184     rillig   5594: ${OPSYS}, ${LOWER_OPSYS}, ${OS_VERSION}
1.1       dsieger  5595: 
1.184     rillig   5596:     Some packages want to embed the OS name and version into some paths. To do
                   5597:     this, use these variables in the PLIST:
1.1       dsieger  5598: 
1.184     rillig   5599:       + ${OPSYS} - output of "uname -s"
1.1       dsieger  5600: 
1.184     rillig   5601:       + ${LOWER_OPSYS} - lowercase common name (eg. "solaris")
1.1       dsieger  5602: 
1.184     rillig   5603:       + ${OS_VERSION} - "uname -r"
1.1       dsieger  5604: 
1.184     rillig   5605: For a list of values which are replaced by default, the output of make help
                   5606: topic=PLIST_SUBST as well as searching the pkgsrc/mk directory with grep for
                   5607: PLIST_SUBST should help.
1.1       dsieger  5608: 
1.184     rillig   5609: If you want to change other variables not listed above, you can add variables
                   5610: and their expansions to this variable in the following way, similar to
                   5611: MESSAGE_SUBST (see Section 12.5, "Optional files"):
1.1       dsieger  5612: 
1.184     rillig   5613: PLIST_SUBST+=   SOMEVAR="somevalue"
1.1       dsieger  5614: 
1.184     rillig   5615: This replaces all occurrences of "${SOMEVAR}" in the PLIST with "somevalue".
1.1       dsieger  5616: 
1.184     rillig   5617: The PLIST_VARS variable can be used to simplify the common case of
                   5618: conditionally including some PLIST entries. It can be done by adding
                   5619: PLIST_VARS+=foo and setting the corresponding PLIST.foo variable to yes if the
                   5620: entry should be included. This will substitute "${PLIST.foo}" in the PLIST with
                   5621: either """" or ""@comment "". For example, in Makefile:
1.1       dsieger  5622: 
1.184     rillig   5623: PLIST_VARS+=    foo
                   5624: .if condition
                   5625: PLIST.foo=      yes
                   5626: .else
1.1       dsieger  5627: 
1.184     rillig   5628: And then in PLIST:
1.1       dsieger  5629: 
1.184     rillig   5630: @comment $NetBSD $
                   5631: bin/bar
                   5632: man/man1/bar.1
                   5633: ${PLIST.foo}bin/foo
                   5634: ${PLIST.foo}man/man1/foo.1
                   5635: ${PLIST.foo}share/bar/foo.data
1.1       dsieger  5636: 
1.184     rillig   5637: An artificial space has been added between NetBSD and $, this is a workaround
                   5638: here to prevent CVS expanding to the filename of the guide. When adding the RCS
1.195     gutterid 5639: ID the space should be omitted.
1.1       dsieger  5640: 
1.184     rillig   5641: 19.5. Man page compression
1.1       dsieger  5642: 
1.184     rillig   5643: Man pages should be installed in compressed form if MANZ is set (in
                   5644: bsd.own.mk), and uncompressed otherwise. To handle this in the PLIST file, the
                   5645: suffix ".gz" is appended/removed automatically for man pages according to MANZ
                   5646: and MANCOMPRESSED being set or not, see above for details. This modification of
                   5647: the PLIST file is done on a copy of it, not PLIST itself.
1.100     leot     5648: 
1.184     rillig   5649: 19.6. Changing PLIST source with PLIST_SRC
1.100     leot     5650: 
1.184     rillig   5651: To use one or more files as source for the PLIST used in generating the binary
                   5652: package, set the variable PLIST_SRC to the names of that file(s). The files are
                   5653: later concatenated using cat(1), and the order of things is important. The
                   5654: default for PLIST_SRC is ${PKGDIR}/PLIST.
1.1       dsieger  5655: 
1.184     rillig   5656: 19.7. Platform-specific and differing PLISTs
1.1       dsieger  5657: 
1.184     rillig   5658: Some packages decide to install a different set of files based on the operating
                   5659: system being used. These differences can be automatically handled by using the
                   5660: following files:
1.1       dsieger  5661: 
1.184     rillig   5662:   * PLIST.common
1.1       dsieger  5663: 
1.184     rillig   5664:   * PLIST.${OPSYS}
1.1       dsieger  5665: 
1.184     rillig   5666:   * PLIST.${MACHINE_ARCH}
1.1       dsieger  5667: 
1.184     rillig   5668:   * PLIST.${OPSYS}-${MACHINE_ARCH}
1.1       dsieger  5669: 
1.184     rillig   5670:   * PLIST.common_end
1.1       dsieger  5671: 
1.184     rillig   5672: 19.8. Build-specific PLISTs
1.1       dsieger  5673: 
1.184     rillig   5674: Some packages decide to generate hard-to-guess file names during installation
                   5675: that are hard to wire down.
1.1       dsieger  5676: 
1.184     rillig   5677: In such cases, you can set the GENERATE_PLIST variable to shell code terminated
                   5678: (with a semicolon) that will output PLIST entries which will be appended to the
                   5679: PLIST
1.1       dsieger  5680: 
1.184     rillig   5681: You can find one example in editors/xemacs:
1.1       dsieger  5682: 
1.184     rillig   5683: GENERATE_PLIST+=        ${ECHO} bin/${DISTNAME}-`${WRKSRC}/src/xemacs -sd`.dmp ;
1.1       dsieger  5684: 
1.184     rillig   5685: which will append something like bin/xemacs-21.4.23-54e8ea71.dmp to the PLIST.
1.1       dsieger  5686: 
1.184     rillig   5687: 19.9. Sharing directories between packages
1.1       dsieger  5688: 
1.184     rillig   5689: A "shared directory" is a directory where multiple (and unrelated) packages
                   5690: install files. These directories were problematic because you had to add
                   5691: special tricks in the PLIST to conditionally remove them, or have some
                   5692: centralized package handle them.
1.106     tnn      5693: 
1.184     rillig   5694: In pkgsrc, it is now easy: Each package should create directories and install
                   5695: files as needed; pkg_delete will remove any directories left empty after
                   5696: uninstalling a package.
1.106     tnn      5697: 
1.184     rillig   5698: If a package needs an empty directory to work, create the directory during
                   5699: installation as usual, and also add an entry to the PLIST:
1.1       dsieger  5700: 
1.184     rillig   5701: @pkgdir path/to/empty/directory
1.1       dsieger  5702: 
1.184     rillig   5703: or take a look at MAKE_DIRS and OWN_DIRS.
1.1       dsieger  5704: 
1.184     rillig   5705: Chapter 20. The pkginstall framework
1.1       dsieger  5706: 
1.184     rillig   5707: Table of Contents
1.1       dsieger  5708: 
1.184     rillig   5709: 20.1. Files and directories outside the installation prefix
1.1       dsieger  5710: 
1.184     rillig   5711:     20.1.1. Directory manipulation
                   5712:     20.1.2. File manipulation
1.1       dsieger  5713: 
1.184     rillig   5714: 20.2. Configuration files
1.1       dsieger  5715: 
1.184     rillig   5716:     20.2.1. How PKG_SYSCONFDIR is set
                   5717:     20.2.2. Telling the software where configuration files are
                   5718:     20.2.3. Patching installations
                   5719:     20.2.4. Disabling handling of configuration files
1.1       dsieger  5720: 
1.184     rillig   5721: 20.3. System startup scripts
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: 20.4. System users and groups
                   5726: 20.5. System shells
1.1       dsieger  5727: 
1.184     rillig   5728:     20.5.1. Disabling shell registration
1.1       dsieger  5729: 
1.184     rillig   5730: 20.6. Fonts
1.1       dsieger  5731: 
1.184     rillig   5732:     20.6.1. Disabling automatic update of the fonts databases
1.1       dsieger  5733: 
1.184     rillig   5734: This chapter describes the framework known as pkginstall, whose key features
                   5735: are:
1.1       dsieger  5736: 
1.184     rillig   5737:   * Generic installation and manipulation of directories and files outside the
                   5738:     pkgsrc-handled tree, LOCALBASE.
1.1       dsieger  5739: 
1.184     rillig   5740:   * Automatic handling of configuration files during installation, provided
                   5741:     that packages are correctly designed.
1.1       dsieger  5742: 
1.184     rillig   5743:   * Generation and installation of system startup scripts.
1.1       dsieger  5744: 
1.184     rillig   5745:   * Registration of system users and groups.
1.1       dsieger  5746: 
1.184     rillig   5747:   * Registration of system shells.
1.1       dsieger  5748: 
1.184     rillig   5749:   * Automatic updating of fonts databases.
1.1       dsieger  5750: 
1.184     rillig   5751: The following sections inspect each of the above points in detail.
1.1       dsieger  5752: 
1.184     rillig   5753: You may be thinking that many of the things described here could be easily done
                   5754: with simple code in the package's post-installation target (post-install). This
                   5755: is incorrect, as the code in them is only executed when building from source.
                   5756: Machines using binary packages could not benefit from it at all (as the code
                   5757: itself could be unavailable). Therefore, the only way to achieve any of the
                   5758: items described above is by means of the installation scripts, which are
                   5759: automatically generated by pkginstall.
1.1       dsieger  5760: 
1.184     rillig   5761: 20.1. Files and directories outside the installation prefix
1.95      wiz      5762: 
1.184     rillig   5763: As you already know, the PLIST file holds a list of files and directories that
                   5764: belong to a package. The names used in it are relative to the installation
                   5765: prefix (${PREFIX}), which means that it cannot register files outside this
                   5766: directory (absolute path names are not allowed). Despite this restriction, some
                   5767: packages need to install files outside this location; e.g., under ${VARBASE} or
                   5768: ${PKG_SYSCONFDIR}. The only way to achieve this is to create such files during
                   5769: installation time by using installation scripts.
1.95      wiz      5770: 
1.184     rillig   5771: The generic installation scripts are shell scripts that can contain arbitrary
                   5772: code. The list of scripts to execute is taken from the INSTALL_FILE variable,
                   5773: which defaults to INSTALL. A similar variable exists for package removal
                   5774: (DEINSTALL_FILE, whose default is DEINSTALL). These scripts can run arbitrary
                   5775: commands, so they have the potential to create and manage files anywhere in the
                   5776: file system.
1.95      wiz      5777: 
1.184     rillig   5778: Using these general installation files is not recommended, but may be needed in
                   5779: some special cases. One reason for avoiding them is that the user has to trust
                   5780: the packager that there is no unwanted or simply erroneous code included in the
                   5781: installation script. Also, previously there were many similar scripts for the
                   5782: same functionality, and fixing a common error involved finding and changing all
                   5783: of them.
1.95      wiz      5784: 
1.184     rillig   5785: The pkginstall framework offers another, standardized way. It provides generic
                   5786: scripts to abstract the manipulation of such files and directories based on
                   5787: variables set in the package's Makefile. The rest of this section describes
                   5788: these variables.
1.1       dsieger  5789: 
1.184     rillig   5790: 20.1.1. Directory manipulation
1.1       dsieger  5791: 
1.184     rillig   5792: The following variables can be set to request the creation of directories
                   5793: anywhere in the file system:
1.1       dsieger  5794: 
1.184     rillig   5795:   * MAKE_DIRS and OWN_DIRS contain a list of directories that should be created
                   5796:     and should attempt to be destroyed by the installation scripts. The
                   5797:     difference between the two is that the latter prompts the administrator to
                   5798:     remove any directories that may be left after deinstallation (because they
                   5799:     were not empty), while the former does not. Example:
1.1       dsieger  5800: 
1.184     rillig   5801:     MAKE_DIRS+=             ${VARBASE}/foo/private
1.1       dsieger  5802: 
1.184     rillig   5803:   * MAKE_DIRS_PERMS and OWN_DIRS_PERMS contain a list of tuples describing
                   5804:     which directories should be created and should attempt to be destroyed by
                   5805:     the installation scripts. Each tuple holds the following values, separated
                   5806:     by spaces: the directory name, its owner, its group and its numerical mode.
                   5807:     For example:
1.1       dsieger  5808: 
1.184     rillig   5809:     MAKE_DIRS_PERMS+=       ${VARBASE}/foo/private \
                   5810:                             ${REAL_ROOT_USER} ${REAL_ROOT_GROUP} 0700
1.1       dsieger  5811: 
1.184     rillig   5812:     The difference between the two is exactly the same as their non-PERMS
                   5813:     counterparts.
1.1       dsieger  5814: 
1.184     rillig   5815: 20.1.2. File manipulation
1.1       dsieger  5816: 
1.184     rillig   5817: Creating non-empty files outside the installation prefix is tricky because the
                   5818: PLIST forces all files to be inside it. To overcome this problem, the only
                   5819: solution is to extract the file in the known place (i.e., inside the
                   5820: installation prefix) and copy it to the appropriate location during
                   5821: installation (done by the installation scripts generated by pkginstall). We
                   5822: will call the former the master file in the following paragraphs, which
                   5823: describe the variables that can be used to automatically and consistently
                   5824: handle files outside the installation prefix:
1.1       dsieger  5825: 
1.184     rillig   5826:   * CONF_FILES and REQD_FILES are pairs of master and target files. During
                   5827:     installation time, the master file is copied to the target one if and only
                   5828:     if the latter does not exist. Upon deinstallation, the target file is
                   5829:     removed provided that it was not modified by the installation.
1.1       dsieger  5830: 
1.184     rillig   5831:     The difference between the two is that the latter prompts the administrator
                   5832:     to remove any files that may be left after deinstallation (because they
                   5833:     were not empty), while the former does not.
1.1       dsieger  5834: 
1.184     rillig   5835:   * CONF_FILES_PERMS and REQD_FILES_PERMS contain tuples describing master
                   5836:     files as well as their target locations. For each of them, it also
                   5837:     specifies their owner, their group and their numeric permissions, in this
                   5838:     order. For example:
1.1       dsieger  5839: 
1.184     rillig   5840:     REQD_FILES_PERMS+=      ${PREFIX}/share/somefile ${VARBASE}/somefile \
                   5841:                             ${REAL_ROOT_USER} ${REAL_ROOT_GROUP} 0700
1.1       dsieger  5842: 
1.184     rillig   5843:     The difference between the two is exactly the same as their non-PERMS
                   5844:     counterparts.
1.1       dsieger  5845: 
1.184     rillig   5846: 20.2. Configuration files
1.1       dsieger  5847: 
1.184     rillig   5848: Configuration files are special in the sense that they are installed in their
                   5849: own specific directory, PKG_SYSCONFDIR, and need special treatment during
                   5850: installation (most of which is automated by pkginstall). The main concept you
                   5851: must bear in mind is that files marked as configuration files are automatically
                   5852: copied to the right place (somewhere inside PKG_SYSCONFDIR) during installation
                   5853: if and only if they didn't exist before. Similarly, they will not be removed if
                   5854: they have local modifications. This ensures that administrators never lose any
                   5855: custom changes they may have made.
1.1       dsieger  5856: 
1.184     rillig   5857: 20.2.1. How PKG_SYSCONFDIR is set
1.1       dsieger  5858: 
1.184     rillig   5859: As said before, the PKG_SYSCONFDIR variable specifies where configuration files
                   5860: shall be installed. Its contents are set based upon the following variables:
1.1       dsieger  5861: 
1.184     rillig   5862:   * PKG_SYSCONFBASE: The configuration's root directory. Defaults to ${PREFIX}/
                   5863:     etc although it may be overridden by the user to point to his preferred
                   5864:     location (e.g., /etc, /etc/pkg, etc.). Packages must not use it directly.
1.1       dsieger  5865: 
1.184     rillig   5866:   * PKG_SYSCONFSUBDIR: A subdirectory of PKG_SYSCONFBASE under which the
                   5867:     configuration files for the package being built shall be installed. The
                   5868:     definition of this variable only makes sense in the package's Makefile
                   5869:     (i.e., it is not user-customizable).
1.1       dsieger  5870: 
1.184     rillig   5871:     As an example, consider the Apache package, www/apache24, which places its
                   5872:     configuration files under the httpd/ subdirectory of PKG_SYSCONFBASE. This
                   5873:     should be set in the package Makefile.
1.1       dsieger  5874: 
1.184     rillig   5875:   * PKG_SYSCONFVAR: Specifies the name of the variable that holds this
                   5876:     package's configuration directory (if different from PKG_SYSCONFBASE). It
                   5877:     defaults to PKGBASE's value, and is always prefixed with PKG_SYSCONFDIR.
1.1       dsieger  5878: 
1.184     rillig   5879:   * PKG_SYSCONFDIR.${PKG_SYSCONFVAR}: Holds the directory where the
                   5880:     configuration files for the package identified by PKG_SYSCONFVAR's shall be
                   5881:     placed.
1.1       dsieger  5882: 
1.184     rillig   5883: Based on the above variables, pkginstall determines the value of
                   5884: PKG_SYSCONFDIR, which is the only variable that can be used within a package to
                   5885: refer to its configuration directory. The algorithm used to set its value is
                   5886: basically the following:
1.1       dsieger  5887: 
1.184     rillig   5888:  1. If PKG_SYSCONFDIR.${PKG_SYSCONFVAR} is set, its value is used.
1.1       dsieger  5889: 
1.184     rillig   5890:  2. If the previous variable is not defined but PKG_SYSCONFSUBDIR is set in the
                   5891:     package's Makefile, the resulting value is ${PKG_SYSCONFBASE}/$
                   5892:     {PKG_SYSCONFSUBDIR}.
1.1       dsieger  5893: 
1.184     rillig   5894:  3. Otherwise, it is set to ${PKG_SYSCONFBASE}.
1.1       dsieger  5895: 
1.184     rillig   5896: It is worth mentioning that ${PKG_SYSCONFDIR} is automatically added to
                   5897: OWN_DIRS. See Section 20.1.1, "Directory manipulation" what this means. This
                   5898: does not apply to subdirectories of ${PKG_SYSCONFDIR}, they still have to be
                   5899: created with OWN_DIRS or MAKE_DIRS.
1.1       dsieger  5900: 
1.184     rillig   5901: 20.2.2. Telling the software where configuration files are
1.1       dsieger  5902: 
1.184     rillig   5903: Given that pkgsrc (and users!) expect configuration files to be in a known
                   5904: place, you need to teach each package where it shall install its files. In some
                   5905: cases you will have to patch the package Makefiles to achieve it. If you are
                   5906: lucky, though, it may be as easy as passing an extra flag to the configuration
                   5907: script; this is the case of GNU Autoconf- generated files:
1.1       dsieger  5908: 
1.184     rillig   5909: CONFIGURE_ARGS+= --sysconfdir=${PKG_SYSCONFDIR}
1.1       dsieger  5910: 
1.184     rillig   5911: Note that this specifies where the package has to look for its configuration
                   5912: files, not where they will be originally installed (although the difference is
                   5913: never explicit, unfortunately).
1.1       dsieger  5914: 
1.184     rillig   5915: 20.2.3. Patching installations
1.1       dsieger  5916: 
1.184     rillig   5917: As said before, pkginstall automatically handles configuration files. This
                   5918: means that the packages themselves must not touch the contents of $
                   5919: {PKG_SYSCONFDIR} directly. Bad news is that many software installation scripts
                   5920: will, out of the box, mess with the contents of that directory. So what is the
                   5921: correct procedure to fix this issue?
1.1       dsieger  5922: 
1.184     rillig   5923: You must teach the package (usually by manually patching it) to install any
                   5924: configuration files under the examples hierarchy, share/examples/${PKGBASE}/.
                   5925: This way, the PLIST registers them and the administrator always has the
                   5926: original copies available.
1.1       dsieger  5927: 
1.184     rillig   5928: Once the required configuration files are in place (i.e., under the examples
                   5929: hierarchy), the pkginstall framework can use them as master copies during the
                   5930: package installation to update what is in ${PKG_SYSCONFDIR}. To achieve this,
                   5931: the variables CONF_FILES and CONF_FILES_PERMS are used. Check out
                   5932: Section 20.1.2, "File manipulation" for information about their syntax and
                   5933: their purpose. Here is an example, taken from the mail/mutt package:
1.1       dsieger  5934: 
1.184     rillig   5935: EGDIR=        ${PREFIX}/share/doc/mutt/samples
                   5936: CONF_FILES=   ${EGDIR}/Muttrc ${PKG_SYSCONFDIR}/Muttrc
1.1       dsieger  5937: 
1.184     rillig   5938: Note that the EGDIR variable is specific to that package and has no meaning
                   5939: outside it.
1.1       dsieger  5940: 
1.184     rillig   5941: 20.2.4. Disabling handling of configuration files
1.1       dsieger  5942: 
1.184     rillig   5943: The automatic copying of config files can be toggled by setting the environment
                   5944: variable PKG_CONFIG prior to package installation.
1.1       dsieger  5945: 
1.184     rillig   5946: 20.3. System startup scripts
1.1       dsieger  5947: 
1.184     rillig   5948: System startup scripts are special files because they must be installed in a
                   5949: place known by the underlying OS, usually outside the installation prefix.
                   5950: Therefore, the same rules described in Section 20.1, "Files and directories
                   5951: outside the installation prefix" apply, and the same solutions can be used.
                   5952: However, pkginstall provides a special mechanism to handle these files.
1.1       dsieger  5953: 
1.184     rillig   5954: In order to provide system startup scripts, the package has to:
1.1       dsieger  5955: 
1.184     rillig   5956:  1. Store the script inside ${FILESDIR}, with the .sh suffix appended.
1.223     nia      5957:     Considering the print/cups-base package as an example, it has a cupsd.sh in
                   5958:     its files directory.
1.95      wiz      5959: 
1.184     rillig   5960:  2. Tell pkginstall to handle it, appending the name of the script, without its
                   5961:     extension, to the RCD_SCRIPTS variable. Continuing the previous example:
1.95      wiz      5962: 
1.184     rillig   5963:     RCD_SCRIPTS+=   cupsd
1.95      wiz      5964: 
1.184     rillig   5965: Once this is done, pkginstall will do the following steps for each script in an
                   5966: automated fashion:
1.95      wiz      5967: 
1.184     rillig   5968:  1. Process the file found in the files directory applying all the
                   5969:     substitutions described in the FILES_SUBST variable.
1.1       dsieger  5970: 
1.184     rillig   5971:  2. Copy the script from the files directory to the examples hierarchy, $
                   5972:     {PREFIX}/share/examples/rc.d/. Note that this master file must be
                   5973:     explicitly registered in the PLIST.
1.1       dsieger  5974: 
1.184     rillig   5975:  3. Add code to the installation scripts to copy the startup script from the
                   5976:     examples hierarchy into the system-wide startup scripts directory.
1.1       dsieger  5977: 
1.184     rillig   5978: 20.3.1. Disabling handling of system startup scripts
1.1       dsieger  5979: 
1.184     rillig   5980: The automatic copying of config files can be toggled by setting the environment
                   5981: variable PKG_RCD_SCRIPTS prior to package installation. Note that the scripts
                   5982: will be always copied inside the examples hierarchy, ${PREFIX}/share/examples/
                   5983: rc.d/, no matter what the value of this variable is.
1.1       dsieger  5984: 
1.184     rillig   5985: 20.4. System users and groups
1.1       dsieger  5986: 
1.184     rillig   5987: If a package needs to create special users and/or groups during installation,
                   5988: it can do so by using the pkginstall framework.
1.1       dsieger  5989: 
1.184     rillig   5990: Users can be created by adding entries to the PKG_USERS variable. Each entry
                   5991: has the following syntax:
1.1       dsieger  5992: 
1.184     rillig   5993: user:group
1.1       dsieger  5994: 
1.184     rillig   5995: Further specification of user details may be done by setting per-user
                   5996: variables. PKG_UID.user is the numeric UID for the user. PKG_GECOS.user is the
                   5997: user's description or comment. PKG_HOME.user is the user's home directory, and
                   5998: defaults to /nonexistent if not specified. PKG_SHELL.user is the user's shell,
                   5999: and defaults to /sbin/nologin if not specified.
1.1       dsieger  6000: 
1.184     rillig   6001: Similarly, groups can be created by adding entries to the PKG_GROUPS variable,
                   6002: whose syntax is:
1.1       dsieger  6003: 
1.184     rillig   6004: group
1.1       dsieger  6005: 
1.184     rillig   6006: The numeric GID of the group may be set by defining PKG_GID.group.
1.1       dsieger  6007: 
1.184     rillig   6008: If a package needs to create the users and groups at an earlier stage, then it
                   6009: can set USERGROUP_PHASE to either configure,build, or pre-install to indicate
                   6010: the phase before which the users and groups are created. In this case, the
                   6011: numeric UIDs and GIDs of the created users and groups are automatically
                   6012: hardcoded into the final installation scripts.
1.1       dsieger  6013: 
1.184     rillig   6014: 20.5. System shells
1.1       dsieger  6015: 
1.184     rillig   6016: Packages that install system shells should register them in the shell database,
                   6017: /etc/shells, to make things easier to the administrator. This must be done from
                   6018: the installation scripts to keep binary packages working on any system.
                   6019: pkginstall provides an easy way to accomplish this task.
1.1       dsieger  6020: 
1.184     rillig   6021: When a package provides a shell interpreter, it has to set the PKG_SHELL
                   6022: variable to its absolute file name. This will add some hooks to the
                   6023: installation scripts to handle it. Consider the following example, taken from
                   6024: shells/zsh:
1.1       dsieger  6025: 
1.184     rillig   6026: PKG_SHELL=      ${PREFIX}/bin/zsh
1.1       dsieger  6027: 
1.184     rillig   6028: 20.5.1. Disabling shell registration
1.1       dsieger  6029: 
1.184     rillig   6030: The automatic registration of shell interpreters can be disabled by the
                   6031: administrator by setting the PKG_REGISTER_SHELLS environment variable to NO.
1.1       dsieger  6032: 
1.184     rillig   6033: 20.6. Fonts
1.1       dsieger  6034: 
1.184     rillig   6035: Packages that install X11 fonts should update the database files that index the
                   6036: fonts within each fonts directory. This can easily be accomplished within the
                   6037: pkginstall framework.
1.1       dsieger  6038: 
1.184     rillig   6039: When a package installs X11 fonts, it must list the directories in which fonts
                   6040: are installed in the FONTS_DIRS.type variables, where type can be one of "ttf",
                   6041: "type1" or "x11". This will add hooks to the installation scripts to run the
                   6042: appropriate commands to update the fonts database files within each of those
                   6043: directories. For convenience, if the directory path is relative, it is taken to
                   6044: be relative to the package's installation prefix. Consider the following
                   6045: example, taken from fonts/dbz-ttf:
1.1       dsieger  6046: 
1.184     rillig   6047: FONTS_DIRS.ttf= ${PREFIX}/share/fonts/X11/TTF
1.1       dsieger  6048: 
1.184     rillig   6049: 20.6.1. Disabling automatic update of the fonts databases
1.1       dsieger  6050: 
1.184     rillig   6051: The automatic update of fonts databases can be disabled by the administrator by
                   6052: setting the PKG_UPDATE_FONTS_DB environment variable to NO.
1.1       dsieger  6053: 
1.154     rillig   6054: Chapter 21. Making your package work
1.1       dsieger  6055: 
                   6056: Table of Contents
                   6057: 
1.154     rillig   6058: 21.1. General operation
1.1       dsieger  6059: 
1.154     rillig   6060:     21.1.1. How to pull in user-settable variables from mk.conf
                   6061:     21.1.2. User interaction
                   6062:     21.1.3. Handling licenses
                   6063:     21.1.4. Restricted packages
                   6064:     21.1.5. Handling dependencies
                   6065:     21.1.6. Handling conflicts with other packages
                   6066:     21.1.7. Packages that cannot or should not be built
                   6067:     21.1.8. Packages which should not be deleted, once installed
                   6068:     21.1.9. Handling packages with security problems
                   6069:     21.1.10. How to handle incrementing versions when fixing an existing
1.1       dsieger  6070:         package
1.154     rillig   6071:     21.1.11. Substituting variable text in the package files (the SUBST
1.1       dsieger  6072:         framework)
                   6073: 
1.154     rillig   6074: 21.2. The fetch phase
1.1       dsieger  6075: 
1.154     rillig   6076:     21.2.1. Packages whose distfiles aren't available for plain downloading
                   6077:     21.2.2. How to handle modified distfiles with the 'old' name
                   6078:     21.2.3. Packages hosted on github.com
                   6079: 
                   6080: 21.3. The configure phase
                   6081: 
                   6082:     21.3.1. Shared libraries - libtool
                   6083:     21.3.2. Using libtool on GNU packages that already support libtool
                   6084:     21.3.3. GNU Autoconf/Automake
1.223     nia      6085:     21.3.4. Meson / ninja
1.154     rillig   6086: 
                   6087: 21.4. Programming languages
                   6088: 
                   6089:     21.4.1. C, C++, and Fortran
                   6090:     21.4.2. Java
1.205     wiz      6091:     21.4.3. Go
1.223     nia      6092:     21.4.4. Rust
                   6093:     21.4.5. Packages containing Perl scripts
                   6094:     21.4.6. Packages containing shell scripts
                   6095:     21.4.7. Other programming languages
1.154     rillig   6096: 
                   6097: 21.5. The build phase
                   6098: 
                   6099:     21.5.1. Compiling C and C++ code conditionally
                   6100:     21.5.2. How to handle compiler bugs
1.172     rillig   6101:     21.5.3. No such file or directory
                   6102:     21.5.4. Undefined reference to "..."
                   6103:     21.5.5. Running out of memory
1.154     rillig   6104: 
                   6105: 21.6. The install phase
                   6106: 
                   6107:     21.6.1. Creating needed directories
                   6108:     21.6.2. Where to install documentation
                   6109:     21.6.3. Installing highscore files
                   6110:     21.6.4. Adding DESTDIR support to packages
                   6111:     21.6.5. Packages with hardcoded paths to other interpreters
1.203     nia      6112:     21.6.6. Packages installing Perl modules
1.154     rillig   6113:     21.6.7. Packages installing info files
                   6114:     21.6.8. Packages installing man pages
1.203     nia      6115:     21.6.9. Packages installing X11 fonts
                   6116:     21.6.10. Packages installing SGML or XML data
                   6117:     21.6.11. Packages installing extensions to the MIME database
                   6118:     21.6.12. Packages using intltool
                   6119:     21.6.13. Packages installing startup scripts
                   6120:     21.6.14. Packages installing TeX modules
                   6121:     21.6.15. Packages supporting running binaries in emulation
                   6122:     21.6.16. Packages installing hicolor icons
                   6123:     21.6.17. Packages installing desktop files
1.1       dsieger  6124: 
1.154     rillig   6125: 21.7. Marking packages as having problems
1.1       dsieger  6126: 
1.154     rillig   6127: 21.1. General operation
1.1       dsieger  6128: 
                   6129: One appealing feature of pkgsrc is that it runs on many different platforms. As
                   6130: a result, it is important to ensure, where possible, that packages in pkgsrc
                   6131: are portable. This chapter mentions some particular details you should pay
                   6132: attention to while working on pkgsrc.
                   6133: 
1.154     rillig   6134: 21.1.1. How to pull in user-settable variables from mk.conf
1.1       dsieger  6135: 
                   6136: The pkgsrc user can configure pkgsrc by overriding several variables in the
1.4       rillig   6137: file pointed to by MAKECONF, which is mk.conf by default. When you want to use
                   6138: those variables in the preprocessor directives of make(1) (for example .if or
                   6139: .for), you need to include the file ../../mk/bsd.prefs.mk before, which in turn
                   6140: loads the user preferences.
1.1       dsieger  6141: 
                   6142: But note that some variables may not be completely defined after ../../mk/
                   6143: bsd.prefs.mk has been included, as they may contain references to variables
1.108     rillig   6144: that are not yet defined. In shell commands (the lines in Makefile that are
                   6145: indented with a tab) this is no problem, since variables are only expanded when
                   6146: they are used. But in the preprocessor directives mentioned above and in
                   6147: dependency lines (of the form target: dependencies) the variables are expanded
                   6148: at load time.
1.1       dsieger  6149: 
                   6150: Note
                   6151: 
1.108     rillig   6152: To check whether a variable can be used at load time, run pkglint -Wall on your
                   6153: package.
1.1       dsieger  6154: 
1.154     rillig   6155: 21.1.2. User interaction
1.1       dsieger  6156: 
                   6157: Occasionally, packages require interaction from the user, and this can be in a
                   6158: number of ways:
                   6159: 
                   6160:   * When fetching the distfiles, some packages require user interaction such as
                   6161:     entering username/password or accepting a license on a web page.
                   6162: 
                   6163:   * When extracting the distfiles, some packages may ask for passwords.
                   6164: 
                   6165:   * help to configure the package before it is built
                   6166: 
                   6167:   * help during the build process
                   6168: 
                   6169:   * help during the installation of a package
                   6170: 
1.108     rillig   6171: A package can set the INTERACTIVE_STAGE variable to define which stages need
                   6172: interaction. This should be done in the package's Makefile, e.g.:
1.1       dsieger  6173: 
                   6174: INTERACTIVE_STAGE=      configure install
                   6175: 
                   6176: The user can then decide to skip this package by setting the BATCH variable.
1.108     rillig   6177: Packages that require interaction are also excluded from bulk builds.
1.1       dsieger  6178: 
1.154     rillig   6179: 21.1.3. Handling licenses
1.1       dsieger  6180: 
                   6181: Authors of software can choose the licence under which software can be copied.
1.111     sevan    6182: The Free Software Foundation has declared some licenses "Free", and the Open
                   6183: Source Initiative has a definition of "Open Source".
                   6184: 
                   6185: By default, pkgsrc allows packages with Free or Open Source licenses to be
                   6186: built. To allow packages with other licenses to be built as well, the pkgsrc
                   6187: user needs to add these licenses to the ACCEPTABLE_LICENSES variable in mk.conf
                   6188: . Note that this variable only affects which packages may be built, while the
                   6189: license terms often also restrict the actual use of the package and its
                   6190: redistribution.
1.1       dsieger  6191: 
                   6192: One might want to only install packages with a BSD license, or the GPL, and not
1.20      jnemeth  6193: the other. The free licenses are added to the default ACCEPTABLE_LICENSES
1.111     sevan    6194: variable. The pkgsrc user can override the default by setting the
                   6195: ACCEPTABLE_LICENSES variable with "=" instead of "+=". The licenses accepted by
                   6196: default are defined in the DEFAULT_ACCEPTABLE_LICENSES variable in the file
                   6197: pkgsrc/mk/license.mk.
1.1       dsieger  6198: 
                   6199: The license tag mechanism is intended to address copyright-related issues
                   6200: surrounding building, installing and using a package, and not to address
1.20      jnemeth  6201: redistribution issues (see RESTRICTED and NO_SRC_ON_FTP, etc.). Packages with
                   6202: redistribution restrictions should set these tags.
1.1       dsieger  6203: 
                   6204: Denoting that a package may be copied according to a particular license is done
                   6205: by placing the license in pkgsrc/licenses and setting the LICENSE variable to a
                   6206: string identifying the license, e.g. in graphics/xv:
                   6207: 
                   6208: LICENSE=        xv-license
                   6209: 
                   6210: When trying to build, the user will get a notice that the package is covered by
                   6211: a license which has not been placed in the ACCEPTABLE_LICENSES variable:
                   6212: 
                   6213: % make
                   6214: ===> xv-3.10anb9 has an unacceptable license: xv-license.
                   6215: ===>     To view the license, enter "/usr/bin/make show-license".
                   6216: ===>     To indicate acceptance, add this line to your /etc/mk.conf:
                   6217: ===>     ACCEPTABLE_LICENSES+=xv-license
                   6218: *** Error code 1
                   6219: 
                   6220: The license can be viewed with make show-license, and if the user so chooses,
1.4       rillig   6221: the line printed above can be added to mk.conf to convey to pkgsrc that it
1.1       dsieger  6222: should not in the future fail because of that license:
                   6223: 
                   6224: ACCEPTABLE_LICENSES+=xv-license
                   6225: 
1.111     sevan    6226: The use of LICENSE=shareware, LICENSE=no-commercial-use, and similar language
                   6227: is deprecated because it does not crisply refer to a particular license text.
                   6228: Another problem with such usage is that it does not enable a user to tell
                   6229: pkgsrc to proceed for a single package without also telling pkgsrc to proceed
                   6230: for all packages with that tag.
                   6231: 
1.154     rillig   6232: 21.1.3.1. Adding a package with a new license
1.1       dsieger  6233: 
1.49      rodent   6234: When adding a package with a new license, the following steps are required:
                   6235: 
1.111     sevan    6236:  1. Check whether the license qualifies as Free or Open Source by referencing
                   6237:     Various Licenses and Comments about Them and Licenses by Name | Open Source
                   6238:     Initiative. If this is the case, the filename in pkgsrc/licenses/ does not
                   6239:     need the -license suffix, and the license name should be added to:
1.49      rodent   6240: 
                   6241:       + DEFAULT_ACCEPTABLE_LICENSES in pkgsrc/mk/license.mk
                   6242: 
                   6243:       + default_acceptable_licenses in pkgsrc/pkgtools/pkg_install/files/lib/
                   6244:         license.c
                   6245: 
                   6246:  2. The license text should be added to pkgsrc/licenses for displaying. A list
                   6247:     of known licenses can be seen in this directory.
1.1       dsieger  6248: 
1.154     rillig   6249: 21.1.3.2. Change to the license
1.1       dsieger  6250: 
1.111     sevan    6251: When the license changes (in a way other than formatting), make sure that the
                   6252: new license has a different name (e.g., append the version number if it exists,
                   6253: or the date). Just because a user told pkgsrc to build programs under a
                   6254: previous version of a license does not mean that pkgsrc should build programs
                   6255: under the new licenses. The higher-level point is that pkgsrc does not evaluate
                   6256: licenses for reasonableness; the only test is a mechanistic test of whether a
                   6257: particular text has been approved by either of two bodies (FSF or OSI).
1.1       dsieger  6258: 
1.154     rillig   6259: 21.1.4. Restricted packages
1.1       dsieger  6260: 
1.111     sevan    6261: Some licenses restrict how software may be re-distributed. By declaring the
                   6262: restrictions, package tools can automatically refrain from e.g. placing binary
                   6263: packages on FTP sites.
                   6264: 
                   6265: There are four possible restrictions, which are the cross product of sources
                   6266: (distfiles) and binaries not being placed on FTP sites and CD-ROMs. Because
                   6267: this is rarely the exact language in any license, and because non-Free licenses
                   6268: tend to be different from each other, pkgsrc adopts a definition of FTP and
                   6269: CD-ROM. "FTP" means making the source or binary file available over the
                   6270: Internet at no charge. "CD-ROM" means making the source or binary available on
                   6271: some kind of media, together with other source and binary packages, which is
                   6272: sold for a distribution charge.
1.1       dsieger  6273: 
                   6274: In order to encode these restrictions, the package system defines five make
                   6275: variables that can be set to note these restrictions:
                   6276: 
                   6277:   * RESTRICTED
                   6278: 
                   6279:     This variable should be set whenever a restriction exists (regardless of
                   6280:     its kind). Set this variable to a string containing the reason for the
                   6281:     restriction. It should be understood that those wanting to understand the
                   6282:     restriction will have to read the license, and perhaps seek advice of
                   6283:     counsel.
                   6284: 
                   6285:   * NO_BIN_ON_CDROM
                   6286: 
                   6287:     Binaries may not be placed on CD-ROM containing other binary packages, for
                   6288:     which a distribution charge may be made. In this case, set this variable to
                   6289:     ${RESTRICTED}.
                   6290: 
                   6291:   * NO_BIN_ON_FTP
                   6292: 
                   6293:     Binaries may not made available on the Internet without charge. In this
                   6294:     case, set this variable to ${RESTRICTED}. If this variable is set, binary
                   6295:     packages will not be included on ftp.NetBSD.org.
                   6296: 
                   6297:   * NO_SRC_ON_CDROM
                   6298: 
                   6299:     Distfiles may not be placed on CD-ROM, together with other distfiles, for
                   6300:     which a fee may be charged. In this case, set this variable to $
                   6301:     {RESTRICTED}.
                   6302: 
                   6303:   * NO_SRC_ON_FTP
                   6304: 
                   6305:     Distfiles may not made available via FTP at no charge. In this case, set
                   6306:     this variable to ${RESTRICTED}. If this variable is set, the distfile(s)
                   6307:     will not be mirrored on ftp.NetBSD.org.
                   6308: 
1.111     sevan    6309: Please note that packages will be removed from pkgsrc when the distfiles are
1.33      wiz      6310: not distributable and cannot be obtained for a period of one full quarter
1.111     sevan    6311: branch. Packages with manual/interactive fetch must have a maintainer and it is
                   6312: his/her responsibility to ensure this.
1.33      wiz      6313: 
1.154     rillig   6314: 21.1.5. Handling dependencies
1.1       dsieger  6315: 
1.175     gutterid 6316: Your package may depend on some other package being present, and there are
                   6317: various ways of expressing this dependency. pkgsrc supports the DEPENDS,
                   6318: BUILD_DEPENDS, TOOL_DEPENDS, and TEST_DEPENDS definitions, the USE_TOOLS
                   6319: definition, as well as dependencies via buildlink3.mk, which is the preferred
                   6320: way to handle dependencies, and which uses the variables named above. See
1.184     rillig   6321: Chapter 18, Buildlink methodology for more information.
1.175     gutterid 6322: 
                   6323: The basic difference is that the DEPENDS definition registers that
                   6324: pre-requisite in the binary package so it will be pulled in when the binary
                   6325: package is later installed, whilst the BUILD_DEPENDS, TOOL_DEPENDS, and
                   6326: TEST_DEPENDS definitions do not, marking a dependency that is only needed for
1.184     rillig   6327: building or testing the resulting package. See also Chapter 14, Creating a new
1.175     gutterid 6328: pkgsrc package from scratch for more information.
                   6329: 
                   6330: This means that if you only need a package present whilst you are building or
                   6331: testing, it should be noted as a TOOL_DEPENDS, BUILD_DEPENDS, or TEST_DEPENDS.
                   6332: When cross-compiling, TOOL_DEPENDS are native packages, i.e. packages for the
                   6333: architecture where the package is built; BUILD_DEPENDS are target packages,
                   6334: i.e., packages for the architecture for which the package is built.
1.1       dsieger  6335: 
1.175     gutterid 6336: The format for a DEPENDS, BUILD_DEPENDS, TOOL_DEPENDS, and TEST_DEPENDS
                   6337: definition is:
1.1       dsieger  6338: 
                   6339: <pre-req-package-name>:../../<category>/<pre-req-package>
                   6340: 
                   6341: Please note that the "pre-req-package-name" may include any of the wildcard
                   6342: version numbers recognized by pkg_info(1).
                   6343: 
1.55      wiz      6344:  1. If your package needs another package's binaries or libraries to build and
1.1       dsieger  6345:     run, and if that package has a buildlink3.mk file available, use it:
                   6346: 
                   6347:     .include "../../graphics/jpeg/buildlink3.mk"
                   6348: 
1.55      wiz      6349:  2. If your package needs another package's binaries or libraries only for
                   6350:     building, and if that package has a buildlink3.mk file available, use it:
                   6351: 
                   6352:     .include "../../graphics/jpeg/buildlink3.mk"
                   6353: 
                   6354:     but set BUILDLINK_DEPMETHOD.jpeg?=build to make it a build dependency only.
                   6355:     This case is rather rare.
                   6356: 
                   6357:  3. If your package needs binaries from another package to build, use the
1.156     leot     6358:     TOOL_DEPENDS definition:
                   6359: 
                   6360:     TOOL_DEPENDS+= itstool-[0-9]*:../../textproc/itstool
1.1       dsieger  6361: 
1.156     leot     6362:  4. If your package needs static libraries to link against, header files to
                   6363:     include, etc. from another package to build, use the BUILD_DEPENDS
                   6364:     definition.
1.1       dsieger  6365: 
1.156     leot     6366:  5. If your package needs a library with which to link and there is no
1.26      spz      6367:     buildlink3.mk file available, create one. Using DEPENDS won't be sufficient
                   6368:     because the include files and libraries will be hidden from the compiler.
1.1       dsieger  6369: 
1.156     leot     6370:  6. If your package needs some executable to be able to run correctly and if
1.26      spz      6371:     there's no buildlink3.mk file, this is specified using the DEPENDS
                   6372:     variable. The print/lyx package needs to be able to execute the latex
1.129     wiz      6373:     binary from the tex-latex-bin package when it runs, and that is specified:
1.1       dsieger  6374: 
1.129     wiz      6375:     DEPENDS+=        tex-latex-bin-[0-9]*:../../print/tex-latex-bin
1.1       dsieger  6376: 
1.175     gutterid 6377:  7. If your package includes a test suite that has extra dependencies only
                   6378:     required for this purpose (frequently this can be run as a "make test"
                   6379:     target), use the TEST_DEPENDS variable.
                   6380: 
                   6381:  8. You can use wildcards in package dependencies. Note that such wildcard
1.26      spz      6382:     dependencies are retained when creating binary packages. The dependency is
                   6383:     checked when installing the binary package and any package which matches
                   6384:     the pattern will be used. Wildcard dependencies should be used with care.
1.1       dsieger  6385: 
                   6386:     The "-[0-9]*" should be used instead of "-*" to avoid potentially ambiguous
                   6387:     matches such as "tk-postgresql" matching a "tk-*" DEPENDS.
                   6388: 
                   6389:     Wildcards can also be used to specify that a package will only build
                   6390:     against a certain minimum version of a pre-requisite:
                   6391: 
1.26      spz      6392:     DEPENDS+=       ImageMagick>=6.0:../../graphics/ImageMagick
1.1       dsieger  6393: 
1.26      spz      6394:     This means that the package will build using version 6.0 of ImageMagick or
                   6395:     newer. Such a dependency may be warranted if, for example, the command line
                   6396:     options of an executable have changed.
                   6397: 
1.183     wiz      6398:     If you need to depend on minimum versions of libraries, set
                   6399:     BUILDLINK_API_DEPENDS.pkg to the appropriate pattern before including its
                   6400:     buildlink3.mk file, e.g.
                   6401: 
                   6402:     BUILDLINK_API_DEPENDS.jpeg+=    jpeg>=9.0
                   6403:     .include "../../graphics/jpeg/buildlink3.mk"
1.1       dsieger  6404: 
                   6405:     For security fixes, please update the package vulnerabilities file. See
1.154     rillig   6406:     Section 21.1.9, "Handling packages with security problems" for more
1.1       dsieger  6407:     information.
                   6408: 
                   6409: If your package needs files from another package to build, add the relevant
                   6410: distribution files to DISTFILES, so they will be extracted automatically. See
                   6411: the print/ghostscript package for an example. (It relies on the jpeg sources
                   6412: being present in source form during the build.)
                   6413: 
1.154     rillig   6414: 21.1.6. Handling conflicts with other packages
1.1       dsieger  6415: 
1.226     gutterid 6416: Your package may conflict with other packages users might already have
                   6417: installed on their system, e.g., if your package installs the same set of files
1.227     wiz      6418: as another package in the pkgsrc tree.
1.1       dsieger  6419: 
1.142     leot     6420: For example, x11/libXaw3d and x11/Xaw-Xpm install the same shared library, thus
                   6421: you set in pkgsrc/x11/libXaw3d/Makefile:
1.1       dsieger  6422: 
1.142     leot     6423: CONFLICTS=      Xaw-Xpm-[0-9]*
1.1       dsieger  6424: 
                   6425: 
1.142     leot     6426: and in pkgsrc/x11/Xaw-Xpm/Makefile:
1.1       dsieger  6427: 
1.142     leot     6428: CONFLICTS=      libXaw3d-[0-9]*
1.1       dsieger  6429: 
1.142     leot     6430: 
                   6431: pkg_add(1) is able to detect attempts to install packages that conflict with
                   6432: existing packages and abort. However, in many situations this is too late in
                   6433: the process. Binary package managers will not know about the conflict until
                   6434: they attempt to install the package after already downloading it and all its
                   6435: dependencies. Users may also waste time building a package and its dependencies
                   6436: only to find out at the end that it conflicts with another package they have
                   6437: installed.
                   6438: 
                   6439: To avoid these issues CONFLICTS entries should be added in all cases where it
                   6440: is known that packages conflict with each other. These CONFLICTS entries are
                   6441: exported in pkg_summary(5) files and consumed by binary package managers to
                   6442: inform users that packages cannot be installed onto the target system.
1.1       dsieger  6443: 
1.154     rillig   6444: 21.1.7. Packages that cannot or should not be built
1.1       dsieger  6445: 
                   6446: There are several reasons why a package might be instructed to not build under
                   6447: certain circumstances. If the package builds and runs on most platforms, the
1.83      dholland 6448: exceptions should be noted with BROKEN_ON_PLATFORM. If the package builds and
                   6449: runs on a small handful of platforms, set BROKEN_EXCEPT_ON_PLATFORM instead.
                   6450: Both BROKEN_ON_PLATFORM and BROKEN_EXCEPT_ON_PLATFORM are OS triples
                   6451: (OS-version-platform) that can use glob-style wildcards.
                   6452: 
1.114     maya     6453: If a package is not appropriate for some platforms (as opposed to merely
1.83      dholland 6454: broken), a different set of variables should be used as this affects failure
                   6455: reporting and statistics. If the package is appropriate for most platforms, the
                   6456: exceptions should be noted with NOT_FOR_PLATFORM. If the package is appropriate
                   6457: for only a small handful of platforms (often exactly one), set
                   6458: ONLY_FOR_PLATFORM instead. Both ONLY_FOR_PLATFORM and NOT_FOR_PLATFORM are OS
                   6459: triples (OS-version-platform) that can use glob-style wildcards.
1.1       dsieger  6460: 
                   6461: Some packages are tightly bound to a specific version of an operating system,
                   6462: e.g. LKMs or sysutils/lsof. Such binary packages are not backwards compatible
                   6463: with other versions of the OS, and should be uploaded to a version specific
                   6464: directory on the FTP server. Mark these packages by setting OSVERSION_SPECIFIC
                   6465: to "yes". This variable is not currently used by any of the package system
                   6466: internals, but may be used in the future.
                   6467: 
                   6468: If the package should be skipped (for example, because it provides
                   6469: functionality already provided by the system), set PKG_SKIP_REASON to a
                   6470: descriptive message. If the package should fail because some preconditions are
                   6471: not met, set PKG_FAIL_REASON to a descriptive message.
                   6472: 
1.154     rillig   6473: 21.1.8. Packages which should not be deleted, once installed
1.1       dsieger  6474: 
                   6475: To ensure that a package may not be deleted, once it has been installed, the
                   6476: PKG_PRESERVE definition should be set in the package Makefile. This will be
1.25      wiz      6477: carried into any binary package that is made from this pkgsrc entry. A "
                   6478: preserved" package will not be deleted using pkg_delete(1) unless the "-f"
1.1       dsieger  6479: option is used.
                   6480: 
1.154     rillig   6481: 21.1.9. Handling packages with security problems
1.1       dsieger  6482: 
                   6483: When a vulnerability is found, this should be noted in localsrc/security/
1.205     wiz      6484: advisories/pkg-vulnerabilities. Entries in that file consist of three parts:
                   6485: 
                   6486:   * package version pattern
                   6487: 
                   6488:   * type of vulnerability (please cut'n'paste an existing one where possible)
                   6489: 
                   6490:   * URL providing additional information about the issue
                   6491: 
                   6492: For the package version pattern please always use `<' to mark an upper bound
                   6493: (not `<='!). This will avoid possible problems due unrelated PKGREVISION bumps
                   6494: not related to security fixes. Lower bounds can be added too, using '>' or '>=
1.206     wiz      6495: '. For example, "foo>=1<1.2" would mark versions 1.0 (included) to 1.2
1.205     wiz      6496: (excluded) of "foo" as affected by the security issue.
                   6497: 
                   6498: Entries should always be added at the bottom of the file.
                   6499: 
                   6500: When fixing packages, please modify the upper bound of the corresponding entry.
                   6501: To continue the previous example, if a fix was backported to version 1.1nb2,
1.206     wiz      6502: change the previous pattern to "foo>=1<1.1nb2".
1.205     wiz      6503: 
                   6504: To locally test a package version pattern against a PKGNAME you can use the 
                   6505: pkg_admin pmatch command.
                   6506: 
                   6507: The URL should be as permanent as possible and provide as much information
                   6508: about the issue as possible. CVE entries are preferred.
                   6509: 
                   6510: After committing that file, ask pkgsrc-security@NetBSD.org to update the file
                   6511: on ftp.NetBSD.org.
1.1       dsieger  6512: 
                   6513: After fixing the vulnerability by a patch, its PKGREVISION should be increased
                   6514: (this is of course not necessary if the problem is fixed by using a newer
1.32      wiz      6515: release of the software), and the pattern in the pkg-vulnerabilities file must
                   6516: be updated.
1.1       dsieger  6517: 
                   6518: Also, if the fix should be applied to the stable pkgsrc branch, be sure to
                   6519: submit a pullup request!
                   6520: 
                   6521: Binary packages already on ftp.NetBSD.org will be handled semi-automatically by
                   6522: a weekly cron job.
                   6523: 
1.205     wiz      6524: In case a security issue is disputed, please contact
                   6525: pkgsrc-security@NetBSD.org.
                   6526: 
1.154     rillig   6527: 21.1.10. How to handle incrementing versions when fixing an existing package
1.1       dsieger  6528: 
                   6529: When making fixes to an existing package it can be useful to change the version
                   6530: number in PKGNAME. To avoid conflicting with future versions by the original
                   6531: author, a "nb1", "nb2", ... suffix can be used on package versions by setting
                   6532: PKGREVISION=1 (2, ...). The "nb" is treated like a "." by the package tools.
                   6533: e.g.
                   6534: 
                   6535: DISTNAME=       foo-17.42
                   6536: PKGREVISION=    9
                   6537: 
                   6538: will result in a PKGNAME of "foo-17.42nb9". If you want to use the original
                   6539: value of PKGNAME without the "nbX" suffix, e.g. for setting DIST_SUBDIR, use
                   6540: PKGNAME_NOREV.
                   6541: 
                   6542: When a new release of the package is released, the PKGREVISION should be
                   6543: removed, e.g. on a new minor release of the above package, things should be
                   6544: like:
                   6545: 
                   6546: DISTNAME=       foo-17.43
                   6547: 
                   6548: PKGREVISION should be incremented for any non-trivial change in the resulting
                   6549: binary package. Without a PKGREVISION bump, someone with the previous version
                   6550: installed has no way of knowing that their package is out of date. Thus,
                   6551: changes without increasing PKGREVISION are essentially labeled "this is so
                   6552: trivial that no reasonable person would want to upgrade", and this is the rough
                   6553: test for when increasing PKGREVISION is appropriate. Examples of changes that
                   6554: do not merit increasing PKGREVISION are:
                   6555: 
1.14      jmcneill 6556:   * Changing HOMEPAGE, MAINTAINER, OWNER, or comments in Makefile.
1.1       dsieger  6557: 
                   6558:   * Changing build variables if the resulting binary package is the same.
                   6559: 
                   6560:   * Changing DESCR.
                   6561: 
                   6562:   * Adding PKG_OPTIONS if the default options don't change.
                   6563: 
                   6564: Examples of changes that do merit an increase to PKGREVISION include:
                   6565: 
                   6566:   * Security fixes
                   6567: 
                   6568:   * Changes or additions to a patch file
                   6569: 
                   6570:   * Changes to the PLIST
                   6571: 
1.12      weinem   6572:   * A dependency is changed or renamed.
                   6573: 
1.1       dsieger  6574: PKGREVISION must also be incremented when dependencies have ABI changes.
                   6575: 
1.154     rillig   6576: 21.1.11. Substituting variable text in the package files (the SUBST framework)
1.1       dsieger  6577: 
1.180     rillig   6578: When you want to replace the same text in multiple files, or multiple times in
                   6579: the same file, it is cumbersome to maintain a patch file for this. This is
                   6580: where the SUBST framework steps in. It provides an easy-to-use interface for
                   6581: replacing text in files. It just needs the following information:
1.172     rillig   6582: 
1.180     rillig   6583:   * In which phase of the package build cycle should the replacement happen?
1.172     rillig   6584: 
1.180     rillig   6585:   * In which files should the replacement happen?
1.172     rillig   6586: 
                   6587:   * Which text should be replaced with what?
                   6588: 
1.180     rillig   6589: This information is encoded in a block of SUBST variables. A minimal example
                   6590: is:
                   6591: 
                   6592: SUBST_CLASSES+=         paths
                   6593: SUBST_STAGE.paths=      pre-configure
                   6594: SUBST_FILES.paths=      src/*.c
                   6595: SUBST_SED.paths=        -e 's,/usr/local,${PREFIX},g'
                   6596: 
                   6597: Translated into English, it means: In the pre-configure stage (that is, after
                   6598: applying the patches from the patches/ directory and before running the
                   6599: configure script and the portability check), replace the text /usr/local with
                   6600: the content of the variable PREFIX.
                   6601: 
                   6602: Each SUBST block starts by appending an identifier to SUBST_CLASSES (note the +
                   6603: =). This identifier can be chosen freely by the package. If there should ever
                   6604: be duplicate identifiers, the pkgsrc infrastructure will catch this and fail
                   6605: early, so don't worry about name collisions.
                   6606: 
                   6607: Except for SUBST_CLASSES, all variables in a SUBST block are parameterized
                   6608: using this identifier. In the remainder of this section, these parameterized
                   6609: variables are written as SUBST_STAGE.*.
                   6610: 
                   6611: SUBST_CLASSES+=         paths
                   6612: SUBST_STAGE.paths=      pre-configure
                   6613: SUBST_MESSAGE.paths=    Fixing absolute paths.
                   6614: SUBST_FILES.paths=      src/*.c
                   6615: SUBST_FILES.paths+=     scripts/*.sh
                   6616: SUBST_SED.paths=        -e 's,"/usr/local,"${PREFIX},g'
                   6617: SUBST_SED.paths+=       -e 's,"/var/log,"${VARBASE}/log,g'
                   6618: SUBST_VARS.paths=       LOCALBASE PREFIX PKGVERSION
                   6619: 
                   6620: To get a complete picture about the SUBST substitutions, run bmake
                   6621: show-all-subst. If something doesn't work as expected, run pkglint on the
                   6622: package, which detects several typical mistakes surrounding the SUBST blocks.
                   6623: For any questions that might remain after this, have a look at mk/subst.mk.
                   6624: 
                   6625: 21.1.11.1. Choosing the time where the substitutions happen
                   6626: 
                   6627: The SUBST_STAGE.* is one of {pre,do,post}-
                   6628: {extract,patch,configure,build,test,install}. Of these, pre-configure is used
                   6629: most often, by far. The most popular stages are, in chronological order:
                   6630: 
                   6631: post-extract
                   6632: 
                   6633:     The substitutions are applied immediately after the distfiles are
                   6634:     extracted. Running bmake extract on the package will leave no traces of the
                   6635:     original files.
                   6636: 
                   6637:     When the substitution applies to files for which there is also a patch in
                   6638:     the patches/ directory, this means that the patches will be computed based
                   6639:     on the result of the substitution. When these patches are sent to the
                   6640:     upstream maintainer later, to be fixed in the upstream package, these
                   6641:     patches may no longer match what the upstream author is used to. Because of
                   6642:     this, pre-configure is often a better choice.
                   6643: 
                   6644: pre-configure
                   6645: 
                   6646:     The substitutions are applied after the patches from the patches/
                   6647:     directory. This makes it possible to run bmake patch on the package, after
                   6648:     which the patches can be edited using the tools pkgvi and mkpatches from
                   6649:     the pkgtools/pkgdiff package.
                   6650: 
                   6651:     When updating the patches, it is helpful to explicitly separate the bmake
                   6652:     patch from the bmake configure, and to only edit the patches between these
                   6653:     commands. Otherwise the substitutions from the SUBST block will end up in
                   6654:     the patch file. When this happens in really obvious ways, pkglint will
                   6655:     complain about patches that contain a hard-coded /usr/pkg instead of the
                   6656:     correct and intended @PREFIX@, but it can only detect these really obvious
                   6657:     cases.
                   6658: 
                   6659: do-configure
                   6660: 
                   6661:     This stage should only be used if the package defines a pre-configure
                   6662:     action itself, and the substitution must happen after that. Typical
                   6663:     examples are packages that use the pre-configure stage to regenerate the
                   6664:     GNU configure script from configure.ac.
                   6665: 
                   6666: post-configure
                   6667: 
                   6668:     This stage is used to fix up any mistakes by the configure stage.
                   6669: 
                   6670: pre-build
                   6671: 
                   6672:     This stage should only be used for substitutions that are clearly related
                   6673:     to building the package, not for fixing the configuration. Substitutions
                   6674:     for pathnames (such as replacing /usr/local with ${PREFIX}) or user names
                   6675:     (such as replacing @MY_USER@ with the actual username) belong in
                   6676:     pre-configure or post-configure instead.
                   6677: 
                   6678: post-build
                   6679: 
                   6680:     Just as with pre-build, this stage should only be used for substitutions
                   6681:     that are clearly related to building the package, not for fixing the
                   6682:     configuration. Substitutions for pathnames (such as replacing /usr/local
                   6683:     with ${PREFIX}) or user names (such as replacing @MY_USER@ with the actual
                   6684:     username) belong in pre-configure or post-configure instead.
                   6685: 
                   6686:     A typical use is to update pkg-config files to include the rpath compiler
                   6687:     options.
                   6688: 
                   6689: pre-install
                   6690: 
                   6691:     In general, the install phase should be as simple as possible. As with the
                   6692:     pre-build and post-build stages, it should not be used to fix pathnames or
                   6693:     user names, these belong in pre-configure instead. There are only few
                   6694:     legitimate use cases for applying substitutions in this stage.
                   6695: 
1.181     rillig   6696: 21.1.11.2. Choosing the files where the substitutions happen
1.180     rillig   6697: 
                   6698: The SUBST_FILES.* variable contains a list of filename patterns. These patterns
                   6699: are relative to WRKSRC since that is where most substitutions happen. A typical
                   6700: example is:
                   6701: 
                   6702: SUBST_FILES.path=       Makefile */Makefile */*/Makefile *.[ch]
                   6703: 
                   6704: The above patterns, especially the last, are quite broad. The SUBST
                   6705: implementation checks that each filename pattern that is mentioned here has an
                   6706: effect. For example, if none of the */*/Makefile files contains the patterns to
                   6707: be found and substituted, that filename pattern is redundant and should be left
1.181     rillig   6708: out. By default, the SUBST framework will complain with an error message. If
                   6709: the text to be substituted occurs in some of the files from a single pattern,
                   6710: but not in all of them, that is totally ok, and the SUBST framework will only
                   6711: print an INFO message for those files.
1.180     rillig   6712: 
                   6713: If there is a good reason for having redundant filename patterns, set
1.181     rillig   6714: SUBST_NOOP_OK.* to yes.
1.180     rillig   6715: 
                   6716: Another popular way of choosing the files for the substitutions is via a shell
                   6717: command, like this:
                   6718: 
1.181     rillig   6719: C_FILES_CMD=            cd ${WRKSRC} && ${FIND} . -name '*.c'
1.180     rillig   6720: SUBST_FILES.path=       ${C_FILES_CMD:sh}
                   6721: 
                   6722: The variable name C_FILES_CMD in this example is freely chosen and independent
                   6723: of the SUBST framework.
                   6724: 
                   6725: In this variant, the SUBST_FILES.* variable lists each file individually.
                   6726: Thereby chances are higher that there are filename patterns in which no
                   6727: substitution happens. Since the SUBST framework cannot know whether the
                   6728: filename patterns in SUBST_FILES.* have been explicitly listed in the Makefile
                   6729: (where any redundant filename pattern would be suspicious) or been generated by
                   6730: a shell command (in which redundant filename patterns are more likely and to be
                   6731: expected), it will complain about these redundant filename patterns. Therefore,
                   6732: SUBST blocks that use a shell command to generate the list of filename patterns
                   6733: often need to set SUBST_NOOP_OK.* to yes.
                   6734: 
                   6735: 21.1.11.3. Choosing what to substitute
                   6736: 
                   6737: In most cases, the substitutions are given using one or more sed(1) commands,
                   6738: like this:
                   6739: 
                   6740: SUBST_SED.path=         -e 's|/usr/local|${PREFIX}|g'
                   6741: 
                   6742: Each of the sed commands needs to be preceded by the -e option and should be
                   6743: specified on a line of its own, to avoid hiding short sed commands at the end
                   6744: of a line.
                   6745: 
                   6746: Since the sed commands often contain shell metacharacters as the separator (the
                   6747: | in the above example), it is common to enclose them in single quotes.
                   6748: 
                   6749: A common substitution is to replace placeholders of the form @VARNAME@ with
                   6750: their pkgsrc counterpart variable ${VARNAME}. A typical example is:
                   6751: 
                   6752: SUBST_VARS.path=        PREFIX
                   6753: 
1.181     rillig   6754: This type of substitutions is typically done by the GNU configure scripts
                   6755: during the do-configure stage, but in some cases these need to be overridden.
                   6756: The same pattern is also used when a package defines patches that replace
                   6757: previously hard-coded paths like /usr/local with a @PREFIX@ placeholder first,
                   6758: which then gets substituted by the actual ${PREFIX} in the pre-configure stage.
                   6759: In many of these cases, it works equally well to just use the SUBST framework
                   6760: to directly replace /usr/local with ${PREFIX}, thereby omitting the
                   6761: intermediate patch file.
1.180     rillig   6762: 
                   6763: If the above is not flexible enough, it is possible to not use sed at all for
                   6764: the substitution but to specify an entirely different command, like this:
                   6765: 
                   6766: SUBST_FILTER_CMD.path=  LC_ALL=C ${TR} -d '\r'
1.1       dsieger  6767: 
1.180     rillig   6768: This is used for the few remaining packages in which the distributed files use
                   6769: Windows-style line endings that need to be converted to UNIX-style line
                   6770: endings.
1.1       dsieger  6771: 
1.180     rillig   6772: 21.1.11.4. Other SUBST variables
1.172     rillig   6773: 
1.180     rillig   6774: When a SUBST block is applied during a package build, a message is logged. The
                   6775: default message is fine for most purposes but can be overridden by setting
                   6776: SUBST_MESSAGE.* to an individual message.
1.1       dsieger  6777: 
1.154     rillig   6778: 21.2. The fetch phase
1.1       dsieger  6779: 
1.154     rillig   6780: 21.2.1. Packages whose distfiles aren't available for plain downloading
1.1       dsieger  6781: 
                   6782: If you need to download from a dynamic URL you can set DYNAMIC_MASTER_SITES and
                   6783: a make fetch will call files/getsite.sh with the name of each file to download
                   6784: as an argument, expecting it to output the URL of the directory from which to
                   6785: download it. graphics/ns-cult3d is an example of this usage.
                   6786: 
                   6787: If the download can't be automated, because the user must submit personal
                   6788: information to apply for a password, or must pay for the source, or whatever,
                   6789: you can set FETCH_MESSAGE to a list of lines that are displayed to the user
                   6790: before aborting the build. Example:
                   6791: 
                   6792: FETCH_MESSAGE=  "Please download the files"
                   6793: FETCH_MESSAGE+= "    "${DISTFILES:Q}
                   6794: FETCH_MESSAGE+= "manually from "${MASTER_SITES:Q}"."
                   6795: 
1.154     rillig   6796: 21.2.2. How to handle modified distfiles with the 'old' name
1.1       dsieger  6797: 
                   6798: Sometimes authors of a software package make some modifications after the
                   6799: software was released, and they put up a new distfile without changing the
                   6800: package's version number. If a package is already in pkgsrc at that time, the
                   6801: checksum will no longer match. The contents of the new distfile should be
                   6802: compared against the old one before changing anything, to make sure the
                   6803: distfile was really updated on purpose, and that no trojan horse or so crept
                   6804: in. Please mention that the distfiles were compared and what was found in your
1.54      rodent   6805: commit message.
                   6806: 
                   6807: Then, the correct way to work around this is to set DIST_SUBDIR to a unique
1.109     wiz      6808: directory name, usually based on PKGNAME_NOREV (but take care with python or
                   6809: ruby packages, where PKGNAME includes a variable prefix). All DISTFILES and
                   6810: PATCHFILES for this package will be put in that subdirectory of the local
1.154     rillig   6811: distfiles directory. (See Section 21.1.10, "How to handle incrementing versions
1.109     wiz      6812: when fixing an existing package" for more details.) In case this happens more
                   6813: often, PKGNAME can be used (thus including the nbX suffix) or a date stamp can
                   6814: be appended, like ${PKGNAME_NOREV}-YYYYMMDD.
1.54      rodent   6815: 
                   6816: DIST_SUBDIR is also used when a distfile's name does not contain a version and
                   6817: the distfile is apt to change. In cases where the likelihood of this is very
                   6818: small, DIST_SUBDIR might not be required. Additionally, DIST_SUBDIR must not be
                   6819: removed unless the distfile name changes, even if a package is being moved or
                   6820: renamed.
                   6821: 
                   6822: Do not forget regenerating the distinfo file after that, since it contains the
                   6823: DIST_SUBDIR path in the filenames. Also, increase the PKGREVISION if the
                   6824: installed package is different. Furthermore, a mail to the package's authors
                   6825: seems appropriate telling them that changing distfiles after releases without
                   6826: changing the file names is not good practice.
1.1       dsieger  6827: 
1.154     rillig   6828: 21.2.3. Packages hosted on github.com
1.88      tnn      6829: 
1.90      tnn      6830: Helper methods exist for packages hosted on github.com which will often have
                   6831: distfile names that clash with other packages, for example 1.0.tar.gz. Use one
                   6832: of the three recipes from below:
1.88      tnn      6833: 
1.154     rillig   6834: 21.2.3.1. Fetch based on a tagged release
1.88      tnn      6835: 
1.189     bacon    6836: If your distfile URL looks similar to https://github.com/username/example/
                   6837: archive/v1.0.zip, then you are packaging a tagged release.
1.88      tnn      6838: 
1.189     bacon    6839: DISTNAME=       example-1.0
1.90      tnn      6840: MASTER_SITES=   ${MASTER_SITE_GITHUB:=username/}
1.189     bacon    6841: #GITHUB_PROJECT= example    # can be omitted if same as DISTNAME
1.90      tnn      6842: GITHUB_TAG=     v${PKGVERSION_NOREV}
1.88      tnn      6843: EXTRACT_SUFX=   .zip
                   6844: 
1.189     bacon    6845: 21.2.3.2. Fetch based on a specific commit before the first release
                   6846: 
                   6847: If your distfile looks similar to https://github.com/username/example/archive/
                   6848: 988881adc9fc3655077dc2d4d757d480b5ea0e11 and is from a commit before the first
                   6849: release, then set the package version to 0.0.0.N, where N is the number of
                   6850: commits to the repository, and set GITHUB_TAG to the commit hash. This will
                   6851: (almost) ensure that the first tagged release will have a version greater than
                   6852: this one so that package upgrades will function properly.
                   6853: 
                   6854: DISTNAME=       example-0.0.0.347
                   6855: MASTER_SITES=   ${MASTER_SITE_GITHUB:=username/}
                   6856: #GITHUB_PROJECT= example    # can be omitted if same as DISTNAME
                   6857: GITHUB_TAG=     988881adc9fc3655077dc2d4d757d480b5ea0e11
                   6858: 
                   6859: 21.2.3.3. Fetch based on a specific commit after a release
1.88      tnn      6860: 
1.189     bacon    6861: If your distfile looks similar to https://github.com/username/example/archive/
                   6862: 988881adc9fc3655077dc2d4d757d480b5ea0e11 and is from a commit after a release,
                   6863: then include the last release version and the commit count since that release
                   6864: in the package version and set GITHUB_TAG to the commit hash. The latest
                   6865: release and commit count are shown in the output of "git describe --tags":
                   6866: 
                   6867: # git clone https://github.com/username/example
                   6868: # cd example
                   6869: # git describe --tags
                   6870: 1.2.3-5-g988881a
1.88      tnn      6871: 
1.189     bacon    6872: DISTNAME=       example-1.2.3.5
                   6873: MASTER_SITES=   ${MASTER_SITE_GITHUB:=username/}
                   6874: #GITHUB_PROJECT= example    # can be omitted if same as DISTNAME
1.90      tnn      6875: GITHUB_TAG=     988881adc9fc3655077dc2d4d757d480b5ea0e11
1.88      tnn      6876: 
1.189     bacon    6877: 21.2.3.4. Fetch based on release
1.88      tnn      6878: 
1.189     bacon    6879: If your distfile URL looks similar to https://github.com/username/example/
                   6880: releases/download/rel-1.6/offensive-1.6.zip, then you are packaging a release.
1.88      tnn      6881: 
1.90      tnn      6882: DISTNAME=       offensive-1.6
1.88      tnn      6883: PKGNAME=        ${DISTNAME:S/offensive/proper/}
1.90      tnn      6884: MASTER_SITES=   ${MASTER_SITE_GITHUB:=username/}
1.189     bacon    6885: GITHUB_PROJECT= example
1.90      tnn      6886: GITHUB_RELEASE= rel-${PKGVERSION_NOREV} # usually just set this to ${DISTNAME}
                   6887: EXTRACT_SUFX=   .zip
1.88      tnn      6888: 
1.154     rillig   6889: 21.3. The configure phase
1.1       dsieger  6890: 
1.154     rillig   6891: 21.3.1. Shared libraries - libtool
1.1       dsieger  6892: 
                   6893: pkgsrc supports many different machines, with different object formats like
                   6894: a.out and ELF, and varying abilities to do shared library and dynamic loading
                   6895: at all. To accompany this, varying commands and options have to be passed to
                   6896: the compiler, linker, etc. to get the Right Thing, which can be pretty annoying
                   6897: especially if you don't have all the machines at your hand to test things. The
                   6898: devel/libtool pkg can help here, as it just "knows" how to build both static
                   6899: and dynamic libraries from a set of source files, thus being
                   6900: platform-independent.
                   6901: 
                   6902: Here's how to use libtool in a package in seven simple steps:
                   6903: 
                   6904:  1. Add USE_LIBTOOL=yes to the package Makefile.
                   6905: 
                   6906:  2. For library objects, use "${LIBTOOL} --mode=compile ${CC}" in place of "$
                   6907:     {CC}". You could even add it to the definition of CC, if only libraries are
                   6908:     being built in a given Makefile. This one command will build both PIC and
                   6909:     non-PIC library objects, so you need not have separate shared and
                   6910:     non-shared library rules.
                   6911: 
                   6912:  3. For the linking of the library, remove any "ar", "ranlib", and "ld
                   6913:     -Bshareable" commands, and instead use:
                   6914: 
                   6915:     ${LIBTOOL} --mode=link \
                   6916:         ${CC} -o ${.TARGET:.a=.la} \
                   6917:             ${OBJS:.o=.lo} \
                   6918:             -rpath ${PREFIX}/lib \
                   6919:             -version-info major:minor
                   6920: 
                   6921:     Note that the library is changed to have a .la extension, and the objects
                   6922:     are changed to have a .lo extension. Change OBJS as necessary. This
                   6923:     automatically creates all of the .a, .so.major.minor, and ELF symlinks (if
                   6924:     necessary) in the build directory. Be sure to include "-version-info",
                   6925:     especially when major and minor are zero, as libtool will otherwise strip
                   6926:     off the shared library version.
                   6927: 
                   6928:     From the libtool manual:
                   6929: 
                   6930:     So, libtool library versions are described by three integers:
                   6931: 
                   6932:     CURRENT
                   6933:     The most recent interface number that this library implements.
                   6934: 
                   6935:     REVISION
                   6936:     The implementation number of the CURRENT interface.
                   6937: 
                   6938:     AGE
                   6939:     The difference between the newest and oldest interfaces that
                   6940:     this library implements.  In other words, the library implements
                   6941:     all the interface numbers in the range from number `CURRENT -
                   6942:     AGE' to `CURRENT'.
                   6943: 
                   6944:     If two libraries have identical CURRENT and AGE numbers, then the
                   6945:     dynamic linker chooses the library with the greater REVISION number.
                   6946: 
                   6947:     The "-release" option will produce different results for a.out and ELF
1.25      wiz      6948:     (excluding symlinks) in only one case. An ELF library of the form "
                   6949:     libfoo-release.so.x.y" will have a symlink of "libfoo.so.x.y" on an a.out
1.1       dsieger  6950:     platform. This is handled automatically.
                   6951: 
                   6952:     The "-rpath argument" is the install directory of the library being built.
                   6953: 
                   6954:     In the PLIST, include only the .la file, the other files will be added
                   6955:     automatically.
                   6956: 
                   6957:  4. When linking shared object (.so) files, i.e. files that are loaded via
                   6958:     dlopen(3), NOT shared libraries, use "-module -avoid-version" to prevent
                   6959:     them getting version tacked on.
                   6960: 
                   6961:     The PLIST file gets the foo.so entry.
                   6962: 
                   6963:  5. When linking programs that depend on these libraries before they are
                   6964:     installed, preface the cc(1) or ld(1) line with "${LIBTOOL} --mode=link",
                   6965:     and it will find the correct libraries (static or shared), but please be
                   6966:     aware that libtool will not allow you to specify a relative path in -L
                   6967:     (such as "-L../somelib"), because it expects you to change that argument to
                   6968:     be the .la file. e.g.
                   6969: 
                   6970:     ${LIBTOOL} --mode=link ${CC} -o someprog -L../somelib -lsomelib
                   6971: 
                   6972:     should be changed to:
                   6973: 
                   6974:     ${LIBTOOL} --mode=link ${CC} -o someprog ../somelib/somelib.la
                   6975: 
                   6976:     and it will do the right thing with the libraries.
                   6977: 
                   6978:  6. When installing libraries, preface the install(1) or cp(1) command with "$
                   6979:     {LIBTOOL} --mode=install", and change the library name to .la. e.g.
                   6980: 
1.23      jakllsch 6981:     ${LIBTOOL} --mode=install ${BSD_INSTALL_LIB} ${SOMELIB:.a=.la} ${PREFIX}/lib
1.1       dsieger  6982: 
                   6983:     This will install the static .a, shared library, any needed symlinks, and
                   6984:     run ldconfig(8).
                   6985: 
                   6986:  7. In your PLIST, include only the .la file (this is a change from previous
                   6987:     behaviour).
                   6988: 
1.154     rillig   6989: 21.3.2. Using libtool on GNU packages that already support libtool
1.1       dsieger  6990: 
                   6991: Add USE_LIBTOOL=yes to the package Makefile. This will override the package's
                   6992: own libtool in most cases. For older libtool using packages, libtool is made by
                   6993: ltconfig script during the do-configure step; you can check the libtool script
                   6994: location by doing make configure; find work*/ -name libtool.
                   6995: 
                   6996: LIBTOOL_OVERRIDE specifies which libtool scripts, relative to WRKSRC, to
                   6997: override. By default, it is set to "libtool */libtool */*/libtool". If this
                   6998: does not match the location of the package's libtool script(s), set it as
                   6999: appropriate.
                   7000: 
                   7001: If you do not need *.a static libraries built and installed, then use
                   7002: SHLIBTOOL_OVERRIDE instead.
                   7003: 
                   7004: If your package makes use of the platform-independent library for loading
                   7005: dynamic shared objects, that comes with libtool (libltdl), you should include
                   7006: devel/libltdl/buildlink3.mk.
                   7007: 
                   7008: Some packages use libtool incorrectly so that the package may not work or build
                   7009: in some circumstances. Some of the more common errors are:
                   7010: 
                   7011:   * The inclusion of a shared object (-module) as a dependent library in an
                   7012:     executable or library. This in itself isn't a problem if one of two things
                   7013:     has been done:
                   7014: 
                   7015:      1. The shared object is named correctly, i.e. libfoo.la, not foo.la
                   7016: 
                   7017:      2. The -dlopen option is used when linking an executable.
                   7018: 
                   7019:   * The use of libltdl without the correct calls to initialisation routines.
                   7020:     The function lt_dlinit() should be called and the macro
                   7021:     LTDL_SET_PRELOADED_SYMBOLS included in executables.
                   7022: 
1.154     rillig   7023: 21.3.3. GNU Autoconf/Automake
1.1       dsieger  7024: 
                   7025: If a package needs GNU autoconf or automake to be executed to regenerate the
1.223     nia      7026: configure script and Makefile.in makefile templates from configure.ac and
                   7027: Makefile.am, then they should be executed in a pre-configure target:
1.1       dsieger  7028: 
1.223     nia      7029: USE_TOOLS+=     autoconf automake autoreconf
                   7030: GNU_CONFIGURE=  yes
1.1       dsieger  7031: ...
                   7032: 
                   7033: pre-configure:
1.223     nia      7034:         set -e; cd ${WRKSRC} && autoreconf -fi
1.1       dsieger  7035: ...
                   7036: 
1.223     nia      7037: Packages which use GNU Automake will sometimes require GNU Make (gmake in
                   7038: USE_TOOLS), but not always. Note that autoreconf only needs to be executed if
                   7039: configure.ac or Makefiles are modified, or configure is not present.
1.1       dsieger  7040: 
                   7041: There are times when the configure process makes additional changes to the
                   7042: generated files, which then causes the build process to try to re-execute the
                   7043: automake sequence. This is prevented by touching various files in the configure
                   7044: stage. If this causes problems with your package you can set AUTOMAKE_OVERRIDE=
                   7045: NO in the package Makefile.
                   7046: 
1.223     nia      7047: 21.3.4. Meson / ninja
                   7048: 
                   7049: Packages using Meson to configure need to include:
                   7050: 
                   7051: .include "../../devel/meson/build.mk"
                   7052: 
                   7053: In nearly all cases (any program with dependencies), pkg-config needs to be
                   7054: added to USE_TOOLS. If the package installs translation files for non-English
                   7055: languages, also add msgfmt and xgettext:
                   7056: 
                   7057: USE_TOOLS+=     pkg-config msgfmt xgettext
                   7058: 
                   7059: If any options need to be passed to Meson, use MESON_ARGS instead of
                   7060: CONFIGURE_ARGS:
                   7061: 
                   7062: MESON_ARGS+=    -Dx11=false
                   7063: 
1.154     rillig   7064: 21.4. Programming languages
1.1       dsieger  7065: 
1.154     rillig   7066: 21.4.1. C, C++, and Fortran
1.1       dsieger  7067: 
1.223     nia      7068: Compilers for the C and C++ languages comes with the NetBSD base system. By
                   7069: default, pkgsrc assumes that a package is written in C and will hide all other
                   7070: compilers (via the wrapper framework, see Chapter 18, Buildlink methodology).
1.1       dsieger  7071: 
                   7072: To declare which language's compiler a package needs, set the USE_LANGUAGES
1.212     wiz      7073: variable. Allowed values currently are:
                   7074: 
                   7075:         c99, c++, c++03, gnu++03, c++0x, gnu++0x, c++11, gnu++11,
                   7076:         c++14, gnu++14, c++17, gnu++17, c++20, gnu++20, fortran,
                   7077:         fortran77, java, objc, obj-c++, and ada.
                   7078: 
                   7079: 
                   7080: (and any combination). The default is "c". Packages using GNU configure
                   7081: scripts, even if written in C++, usually need a C compiler for the configure
                   7082: phase.
1.1       dsieger  7083: 
1.223     nia      7084: To express a general requirement on a specific C or C++ version, normally only
                   7085: GCC_REQD needs to be set. For example, GCC 7 includes support for C++17, so if
                   7086: the package uses C++17 it should specify:
                   7087: 
                   7088:         GCC_REQD+=      7
                   7089: 
                   7090: 
                   7091: Language variants like c++11 for USE_LANGUAGES should only be specified if the
                   7092: package does not explicitly set -std=... when compiling (i.e. the package
                   7093: assumes the compiler defaults to C++11 or some other standard). This is usually
                   7094: a bug in the upstream build system.
                   7095: 
                   7096: GCC version 5 includes support for C++14, while GCC 4.7 includes more-or-less
                   7097: complete support for C++11. For more information, consult GCC's own
                   7098: documentation on programming language support.
                   7099: 
1.154     rillig   7100: 21.4.2. Java
1.1       dsieger  7101: 
                   7102: If a program is written in Java, use the Java framework in pkgsrc. The package
                   7103: must include ../../mk/java-vm.mk. This Makefile fragment provides the following
                   7104: variables:
                   7105: 
                   7106:   * USE_JAVA defines if a build dependency on the JDK is added. If USE_JAVA is
                   7107:     set to "run", then there is only a runtime dependency on the JDK. The
                   7108:     default is "yes", which also adds a build dependency on the JDK.
                   7109: 
                   7110:   * Set USE_JAVA2 to declare that a package needs a Java2 implementation. The
                   7111:     supported values are "yes", "1.4", and "1.5". "yes" accepts any Java2
                   7112:     implementation, "1.4" insists on versions 1.4 or above, and "1.5" only
                   7113:     accepts versions 1.5 or above. This variable is not set by default.
                   7114: 
1.25      wiz      7115:   * PKG_JAVA_HOME is automatically set to the runtime location of the used Java
                   7116:     implementation dependency. It may be used to set JAVA_HOME to a good value
                   7117:     if the program needs this variable to be defined.
                   7118: 
1.205     wiz      7119: 21.4.3. Go
                   7120: 
                   7121: If a program is written in Go and has any dependencies on other Go modules,
                   7122: have the package include ../../lang/go/go-module.mk.
                   7123: 
                   7124:  1. Generate a list of those dependencies with make clean && make patch && make
                   7125:     show-go-modules > go-modules.mk.
                   7126: 
1.223     nia      7127:  2. Prepend .include "go-modules.mk" to any other .includes.
                   7128: 
                   7129:  3. Incorporate these modules in distinfo with make makesum.
1.205     wiz      7130: 
1.223     nia      7131: 21.4.4. Rust
1.205     wiz      7132: 
1.223     nia      7133: If a program is written in Rust and uses Cargo to build, have the package
                   7134: include ../../lang/rust/cargo.mk.
1.205     wiz      7135: 
1.223     nia      7136:  1. Generate a list of those dependencies with make CARGO_ARGS="build
                   7137:     --release" build && make print-cargo-depends > cargo-depends.mk.
1.205     wiz      7138: 
1.223     nia      7139:  2. Prepend .include "cargo-depends.mk" to any other .includes.
1.205     wiz      7140: 
                   7141:  3. Incorporate these modules in distinfo with make makesum.
                   7142: 
1.223     nia      7143: 21.4.5. Packages containing Perl scripts
1.1       dsieger  7144: 
1.203     nia      7145: If your package contains interpreted Perl scripts, add "perl" to the USE_TOOLS
1.1       dsieger  7146: variable and set REPLACE_PERL to ensure that the proper interpreter path is
                   7147: set. REPLACE_PERL should contain a list of scripts, relative to WRKSRC, that
1.74      wiz      7148: you want adjusted. Every occurrence of */bin/perl in a she-bang line will be
1.210     gutterid 7149: replaced with the full path to the Perl executable.
1.1       dsieger  7150: 
1.210     gutterid 7151: If a particular version of Perl is needed, set the PERL5_REQD variable to the
1.1       dsieger  7152: version number. The default is "5.0".
                   7153: 
1.203     nia      7154: See Section 21.6.6, "Packages installing Perl modules" for information about
1.210     gutterid 7155: handling Perl modules.
                   7156: 
                   7157: There is also the REPLACE_PERL6 variable for the language now known as Raku.
1.1       dsieger  7158: 
1.223     nia      7159: 21.4.6. Packages containing shell scripts
1.41      wiz      7160: 
                   7161: REPLACE_SH, REPLACE_BASH, REPLACE_CSH, and REPLACE_KSH can be used to replace
1.225     gutterid 7162: shell she-bangs in files. Please use the appropriate one, preferring REPLACE_SH
                   7163: when this shell is sufficient. Each should contain a list of scripts, relative
                   7164: to WRKSRC, that you want adjusted. Every occurrence of the matching shell in a
                   7165: she-bang line will be replaced with the full path to the shell executable. When
                   7166: using REPLACE_BASH, don't forget to add bash to USE_TOOLS.
1.41      wiz      7167: 
1.223     nia      7168: 21.4.7. Other programming languages
1.1       dsieger  7169: 
1.210     gutterid 7170: There are further similar REPLACE variables available, e.g., REPLACE_AWK for
                   7171: packages containing awk scripts, and REPLACE_R for R. These two, like the
1.211     gutterid 7172: others noted above, have their actions defined centrally in mk/configure/
                   7173: replace-interpreter.mk. Other languages define the actions of these variables
                   7174: within their own dedicated part of the tree, e.g., REPLACE_PHP is actioned in
                   7175: lang/php/phpversion.mk, and REPLACE_PYTHON is actioned in lang/python/
                   7176: application.mk. For other languages, consult the mk files found within their
1.216     gutterid 7177: specific directories (the naming convention varies), or check the list found in
                   7178: Appendix E, Help topics.
1.210     gutterid 7179: 
                   7180: Currently, special handling for other languages varies in pkgsrc. If a compiler
                   7181: package provides a buildlink3.mk file, include that, otherwise just add a
                   7182: (build) dependency on the appropriate compiler package.
1.1       dsieger  7183: 
1.154     rillig   7184: 21.5. The build phase
1.1       dsieger  7185: 
                   7186: The most common failures when building a package are that some platforms do not
                   7187: provide certain header files, functions or libraries, or they provide the
                   7188: functions in a library that the original package author didn't know. To work
                   7189: around this, you can rewrite the source code in most cases so that it does not
                   7190: use the missing functions or provides a replacement function.
                   7191: 
1.154     rillig   7192: 21.5.1. Compiling C and C++ code conditionally
1.1       dsieger  7193: 
                   7194: If a package already comes with a GNU configure script, the preferred way to
                   7195: fix the build failure is to change the configure script, not the code. In the
                   7196: other cases, you can utilize the C preprocessor, which defines certain macros
                   7197: depending on the operating system and hardware architecture it compiles for.
                   7198: These macros can be queried using for example #if defined(__i386). Almost every
                   7199: operating system, hardware architecture and compiler has its own macro. For
                   7200: example, if the macros __GNUC__, __i386__ and __NetBSD__ are all defined, you
                   7201: know that you are using NetBSD on an i386 compatible CPU, and your compiler is
                   7202: GCC.
                   7203: 
                   7204: The list of the following macros for hardware and operating system depends on
                   7205: the compiler that is used. For example, if you want to conditionally compile
                   7206: code on Solaris, don't use __sun__, as the SunPro compiler does not define it.
                   7207: Use __sun instead.
                   7208: 
1.154     rillig   7209: 21.5.1.1. C preprocessor macros to identify the operating system
1.1       dsieger  7210: 
1.223     nia      7211: To distinguish between specific NetBSD versions, you should use the following
                   7212: code.
                   7213: 
                   7214: #ifdef __NetBSD__
                   7215: #include <sys/param.h>
                   7216: #if __NetBSD_Prereq__(9,99,17)
                   7217: /* use a newer feature */
                   7218: #else
                   7219: /* older code */
                   7220: #endif
                   7221: #endif
                   7222: 
                   7223: #ifndef _WIN32
                   7224: /* Unix-like specific code */
                   7225: #endif
                   7226: 
1.1       dsieger  7227: To distinguish between 4.4 BSD-derived systems and the rest of the world, you
                   7228: should use the following code.
                   7229: 
                   7230: #include <sys/param.h>
                   7231: #if (defined(BSD) && BSD >= 199306)
                   7232: /* BSD-specific code goes here */
                   7233: #else
                   7234: /* non-BSD-specific code goes here */
                   7235: #endif
                   7236: 
1.223     nia      7237: You can also test for the following macros:
1.1       dsieger  7238: 
1.46      obache   7239: Cygwin      __CYGWIN__
                   7240: DragonFly   __DragonFly__
1.1       dsieger  7241: FreeBSD     __FreeBSD__
1.46      obache   7242: Haiku       __HAIKU__
1.1       dsieger  7243: Interix     __INTERIX
                   7244: IRIX        __sgi (TODO: get a definite source for this)
1.223     nia      7245: Linux       __linux
1.83      dholland 7246: Mac OS X    __APPLE__
1.46      obache   7247: MirBSD      __MirBSD__ (__OpenBSD__ is also defined)
                   7248: Minix3      __minix
1.1       dsieger  7249: NetBSD      __NetBSD__
                   7250: OpenBSD     __OpenBSD__
                   7251: Solaris     sun, __sun
                   7252: 
1.154     rillig   7253: 21.5.1.2. C preprocessor macros to identify the hardware architecture
1.1       dsieger  7254: 
                   7255: i386        i386, __i386, __i386__
1.223     nia      7256: x86-64      __amd64__, __x86_64__
                   7257: ARM         __arm__
1.1       dsieger  7258: MIPS        __mips
                   7259: SPARC       sparc, __sparc
1.223     nia      7260: PowerPC     __powerpc
1.1       dsieger  7261: 
1.154     rillig   7262: 21.5.1.3. C preprocessor macros to identify the compiler
1.1       dsieger  7263: 
                   7264: GCC         __GNUC__ (major version), __GNUC_MINOR__
                   7265: MIPSpro     _COMPILER_VERSION (0x741 for MIPSpro 7.41)
                   7266: SunPro      __SUNPRO_C (0x570 for Sun C 5.7)
                   7267: SunPro C++  __SUNPRO_CC (0x580 for Sun C++ 5.8)
                   7268: 
1.154     rillig   7269: 21.5.2. How to handle compiler bugs
1.1       dsieger  7270: 
                   7271: Some source files trigger bugs in the compiler, based on combinations of
                   7272: compiler version and architecture and almost always relation to optimisation
                   7273: being enabled. Common symptoms are gcc internal errors or never finishing
                   7274: compiling a file.
                   7275: 
                   7276: Typically, a workaround involves testing the MACHINE_ARCH and compiler version,
1.87      tnn      7277: disabling optimisation for that combination of file, MACHINE_ARCH and compiler.
                   7278: 
                   7279: This used to be a big problem in the past, but is rarely needed now as compiler
                   7280: technology has matured. If you still need to add a compiler specific
                   7281: workaround, please do so in the file hacks.mk and describe the symptom and
                   7282: compiler version as detailed as possible.
1.1       dsieger  7283: 
1.172     rillig   7284: 21.5.3. No such file or directory
                   7285: 
                   7286: Compilation sometimes fails with an error message like this:
                   7287: 
                   7288: .../x11/gtk3/work/gtk+-3.24.12/gdk/gdktypes.h:35:10:
                   7289:     fatal error: pango/pango.h: No such file or directory
                   7290: 
                   7291: The proper way to fix this problem depends on the type of the header, which is
                   7292: described in the following sections.
                   7293: 
                   7294: 21.5.3.1. Headers from other packages
                   7295: 
                   7296: If the header name looks like it comes from a different package, that other
                   7297: package should be included via the buildlink3 framework.
                   7298: 
                   7299: First, look whether the header is somewhere in the buildlink3 directory below
                   7300: WRKDIR. In the above case of the missing Pango header:
                   7301: 
                   7302: $ find work/.buildlink/ -print | grep -F pango/pango.h
                   7303: 
                   7304: In the case of Pango, the output is:
                   7305: 
                   7306: work/.buildlink/include/pango-1.0/pango/pango.h
                   7307: 
                   7308: If the pango/pango.h file were placed directly in the .buildlink directory, it
                   7309: would have been found automatically. There is an extra pango-1.0 path component
                   7310: though, which means that the compiler command line must contain an option of
                   7311: the form -I${BUILDLINK3_PREFIX.pango}/include/pango-1.0. In most cases this
                   7312: option is generated by the configure script, which can be examined using:
                   7313: 
                   7314: $ $ grep -o '[-]I[^[:space:]]*/pango[^[:space:]]*' work/*/Makefile
                   7315: -I/usr/pkg/include/pango-1.0
                   7316: -I/usr/pkg/include/pango-1.0
                   7317: -I/usr/pkg/include/pango-1.0
                   7318: -I/usr/pkg/include/pango-1.0
                   7319: -I/usr/pkg/include/pango-1.0
                   7320: 
                   7321: This looks good. These options are transformed by the buildlink wrapper to
                   7322: refer to the correct path inside work/.buildlink.
                   7323: 
                   7324: Since the compilation fails though, examine the compiler command lines in work
                   7325: /.work.log to see whether the -I option is included in the particular command
                   7326: line.
                   7327: 
                   7328: To further analyze the situation, run bmake build-env, which sets up an
                   7329: interactive, realistic environment including all the pkgsrc wrapper commands
                   7330: and environment variables. From there, try to compile some simple example
                   7331: programs that use the header.
                   7332: 
                   7333: 21.5.3.2. Headers generated during the build
                   7334: 
                   7335: If the name of the header seems to come from the package itself, and if the
                   7336: build is run with parallel jobs, the package may have some undeclared
                   7337: dependencies between the .c and the .h files, and a C file is compiled before
                   7338: its required header is generated.
                   7339: 
                   7340: To see whether the build runs with parallel jobs, run bmake show-all-build |
                   7341: grep JOBS. Its output looks like this:
                   7342: 
                   7343:   usr   MAKE_JOBS=              7
                   7344:   pkg   MAKE_JOBS_SAFE          # undefined
                   7345:   def   _MAKE_JOBS_N=           7
                   7346: 
                   7347: In this case the pkgsrc user has asked pkgsrc to build packages with 7 jobs in
                   7348: parallel (MAKE_JOBS). The package could have disabled parallel builds by
                   7349: setting MAKE_JOBS_SAFE to no, but in this case it hasn't.
                   7350: 
                   7351: To see whether the build failure is caused by parallel builds, first save the
                   7352: exact error message and a bit of context, maybe you need it later for reporting
                   7353: a bug. Next, run:
                   7354: 
                   7355: MAKE_JOBS_SAFE=no bmake clean build
                   7356: 
                   7357: If that succeeds, file a bug report against the pkgsrc package, including the
                   7358: exact error message and the contents of your mk.conf file.
                   7359: 
1.173     rillig   7360: 21.5.3.3. Symlinks
                   7361: 
                   7362: Pkgsrc does not work reliably if any of LOCALBASE, VARBASE or WRKDIR contains a
                   7363: symlink. Since 2019Q2, the pkgsrc bootstrap program prevents installing pkgsrc
                   7364: in symlink-based directories. Existing pkgsrc installations are not checked for
                   7365: symlinks though.
                   7366: 
                   7367: The "No such file or directory" error messages are a typical symptom of
                   7368: symlinks, and it's quite difficult to find out that this is the actual cause.
                   7369: 
                   7370: 21.5.3.4. Stale working directories
                   7371: 
                   7372: When building a hierarchy of packages, it may happen that one package is built
                   7373: and then pkgsrc is updated. This situation can provoke various hard to diagnose
                   7374: build errors. To clean up the situation:
                   7375: 
1.223     nia      7376: $ (cd ../../ && cat mk/bsd.pkg.mk >/dev/null && rm -rf */*/work)
1.173     rillig   7377: 
1.223     nia      7378: (The only purpose of the bsd.pkg.mk is to prevent running this command in the
                   7379: wrong directory.)
1.173     rillig   7380: 
                   7381: If you have set WRKOBJDIR in mk.conf, remove that directory as well.
                   7382: 
                   7383: 21.5.3.5. Other possible reasons
                   7384: 
                   7385: On platforms other than BSD, third-party packages are installed in /usr/
                   7386: include, together with the base system. This means that pkgsrc cannot
                   7387: distinguish between headers provided by the base system (which it needs) and
                   7388: headers from third-party packages (which are often included in pkgsrc as well).
                   7389: This can lead to subtle version mismatches.
                   7390: 
                   7391: In pkgsrc installations that have been active for several years, it may happen
                   7392: that some files are manually deleted. To exclude this unlikely reason, run 
                   7393: pkg_admin check.
                   7394: 
                   7395: It may help to run pkg_admin rebuild-tree to check/fix dependencies.
                   7396: 
                   7397: If all of the above doesn't help, see Chapter 2, Getting help for contact
                   7398: information. Be prepared to describe what you have tried so far and what any
                   7399: error messages were.
                   7400: 
1.172     rillig   7401: 21.5.4. Undefined reference to "..."
1.1       dsieger  7402: 
                   7403: This error message often means that a package did not link to a shared library
                   7404: it needs. The following functions are known to cause this error message over
                   7405: and over.
                   7406: 
                   7407: +-----------------------------------------------------+
                   7408: |        Function         |Library |Affected platforms|
                   7409: |-------------------------+--------+------------------|
                   7410: |accept, bind, connect    |-lsocket|Solaris           |
                   7411: |-------------------------+--------+------------------|
                   7412: |crypt                    |-lcrypt |DragonFly, NetBSD |
                   7413: |-------------------------+--------+------------------|
                   7414: |dlopen, dlsym            |-ldl    |Linux             |
                   7415: |-------------------------+--------+------------------|
                   7416: |gethost*                 |-lnsl   |Solaris           |
                   7417: |-------------------------+--------+------------------|
                   7418: |inet_aton                |-lresolv|Solaris           |
                   7419: |-------------------------+--------+------------------|
                   7420: |nanosleep, sem_*, timer_*|-lrt    |Solaris           |
                   7421: |-------------------------+--------+------------------|
                   7422: |openpty                  |-lutil  |Linux             |
                   7423: +-----------------------------------------------------+
                   7424: 
1.223     nia      7425: To fix these linker errors, it is often sufficient to add LIBS.OperatingSystem+
                   7426: = -lfoo to the package Makefile and then run bmake clean; bmake.
1.1       dsieger  7427: 
1.223     nia      7428: 21.5.4.1. The SunPro compiler and inline functions
1.1       dsieger  7429: 
                   7430: When you are using the SunPro compiler, there is another possibility. That
                   7431: compiler cannot handle the following code:
                   7432: 
                   7433: extern int extern_func(int);
                   7434: 
                   7435: static inline int
                   7436: inline_func(int x)
                   7437: {
                   7438:         return extern_func(x);
                   7439: }
                   7440: 
                   7441: int main(void)
                   7442: {
                   7443:         return 0;
                   7444: }
                   7445: 
                   7446: It generates the code for inline_func even if that function is never used. This
                   7447: code then refers to extern_func, which can usually not be resolved. To solve
                   7448: this problem you can try to tell the package to disable inlining of functions.
                   7449: 
1.228     gutterid 7450: 21.5.4.2. Missing atomic functions
                   7451: 
                   7452: When building for older machine architectures (e.g., i386, PowerPC), builds may
                   7453: fail because the package expects modern 64-bit atomic functions which the
                   7454: underlying hardware either doesn't support, or will only support with specific
                   7455: compiler flags. This is generally handled via inclusion of mk/atomic64.mk.
                   7456: 
1.172     rillig   7457: 21.5.5. Running out of memory
1.1       dsieger  7458: 
                   7459: Sometimes packages fail to build because the compiler runs into an operating
                   7460: system specific soft limit. With the UNLIMIT_RESOURCES variable pkgsrc can be
1.223     nia      7461: told to unlimit the resources. The allowed values are any combination of "
                   7462: cputime", "datasize", "memorysize", "stacksize" and "virtualsize". Setting this
                   7463: variable is similar to running the shell builtin ulimit command to raise the
                   7464: maximum data segment size or maximum stack size of a process, respectively, to
                   7465: their hard limits.
1.1       dsieger  7466: 
1.154     rillig   7467: 21.6. The install phase
1.1       dsieger  7468: 
1.154     rillig   7469: 21.6.1. Creating needed directories
1.1       dsieger  7470: 
                   7471: The BSD-compatible install supplied with some operating systems cannot create
                   7472: more than one directory at a time. As such, you should call ${INSTALL_*_DIR}
                   7473: like this:
                   7474: 
                   7475: ${INSTALL_DATA_DIR} ${PREFIX}/dir1
                   7476: ${INSTALL_DATA_DIR} ${PREFIX}/dir2
                   7477: 
1.223     nia      7478: Instead of running the install commands directly, you can also append "dir1
                   7479: dir2" to the INSTALLATION_DIRS variable, which will automatically do the right
                   7480: thing.
1.1       dsieger  7481: 
1.154     rillig   7482: 21.6.2. Where to install documentation
1.1       dsieger  7483: 
                   7484: In general, documentation should be installed into ${PREFIX}/share/doc/$
1.223     nia      7485: {PKGBASE} or ${PREFIX}/share/doc/${PKGNAME_NOREV} (the latter includes the
                   7486: version number of the package).
1.1       dsieger  7487: 
                   7488: Many modern packages using GNU autoconf allow to set the directory where HTML
                   7489: documentation is installed with the "--with-html-dir" option. Sometimes using
                   7490: this flag is needed because otherwise the documentation ends up in ${PREFIX}/
1.223     nia      7491: share/doc/html or other places. In pkgsrc, the HTML documentation should go
                   7492: into the package-specific directory, just like any other documentation.
1.1       dsieger  7493: 
                   7494: An exception to the above is that library API documentation generated with the
                   7495: textproc/gtk-doc tools, for use by special browsers (devhelp) should be left at
                   7496: their default location, which is ${PREFIX}/share/gtk-doc. Such documentation
                   7497: can be recognized from files ending in .devhelp or .devhelp2. (It is also
                   7498: acceptable to install such files in ${PREFIX}/share/doc/${PKGBASE} or ${PREFIX}
                   7499: /share/doc/${PKGNAME}; the .devhelp* file must be directly in that directory
                   7500: then, no additional subdirectory level is allowed in this case. This is usually
                   7501: achieved by using "--with-html-dir=${PREFIX}/share/doc". ${PREFIX}/share/
                   7502: gtk-doc is preferred though.)
                   7503: 
1.154     rillig   7504: 21.6.3. Installing highscore files
1.1       dsieger  7505: 
                   7506: Certain packages, most of them in the games category, install a score file that
                   7507: allows all users on the system to record their highscores. In order for this to
                   7508: work, the binaries need to be installed setgid and the score files owned by the
1.36      wiz      7509: appropriate group and/or owner (traditionally the "games" user/group). Set
                   7510: USE_GAMESGROUP to yes to support this. The following variables, documented in
                   7511: more detail in mk/defaults/mk.conf, control this behaviour: GAMEDATAMODE,
1.100     leot     7512: GAMEDIRMODE, GAMES_GROUP, GAMEMODE, GAME_USER. Other useful variables are:
                   7513: GAMEDIR_PERMS, GAMEDATA_PERMS and SETGID_GAMES_PERMS.
                   7514: 
                   7515: An example that illustrates some of the variables described above is games/
                   7516: moon-buggy. OWN_DIRS_PERMS is used to properly set directory permissions of the
                   7517: directory where the scorefile is saved, REQD_FILES_PERMS is used to create a
                   7518: dummy scorefile (mbscore) with the proper permissions and SPECIAL_PERMS is used
                   7519: to install setgid the game binary:
                   7520: 
                   7521: USE_GAMESGROUP=         yes
                   7522: 
                   7523: BUILD_DEFS+=            VARBASE
                   7524: 
                   7525: OWN_DIRS_PERMS+=        ${VARBASE}/games/moon-buggy ${GAMEDIR_PERMS}
                   7526: REQD_FILES_PERMS+=      /dev/null ${VARBASE}/games/moon-buggy/mbscore ${GAMEDATA_PERMS}
                   7527: SPECIAL_PERMS+=         ${PREFIX}/bin/moon-buggy ${SETGID_GAMES_PERMS}
                   7528: 
                   7529: Various INSTALL_* variables are also available: INSTALL_GAME to install setgid
                   7530: game binaries, INSTALL_GAME_DIR to install game directories that are needed to
                   7531: be accessed by setgid games and INSTALL_GAME_DATA to install scorefiles.
1.1       dsieger  7532: 
1.14      jmcneill 7533: A package should therefore never hard code file ownership or access permissions
1.100     leot     7534: but rely on *_PERMS as described above or alternatively on INSTALL_GAME,
                   7535: INSTALL_GAME_DATA and INSTALL_GAME_DIR to set these correctly.
1.1       dsieger  7536: 
1.154     rillig   7537: 21.6.4. Adding DESTDIR support to packages
1.4       rillig   7538: 
1.14      jmcneill 7539: DESTDIR support means that a package installs into a staging directory, not the
                   7540: final location of the files. Then a binary package is created which can be used
                   7541: for installation as usual. There are two ways: Either the package must install
1.25      wiz      7542: as root ("destdir") or the package can install as non-root user ("user-destdir"
                   7543: ).
1.14      jmcneill 7544: 
1.113     leot     7545:   * PKG_DESTDIR_SUPPORT has to be set to "destdir" or "user-destdir". By
                   7546:     default PKG_DESTDIR_SUPPORT is set to "user-destdir" to help catching more
                   7547:     potential packaging problems. If bsd.prefs.mk is included in the Makefile,
                   7548:     PKG_DESTDIR_SUPPORT needs to be set before the inclusion.
1.14      jmcneill 7549: 
1.4       rillig   7550:   * All installation operations have to be prefixed with ${DESTDIR}.
                   7551: 
                   7552:   * automake gets this DESTDIR mostly right automatically. Many manual rules
                   7553:     and pre/post-install often are incorrect; fix them.
                   7554: 
1.17      imil     7555:   * If files are installed with special owner/group use SPECIAL_PERMS.
1.4       rillig   7556: 
                   7557:   * In general, packages should support UNPRIVILEGED to be able to use DESTDIR.
                   7558: 
1.154     rillig   7559: 21.6.5. Packages with hardcoded paths to other interpreters
1.1       dsieger  7560: 
                   7561: Your package may also contain scripts with hardcoded paths to other
1.203     nia      7562: interpreters besides (or as well as) Perl. To correct the full pathname to the
1.1       dsieger  7563: script interpreter, you need to set the following definitions in your Makefile
                   7564: (we shall use tclsh in this example):
                   7565: 
                   7566: REPLACE_INTERPRETER+=   tcl
                   7567: REPLACE.tcl.old=        .*/bin/tclsh
                   7568: REPLACE.tcl.new=        ${PREFIX}/bin/tclsh
                   7569: REPLACE_FILES.tcl=      # list of tcl scripts which need to be fixed,
                   7570: # relative to ${WRKSRC}, just as in REPLACE_PERL
                   7571: 
1.203     nia      7572: 21.6.6. Packages installing Perl modules
1.1       dsieger  7573: 
                   7574: Makefiles of packages providing perl5 modules should include the Makefile
                   7575: fragment ../../lang/perl5/module.mk. It provides a do-configure target for the
                   7576: standard perl configuration for such modules as well as various hooks to tune
                   7577: this configuration. See comments in this file for details.
                   7578: 
                   7579: Perl5 modules will install into different places depending on the version of
                   7580: perl used during the build process. To address this, pkgsrc will append lines
                   7581: to the PLIST corresponding to the files listed in the installed .packlist file
                   7582: generated by most perl5 modules. This is invoked by defining PERL5_PACKLIST to
1.48      wiz      7583: a space-separated list of packlist files relative to PERL5_PACKLIST_DIR
                   7584: (PERL5_INSTALLVENDORARCH by default), e.g.:
1.1       dsieger  7585: 
1.48      wiz      7586: PERL5_PACKLIST= auto/Pg/.packlist
1.1       dsieger  7587: 
1.48      wiz      7588: The perl5 config variables installarchlib, installscript, installvendorbin,
                   7589: installvendorscript, installvendorarch, installvendorlib, installvendorman1dir,
                   7590: and installvendorman3dir represent those locations in which components of perl5
                   7591: modules may be installed, provided as variable with uppercase and prefixed with
                   7592: PERL5_, e.g. PERL5_INSTALLARCHLIB and may be used by perl5 packages that don't
                   7593: have a packlist. These variables are also substituted for in the PLIST as
                   7594: uppercase prefixed with PERL5_SUB_.
1.1       dsieger  7595: 
1.154     rillig   7596: 21.6.7. Packages installing info files
1.1       dsieger  7597: 
                   7598: Some packages install info files or use the "makeinfo" or "install-info"
                   7599: commands. INFO_FILES should be defined in the package Makefile so that INSTALL
                   7600: and DEINSTALL scripts will be generated to handle registration of the info
                   7601: files in the Info directory file. The "install-info" command used for the info
                   7602: files registration is either provided by the system, or by a special purpose
                   7603: package automatically added as dependency if needed.
                   7604: 
                   7605: PKGINFODIR is the directory under ${PREFIX} where info files are primarily
                   7606: located. PKGINFODIR defaults to "info" and can be overridden by the user.
                   7607: 
                   7608: The info files for the package should be listed in the package PLIST; however
                   7609: any split info files need not be listed.
                   7610: 
                   7611: A package which needs the "makeinfo" command at build time must add "makeinfo"
                   7612: to USE_TOOLS in its Makefile. If a minimum version of the "makeinfo" command is
                   7613: needed it should be noted with the TEXINFO_REQD variable in the package
                   7614: Makefile. By default, a minimum version of 3.12 is required. If the system does
                   7615: not provide a makeinfo command or if it does not match the required minimum, a
                   7616: build dependency on the devel/gtexinfo package will be added automatically.
                   7617: 
                   7618: The build and installation process of the software provided by the package
                   7619: should not use the install-info command as the registration of info files is
1.25      wiz      7620: the task of the package INSTALL script, and it must use the appropriate 
1.1       dsieger  7621: makeinfo command.
                   7622: 
                   7623: To achieve this goal, the pkgsrc infrastructure creates overriding scripts for
                   7624: the install-info and makeinfo commands in a directory listed early in PATH.
                   7625: 
                   7626: The script overriding install-info has no effect except the logging of a
                   7627: message. The script overriding makeinfo logs a message and according to the
                   7628: value of TEXINFO_REQD either runs the appropriate makeinfo command or exit on
                   7629: error.
                   7630: 
1.154     rillig   7631: 21.6.8. Packages installing man pages
1.1       dsieger  7632: 
                   7633: All packages that install manual pages should install them into the same
                   7634: directory, so that there is one common place to look for them. In pkgsrc, this
                   7635: place is ${PREFIX}/${PKGMANDIR}, and this expression should be used in
1.25      wiz      7636: packages. The default for PKGMANDIR is "man". Another often-used value is "
                   7637: share/man".
1.1       dsieger  7638: 
                   7639: Note
                   7640: 
                   7641: The support for a custom PKGMANDIR is far from complete.
                   7642: 
                   7643: The PLIST files can just use man/ as the top level directory for the man page
                   7644: file entries, and the pkgsrc framework will convert as needed. In all other
                   7645: places, the correct PKGMANDIR must be used.
                   7646: 
                   7647: Packages that are configured with GNU_CONFIGURE set as "yes", by default will
                   7648: use the ./configure --mandir switch to set where the man pages should be
                   7649: installed. The path is GNU_CONFIGURE_MANDIR which defaults to ${PREFIX}/$
                   7650: {PKGMANDIR}.
                   7651: 
                   7652: Packages that use GNU_CONFIGURE but do not use --mandir, can set
                   7653: CONFIGURE_HAS_MANDIR to "no". Or if the ./configure script uses a non-standard
                   7654: use of --mandir, you can set GNU_CONFIGURE_MANDIR as needed.
                   7655: 
1.184     rillig   7656: See Section 19.5, "Man page compression" for information on installation of
1.1       dsieger  7657: compressed manual pages.
                   7658: 
1.203     nia      7659: 21.6.9. Packages installing X11 fonts
1.1       dsieger  7660: 
                   7661: If a package installs font files, you will need to rebuild the fonts database
                   7662: in the directory where they get installed at installation and deinstallation
                   7663: time. This can be automatically done by using the pkginstall framework.
                   7664: 
                   7665: You can list the directories where fonts are installed in the FONTS_DIRS.type
                   7666: variables, where type can be one of "ttf", "type1" or "x11". Also make sure
                   7667: that the database file fonts.dir is not listed in the PLIST.
                   7668: 
                   7669: Note that you should not create new directories for fonts; instead use the
                   7670: standard ones to avoid that the user needs to manually configure his X server
                   7671: to find them.
                   7672: 
1.203     nia      7673: 21.6.10. Packages installing SGML or XML data
1.1       dsieger  7674: 
                   7675: If a package installs SGML or XML data files that need to be registered in
                   7676: system-wide catalogs (like DTDs, sub-catalogs, etc.), you need to take some
                   7677: extra steps:
                   7678: 
                   7679:  1. Include ../../textproc/xmlcatmgr/catalogs.mk in your Makefile, which takes
                   7680:     care of registering those files in system-wide catalogs at installation and
                   7681:     deinstallation time.
                   7682: 
                   7683:  2. Set SGML_CATALOGS to the full path of any SGML catalogs installed by the
                   7684:     package.
                   7685: 
                   7686:  3. Set XML_CATALOGS to the full path of any XML catalogs installed by the
                   7687:     package.
                   7688: 
                   7689:  4. Set SGML_ENTRIES to individual entries to be added to the SGML catalog.
                   7690:     These come in groups of three strings; see xmlcatmgr(1) for more
                   7691:     information (specifically, arguments recognized by the 'add' action). Note
                   7692:     that you will normally not use this variable.
                   7693: 
                   7694:  5. Set XML_ENTRIES to individual entries to be added to the XML catalog. These
                   7695:     come in groups of three strings; see xmlcatmgr(1) for more information
                   7696:     (specifically, arguments recognized by the 'add' action). Note that you
                   7697:     will normally not use this variable.
                   7698: 
1.203     nia      7699: 21.6.11. Packages installing extensions to the MIME database
1.1       dsieger  7700: 
                   7701: If a package provides extensions to the MIME database by installing .xml files
                   7702: inside ${PREFIX}/share/mime/packages, you need to take some extra steps to
                   7703: ensure that the database is kept consistent with respect to these new files:
                   7704: 
                   7705:  1. Include ../../databases/shared-mime-info/mimedb.mk (avoid using the
                   7706:     buildlink3.mk file from this same directory, which is reserved for
                   7707:     inclusion from other buildlink3.mk files). It takes care of rebuilding the
                   7708:     MIME database at installation and deinstallation time, and disallows any
                   7709:     access to it directly from the package.
                   7710: 
1.25      wiz      7711:  2. Check the PLIST and remove any entries under the share/mime directory, 
1.1       dsieger  7712:     except for files saved under share/mime/packages. The former are handled
                   7713:     automatically by the update-mime-database program, but the latter are
                   7714:     package-dependent and must be removed by the package that installed them in
                   7715:     the first place.
                   7716: 
                   7717:  3. Remove any share/mime/* directories from the PLIST. They will be handled by
                   7718:     the shared-mime-info package.
                   7719: 
1.203     nia      7720: 21.6.12. Packages using intltool
1.1       dsieger  7721: 
                   7722: If a package uses intltool during its build, add intltool to the USE_TOOLS,
                   7723: which forces it to use the intltool package provided by pkgsrc, instead of the
                   7724: one bundled with the distribution file.
                   7725: 
                   7726: This tracks intltool's build-time dependencies and uses the latest available
                   7727: version; this way, the package benefits of any bug fixes that may have appeared
                   7728: since it was released.
                   7729: 
1.203     nia      7730: 21.6.13. Packages installing startup scripts
1.1       dsieger  7731: 
                   7732: If a package contains a rc.d script, it won't be copied into the startup
                   7733: directory by default, but you can enable it, by adding the option
1.4       rillig   7734: PKG_RCD_SCRIPTS=YES in mk.conf. This option will copy the scripts into /etc/
                   7735: rc.d when a package is installed, and it will automatically remove the scripts
                   7736: when the package is deinstalled.
1.1       dsieger  7737: 
1.203     nia      7738: 21.6.14. Packages installing TeX modules
1.1       dsieger  7739: 
                   7740: If a package installs TeX packages into the texmf tree, the ls-R database of
                   7741: the tree needs to be updated.
                   7742: 
                   7743: Note
                   7744: 
1.23      jakllsch 7745: Except the main TeX packages such as kpathsea, packages should install files
                   7746: into ${PREFIX}/share/texmf-dist, not ${PREFIX}/share/texmf.
1.1       dsieger  7747: 
1.23      jakllsch 7748:  1. Include ../../print/kpathsea/texmf.mk. This takes care of rebuilding the
                   7749:     ls-R database at installation and deinstallation time.
1.1       dsieger  7750: 
1.23      jakllsch 7751:  2. If your package installs files into a texmf tree other than the one at $
                   7752:     {PREFIX}/share/texmf-dist, set TEX_TEXMF_DIRS to the list of all texmf
                   7753:     trees that need database update.
1.1       dsieger  7754: 
                   7755:     If your package also installs font map files that need to be registered
1.30      dholland 7756:     using updmap, include ../../print/tex-tetex/map.mk and set TEX_MAP_FILES
                   7757:     and/or TEX_MIXEDMAP_FILES to the list of all such font map files. Then 
                   7758:     updmap will be run automatically at installation/deinstallation to enable/
                   7759:     disable font map files for TeX output drivers.
1.1       dsieger  7760: 
                   7761:  3. Make sure that none of ls-R databases are included in PLIST, as they will
1.30      dholland 7762:     be removed only by the kpathsea package.
1.1       dsieger  7763: 
1.203     nia      7764: 21.6.15. Packages supporting running binaries in emulation
1.1       dsieger  7765: 
                   7766: There are some packages that provide libraries and executables for running
                   7767: binaries from a one operating system on a different one (if the latter supports
                   7768: it). One example is running Linux binaries on NetBSD.
                   7769: 
                   7770: The pkgtools/rpm2pkg helps in extracting and packaging Linux rpm packages.
                   7771: 
                   7772: The CHECK_SHLIBS can be set to no to avoid the check-shlibs target, which tests
                   7773: if all libraries for each installed executable can be found by the dynamic
                   7774: linker. Since the standard dynamic linker is run, this fails for emulation
                   7775: packages, because the libraries used by the emulation are not in the standard
                   7776: directories.
                   7777: 
1.203     nia      7778: 21.6.16. Packages installing hicolor icons
1.1       dsieger  7779: 
                   7780: If a package installs images under the share/icons/hicolor and/or updates the
                   7781: share/icons/hicolor/icon-theme.cache database, you need to take some extra
                   7782: steps to make sure that the shared theme directory is handled appropriately and
                   7783: that the cache database is rebuilt:
                   7784: 
                   7785:  1. Include ../../graphics/hicolor-icon-theme/buildlink3.mk.
                   7786: 
                   7787:  2. Check the PLIST and remove the entry that refers to the theme cache.
                   7788: 
                   7789:  3. Ensure that the PLIST does not remove the shared icon directories from the
                   7790:     share/icons/hicolor hierarchy because they will be handled automatically.
                   7791: 
                   7792: The best way to verify that the PLIST is correct with respect to the last two
                   7793: points is to regenerate it using make print-PLIST.
                   7794: 
1.203     nia      7795: 21.6.17. Packages installing desktop files
1.1       dsieger  7796: 
                   7797: If a package installs .desktop files under share/applications and these include
1.54      rodent   7798: MIME information (MimeType key), you need to take extra steps to ensure that
                   7799: they are registered into the MIME database:
1.1       dsieger  7800: 
                   7801:  1. Include ../../sysutils/desktop-file-utils/desktopdb.mk.
                   7802: 
                   7803:  2. Check the PLIST and remove the entry that refers to the share/applications/
                   7804:     mimeinfo.cache file. It will be handled automatically.
                   7805: 
                   7806: The best way to verify that the PLIST is correct with respect to the last point
                   7807: is to regenerate it using make print-PLIST.
                   7808: 
1.154     rillig   7809: 21.7. Marking packages as having problems
1.1       dsieger  7810: 
1.23      jakllsch 7811: In some cases one does not have the time to solve a problem immediately. In
                   7812: this case, one can plainly mark a package as broken. For this, one just sets
                   7813: the variable BROKEN to the reason why the package is broken (similar to the
1.162     rillig   7814: PKG_FAIL_REASON variable). A user trying to build the package will immediately
                   7815: be shown this message, and the build will not be even tried.
1.1       dsieger  7816: 
1.23      jakllsch 7817: BROKEN packages are removed from pkgsrc in irregular intervals.
1.1       dsieger  7818: 
1.184     rillig   7819: Chapter 22. GNOME packaging and porting
                   7820: 
                   7821: Table of Contents
                   7822: 
                   7823: 22.1. Meta packages
                   7824: 22.2. Packaging a GNOME application
                   7825: 22.3. Updating GNOME to a newer version
                   7826: 22.4. Patching guidelines
                   7827: 
                   7828: Quoting GNOME's web site:
                   7829: 
                   7830:     The GNOME project provides two things: The GNOME desktop environment, an
                   7831:     intuitive and attractive desktop for users, and the GNOME development
                   7832:     platform, an extensive framework for building applications that integrate
                   7833:     into the rest of the desktop.
                   7834: 
                   7835: pkgsrc provides a seamless way to automatically build and install a complete
                   7836: GNOME environment under many different platforms. We can say with confidence
                   7837: that pkgsrc is one of the most advanced build and packaging systems for GNOME
                   7838: due to its included technologies buildlink3, the wrappers and tools framework
                   7839: and automatic configuration file management. Lots of efforts are put into
                   7840: achieving a completely clean deinstallation of installed software components.
                   7841: 
                   7842: Given that pkgsrc is NetBSD's official packaging system, the above also means
                   7843: that great efforts are put into making GNOME work under this operating system.
                   7844: 
                   7845: This chapter is aimed at pkgsrc developers and other people interested in
                   7846: helping our GNOME porting and packaging efforts. It provides instructions on
                   7847: how to manage the existing packages and some important information regarding
                   7848: their internals.
                   7849: 
                   7850: 22.1. Meta packages
                   7851: 
                   7852: pkgsrc includes three GNOME-related meta packages:
                   7853: 
                   7854:   * meta-pkgs/gnome-base: Provides the core GNOME desktop environment. It only
                   7855:     includes the necessary bits to get it to boot correctly, although it may
                   7856:     lack important functionality for daily operation. The idea behind this
                   7857:     package is to let end users build their own configurations on top of this
                   7858:     one, first installing this meta package to achieve a functional setup and
                   7859:     then adding individual applications.
                   7860: 
                   7861:   * meta-pkgs/gnome: Provides a complete installation of the GNOME platform and
                   7862:     desktop as defined by the GNOME project; this is based on the components
                   7863:     distributed in the platform/x.y/x.y.z/sources and desktop/x.y/x.y.z/sources
                   7864:     directories of the official FTP server. Developer-only tools found in those
                   7865:     directories are not installed unless required by some other component to
                   7866:     work properly. Similarly, packages from the bindings set (bindings/x.y/
                   7867:     x.y.z/sources) are not pulled in unless required as a dependency for an
                   7868:     end-user component. This package "extends" meta-pkgs/gnome-base.
                   7869: 
                   7870:   * meta-pkgs/gnome-devel: Installs all the tools required to build a GNOME
                   7871:     component when fetched from the CVS repository. These are required to let
                   7872:     the autogen.sh scripts work appropriately.
                   7873: 
                   7874: In all these packages, the DEPENDS lines are sorted in a way that eases
                   7875: updates: a package may depend on other packages listed before it but not on any
                   7876: listed after it. It is very important to keep this order to ease updates so... 
                   7877: do not change it to alphabetical sorting!
                   7878: 
                   7879: 22.2. Packaging a GNOME application
                   7880: 
                   7881: Almost all GNOME applications are written in C and use a common set of tools as
                   7882: their build system. Things get different with the new bindings to other
                   7883: languages (such as Python), but the following will give you a general idea on
                   7884: the minimum required tools:
                   7885: 
                   7886:   * Almost all GNOME applications use the GNU Autotools as their build system.
                   7887:     As a general rule you will need to tell this to your package:
                   7888: 
1.223     nia      7889:     GNU_CONFIGURE=  yes
                   7890:     USE_LIBTOOL=    yes
                   7891:     USE_TOOLS+=     gmake
1.184     rillig   7892: 
                   7893:   * If the package uses pkg-config to detect dependencies, add this tool to the
                   7894:     list of required utilities:
                   7895: 
1.223     nia      7896:     USE_TOOLS+=     pkg-config
1.184     rillig   7897: 
                   7898:     Also use pkgtools/verifypc at the end of the build process to ensure that
                   7899:     you did not miss to specify any dependency in your package and that the
                   7900:     version requirements are all correct.
                   7901: 
                   7902:   * If the package uses intltool, be sure to add intltool to the USE_TOOLS to
                   7903:     handle dependencies and to force the package to use the latest available
                   7904:     version.
                   7905: 
                   7906:   * If the package uses gtk-doc (a documentation generation utility), do not
                   7907:     add a dependency on it. The tool is rather big and the distfile should come
                   7908:     with pregenerated documentation anyway; if it does not, it is a bug that
                   7909:     you ought to report. For such packages you should disable gtk-doc (unless
                   7910:     it is the default):
                   7911: 
1.223     nia      7912:     CONFIGURE_ARGS+=        --disable-gtk-doc
1.184     rillig   7913: 
                   7914:     The default location of installed HTML files (share/gtk-doc/<package-name>)
                   7915:     is correct and should not be changed unless the package insists on
                   7916:     installing them somewhere else. Otherwise programs as devhelp will not be
                   7917:     able to open them. You can do that with an entry similar to:
1.1       dsieger  7918: 
1.223     nia      7919:     CONFIGURE_ARGS+=        --with-html-dir=${PREFIX}/share/gtk-doc/...
1.1       dsieger  7920: 
1.184     rillig   7921: GNOME uses multiple shared directories and files under the installation prefix
                   7922: to maintain databases. In this context, shared means that those exact same
                   7923: directories and files are used among several different packages, leading to
                   7924: conflicts in the PLIST. pkgsrc currently includes functionality to handle the
                   7925: most common cases, so you have to forget about using @unexec ${RMDIR} lines in
                   7926: your file lists and omitting shared files from them. If you find yourself doing
                   7927: those, your package is most likely incorrect.
1.1       dsieger  7928: 
1.184     rillig   7929: The following table lists the common situations that result in using shared
                   7930: directories or files. For each of them, the appropriate solution is given.
                   7931: After applying the solution be sure to regenerate the package's file list with 
                   7932: make print-PLIST and ensure it is correct.
1.1       dsieger  7933: 
1.184     rillig   7934: Table 22.1. PLIST handling for GNOME packages
1.1       dsieger  7935: 
1.184     rillig   7936: +-----------------------------------------------------------------------------+
                   7937: |             If the package...             |             Then...             |
                   7938: |-------------------------------------------+---------------------------------|
1.203     nia      7939: |Installs icons under the share/icons/      |See Section 21.6.16, "Packages   |
                   7940: |hicolor hierarchy or updates share/icons/  |installing hicolor icons".       |
1.184     rillig   7941: |hicolor/icon-theme.cache.                  |                                 |
                   7942: |-------------------------------------------+---------------------------------|
1.203     nia      7943: |                                           |See Section 21.6.11, "Packages   |
1.184     rillig   7944: |Installs files under share/mime/packages.  |installing extensions to the MIME|
                   7945: |                                           |database".                       |
                   7946: |-------------------------------------------+---------------------------------|
1.203     nia      7947: |Installs .desktop files under share/       |See Section 21.6.17, "Packages   |
1.184     rillig   7948: |applications and these include MIME        |installing desktop files".       |
                   7949: |information.                               |                                 |
                   7950: +-----------------------------------------------------------------------------+
1.1       dsieger  7951: 
                   7952: 
1.184     rillig   7953: 22.3. Updating GNOME to a newer version
1.1       dsieger  7954: 
1.184     rillig   7955: When seeing GNOME as a whole, there are two kinds of updates:
1.1       dsieger  7956: 
1.184     rillig   7957: Major update
1.1       dsieger  7958: 
1.184     rillig   7959:     Given that there is still a very long way for GNOME 3 (if it ever appears),
                   7960:     we consider a major update one that goes from a 2.X version to a 2.Y one,
                   7961:     where Y is even and greater than X. These are hard to achieve because they
                   7962:     introduce lots of changes in the components' code and almost all GNOME
                   7963:     distfiles are updated to newer versions. Some of them can even break API
                   7964:     and ABI compatibility with the previous major version series. As a result,
                   7965:     the update needs to be done all at once to minimize breakage.
1.1       dsieger  7966: 
1.184     rillig   7967:     A major update typically consists of around 80 package updates and the
                   7968:     addition of some new ones.
1.1       dsieger  7969: 
1.184     rillig   7970: Minor update
1.1       dsieger  7971: 
1.184     rillig   7972:     We consider a minor update one that goes from a 2.A.X version to a 2.A.Y
                   7973:     one where Y is greater than X. These are easy to achieve because they do
                   7974:     not update all GNOME components, can be done in an incremental way and do
                   7975:     not break API nor ABI compatibility.
1.1       dsieger  7976: 
1.184     rillig   7977:     A minor update typically consists of around 50 package updates, although
                   7978:     the numbers here may vary a lot.
1.1       dsieger  7979: 
1.184     rillig   7980: In order to update the GNOME components in pkgsrc to a new stable release
                   7981: (either major or minor), the following steps should be followed:
1.1       dsieger  7982: 
1.184     rillig   7983:  1. Get a list of all the tarballs that form the new release by using the
                   7984:     following commands. These will leave the full list of the components'
                   7985:     distfiles into the list.txt file:
1.1       dsieger  7986: 
1.184     rillig   7987:     % echo ls "*.tar.bz2" | \
                   7988:         ftp -V ftp://ftp.gnome.org/pub/gnome/platform/x.y/x.y.z/sources/ | \
                   7989:         awk '{ print $9 }' >list.txt
                   7990:     % echo ls "*.tar.bz2" | \
                   7991:         ftp -V ftp://ftp.gnome.org/pub/gnome/desktop/x.y/x.y.z/sources/ | \
                   7992:         awk '{ print $9 }' >>list.txt
1.1       dsieger  7993: 
1.184     rillig   7994:  2. Open each meta package's Makefile and bump their version to the release you
                   7995:     are updating them to. The three meta packages should be always consistent
                   7996:     with versioning. Obviously remove any PKGREVISIONs that might be in them.
1.1       dsieger  7997: 
1.184     rillig   7998:  3. For each meta package, update all its DEPENDS lines to match the latest
                   7999:     versions as shown by the above commands. Do not list any newer version
                   8000:     (even if found in the FTP) because the meta packages are supposed to list
                   8001:     the exact versions that form a specific GNOME release. Exceptions are
                   8002:     permitted here if a newer version solves a serious issue in the overall
                   8003:     desktop experience; these typically come in the form of a revision bump in
                   8004:     pkgsrc, not in newer versions from the developers.
1.1       dsieger  8005: 
1.184     rillig   8006:     Packages not listed in the list.txt file should be updated to the latest
                   8007:     version available (if found in pkgsrc). This is the case, for example, of
                   8008:     the dependencies on the GNU Autotools in the meta-pkgs/gnome-devel meta
                   8009:     package.
1.1       dsieger  8010: 
1.184     rillig   8011:  4. Generate a patch from the modified meta packages and extract the list of
                   8012:     "new" lines. This will provide you an outline on what packages need to be
                   8013:     updated in pkgsrc and in what order:
1.1       dsieger  8014: 
1.184     rillig   8015:     % cvs diff -u gnome-devel gnome-base gnome | grep '^+D' >todo.txt
1.1       dsieger  8016: 
1.184     rillig   8017:  5. For major desktop updates it is recommended to zap all your installed
                   8018:     packages and start over from scratch at this point.
1.1       dsieger  8019: 
1.184     rillig   8020:  6. Now comes the longest step by far: iterate over the contents of todo.txt
                   8021:     and update the packages listed in it in order. For major desktop updates
                   8022:     none of these should be committed until the entire set is completed because
                   8023:     there are chances of breaking not-yet-updated packages.
1.1       dsieger  8024: 
1.184     rillig   8025:  7. Once the packages are up to date and working, commit them to the tree one
                   8026:     by one with appropriate log messages. At the end, commit the three meta
                   8027:     package updates and all the corresponding changes to the doc/CHANGES-<YEAR>
                   8028:     and pkgsrc/doc/TODO files.
1.1       dsieger  8029: 
1.184     rillig   8030: 22.4. Patching guidelines
1.1       dsieger  8031: 
1.184     rillig   8032: GNOME is a very big component in pkgsrc which approaches 100 packages. Please,
                   8033: it is very important that you always, always, always feed back any portability
                   8034: fixes you do to a GNOME package to the mainstream developers (see
                   8035: Section 12.3.5, "Feedback to the author"). This is the only way to get their
                   8036: attention on portability issues and to ensure that future versions can be built
                   8037: out-of-the box on NetBSD. The less custom patches in pkgsrc, the easier further
                   8038: updates are. Those developers in charge of issuing major GNOME updates will be
                   8039: grateful if you do that.
1.1       dsieger  8040: 
1.200     cirnatda 8041: The most common places to report bugs are the GNOME's GitLab and the
                   8042: freedesktop.org's GitLab. Not all components use these to track bugs, but most
                   8043: of them do. Do not be short on your reports: always provide detailed
1.184     rillig   8044: explanations of the current failure, how it can be improved to achieve maximum
1.200     cirnatda 8045: portability and, if at all possible, provide a patch against the main Git
                   8046: branch. The more verbose you are, the higher chances of your patch being
                   8047: accepted.
1.1       dsieger  8048: 
1.184     rillig   8049: Also, please avoid using preprocessor magic to fix portability issues. While
                   8050: the FreeBSD GNOME people are doing a great job in porting GNOME to their
                   8051: operating system, the official GNOME sources are now plagued by conditionals
                   8052: that check for __FreeBSD__ and similar macros. This hurts portability. Please
                   8053: see our patching guidelines (Section 12.3.4, "Patching guidelines") for more
                   8054: details.
1.1       dsieger  8055: 
1.154     rillig   8056: Chapter 23. Submitting and Committing
1.1       dsieger  8057: 
                   8058: Table of Contents
                   8059: 
1.154     rillig   8060: 23.1. Submitting binary packages
                   8061: 23.2. Submitting source packages (for non-NetBSD-developers)
                   8062: 23.3. General notes when adding, updating, or removing packages
                   8063: 23.4. Commit Messages
                   8064: 23.5. Committing: Adding a package to CVS
                   8065: 23.6. Updating a package to a newer version
                   8066: 23.7. Renaming a package in pkgsrc
                   8067: 23.8. Moving a package in pkgsrc
1.1       dsieger  8068: 
1.154     rillig   8069: 23.1. Submitting binary packages
1.1       dsieger  8070: 
                   8071: Our policy is that we accept binaries only from pkgsrc developers to guarantee
                   8072: that the packages don't contain any trojan horses etc. This is not to annoy
                   8073: anyone but rather to protect our users! You're still free to put up your
                   8074: home-made binary packages and tell the world where to get them. NetBSD
1.154     rillig   8075: developers doing bulk builds and wanting to upload them please see Chapter 8, 
1.66      asau     8076: Creating binary packages for everything in pkgsrc (bulk builds).
1.1       dsieger  8077: 
1.154     rillig   8078: 23.2. Submitting source packages (for non-NetBSD-developers)
1.1       dsieger  8079: 
1.218     nia      8080: Firstly, you can import new packages into pkgsrc-wip ("pkgsrc work-in-progress"
                   8081: ); see the homepage at https://pkgsrc.org/wip/ for details.
                   8082: 
                   8083: Next, check that your package is complete, compiles and runs well; see
1.184     rillig   8084: Chapter 14, Creating a new pkgsrc package from scratch and the rest of this
1.218     nia      8085: document. Run the pkgtools/pkglint tool and fix any errors that appear.
                   8086: 
                   8087: Finally, send a report to the pkgsrc bug tracking system, either with the
                   8088: send-pr(1) command, or if you don't have that, go to the web page https://
                   8089: www.NetBSD.org/support/send-pr.html, which contains some instructions and a
                   8090: link to a form where you can submit packages. The sysutils/gtk-send-pr package
                   8091: is also available as a substitute for either of the above two tools.
1.1       dsieger  8092: 
                   8093: In the form of the problem report, the category should be "pkg", the synopsis
                   8094: should include the package name and version number, and the description field
                   8095: should contain a short description of your package (contents of the COMMENT
1.218     nia      8096: variable or DESCR file are OK).
1.1       dsieger  8097: 
1.154     rillig   8098: 23.3. General notes when adding, updating, or removing packages
1.1       dsieger  8099: 
                   8100: Please note all package additions, updates, moves, and removals in pkgsrc/doc/
                   8101: CHANGES-YYYY. It's very important to keep this file up to date and conforming
                   8102: to the existing format, because it will be used by scripts to automatically
                   8103: update pages on www.NetBSD.org and other sites. Additionally, check the pkgsrc/
                   8104: doc/TODO file and remove the entry for the package you updated or removed, in
                   8105: case it was mentioned there.
                   8106: 
                   8107: When the PKGREVISION of a package is bumped, the change should appear in pkgsrc
                   8108: /doc/CHANGES-YYYY if it is security related or otherwise relevant. Mass bumps
                   8109: that result from a dependency being updated should not be mentioned. In all
                   8110: other cases it's the developer's decision.
                   8111: 
                   8112: There is a make target that helps in creating proper CHANGES-YYYY entries: make
                   8113: changes-entry. It uses the optional CTYPE and NETBSD_LOGIN_NAME variables. The
                   8114: general usage is to first make sure that your CHANGES-YYYY file is up-to-date
                   8115: (to avoid having to resolve conflicts later-on) and then to cd to the package
                   8116: directory. For package updates, make changes-entry is enough. For new packages,
                   8117: or package moves or removals, set the CTYPE variable on the command line to
1.4       rillig   8118: "Added", "Moved", or "Removed". You can set NETBSD_LOGIN_NAME in mk.conf if
1.23      jakllsch 8119: your local login name is not the same as your NetBSD login name. The target
                   8120: also automatically removes possibly existing entries for the package in the
                   8121: TODO file. Don't forget to commit the changes, e.g. by using make
1.66      asau     8122: commit-changes-entry! If you are not using a checkout directly from
1.23      jakllsch 8123: cvs.NetBSD.org, but e.g. a local copy of the repository, you can set
                   8124: USE_NETBSD_REPO=yes. This makes the cvs commands use the main repository.
1.1       dsieger  8125: 
1.154     rillig   8126: 23.4. Commit Messages
1.130     wiz      8127: 
                   8128: For several years, there have been mirrors of pkgsrc in fossil, git, and hg.
                   8129: Standard practise when using these tools is to make the first line of a commit
                   8130: message function as a summary that can be read without the rest, such as is
                   8131: commonly done with "git log --oneline". For this reason, we have the following
                   8132: guidelines for pkgsrc commit messages:
                   8133: 
1.131     wiz      8134:   * Start the commit message with a line that explains the big picture in 65
1.130     wiz      8135:     characters or less. When a commit is for one package, include the name of
                   8136:     the package. For updates, include the version to which it is updated.
                   8137: 
                   8138:   * Leave the next line empty.
                   8139: 
                   8140:   * Then come the details for the commit (changes in that package, reason for a
                   8141:     change) and any relevant PRs. Wrap this section.
                   8142: 
                   8143: Here is an example:
                   8144: 
                   8145:   libxslt: update to 1.0.30
                   8146: 
                   8147:   Changes since 1.0.29:
                   8148:   ...
                   8149: 
                   8150: 
                   8151: Here is another example:
                   8152: 
                   8153:   mk/bsd.pkg.mk: enable SSP by default on NetBSD
                   8154: 
                   8155:   (rationale)
                   8156: 
                   8157: 
                   8158: Commit messages are final: no "cvs admin" is allowed on the pkgsrc repository
                   8159: to change commit messages.
                   8160: 
1.154     rillig   8161: 23.5. Committing: Adding a package to CVS
1.1       dsieger  8162: 
                   8163: This section is only of interest for pkgsrc developers with write access to the
1.34      wiz      8164: pkgsrc repository.
                   8165: 
                   8166: When the package is finished, "cvs add" the files. Start by adding the
                   8167: directory and then files in the directory. Don't forget to add the new package
                   8168: to the category's Makefile. Make sure you don't forget any files; you can check
                   8169: by running "cvs status". An example:
                   8170: 
                   8171: $ cd .../pkgsrc/category
                   8172: $ cvs add pkgname
                   8173: $ cd pkgname
                   8174: $ cvs add DESCR Makefile PLIST distinfo buildlink3.mk patches
                   8175: $ cvs add patches/p*
                   8176: $ cvs status | less
1.35      wiz      8177: $ cvs commit
1.34      wiz      8178: $ cd ..
                   8179: $ vi Makefile # add SUBDIRS+=pkgname line
1.35      wiz      8180: $ cvs commit Makefile
1.66      asau     8181: $ cd pkgname
1.73      jnemeth  8182: $ make CTYPE=Added commit-changes-entry
1.1       dsieger  8183: 
                   8184: The commit message of the initial import should include part of the DESCR file,
                   8185: so people reading the mailing lists know what the package is/does.
                   8186: 
1.34      wiz      8187: Also mention the new package in pkgsrc/doc/CHANGES-20xx.
                   8188: 
                   8189: Previously, "cvs import" was suggested, but it was much easier to get wrong
                   8190: than "cvs add".
1.1       dsieger  8191: 
1.154     rillig   8192: 23.6. Updating a package to a newer version
1.1       dsieger  8193: 
                   8194: Please always put a concise, appropriate and relevant summary of the changes
                   8195: between old and new versions into the commit log when updating a package. There
                   8196: are various reasons for this:
                   8197: 
                   8198:   * A URL is volatile, and can change over time. It may go away completely or
                   8199:     its information may be overwritten by newer information.
                   8200: 
                   8201:   * Having the change information between old and new versions in our CVS
                   8202:     repository is very useful for people who use either cvs or anoncvs.
                   8203: 
                   8204:   * Having the change information between old and new versions in our CVS
                   8205:     repository is very useful for people who read the pkgsrc-changes mailing
                   8206:     list, so that they can make tactical decisions about when to upgrade the
                   8207:     package.
                   8208: 
                   8209: Please also recognize that, just because a new version of a package has been
                   8210: released, it should not automatically be upgraded in the CVS repository. We
                   8211: prefer to be conservative in the packages that are included in pkgsrc -
                   8212: development or beta packages are not really the best thing for most places in
                   8213: which pkgsrc is used. Please use your judgement about what should go into
                   8214: pkgsrc, and bear in mind that stability is to be preferred above new and
                   8215: possibly untested features.
                   8216: 
1.154     rillig   8217: 23.7. Renaming a package in pkgsrc
1.21      snj      8218: 
                   8219: Renaming packages is not recommended.
                   8220: 
1.175     gutterid 8221: When renaming packages, be sure to fix any references to the old name in other
1.21      snj      8222: Makefiles, options, buildlink files, etc.
                   8223: 
1.175     gutterid 8224: Also, when renaming a package, please add the package name and version pattern
1.167     leot     8225: (s) of the previous package to SUPERSEDES. This may be repeated for multiple
                   8226: renames. The new package would be an exact replacement. Example:
                   8227: 
                   8228: SUPERSEDES+=    p5-IO-Compress-Zlib<2.017
                   8229: SUPERSEDES+=    optcomp-[0-9]*
1.21      snj      8230: 
                   8231: Note that "successor" in the CHANGES-YYYY file doesn't necessarily mean that it
                   8232: supersedes, as that successor may not be an exact replacement but is a
                   8233: suggestion for the replaced functionality.
                   8234: 
1.154     rillig   8235: 23.8. Moving a package in pkgsrc
1.21      snj      8236: 
                   8237: It is preferred that packages are not renamed or moved, but if needed please
                   8238: follow these steps.
1.1       dsieger  8239: 
                   8240:  1. Make a copy of the directory somewhere else.
                   8241: 
                   8242:  2. Remove all CVS dirs.
                   8243: 
                   8244:     Alternatively to the first two steps you can also do:
                   8245: 
                   8246:     % cvs -d user@cvs.NetBSD.org:/cvsroot export -D today pkgsrc/category/package
                   8247: 
                   8248:     and use that for further work.
                   8249: 
1.25      wiz      8250:  3. Fix CATEGORIES and any DEPENDS paths that just did "../package" instead of 
1.1       dsieger  8251:     "../../category/package".
                   8252: 
1.21      snj      8253:  4. In the modified package's Makefile, consider setting PREV_PKGPATH to the
                   8254:     previous category/package pathname. The PREV_PKGPATH can be used by tools
                   8255:     for doing an update using pkgsrc building; for example, it can search the
                   8256:     pkg_summary(5) database for PREV_PKGPATH (if no SUPERSEDES) and then use
                   8257:     the corresponding new PKGPATH for that moved package. Note that it may have
                   8258:     multiple matches, so the tool should also check on the PKGBASE too. The
                   8259:     PREV_PKGPATH probably has no value unless SUPERSEDES is not set, i.e.
                   8260:     PKGBASE stays the same.
                   8261: 
                   8262:  5. cvs import the modified package in the new place.
1.1       dsieger  8263: 
1.21      snj      8264:  6. Check if any package depends on it:
1.1       dsieger  8265: 
                   8266:     % cd /usr/pkgsrc
                   8267:     % grep /package */*/Makefile* */*/buildlink*
                   8268: 
1.21      snj      8269:  7. Fix paths in packages from step 5 to point to new location.
1.1       dsieger  8270: 
1.21      snj      8271:  8. cvs rm (-f) the package at the old location.
1.1       dsieger  8272: 
1.21      snj      8273:  9. Remove from oldcategory/Makefile.
1.1       dsieger  8274: 
1.21      snj      8275: 10. Add to newcategory/Makefile.
1.1       dsieger  8276: 
1.21      snj      8277: 11. Commit the changed and removed files:
1.1       dsieger  8278: 
                   8279:     % cvs commit oldcategory/package oldcategory/Makefile newcategory/Makefile
                   8280: 
                   8281:     (and any packages from step 5, of course).
                   8282: 
1.154     rillig   8283: Chapter 24. Frequently Asked Questions
1.1       dsieger  8284: 
                   8285: This section contains the answers to questions that may arise when you are
                   8286: writing a package. If you don't find your question answered here, first have a
                   8287: look in the other chapters, and if you still don't have the answer, ask on the
                   8288: pkgsrc-users mailing list.
                   8289: 
1.154     rillig   8290: 24.1. What is the difference between MAKEFLAGS, .MAKEFLAGS and MAKE_FLAGS?
                   8291: 24.2. What is the difference between MAKE, GMAKE and MAKE_PROGRAM?
                   8292: 24.3. What is the difference between CC, PKG_CC and PKGSRC_COMPILER?
1.223     nia      8293: 24.4. Why does make show-var VARNAME=BUILDLINK_PREFIX.foo say it's empty?
                   8294: 24.5. What does ${MASTER_SITE_SOURCEFORGE:=package/} mean? I don't understand
1.1       dsieger  8295:     the := inside it.
1.223     nia      8296: 24.6. Which mailing lists are there for package developers?
                   8297: 24.7. Where is the pkgsrc documentation?
                   8298: 24.8. I have a little time to kill. What shall I do?
1.1       dsieger  8299: 
1.154     rillig   8300: 24.1. What is the difference between MAKEFLAGS, .MAKEFLAGS and MAKE_FLAGS?
1.1       dsieger  8301: 
                   8302:       MAKEFLAGS are the flags passed to the pkgsrc-internal invocations of make
1.223     nia      8303:       (1).
                   8304: 
                   8305:       MAKE_FLAGS are the flags that are passed to the MAKE_PROGRAM when
                   8306:       building the package.
                   8307: 
                   8308:       .MAKEFLAGS is an internal variable of bmake and should not be used by
                   8309:       packages.
1.1       dsieger  8310: 
1.154     rillig   8311: 24.2. What is the difference between MAKE, GMAKE and MAKE_PROGRAM?
1.1       dsieger  8312: 
                   8313:       MAKE is the path to the make(1) program that is used in the pkgsrc
1.223     nia      8314:       infrastructure.
                   8315: 
                   8316:       GMAKE is the path to GNU Make, but you need to say USE_TOOLS+=gmake to
                   8317:       use that.
                   8318: 
                   8319:       MAKE_PROGRAM is the path to the Make program that is used for building
                   8320:       the package.
1.1       dsieger  8321: 
1.154     rillig   8322: 24.3. What is the difference between CC, PKG_CC and PKGSRC_COMPILER?
1.1       dsieger  8323: 
                   8324:       CC is the path to the real C compiler, which can be configured by the
1.223     nia      8325:       pkgsrc user.
1.1       dsieger  8326: 
1.223     nia      8327:       PKG_CC is the path to the compiler wrapper.
1.1       dsieger  8328: 
1.223     nia      8329:       PKGSRC_COMPILER is not a path to a compiler, but the type of compiler
                   8330:       that should be used. See mk/compiler.mk for more information about the
                   8331:       latter variable.
1.1       dsieger  8332: 
1.223     nia      8333: 24.4. Why does make show-var VARNAME=BUILDLINK_PREFIX.foo say it's empty?
1.1       dsieger  8334: 
1.25      wiz      8335:       For optimization reasons, some variables are only available in the "
                   8336:       wrapper" phase and later. To "simulate" the wrapper phase, append 
1.1       dsieger  8337:       PKG_PHASE=wrapper to the above command.
                   8338: 
1.223     nia      8339: 24.5. What does ${MASTER_SITE_SOURCEFORGE:=package/} mean? I don't understand
1.1       dsieger  8340:       the := inside it.
                   8341: 
1.223     nia      8342:       The := is not an assignment operator, even though it may look like one.
1.108     rillig   8343:       Instead, it is a degenerate form of ${LIST:old_string=new_string}, which
                   8344:       is documented in the make(1) man page and which is commonly used in the
                   8345:       form ${SRCS:.c=.o}. In the case of MASTER_SITE_*, old_string is the empty
                   8346:       string and new_string is package/. That's where the : and the = fall
                   8347:       together.
1.1       dsieger  8348: 
1.223     nia      8349: 24.6. Which mailing lists are there for package developers?
1.1       dsieger  8350: 
                   8351:       tech-pkg
                   8352: 
                   8353:           This is a list for technical discussions related to pkgsrc
                   8354:           development, e.g. soliciting feedback for changes to pkgsrc
                   8355:           infrastructure, proposed new features, questions related to porting
                   8356:           pkgsrc to a new platform, advice for maintaining a package, patches
                   8357:           that affect many packages, help requests moved from pkgsrc-users when
                   8358:           an infrastructure bug is found, etc.
                   8359: 
                   8360:       pkgsrc-bugs
                   8361: 
                   8362:           All bug reports in category "pkg" sent with send-pr(1) appear here.
                   8363:           Please do not report your bugs here directly; use one of the other
                   8364:           mailing lists.
                   8365: 
1.223     nia      8366: 24.7. Where is the pkgsrc documentation?
1.1       dsieger  8367: 
                   8368:       There are many places where you can find documentation about pkgsrc:
                   8369: 
                   8370:         * The pkgsrc guide (this document) is a collection of chapters that
                   8371:           explain large parts of pkgsrc, but some chapters tend to be outdated.
                   8372:           Which ones they are is hard to say.
                   8373: 
1.174     leot     8374:         * On the mailing list archives (see https://mail-index.NetBSD.org/),
                   8375:           you can find discussions about certain features, announcements of new
1.1       dsieger  8376:           parts of the pkgsrc infrastructure and sometimes even announcements
                   8377:           that a certain feature has been marked as obsolete. The benefit here
                   8378:           is that each message has a date appended to it.
                   8379: 
                   8380:         * Many of the files in the mk/ directory start with a comment that
                   8381:           describes the purpose of the file and how it can be used by the
                   8382:           pkgsrc user and package authors. An easy way to find this
                   8383:           documentation is to run bmake help.
                   8384: 
                   8385:         * The CVS log messages are a rich source of information, but they tend
                   8386:           to be highly abbreviated, especially for actions that occur often.
                   8387:           Some contain a detailed description of what has changed, but they are
                   8388:           geared towards the other pkgsrc developers, not towards an average
                   8389:           pkgsrc user. They also only document changes, so if you don't know
                   8390:           what has been before, these messages may not be worth too much to
                   8391:           you.
                   8392: 
                   8393:         * Some parts of pkgsrc are only "implicitly documented", that is the
                   8394:           documentation exists only in the mind of the developer who wrote the
                   8395:           code. To get this information, use the cvs annotate command to see
                   8396:           who has written it and ask on the tech-pkg mailing list, so that
                   8397:           others can find your questions later (see above). To be sure that the
                   8398:           developer in charge reads the mail, you may CC him or her.
                   8399: 
1.223     nia      8400: 24.8. I have a little time to kill. What shall I do?
1.1       dsieger  8401: 
                   8402:       This is not really an FAQ yet, but here's the answer anyway.
                   8403: 
                   8404:         * Run pkg_chk -N (from the pkgtools/pkg_chk package). It will tell you
                   8405:           about newer versions of installed packages that are available, but
                   8406:           not yet updated in pkgsrc.
                   8407: 
1.198     leot     8408:         * Browse pkgsrc/doc/TODO -- it contains a list of suggested new
                   8409:           packages and a list of cleanups and enhancements for pkgsrc that
                   8410:           would be nice to have.
1.1       dsieger  8411: 
1.71      wiz      8412:         * Review packages for which review was requested on the tech-pkg
                   8413:           mailing list.
1.1       dsieger  8414: 
                   8415: Part III. The pkgsrc infrastructure internals
                   8416: 
                   8417: This part of the guide deals with everything from the infrastructure that is
                   8418: behind the interfaces described in the developer's guide. A casual package
                   8419: maintainer should not need anything from this part.
                   8420: 
                   8421: Table of Contents
                   8422: 
1.184     rillig   8423: 25. Design of the pkgsrc infrastructure
1.1       dsieger  8424: 
1.184     rillig   8425:     25.1. The meaning of variable definitions
                   8426:     25.2. Avoiding problems before they arise
                   8427:     25.3. Variable evaluation
1.1       dsieger  8428: 
1.184     rillig   8429:         25.3.1. At load time
                   8430:         25.3.2. At runtime
1.1       dsieger  8431: 
1.184     rillig   8432:     25.4. How can variables be specified?
                   8433:     25.5. Designing interfaces for Makefile fragments
1.1       dsieger  8434: 
1.184     rillig   8435:         25.5.1. Procedures with parameters
                   8436:         25.5.2. Actions taken on behalf of parameters
1.1       dsieger  8437: 
1.184     rillig   8438:     25.6. The order in which files are loaded
1.1       dsieger  8439: 
1.184     rillig   8440:         25.6.1. The order in bsd.prefs.mk
                   8441:         25.6.2. The order in bsd.pkg.mk
1.1       dsieger  8442: 
1.184     rillig   8443: 26. Regression tests
1.1       dsieger  8444: 
1.184     rillig   8445:     26.1. Running the regression tests
                   8446:     26.2. Adding a new regression test
1.1       dsieger  8447: 
1.184     rillig   8448:         26.2.1. Overridable functions
                   8449:         26.2.2. Helper functions
1.1       dsieger  8450: 
1.184     rillig   8451: 27. Porting pkgsrc
1.1       dsieger  8452: 
1.184     rillig   8453:     27.1. Porting pkgsrc to a new operating system
1.1       dsieger  8454: 
1.184     rillig   8455: Chapter 25. Design of the pkgsrc infrastructure
1.1       dsieger  8456: 
                   8457: Table of Contents
                   8458: 
1.184     rillig   8459: 25.1. The meaning of variable definitions
                   8460: 25.2. Avoiding problems before they arise
                   8461: 25.3. Variable evaluation
1.1       dsieger  8462: 
1.184     rillig   8463:     25.3.1. At load time
                   8464:     25.3.2. At runtime
1.1       dsieger  8465: 
1.184     rillig   8466: 25.4. How can variables be specified?
                   8467: 25.5. Designing interfaces for Makefile fragments
1.1       dsieger  8468: 
1.184     rillig   8469:     25.5.1. Procedures with parameters
                   8470:     25.5.2. Actions taken on behalf of parameters
1.1       dsieger  8471: 
1.184     rillig   8472: 25.6. The order in which files are loaded
1.1       dsieger  8473: 
1.184     rillig   8474:     25.6.1. The order in bsd.prefs.mk
                   8475:     25.6.2. The order in bsd.pkg.mk
1.1       dsieger  8476: 
                   8477: The pkgsrc infrastructure consists of many small Makefile fragments. Each such
                   8478: fragment needs a properly specified interface. This chapter explains how such
                   8479: an interface looks like.
                   8480: 
1.184     rillig   8481: 25.1. The meaning of variable definitions
1.1       dsieger  8482: 
                   8483: Whenever a variable is defined in the pkgsrc infrastructure, the location and
                   8484: the way of definition provide much information about the intended use of that
                   8485: variable. Additionally, more documentation may be found in a header comment or
                   8486: in this pkgsrc guide.
                   8487: 
                   8488: A special file is mk/defaults/mk.conf, which lists all variables that are
                   8489: intended to be user-defined. They are either defined using the ?= operator or
                   8490: they are left undefined because defining them to anything would effectively
                   8491: mean "yes". All these variables may be overridden by the pkgsrc user in the
                   8492: MAKECONF file.
                   8493: 
                   8494: Outside this file, the following conventions apply: Variables that are defined
                   8495: using the ?= operator may be overridden by a package.
                   8496: 
                   8497: Variables that are defined using the = operator may be used read-only at
                   8498: run-time.
                   8499: 
                   8500: Variables whose name starts with an underscore must not be accessed outside the
                   8501: pkgsrc infrastructure at all. They may change without further notice.
                   8502: 
                   8503: Note
                   8504: 
                   8505: These conventions are currently not applied consistently to the complete pkgsrc
                   8506: infrastructure.
                   8507: 
1.184     rillig   8508: 25.2. Avoiding problems before they arise
1.1       dsieger  8509: 
                   8510: All variables that contain lists of things should default to being empty. Two
                   8511: examples that do not follow this rule are USE_LANGUAGES and DISTFILES. These
                   8512: variables cannot simply be modified using the += operator in package Makefiles
                   8513: (or other files included by them), since there is no guarantee whether the
                   8514: variable is already set or not, and what its value is. In the case of
                   8515: DISTFILES, the packages "know" the default value and just define it as in the
                   8516: following example.
                   8517: 
                   8518: DISTFILES=      ${DISTNAME}${EXTRACT_SUFX} additional-files.tar.gz
                   8519: 
                   8520: Because of the selection of this default value, the same value appears in many
                   8521: package Makefiles. Similarly for USE_LANGUAGES, but in this case the default
                   8522: value ("c") is so short that it doesn't stand out. Nevertheless it is mentioned
                   8523: in many files.
                   8524: 
1.184     rillig   8525: 25.3. Variable evaluation
1.1       dsieger  8526: 
1.184     rillig   8527: 25.3.1. At load time
1.1       dsieger  8528: 
                   8529: Variable evaluation takes place either at load time or at runtime, depending on
                   8530: the context in which they occur. The contexts where variables are evaluated at
                   8531: load time are:
                   8532: 
                   8533:   * The right hand side of the := and != operators,
                   8534: 
                   8535:   * Make directives like .if or .for,
                   8536: 
                   8537:   * Dependency lines.
                   8538: 
                   8539: A special exception are references to the iteration variables of .for loops,
                   8540: which are expanded inline, no matter in which context they appear.
                   8541: 
                   8542: As the values of variables may change during load time, care must be taken not
                   8543: to evaluate them by accident. Typical examples for variables that should not be
                   8544: evaluated at load time are DEPENDS and CONFIGURE_ARGS. To make the effect more
                   8545: clear, here is an example:
                   8546: 
                   8547: CONFIGURE_ARGS=         # none
                   8548: CFLAGS=                 -O
                   8549: CONFIGURE_ARGS+=        CFLAGS=${CFLAGS:Q}
                   8550: 
                   8551: CONFIGURE_ARGS:=        ${CONFIGURE_ARGS}
                   8552: 
                   8553: CFLAGS+=                -Wall
                   8554: 
                   8555: This code shows how the use of the := operator can quickly lead to unexpected
                   8556: results. The first paragraph is fairly common code. The second paragraph
                   8557: evaluates the CONFIGURE_ARGS variable, which results in CFLAGS=-O. In the third
                   8558: paragraph, the -Wall is appended to the CFLAGS, but this addition will not
                   8559: appear in CONFIGURE_ARGS. In actual code, the three paragraphs from above
                   8560: typically occur in completely unrelated files.
                   8561: 
1.184     rillig   8562: 25.3.2. At runtime
1.1       dsieger  8563: 
                   8564: After all the files have been loaded, the values of the variables cannot be
                   8565: changed anymore. Variables that are used in the shell commands are expanded at
                   8566: this point.
                   8567: 
1.184     rillig   8568: 25.4. How can variables be specified?
1.1       dsieger  8569: 
                   8570: There are many ways in which the definition and use of a variable can be
                   8571: restricted in order to detect bugs and violations of the (mostly unwritten)
1.108     rillig   8572: policies. A package can be checked with pkglint -Wall to see whether it meets
                   8573: these rules.
1.1       dsieger  8574: 
1.184     rillig   8575: 25.5. Designing interfaces for Makefile fragments
1.1       dsieger  8576: 
                   8577: Most of the .mk files fall into one of the following classes. Cases where a
                   8578: file falls into more than one class should be avoided as it often leads to
                   8579: subtle bugs.
                   8580: 
1.184     rillig   8581: 25.5.1. Procedures with parameters
1.1       dsieger  8582: 
                   8583: In a traditional imperative programming language some of the .mk files could be
1.198     leot     8584: described as procedures. They take some input parameters and--after
                   8585: inclusion--provide a result in output parameters. Since all variables in
1.23      jakllsch 8586: Makefiles have global scope care must be taken not to use parameter names that
                   8587: have already another meaning. For example, PKGNAME is a bad choice for a
                   8588: parameter name.
1.1       dsieger  8589: 
                   8590: Procedures are completely evaluated at preprocessing time. That is, when
                   8591: calling a procedure all input parameters must be completely resolvable. For
                   8592: example, CONFIGURE_ARGS should never be an input parameter since it is very
                   8593: likely that further text will be added after calling the procedure, which would
                   8594: effectively apply the procedure to only a part of the variable. Also,
1.108     rillig   8595: references to other variables will be modified after calling the procedure.
1.1       dsieger  8596: 
                   8597: A procedure can declare its output parameters either as suitable for use in
                   8598: preprocessing directives or as only available at runtime. The latter
                   8599: alternative is for variables that contain references to other runtime
                   8600: variables.
                   8601: 
                   8602: Procedures shall be written such that it is possible to call the procedure more
                   8603: than once. That is, the file must not contain multiple-inclusion guards.
                   8604: 
                   8605: Examples for procedures are mk/bsd.options.mk and mk/buildlink3/bsd.builtin.mk.
                   8606: To express that the parameters are evaluated at load time, they should be
                   8607: assigned using the := operator, which should be used only for this purpose.
                   8608: 
1.184     rillig   8609: 25.5.2. Actions taken on behalf of parameters
1.1       dsieger  8610: 
                   8611: Action files take some input parameters and may define runtime variables. They
                   8612: shall not define loadtime variables. There are action files that are included
                   8613: implicitly by the pkgsrc infrastructure, while other must be included
                   8614: explicitly.
                   8615: 
                   8616: An example for action files is mk/subst.mk.
                   8617: 
1.184     rillig   8618: 25.6. The order in which files are loaded
1.1       dsieger  8619: 
                   8620: Package Makefiles usually consist of a set of variable definitions, and include
                   8621: the file ../../mk/bsd.pkg.mk in the very last line. Before that, they may also
                   8622: include various other *.mk files if they need to query the availability of
                   8623: certain features like the type of compiler or the X11 implementation. Due to
                   8624: the heavy use of preprocessor directives like .if and .for, the order in which
                   8625: the files are loaded matters.
                   8626: 
                   8627: This section describes at which point the various files are loaded and gives
                   8628: reasons for that order.
                   8629: 
1.184     rillig   8630: 25.6.1. The order in bsd.prefs.mk
1.1       dsieger  8631: 
                   8632: The very first action in bsd.prefs.mk is to define some essential variables
                   8633: like OPSYS, OS_VERSION and MACHINE_ARCH.
                   8634: 
1.4       rillig   8635: Then, the user settings are loaded from the file specified in MAKECONF, which
                   8636: is usually mk.conf. After that, those variables that have not been overridden
                   8637: by the user are loaded from mk/defaults/mk.conf.
1.1       dsieger  8638: 
                   8639: After the user settings, the system settings and platform settings are loaded,
                   8640: which may override the user settings.
                   8641: 
                   8642: Then, the tool definitions are loaded. The tool wrappers are not yet in effect.
                   8643: This only happens when building a package, so the proper variables must be used
                   8644: instead of the direct tool names.
                   8645: 
                   8646: As the last steps, some essential variables from the wrapper and the package
                   8647: system flavor are loaded, as well as the variables that have been cached in
                   8648: earlier phases of a package build.
                   8649: 
1.184     rillig   8650: 25.6.2. The order in bsd.pkg.mk
1.1       dsieger  8651: 
                   8652: First, bsd.prefs.mk is loaded.
                   8653: 
                   8654: Then, the various *-vars.mk files are loaded, which fill default values for
                   8655: those variables that have not been defined by the package. These variables may
                   8656: later be used even in unrelated files.
                   8657: 
                   8658: Then, the file bsd.pkg.error.mk provides the target error-check that is added
                   8659: as a special dependency to all other targets that use DELAYED_ERROR_MSG or
                   8660: DELAYED_WARNING_MSG.
                   8661: 
                   8662: Then, the package-specific hacks from hacks.mk are included.
                   8663: 
                   8664: Then, various other files follow. Most of them don't have any dependencies on
                   8665: what they need to have included before or after them, though some do.
                   8666: 
                   8667: The code to check PKG_FAIL_REASON and PKG_SKIP_REASON is then executed, which
                   8668: restricts the use of these variables to all the files that have been included
                   8669: before. Appearances in later files will be silently ignored.
                   8670: 
                   8671: Then, the files for the main targets are included, in the order of later
                   8672: execution, though the actual order should not matter.
                   8673: 
                   8674: At last, some more files are included that don't set any interesting variables
                   8675: but rather just define make targets to be executed.
                   8676: 
1.184     rillig   8677: Chapter 26. Regression tests
1.1       dsieger  8678: 
                   8679: Table of Contents
                   8680: 
1.184     rillig   8681: 26.1. Running the regression tests
                   8682: 26.2. Adding a new regression test
1.1       dsieger  8683: 
1.184     rillig   8684:     26.2.1. Overridable functions
                   8685:     26.2.2. Helper functions
1.1       dsieger  8686: 
                   8687: The pkgsrc infrastructure consists of a large codebase, and there are many
                   8688: corners where every little bit of a file is well thought out, making pkgsrc
                   8689: likely to fail as soon as anything is changed near those parts. To prevent most
                   8690: changes from breaking anything, a suite of regression tests should go along
                   8691: with every important part of the pkgsrc infrastructure. This chapter describes
                   8692: how regression tests work in pkgsrc and how you can add new tests.
                   8693: 
1.184     rillig   8694: 26.1. Running the regression tests
1.1       dsieger  8695: 
1.25      wiz      8696: You first need to install the pkgtools/pkg_regress package, which provides the 
1.1       dsieger  8697: pkg_regress command. Then you can simply run that command, which will run all
1.168     rillig   8698: tests in the regress/ directory.
1.1       dsieger  8699: 
1.184     rillig   8700: 26.2. Adding a new regression test
1.1       dsieger  8701: 
1.168     rillig   8702: Every directory in the regress/ directory that contains a file called spec is
1.1       dsieger  8703: considered a regression test. This file is a shell program that is included by
                   8704: the pkg_regress command. The following functions can be overridden to suit your
                   8705: needs.
                   8706: 
1.184     rillig   8707: 26.2.1. Overridable functions
1.1       dsieger  8708: 
1.108     rillig   8709: These functions do not take any parameters. Although they are called in "set -e
1.168     rillig   8710: " mode, they don't stop at the first failing command. See this Stack Overflow
1.108     rillig   8711: question for details.
1.1       dsieger  8712: 
1.108     rillig   8713: do_setup
1.1       dsieger  8714: 
                   8715:     This function prepares the environment for the test. By default it does
                   8716:     nothing.
                   8717: 
1.108     rillig   8718: do_test
1.1       dsieger  8719: 
                   8720:     This function runs the actual test. By default, it calls TEST_MAKE with the
                   8721:     arguments MAKEARGS_TEST and writes its output including error messages into
                   8722:     the file TEST_OUTFILE.
                   8723: 
1.108     rillig   8724:     When defining this function, make sure that all output that needs to be
                   8725:     checked is written to the correct output file. Example:
                   8726: 
                   8727:     do_test() {
                   8728:             echo "Example output"
                   8729:     } 1>$TEST_OUTFILE 2>&1
                   8730: 
                   8731: check_result
1.1       dsieger  8732: 
                   8733:     This function is run after the test and is typically used to compare the
                   8734:     actual output from the one that is expected. It can make use of the various
1.108     rillig   8735:     helper functions from the next section. Example:
                   8736: 
                   8737:     check_result() {
                   8738:             exit_status 0
                   8739:             output_require "Example"
                   8740:             output_require "^[[:alpha:]+[[:space:]][[:alpha:]]{6}$"
                   8741:             output_prohibit "no such file or directory"
1.169     rillig   8742:             regress_fail "expected $expected but got $actual for input $input"
1.108     rillig   8743:     }
1.1       dsieger  8744: 
1.108     rillig   8745: do_cleanup
1.1       dsieger  8746: 
                   8747:     This function cleans everything up after the test has been run. By default
                   8748:     it does nothing.
                   8749: 
1.184     rillig   8750: 26.2.2. Helper functions
1.1       dsieger  8751: 
1.168     rillig   8752: regress_fail message...
                   8753: 
                   8754:     This function makes the test fail with the given error message.
                   8755: 
1.108     rillig   8756: exit_status expected
1.1       dsieger  8757: 
1.108     rillig   8758:     This function compares the exitcode of the do_test function with its first
                   8759:     parameter. If they differ, the test will fail.
1.1       dsieger  8760: 
1.108     rillig   8761: output_require regex...
1.1       dsieger  8762: 
                   8763:     This function checks for each of its parameters if the output from do_test
1.108     rillig   8764:     matches the extended regular expression. If it does not, the test will
                   8765:     fail. Example:
                   8766: 
                   8767:     output_require "looks fine"
                   8768:     output_require "^[[:alpha:]+[[:space:]][[:alpha:]]{6}$"
1.1       dsieger  8769: 
1.177     leot     8770: output_prohibit regex...
1.1       dsieger  8771: 
                   8772:     This function checks for each of its parameters if the output from do_test
                   8773:     () does not match the extended regular expression. If any of the regular
                   8774:     expressions matches, the test will fail.
                   8775: 
1.184     rillig   8776: Chapter 27. Porting pkgsrc
1.1       dsieger  8777: 
                   8778: Table of Contents
                   8779: 
1.184     rillig   8780: 27.1. Porting pkgsrc to a new operating system
1.1       dsieger  8781: 
                   8782: The pkgsrc system has already been ported to many operating systems, hardware
                   8783: architectures and compilers. This chapter explains the necessary steps to make
                   8784: pkgsrc even more portable.
                   8785: 
1.184     rillig   8786: 27.1. Porting pkgsrc to a new operating system
1.1       dsieger  8787: 
                   8788: To port pkgsrc to a new operating system (called MyOS in this example), you
                   8789: need to touch the following files:
                   8790: 
                   8791: pkgtools/bootstrap-mk-files/files/mods/MyOS.sys.mk
                   8792: 
                   8793:     This file contains some basic definitions, for example the name of the C
                   8794:     compiler.
                   8795: 
                   8796: mk/bsd.prefs.mk
                   8797: 
1.212     wiz      8798:     Insert code that defines the variables OPSYS, OS_VERSION, OPSYS_VERSION,
1.1       dsieger  8799:     LOWER_VENDOR, MACHINE_ARCH, OBJECT_FMT, APPEND_ELF, and the other variables
                   8800:     that appear in this file.
                   8801: 
                   8802: mk/platform/MyOS.mk
                   8803: 
                   8804:     This file contains the platform-specific definitions that are used by
                   8805:     pkgsrc. Start by copying one of the other files and edit it to your needs.
                   8806: 
                   8807: mk/tools/tools.MyOS.mk
                   8808: 
                   8809:     This file defines the paths to all the tools that are needed by one or the
                   8810:     other package in pkgsrc, as well as by pkgsrc itself. Find out where these
                   8811:     tools are on your platform and add them.
                   8812: 
                   8813: Now, you should be able to build some basic packages, like lang/perl5, shells/
                   8814: bash.
                   8815: 
                   8816: Appendix A. A simple example package: bison
                   8817: 
                   8818: Table of Contents
                   8819: 
                   8820: A.1. files
                   8821: 
                   8822:     A.1.1. Makefile
                   8823:     A.1.2. DESCR
                   8824:     A.1.3. PLIST
                   8825:     A.1.4. Checking a package with pkglint
                   8826: 
                   8827: A.2. Steps for building, installing, packaging
                   8828: 
                   8829: We checked to find a piece of software that wasn't in the packages collection,
1.25      wiz      8830: and picked GNU bison. Quite why someone would want to have bison when Berkeley 
1.1       dsieger  8831: yacc is already present in the tree is beyond us, but it's useful for the
                   8832: purposes of this exercise.
                   8833: 
                   8834: A.1. files
                   8835: 
                   8836: A.1.1. Makefile
                   8837: 
1.2       rillig   8838: # $NetBSD$
1.1       dsieger  8839: #
                   8840: 
                   8841: DISTNAME=       bison-1.25
                   8842: CATEGORIES=     devel
1.171     rillig   8843: MASTER_SITES=   ${MASTER_SITE_GNU:=bison/}
1.1       dsieger  8844: 
1.30      dholland 8845: MAINTAINER=     pkgsrc-users@NetBSD.org
1.174     leot     8846: HOMEPAGE=       https://www.gnu.org/software/bison/bison.html
1.1       dsieger  8847: COMMENT=        GNU yacc clone
                   8848: 
                   8849: GNU_CONFIGURE=  yes
1.47      wiz      8850: INFO_FILES=     yes
1.1       dsieger  8851: 
                   8852: .include "../../mk/bsd.pkg.mk"
                   8853: 
                   8854: A.1.2. DESCR
                   8855: 
                   8856: GNU version of yacc.  Can make re-entrant parsers, and numerous other
                   8857: improvements.  Why you would want this when Berkeley yacc(1) is part
                   8858: of the NetBSD source tree is beyond me.
                   8859: 
                   8860: A.1.3. PLIST
                   8861: 
1.2       rillig   8862: @comment $NetBSD$
1.1       dsieger  8863: bin/bison
                   8864: man/man1/bison.1.gz
                   8865: share/bison.simple
                   8866: share/bison.hairy
                   8867: 
                   8868: A.1.4. Checking a package with pkglint
                   8869: 
                   8870: The NetBSD package system comes with pkgtools/pkglint which helps to check the
                   8871: contents of these files. After installation it is quite easy to use, just
1.171     rillig   8872: change to the directory of the package you wish to examine and run pkglint:
1.1       dsieger  8873: 
                   8874: $ pkglint
1.171     rillig   8875: ERROR: Makefile: Each package must define its LICENSE.
                   8876: WARN: Makefile:9: HOMEPAGE should migrate from http to https.
                   8877: NOTE: PLIST:3: The .gz extension is unnecessary for manual pages.
                   8878: WARN: PLIST:5: "share/bison.hairy" should be sorted before "share/bison.simple".
                   8879: 1 error, 2 warnings and 1 note found.
                   8880: (Run "pkglint -e" to show explanations.)
                   8881: (Run "pkglint -fs" to show what can be fixed automatically.)
1.172     rillig   8882: (Run "pkglint -F" to automatically fix some issues.)
1.1       dsieger  8883: 
                   8884: Depending on the supplied command line arguments (see pkglint(1)), more checks
1.170     rillig   8885: will be performed. Use e.g. pkglint -Wall for a very thorough check.
1.1       dsieger  8886: 
                   8887: A.2. Steps for building, installing, packaging
                   8888: 
                   8889: Create the directory where the package lives, plus any auxiliary directories:
                   8890: 
                   8891: # cd /usr/pkgsrc/lang
                   8892: # mkdir bison
                   8893: # cd bison
                   8894: # mkdir patches
                   8895: 
1.184     rillig   8896: Create Makefile, DESCR and PLIST (see Chapter 12, Package components - files,
1.1       dsieger  8897: directories and contents) then continue with fetching the distfile:
                   8898: 
                   8899: # make fetch
                   8900: >> bison-1.25.tar.gz doesn't seem to exist on this system.
                   8901: >> Attempting to fetch from ftp://prep.ai.mit.edu/pub/gnu//.
                   8902: Requesting ftp://prep.ai.mit.edu/pub/gnu//bison-1.25.tar.gz (via ftp://orpheus.amdahl.com:80/)
                   8903: ftp: Error retrieving file: 500 Internal error
                   8904: 
                   8905: >> Attempting to fetch from ftp://wuarchive.wustl.edu/systems/gnu//.
                   8906: Requesting ftp://wuarchive.wustl.edu/systems/gnu//bison-1.25.tar.gz (via ftp://orpheus.amdahl.com:80/)
                   8907: ftp: Error retrieving file: 500 Internal error
                   8908: 
                   8909: >> Attempting to fetch from ftp://ftp.freebsd.org/pub/FreeBSD/distfiles//.
                   8910: Requesting ftp://ftp.freebsd.org/pub/FreeBSD/distfiles//bison-1.25.tar.gz (via ftp://orpheus.amdahl.com:80/)
                   8911: Successfully retrieved file.
                   8912: 
                   8913: Generate the checksum of the distfile into distinfo:
                   8914: 
                   8915: # make makedistinfo
                   8916: 
                   8917: Now compile:
                   8918: 
                   8919: # make
                   8920: >> Checksum OK for bison-1.25.tar.gz.
                   8921: ===>  Extracting for bison-1.25
                   8922: ===>  Patching for bison-1.25
                   8923: ===>   Ignoring empty patch directory
                   8924: ===>  Configuring for bison-1.25
                   8925: creating cache ./config.cache
                   8926: checking for gcc... cc
                   8927: checking whether we are using GNU C... yes
                   8928: checking for a BSD compatible install... /usr/bin/install -c -o bin -g bin
                   8929: checking how to run the C preprocessor... cc -E
                   8930: checking for minix/config.h... no
                   8931: checking for POSIXized ISC... no
                   8932: checking whether cross-compiling... no
                   8933: checking for ANSI C header files... yes
                   8934: checking for string.h... yes
                   8935: checking for stdlib.h... yes
                   8936: checking for memory.h... yes
                   8937: checking for working const... yes
                   8938: checking for working alloca.h... no
                   8939: checking for alloca... yes
                   8940: checking for strerror... yes
                   8941: updating cache ./config.cache
                   8942: creating ./config.status
                   8943: creating Makefile
                   8944: ===>  Building for bison-1.25
                   8945: 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
                   8946: 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
                   8947: 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
                   8948: 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
                   8949: 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
                   8950: 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
                   8951: 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
                   8952: 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
                   8953: 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
                   8954: 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
                   8955: 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
                   8956: 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
                   8957: 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
                   8958: 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
                   8959: 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
                   8960: 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
                   8961: 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
                   8962: 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
                   8963: 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
                   8964: 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
                   8965: 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
                   8966: 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
                   8967: ./files.c:240: warning: mktemp() possibly used unsafely, consider using mkstemp()
                   8968: rm -f bison.s1
                   8969: sed -e "/^#line/ s|bison|/usr/pkg/share/bison|" < ./bison.simple > bison.s1
                   8970: 
                   8971: Everything seems OK, so install the files:
                   8972: 
                   8973: # make install
                   8974: >> Checksum OK for bison-1.25.tar.gz.
                   8975: ===>  Installing for bison-1.25
                   8976: sh ./mkinstalldirs /usr/pkg/bin /usr/pkg/share  /usr/pkg/info /usr/pkg/man/man1
                   8977: rm -f /usr/pkg/bin/bison
                   8978: cd /usr/pkg/share; rm -f bison.simple bison.hairy
                   8979: rm -f /usr/pkg/man/man1/bison.1 /usr/pkg/info/bison.info*
                   8980: install -c  -o bin -g bin -m 555 bison /usr/pkg/bin/bison
                   8981: /usr/bin/install -c -o bin -g bin -m 644 bison.s1 /usr/pkg/share/bison.simple
                   8982: /usr/bin/install -c -o bin -g bin -m 644 ./bison.hairy /usr/pkg/share/bison.hairy
                   8983: cd .; for f in bison.info*;  do /usr/bin/install -c -o bin -g bin -m 644 $f /usr/pkg/info/$f; done
                   8984: /usr/bin/install -c -o bin -g bin -m 644 ./bison.1 /usr/pkg/man/man1/bison.1
                   8985: ===>  Registering installation for bison-1.25
                   8986: 
                   8987: You can now use bison, and also - if you decide so - remove it with pkg_delete
                   8988: bison. Should you decide that you want a binary package, do this now:
                   8989: 
                   8990: # make package
                   8991: >> Checksum OK for bison-1.25.tar.gz.
                   8992: ===>  Building package for bison-1.25
                   8993: Creating package bison-1.25.tgz
                   8994: Registering depends:.
                   8995: Creating gzip'd tar ball in '/u/pkgsrc/lang/bison/bison-1.25.tgz'
                   8996: 
                   8997: Now that you don't need the source and object files any more, clean up:
                   8998: 
                   8999: # make clean
                   9000: ===>  Cleaning for bison-1.25
                   9001: 
1.207     leot     9002: Appendix B. Security hardening
                   9003: 
                   9004: Table of Contents
                   9005: 
                   9006: B.1. Mechanisms
                   9007: 
                   9008:     B.1.1. Enabled by default
                   9009:     B.1.2. Not enabled by default
                   9010: 
                   9011: B.2. Caveats
                   9012: 
                   9013:     B.2.1. Problems with PKGSRC_MKPIE
                   9014:     B.2.2. Problems with PKGSRC_USE_FORTIFY
                   9015:     B.2.3. Problems with PKGSRC_USE_RELRO
                   9016:     B.2.4. Problems with PKGSRC_USE_SSP
                   9017: 
                   9018: B.3. Auditing the system
                   9019: 
                   9020:     B.3.1. Checking for PIE
                   9021:     B.3.2. Checking for partial RELRO
                   9022:     B.3.3. Checking for full RELRO
                   9023:     B.3.4. Checking for SSP
                   9024: 
                   9025: A number of mechanisms are available in pkgsrc to improve the security of the
                   9026: resulting system. This page describes the mechanisms, and gives hints about
                   9027: detecting and fixing problems.
                   9028: 
                   9029: Mechanisms can be enabled individually in mk.conf, and are individually
                   9030: described below.
                   9031: 
                   9032: Typically, a feature will cause some programs to fail to build or work when
                   9033: first enabled. This can be due to latent problems in the program, and can be
                   9034: due to other reasons. After enough testing to have confidence that user
                   9035: problems will be quite rare, individual mechanisms will be enabled by default.
                   9036: 
                   9037: For each mechanism, see the Caveats section below for an explanation of what
                   9038: might go wrong at compile time and at run time, and how to notice and address
                   9039: these problems.
                   9040: 
                   9041: B.1. Mechanisms
                   9042: 
                   9043: B.1.1. Enabled by default
                   9044: 
                   9045: B.1.1.1. PKGSRC_USE_FORTIFY
                   9046: 
                   9047: This allows substitute wrappers to be used for some commonly used library
                   9048: functions that do not have built-in bounds checking - but could in some cases.
                   9049: 
                   9050: Two mitigation levels are available:
                   9051: 
                   9052:   * "weak" only enables checks at compile-time.
                   9053: 
                   9054:   * "strong" enables checks at compile-time and runtime.
                   9055: 
                   9056: "strong" has been enabled by default since pkgsrc-2017Q3.
                   9057: 
                   9058: B.1.1.2. PKGSRC_USE_SSP
                   9059: 
                   9060: This enables a stack-smashing protection mitigation. It is done by adding a
                   9061: guard variable to functions with vulnerable objects. The guards are initialized
                   9062: when a function is entered and then checked when the function exits. The guard
                   9063: check will fail and the program forcibly exited if the variable was modified in
                   9064: the meantime. This can happen in case of buffer overflows or memory corruption,
                   9065: and therefore exposing these bugs.
                   9066: 
                   9067: Different mitigation levels are available:
                   9068: 
                   9069:   * "yes", which will only protect functions considered vulnerable by the
                   9070:     compiler;
                   9071: 
                   9072:   * "all", which will protect every function;
                   9073: 
                   9074:   * "strong", the default, which will apply a better balance between the two
                   9075:     settings above.
                   9076: 
                   9077: This mitigation is supported by both GCC and clang. It may be supported in
                   9078: additional compilers, possibly under a different name. It is particularly
                   9079: useful for unsafe programming languages, such as C/C++.
                   9080: 
                   9081:   * "yes" is enabled by default where known supported since pkgsrc-2017Q3.
                   9082: 
                   9083:   * "strong" is enabled by default where known supported since pkgsrc-2021Q4.
                   9084: 
                   9085: More details can be found here:
                   9086: 
                   9087:   * Buffer overflow protection on Wikipedia
                   9088: 
                   9089: B.1.1.3. PKGSRC_MKPIE
                   9090: 
                   9091: This requests the creation of PIE (Position Independent Executables) for all
                   9092: executables. The PIE mechanism is normally used for shared libraries, so that
                   9093: they can be loaded at differing addresses at runtime. PIE itself does not have
                   9094: useful security properties; however, it is necessary to fully leverage some,
                   9095: such as ASLR. Some operating systems support Address Space Layout Randomization
                   9096: (ASLR), which causes different addresses to be used each time a program is run.
                   9097: This makes it more difficult for an attacker to guess addresses and thus makes
                   9098: exploits harder to construct. With PIE, ASLR can really be applied to the
                   9099: entire program, instead of the stack and heap only.
                   9100: 
                   9101: PIE executables will only be built for toolchains that are known to support
                   9102: PIE. Currently, this means NetBSD on x86, ARM, SPARC64, m68k, and MIPS.
                   9103: 
                   9104: PKGSRC_MKPIE was enabled by default after the pkgsrc-2021Q3 branch.
                   9105: 
1.219     nia      9106: B.1.1.4. PKGSRC_USE_RELRO
1.207     leot     9107: 
                   9108: This also makes the exploitation of some security vulnerabilities more
                   9109: difficult in some cases.
                   9110: 
                   9111: Two different mitigation levels are available:
                   9112: 
1.219     nia      9113:   * partial (the default): the ELF sections are reordered so that internal data
                   9114:     sections precede the program's own data sections, and non-PLT GOT is
                   9115:     read-only;
1.207     leot     9116: 
                   9117:   * full: in addition to partial RELRO, every relocation is performed
1.218     nia      9118:     immediately when starting the program, allowing the entire GOT to be
                   9119:     read-only. This can greatly slow down startup of large programs.
1.207     leot     9120: 
                   9121: This is currently supported by GCC. Many software distributions now enable this
1.220     nia      9122: feature by default, at the "partial" level.
1.207     leot     9123: 
                   9124: More details can be found here:
                   9125: 
                   9126:   * Hardening ELF binaries using Relocation Read-Only (RELRO)
                   9127: 
1.219     nia      9128: B.1.2. Not enabled by default
                   9129: 
                   9130: B.1.2.1. PKGSRC_MKREPRO
                   9131: 
                   9132: With this option, pkgsrc will try to build packages reproducibly. This allows
                   9133: packages built from the same tree and with the same options, to produce
                   9134: identical results bit by bit. This option should be combined with ASLR and
                   9135: PKGSRC_MKPIE to avoid predictable address offsets for attackers attempting to
                   9136: exploit security vulnerabilities.
                   9137: 
                   9138: More details can be found here:
                   9139: 
                   9140:   * Reproducible Builds - a set of software development practices that create
                   9141:     an independently-verifiable path from source to binary code
                   9142: 
                   9143: More work likely needs to be done before pkgsrc is fully reproducible.
                   9144: 
                   9145: B.1.2.2. PKGSRC_USE_STACK_CHECK
1.207     leot     9146: 
                   9147: This uses -fstack-check with GCC for another stack protection mitigation.
                   9148: 
                   9149: It asks the compiler to generate code verifying that it does not corrupt the
                   9150: stack. According to GCC's manual page, this is really only useful for
                   9151: multi-threaded programs.
                   9152: 
                   9153: B.2. Caveats
                   9154: 
                   9155: B.2.1. Problems with PKGSRC_MKPIE
                   9156: 
                   9157: B.2.1.1. Packages failing to build
                   9158: 
                   9159: A number of packages may fail to build with this option enabled. The failures
                   9160: are often related to the absence of the -fPIC compilation flag when building
                   9161: libraries or executables (or ideally -fPIE in the latter case). This flag is
                   9162: added to the CFLAGS already, but requires the package to actually support it.
                   9163: 
                   9164: B.2.1.1.1. How to fix
                   9165: 
                   9166: These instructions are meant as a reference only; they likely need to be
                   9167: adapted for many packages individually.
                   9168: 
                   9169: For packages using Makefiles:
                   9170: 
                   9171: MAKE_FLAGS+=    CFLAGS=${CFLAGS:Q}
                   9172: MAKE_FLAGS+=    LDFLAGS=${LDFLAGS:Q}
                   9173: 
                   9174: For packages using Imakefiles:
                   9175: 
                   9176: MAKE_FLAGS+=    CCOPTIONS=${CFLAGS:Q}
                   9177: MAKE_FLAGS+=    LOCAL_LDFLAGS=${LDFLAGS:Q}
                   9178: 
                   9179: B.2.1.2. Run-time crashes
                   9180: 
                   9181: Some programs may fail to run, or crash at random times once built as PIE. Two
                   9182: scenarios are essentially possible. This is nearly always due to a bug in the
                   9183: program being exposed due to ASLR.
                   9184: 
                   9185: B.2.1.3. Disabling PKGSRC_MKPIE on a per-package basis
                   9186: 
                   9187: Ideally, packages should be fixed for compatibility with MKPIE. However, in
                   9188: some cases this is very difficult, due to complex build systems, packages using
                   9189: non-standard toolchains, or programming languages with odd bootstrapping
                   9190: mechanisms.
                   9191: 
                   9192: To disable PKGSRC_MKPIE on a per-package basis, set MKPIE_SUPPORTED= no in the
                   9193: package's Makefile before bsd.prefs.mk is included.
                   9194: 
                   9195: B.2.2. Problems with PKGSRC_USE_FORTIFY
                   9196: 
                   9197: B.2.2.1. Packages failing to build
                   9198: 
                   9199: This feature makes use of pre-processing directives to look for hardened,
                   9200: alternative implementations of essential library calls. Some programs may fail
                   9201: to build as a result; this usually happens for those trying too hard to be
                   9202: portable, or otherwise abusing definitions in the standard library.
                   9203: 
                   9204: B.2.2.2. Run-time crashes
                   9205: 
                   9206: This feature may cause some programs to crash, usually indicating an actual bug
                   9207: in the program. The fix will typically involve patching the original program's
                   9208: source code.
                   9209: 
                   9210: B.2.2.3. Optimization is required
                   9211: 
                   9212: At least in the case of GCC, FORTIFY will only be applied if optimization is
                   9213: applied while compiling. This means that the CFLAGS should also contain -O, -O2
                   9214: or another optimization level. This cannot easily be applied globally, as some
                   9215: packages may require specific optimization levels.
                   9216: 
                   9217: B.2.2.4. Disabling FORTIFY on a per-package basis
                   9218: 
                   9219: Note
                   9220: 
                   9221: FORTIFY should not be disabled to work around runtime crashes in the program!
                   9222: This is a very bad idea and will expose you to security vulnerabilities.
                   9223: 
                   9224: To disable FORTIFY on a per-package basis, set the following in the package's
                   9225: Makefile before bsd.prefs.mk is included:
                   9226: 
                   9227: FORTIFY_SUPPORTED=      no
                   9228: 
                   9229: B.2.3. Problems with PKGSRC_USE_RELRO
                   9230: 
                   9231: B.2.3.1. Performance impact
                   9232: 
                   9233: For better protection, full RELRO requires every symbol to be resolved when the
                   9234: program starts, rather than simply when required at run-time. This will have
                   9235: more impact on programs using a lot of symbols, or linked to libraries exposing
                   9236: a lot of symbols. Therefore, daemons or programs otherwise running in
                   9237: background are affected only when started. Programs loading plug-ins at
                   9238: run-time are affected when loading the plug-ins.
                   9239: 
                   9240: The impact is not expected to be noticeable on modern hardware, except in some
                   9241: cases for big programs.
                   9242: 
                   9243: B.2.3.2. Run-time crashes
                   9244: 
                   9245: Some programs handle plug-ins and dependencies in a way that conflicts with
                   9246: RELRO: for instance, with an initialization routine listing any other plug-in
                   9247: required. With full RELRO, the missing symbols are resolved before the
                   9248: initialization routine can run, and the dynamic loader will not be able to find
                   9249: them directly and abort as a result. Unfortunately, this is how Xorg loads its
                   9250: drivers. Partial RELRO can be applied instead in this case.
                   9251: 
                   9252: B.2.3.3. Disabling RELRO on a per-package basis
                   9253: 
                   9254: To disable RELRO on a per-package basis, set the following in the package's
                   9255: Makefile before bsd.prefs.mk is included:
                   9256: 
                   9257: RELRO_SUPPORTED=        no
                   9258: 
1.209     nia      9259: It is also possible to at most enable partial RELRO, by setting RELRO_SUPPORTED
                   9260: to partial.
                   9261: 
1.207     leot     9262: B.2.4. Problems with PKGSRC_USE_SSP
                   9263: 
                   9264: B.2.4.1. Packages failing to build
                   9265: 
                   9266: The stack-smashing protection provided by this option does not work for some
                   9267: programs. The most common situation in which this happens is when the program
                   9268: allocates variables on the stack, with the size determined at run-time.
                   9269: 
                   9270: B.2.4.2. Run-time crashes
                   9271: 
                   9272: Again, this feature may cause some programs to crash via a SIGABRT, usually
                   9273: indicating an actual bug in the program.
                   9274: 
                   9275: On NetBSD LOG_CRIT level syslog messages are sent and - by default - appended
                   9276: to /var/log/messages, e.g.:
                   9277: 
                   9278: Jan  6 15:42:51 hostname -: hostname program - - - buffer overflow detected; terminated
                   9279: 
                   9280: (where hostname is the hostname(1) and program is the basename(1) of the
                   9281: program crashed).
                   9282: 
                   9283: Patching the original program is then required.
                   9284: 
                   9285: Rebuilding the package via:
                   9286: 
                   9287: % env CFLAGS=-g INSTALL_UNSTRIPPED=yes make replace
                   9288: 
                   9289: and inspecting the backtrace of the coredump via the debugger should point out
                   9290: the problematic call by inspecting the frame calling the _chk() (SSP) function.
                   9291: 
                   9292: B.2.4.3. Performance impact
                   9293: 
                   9294: The compiler emits extra code when using this feature: a check for buffer
                   9295: overflows is performed when entering and exiting functions, requiring an extra
                   9296: variable on the stack. The level of protection can otherwise be adjusted to
                   9297: affect only those functions considered more sensitive by the compiler (with
                   9298: -fstack-protector instead of -fstack-protector-all).
                   9299: 
                   9300: The impact is not expected to be noticeable on modern hardware. However,
                   9301: programs with a hard requirement to run at the fastest possible speed should
                   9302: avoid using this feature, or using libraries built with this feature.
                   9303: 
                   9304: B.2.4.4. Disabling SSP on a per-package basis
                   9305: 
                   9306: Note
                   9307: 
                   9308: SSP should not be disabled to work around runtime crashes in the program! This
                   9309: is a very bad idea and will expose you to security vulnerabilities.
                   9310: 
                   9311: To disable SSP on a per-package basis, set the following in the package's
                   9312: Makefile before bsd.prefs.mk is included:
                   9313: 
                   9314: SSP_SUPPORTED=  no
                   9315: 
                   9316: B.3. Auditing the system
                   9317: 
                   9318: The illusion of security is worse than having no security at all. This section
                   9319: lists a number of ways to ensure the security features requested are actually
                   9320: effective.
                   9321: 
                   9322: These instructions were obtained and tested on a system derived from NetBSD 7
                   9323: (amd64). YMMV.
                   9324: 
                   9325: B.3.1. Checking for PIE
                   9326: 
                   9327: The ELF executable type in use changes for binaries built as PIE; without:
                   9328: 
                   9329: $ file /path/to/bin/ary
                   9330: /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
                   9331: 
                   9332: as opposed to the following binary, built as PIE:
                   9333: 
                   9334: $ file /path/to/pie/bin/ary
                   9335: /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
                   9336: 
                   9337: The latter result is then what is expected.
                   9338: 
                   9339: B.3.2. Checking for partial RELRO
                   9340: 
                   9341: The following command should list a section called RELRO:
                   9342: 
                   9343: $ objdump -p /path/to/bin/ary
                   9344: 
                   9345: /path/to/bin/ary:     file format elf64-x86-64
                   9346: 
                   9347: Program Header:
                   9348: [...]
                   9349:    RELRO off    0x0000000000000d78 vaddr 0x0000000000600d78 paddr 0x0000000000600d78 align 2**0
                   9350: 
                   9351: This check is now performed automatically if PKG_DEVELOPER is set and RELRO is
                   9352: enabled.
                   9353: 
                   9354: B.3.3. Checking for full RELRO
                   9355: 
                   9356: The dynamic loader will apply RELRO immediately when detecting the presence of
                   9357: the BIND_NOW flag:
                   9358: 
                   9359: $ objdump -x /path/to/bin/ary
                   9360: 
                   9361: /path/to/bin/ary:     file format elf64-x86-64
                   9362: 
                   9363: Dynamic Section:
                   9364: [...]
                   9365:   BIND_NOW             0x0000000000000000
                   9366: 
                   9367: This has to be combined with partial RELRO (see above) to be fully efficient.
                   9368: 
                   9369: This check is now performed automatically (where supported) if PKG_DEVELOPER is
                   9370: set.
                   9371: 
                   9372: B.3.4. Checking for SSP
                   9373: 
1.208     nia      9374: Note
                   9375: 
                   9376: Checking for SSP using this method only works where the operating system uses
                   9377: libssp. libssp is not used on recent NetBSD/FreeBSD/Linux versions.
                   9378: 
1.207     leot     9379: Building objects, binaries and libraries with SSP will affect the presence of
                   9380: additional symbols in the resulting file:
                   9381: 
                   9382: $ nm /path/to/bin/ary
                   9383: [...]
                   9384:                  U __stack_chk_fail
                   9385: 0000000000600ea0 B __stack_chk_guard
                   9386: 
                   9387: This is an indicator that the program was indeed built with support for SSP.
                   9388: 
                   9389: This check is now performed automatically (where supported) if PKG_DEVELOPER is
                   9390: set and SSP is enabled.
                   9391: 
                   9392: Appendix C. Build logs
1.1       dsieger  9393: 
                   9394: Table of Contents
                   9395: 
1.207     leot     9396: C.1. Building figlet
                   9397: C.2. Packaging figlet
1.1       dsieger  9398: 
1.207     leot     9399: C.1. Building figlet
1.1       dsieger  9400: 
                   9401: # make
                   9402: ===> Checking for vulnerabilities in figlet-2.2.1nb2
                   9403: => figlet221.tar.gz doesn't seem to exist on this system.
                   9404: => Attempting to fetch figlet221.tar.gz from ftp://ftp.figlet.org/pub/figlet/program/unix/.
                   9405: => [172219 bytes]
                   9406: Connected to ftp.plig.net.
                   9407: 220 ftp.plig.org NcFTPd Server (licensed copy) ready.
                   9408: 331 Guest login ok, send your complete e-mail address as password.
                   9409: 230-You are user #5 of 500 simultaneous users allowed.
                   9410: 230-
                   9411: 230-  ___ _             _ _
                   9412: 230- |  _| |_ ___   ___| |_|___   ___ ___ ___
                   9413: 230- |  _|  _| . |_| . | | | . |_| . |  _| . |
                   9414: 230- |_| |_| |  _|_|  _|_|_|_  |_|___|_| |_  |
                   9415: 230-         |_|   |_|     |___|         |___|
                   9416: 230-
                   9417: 230-** Welcome to ftp.plig.org **
                   9418: 230-
                   9419: 230-Please note that all transfers from this FTP site are logged. If you
                   9420: 230-do not like this, please disconnect now.
                   9421: 230-
1.19      snj      9422: 230-This archive is available via
1.1       dsieger  9423: 230-
                   9424: 230-HTTP:  http://ftp.plig.org/
                   9425: 230-FTP:   ftp://ftp.plig.org/     (max 500 connections)
                   9426: 230-RSYNC: rsync://ftp.plig.org/   (max  30 connections)
                   9427: 230-
                   9428: 230-Please email comments, bug reports and requests for packages to be
                   9429: 230-mirrored to ftp-admin@plig.org.
                   9430: 230-
                   9431: 230-
                   9432: 230 Logged in anonymously.
                   9433: Remote system type is UNIX.
                   9434: Using binary mode to transfer files.
                   9435: 200 Type okay.
                   9436: 250 "/pub" is new cwd.
                   9437: 250-"/pub/figlet" is new cwd.
                   9438: 250-
                   9439: 250-Welcome to the figlet archive at ftp.figlet.org
                   9440: 250-
                   9441: 250-    ftp://ftp.figlet.org/pub/figlet/
                   9442: 250-
                   9443: 250-The official FIGlet web page is:
                   9444: 250-    http://www.figlet.org/
                   9445: 250-
                   9446: 250-If you have questions, please mailto:info@figlet.org. If you want to
                   9447: 250-contribute a font or something else, you can email us.
                   9448: 250
                   9449: 250 "/pub/figlet/program" is new cwd.
                   9450: 250 "/pub/figlet/program/unix" is new cwd.
                   9451: local: figlet221.tar.gz remote: figlet221.tar.gz
                   9452: 502 Unimplemented command.
                   9453: 227 Entering Passive Mode (195,40,6,41,246,104)
                   9454: 150 Data connection accepted from 84.128.86.72:65131; transfer starting for figlet221.tar.gz (172219 bytes).
                   9455: 38% |**************                       | 65800      64.16 KB/s    00:01 ETA
                   9456: 226 Transfer completed.
                   9457: 172219 bytes received in 00:02 (75.99 KB/s)
                   9458: 221 Goodbye.
                   9459: => Checksum OK for figlet221.tar.gz.
                   9460: ===> Extracting for figlet-2.2.1nb2
                   9461: ===> Required installed package ccache-[0-9]*: ccache-2.3nb1 found
                   9462: ===> Patching for figlet-2.2.1nb2
                   9463: ===> Applying pkgsrc patches for figlet-2.2.1nb2
                   9464: ===> Overriding tools for figlet-2.2.1nb2
                   9465: ===> Creating toolchain wrappers for figlet-2.2.1nb2
                   9466: ===> Configuring for figlet-2.2.1nb2
                   9467: ===> Building for figlet-2.2.1nb2
                   9468: gcc -O2 -DDEFAULTFONTDIR=\"/usr/pkg/share/figlet\"  -DDEFAULTFONTFILE=\"standard.flf\"  figlet.c zipio.c crc.c inflate.c -o figlet
                   9469: chmod a+x figlet
                   9470: gcc -O2 -o chkfont chkfont.c
                   9471: => Unwrapping files-to-be-installed.
                   9472: #
                   9473: # make install
                   9474: ===> Checking for vulnerabilities in figlet-2.2.1nb2
                   9475: ===> Installing for figlet-2.2.1nb2
                   9476: install -d -o root -g wheel -m 755 /usr/pkg/bin
                   9477: install -d -o root -g wheel -m 755 /usr/pkg/man/man6
                   9478: mkdir -p /usr/pkg/share/figlet
                   9479: cp figlet /usr/pkg/bin
                   9480: cp chkfont /usr/pkg/bin
                   9481: chmod 555 figlist showfigfonts
                   9482: cp figlist /usr/pkg/bin
                   9483: cp showfigfonts /usr/pkg/bin
                   9484: cp fonts/*.flf /usr/pkg/share/figlet
                   9485: cp fonts/*.flc /usr/pkg/share/figlet
                   9486: cp figlet.6 /usr/pkg/man/man6
                   9487: ===> Registering installation for figlet-2.2.1nb2
                   9488: #
                   9489: 
1.207     leot     9490: C.2. Packaging figlet
1.1       dsieger  9491: 
                   9492: # make package
                   9493: ===> Checking for vulnerabilities in figlet-2.2.1nb2
                   9494: ===> Packaging figlet-2.2.1nb2
                   9495: ===> Building binary package for figlet-2.2.1nb2
                   9496: Creating package /home/cvs/pkgsrc/packages/i386/All/figlet-2.2.1nb2.tgz
                   9497: Using SrcDir value of /usr/pkg
                   9498: Registering depends:.
                   9499: #
                   9500: 
1.207     leot     9501: Appendix D. Directory layout of the pkgsrc FTP server
1.1       dsieger  9502: 
                   9503: Table of Contents
                   9504: 
1.207     leot     9505: D.1. distfiles: The distributed source files
                   9506: D.2. misc: Miscellaneous things
                   9507: D.3. packages: Binary packages
                   9508: D.4. reports: Bulk build reports
                   9509: D.5. current, stable, pkgsrc-20xxQy: source packages
1.1       dsieger  9510: 
                   9511: As in other big projects, the directory layout of pkgsrc is quite complex for
                   9512: newbies. This chapter explains where you find things on the FTP server. The
                   9513: base directory on ftp.NetBSD.org is /pub/pkgsrc/. On other servers it may be
                   9514: different, but inside this directory, everything should look the same, no
                   9515: matter on which server you are. This directory contains some subdirectories,
                   9516: which are explained below.
                   9517: 
1.207     leot     9518: D.1. distfiles: The distributed source files
1.1       dsieger  9519: 
                   9520: The directory distfiles contains lots of archive files from all pkgsrc
                   9521: packages, which are mirrored here. The subdirectories are called after their
                   9522: package names and are used when the distributed files have names that don't
                   9523: explicitly contain a version number or are otherwise too generic (for example
                   9524: release.tar.gz).
                   9525: 
1.207     leot     9526: D.2. misc: Miscellaneous things
1.1       dsieger  9527: 
                   9528: This directory contains things that individual pkgsrc developers find worth
                   9529: publishing.
                   9530: 
1.207     leot     9531: D.3. packages: Binary packages
1.1       dsieger  9532: 
1.3       rillig   9533: This directory contains binary packages for the various platforms that are
                   9534: supported by pkgsrc. Each subdirectory is of the form OPSYS/ARCH/OSVERSION_TAG.
                   9535: The meaning of these variables is:
                   9536: 
                   9537:   * OPSYS is the name of the operating system for which the packages have been
1.9       rillig   9538:     built. The name is taken from the output of the uname command, so it may
                   9539:     differ from the one you are used to hear.
1.3       rillig   9540: 
1.8       rillig   9541:   * ARCH is the hardware architecture of the platform for which the packages
1.10      hubertf  9542:     have been built. It also includes the ABI (Application Binary Interface)
                   9543:     for platforms that have several of them.
1.3       rillig   9544: 
1.8       rillig   9545:   * OSVERSION is the version of the operating system. For version numbers that
                   9546:     change often (for example NetBSD-current), the often-changing part should
                   9547:     be replaced with an x, for example 4.99.x.
1.3       rillig   9548: 
1.23      jakllsch 9549:   * TAG is either 20xxQy for a stable branch, or head for packages built from
1.8       rillig   9550:     the HEAD branch. The latter should only be used when the packages are
                   9551:     updated on a regular basis. Otherwise the date from checking out pkgsrc
                   9552:     should be appended, for example head_20071015.
1.3       rillig   9553: 
                   9554: The rationale for exactly this scheme is that the pkgsrc users looking for
                   9555: binary packages can quickly click through the directories on the server and
                   9556: find the best binary packages for their machines. Since they usually know the
                   9557: operating system and the hardware architecture, OPSYS and ARCH are placed
                   9558: first. After these choices, they can select the best combination of OSVERSION
                   9559: and TAG together, since it is usually the case that packages stay compatible
                   9560: between different version of the operating system.
                   9561: 
                   9562: In each of these directories, there is a whole binary packages collection for a
                   9563: specific platform. It has a directory called All which contains all binary
                   9564: packages. Besides that, there are various category directories that contain
                   9565: symbolic links to the real binary packages.
1.1       dsieger  9566: 
1.207     leot     9567: D.4. reports: Bulk build reports
1.8       rillig   9568: 
                   9569: Here are the reports from bulk builds, for those who want to fix packages that
                   9570: didn't build on some of the platforms. The structure of subdirectories should
1.207     leot     9571: look like the one in Section D.3, "packages: Binary packages".
1.8       rillig   9572: 
1.207     leot     9573: D.5. current, stable, pkgsrc-20xxQy: source packages
1.1       dsieger  9574: 
                   9575: These directories contain the "real" pkgsrc, that is the files that define how
                   9576: to create binary packages from source archives.
                   9577: 
1.149     leot     9578: Each of the current, stable and pkgsrc-20xxQy directories share the same
                   9579: structure. They each contain a pkgsrc directory and pkgsrc.tar.{bz,gz,xz} file.
                   9580: 
1.1       dsieger  9581: The directory pkgsrc contains a snapshot of the CVS repository, which is
1.149     leot     9582: updated regularly. The file pkgsrc.tar.{bz,gz,xz} contains the same as the
                   9583: directory, ready to be downloaded as a whole.
1.1       dsieger  9584: 
1.149     leot     9585: The current directory contains files related to the HEAD branch of the CVS
                   9586: repository. In this directory there is an additional file called
                   9587: pkgsrc-readmes.tar.{bz,gz,xz} that contains all pkgsrc READMEs with information
                   9588: about categories and packages.
                   9589: 
                   9590: The stable directory is a symlink to the latest pkgsrc-20xxQy.
                   9591: 
                   9592: The pkgsrc-20xxQy. directories contain files related to the -20xxQy stable
                   9593: branch of the CVS repository. In these directories there is an additional file
                   9594: called pkgsrc-20xxQy.tar.{bz,gz,xz}, which contains the state of pkgsrc when it
                   9595: was branched.
1.148     leot     9596: 
1.207     leot     9597: Appendix E. Help topics
1.154     rillig   9598: 
                   9599: The following list contains all help topics that are available when running 
                   9600: bmake help topic=:index.
                   9601: 
1.229   ! gutterid 9602: #!                                -lintl
        !          9603: 32bit                             64bit
        !          9604: ABI                               ACCEPTABLE_LICENSES
        !          9605: ACROREAD_FONTPATH                 ADDITIONAL
        !          9606: AFAIK                             AIX
        !          9607: ALLOW_VULNERABLE_PACKAGES         ALL_ENV
        !          9608: ALTERNATIVES_SRC                  AMANDA_TMP
        !          9609: AMANDA_USER                       AMANDA_VAR
        !          9610: APACHE_GROUP                      APACHE_MODULE_NAME
        !          9611: APACHE_MODULE_SRC                 APACHE_MODULE_SRCDIR
        !          9612: APACHE_PKG_PREFIX                 APACHE_SUEXEC_CONFIGURE_ARGS
        !          9613: APACHE_SUEXEC_DOCROOT             APACHE_USER
        !          9614: APPEND_ABI                        APPEND_ELF
        !          9615: ARLA_CACHE                        AUDIT_PACKAGES_FLAGS
        !          9616: AUTOCONF_REQD                     AUTOMAKE_OVERRIDE
        !          9617: AUTOMAKE_REQD                     AUTO_MKDIRS
        !          9618: BDB185_DEFAULT                    BDBBASE
        !          9619: BDB_ACCEPTED                      BDB_DEFAULT
        !          9620: BDB_LIBS                          BDB_TYPE
        !          9621: BINCIMAP_GROUP                    BINCIMAP_USER
        !          9622: BIND_DIR                          BIND_GROUP
        !          9623: BIND_USER                         BINOWN
        !          9624: BINPKG_SITES                      BIN_INSTALL_FLAGS
        !          9625: BISON_PKGDATADIR                  BLAS
        !          9626: BLAS_ACCEPTED                     BLAS_C_INTERFACE
        !          9627: BLAS_INCLUDES                     BLAS_INDEX64
        !          9628: BLAS_LIBS                         BLAS_PC
        !          9629: BLAS_TYPE                         BOOTSTRAP_DEPENDS
        !          9630: BROKEN                            BROKEN_EXCEPT_ON_PLATFORM
        !          9631: BROKEN_ON_PLATFORM                BSDSRCDIR
        !          9632: BSDXSRCDIR                        BSD_MAKE_ENV
        !          9633: BUILDLINK_AUTO_DIRS               BUILDLINK_AUTO_VARS
        !          9634: BUILDLINK_CFLAGS                  BUILDLINK_CONTENTS_FILTER
        !          9635: BUILDLINK_CPPFLAGS                BUILDLINK_FILES
        !          9636: BUILDLINK_FILES_CMD               BUILDLINK_FNAME_TRANSFORM
        !          9637: BUILDLINK_LDFLAGS                 BUILDLINK_LIBS
        !          9638: BUILDLINK_OPSYS_SUPPORT_PTHREAD   BUILDLINK_PKGNAME
        !          9639: BUILDLINK_PREFIX                  BUILDLINK_RPATHDIRS
        !          9640: BUILDLINK_TREE                    BUILD_DEFS
        !          9641: BUILD_DEFS_EFFECTS                BUILD_DEPENDS
        !          9642: BUILD_DIRS                        BUILD_ENV_SHELL
        !          9643: BUILD_MAKE_CMD                    BUILD_MAKE_FLAGS
        !          9644: BUILD_TARGET                      BUILTIN_FIND_FILES
        !          9645: BUILTIN_FIND_FILES_VAR            BUILTIN_FIND_GREP
        !          9646: BUILTIN_FIND_HEADERS              BUILTIN_FIND_HEADERS_VAR
        !          9647: BUILTIN_FIND_PKGCONFIG            BUILTIN_FIND_PKGCONFIG_VAR
        !          9648: BUILTIN_PKG                       BUILTIN_TEST_CURSES_DEFINES
        !          9649: BUILTIN_TEST_CURSES_FUNCS         BUILTIN_VERSION_SCRIPT
        !          9650: BUILTIN_X11_TYPE                  BUILTIN_X11_VERSION
        !          9651: CACTI_GROUP                       CACTI_USER
        !          9652: CANNA_GROUP                       CANNA_USER
        !          9653: CAT                               CBLAS_LIBS
        !          9654: CBLAS_PC                          CCACHE_BASE
        !          9655: CCACHE_DIR                        CCACHE_LOGFILE
        !          9656: CC_VERSION                        CC_VERSION_STRING
        !          9657: CDRECORD_CONF                     CDROM_PKG_URL_DIR
        !          9658: CDROM_PKG_URL_HOST                CHANGES
        !          9659: CHECK_COMPILER                    CHECK_FAKEHOME
        !          9660: CHECK_FILES                       CHECK_FILES_SKIP
        !          9661: CHECK_FILES_STRICT                CHECK_HEADERS
        !          9662: CHECK_HEADERS_SKIP                CHECK_INTERPRETER
        !          9663: CHECK_INTERPRETER_SKIP            CHECK_PERMS
        !          9664: CHECK_PERMS_AUTOFIX               CHECK_PERMS_SKIP
        !          9665: CHECK_PIE                         CHECK_PIE_SKIP
        !          9666: CHECK_PIE_SUPPORTED               CHECK_PORTABILITY
        !          9667: CHECK_PORTABILITY_EXPERIMENTAL    CHECK_PORTABILITY_SKIP
        !          9668: CHECK_RELRO                       CHECK_RELRO_SKIP
        !          9669: CHECK_RELRO_SUPPORTED             CHECK_SHLIBS
        !          9670: CHECK_SHLIBS_SKIP                 CHECK_SHLIBS_SUPPORTED
        !          9671: CHECK_SHLIBS_TOXIC                CHECK_SSP
        !          9672: CHECK_SSP_SKIP                    CHECK_SSP_SUPPORTED
        !          9673: CHECK_STRIPPED                    CHECK_STRIPPED_SKIP
        !          9674: CHECK_WRKREF                      CHECK_WRKREF_EXTRA_DIRS
        !          9675: CHECK_WRKREF_SKIP                 CLAMAV_DBDIR
        !          9676: CLAMAV_GROUP                      CLAMAV_USER
        !          9677: CLANGBASE                         CLEANDEPENDS
        !          9678: CMAKE_DEPENDENCIES_REWRITE        CMAKE_INSTALL_NAME_DIR
        !          9679: CMAKE_INSTALL_PREFIX              CMAKE_MODULE_PATH_OVERRIDE
        !          9680: CMAKE_PKGSRC_BUILD_FLAGS          CMAKE_PREFIX_PATH
        !          9681: CMAKE_USE_GNU_INSTALL_DIRS        COMPILER_RPATH_FLAG
        !          9682: COMPILER_USE_SYMLINKS             CONFIGURE_ARGS
        !          9683: CONFIGURE_DIRS                    CONFIGURE_ENV
        !          9684: CONFIGURE_ENV_SHELL               CONFIGURE_HAS_INFODIR
        !          9685: CONFIGURE_HAS_MANDIR              CONFIGURE_SCRIPT
        !          9686: CONFIG_SHELL                      CONFIG_SHELL_FLAGS
        !          9687: CONF_FILES                        CONF_FILES_MODE
        !          9688: CONF_FILES_PERMS                  CONSERVER_DEFAULTHOST
        !          9689: CONSERVER_DEFAULTPORT             CP
        !          9690: CPP                               CPP_PRECOMP_FLAGS
        !          9691: CREATE_WRKDIR_SYMLINK             CROSSBASE
        !          9692: CTFCONVERT                        CTF_FILES_SKIP
        !          9693: CTF_SUPPORTED                     CTYPE
        !          9694: CUPS_GROUP                        CUPS_SYSTEM_GROUPS
        !          9695: CUPS_USER                         CURSES_DEFAULT
        !          9696: CURSES_TYPE                       CXX
        !          9697: CYRUS_GROUP                       CYRUS_IDLE
        !          9698: CYRUS_USER                        DAEMONTOOLS_GROUP
        !          9699: DAEMONTOOLS_LOG_USER              DARWIN_NO_SYSTEM_LIBS
        !          9700: DARWIN_REQUIRES_FILTER            DBUS_GROUP
        !          9701: DBUS_USER                         DEFANG_GROUP
        !          9702: DEFANG_USER                       DEFAULT_ACCEPTABLE_LICENSES
        !          9703: DEFAULT_DISTFILES                 DEFAULT_IRC_SERVER
        !          9704: DEFAULT_SERIAL_DEVICE             DEF_UMASK
        !          9705: DEINSTALLDEPENDS                  DEINSTALL_SRC
        !          9706: DEINSTALL_TEMPLATES               DELAYED_ERROR_MSG
        !          9707: DELAYED_WARNING_MSG               DEPENDS
        !          9708: DEPENDS_TARGET                    DEPENDS_TYPE
        !          9709: DESTDIR                           DESTDIR_VARNAME
        !          9710: DIALER_GROUP                      DIGEST_REQD
        !          9711: DISTDIR                           DISTFILES
        !          9712: DISTINFO_FILE                     DISTNAME
        !          9713: DIST_PATH                         DIST_SUBDIR
        !          9714: DJBDNS_AXFR_USER                  DJBDNS_CACHE_USER
        !          9715: DJBDNS_DJBDNS_GROUP               DJBDNS_LOG_USER
        !          9716: DJBDNS_RBL_USER                   DJBDNS_TINY_USER
        !          9717: DLOPEN_REQUIRE_PTHREADS           DL_AUTO_VARS
        !          9718: DL_CFLAGS                         DL_LDFLAGS
        !          9719: DL_LIBS                           DNS
        !          9720: DOCOWN                            DOWNLOADED_DISTFILE
        !          9721: DQCACHE_GROUP                     DQCACHE_USER
        !          9722: DT_LAYOUT                         DYNAMIC_SITES_CMD
        !          9723: DYNAMIC_SITES_SCRIPT              ECHO
        !          9724: ECHO_N                            ELK_GUI
        !          9725: EMACS_TYPE                        EMULDIR
        !          9726: EMULSUBDIR                        EMULSUBDIRSLASH
        !          9727: EMUL_ARCH                         EMUL_DISTRO
        !          9728: EMUL_EXEC_FMT                     EMUL_IS_NATIVE
        !          9729: EMUL_MODULES                      EMUL_OPSYS
        !          9730: EMUL_PKG_FMT                      EMUL_PLATFORM
        !          9731: EMUL_PLATFORMS                    EMUL_PREFER
        !          9732: EMUL_REQD                         EMUL_TYPE
        !          9733: ERROR_MSG                         EXIM_GROUP
        !          9734: EXIM_USER                         EXPORT_SYMBOLS_LDFLAGS
        !          9735: EXTRACTOR                         EXTRACT_CMD
        !          9736: EXTRACT_CMD_DEFAULT               EXTRACT_DIR
        !          9737: EXTRACT_ELEMENTS                  EXTRACT_ENV
        !          9738: EXTRACT_ONLY                      EXTRACT_OPTS
        !          9739: EXTRACT_SUFX                      EXTRACT_USING
        !          9740: FAIL                              FAILOVER_FETCH
        !          9741: FAIL_MSG                          FAKE_NCURSES
        !          9742: FAM                               FAM_ACCEPTED
        !          9743: FAM_DEFAULT                       FAM_SERVER
        !          9744: FCPATH                            FEATURE_CPPFLAGS
        !          9745: FEATURE_LDFLAGS                   FEATURE_LIBS
        !          9746: FETCH_AFTER_ARGS                  FETCH_BEFORE_ARGS
        !          9747: FETCH_CMD                         FETCH_OUTPUT_ARGS
        !          9748: FETCH_PROXY                       FETCH_RESUME_ARGS
        !          9749: FETCH_TIMEOUT                     FETCH_USE_IPV4_ONLY
        !          9750: FETCH_USING                       FILES_SUBST
        !          9751: FILES_SUBST_SED                   FIX_SYSTEM_HEADERS
        !          9752: FONTS_DIRS                        FONTS_VERBOSE
        !          9753: FOO_HACKS_MK                      FOX_USE_XUNICODE
        !          9754: FREEWNN_GROUP                     FREEWNN_USER
        !          9755: FTP_PKG_URL_DIR                   FTP_PKG_URL_HOST
        !          9756: GAMEDATAMODE                      GAMEDATA_PERMS
        !          9757: GAMEDIRMODE                       GAMEDIR_PERMS
        !          9758: GAMEGRP                           GAMEMODE
        !          9759: GAMEOWN                           GAMES_GROUP
        !          9760: GAMES_USER                        GCC
        !          9761: GCCBASE                           GCC_REQD
        !          9762: GCC_VERSION_SUFFIX                GEM_BUILD
        !          9763: GEM_CLEANBUILD                    GEM_CLEANBUILD_EXTENSIONS
        !          9764: GEM_DOCDIR                        GEM_EXTSDIR
        !          9765: GEM_HOME                          GEM_KEEPBUILD
        !          9766: GEM_LIBDIR                        GEM_NAME
        !          9767: GEM_PATH                          GEM_PLUGINSDIR
        !          9768: GEM_SPECFILE                      GENERATE_PLIST
        !          9769: GHC                               GHOSTSCRIPT_REQD
        !          9770: GITHUB_PROJECT                    GITHUB_RELEASE
        !          9771: GITHUB_SUBMODULES                 GITHUB_TAG
        !          9772: GITHUB_TYPE                       GITLAB_PROJECT
        !          9773: GITLAB_RELEASE                    GITLAB_SUBMODULES
        !          9774: GITLAB_TAG                        GITLAB_TYPE
        !          9775: GNU                               GNU_CONFIGURE
        !          9776: GNU_CONFIGURE_INFODIR             GNU_CONFIGURE_MANDIR
        !          9777: GNU_CONFIGURE_QUIET               GNU_CONFIGURE_STRICT
        !          9778: GODEP_REDIRECTS                   GO_BUILD_PATTERN
        !          9779: GO_DEPS                           GO_DIST_BASE
        !          9780: GO_EXTRA_MOD_DIRS                 GO_MODULE_FILES
        !          9781: GO_SRCPATH                        GROUP_SPECIFIC_PKGS
        !          9782: GRUB_NETWORK_CARDS                GRUB_PRESET_COMMAND
        !          9783: GRUB_SCAN_ARGS                    GZIP
        !          9784: HASKELL_ENABLE_DYNAMIC_EXECUTABLE HASKELL_ENABLE_HADDOCK_DOCUMENTATION
        !          9785: HASKELL_ENABLE_LIBRARY_PROFILING  HASKELL_ENABLE_SHARED_LIBRARY
        !          9786: HASKELL_OPTIMIZATION_LEVEL        HASKELL_PKG_NAME
        !          9787: HASKELL_UNRESTRICT_DEPENDENCIES   HAS_CONFIGURE
        !          9788: HEADER_TEMPLATES                  HOMEPAGE
        !          9789: HOST_PKGTOOLS_ARGS                HOST_SPECIFIC_PKGS
        !          9790: HOWL_GROUP                        HOWL_USER
        !          9791: ICCBASE                           ICECAST_CHROOTDIR
        !          9792: ICON_THEMES                       IDOBASE
        !          9793: IGNORE_CCACHE                     IGNORE_INFO_DIRS
        !          9794: IGNORE_INTERACTIVE_FETCH          IMAKE
        !          9795: IMAKEOPTS                         IMAKE_MAKE
        !          9796: IMAKE_MANINSTALL                  IMAP_UW_CCLIENT_MBOX_FMT
        !          9797: IMDICTDIR                         INCOMPAT_CURSES
        !          9798: INFO_DIR                          INFO_FILES
        !          9799: INFO_FILES_VERBOSE                INFO_MSG
        !          9800: INIT_SYSTEM                       INN_DATA_DIR
        !          9801: INN_GROUP                         INN_USER
        !          9802: INSTALLATION_DIRS                 INSTALLATION_DIRS_FROM_PLIST
        !          9803: INSTALL_ENV                       INSTALL_SH_OVERRIDE
        !          9804: INSTALL_SRC                       INSTALL_TEMPLATES
        !          9805: INSTALL_UNSTRIPPED                IRCD_HYBRID_IRC_GROUP
        !          9806: IRCD_HYBRID_IRC_USER              IRCD_HYBRID_MAXCONN
        !          9807: IRCD_HYBRID_NICLEN                IRCD_HYBRID_SYSLOG_EVENTS
        !          9808: IRCD_HYBRID_SYSLOG_FACILITY       IRCD_HYBRID_TOPICLEN
        !          9809: IRIX                              IRRD_USE_PGP
        !          9810: JABBERD_GROUP                     JABBERD_LOGDIR
        !          9811: JABBERD_PIDDIR                    JABBERD_SPOOLDIR
        !          9812: JABBERD_USER                      JAVA_BINPREFIX
        !          9813: JAVA_CLASSPATH                    JAVA_HOME
        !          9814: JAVA_LD_LIBRARY_PATH              JAVA_NAME
        !          9815: JAVA_UNLIMIT                      JAVA_WRAPPERS
        !          9816: JPEG_ACCEPTED                     JPEG_DEFAULT
        !          9817: KERBEROS                          KERMIT_SUID_UUCP
        !          9818: KJS_USE_PCRE                      KNEWS_DOMAIN_FILE
        !          9819: KNEWS_DOMAIN_NAME                 KRB5_ACCEPTED
        !          9820: KRB5_DEFAULT                      LANGUAGES
        !          9821: LAPACKE_LIBS                      LAPACKE_PC
        !          9822: LAPACK_LIBS                       LAPACK_PC
        !          9823: LATEX2HTML_ICONPATH               LDCONFIG_ADD_CMD
        !          9824: LDCONFIG_REMOVE_CMD               LDD
        !          9825: LEAFNODE_DATA_DIR                 LEAFNODE_GROUP
        !          9826: LEAFNODE_USER                     LIBDVDCSS_HOMEPAGE
        !          9827: LIBDVDCSS_MASTER_SITES            LIBRSVG_TYPE
        !          9828: LIBTOOL                           LIBTOOLIZE_PLIST
        !          9829: LIBTOOL_M4_OVERRIDE               LIBUSB_TYPE
        !          9830: LICENSE                           LINKER_RPATH_FLAG
        !          9831: LINK_RPATH_FLAG                   LINUX_LOCALES
        !          9832: LOCALBASE                         LOCALBASE_LOCKTYPE
        !          9833: LOCALPATCHES                      LOVE_DATA
        !          9834: LOVE_GAME                         LOVE_VERSION
        !          9835: LP32PLATFORMS                     LP64PLATFORMS
        !          9836: LUA_BUSTED_ARGS                   LUA_CDIR
        !          9837: LUA_COMPILER                      LUA_DOCDIR
        !          9838: LUA_EXAMPLESDIR                   LUA_INCDIR
        !          9839: LUA_INTERPRETER                   LUA_LDIR
        !          9840: LUA_LINKER_MAGIC                  LUA_PKGPREFIX
        !          9841: LUA_SELF_CONFLICT                 LUA_USE_BUSTED
        !          9842: LUA_VERSIONS_ACCEPTED             LUA_VERSIONS_INCOMPATIBLE
        !          9843: LUA_VERSION_DEFAULT               LUA_VERSION_REQD
        !          9844: Lua                               MACHINE_PLATFORM
        !          9845: MAILAGENT_DOMAIN                  MAILAGENT_EMAIL
        !          9846: MAILAGENT_FQDN                    MAILAGENT_ORGANIZATION
        !          9847: MAJORDOMO_HOMEDIR                 MAKEINFO_ARGS
        !          9848: MAKE_DIRS                         MAKE_DIRS_PERMS
        !          9849: MAKE_ENV                          MAKE_FILE
        !          9850: MAKE_FLAGS                        MAKE_JOBS
        !          9851: MAKE_JOBS_SAFE                    MAKE_PROGRAM
        !          9852: MANCOMPRESSED_IF_MANZ             MANINSTALL
        !          9853: MANZ                              MASTER_SITES
        !          9854: MASTER_SITE_BACKUP                MASTER_SITE_LOCAL
        !          9855: MASTER_SITE_MOZILLA               MASTER_SITE_OVERRIDE
        !          9856: MASTER_SITE_PERL_CPAN             MASTER_SORT
        !          9857: MASTER_SORT_RANDOM                MASTER_SORT_REGEX
        !          9858: MECAB_CHARSET                     MEDIATOMB_GROUP
        !          9859: MEDIATOMB_USER                    MIPSPROBASE
        !          9860: MIREDO_GROUP                      MIREDO_USER
        !          9861: MISSING_FEATURES                  MKDIR
        !          9862: MKPIE_SUPPORTED                   MLDONKEY_GROUP
        !          9863: MLDONKEY_HOME                     MLDONKEY_USER
        !          9864: MONOTONE_GROUP                    MONOTONE_USER
        !          9865: MOTIFBASE                         MOTIF_TYPE
        !          9866: MOTIF_TYPE_DEFAULT                MPI_TYPE
        !          9867: MSGFMT_STRIP_MSGCTXT              MSGFMT_STRIP_MSGID_PLURAL
        !          9868: MTOOLS_ENABLE_FLOPPYD             MV
        !          9869: MYSQL_CHARSET                     MYSQL_DATADIR
        !          9870: MYSQL_EXTRA_CHARSET               MYSQL_GROUP
        !          9871: MYSQL_USER                        MYSQL_VERSION
        !          9872: MYSQL_VERSIONS_ACCEPTED           MYSQL_VERSIONS_ALL
        !          9873: MYSQL_VERSION_DEFAULT             NAGIOSCMD_GROUP
        !          9874: NAGIOSDIR                         NAGIOS_GROUP
        !          9875: NAGIOS_USER                       NATIVE_APPEND_ABI
        !          9876: NATIVE_APPEND_ELF                 NATIVE_EXEC_FMT
        !          9877: NATIVE_MACHINE_PLATFORM           NATIVE_OBJECT_FMT
        !          9878: NBPAX_PROGRAM_PREFIX              NETBSD_LOGIN_NAME
        !          9879: NMH_EDITOR                        NMH_MTA
        !          9880: NMH_PAGER                         NODE_VERSIONS_ACCEPTED
        !          9881: NODE_VERSIONS_INCOMPATIBLE        NODE_VERSION_DEFAULT
        !          9882: NODE_VERSION_REQD                 NOLOGIN
        !          9883: NOTE                              NOT_FOR_PLATFORM
        !          9884: NOT_PAX_ASLR_SAFE                 NOT_PAX_MPROTECT_SAFE
        !          9885: NO_BUILD                          NO_CHECKSUM
        !          9886: NO_CONFIGURE                      NO_SKIP
        !          9887: NS_PREFERRED                      NULLMAILER_GROUP
        !          9888: NULLMAILER_USER                   OASIS
        !          9889: OASIS_BUILD_ARGS                  OBJHOSTNAME
        !          9890: OBJMACHINE                        OCAML_FINDLIB_DIRS
        !          9891: OCAML_FINDLIB_REGISTER            OCAML_FINDLIB_REGISTER_VERBOSE
        !          9892: OCAML_SITELIBDIR                  OCAML_TOPKG_DOCDIR
        !          9893: OCAML_USE_DUNE                    OCAML_USE_FINDLIB
        !          9894: OCAML_USE_OASIS                   OCAML_USE_OASIS_DYNRUN
        !          9895: OCAML_USE_OPAM                    OCAML_USE_TOPKG
        !          9896: OMF                               ONLY_FOR_COMPILER
        !          9897: ONLY_FOR_PLATFORM                 OPENSSH_CHROOT
        !          9898: OPENSSH_GROUP                     OPENSSH_USER
        !          9899: OPSYS                             OPSYS_EMULDIR
        !          9900: OPSYS_VERSION                     OS
        !          9901: OSS_TYPE                          OSX
        !          9902: OSX_TOLERATE_SDK_SKEW             OS_VARIANT
        !          9903: OS_VERSION                        OTF_FONTS_DIR
        !          9904: OVERRIDE_DIRDEPTH                 OVERRIDE_GEMSPEC
        !          9905: OVERRIDE_GNU_CONFIG_SCRIPTS       OWN_DIRS
        !          9906: OWN_DIRS_PERMS                    P4GROUP
        !          9907: P4PORT                            P4ROOT
        !          9908: P4USER                            PACKAGES
        !          9909: PALMOS_DEFAULT_SDK                PAMBASE
        !          9910: PAM_DEFAULT                       PAPERSIZE
        !          9911: PASSIVE_FETCH                     PATCHDIR
        !          9912: PATCHFILES                        PATCH_ARGS
        !          9913: PATCH_DEBUG                       PATCH_DIST_ARGS
        !          9914: PATCH_DIST_CAT                    PATCH_DIST_STRIP
        !          9915: PATCH_FUZZ_FACTOR                 PATCH_STRIP
        !          9916: PATH                              PCCBASE
        !          9917: PEAR_CMD                          PEAR_LIB
        !          9918: PEAR_PACKAGE_XML                  PERL5
        !          9919: PERL5_CONFIGURE                   PERL5_CONFIGURE_DIRS
        !          9920: PERL5_LDFLAGS                     PERL5_LICENSE
        !          9921: PERL5_MODULE_TYPE                 PERL5_PACKLIST
        !          9922: PERL5_PACKLIST_DIR                PERL5_PERLBASE
        !          9923: PERL5_SITEBASE                    PERL5_USE_PACKLIST
        !          9924: PERL5_VENDORBASE                  PFCTL
        !          9925: PFVAR_H                           PF_VERSION
        !          9926: PGGROUP                           PGHOME
        !          9927: PGPKGSRCDIR                       PGSQL_TYPE
        !          9928: PGSQL_VERSION                     PGSQL_VERSIONS_ACCEPTED
        !          9929: PGSQL_VERSION_DEFAULT             PGUSER
        !          9930: PG_LIB_EXT                        PHP
        !          9931: PHPCOMMON_MK                      PHPPKGSRCDIR
        !          9932: PHP_BASE_VERS                     PHP_CHECK_INSTALLED
        !          9933: PHP_EXTENSION_DIR                 PHP_INITIAL_TEENY
        !          9934: PHP_PKG_PREFIX                    PHP_VERSION
        !          9935: PHP_VERSIONS_ACCEPTED             PHP_VERSIONS_INCOMPATIBLE
        !          9936: PHP_VERSION_DEFAULT               PHP_VERSION_REQD
        !          9937: PILRC_USE_GTK                     PKGCONFIG_BASE
        !          9938: PKGCONFIG_FILE                    PKGCONFIG_OVERRIDE
        !          9939: PKGCONFIG_OVERRIDE_STAGE          PKGDIR
        !          9940: PKGGNUDIR                         PKGINFODIR
        !          9941: PKGLOCALEDIR                      PKGMANDIR
        !          9942: PKGNAME                           PKGNAME_REQD
        !          9943: PKGPATH                           PKGREVISION
        !          9944: PKGSRC_BLAS_TYPES                 PKGSRC_CHANGES
        !          9945: PKGSRC_COMPILER                   PKGSRC_KEEP_BIN_PKGS
        !          9946: PKGSRC_LOCKTYPE                   PKGSRC_MAKE_ENV
        !          9947: PKGSRC_MESSAGE_RECIPIENTS         PKGSRC_MKPIE
        !          9948: PKGSRC_MKREPRO                    PKGSRC_OVERRIDE_MKPIE
        !          9949: PKGSRC_RUN_TEST                   PKGSRC_SETENV
        !          9950: PKGSRC_SLEEPSECS                  PKGSRC_TODO
        !          9951: PKGSRC_USE_CTF                    PKGSRC_USE_FORTIFY
        !          9952: PKGSRC_USE_MKTOOLS                PKGSRC_USE_RELRO
        !          9953: PKGSRC_USE_SSP                    PKGSRC_USE_STACK_CHECK
        !          9954: PKGTASKS_DATAFILE                 PKGTOOLS_ARGS
        !          9955: PKGTOOLS_ENV                      PKG_ALTERNATIVES
        !          9956: PKG_APACHE                        PKG_APACHE_ACCEPTED
        !          9957: PKG_APACHE_DEFAULT                PKG_BEST_EXISTS
        !          9958: PKG_BUILD_OPTIONS                 PKG_COMPRESSION
        !          9959: PKG_CONFIG                        PKG_CONFIG_PERMS
        !          9960: PKG_CREATE_USERGROUP              PKG_DB_TMPDIR
        !          9961: PKG_DEBUG_LEVEL                   PKG_DEFAULT_OPTIONS
        !          9962: PKG_DESTDIR_SUPPORT               PKG_DEVELOPER
        !          9963: PKG_DISABLED_OPTIONS              PKG_FATAL_ERRORS
        !          9964: PKG_FC                            PKG_FILELIST_CMD
        !          9965: PKG_GECOS                         PKG_GID
        !          9966: PKG_GROUPS                        PKG_GROUPS_VARS
        !          9967: PKG_HOME                          PKG_INIT_SCRIPTS
        !          9968: PKG_JAVA_HOME                     PKG_JVM
        !          9969: PKG_JVMS_ACCEPTED                 PKG_JVM_DEFAULT
        !          9970: PKG_LEGACY_OPTIONS                PKG_LIBTOOL
        !          9971: PKG_MKSYMLINKS                    PKG_OPTIONS
        !          9972: PKG_OPTIONS_DEPRECATED_WARNINGS   PKG_OPTIONS_LEGACY_OPTS
        !          9973: PKG_OPTIONS_LEGACY_VARS           PKG_OPTIONS_NONEMPTY_SETS
        !          9974: PKG_OPTIONS_OPTIONAL_GROUPS       PKG_OPTIONS_REQUIRED_GROUPS
        !          9975: PKG_OPTIONS_VAR                   PKG_PHP
        !          9976: PKG_PHP_MAJOR_VERS                PKG_PHP_VERSION
        !          9977: PKG_RCD_SCRIPTS                   PKG_REFCOUNT_DBDIR
        !          9978: PKG_REGISTER_SHELLS               PKG_RESUME_TRANSFERS
        !          9979: PKG_SHELL                         PKG_SUGGESTED_OPTIONS
        !          9980: PKG_SUPPORTED_OPTIONS             PKG_SYSCONFBASE
        !          9981: PKG_SYSCONFBASEDIR                PKG_SYSCONFDIR
        !          9982: PKG_SYSCONFDIR_PERMS              PKG_SYSCONFSUBDIR
        !          9983: PKG_SYSCONFVAR                    PKG_TOOLS_BIN
        !          9984: PKG_UID                           PKG_UPDATE_FONTS_DB
        !          9985: PKG_USERS                         PKG_USERS_VARS
        !          9986: PKG_VERBOSE                       PLEASE
        !          9987: PLIST                             PLIST_AWK
        !          9988: PLIST_AWK_ENV                     PLIST_SRC
        !          9989: PLIST_SUBST                       PLIST_TYPE
        !          9990: PLIST_VARS                        POPTOP_USE_MPPE
        !          9991: POSSIBLE_GFORTRAN_VERSION         POST_FETCH_HOOK
        !          9992: PREFER                            PREFER_NATIVE
        !          9993: PREFER_NATIVE_PTHREADS            PREFER_PKGSRC
        !          9994: PREFIX                            PREPEND_PATH
        !          9995: PRE_ROOT_CMD                      PRIVILEGED_STAGES
        !          9996: PS                                PTHREAD_AUTO_VARS
        !          9997: PTHREAD_CFLAGS                    PTHREAD_LDFLAGS
        !          9998: PTHREAD_LIBS                      PTHREAD_OPTS
        !          9999: PTHREAD_TYPE                      PVM_SSH
        !          10000: PYPKGPREFIX                       PYTHON_FOR_BUILD_ONLY
        !          10001: PYTHON_SELF_CONFLICT              PYTHON_VERSIONED_DEPENDENCIES
        !          10002: PYTHON_VERSIONS_ACCEPTED          PYTHON_VERSIONS_INCOMPATIBLE
        !          10003: PYTHON_VERSION_DEFAULT            PYTHON_VERSION_REQD
        !          10004: PYVERSSUFFIX                      QMAILDIR
        !          10005: QMAIL_ALIAS_USER                  QMAIL_DAEMON_USER
        !          10006: QMAIL_LOG_USER                    QMAIL_NOFILES_GROUP
        !          10007: QMAIL_PASSWD_USER                 QMAIL_QMAIL_GROUP
        !          10008: QMAIL_QUEUE_DIR                   QMAIL_QUEUE_EXTRA
        !          10009: QMAIL_QUEUE_USER                  QMAIL_REMOTE_USER
        !          10010: QMAIL_ROOT_USER                   QMAIL_SEND_USER
        !          10011: QORE_LATEST_MODULE_API            QORE_MODULE_API
        !          10012: QORE_MODULE_DIR                   QORE_USER_MODULE_DIR
        !          10013: QORE_VERSION                      QPOPPER_FAC
        !          10014: QPOPPER_SPOOL_DIR                 QPOPPER_USER
        !          10015: RAKE_NAME                         RASMOL_DEPTH
        !          10016: RCD_SCRIPTS                       RCD_SCRIPTS_DIR
        !          10017: RCD_SCRIPTS_EXAMPLEDIR            RCD_SCRIPTS_MODE
        !          10018: RCD_SCRIPTS_SHELL                 RCD_SCRIPT_SRC
        !          10019: RDOC                              READLINE_DEFAULT
        !          10020: READLINE_TYPE                     REAL_ROOT_GROUP
        !          10021: REAL_ROOT_USER                    RECURSIVE_MAKE
        !          10022: RELAY_CTRL_DIR                    RELRO_SUPPORTED
        !          10023: REPLACE_AWK                       REPLACE_BASH
        !          10024: REPLACE_CSH                       REPLACE_KSH
        !          10025: REPLACE_LUA                       REPLACE_NODEJS
        !          10026: REPLACE_OCTAVE                    REPLACE_PERL
        !          10027: REPLACE_PERL6                     REPLACE_PHP
        !          10028: REPLACE_PYTHON                    REPLACE_QORE
        !          10029: REPLACE_R                         REPLACE_RUBY
        !          10030: REPLACE_RUBY_DIRS                 REPLACE_RUBY_PAT
        !          10031: REPLACE_SH                        REPLACE_TEXLUA
        !          10032: REPLACE_WISH                      REQD_DIRS
        !          10033: REQD_DIRS_PERMS                   REQD_FILES
        !          10034: REQD_FILES_MODE                   REQD_FILES_PERMS
        !          10035: RESOLV_AUTO_VARS                  RESOLV_LDFLAGS
        !          10036: RESOLV_LIBS                       RM
        !          10037: ROOT_CMD                          ROOT_GROUP
        !          10038: ROOT_USER                         RPCGEN
        !          10039: RPM                               RPM2PKG_PLIST
        !          10040: RPM2PKG_PREFIX                    RPM2PKG_STAGE
        !          10041: RPM2PKG_STRIP                     RPM2PKG_SUBPREFIX
        !          10042: RPMFILES                          RPMIGNOREPATH
        !          10043: RPM_DB_PREFIX                     RSSH_CVS_PATH
        !          10044: RSSH_RDIST_PATH                   RSSH_RSYNC_PATH
        !          10045: RSSH_SCP_PATH                     RSSH_SFTP_SERVER_PATH
        !          10046: RUBY                              RUBYGEM
        !          10047: RUBYGEM_NAME                      RUBYGEM_OPTIONS
        !          10048: RUBYGEM_VERBOSE                   RUBY_ABI_VERSION
        !          10049: RUBY_ARCH                         RUBY_ARCHINC
        !          10050: RUBY_ARCHLIB                      RUBY_BASE
        !          10051: RUBY_BASERIDIR                    RUBY_BUILD_DOCUMENT
        !          10052: RUBY_DLEXT                        RUBY_DOC
        !          10053: RUBY_DYNAMIC_DIRS                 RUBY_EG
        !          10054: RUBY_ENCODING_ARG                 RUBY_EXTCONF
        !          10055: RUBY_EXTCONF_CHECK                RUBY_EXTCONF_DEBUG
        !          10056: RUBY_EXTCONF_MAKEFILE             RUBY_GEM_ARCH
        !          10057: RUBY_GEM_BASE                     RUBY_INC
        !          10058: RUBY_LIB                          RUBY_LIB_BASE
        !          10059: RUBY_NAME                         RUBY_NOVERSION
        !          10060: RUBY_PKGPREFIX                    RUBY_RAILS
        !          10061: RUBY_RAILS52_VERSION              RUBY_RAILS60_VERSION
        !          10062: RUBY_RAILS61_VERSION              RUBY_RAILS70_VERSION
        !          10063: RUBY_RAILS_ACCEPTED               RUBY_RAILS_DEFAULT
        !          10064: RUBY_RAILS_REQD                   RUBY_RAILS_STRICT_DEP
        !          10065: RUBY_RIDIR                        RUBY_SETUP
        !          10066: RUBY_SHLIB                        RUBY_SHLIBALIAS
        !          10067: RUBY_SHLIBVER                     RUBY_SIMPLE_INSTALL
        !          10068: RUBY_SITEARCHLIB                  RUBY_SITELIB
        !          10069: RUBY_SITELIB_BASE                 RUBY_SITERIDIR
        !          10070: RUBY_SLEXT                        RUBY_SRCDIR
        !          10071: RUBY_STATICLIB                    RUBY_SUFFIX
        !          10072: RUBY_SYSRIDIR                     RUBY_USE_PTHREAD
        !          10073: RUBY_VENDORARCHLIB                RUBY_VENDORLIB
        !          10074: RUBY_VENDORLIB_BASE               RUBY_VER
        !          10075: RUBY_VERSION                      RUBY_VERSIONS_ACCEPTED
        !          10076: RUBY_VERSIONS_INCOMPATIBLE        RUBY_VERSION_DEFAULT
        !          10077: RUBY_VERSION_REQD                 RUBY_VER_DIR
        !          10078: RUN                               RUN_LDCONFIG
        !          10079: RUST_TYPE                         SCO
        !          10080: SCREWS_GROUP                      SCREWS_USER
        !          10081: SCRIPTS_ENV                       SCROLLKEEPER_DATADIR
        !          10082: SCROLLKEEPER_REBUILDDB            SCROLLKEEPER_UPDATEDB
        !          10083: SDIST_PAWD                        SDL12_TYPE
        !          10084: SERIAL_DEVICES                    SETGIDGAME
        !          10085: SETGID_GAMES_PERMS                SETUID_ROOT_PERMS
        !          10086: SH                                SHLIB
        !          10087: SIGN_PACKAGES                     SILC_CLIENT_WITH_PERL
        !          10088: SITE_SPECIFIC_PKGS                SKIP_DEPENDS
        !          10089: SMF_INSTANCES                     SMF_MANIFEST
        !          10090: SMF_METHODS                       SMF_METHOD_SHELL
        !          10091: SMF_METHOD_SRC                    SMF_NAME
        !          10092: SMF_PREFIX                        SMF_SRCDIR
        !          10093: SNIPROXY_GROUP                    SNIPROXY_USER
        !          10094: SOURCE_BUFFSIZE                   SPECIAL_PERMS
        !          10095: SPECIFIC_PKGS                     SSH_SUID
        !          10096: SSP_SUPPORTED                     SSYNC_PAWD
        !          10097: STEP_MSG                          STRIP
        !          10098: STRIP_DBG                         STRIP_DEBUG
        !          10099: STRIP_DEBUG_SUPPORTED             STRIP_FILES_SKIP
        !          10100: SU                                SUBDIR
        !          10101: SUBST                             SUBST_CLASSES
        !          10102: SUBST_FILES                       SUBST_FILTER_CMD
        !          10103: SUBST_MESSAGE                     SUBST_NOOP_OK
        !          10104: SUBST_SED                         SUBST_SHOW_DIFF
        !          10105: SUBST_SKIP_TEXT_CHECK             SUBST_STAGE
        !          10106: SUBST_VARS                        SUNWSPROBASE
        !          10107: SUSE_PREFER                       SU_CMD
        !          10108: SYSCONFBASE                       TARGET_ARCH
        !          10109: TBL                               TERMCAP_TYPE
        !          10110: TERMINFO_DEFAULT                  TERMINFO_TYPE
        !          10111: TEST                              TEST_DEPENDS
        !          10112: TEST_DIRS                         TEST_ENV
        !          10113: TEST_ENV_SHELL                    TEST_MAKE_CMD
        !          10114: TEST_MAKE_FLAGS                   TEST_TARGET
        !          10115: TEXLIVE_IGNORE_PATTERNS           TEXLIVE_REV
        !          10116: TEXLIVE_UNVERSIONED               TEXMFSITE
        !          10117: TEX_FORMATS                       TEX_HYPHEN_DAT
        !          10118: TEX_HYPHEN_DEF                    TEX_TEXMF_DIRS
        !          10119: THTTPD_LOG_FACILITY               TINYDYN_USER
        !          10120: TLSWRAPPER_CHROOT                 TO
        !          10121: TOOLS_ALIASES                     TOOLS_ALWAYS_WRAP
        !          10122: TOOLS_ARGS                        TOOLS_BROKEN
        !          10123: TOOLS_CMD                         TOOLS_CMDLINE_SED
        !          10124: TOOLS_CREATE                      TOOLS_CROSS_DESTDIR
        !          10125: TOOLS_DIR                         TOOLS_FAIL
        !          10126: TOOLS_GNU_MISSING                 TOOLS_LDCONFIG
        !          10127: TOOLS_NOOP                        TOOLS_PATH
        !          10128: TOOLS_SCRIPT                      TOOLS_USE_CROSS_COMPILE
        !          10129: TOOL_DEPENDS                      TTF_FONTS_DIR
        !          10130: TYPE                              UAC_REQD_EXECS
        !          10131: UCSPI_SSL_GROUP                   UCSPI_SSL_USER
        !          10132: UNLIMIT_RESOURCES                 UNPRIVILEGED
        !          10133: UNPRIVILEGED_GROUP                UNPRIVILEGED_GROUPS
        !          10134: UNPRIVILEGED_USER                 UNWRAP_FILES
        !          10135: UNWRAP_PATTERNS                   UPDATE_GEMSPEC
        !          10136: UPDATE_TARGET                     URI
        !          10137: USERGROUP_PHASE                   USERPPP_GROUP
        !          10138: USER_SPECIFIC_PKGS                USE_ABI_DEPENDS
        !          10139: USE_APR                           USE_BSD_MAKEFILE
        !          10140: USE_BUILTIN                       USE_CROSS_COMPILE
        !          10141: USE_CURSES                        USE_CWRAPPERS
        !          10142: USE_DB185                         USE_FEATURES
        !          10143: USE_GAMESGROUP                    USE_GCC_RUNTIME
        !          10144: USE_IMAKE                         USE_JAVA
        !          10145: USE_JAVA2                         USE_LANGUAGES
        !          10146: USE_LIBTOOL                       USE_NATIVE_GCC
        !          10147: USE_NETBSD_REPO                   USE_PKGSRC_GCC
        !          10148: USE_PKGSRC_GCC_RUNTIME            USE_PKGTASKS
        !          10149: USE_PKG_ADMIN_DIGEST              USE_RUBY_EXTCONF
        !          10150: USE_RUBY_INSTALL                  USE_RUBY_SETUP
        !          10151: USE_RUBY_SETUP_PKG                USE_TOOLS
        !          10152: UUCP_GROUP                        UUCP_USER
        !          10153: VARBASE                           VARNAME
        !          10154: VIM_EXTRA_OPTS                    WARNING_MSG
        !          10155: WCALC_CGIDIR                      WCALC_CGIPATH
        !          10156: WCALC_HTMLDIR                     WCALC_HTMLPATH
        !          10157: WDM_MANAGERS                      WRAPPER_CC
        !          10158: WRAPPER_REORDER_CMDS              WRKDIR
        !          10159: WRKDIR_BASENAME                   WRKDIR_LOCKTYPE
        !          10160: WRKLOG                            WRKOBJDIR
        !          10161: WRKSRC                            X10_PORT
        !          10162: X11                               X11BASE
        !          10163: X11_PKGSRCDIR                     X11_TYPE
        !          10164: X509_CERTIFICATE                  X509_KEY
        !          10165: XAW_TYPE                          XLOCK_DEFAULT_MODE
        !          10166: XMKMF                             XMKMF_FLAGS
        !          10167: XXX                               YES
        !          10168: ZSH_STATIC                        __stdc__
        !          10169: _vargroups                        accept
        !          10170: acquire-localbase-lock            acquire-lock
        !          10171: add                               added
        !          10172: administrator                     alloca
        !          10173: alternatives                      aslr
        !          10174: asprintf                          atlas
        !          10175: autoconf                          automake
        !          10176: autoreconf                        awk
        !          10177: bash                              big-endian
        !          10178: bin-install                       bind
        !          10179: binpkg-list                       blas
        !          10180: bootstrap-depends                 broken
        !          10181: broken_on_platform                bsd
        !          10182: bsd.prog.mk                       build
        !          10183: build-env                         buildlink-directories
        !          10184: buildlink-oss-soundcard-h         c
        !          10185: c++                               ccache
        !          10186: cce                               cdefs
        !          10187: ceil                              changes
        !          10188: changes-entry                     changes-entry-noupdate
        !          10189: check                             check-clean
        !          10190: check-files                       check-files-clean
        !          10191: check-vulnerable                  checksum
        !          10192: checksum-phase                    clean
        !          10193: clean-depends                     cleandir
        !          10194: commit                            commit-changes-entry
        !          10195: compact                           compiler
        !          10196: conf                              config.guess
        !          10197: config.sub                        configuration
        !          10198: configure                         configure-env
        !          10199: configure-help                    configure_args
        !          10200: connect                           cos
        !          10201: cputime                           create-usergroup
        !          10202: csh                               ctf
        !          10203: debug                             declaration
        !          10204: declare                           defined
        !          10205: depend                            dependencies
        !          10206: depends                           depends-checksum
        !          10207: depends-fetch                     deps
        !          10208: describe                          destdir
        !          10209: disable                           distclean
        !          10210: distinfo                          dl
        !          10211: dlopen                            do-buildlink
        !          10212: do-clean                          do-configure
        !          10213: do-configure-post-hook            do-extract
        !          10214: do-fetch                          do-install
        !          10215: emul                              emul-distinfo
        !          10216: emul-fetch                        emulation
        !          10217: emulator                          enable
        !          10218: endian                            enomem
        !          10219: ensurepip                         err
        !          10220: errx                              etc
        !          10221: exp                               extract-rpm
        !          10222: fabs                              feature
        !          10223: features                          fetch
        !          10224: fetch-list                        follows
        !          10225: forbids                           form
        !          10226: format                            fortify
        !          10227: fortify_source                    friend
        !          10228: fts                               fts_close
        !          10229: fts_open                          fts_read
        !          10230: fts_set                           gcc
        !          10231: gethostbyaddr                     gethostbyname
        !          10232: gethostbyname2                    getopt_long
        !          10233: getprogname                       getservbyname
        !          10234: getservbyport                     getservent
        !          10235: gettext                           github
        !          10236: gitlab                            glob
        !          10237: gnu                               gnu_configure_strict
        !          10238: go                                go-deps
        !          10239: golang                            guess-license
        !          10240: hashbang                          heimdal
        !          10241: help                              imake
        !          10242: increment                         indirect
        !          10243: inet_aton                         interp
        !          10244: interpreter                       intl
        !          10245: ip4                               ip6
        !          10246: ipv4                              ipv6
        !          10247: iso                               kerberos
        !          10248: krb                               krb5
        !          10249: ksh                               lapack
        !          10250: latex                             libintl_bindtextdomain
        !          10251: libintl_gettext                   libintl_textdomain
        !          10252: libnbcompat                       libs
        !          10253: libtool                           licence
        !          10254: license                           lintl
        !          10255: little-endian                     lock
        !          10256: locking                           lua
        !          10257: lvalue                            make
        !          10258: makesum                           memory
        !          10259: meta                              meta-package
        !          10260: meta_package                      mit-krb5
        !          10261: mk.conf                           mkl
        !          10262: mount                             move
        !          10263: moved                             mprotect
        !          10264: mremap                            nb
        !          10265: nbcompat                          netlib
        !          10266: node                              node.js
        !          10267: nodejs                            obstack
        !          10268: obstack_ptr_grow                  occurs
        !          10269: only                              openblas
        !          10270: options                           options.mk
        !          10271: order                             override
        !          10272: override-intltool                 override-message-intltool
        !          10273: package                           parallel
        !          10274: path                              pax
        !          10275: paxctl                            pbulk-index
        !          10276: pc                                perl
        !          10277: perl5                             perms
        !          10278: php                               pkg-build-options
        !          10279: pkg-config                        pkg_build_options
        !          10280: platform                          plist
        !          10281: post-extract                      post-fetch
        !          10282: post-wrapper                      pre-build-checks-hook
        !          10283: pre-configure                     pre-configure-checks-hook
        !          10284: pre-extract                       pre-fetch
        !          10285: print-go-deps                     print-plist
        !          10286: print-summary-data                privileged-install-hook
        !          10287: pypi                              python
        !          10288: r                                 readme-all
        !          10289: recursive                         recv
        !          10290: recvfrom                          regcomp
        !          10291: release-localbase-lock            release-lock
        !          10292: relro                             remove
        !          10293: removed                           rename
        !          10294: renamed                           reorder
        !          10295: replace                           replace_interpreter
        !          10296: reproducible                      resolv
        !          10297: root                              ruby
        !          10298: send                              sendfile
        !          10299: sendto                            setenv
        !          10300: setgid                            setprogname
        !          10301: setuid                            sh
        !          10302: shebang                           show
        !          10303: show-all                          show-build-defs
        !          10304: show-depends                      show-depends-dirs
        !          10305: show-depends-pkgpaths             show-depends-recursive
        !          10306: show-deps                         show-distfiles
        !          10307: show-downlevel                    show-subdir-var
        !          10308: show-tools                        show-var
        !          10309: show-vars                         snprintf
        !          10310: socket                            ssp
        !          10311: st_mode                           stage-install
        !          10312: strcasestr                        strict
        !          10313: strip                             strndup
        !          10314: strnlen                           strsep
        !          10315: subst                             substitutions
        !          10316: sun                               sunpro
        !          10317: sunwspro                          symlink
        !          10318: test                              test-env
        !          10319: tex                               texlive
        !          10320: tmp                               todo
        !          10321: tool                              tools
        !          10322: tools-libtool-m4-override         transitive
        !          10323: type                              ulimit
        !          10324: undefined                         undo-replace
        !          10325: unlimit                           unprivileged
        !          10326: unprivileged-install-hook         unstripped
        !          10327: update                            updated
        !          10328: upload                            upload-distfiles
        !          10329: use_tools                         user
        !          10330: utimes                            vasprintf
        !          10331: verbose                           vsnprintf
        !          10332: warn                              warning
        !          10333: warnings                          warnx
        !          10334: wattr_off                         wattr_on
        !          10335: work                              wrapper
        !          10336: wrkdir                             
1.154     rillig   10337: 
1.207     leot     10338: Appendix F. Editing guidelines for the pkgsrc guide
1.1       dsieger  10339: 
                   10340: Table of Contents
                   10341: 
1.207     leot     10342: F.1. Make targets
                   10343: F.2. Procedure
1.1       dsieger  10344: 
                   10345: This section contains information on editing the pkgsrc guide itself.
                   10346: 
1.207     leot     10347: F.1. Make targets
1.1       dsieger  10348: 
                   10349: The pkgsrc guide's source code is stored in pkgsrc/doc/guide/files, and several
                   10350: files are created from it:
                   10351: 
                   10352:   * pkgsrc/doc/pkgsrc.txt
                   10353: 
                   10354:   * pkgsrc/doc/pkgsrc.html
                   10355: 
1.174     leot     10356:   * https://www.NetBSD.org/docs/pkgsrc/
1.1       dsieger  10357: 
1.174     leot     10358:   * https://www.NetBSD.org/docs/pkgsrc/pkgsrc.pdf: The PDF version of the
                   10359:     pkgsrc guide.
1.1       dsieger  10360: 
1.174     leot     10361:   * https://www.NetBSD.org/docs/pkgsrc/pkgsrc.ps: PostScript version of the
1.2       rillig   10362:     pkgsrc guide.
1.1       dsieger  10363: 
1.207     leot     10364: F.2. Procedure
1.1       dsieger  10365: 
                   10366: The procedure to edit the pkgsrc guide is:
                   10367: 
1.190     bacon    10368:  1. Make sure you have checked out the htdocs repository into a sibling
                   10369:     directory of your pkgsrc directory. You will need the ability to commit
                   10370:     from both pkgsrc and htdocs.
                   10371: 
                   10372:  2. Make sure you have the packages needed to regenerate the pkgsrc guide (and
1.46      obache   10373:     other XML-based NetBSD documentation) installed. These are automatically
                   10374:     installed when you install the meta-pkgs/pkgsrc-guide-tools package.
1.1       dsieger  10375: 
1.190     bacon    10376:  3. Run cd doc/guide to get to the right directory. All further steps will take
1.1       dsieger  10377:     place here.
                   10378: 
1.190     bacon    10379:  4. Edit the XML file(s) in files/.
1.1       dsieger  10380: 
1.190     bacon    10381:  5. Run bmake to check the pkgsrc guide for valid XML and to build the final
1.1       dsieger  10382:     output files. If you get any errors at this stage, you can just edit the
                   10383:     files, as there are only symbolic links in the working directory, pointing
                   10384:     to the files in files/.
                   10385: 
1.190     bacon    10386:  6. (cd files && cvs commit)
1.1       dsieger  10387: 
1.190     bacon    10388:  7. Run bmake clean && bmake to regenerate the output files with the proper RCS
1.1       dsieger  10389:     Ids.
                   10390: 
1.190     bacon    10391:  8. Run bmake regen to install and commit the files in both pkgsrc/doc and
1.1       dsieger  10392:     htdocs.
                   10393: 
                   10394:     Note
                   10395: 
                   10396:     If you have added, removed or renamed some chapters, you need to
                   10397:     synchronize them using cvs add or cvs delete in the htdocs directory.
                   10398: 

CVSweb <webmaster@jp.NetBSD.org>