<!doctype debiandoc public "-//DebianDoc//DTD DebianDoc//EN"> <book>
  <title>
    Debian CLI Policy
  </title>
  
  <author>
    <name>Mirco Bauer</name>
    <email>meebey@debian.org</email>
  </author>
  <author>
    <name>Brandon Hale</name>
    <email>brandon@smarterits.com</email>
  </author>
  <author>
    <name>Sebastian Dr&ouml;ge</name>
    <email>slomo@debian.org</email>
  </author>
  <author>
    <name>Dylan R. E. Moonfire</name>
    <email>debian@mfgames.com</email>
  </author>
  
  <version>
    Version 0.7
  </version>

  <abstract>
    This document lays out basic policies regarding packaging Mono, other
    <qref id="CLR">CLRs</qref> and <qref id="CLI">CLI</qref> based applications/libraries on Debian GNU/Linux.
  </abstract>

  <copyright>
    <copyrightsummary>
      Copyright &copy; 2005-2009 Mirco Bauer
      Copyright &copy; 2005 Brandon Hale
      Copyright &copy; 2006 Sebastian Dr&ouml;ge
      Copyright &copy; 2006 Dylan R. E. Moonfire.
    </copyrightsummary>
    
    <p>This manual is free software; you may redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the Free
    Software Foundation; either version 2, or (at your option) any later
    version.</p>

    <p>This is distributed in the hope that it will be useful, but without
    any warranty; without even the implied warranty of merchantability or
    fitness for a particular purpose. See the GNU General Public License
    for more details.</p>

    <p>A copy of the GNU General Public License is available as
    /usr/share/common-licenses/GPL in the Debian GNU/Linux distribution or
    on the World Wide Web at the GNU General Public Licence. You can also
    obtain it by writing to the Free Software Foundation, Inc., 59 Temple
    Place - Suite 330, Boston, MA 02111-1307, USA.</p>
  </copyright>

  <toc sect1>

  <chapt id="history">
    <heading>Policy History</heading>
    
    <p>Here are the changes to the Debian CLI Policy document.</p>
    
    <p>
      Changes from 0.5.1 to 0.7:
      <list>
        <item><ref id="file-locations">: GAC libraries must now go in /usr/lib/cli/assembly_name-X.Y instead of /usr/lib/cli/upstream_package_name-X.Y, as one source package might ship many assemblies with different ABI versions.  This would produce very confusing directory names.</item>
        <item><ref id="gac-naming-versioning">: Late-GAC install is now mandatory.</item>
        <item><ref id="build-deps">: Added CLI SDKs as alternative to the compiler.</item>
        <item><ref id="signing">: Using the mono.snk key of cli-common-dev is now mandatory if upstream doesn't ship one.</item>
        <item><ref id="mono-disable-shm">: Replaced MONO_SHARED_DIR workaround with cli.make and MONO_DISABLE_SHM.</item>
        <item><ref id="debhelper7-example">: Added debhelper 7 example.</item>
        <item><ref id="gac-policy-files">: Added reference to the mono-api-check tool and made raising clilibs version mandatory.</item>
        <item><ref id=".NET">: Updated URL to Microsoft .NET Guidelines.</item>
        <item><ref id="package-names">: Made upstream tarball names clearer.</item>
        <item><ref id="file-perms">: Replaced find commands with dh + cli.make.</item>
        <item><ref id="gac-naming-versioning">: Removed ASP.NET as it's not a programming language and added IronPython and IronRuby.</item>
      </list>
    </p>
    <p>
      Changes from 0.5.0 to 0.5.1:
      <list>
        <item><ref id="package-names">: Added examples for the different meanings of package name.</item>
        <item><ref id="gac-naming-versioning">: Explicitly name the "lib" prefix requirement for library packages.</item>
      </list>
    </p>
    <p>
      Changes from 0.4.4 to 0.5.0:
      <list>
        <item>Removed DRAFT tag, the policy is now official.</item>
        <item><ref id="build-deps">: Added C# 3.0 to the compiler list.</item>
        <item><ref id="file-perms">: Added dh_clifixperms as alternative to the find command.</item>
      </list>
    </p>
    <p>
      Changes from 0.4.2 to 0.4.3:
      <list>
        <item><ref id="dh_installcligac">: Fixed order of dh_installcligac calls.</item>
        <item><ref id="debhelper-example">: Fixed debhelper example (order).</item>
        <item><ref id="cdbs-example">: Fixed cdbs example (order).</item>
      </list>
    </p>
    <p>
      Changes from 0.4.1 to 0.4.2:
      <list>
        <item><ref id="gac-policy-file-example">: Fixed naming of the policy
        files.</item>
      </list>
    </p>
    <p>
      Changes from 0.4.0 to 0.4.1:
      <list>
        <item><ref id="debhelper-example">: Fixed typo.</item>
      </list>
    </p>    

    <p>
      Changes from 0.3.0 to 0.4.0:
      <list>
        <item><ref id="build-deps">: Added nemerle to the compilers.</item>
        <item><ref id="packaging">: Added a packaging chapter that includes some of the old chapter and some new.</item>
        <item><ref id="gac-library-packaging">: Added informations about signing and policy files.</item>
        <item><ref id="dh_installcligac">: Added and consolidated the
        information on <file>dh_installcligac</file>.</item>
        <item><ref id="file-locations">: Require that files are installed into <file>/usr/lib/package</file> or <file>/usr/lib/cli/package-X.Y</file> now.</item>
      </list>
    </p>    
    <p>
      Changes from 0.2.1 to 0.3.0:
      <list>
        <item><ref id=".NET">: Added URL for the ".NET" term.</item>
        <item><ref id="GAC">: Added explanation of GAC.</item>
        <item><ref id="gac-library-packaging">: Added section for naming of GAC packages.</item>
      </list>
    </p>

    <p>
      Changes from 0.2.0 to 0.2.1:
      <list>
        <item><ref id="cli-common-dev">: Added examples for debhelper and CDBS.</item>
      </list>
    </p>

    <p>
      Changes from 0.1.1 to 0.2.0:
      <list>
        <item><ref id="history">: Added chapter "Policy History"</item>
        <item><ref id="build-deps">: Compiler dependency is no longer strict on
        mono-mcs</item>
        <item><ref id="cli-common-dev">: Note that dh_makeclilibs must be called before
        dh_clideps</item>
        <item><ref id="build-deps">: Moved dh_clideps and dh_makeclilibs into
        their own subsections</item>
        <item><ref id="file-perms">: Added chapter "File Permissions"</item>
        <item><ref id="migrating">: cli-wrapper is now deprecated</item>
        <item><ref id="dll-maps-intro">: Added an external link for
        DllNotFoundException</item>
      </list>
    </p>
  </chapt>
  
  <chapt id="terms">
    <heading>Used Terms</heading>
    
    <p>
      The ".NET" area uses its own set of abbreviations, which can
      look confusing to other people.
      This chapter lists some of the terms along with their explanations:
    </p>
    
    <sect id="CLI">
      <heading>CLI - Common Language Infrastructure</heading>
      
      <p>
        This is what most people mean when they say ".NET".
        The CLI defines mainly the virtual machine, the bytecode and how everything
        works together.  It is both an
    <url id="http://www.iso.org/iso/en/CatalogueDetailPage.CatalogueDetail?CSNUMBER=36769" name="ISO">
        and <url id="http://www.ecma-international.org/publications/standards/Ecma-335.htm" name="ECMA">
        standard.
      </p>
    </sect>
    
    <sect id="CLR">
      <heading>CLR - Common Language Runtime</heading>
     
      <p>
        The CLR is an implementation of the <qref id="CLI">CLI</qref> (often with a lot of add-ons or tools
        for developers). Mono and Microsoft .NET Framework are CLRs.
      </p>
    </sect>
    
    <sect id="CIL">
      <heading>CIL - Common Intermediate Language</heading>
      
      <p>
        The CIL is the format of the bytecode for binaries and libraries
        used by the <qref id="CLI">CLI</qref>.
      </p>
    </sect>
    
    <sect id=".NET">
      <heading>".NET" or long "Microsoft .NET Framework"</heading>
      
      <p>
        The ".NET" word is a Microsoft marketing phrase and mostly is a
        CLR with added Microsoft technologies like: ASP.NET, VB.NET,
        System.Windows.Forms, Passport plus a lot of other things.
      <p>

      <p>
        <strong>We highly discourage from using any form of the word ".NET", it is
        burdened by copyright and marketing.</strong>  We  advice to use the correct
        term instead, which is usually <qref id="CLI">CLI</qref>.
      </p>

      <p>
        If you really want to use the ".NET" term in a correct form please refer to the
        <url id="http://www.microsoft.com/about/legal/trademarks/usage/net.mspx" name="Microsoft .NET Guidelines">.
      </p>
    </sect>

    <sect id="GAC">
      <heading>GAC - Global Assembly Cache</heading>

      <p>
        The GAC contains and manages the libraries for the <qref id="CLR">CLR</qref>.
        It allows users to install multiple versions of the same library and enables loading of
        the right version when an application is executed.
      </p>
      <p>
        Mono stores the GAC at <file>/usr/lib/mono/gac</file>
      </p>
      <p>
        DotGNU Portable.NET stores the GAC at <file>/usr/lib/cscc/lib</file>
      </p>
    </sect>

    <sect id="package-names">
      <heading>Package Names</heading>

      <p>
        There are different set of package names we refer in this policy to.
        Here a list of examples for the different names:
        <list>
           <item>
             assembly (file) names:
             <example>gtk-sharp.dll</example>
             <example>log4net.dll</example>
             <example>FlickrNet.dll</example>
           </item>
           <item>
             (debian) source package names:
             <example>gtk-sharp2</example>
             <example>log4net</example>
             <example>libflickrnet</example>
           </item>
           <item>
             (debian) binary package names:
             <example>libgtk2.0-cil</example>
             <example>libgnome2.0-cil</example>
             <example>liblog4net1.2-cil</example>
             <example>libflickrnet2.1.5-cil</example>
           </item>
           <item>
             upstream package names (a good indicator is the pkg-config file name):
             <example>gtk-sharp-2.0</example>
             <example>log4net</example>
             <example>flickrnet</example>
           </item>
           <item>
             upstream tarball names (without version and file extension):
             <example>gtk-sharp-2.12.9.tar.gz -> gtk-sharp</example>
             <example>log4net-1.2.0-beta8.zip -> log4net</example>
             <example>FlickrNet-25207.zip -> FlickrNet</example>
           </item>
        </list>
      </p>
    </sect>
  </chapt>

  <chapt id="packaging">
    <heading>Packaging Policy</heading>

    <p>
      This section describes the additions to the
      <url id="http://www.debian.org/doc/debian-policy/" name="Debian Policy">
      that are required for <qref id="CLI">CLI</qref> packages.
    </p>

    <sect id="general-packaging">
      <heading>General Packaging</heading>

      <sect1 id="architecture">
        <heading>Architecture</heading>
        
        <p>
          For packages that consist of 100% managed code, "Architecture: all" <em>must</em> be chosen in debian/control.
        </p>
        <p>
          Packages containing a mix of managed and native code <em>must</em> be "Architecure: any" or
          depending on the specific package a more restricted set of architectures is valid.
        </p>
      </sect1>

      <sect1 id="file-locations">
        <heading>File Locations</heading>
        
        <p>
          The package's applications, libraries and meta-data <em>must</em> be installed into
          <file>
            /usr/lib/<qref id="package-names"><var>upstream_package_name</var></qref>
          </file>.
        <p>

        <p>
          Libraries that will be installed into the GAC <em>must</em> be installed into
          <file>
            /usr/lib/cli/<qref id="package-names"><var>assembly_name</var></qref>-X.Y
          </file> 
          (for more details about the X.Y version see <qref id="gac-naming-versioning">GAC versioning</qref>).
          <var>assembly_name</var> is the assembly name without the file extension (.dll).
          The commonly seen
          <file>
            /usr/lib/<strong>mono</strong>/<qref id="package-names"><var>upstream_package_name</var></qref>
          </file>
          path should <em>only</em> be used for Mono project packages.
        </p>

        <p>
          Example path for the <package>log4net</package> package:
          <example>
