Annotation of htdocs/docs/pkgsrc/components.html, revision 1.39

1.32      sevan       1: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
1.1       dsieger     2: <html>
                      3: <head>
                      4: <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
1.39    ! rillig      5: <title>Chapter 13. Package components - files, directories and contents</title>
1.14      spz         6: <link rel="stylesheet" type="text/css" href="/global.css">
1.1       dsieger     7: <meta name="generator" content="DocBook XSL Stylesheets VX.X.X">
1.10      rillig      8: <link rel="home" href="index.html" title="The pkgsrc guide">
1.1       dsieger     9: <link rel="up" href="developers-guide.html" title="Part II. The pkgsrc developer's guide">
1.39    ! rillig     10: <link rel="prev" href="creating.html" title="Chapter 12. Creating a new pkgsrc package from scratch">
        !            11: <link rel="next" href="makefile.html" title="Chapter 14. Programming in Makefiles">
1.1       dsieger    12: </head>
                     13: <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
                     14: <div class="navheader">
                     15: <table width="100%" summary="Navigation header">
1.39    ! rillig     16: <tr><th colspan="3" align="center">Chapter 13. Package components - files, directories and contents</th></tr>
1.1       dsieger    17: <tr>
                     18: <td width="20%" align="left">
                     19: <a accesskey="p" href="creating.html">Prev</a> </td>
                     20: <th width="60%" align="center">Part II. The pkgsrc developer's guide</th>
                     21: <td width="20%" align="right"> <a accesskey="n" href="makefile.html">Next</a>
                     22: </td>
                     23: </tr>
                     24: </table>
                     25: <hr>
                     26: </div>
1.18      asau       27: <div class="chapter">
1.1       dsieger    28: <div class="titlepage"><div><div><h2 class="title">
1.39    ! rillig     29: <a name="components"></a>Chapter 13. Package components - files, directories and contents</h2></div></div></div>
1.1       dsieger    30: <div class="toc">
                     31: <p><b>Table of Contents</b></p>
