Adding a package to the Build System

If you want to add a package to the build system, there are a couple of things needed. If the package is designed to be built with GNU make (most of them), the process is fairly straight forward. For this example, I'll take the example of xinetd. xinetd is setup to use the GNU autoconf configure script. Here's the series of steps I went through to get xinetd building under the Darwin Build System.

Adding a GNU Autoconf package

  • Download the package. The version I'm using is 2.1.8.9pre14, so the package is xinetd-2.1.8.9pre14.tar.gz.

  • Unpack the package. After untarring the package, I have the directory xinetd-2.1.8.9pre14

  • Create a directory above the package's directory. Create a directory xinetd and move xinetd-2.1.8.9pre14 into the newly created xinetd directory and rename it xinetd as well:

    mkdir xinetd

    mv xinetd-2.1.8.9pre14 xinetd/xinetd

  • Create a dpkg control file. Create the dpkg directory xinetd/dpkg, and create a control file. The control file should be similar to the following:


    Package: xinetd
    Maintainer: Synack Communications 
    Vendor: Synack Communications
    Version: 2.1.8.9pre14
    Build-Depends: build-base
    Description: xinetd is a replacement for inetd.

    The Build-Depends tag is a space separated list of packages required to build the package. build-base is a predefined tag that consists of the compiler and most libraries and utilities needed to build most packages.

  • Create a high level package Makefile. Create a Makefile, xinetd/Makefile, that looks like:


    Project               = xinetd
    UserType              = Administrator
    ToolType              = Commands
    Extra_Configure_Flags = --with-libwrap

    # It's a GNU Source project
    include $(MAKEFILEPATH)/CoreOS/ReleaseControl/GNUSource.make

    Install_Target = install

    The Extra_Configure_Flags is a list of flags to pass to configure.

  • Build the package. Run the command to build the system:

    sudo darwin-buildpackage --dir xinetd in out

    Now, assuming the package properly supports the use of the --srcdir flag to configure, the package will build correctly. Very odd errors can happen when trying to build a package under the Darwin Build System, because it does not build the package in the source directory. Instead it has a separate temporary directory for the intermediate object files.

Adding a 3rd Party Package

This section describes how to add a package to the Darwin build system that does not use the GNU Autoconf system to build the project. This section will be rather generic, since a "3rd Party Package" can do just about anything to build its self.

  • Get the package. For this example, I'll use mkisofs.

  • Put the package in a nested directory in mkisofs/mkisofs. This will let the wrapper Makefile and control files go in the top directory, and the actual unmodified source go in the lower directory.

  • Create a mkisofs/dpkg directory, and a control file within it. The control file should be similar to the one mentioned in the previous GNU Autoconf example.

  • Create the wrapper Makefile. The Makefile will look similar to this:


    # Project info

    # Project should be the project name, but also the name of the subdirectory
    # where the project actually lives.
    Project               = mkisofs
    UserType              = Administration
    ToolType              = Commands
    # Extra_Environment is a variable you can set with extra environment variables
    # while building the project
    Extra_Environment     =

    # It's a 3rd Party Source project, meaning it doesn't use autoconf or the
    # BSD style project building...
    include $(MAKEFILEPATH)/CoreOS/ReleaseControl/Common.make

    # Dunno, just copied over and it makes things happy.
    lazy_install_source:: shadow_source

    # Every project should have a 'build' target.  This is the target that
    # the build scripts use to compile the whole thing.
    build:: lazy_install_source
          @echo "Building $(Project)..."
          # Fill in necessary commands to build the project
          # Example make command:
          #$(_v) $(MAKE) -C $(BuildDirectory)/$(Project) $(Environment)

    # Every project should also have an 'install' target.  This is the target
    # the build scripts use to install the package, and wrap it up.
    install:: build
          @echo "Installing $(Project)..."
          # Fill in the necissary commands to install the project
          # Example make install command:
          #$(_v) $(MAKE) -C $(BuildDirectory)/$(Project) $(Environment) install

    This Makefile includes the "Common.make" file, which sets up a bunch of the make rules you'll need, but it does not setup the build or install targets. These are the two targets you'll need to implement in your Makefile for the build system to work correctly.

You will run into problems when trying to get the build system to work. There are a couple of things you'll need to remember. First, you cannot modify the source. Second, you're building in a directory separate from where the source lives. The latter will often cause problems because Makefile variables are setup expecting to be built in the source directory. If it is a simple matter of Makefile variables, you can override them with the Extra_Environment variable in the wrapper Makefile.