Wednesday, December 7, 2022

NetBSD pkgsrc on Solaris 10/sparc

Anyone who still has a fondness for pre-Oracle Solaris knows the hell that is getting a functional C compiler installed and building common open source packages. One common way to deal with this problem, if you want up-to-date packages, is to use the pkgsrc collection, from the NetBSD project.

pkgsrc has been around for quite some time, having been forked from FreeBSD's ports collection in the late 1990s. Solaris support (initially termed "zoularis", for the initial build script creator, Christos Zoulas) was added just before the new millennium.

The theory is that pkgsrc is easy to get going, and the basic tasks needed are:

  1. download pkgsrc.tar.gz from NetBSD
  2. extract to /usr/pkgsrc
  3. cd to /usr/pkgsrc/bootstrap
  4. run ./bootstrap

Under Solaris 10, though, the system doesn't come with a functional C compiler, making the process a bit of a chicken and egg problem. After doing quite a bit of research, and digging through a lot of blogs, here is the process that worked for me:

  • using the Sun-supported SFW gcc 3.4 and related tools, install a newer version of gcc
    • Set your path to include /usr/sfw/bin and /usr/ccs/bin
# export PATH=/usr/sbin:/usr/bin:/usr/sfw/bin:/usr/ccs/bin
    • I used gcc-9.3.0, which is apparently the final version that supports Solaris 10
# gtar zxvf gcc-9.3.0.tar.gz
# mkdir objdir
# cd objdir
# ~/gcc-9.3.0/configure --enable-obsolete --prefix=/op
t/gcc-9.3.0 --enable-languages=c,c++,fortran

# gmake
# gmake install
    • Add the gcc library directories to the runtime linker paths with crle
# crle -u -l /opt/gcc-9.3.0/lib
# crle -64 -u -l /opt/gcc-9.3.0/lib/sparcv9
    • Grab pkgsrc, I used current stable, which is at the moment 2022-Q3
    • Extract to /usr/pkgsrc
    • Bootstrap pkgsrc
# cd /usr/pkgsrc/bootstrap
      • set your path to include your new gcc and the /usr/ccs/bin tools, like ar, nm and friends and remove /usr/sfw
# export PATH=/usr/sbin:/usr/bin:/opt/gcc-9.3.0/bin:/usr/ccs/bin
# env CFLAGS=-O2 ./bootstrap
    • Once this is complete, add pkgsrc tools to your path
# export PATH=/usr/pkg/sbin:/usr/pkg/bin:/usr/sbin:/usr/bin:/opt/gcc-9.3.0/bin:/usr/ccs/bin
    • Edit your pkgsrc mk.conf to use the gcc version that you built
      • Add the following lines to /usr/pkg/etc/mk.conf:
GCCBASE=                /opt/gcc-9.3.0
USE_NATIVE_GCC=         yes
 
 
Now, you should be able to use the NetBSD pkgsrc collection to build a create variety of useful software on Solaris 10.