Compiling Solaris Software
Since everything we compile is packaged now, you should take care when placing anything in /usr/local. Please follow these instructions in their entirety, and report any problems or inaccuracies to me (nate).
Important notes, before you start
For the purposes of this document, we'll use CSEreadline (the GNU Readline library) as an example.
If the software uses GNU Autoconf (which most stuff does), this will help you greatly. If not, you need to configure the software to install to some temporary location (such as /var/tmp/readline, in our example). Dealing with non-autoconf software is outside the scope of this document, though, and you should probably talk to me if you have questions (especially about how to package said software).
Environment
It's a good idea to set up your environment as follows:
setenv CC "/opt/SUNWspro/bin/cc"
setenv CXX "/opt/SUNWspro/bin/CC"
setenv CPP "/opt/SUNWspro/bin/cc -E"
setenv F77 "/opt/SUNWspro/bin/f77"
setenv CFLAGS "-O -g -I/usr/local/include -I/usr/sfw/include"
setenv CPPFLAGS "-I/usr/local/include -I/usr/sfw/include"
setenv CXXFLAGS "-I/usr/local/include -I/usr/sfw/include"
setenv LDFLAGS "-L/usr/sfw/lib -R/usr/sfw/lib -L/usr/local/lib -R/usr/local/lib"
unsetenv LD_LIBRARY_PATH
ALWAYS ALWAYS ALWAYS ALWAYS ALWAYS unsetenv LD_LIBRARY_PATH. LD_LIBRARY_PATH IS EVIL! Using LDFLAGS as above will negate the need for LD_LIBRARY_PATH.
The above configures your environment to use the Sun compilers and will generally find all libraries you may need.
The Source Tree
The source tree lives in /export/src on neuromancer (note to self: this will change soon).
Find a semi-appropriate location in this tree to place your source (if you're upgrading already-installed software, this location will already exist). For example, gcc goes in /export/src/devel/gcc. It's not a cut-and-dry science, so if you're not sure, just stick it somewhere that seems reasonable.
Make sure you do this as yourself. Usually what I do is make sure the parent directory is owned by myself or at least writable by group staff. Always build software as yourself, never as root. If anyone wants to muck with your source later, they can chown it.
New Software
If this is new software, it goes something like this:
% cd /export/src/GNU
% sudo mkdir readline
% sudo chown nate:staff readline
Upgrading Software
If you're upgrading software, there should be old source in the directory. I keep 1 old version of the source around:
% cd /export/src/GNU/readline
% ls
pkg/
readline-4.3/
readline-4.3.tar.gz
readline-5.0/
readline-5.0.tar.gz
To keep things clean, go ahead and remove the oldest version:
% sudo rm -rf readline-4.3*
If you're recompiling the same version, keep the old source for reference by renaming the source directory. You don't need to do this if you're getting a new version of the software that won't clobber the current version:
% mv readline-5.0 readline-5.0.old
If the previous maintainer had to do anything special, or had an excruciatingly difficult time compiling the software, they have hopefully left notes for you in CSE.README or a similar file. Be sure to read this, if it exists.
Both
Untar your source:
% tar zxvf readline-5.0.1.tar.gz
% cd readline-5.0.1
Read the README, INSTALL, and any other files that look like they may pertain to successful building under Solaris:
% less README
% less INSTALL
Configuring, Building
I usually check './configure --help' to see if there are any libraries that we have installed that we can link the software too. This hopefully increases it's usefulness. For example, here's some interesting bits from './configure --help' in the teTeX source:
--with-libwww=DIR Specify path to W3C Reference Library distribution.
Meaning that if I were to run './configure --with-libwww', it would compile in support for libwww. This is probably a good thing.
Upgrading Software
Check out the old version's source and review the top of config.status or config.log (e.g. 'head config.foo'). In one of those two will be the invocation of './configure' that was used to configure the software last time. Using this, you can ensure that you configure the new version with the same options:
% head /export/src/GNU/readline/readline-5.0/config.log
% head /export/src/GNU/readline/readline-5.0/config.status
look for:
Invocation command line was
$ ./configure
So in this case, './configure' was run with no special arguments.
Both
Proceed with the usual:
% cd /export/src/GNU/readline/readline-5.0.1
% ./configure ARGS
% make
Pre-Packaging
Before you 'make install':
% umask 022
We're going to install into a temporary directory for packaging purposes. Make sure /var/tmp/readline doesn't exist from an old installation.
% make DESTDIR=/var/tmp/readline install
The value of DESTDIR is prepended to the installation path and installed at that path (i.e. it will be installed in /var/tmp/readline/usr/local).
You can now create the appropriate package components:
% cd /var/tmp/readline/usr/local
% sudo tcsh
# /bin/chown -Rh root:root *
# find . | pkgproto > /usr/local/prototype
If installing new software:
# cp /export/src/pkginfo-template /usr/local/pkginfo
If upgrading existing software:
# cp /export/src/GNU/readline/pkg/CSEreadline/pkginfo /usr/local
Edit the pkginfo file to contain information about the software you're installing. I use 'CSE' as the base for all our package names, (i.e. CSErxvt or CSEgcc):
# vi /usr/local/pkginfo
PSTAMP=you 01.23.2005
VERSION=5.0.1
PKG=CSEreadline
NAME=GNU Readline
DESC=A library which provides a set of functions for use by applications that allow users to edit command lines as they are typed in.
Stuff below the "DESC" line shouldn't need to be changed.
Edit the prototype file and add a line containing 'i pkginfo' to the top of the file:
# vi prototype (and insert:)
i pkginfo
If there's an entry for the 'prototype' file itself in 'prototype', remove that line. Also, remove any line containing the 'info/dir' file, as this is a dynamic file.
Installation, Packaging
# cd /export/src/GNU/readline/readline-5.0.1
# umask 022
# make install
Package up the software from it's installed location in /usr/local:
# cd /usr/local
# pkgmk -r . -d /var/tmp
You should now have a directory with the same name as your package (i.e. /var/tmp/CSEreadline) in /var/tmp. I typically create a pkg directory one directory up from where I untarred the source and move the package there.
# cd /export/src/GNU/readline
# mkdir pkg
# mv /var/tmp/CSEreadline pkg
Even though the software is now fully installed in /usr/local, you have to use pkgadd for the package to actually be installed into Solaris' package database (i.e. what you see when you execute 'pkginfo'):
# cd /export/src/GNU/readline/pkg
# pkgadd -d . CSEreadline
And assuming that went okay, clean up:
# rm -rf /var/tmp/readline
# rm /usr/local/prototype /usr/local/pkginfo