1.28      leot       32: <dl class="toc">
1.39    ! rillig     33: <dt><span class="sect1"><a href="components.html#components.Makefile">13.1. <code class="filename">Makefile</code></a></span></dt>
        !            34: <dt><span class="sect1"><a href="components.html#components.distinfo">13.2. <code class="filename">distinfo</code></a></span></dt>
        !            35: <dt><span class="sect1"><a href="components.html#components.patches">13.3. <code class="filename">patches/*</code></a></span></dt>
1.1       dsieger    36: <dd><dl>
1.39    ! rillig     37: <dt><span class="sect2"><a href="components.html#components.patch.structure">13.3.1. Structure of a single patch file</a></span></dt>
        !            38: <dt><span class="sect2"><a href="components.html#components.patches.caveats">13.3.2. Creating patch files</a></span></dt>
        !            39: <dt><span class="sect2"><a href="components.html#components.patches.sources">13.3.3. Sources where the patch files come from</a></span></dt>
        !            40: <dt><span class="sect2"><a href="components.html#components.patches.guidelines">13.3.4. Patching guidelines</a></span></dt>
        !            41: <dt><span class="sect2"><a href="components.html#components.patches.feedback">13.3.5. Feedback to the author</a></span></dt>
1.1       dsieger    42: </dl></dd>
1.39    ! rillig     43: <dt><span class="sect1"><a href="components.html#other-mandatory-files">13.4. Other mandatory files</a></span></dt>
        !            44: <dt><span class="sect1"><a href="components.html#components.optional">13.5. Optional files</a></span></dt>
1.1       dsieger    45: <dd><dl>
1.39    ! rillig     46: <dt><span class="sect2"><a href="components.html#components.optional.bin">13.5.1. Files affecting the binary package</a></span></dt>
        !            47: <dt><span class="sect2"><a href="components.html#components.optional.build">13.5.2. Files affecting the build process</a></span></dt>
        !            48: <dt><span class="sect2"><a href="components.html#components.optional.none">13.5.3. Files affecting nothing at all</a></span></dt>
1.1       dsieger    49: </dl></dd>
1.39    ! rillig     50: <dt><span class="sect1"><a href="components.html#work-dir">13.6. <code class="filename">work*</code></a></span></dt>
        !            51: <dt><span class="sect1"><a href="components.html#files-dir">13.7. <code class="filename">files/*</code></a></span></dt>
1.1       dsieger    52: </dl>
                     53: </div>
                     54: <p>Whenever you're preparing a package, there are a number of
                     55: files involved which are described in the following
                     56: sections.</p>
1.18      asau       57: <div class="sect1">
1.1       dsieger    58: <div class="titlepage"><div><div><h2 class="title" style="clear: both">
1.39    ! rillig     59: <a name="components.Makefile"></a>13.1. <code class="filename">Makefile</code>
1.1       dsieger    60: </h2></div></div></div>
                     61: <p>Building, installation and creation of a binary package are all
                     62:   controlled by the package's <code class="filename">Makefile</code>.
                     63:   The <code class="filename">Makefile</code> describes various things about
                     64:   a package, for example from where to get it, how to configure,
                     65:   build, and install it.</p>
                     66: <p>A package <code class="filename">Makefile</code> contains several
                     67:   sections that describe the package.</p>
                     68: <p>In the first section there are the following variables, which
                     69:   should appear exactly in the order given here.  The order and
                     70:   grouping of the variables is mostly historical and has no further
                     71:   meaning.</p>
1.18      asau       72: <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
1.12      wiz        73: <li class="listitem"><p><code class="varname">DISTNAME</code> is the basename of the
1.1       dsieger    74:     distribution file to be downloaded from the package's
                     75:     website.</p></li>
1.12      wiz        76: <li class="listitem"><p><code class="varname">PKGNAME</code> is the name of the
1.19      asau       77:     package, as used by pkgsrc. You need to provide it if
1.1       dsieger    78:     <code class="varname">DISTNAME</code> (which is the default) is not a good
1.19      asau       79:     name for the package in pkgsrc or <code class="varname">DISTNAME</code> is not
                     80:     provided (no distribution file is required).  Usually it is the pkgsrc
1.1       dsieger    81:     directory name together with the version number. It must match the
                     82:     regular expression
                     83:     <code class="varname">^[A-Za-z0-9][A-Za-z0-9-_.+]*$</code>, that is, it
                     84:     starts with a letter or digit, and contains only letters, digits,
                     85:     dashes, underscores, dots and plus signs.</p></li>
1.12      wiz        86: <li class="listitem">
1.1       dsieger    87: <p><code class="varname">CATEGORIES</code> is a list of categories
                     88:     which the package fits in. You can choose any of the top-level
                     89:     directories of pkgsrc for it.</p>
                     90: <p>Currently the following values are available for
                     91:     <code class="varname">CATEGORIES</code>. If more than
                     92:     one is used, they need to be separated by spaces:</p>
                     93: <pre class="programlisting">
                     94: archivers     cross         geography     meta-pkgs     security
                     95: audio         databases     graphics      misc          shells
                     96: benchmarks    devel         ham           multimedia    sysutils
                     97: biology       editors       inputmethod   net           textproc
                     98: cad           emulators     lang          news          time
                     99: chat          finance       mail          parallel      wm
                    100: comms         fonts         math          pkgtools      www
                    101: converters    games         mbone         print         x11
                    102: </pre>
                    103: </li>
1.12      wiz       104: <li class="listitem"><p><code class="varname">MASTER_SITES</code>,
1.1       dsieger   105:     <code class="varname">DYNAMIC_MASTER_SITES</code>,
                    106:     <code class="varname">DIST_SUBDIR</code>, <code class="varname">EXTRACT_SUFX</code>
                    107:     and <code class="varname">DISTFILES</code> are discussed in detail in
1.39    ! rillig    108:     <a class="xref" href="build.html#build.fetch" title="19.5. The fetch phase">Section 19.5, &#8220;The <span class="emphasis"><em>fetch</em></span> phase&#8221;</a>.</p></li>
1.1       dsieger   109: </ul></div>
                    110: <p>The second section contains information about separately
                    111:   downloaded patches, if any.
                    112:   </p>
1.18      asau      113: <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
1.21      wiz       114: <li class="listitem"><p><code class="varname">PATCHFILES</code>:
1.1       dsieger   115:     Name(s) of additional files that contain distribution patches.
                    116:     There is no default. pkgsrc will look for them at
                    117:     <code class="varname">PATCH_SITES</code>.
                    118:     They will automatically be uncompressed before patching if
                    119:     the names end with <code class="filename">.gz</code> or
                    120:     <code class="filename">.Z</code>.</p></li>
1.12      wiz       121: <li class="listitem"><p><code class="varname">PATCH_SITES</code>:
1.1       dsieger   122:     Primary location(s) for distribution patch files (see
1.21      wiz       123:     <code class="varname">PATCHFILES</code> above) if not found locally.</p></li>
                    124: <li class="listitem"><p><code class="varname">PATCH_DIST_STRIP</code>:
1.37      leot      125:     an argument to <a class="citerefentry" href="http://netbsd.gw.com/cgi-bin/man-cgi?patch+1.i386+NetBSD-8.0"><span class="citerefentry"><span class="refentrytitle">patch</span>(1)</span></a> that sets the pathname strip count to
1.21      wiz       126:     help find the correct files to patch. It defaults to
                    127:     <span class="command"><strong>-p0</strong></span>.</p></li>
1.1       dsieger   128: </ul></div>
                    129: <p>The third section contains the following variables.
                    130:   </p>
1.18      asau      131: <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
1.12      wiz       132: <li class="listitem"><p><code class="varname">MAINTAINER</code> is the email
1.9       jmcneill  133:     address of the person who feels responsible for this package,
                    134:     and who is most likely to look at problems or questions regarding
1.37      leot      135:     this package which have been reported with <a class="citerefentry" href="http://netbsd.gw.com/cgi-bin/man-cgi?send-pr+1.i386+NetBSD-8.0"><span class="citerefentry"><span class="refentrytitle">send-pr</span>(1)</span></a>.
1.9       jmcneill  136:     Other developers may contact the <code class="varname">MAINTAINER</code>
                    137:     before making changes to the package, but are not required to
                    138:     do so. When packaging a new program, set <code class="varname">MAINTAINER</code>
                    139:     to yourself. If you really can't maintain the package for future
                    140:     updates, set it to
1.6       hubertf   141:     <code class="email">&lt;<a class="email" href="mailto:pkgsrc-users@NetBSD.org">pkgsrc-users@NetBSD.org</a>&gt;</code>.</p></li>
1.12      wiz       142: <li class="listitem"><p><code class="varname">OWNER</code> should be used instead
1.9       jmcneill  143:     of <code class="varname">MAINTAINER</code> when you do not want other
                    144:     developers to update or change the package without contacting
                    145:     you first. A package Makefile should contain one of
                    146:     <code class="varname">MAINTAINER</code> or <code class="varname">OWNER</code>, but
                    147:     not both.  </p></li>
1.12      wiz       148: <li class="listitem"><p><code class="varname">HOMEPAGE</code> is a URL where users can
1.1       dsieger   149:     find more information about the package.</p></li>
1.12      wiz       150: <li class="listitem"><p><code class="varname">COMMENT</code> is a one-line
1.1       dsieger   151:     description of the package (should not include the package
                    152:     name).</p></li>
1.33      leot      153: <li class="listitem"><p><code class="varname">LICENSE</code> indicates the license(s)
1.39    ! rillig    154:     applicable for the package. See <a class="xref" href="fixes.html#handling-licenses" title="21.1.3. Handling licenses">Section 21.1.3, &#8220;Handling licenses&#8221;</a> for further details.</p></li>
1.1       dsieger   155: </ul></div>
                    156: <p>Other variables that affect the build:
                    157:   </p>
1.18      asau      158: <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
1.1       dsieger   159: <p><code class="varname">WRKSRC</code>: The directory where the
                    160:       interesting distribution files of the package are found. The
                    161:       default is <code class="filename">${WRKDIR}/${DISTNAME}</code>, which
                    162:       works for most packages.</p>
                    163: <p>If a package doesn't create a subdirectory for itself
                    164:       (most GNU software does, for instance), but extracts itself in
                    165:       the current directory, you should set
                    166:       <code class="varname">WRKSRC=${WRKDIR}</code>.</p>
                    167: <p>If a package doesn't create a subdirectory with the
                    168:       name of <code class="varname">DISTNAME</code> but some different name,
                    169:       set <code class="varname">WRKSRC</code> to point to the proper name in
                    170:       <code class="filename">${WRKDIR}</code>, for example
                    171:       <code class="varname">WRKSRC=${WRKDIR}/${DISTNAME}/unix</code>. See
1.35      leot      172:       <a href="https://cdn.NetBSD.org/pub/pkgsrc/current/pkgsrc/lang/tcl/README.html" target="_top"><code class="filename">lang/tcl</code></a> and <a href="https://cdn.NetBSD.org/pub/pkgsrc/current/pkgsrc/x11/tk/README.html" target="_top"><code class="filename">x11/tk</code></a> for other examples.</p>
1.1       dsieger   173: <p>The name of the working directory created by pkgsrc is
                    174:       taken from the <code class="varname">WRKDIR_BASENAME</code>
                    175:       variable. By default, its value is
                    176:       <code class="filename">work</code>. If you want to use the same
                    177:       pkgsrc tree for building different kinds of binary packages,
                    178:       you can change the variable according to your needs. Two
                    179:       other variables handle common cases of setting
                    180:       <code class="varname">WRKDIR_BASENAME</code> individually. If
                    181:       <code class="varname">OBJHOSTNAME</code> is defined in
1.6       hubertf   182:       <a class="link" href="configuring.html#mk.conf"><code class="filename">mk.conf</code></a>, the first component of
1.1       dsieger   183:       the host's name is attached to the directory name. If
                    184:       <code class="varname">OBJMACHINE</code> is defined, the platform name
                    185:       is attached, which might look like
                    186:       <code class="filename">work.i386</code> or
                    187:       <code class="filename">work.sparc</code>.</p>
                    188: </li></ul></div>
                    189: <p>Please pay attention to the following gotchas:</p>
1.18      asau      190: <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
1.12      wiz       191: <li class="listitem"><p>Add <code class="varname">MANCOMPRESSED</code> if man pages are
1.1       dsieger   192:       installed in compressed form by the package.  For packages using
                    193:       BSD-style makefiles which honor MANZ, there is
                    194:       <code class="varname">MANCOMPRESSED_IF_MANZ</code>.</p></li>
1.12      wiz       195: <li class="listitem"><p>Replace <code class="filename">/usr/local</code> with
                    196:       <span class="quote">&#8220;<span class="quote">${PREFIX}</span>&#8221;</span> in all files (see patches,
1.1       dsieger   197:       below).</p></li>
1.39    ! rillig    198: <li class="listitem"><p>If the package installs any info files, see <a class="xref" href="fixes.html#faq.info-files" title="21.6.7. Packages installing info files">Section 21.6.7, &#8220;Packages installing info files&#8221;</a>.</p></li>
1.1       dsieger   199: </ul></div>
                    200: </div>
1.18      asau      201: <div class="sect1">
1.1       dsieger   202: <div class="titlepage"><div><div><h2 class="title" style="clear: both">
1.39    ! rillig    203: <a name="components.distinfo"></a>13.2. <code class="filename">distinfo</code>
1.1       dsieger   204: </h2></div></div></div>
                    205: <p>The <code class="filename">distinfo</code> file contains the message
                    206:   digest, or checksum, of each distfile needed for the package. This
                    207:   ensures that the distfiles retrieved from the Internet have not been
                    208:   corrupted during transfer or altered by a malign force to introduce
1.30      rillig    209:   a security hole. To provide maximum security, all distfiles are
                    210:   protected using three different message digest algorithms (SHA1,
                    211:   RMD160, SHA512), as well as the file size.</p>
1.1       dsieger   212: <p>The <code class="filename">distinfo</code> file also contains the
                    213:   checksums for all the patches found in the
1.39    ! rillig    214:   <code class="filename">patches</code> directory (see <a class="xref" href="components.html#components.patches" title="13.3. patches/*">Section 13.3, &#8220;<code class="filename">patches/*</code>&#8221;</a>). These checksums ensure that patches
1.38      leot      215:   are only applied intentionally and that they don't accidentally change,
                    216:   e.g. when merging different changes together. They also make sure that
                    217:   new patches are actually added to CVS and old ones are removed.
                    218:   Too see whether the patches and the <code class="filename">distinfo</code> file
                    219:   match, run <span class="command"><strong>pkglint</strong></span> after changing the patches.</p>
1.1       dsieger   220: <p>To regenerate the <code class="filename">distinfo</code> file, use the
1.30      rillig    221:   <span class="command"><strong>make distinfo</strong></span> command.</p>
1.1       dsieger   222: <p>Some packages have different sets of distfiles depending on
1.35      leot      223:   the platform, for example <a href="https://cdn.NetBSD.org/pub/pkgsrc/current/pkgsrc/lang/openjdk7/README.html" target="_top"><code class="filename">lang/openjdk7</code></a>. These are kept in the same
1.1       dsieger   224:   <code class="filename">distinfo</code> file and care should be taken when
                    225:   upgrading such a package to ensure distfile information is not
                    226:   lost.</p>
                    227: </div>
1.18      asau      228: <div class="sect1">
1.1       dsieger   229: <div class="titlepage"><div><div><h2 class="title" style="clear: both">
1.39    ! rillig    230: <a name="components.patches"></a>13.3. <code class="filename">patches/*</code>
1.30      rillig    231: </h2></div></div></div>
                    232: <p>Some packages don't work out-of-the box on the various
                    233:   platforms that are supported by pkgsrc. These packages need
                    234:   to be patched to make them work. The patch files can be
1.1       dsieger   235:   found in the <code class="filename">patches/</code> directory.</p>
                    236: <p>In the <span class="emphasis"><em>patch</em></span> phase, these patches are
                    237:   applied to the files in <code class="varname">WRKSRC</code> directory after
1.30      rillig    238:   extracting them, in alphabetic order.</p>
1.18      asau      239: <div class="sect2">
1.1       dsieger   240: <div class="titlepage"><div><div><h3 class="title">
1.39    ! rillig    241: <a name="components.patch.structure"></a>13.3.1. Structure of a single patch file</h3></div></div></div>
1.1       dsieger   242: <p>The <code class="filename">patch-*</code> files should be in
1.6       hubertf   243:   <span class="command"><strong>diff -bu</strong></span> format, and apply without a fuzz to avoid
1.1       dsieger   244:   problems. (To force patches to apply with fuzz you can set
                    245:   <code class="varname">PATCH_FUZZ_FACTOR=-F2</code>). Furthermore, each patch
                    246:   should contain only changes for a single file, and no file should be
                    247:   patched by more than one patch file. This helps to keep future
                    248:   modifications simple.</p>
                    249: <p>Each patch file is structured as follows: In the first line,
                    250:   there is the RCS Id of the patch itself. The second line should be
                    251:   empty for aesthetic reasons. After that, there should be a comment for
                    252:   each change that the patch does. There are a number of standard
                    253:   cases:</p>
1.18      asau      254: <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
1.12      wiz       255: <li class="listitem"><p>Patches for commonly known vulnerabilities should
1.1       dsieger   256:   mention the vulnerability ID (CAN, CVE).</p></li>
1.12      wiz       257: <li class="listitem"><p>Patches that change source code should mention the
1.1       dsieger   258:   platform and other environment (for example, the compiler) that the
                    259:   patch is needed for.</p></li>
                    260: </ul></div>
1.30      rillig    261: <p>The patch should be commented so that any
1.1       dsieger   262:   developer who knows the code of the application can make some use of
                    263:   the patch. Special care should be taken for the upstream developers,
                    264:   since we generally want that they accept our patches, so we have less
                    265:   work in the future.</p>
                    266: </div>
1.18      asau      267: <div class="sect2">
1.1       dsieger   268: <div class="titlepage"><div><div><h3 class="title">
1.39    ! rillig    269: <a name="components.patches.caveats"></a>13.3.2. Creating patch files</h3></div></div></div>
1.1       dsieger   270: <p>One important thing to mention is to pay attention that no RCS
                    271:   IDs get stored in the patch files, as these will cause problems when
                    272:   later checked into the NetBSD CVS tree. Use the
1.35      leot      273:   <span class="command"><strong>pkgdiff</strong></span> command from the <a href="https://cdn.NetBSD.org/pub/pkgsrc/current/pkgsrc/pkgtools/pkgdiff/README.html" target="_top"><code class="filename">pkgtools/pkgdiff</code></a> package to avoid these
1.1       dsieger   274:   problems.</p>
                    275: <p>For even more automation, we recommend using
1.6       hubertf   276:   <span class="command"><strong>mkpatches</strong></span> from the same package to make a
1.1       dsieger   277:   whole set of patches. You just have to backup files before you
                    278:   edit them to <code class="filename">filename.orig</code>, e.g. with
1.6       hubertf   279:   <span class="command"><strong>cp -p filename filename.orig</strong></span> or, easier, by
                    280:   using <span class="command"><strong>pkgvi</strong></span> again from the same package. If
1.1       dsieger   281:   you upgrade a package this way, you can easily compare the new
                    282:   set of patches with the previously existing one with
1.13      wiz       283:   <span class="command"><strong>patchdiff</strong></span>. The files in <code class="filename">patches</code>
                    284:   are replaced by new files, so carefully check if you want to take all
                    285:   the changes.</p>
1.1       dsieger   286: <p>When you have finished a package, remember to generate
1.6       hubertf   287:   the checksums for the patch files by using the <span class="command"><strong>make
1.39    ! rillig    288:   makepatchsum</strong></span> command, see <a class="xref" href="components.html#components.distinfo" title="13.2. distinfo">Section 13.2, &#8220;<code class="filename">distinfo</code>&#8221;</a>.</p>
1.1       dsieger   289: <p>When adding a patch that corrects a problem in the
                    290:   distfile (rather than e.g. enforcing pkgsrc's view of where
                    291:   man pages should go), send the patch as a bug report to the
                    292:   maintainer.  This benefits non-pkgsrc users of the package,
                    293:   and usually makes it possible to remove the patch in future
                    294:   version.</p>
1.2       rillig    295: <p>The file names of the patch files are usually of the form
1.13      wiz       296:   <code class="filename">patch-<em class="replaceable"><code>path_to_file__with__underscores.c</code></em></code>.
                    297:   Many packages still use the previous convention
                    298:   <code class="filename">patch-<em class="replaceable"><code>[a-z][a-z]</code></em></code>,
                    299:   but new patches should be of the form containing the filename.
1.35      leot      300:   <span class="command"><strong>mkpatches</strong></span> included in <a href="https://cdn.NetBSD.org/pub/pkgsrc/current/pkgsrc/pkgtools/pkgdiff/README.html" target="_top"><code class="filename">pkgtools/pkgdiff</code></a> takes care of the name
1.13      wiz       301:   automatically.</p>
1.1       dsieger   302: </div>
1.18      asau      303: <div class="sect2">
1.1       dsieger   304: <div class="titlepage"><div><div><h3 class="title">
1.39    ! rillig    305: <a name="components.patches.sources"></a>13.3.3. Sources where the patch files come from</h3></div></div></div>
1.1       dsieger   306: <p>If you want to share patches between multiple packages
                    307:   in pkgsrc, e.g. because they use the same distfiles, set
                    308:   <code class="varname">PATCHDIR</code> to the path where the patch files
                    309:   can be found, e.g.:</p>
                    310: <pre class="programlisting">
                    311: PATCHDIR= ${.CURDIR}/../xemacs/patches
                    312: </pre>
                    313: <p>Patch files that are distributed by the author or other
                    314:     maintainers can be listed in
                    315:     <code class="varname">PATCHFILES</code>.</p>
                    316: <p>If it is desired to store any patches that should not be
                    317:     committed into pkgsrc, they can be kept outside the pkgsrc
                    318:     tree in the <code class="filename">$LOCALPATCHES</code> directory. The
                    319:     directory tree there is expected to have the same
1.12      wiz       320:     <span class="quote">&#8220;<span class="quote">category/package</span>&#8221;</span> structure as pkgsrc, and
1.1       dsieger   321:     patches are expected to be stored inside these dirs (also
                    322:     known as <code class="filename">$LOCALPATCHES/$PKGPATH</code>). For
                    323:     example, if you want to keep a private patch for
                    324:     <code class="filename">pkgsrc/graphics/png</code>, keep it in
                    325:     <code class="filename">$LOCALPATCHES/graphics/png/mypatch</code>. All
                    326:     files in the named directory are expected to be patch files,
                    327:     and <span class="emphasis"><em>they are applied after pkgsrc patches are
                    328:     applied</em></span>.</p>
                    329: </div>
1.18      asau      330: <div class="sect2">
1.1       dsieger   331: <div class="titlepage"><div><div><h3 class="title">
1.39    ! rillig    332: <a name="components.patches.guidelines"></a>13.3.4. Patching guidelines</h3></div></div></div>
1.1       dsieger   333: <p>When fixing a portability issue in the code do not use
                    334:       preprocessor magic to check for the current operating system nor
                    335:       platform.  Doing so hurts portability to other platforms because
                    336:       the OS-specific details are not abstracted appropriately.</p>
                    337: <p>The general rule to follow is: instead of checking for the
                    338:       operating system the application is being built on, check for the
                    339:       specific <span class="emphasis"><em>features</em></span> you need.  For example,
                    340:       instead of assuming that kqueue is available under NetBSD and
                    341:       using the <code class="varname">__NetBSD__</code> macro to conditionalize
1.9       jmcneill  342:       kqueue support, add a check that detects kqueue itself &mdash;
1.1       dsieger   343:       yes, this generally involves patching the
1.6       hubertf   344:       <span class="command"><strong>configure</strong></span> script.  There is absolutely nothing
1.1       dsieger   345:       that prevents some OSes from adopting interfaces from other OSes
                    346:       (e.g. Linux implementing kqueue), something that the above checks
                    347:       cannot take into account.</p>
                    348: <p>Of course, checking for features generally involves more
                    349:       work on the developer's side, but the resulting changes are
                    350:       cleaner and there are chances they will work on many other
                    351:       platforms.  Not to mention that there are higher chances of being
                    352:       later integrated into the mainstream sources.  Remember:
                    353:       <span class="emphasis"><em>It doesn't work unless it is right!</em></span></p>
                    354: <p>Some typical examples:</p>
                    355: <div class="table">
1.39    ! rillig    356: <a name="patch-examples"></a><p class="title"><b>Table 13.1. Patching examples</b></p>
1.29      tnn       357: <div class="table-contents"><table class="table" summary="Patching examples" border="1">
1.1       dsieger   358: <colgroup>
                    359: <col>
                    360: <col>
                    361: <col>
                    362: </colgroup>
                    363: <thead><tr>
                    364: <th>Where</th>
                    365: <th>Incorrect</th>
                    366: <th>Correct</th>
                    367: </tr></thead>
                    368: <tbody>
                    369: <tr>
                    370: <td>configure script</td>
                    371: <td>
                    372: <pre class="programlisting">
                    373: case ${target_os} in
                    374: netbsd*) have_kvm=yes ;;
                    375: *)       have_kvm=no  ;;
                    376: esac
                    377: </pre>
                    378:              </td>
                    379: <td>
                    380: <pre class="programlisting">
                    381: AC_CHECK_LIB(kvm, kvm_open, have_kvm=yes, have_kvm=no)
                    382: </pre>
                    383:              </td>
                    384: </tr>
                    385: <tr>
                    386: <td>C source file</td>
                    387: <td>
                    388: <pre class="programlisting">
                    389: #if defined(__NetBSD__)
                    390: #  include &lt;sys/event.h&gt;
                    391: #endif
                    392: </pre>
                    393:              </td>
                    394: <td>
                    395: <pre class="programlisting">
                    396: #if defined(HAVE_SYS_EVENT_H)
                    397: #  include &lt;sys/event.h&gt;
                    398: #endif
                    399: </pre>
                    400:              </td>
                    401: </tr>
                    402: <tr>
                    403: <td>C source file</td>
                    404: <td>
                    405: <pre class="programlisting">
                    406: int
                    407: monitor_file(...)
                    408: {
                    409: #if defined(__NetBSD__)
                    410:         int fd = kqueue();
                    411:         ...
                    412: #else
                    413:         ...
                    414: #endif
                    415: }
                    416: </pre>
                    417:              </td>
                    418: <td>
                    419: <pre class="programlisting">
                    420: int
                    421: monitor_file(...)
                    422: {
                    423: #if defined(HAVE_KQUEUE)
                    424:         int fd = kqueue();
                    425:         ...
                    426: #else
1.31      rillig    427:         ...
1.1       dsieger   428: #endif
                    429: }
                    430: </pre>
                    431:              </td>
                    432: </tr>
                    433: </tbody>
                    434: </table></div>
                    435: </div>
1.36      maya      436: <br class="table-break">
1.1       dsieger   437: </div>
1.18      asau      438: <div class="sect2">
1.1       dsieger   439: <div class="titlepage"><div><div><h3 class="title">
1.39    ! rillig    440: <a name="components.patches.feedback"></a>13.3.5. Feedback to the author</h3></div></div></div>
1.1       dsieger   441: <p>Always, always, <span class="strong"><strong>always</strong></span>
                    442:       feed back any <span class="emphasis"><em>portability fixes</em></span> or
                    443:       improvements you do to a package to the mainstream developers.
                    444:       This is the only way to get their attention on portability issues
                    445:       and to ensure that future versions can be built out-of-the box on
                    446:       NetBSD.  Furthermore, any user that gets newer distfiles will get
                    447:       the fixes straight from the packaged code.</p>
                    448: <p>This generally involves cleaning up the patches
                    449:       (because sometimes the patches that are
1.17      wiz       450:       added to pkgsrc are quick hacks), filing bug reports in the
1.1       dsieger   451:       appropriate trackers for the projects and working with the
                    452:       mainstream authors to accept your changes.  It is
                    453:       <span class="emphasis"><em>extremely important</em></span> that you do it so that
                    454:       the packages in pkgsrc are kept simple and thus further changes
                    455:       can be done without much hassle.</p>
1.13      wiz       456: <p>When you have done this, please add a URL to the upstream
                    457:       bug report to the patch comment.</p>
1.1       dsieger   458: <p>Support the idea of free software!</p>
                    459: </div>
                    460: </div>
1.18      asau      461: <div class="sect1">
1.1       dsieger   462: <div class="titlepage"><div><div><h2 class="title" style="clear: both">
1.39    ! rillig    463: <a name="other-mandatory-files"></a>13.4. Other mandatory files</h2></div></div></div>
1.18      asau      464: <div class="variablelist"><dl class="variablelist">
1.1       dsieger   465: <dt><span class="term"><code class="filename">DESCR</code></span></dt>
                    466: <dd><p>A multi-line description of the piece of software.  This should include
                    467:          any credits where they are due.  Please bear in mind that others do not
                    468:          share your sense of humour (or spelling idiosyncrasies), and that others
                    469:          will read everything that you write here.</p></dd>
                    470: <dt><span class="term"><code class="filename">PLIST</code></span></dt>
                    471: <dd><p>This file governs the files that are installed on your
                    472:          system: all the binaries, manual pages, etc. There are other
                    473:          directives which may be entered in this file, to control the
                    474:          creation and deletion of directories, and the location of
1.39    ! rillig    475:          inserted files.  See <a class="xref" href="plist.html" title="Chapter 15. PLIST issues">Chapter 15, <i>PLIST issues</i></a> for more
1.1       dsieger   476:          information.</p></dd>
                    477: </dl></div>
                    478: </div>
1.18      asau      479: <div class="sect1">
1.1       dsieger   480: <div class="titlepage"><div><div><h2 class="title" style="clear: both">
1.39    ! rillig    481: <a name="components.optional"></a>13.5. Optional files</h2></div></div></div>
1.18      asau      482: <div class="sect2">
1.1       dsieger   483: <div class="titlepage"><div><div><h3 class="title">
1.39    ! rillig    484: <a name="components.optional.bin"></a>13.5.1. Files affecting the binary package</h3></div></div></div>
1.18      asau      485: <div class="variablelist"><dl class="variablelist">
1.1       dsieger   486: <dt><span class="term"><code class="filename">INSTALL</code></span></dt>
1.15      wiz       487: <dd>
1.37      leot      488: <p>This shell script is invoked twice by <a class="citerefentry" href="http://netbsd.gw.com/cgi-bin/man-cgi?pkg_add+1.i386+NetBSD-8.0"><span class="citerefentry"><span class="refentrytitle">pkg_add</span>(1)</span></a>.
1.1       dsieger   489:            First time after package extraction and before files are
                    490:            moved in place, the second time after the files to install
                    491:            are moved in place. This can be used to do any custom
                    492:            procedures not possible with @exec commands in
1.37      leot      493:            <code class="filename">PLIST</code>. See <a class="citerefentry" href="http://netbsd.gw.com/cgi-bin/man-cgi?pkg_add+1.i386+NetBSD-8.0"><span class="citerefentry"><span class="refentrytitle">pkg_add</span>(1)</span></a> and
1.39    ! rillig    494:            <a class="citerefentry" href="http://netbsd.gw.com/cgi-bin/man-cgi?pkg_create+1.i386+NetBSD-8.0"><span class="citerefentry"><span class="refentrytitle">pkg_create</span>(1)</span></a> for more information.  See also <a class="xref" href="pkginstall.html#files-and-dirs-outside-prefix" title="17.1. Files and directories outside the installation prefix">Section 17.1, &#8220;Files and directories outside the installation prefix&#8221;</a>.
1.15      wiz       495:            Please note that you can modify variables in it easily by using
                    496:            <code class="varname">FILES_SUBST</code> in the package's
                    497:            <code class="filename">Makefile</code>:</p>
                    498: <pre class="programlisting">
                    499: FILES_SUBST+=  SOMEVAR="somevalue"
                    500: </pre>
                    501: <p>replaces "@SOMEVAR@" with <span class="quote">&#8220;<span class="quote">somevalue</span>&#8221;</span> in the
                    502:            <code class="filename">INSTALL</code>.  By default, substitution is
                    503:            performed for <code class="varname">PREFIX</code>,
                    504:            <code class="varname">LOCALBASE</code>, <code class="varname">X11BASE</code>,
                    505:            <code class="varname">VARBASE</code>, and a few others, type
                    506:            <span class="command"><strong>make help topic=FILES_SUBST</strong></span> for a
                    507:            complete list.</p>
                    508: </dd>
1.1       dsieger   509: <dt><span class="term"><code class="filename">DEINSTALL</code></span></dt>
                    510: <dd><p>This script is executed before and after any files are removed.  It is
                    511:            this script's responsibility to clean up any additional messy details
                    512:            around the package's installation, since all pkg_delete knows is how to
                    513:            delete the files created in the original distribution.
1.37      leot      514:            See <a class="citerefentry" href="http://netbsd.gw.com/cgi-bin/man-cgi?pkg_delete+1.i386+NetBSD-8.0"><span class="citerefentry"><span class="refentrytitle">pkg_delete</span>(1)</span></a>
                    515:            and <a class="citerefentry" href="http://netbsd.gw.com/cgi-bin/man-cgi?pkg_create+1.i386+NetBSD-8.0"><span class="citerefentry"><span class="refentrytitle">pkg_create</span>(1)</span></a> for more information.
1.15      wiz       516:            The same methods to replace variables can be used as for
                    517:            the <code class="filename">INSTALL</code> file.</p></dd>
1.1       dsieger   518: <dt><span class="term"><code class="filename">MESSAGE</code></span></dt>
                    519: <dd>
                    520: <p>This file is displayed after installation of the package.
                    521:            Useful for things like legal notices on almost-free
                    522:            software and hints for updating config files after
                    523:            installing modules for apache, PHP etc.
                    524:            Please note that you can modify variables in it easily by using
                    525:            <code class="varname">MESSAGE_SUBST</code> in the package's
                    526:            <code class="filename">Makefile</code>:</p>
                    527: <pre class="programlisting">
                    528: MESSAGE_SUBST+=  SOMEVAR="somevalue"
                    529: </pre>
1.12      wiz       530: <p>replaces "${SOMEVAR}" with <span class="quote">&#8220;<span class="quote">somevalue</span>&#8221;</span> in
1.1       dsieger   531:            <code class="filename">MESSAGE</code>.  By default, substitution is
                    532:            performed for <code class="varname">PKGNAME</code>,
                    533:            <code class="varname">PKGBASE</code>, <code class="varname">PREFIX</code>,
1.27      sevan     534:            <code class="varname">LOCALBASE</code>, <code class="varname">X11BASE</code>,
1.1       dsieger   535:            <code class="varname">PKG_SYSCONFDIR</code>,
                    536:            <code class="varname">ROOT_GROUP</code>, and
1.11      jnemeth   537:            <code class="varname">ROOT_USER</code>.</p>
1.1       dsieger   538: <p>You can display a different or additional files by
                    539:            setting the <code class="varname">MESSAGE_SRC</code> variable.  Its
                    540:            default is <code class="filename">MESSAGE</code>, if the file
                    541:            exists.</p>
                    542: </dd>
                    543: <dt><span class="term"><code class="filename">ALTERNATIVES</code></span></dt>
1.19      asau      544: <dd>
                    545: <p>This file is used by the alternatives framework.
                    546:            It creates, configures, and destroys generic wrappers used to
                    547:            run programs with similar interfaces.
                    548:            See pkg_alternatives(8) from pkgtools/pkg_alternatives
                    549:             for more information.</p>
                    550: <p>Each line of the file contains two filenames, first
                    551:            the wrapper and then the alternative provided by the package.
                    552:            Both paths are relative to <code class="varname">PREFIX</code>.</p>
                    553: </dd>
1.1       dsieger   554: </dl></div>
                    555: </div>
1.18      asau      556: <div class="sect2">
1.1       dsieger   557: <div class="titlepage"><div><div><h3 class="title">
1.39    ! rillig    558: <a name="components.optional.build"></a>13.5.2. Files affecting the build process</h3></div></div></div>
1.18      asau      559: <div class="variablelist"><dl class="variablelist">
1.1       dsieger   560: <dt><span class="term"><code class="filename">Makefile.common</code></span></dt>
                    561: <dd><p>This file contains arbitrary things that could
                    562:        also go into a <code class="filename">Makefile</code>, but its purpose is
                    563:        to be used by more than one package. This file should only be
                    564:        used when the packages that will use the file are known in
                    565:        advance. For other purposes it is often better to write a
                    566:        <code class="filename">*.mk</code> file and give it a good name that
                    567:        describes what it does.</p></dd>
                    568: <dt><span class="term"><code class="filename">buildlink3.mk</code></span></dt>
                    569: <dd><p>This file contains the dependency information
1.39    ! rillig    570:        for the buildlink3 framework (see <a class="xref" href="buildlink.html" title="Chapter 16. Buildlink methodology">Chapter 16, <i>Buildlink methodology</i></a>).</p></dd>
1.1       dsieger   571: <dt><span class="term"><code class="filename">hacks.mk</code></span></dt>
                    572: <dd><p>This file contains workarounds for compiler bugs
                    573:        and similar things. It is included automatically by the pkgsrc
                    574:        infrastructure, so you don't need an extra
                    575:        <code class="literal">.include</code> line for
                    576:        it.</p></dd>
                    577: <dt><span class="term"><code class="filename">options.mk</code></span></dt>
                    578: <dd><p>This file contains the code for the
1.39    ! rillig    579:        package-specific options (see <a class="xref" href="options.html" title="Chapter 18. Options handling">Chapter 18, <i>Options handling</i></a>) that can be
1.1       dsieger   580:        selected by the user. If a package has only one or two options,
                    581:        it is equally acceptable to put the code directly into the
                    582:        <code class="filename">Makefile</code>.</p></dd>
                    583: </dl></div>
                    584: </div>
1.18      asau      585: <div class="sect2">
1.1       dsieger   586: <div class="titlepage"><div><div><h3 class="title">
1.39    ! rillig    587: <a name="components.optional.none"></a>13.5.3. Files affecting nothing at all</h3></div></div></div>
1.18      asau      588: <div class="variablelist"><dl class="variablelist">
1.1       dsieger   589: <dt><span class="term"><code class="filename">README*</code></span></dt>
                    590: <dd><p>These files do not take place in the creation of
                    591:        a package and thus are purely informative to the package
                    592:        developer.</p></dd>
                    593: <dt><span class="term"><code class="filename">TODO</code></span></dt>
                    594: <dd><p>This file contains things that need to be done
                    595:        to make the package even
                    596:        better.</p></dd>
                    597: </dl></div>
                    598: </div>
                    599: </div>
1.18      asau      600: <div class="sect1">
1.1       dsieger   601: <div class="titlepage"><div><div><h2 class="title" style="clear: both">
1.39    ! rillig    602: <a name="work-dir"></a>13.6. <code class="filename">work*</code>
1.1       dsieger   603: </h2></div></div></div>
1.6       hubertf   604: <p>When you type <span class="command"><strong>make</strong></span>, the distribution files are
1.1       dsieger   605:     unpacked into the directory denoted by
                    606:     <code class="varname">WRKDIR</code>. It can be removed by running
1.6       hubertf   607:     <span class="command"><strong>make clean</strong></span>. Besides the sources, this
1.1       dsieger   608:     directory is also used to keep various timestamp files.
                    609:     The directory gets <span class="emphasis"><em>removed completely</em></span> on clean.
                    610:     The default is <code class="filename">${.CURDIR}/work</code>
                    611:     or <code class="filename">${.CURDIR}/work.${MACHINE_ARCH}</code>
                    612:     if <code class="varname">OBJMACHINE</code> is set.</p>
                    613: </div>
1.18      asau      614: <div class="sect1">
1.1       dsieger   615: <div class="titlepage"><div><div><h2 class="title" style="clear: both">
1.39    ! rillig    616: <a name="files-dir"></a>13.7. <code class="filename">files/*</code>
1.1       dsieger   617: </h2></div></div></div>
                    618: <p>If you have any files that you wish to be placed in the package prior
                    619:     to configuration or building, you could place these files here and use
1.6       hubertf   620:     a <span class="command"><strong>${CP}</strong></span> command in the
1.12      wiz       621:     <span class="quote">&#8220;<span class="quote">pre-configure</span>&#8221;</span> target to achieve
1.1       dsieger   622:     this. Alternatively, you could simply diff the file against
                    623:     <code class="filename">/dev/null</code> and use the patch mechanism to manage
                    624:     the creation of this file.</p>
                    625: <p>If you want to share files in this way with other
                    626:     packages, set the <code class="varname">FILESDIR</code> variable to point
                    627:     to the other package's <code class="filename">files</code> directory,
                    628:     e.g.:</p>
                    629: <pre class="programlisting">
                    630: FILESDIR=${.CURDIR}/../xemacs/files
                    631: </pre>
                    632: </div>
                    633: </div>
                    634: <div class="navfooter">
                    635: <hr>
                    636: <table width="100%" summary="Navigation footer">
                    637: <tr>
                    638: <td width="40%" align="left">
                    639: <a accesskey="p" href="creating.html">Prev</a> </td>
                    640: <td width="20%" align="center"><a accesskey="u" href="developers-guide.html">Up</a></td>
                    641: <td width="40%" align="right"> <a accesskey="n" href="makefile.html">Next</a>
                    642: </td>
                    643: </tr>
                    644: <tr>
1.39    ! rillig    645: <td width="40%" align="left" valign="top">Chapter 12. Creating a new pkgsrc package from scratch </td>
1.1       dsieger   646: <td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
1.39    ! rillig    647: <td width="40%" align="right" valign="top"> Chapter 14. Programming in <code class="filename">Makefile</code>s</td>
1.1       dsieger   648: </tr>
                    649: </table>
                    650: </div>
                    651: </body>
                    652: </html>

CVSweb <webmaster@jp.NetBSD.org>