The basic steps for building a program are always the same. First the program's source (distfile) must be brought to the local system and then extracted. After any patches to compile properly on NetBSD are applied, the software can be configured, then built (usually by compiling), and finally the generated binaries etc. can be put into place on the system. These are exactly the steps performed by the NetBSD package system, which is implemented as a series of targets in a central Makefile, /usr/pkgsrc/mk/bsd.pkg.mk.
Before outlining the process performed by the NetBSD package system in the next section, here's a brief discussion on where programs are installed, and which variables influence this.
The automatic variable PREFIX indicates where all files of the final program shall be installed. It is usually set to $LOCALBASE (/usr/pkg), or $CROSSBASE for pkgs in the cross category, though its value becomes that of $X11BASE if USE_IMAKE, USE_MOTIF, or USE_X11BASE is set. The value ${PREFIX} needs to be put into the various places in the program's source where paths to these files are encoded; see sections patches/* and Shared libraries - libtool for details on this.
When choosing which of these variables to use, follow the following rules:
${PREFIX} always points to the location where the current package will be installed. When referring to a package's own installation path, use ${PREFIX}.
${LOCALBASE} is where all non-X11 pkgs are installed. If you need to construct a -I or -L argument to the compiler to find includes and libraries installed by another non-X11 pkg, use ${LOCALBASE}.
${X11BASE} is where the actual X11 distribution is installed. When looking for standard X11 includes (not those installed by a pkg), use ${X11BASE}.
X11 based pkgs are special in that they may be installed in either X11BASE or LOCALBASE. To install X11 packages in LOCALBASE, simply install the xpkgwedge package (pkgsrc/pkgtools/xpkgwedge). If you need to find includes or libraries installed by a pkg that has USE_IMAKE, USE_MOTIF, or USE_X11BASE in its pkg Makefile, you need to use both ${X11BASE} and ${LOCALBASE}.
${X11BASE} points to the root of the installed X11 tree. To refer to the installed location of an X11 package, use the ${X11PREFIX} definition (this will be ${LOCALBASE} if xpkgwedge is installed, and ${X11BASE} if not).