Anatomy of a FreeBSD port (part 4)

This week’s entry is less of a packaging tutorial and more an example of how silly things can be within the framework.

As mentioned previously, there has been unexpected interest in a port of OpenAFS to FreeBSD. The current state of the git tree is usable for some people, so I might as well throw some packaging around it and make it available for other people to use. Unfortunately, there were a lot of changes since the last released version of OpenAFS (1.5.73), and splitting all those changes into per-file patches would be a fair bit of work for minimal gain. So, instead of using the traditional download-a-tarball-then-patch-it approach, I went for the crazy option of just creating a git checkout in the build directory!

As we recall from previous posts in this series, the build process is fetch–extract–patch–configure–build–install. We’ll need to divert the fetch through patch stages for this to work, and then we should be able to configure, build, and install as usual.

We need to declare a dependency on git to ensure that it will be available during the build:

BUILD_DEPENDS=  git:${PORTSDIR}/devel/git

Then, on to the madness!

do-fetch:
        ${MKDIR} ${WRKDIR}

do-extract:
        @(cd ${WRKDIR} && git clone git://git.openafs.org/openafs.git)

do-patch:

(Yes, the do-patch target has an empty body. This is overkill, but makes it easier to pull in proposed changes from gerrit.openafs.org later, if needed.)
The tree from git doesn’t have a configure script included, but does provide a regen.sh that prepares everything for us:

pre-configure:
        cd ${WRKSRC} && ./regen.sh

The packaging also provides a convenient way to specify some knobs so that ordinary users don’t have to worry about them. For instance, the OpenAFS tree hasn’t produced the appropriate definitions for FreeBSD 8.1 and 9.0 (which aren’t released, yet!), so users of FreeBSD development branches would get a build error otherwise:

.if !defined(AFS_SYSNAME)
.if ${OSVERSION} < 800000
IGNORE= supports FreeBSD 8.0 and later
.endif

AFS_SYSNAME=$(OPENAFS_ARCH)_fbsd_80
.endif

CONFIGURE_ARGS= --prefix=${PREFIX} \
        --localstatedir=/var \
        --with-bsd-kernel-build=/usr/obj/usr/src/sys/GENERIC \
        --enable-debug \
        --enable-debug-lwp \
        --with-afs-sysname=${AFS_SYSNAME} \
        --includedir=${PREFIX}/include/openafs \
        --enable-demand-attach-fs \
        --with-krb5 KRB5CFLAGS=-I/usr/include \
        KRB5LIBS='-lkrb5 -lcom_err -lcrypto -lcrypt -lasn1 -lhx509 -lroken' \
                        ${CONFIGURE_TARGET}

(Clever commenters will point out that I should be using krb5-config instead of a hardcoded list of libraries. This is a quick-and-dirty port; clean-up will be done before anything hits the FreeBSD ports tree.)

And that's it! I can point people here, and they can run sh openafs-devel.shar.txt in /usr/ports/net, and then make install away!

Comments are closed.