/usr/lib/cli/log4net-1.2
          </example>
        </p>
        
        <p>
          Never install native "glue" libraries into <file>/usr/lib</file>, instead install them at
          <file>
            /usr/lib/cli/<qref id="package-names"><var>assembly_name</var></qref>-X.Y
          </file>. When moving libraries
          update the references to the new location using a DLL Map.  See the
          <qref id="dll-maps-intro">Mono DLL maps</qref> section for an example.
        </p>

        <p>
          The only exception here is for native libraries that are of wider use;
          can be used other packages. Native libraries should be packaged according to the
          <url id="http://www.netfort.gr.jp/~dancer/column/libpkg-guide/libpkg-guide.html"
          name="Library Packaging Guide"> in a Debain Policy conformant way.
        </p>

        <p>
          You <em>must not</em> install application files (<file>.exe</file>) directly into <file>/usr/bin</file>.
          Instead create a <qref id="wrapper-script-example">wrapper script</qref>
          into <file>/usr/bin</file> to allow them to be run without path and the <file>.exe</file> suffix.
        </p>
      </sect1>

      <sect1 id="file-perms">
        <heading>File Permissions</heading>
     
        <p>
          Source code files (<file>*.cs</file>, <file>*.vb</file>, <file>*.boo</file>, etc.) should be non-executable.
        </p>
        <p>
          Library files (<file>*.dll</file>) should be non-executable.
        </p>
        <p>
          Debug symbol files (<file>*.mdb</file>) should be non-executable.
        </p>
        <p>
          Assembly config files (<file>*.config</file>) should be non-executable.
        </p>
        
        <p>
          Application files (<file>*.exe</file>) <em>must</em> have the executable flag (+x) set to enable
          compatiblity with direct invokation as <file>./foo.exe</file> using Linux's BINFMT support.
        </p>
        
        <p>
          To ensure that all files have correct permissions, you <em>should</em> use Debhelper's
          <file>/usr/bin/dh</file> combined with <file>cli.make</file>.  Otherwise you <em>should</em> add
          <file>dh_clifixperms</file> after <file>dh_fixperms</file> in the binary-* targets of
          <file>debian/rules</file>.
        </p>
      </sect1>

      <sect1 id="build-deps">
        <heading>Build Dependencies</heading>
        
        <p>
          At a minimum, CLI packages <em>should</em> Build-Depends on
          <package>cli-common-dev</package> (&gt;= 0.7) and the
          appropriate CLI compiler or CLI SDK package.
        </p>
        
        <p>
          Current CLI compilers in Debian:
          <list>
            <item>
              C#: <package>mono-mcs</package> (&gt;= 1.0) | c-sharp-compiler
            </item>
            <item>
              C# 2.0: <package>mono-gmcs</package> (&gt;= 1.1.8) | c-sharp-2.0-compiler
            </item>
            <item>
              C# 3.0: <package>mono-gmcs</package> (&gt;= 1.2.5) | c-sharp-3.0-compiler
            </item>
            <item>
              Nemerle: <package>nemerle</package> (&gt;= 0.9)
            </item>
            <item>
              Boo: <package>boo</package> (&gt;= 0.5.6)
            </item>
          </list>

          Current CLI SDKs in Debian:
          <list>
            <item>
              Mono: <package>mono-devel</package> (&gt;= 2.4.2.3)
            </item>
          </list>
        </p>
        
        <p>
          Software that uses Mono via the C interface library
          (<file>libmono.so</file>) or requires the
          <file>/usr/lib/pkgconfig/mono.pc</file> file <em>must</em>
          Build-Depends on libmono-dev (&gt;= 1.0)
        </p>
        
        <p>
          Note that there are architectures for which no <qref id="CLR">CLR</qref> is
          available and thus you may have to restrict the Build-Depends for your
          package to the architectures available.
        </p>

        <p>
          If your package is <file>Architecture: all</file>, you should specify this as Build-Depends-Indep.
          Never put <package>debhelper</package>, <package>cdbs</package>, <package>dpatch</package> and
          <package>quilt</package> into Build-Depends-Indep. See the <url
          id="http://www.debian.org/doc/debian-policy/ch-relationships.html#s-sourcebinarydeps"
          name="Debian Policy Manual"> for more information on this.
        </p>
      </sect1>  
    </sect>

    <sect id="gac-library-packaging">
      <heading>GAC Library Packaging</heading>

      <p>
        Libraries that are installed into the <qref id="GAC">GAC</qref>
        should provide decent ABI stability and be useful for other
        packages.  Otherwise, they should remain private to the package.
      </p>

      <sect1 id="gac-naming-versioning">
        <heading>Naming &amp; Versioning</heading>
        
        <p>
          Libraries that are installed into the <qref id="GAC">GAC</qref> <em>must</em> be
          strong-named, i.e. <qref id="signing">signed</qref>.
        </p>
        
        <p>
          Libraries <em>must</em> to be installed into the GAC at package install
          time (postinst) which is provided by the <qref id="dh_installcligac">dh_installcligac</qref>
          tool of the <package>cli-common-dev</package> package.
        </p>

        <p>
          Each of the libraries in the <qref id="GAC">GAC</qref> has
          an assembly version number that consists of 4 parts (major, minor, build
          and revision number). When loading libraries from the
          <qref id="GAC">GAC</qref> all 4 parts and the public
          signing key fingerprint must match.
        </p>
        
        <p>
          It is general practice and <url
          id="http://msdn.microsoft.com/netframework/programming/deployment/default.aspx?pull=/library/en-us/dndotnet/html/dplywithnet.asp#dplywithnet_version"
          name="recommended by Microsoft">
          that a library is ABI compatible when only the build and
          revision number change and the major and minor number stay
          the same.
        </p>
        
        <p>
          The library package name <em>must</em> be prefixed with <file>lib</file>.
        </p>

        <p>
          To reflect the ABI stability and prevent breakages when a
          ABI-incompatible version is released, a similar solution for
          <url id="http://www.netfort.gr.jp/~dancer/column/libpkg-guide/libpkg-guide.html#naminglibpkg"
          name="native library packages">
          is used. The major and minor number <em>must</em> mirror
          the SONAME version and the resulting package name should be
          <package>libfooX.Y-cil</package>, where X is the major and
          Y the minor number of the assembly version.
        </p>

        <p>
          One notable exception for this naming are assemblies that
          end on a number (Mono.C5 for example).  In this case the
          package should be named <package>libfoo123-X.Y-cil</package>
          (i.e. <package>libmono-c5-0.5-cil</package>) to improve the
          readability.
        </p>
        
        <p>
          The <file>-cil</file> suffix is chosen to prevent confusion
          with native library package names. Never use "sharp" in the package
          name as it does not represent the language, and a <qref id="CLI">CLI</qref>
          library can be used with all <qref id="CLI">CLI</qref> implemented / enabled
          languages such as C#, IronPython, IronRuby, Boo, Nemerle, J#, VB.NET
          (<url id="http://www.mono-project.com/Languages" name="full list">).
        </p>

        <p>
          Unnecessary package renames should be avoided.  Existing
          package names that do not follow this policy should not be
          renamed until the next incompatible ABI change, at which point the
          new naming scheme should be used.
        </p>
        
        <p>
          If the upstream software does not use major and minor
          number to reflect ABI stability or breaks ABI with a change
          in build or revision, the package <em>must</em> be renamed to either
          <package>libfooA.B.C-cil</package> or
          <package>libfooA.B.C.D-cil</package>
          (where A, B, C, D are the complete assembly version numbers),
          depending at which point (major or minor) the breakage occurred.
          All <qref id="gac-policy-files">Policy Files </qref>
          <em>must</em> be dropped at this stage until a new major or minor
          version is released.
        </p>
        
        <p>
          The upstream software may use wildcards in the assembly versions (1.2.* for example) which
          are filled by the compiler with a random value. You <em>must</em> replace these wildcards
          with 0 (1.2.0.0 in the example) to make it possible to use
          <qref id="gac-policy-files">Policy Files</qref> and make predictable version numbers.
        </p>
        
        <p>
          More than one library can be installed in one package but
          it is required that they <em>must</em> all have the same
          assembly version and belong together.
        </p>
      </sect1>

      
      <sect1 id="gac-policy-files">
        <heading>Policy Files</heading>

        <p>
          As explained above a exact match of the version number is required
          to load a library from the <qref id="GAC">GAC</qref>. To override this behaviour
          and make different versions of ABI-compatible library packages really
          ABI-compatible you have to use <url
          id="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcreatingpublisherpolicyfile.asp"
          name="Policy Files">. These files have to be named <file>policy.X.Y.foo.dll</file> (where X and Y
          are the major and minor number of the assembly it should be compatible with),
          it <em>must</em> be signed with the same signing key as the original assembly and it must be installed
          into the <qref id="GAC">GAC</qref>. For information on how to create policy files
          look at the previous Policy Files link or at the <qref id="gac-policy-file-example">example</qref>
          below.
        </p>
        
        <p>
          Overriding the <qref id="GAC">GAC</qref> policy should only
          be done when the different library versions are really
          ABI-compatible. This can be checked using <qref id="api-compat-example">mono-api-check</qref>
          of the <package>mono-devel</package> package.  You <em>must</em> also raise
          the version in the <qref id="clilibs-control-file">clilibs control file</qref>
          to the minimum version when new interfaces/classes/methods were added.
        </p>
      </sect1>

      <sect1 id="clilibs-control-file">
        <heading>clilibs Control File</heading>

        <p>
          The <file>clilibs</file> control file <em>MUST</em> be present in all <qref id="GAC">GAC</qref> library
          packages. It can be created with the <qref id="dh_makeclilibs">dh_makeclilibs</qref>
          helper script and has a format similar to the <file>shlibs</file> file created by <manref name="dh_makeshlibs" section="1">
          and also has a similar use: it is used by
          <qref id="dh_clideps">dh_clideps</qref>
          helper script to find the correct dependencies.
        </p>
        
        <p>
          You <em>should</em> always set the minimum required version of the library in the <file>clilibs</file> file.
        </p>
      </sect1>

      <sect1 id="pkg-config-file">
        <heading>pkg-config File</heading>
        
        <p>
          Many libraries deliver a <file>.pc</file> file for use by
          the <file>pkg-config</file> helper utility, which aids
          other libraries and applications to link against libraries.
        </p>

        <p>
          All GAC library packages should have a pkg-config <file>.pc</file> file located in <file>/usr/lib/pkgconfig</file>.
          The filename <em>must</em> be identical to that shipped by upstream.
        </p>
      </sect1>

      <sect1 id="signing">
        <heading>Signing</heading>

        <p>
          When installing libraries into the <qref id="GAC">GAC</qref> signing
          is required. The signing key should be supplied by upstream.
          If upstream is not supplying the key then you <em>must</em> use the
          <file>mono.snk</file> key from the <package>cli-common-dev</package>
          package. This key <em>must</em> be used for all following versions of
          the library to maintain ABI compatbility.
        </p>

        <p>
          Unnecessary ABI breakages should be avoided.  Existing
          keys shipped by the source package should not be replaced
          (with mono.snk) until the next incompatible ABI change.
        </p>
      </sect1>
    </sect>
    
    <sect id="non-gac-library-packaging">
      <heading>non-GAC Library Packaging</heading>

      <p>
        This includes libraries that are not ABI-stable, may be not
        strong-named and are usually in an early stage of
        development. They <em>must</em> not include a clilibs control file.
      </p>

      <sect1 id="non-gac-naming">
        <heading>Naming</heading>

        <p>
          The package should be named <file>libfoo-cil</file> (without a version in the package name)
          and libraries should not be installed into the <qref id="GAC">GAC</qref> but only
          into <file>/usr/lib/upstream_package_name</file>.
        </p>

        <p>
          Applications using non-GAC libraries <em>must</em> copy the libraries they need into their own
          application directory. You can compare this with static linking of native libraries.
        </p>
      </sect1>      
    </sect>
  </chapt>
  

  <chapt id="mono">
    <heading>Mono Specific Packaging help</heading>
    
    <p>
      This section offers help with common problems encountered when
      packaging Mono-specific applications for Debian.
    </p>
    <sect>
      <heading>Naming</heading>
      
      <p>
        The official name of the Mono Project is: Mono, mono:: or mono.
        To keep this consistent for users, it should
        <em>always</em> be called "Mono" (not MONO, mono, mono:: or mixed
        with the .NET name). The explanation of what Mono is, should be in
        the package <em>long</em> description.
      </p>
    </sect>

    <sect>
      <heading>DLL Maps</heading>
      
      <p>
        Often times, upstream software developers are not
        packagers, and vice versa. Developers do not necessarily test their
        software with packaging issues in mind. The most common problem we
        see from this are missing DLL exceptions.
      </p>

      <sect1 id="dll-maps-intro">
        <heading>Introduction</heading>
        
        <p>
          When Mono code invokes an external library, it usually calls
          something like [DllImport("foo")] which expands "foo" to
          a shared library name such as "libfoo.so" which is then
          searched for in the library search path.
        </p>

        <p>
          In Debian and some other binary Linux distributions,
          packages are split into runtime and developer (-dev)
          packages. Since the versioned library libfoo.so.X is
          usually used at runtime, and libfoo.so is a symlink only
          used when building against the library, the libfoo.so
          symlink is in the libfoo-dev package.
        </p>

        <p>
          When packaging an application which uses libfoo.so normal
          users should not need the -dev packages installed just to
          run the application.  However, Mono defaults to looking for
          the unversioned libfoo.so, which is unavailable in the
          runtime package.
        </p>

        <p>
          When the DLL map is missing or upstream forgets to install
          the DLL map, it will result in a
          <url id="http://www.mono-project.com/DllNotFoundException" name="DllNotFoundException">
          which will stop the execution of the program.
        </p>
      </sect1>
      
      <sect1>
        <heading>Solution: DLL map config file</heading>
          
        <p>
          This can be fixed by creating a DLL map for the application exe or
          for the library DLL that is trying to invoke libfoo.so.
          If libfoo.so is invoked by the DLL bar.dll, create an xml file,
          bar.dll.config to tell Mono which .so should be loaded at runtime.
          bar.dll.config should be installed to the same directory as bar.dll.
        </p>

        <p>
          <example>
          &lt;configuration&gt;
          &lt;dllmap dll="foo" target="libfoo.so.0"/&gt;
          &lt;/configuration&gt;
          </example>
        </p>

        <p>
          A config file can contain as many dllmap directives as are needed.
          If the upstream developer already ships a config file, but it is
          incomplete, you should create a patch against it in your package.
        </p>

        <p>
          Most Mono software developers are very helpful people, and will
          readily accept patches to solve this type of bug if you bring it to
          their attention. Please be sure to inform them of all these changes.
        </p>
      </sect1>
    </sect>
    
    <sect id="mono-disable-shm">
      <heading>MONO_DISABLE_SHM</heading>
      
      <p>
        The Mono runtime uses a shared directory, by default
        <file>~/.wapi</file>. This directory will be created/used when any CLI
        application is executed (like the C# compiler mcs).
      </p>
      
      <p>
        There are 2 problems with this:
        <list>
          <item>In an autobuilder environment often the running user has no home directory.</item>
          <item>Mono uses the wrong home directory when running within fakeroot
          (it tries <file>/root/.wapi</file> instead of <file>$HOME/.wapi
          </file>).</item>
        </list>
      </p>
      
      <p>
        In these cases, the package building will fail, applications
        will hang, die with strange Mono runtime errors or segfault.
        This includes dh_clideps or dh_makeclilibs, since they run
        monodis.
     </p>

     <p>
        The solution is to include <file>cli.make</file> from
        <package>cli-common-dev</package> in <file>debian/rules</file> or
        to manually set the MONO_DISABLE_SHM environment variable.
        <example>
        export MONO_DISABLE_SHM = 1
        </example>
      </p>
    </sect>
  </chapt>

  <chapt id="pnet">
    <heading>DotGNU Portable.NET Packaging help</heading>
    
    <p>
      This section offers help to common problems encountered when
      packaging DotGNU Portable.NET-specific applications for Debian.
    </p>
    <sect>
      <heading>Naming</heading>
      
      <p>
        The official name of the DotGNU Portable.NET project is exactly that.
        To keep this consistent for users, it should be <em>always
        </em> called "DotGNU Portable.NET" (not pnet or Portable.NET).
        The explanation of what DotGNU Portable.NET is, should be in
        the package <em>long</em> description.
      </p>
    </sect>
  </chapt>

  <chapt id="appendix">
    <heading>Appendix</heading>

    <sect id="cli-common-dev">
      <heading>Helper Scripts: cli-common-dev</heading>

      <p>
        When using cli-common-dev and the included dh_* scripts packages <em>must</em>
        Build-Depends on <package>cli-common-dev</package> (&gt;= 0.7)
        (this version may change later, when cli-common-dev has changes which
        are required to be used by all CLI packages, the CLI Policy version will
        represent such changes).
      </p>

      <sect1 id="dh_makeclilibs">
        <heading>dh_makeclilibs</heading>

        <p>
          dh_makeclilibs is used to create the <qref id="clilibs-control-file">clilibs
          control files</qref> which are used later by <file>dh_clideps</file> for this or other
          packages. It <em>must</em> only be used when your package contains libraries
          that other packages may link against.
        </p>
        <p>
          It has the same use (and very similar parameters) to
          <file>dh_makeshlibs</file>. You should always use the
          most minimal version necessary.
        </p>
        <p>
          <em>This program <em>must</em> be called before <file>dh_clideps</file>.</em>
        </p>
        
        <p>
          See <manref name="dh_makeclilibs" section="1"> for details.
        </p>
      </sect1>

      <sect1 id="dh_clideps">
        <heading>dh_clideps</heading>

        <p>
          <file>dh_clideps</file> is used to discover the native and managed dependencies
          of the packages. It uses the <qref id="clilibs-control-file">clilibs
          control files</qref>, the <file>.config</file> of assemblies and the <file>shlibs</file>
          files created by <file>dh_makeshlibs</file>. The discovered dependencies are written into the ${cli:Depends} variable.
        </p>

        <p>
          <em><file>dh_shlibdeps</file> must be run before
          <file>dh_clideps</file>.  <file>dh_makeshlibs</file> and
          <file>dh_makeclilibs</file> must be run before
          <file>dh_clideps</file></em>. If not, when two binary
          packages from the same source package depend on one
          another, <file>dh_clideps</file> will not be able to
          determine the dependencies.
        </p>
        
        <p>
          <file>dh_clideps</file> can remove duplicate dependencies
          created by running <file>dh_clideps</file> and
          <file>dh_shlibsdeps</file> when run given the -d parameter.
        </p>
        
        <p>
          See <manref name="dh_clideps" section="1"> for details.
        </p>
      </sect1>

      <sect1 id="dh_installcligac">
        <heading>dh_installcligac</heading>

        <p>
          <file>dh_installcligac</file> is used to facilitate the
          installation of strong-named assemblies into the various
          caches installed on the user's machine. Its primary purpose is
          to install the assemblies at the point of installation instead
          of pre-packing them inside the Debian package; this is also
          known as late-GAC install.
        </p>

        <p>
          To identify which assemblies need to be installed into the
          GAC, <file>dh_installcligac</file> uses the
          <file>debian/installcligac</file> or the
          <file>debian/packagename.installcligac</file> to list the
          assemblies to install or uninstall at installation or removal
          respectivly.
        </p>

        <p>
          The file format of the <file>installcligac</file> is
          simple: the full installed path of every assembly to install
          into the <qref id="GAC">GAC</qref>. For example, the
          liblog4net1.2-cil package would have this in the
          <file>debian/installcligac</file> file:

          <example>/usr/lib/cli/log4net-1.2/log4net.dll</example>
        </p>

        <p>
          <file>dh_installcligac</file> needs to be called after
          <file>dh_install</file> and before <file>dh_clideps</file>.
          See <manref name="dh_installcligac" section="1"> for details.
        </p>
      </sect1>
    </sect>

    <sect id="examples">
      <heading>Examples</heading>

      <sect1 id="debhelper-example">
        <heading>debhelper 5/6 Example</heading>

        <p>
          For binary-arch packages:
          <example>
binary-arch: build install
	...
	dh_shlibdeps -a
	dh_makeclilibs -a -V
	dh_installcligac -a
	dh_clideps -a
	...
          </example>

          For binary-indep packages:
          <example>
binary-indep: build install
	...
	dh_makeclilibs -i -V
	dh_installcligac -i
	dh_clideps -i
	...
          </example>
        </p>
      </sect1>

      <sect1 id="debhelper7-example">
        <heading>debhelper 7 Example</heading>

        <p>
          With debhelper's 7 <file>/usr/bin/dh</file> you don't need to add any
          extra commands to <file>debian/rules</file> yourself as debhelper has
          an API that allows to extend it.
          <package>cli-common-dev</package> as of version 0.5.7 can extend
          debhelper 7 with all commands that are needed. You can enable this by
          including the <file>cli.make</file> file in <file>debain/rules</file>
          like this:
          <example>
include /usr/share/cli-common/cli.make
          </example>

          That's it, you are done! :-)
        </p>
      </sect1>

      <sect1 id="cdbs-example">
        <heading>cdbs Example</heading>

        <p>
          <example>
common-binary-predeb-arch common-binary-predeb-indep::
	dh_shlibdeps
	dh_makeclilibs -V
	dh_installcligac
	dh_clideps
          </example>
        </p>
      </sect1>

      <sect1 id="wrapper-script-example">
        <heading>Executable Wrapper Script Example</heading>

        <p>
          <example>
#!/bin/sh
exec /usr/bin/cli /usr/lib/package/package.exe "$@"
          </example>
        </p>
      </sect1>

      <sect1 id="api-compat-example">
        <heading>API Compatibility Check Example</heading>
        <p>
          You need to install following packages for this example: mono-devel libmono-sharpzip0.6-cil libmono-sharpzip0.84-cil
          <example>
mono-api-check /usr/lib/mono/gac/ICSharpCode.SharpZipLib/0.6.0.0__1b03e6acf1164f73/ICSharpCode.SharpZipLib.dll \
   /usr/lib/mono/gac/ICSharpCode.SharpZipLib/0.84.0.0__1b03e6acf1164f73/ICSharpCode.SharpZipLib.dll
CLI API Check
Assembly Name:          ICSharpCode.SharpZipLib
Missing Interfaces:     44
Additional Interfaces:  79

The two assemblies you compared are not API compatible!
You must use a new package name!

The new assembly has additional interfaces. You must raise
the minimal version in clilibs!
          </example>
          The mono-api-check wrapper script checks whether there are new public/protected interfaces (where interface
          in this context means namespace, class, method, interface, delegate, etc) or any missing ones. When an interface
          is changed it will show up as missing and additional. You should follow the instructions, in this case you must
          create a new versioned package for the library and raise the minimal version number for the
          <qref id="dh_makeclilibs">dh_makeclilibs</qref> call.
        </p>
      </sect1>

      <sect1 id="gac-policy-file-example">
        <heading>GAC Policy File Example</heading>
        <p>
          <example>
&lt;configuration&gt;
   &lt;runtime&gt;
      &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
       &lt;dependentAssembly&gt;
         &lt;assemblyIdentity name="foo" publicKeyToken="35e10195dab3c99f" /&gt;
         &lt;bindingRedirect oldVersion="1.2.0.0-1.2.10.0" newVersion="1.3.0.0"/&gt;
       &lt;/dependentAssembly&gt;
      &lt;/assemblyBinding&gt;
   &lt;/runtime&gt;
&lt;/configuration&gt;
          </example>
          The above example would be used for a policy file for the "foo" assembly and would tell
          the <qref id="GAC">GAC</qref> that version 1.3.0.0 is compatible with versions 1.2.0.0 to 1.2.10.0.
          You have to compile and install it with
          <example>
al -link:policy.1.2.foo.config -out:policy.1.2.foo.dll -keyfile:path/to/keyfile
gacutil /i policy.1.2.foo.dll
          </example>
        </p>
        <p>
          Keep in mind that the filenames <em>must</em> be
          policy.X.Y.foo.config and policy.X.Y.foo.dll where
          foo is the assembly name and X.Y is the major and minor version
          number you want to be compatible with.
        </p>
      </sect1>
    </sect>

    <sect id="migrating">
      <heading>Migrating Existing Packages</heading>
      
      <p>
        Many CLI packages already exist in Debian, or are in ITP, and conform to
        the deprecated <url id="http://wiki.debian.org/?MonoConventions"
        name="Mono Conventions">.
      </p>

      <p>
        Any <file>debian/rules</file> hacks or patches that exist to redirect
        files to <file>/usr/share/dotnet</file> should be removed, and adjusted
        according to upstream file locations (<file>/usr/lib</file>). See
        <url id="http://wiki.debian.org/?MonoDebianPlan" name="Mono Debian Plan">
        for the rationale behind this change.
      </p>

      <p>
        Also, be sure to replace references to dh_netdepends, dh_makenetlibs, and
        ${net:Depends} with the newer names described in the policy above.
      </p>

      <p>
        Please remove any build-deps on <package>mono-jit</package>,
        <package>mono-mint</package>, <package>mono-utils</package> (this one had
        the dh_* helper scripts which are now in <package>cli-common-dev</package>)
        and <package>libmono-dev</package> (use this one only if the package
        really links against <package>mono</package> or requires the mono.pc
        file).
      </p>
    </sect>
  </chapt>
</book>

