Examples for pkgsrc-specific mk.conf files
From NetBSD Wiki
This article collects some settings from mk.conf files that are likely to be useful for others. The preferred way to use them is to save each of these code snippets into its own file and to use the .include directive.
Contents |
Strict checks
Set the consistency checks from pkgsrc/mk/check to the strictest version.
# version 1 PKG_DEVELOPER= yes CHECK_FILES_STRICT= yes CHECK_HEADERS= yes CHECK_INTERPRETER= yes CHECK_WRKREF= wrkobjdir
Building packages in quiet mode
When QUIET is set to "yes", the "configure" and "build" phases are pretty quiet. This allows me to better concentrate on the warnings and error messages.
# version 1 QUIET?= no .if !empty(QUIET:M[Yy][Ee][Ss]) . if defined(GNU_CONFIGURE) CONFIGURE_ARGS+= -q . endif MAKE_FLAGS+= -s . if defined(USE_LIBTOOL) LIBTOOL= libtool --quiet . endif .endif
More compiler warnings
The following lines enable almost all of the warnings that can be produced by gcc/g++, just to see how badly some packages' code is. They also give useful hints where to look for security holes in packages. Especially the -Wformat=2 option is very useful here.
# version 2
EXTRA_WARNINGS?= yes
PEDANTIC?= no
.if ${EXTRA_WARNINGS:M[Yy][Ee][Ss]} != ""
_WRAP_EXTRA_ARGS.CC+= -Wall -W -Wno-write-strings -Wno-error
_WRAP_EXTRA_ARGS.CC+= -Wno-unused -Wformat=2 -Wno-long-long
. if ${PEDANTIC:M[Yy][Ee][Ss]} != ""
_WRAP_EXTRA_ARGS.CC+= -pedantic
. endif
_WRAP_EXTRA_ARGS.CXX+= -Wall -W -Wno-error -Wno-unused -fmessage-length=0
.endif
Warning: there are still packages using autoconf2.13, which treats a compilation as failed as soon as there is anything printed on stderr, even if it's only a harmless warning. This often results in mysterious build failures. A good way to check if this has just happened is to see whether the macro STDC_HEADERS is defined in the config.h files (it should always be).
Packages that fail using these settings
- many packages that use autoconf2.13, since that assumes that a compilation failed as soon as there is any warning printed to stderr.
- chat/fugu
Overriding the user and group in unprivileged mode
There are many packages in pkgsrc that require a unique user/group, as they are usually network servers or other daemons. Since the variables follow a consistent naming scheme, I could iterate over them in a simple way.
# version 1
UNPRIVILEGED= yes
.for p in \
APACHE CUPS CYRUS HOWL JB LIGHTTPD MAJORDOMO MUNIN MYSQL \
NAGIOS NAGIOSADM PRAYER QPOPPER SQUID TINYPROXY USERPPP
${p}_USER= ${BINOWN}
${p}_GROUP= ${BINGRP}
.endfor
Checking whether packages accept user-settable CFLAGS
Many packages, especially those using the GNU autotools, allow the user to specify the flags to the compilers. This is good. On the other hand, many hand-written packages don't allow that. With the following settings, one can check whether the package accepts the user-settable variables.
To check whether a package accepts these flags from the user, just build it and watch the command lines where the compiler is called. They should contain the strings from below. If you cannot see the actual compiler calls (maybe only Compiling foobar.c...), you can still look up the actual calls in the work*/.work.log file.
Care has been taken to use flags that are very unlikely to have an effect on the actual compilation, but it is not perfect. The variables LIBS and LDADD sometimes cause problems because packages assume that they don't contain any -L... options. That's not a bug in the package, because LDFLAGS serves that purpose. The other variables (CPPFLAGS, CFLAGS, CXXFLAGS and LDFLAGS) have caused no problems so far.
# version 1
CPP_PKGNAME= ${PKGNAME:C,[^A-Za-z0-9],_,g}
CPPFLAGS+= -Dpkgsrc_${CPP_PKGNAME}_CPPFLAGS
CFLAGS+= -Dpkgsrc_${CPP_PKGNAME}_CFLAGS
CXXFLAGS+= -Dpkgsrc_${CPP_PKGNAME}_CXXFLAGS
LDFLAGS+= -L/pkgsrc_${CPP_PKGNAME}_LDFLAGS
LIBS+= -L/pkgsrc_${CPP_PKGNAME}_LIBS
LDADD+= -L/pkgsrc_${CPP_PKGNAME}_LDADD
There is a patch that adds checks to the pkgsrc wrappers to see whether all invocations of the compiler can see the CFLAGS, CPPFLAGS and CXXFLAGS.
