pkgsrc survival guide
Contents
pkgsrc is NetBSD's ports system. But it's also cross-platform, available on Mac and Linux. It also support unprivileged use. This is a quick reference for it.
First let's make a few decisions about the installation locations:
1 | # Location of the pkgsrc |
BOOTSTRAPPING
First download pkgsrc - it's a collection of configurations instructing how to download and build different packages.
1 | wget https://ftp.netbsd.org/pub/pkgsrc/stable/pkgsrc.tar.gz |
pkgsrc needs to be bootstrapped on the target machine where packages are to be built. The bootstrapping process builds the necessary tools pkgsrc will be using later on. We will focus on unprivileged use, since that's more fun and less covered by documents everywhere else:
1 | cd $PKGSRC_DIR/bootstrap |
Finally we need to export PATH
and MANPATH
to include $PKG_DIR
.
PARALLEL BUILD
1 | MAKE_JOBS=<num_cpus> bmake |
USEFUL TARGETS, GETTING HELP
1 | bmake help |
See pkgsrc targets The following targets may be useful to invoke from keyboard:
depends
to build and install dependenciesfetch
to fetch distribution file(s)checksum
to fetch and check distribution file(s)extract
to look at unmodified sourcepatch
to look at initial sourceconfigure
to stop after configure stageall
or build to stop after build stagestage
-install to install under stage directorytest
to run package's self-tests, if any exist and supportedpackage
to create binary package before installing itreplace
to change (upgrade, downgrade, or just replace) installed package in-placedeinstall
to deinstall previous packagepackage
-install to install package and build binary packageinstall
to install packagebin-install
to attempt to skip building from source and use pre-built binary packageshow-depends
print dependencies for buildingshow-options
print available options from options.mk
Cleanup targets (in separate section because of importance):
clean
-depends to remove work directories for dependenciesclean
to remove work directorydistclean
to remove distribution file(s)package-clean
to remove binary package
The following targets are useful in development and thus may be useful for an advanced user:
makesum
to fetch and generate checksum for distributed file(s)makepatchsum
to (re)generate checksum for patchesmakedistinfo
to (re)generate distinfo file (creating checksums for distributed file and patches)mps
short for makepatchsummdi
short for makedistinfoprint-PLIST
to attempt to generate correct packaging list (NB! It helps, but it doesn't eliminate manual work.)
USEFUL PKG TOOLS
1 | (cd pkgtools && bmake install) |
DISTFILES, FETCHING ETC
1 | # generate sh script which downloads distfiles when run |
BUILD OPTIONS
$PKG_DIR/etc/mk.conf
is where to set build options. For specific package, add line:
1 | PKG_OPTIONS.<pkg_name>+= <option> |
bmake show-all
is helpful in discovering available build options, and what are enabled/disabled.
USEFUL ENVIRONMENT VARS
These can be specified in mk.conf
, or on each build instance:
1 | DISTDIR=... bmake |
DISTDIR
: directory where to look for distfilesFETCH_USING
: the program for fetching (can set to wget)
TROUBLESHOOTING
1 | # Prints detailed build command |
BUILD PHASES
https://www.netbsd.org/docs/pkgsrc/build.html
- The fetch phase
- The checksum phase
- The extract phase
- The patch phase
- The tools phase
- The wrapper phase
- The configure phase
- The build phase
- The test phase
- The install phase
- The package phase
Use pkgsrc along side Joyent pkgsrc binary distribution
Sat May 28 14:58:51 PDT 2022
- Install Joyent's pkgsrc binary distribution (this must be installed at the pre-determined location. E.g., for MacOS, at
/opt/pkg
) - At any location, git clone pkgsrc source repo (e.g., clone into
~/work/pkgsrc
) - To build from source, just
cd ~/work/pkgsrc/net/sshping && bmake install
bmake
is from/opt/pkg/bin
. Installed package will also go there.
Since this installs to system location, there maybe frequent prompt for root
password. Use this patch can fix it. Note that it assumes you have sudo
already installed at /usr/bin/sudo. Otherwise, follow the pkgsrc
FAQ (use pkgsrc to install
sudo
first):
1 | --- /tmp/mk.conf 2022-05-28 15:03:49.000000000 -0700 |
Rebuild only changed files
There's the $WRKDIR/.build_done
cookie that skips build. So:
1 | bmake rebuild |