HOWTO: build a CSW pkg, the easy way

This page gives a step-by-step case study of building a package for opencsw, on our build machines. It shows the "easy way", using the CSW maintainer scripts [part of the cswutils package], and does not show what to do if you hit difficulties, or need fancy package optimizations.

Alternative method

The instructions on this page will work for builds "anywhere, by anyone", for pretty much any kind of package.

Alternatively if you are already a maintainer, you can choose to use our "GAR" build system to build packages. See the GAR Getting Started web page for information. [The SVN page/site needs to have a new home.... link removed]

If you need to see how to handle adversity, take a look at the GNU grep pkg case study.
In contrast, this walkthrough will package the GNU textutils software.

Note: Due to a bug in the solx86 port of fakeroot somewhere, it will make your prototype file come out better if you start your package building on sparc, and do the build on x86 second.

Home directory layout

The following is a suggested directory structure that you can use for building packages. You dont have to use it, but this walkthrough assumes you are.

Directory tree

$HOME/pkgs/                # maintainer info about software
$HOME/pkgs/textutils/      # maintainer info about specific package
$HOME/src/                 # symlink to /export/medusa/src
$HOME/build/		   # symlink to nice place like /export/medusa/you/build
$HOME/build/textutils-2.1/ # where you will do 'make's of textutils
$HOME/build/textutils-2.1/cswstage  # automatically created directory

You dont have to make the $HOME/src symlink, but it's important to keep source code for current packages in /export/medusa/src, for legal reasons. Please leave them gzipped or bzipped there.

pkginfo - basic package information

Start by making a directory that will hold the long term, persistent information about the package. You will always have to create creating "pkginfo" and "copyright" files.

mkdir ~/pkgs/textutils
cd  ~/pkgs/textutils
[create pkginfo, as follows:]
 PKG=CSWtextutils
 NAME=textutils - GNU text utilities
 VERSION=2.1
 CATEGORY=application
 VENDOR=http://ftp.gnu.org/pub/gnu/textutils/  packaged for CSW by Philip Brown
 HOTLINE=http://www.opencsw.org/bugtrack/
 EMAIL=[yourlogin@opencsw.org]
cd ~/build
gtar zxvf ~/src/textutils-2.1.tar.gz
cd textutils-2.1
cp COPYING ~/pkgs/textutils/copyright

Next, build the sucker. Make sure you do not have LD_LIBRARY_PATH defined from here on in.

export LD_OPTIONS='-R/opt/csw/lib/$ISALIST -R/opt/csw/lib -L/opt/csw/lib'
./configure --prefix=/opt/csw --program-prefix=g

# --program-prefix only needed for GNU stuff that conflicts with system stuff

gmake

You now need to "install" the executables. Without root permissions, you'll need to install them into a "staging area". The easy way to do this is to use the "stagepkg" script, which will also strip the binaries for you, and generate an initial 'prototype' file for you (which determines where binaries get installed to, under /opt/csw). Happily, this is a very simple step:

stagepkg
#
# This will do, amoung other things,
#    "make DESTDIR=$PWD/cswstage install"
#
Some software packages require using a different variable name instead of DESTDIR. Some of them also require use of gmake, to install.
If, for example, the Makefile used INSTALL_ROOT, you can adjust your invocation of stagepkg as follows:
MAKE=gmake stagepkg INSTALL_ROOT=$PWD/cswstage install

Whatever variable is needed instead of DESTDIR, make sure that you specify the FULL PATH to (hence the "$PWD" given to INSTALL_ROOT, above)

prototype file - location of files

You're almost done!
You need to copy the prototype file generated in the above steps, and edit it to clean it up, then put together the final package, as follows:

cd cswstage
 [edit ./prototype, fix ownerships to normally be "root bin",
   and anything else that needs cleanup]
cp prototype ~/pkgs/textutils # comparing with any old one first
cd ~/pkgs/textutils

[Then, depending on whether stagepkg said to use -r or -b, do]
createpkg -r ~/build/textutils-2.1/cswstage
[OR]
createpkg -b ~/build/textutils-2.1/cswstage/opt/csw

It so happens that the output from checkpkg, which gets called by createkpg, shows that some of the executables depend on /opt/csw/lib/libintl.so.2, but we do not have a depend file. Since /opt/csw/lib/libintl.so.2 clearly belongs to another CSW package, we need to create a depend file to mention it.

If you do not already know what package a file belongs to, you can use the following command:

pkgchk -l -p  /opt/csw/lib/libintl.so.2
This tells us it is part of CSWggettext, so create a depend file, with the line
P	CSWggettext
Now edit the prototype file, and add the line:
i depend

A finished prototype file generally looks something like the following:

i pkginfo
i depend
i copyright
d none /opt/csw/bin
f none /opt/csw/bin/someprog
 ....

Now we can run createpkg again:

createpkg -r ~/build/textutils-2.1/cswstage
This time, there are no surprises. We are done creating the package... on this cpu type.

Don't forget the "other" architecture(s) !

Now you get to do it ALL OVER AGAIN, on the other build machine! Copy over the contents of your ~/pkgs/textutils directory to the other machine, and start building.

The good news is, you can normally use the prototype file you just copied over, rather than re-editing the new prototype file generated by stagepkg.

Package submission

If you want some additional in-house testing, [This section is unfortunatley out of date. bug the maintainers list]

When you're satisfied that the package is worthy of public release, copy your finished packages to /home/newpkgs on www.opencsw.org and let Phil know they are ready. (remove them from /testing at this time, if they are there)

Note that Phil will remove them from newpkgs, when they are accepted.

Note #2: If you need to resubmit a package to fix some kind of bug, but it is the same release number as a prior one; you need to differentiate it with an additional ",REV=yyyy.mm.dd" type string, as mentioned in our software build guide