Creating FreeBSD packages from ports

A python vulnerability made it necessary for me to upgrade the python installation on FreeBSD. Since this would have to be performed on three machines, I decided to built the port on my fastest hardware, then create a package of it for installation on the two slow machines.

First, I had to update the ports tree:

  csup -g -L 2 /usr/local/etc/cvsup/ports-supfile

There is a standard make target for ports, package, which will create a package from the installed port. So I used the following sequence of commands:

  # cd /usr/ports/lang/python25
  # make clean
  # make
  # make deinstall
  # make reinstall
  # make package

The created package can then be installed by:

  pkg_add python25-2.5.2_2.tbz

on the target machine. The same effect can be achieved using the pkg_create command, e.g.

  pkg_create -jb python25-2.5.2_2

However, the make package command resulted in the following error:

  Creating bzip'd tar ball in '/usr/ports/lang/python25/python25-2.5.2_2.tbz'
  tar: lib/python2.5/lib-dynload/nis.so: Cannot stat: No such file or directory
  tar: Error exit delayed from previous errors.
  pkg_create: make_dist: tar command failed with code 256
  *** Error code 1

  Stop in /usr/ports/lang/python25.

The error was due to two factors: (a) I set NO_NIS="true" in /etc/make.conf, and (b) I had an old copy of /usr/bin/ypcat on my machine. This triggered the following code in the python Makefile:

  .if !exists(/usr/bin/ypcat) # the world with NO_NIS 
  PLIST_SUB+= NO_NIS="@comment "
  .else
  PLIST_SUB+= NO_NIS=""
  .endif

This code then ignores the /etc/make.conf NO_NIS setting. One easy fix was to delete /usr/bin/ypcat. Maybe a better fix would be to change the Makefile to obey the setting in /etc/make.conf. Something like:

  .if  !exists(/usr/bin/ypcat) || ${NO_NIS} != "" # the world with NO_NIS
  PLIST_SUB+= NO_NIS="@comment "
  .else
  PLIST_SUB+= NO_NIS=""
  .endif

Producing the following unified diff:

  --- Makefile            2008-04-27 13:35:47.000000000 +0100
  +++ Makefile.new        2008-04-27 13:35:33.000000000 +0100
  @@ -104,7 +104,7 @@
  CFLAGS+=        -DPYTHON_DEFAULT_RECURSION_LIMIT=900
  .endif
  
  -.if  !exists(/usr/bin/ypcat) # the world with NO_NIS
  +.if  !exists(/usr/bin/ypcat) || ${NO_NIS} != "" # the world with NO_NIS
  PLIST_SUB+=    NO_NIS="@comment "
  .else
  PLIST_SUB+=    NO_NIS=""

Once this change is made in the Makefile, the port must be re-built so that the package list reflects the absence of NIS.

I see from the FreeBSD PR database that this problem has already been reported in ports/119440 and ports/115940. One less job to do.