I've been asking around for the best way to use ccache within
OpenBSD ports.  It seems everyone has a different way of doing
it, and what follows is maybe the simplest.

For those who don't know, devel/ccache is a compiler cache that
significantly speeds up the sometimes unavoidable make ; make
clean ; make cycle when working on a port.

So, the idea is a module, ccache, and a ccache.port.mk like so:

CCACHE_DIR?=    "${WRKDIR}/ccache"

BUILD_DEPENDS+= ::devel/ccache

CONFIGURE_ENV+= CCACHE_DIR="${CCACHE_DIR}" \
                CC="ccache ${CC}" \
                CXX="ccache ${CXX}"

MAKE_ENV+=      CCACHE_DIR="${CCACHE_DIR}"

Putting the ccache dir within the WRKDIR is pretty much useless,
since it gets wiped out on a make clean, but it needs to be set
to something or the build will just fail.  The best idea was
making it a subdirectory of TMPDIR; that way no systrace filter
modification is required.

So, this way, to use ccache on your port you only need to add
this ccache.port.mk into /usr/ports/infrastructure/mk and add a
few lines to your port like this:

MODULES=ccache
TMPDIR=/usr/obj
CCACHE_DIR=${TMPDIR}/ccache

Or, you can put your TMPDIR and CCACHE_DIR in your /etc/mk.conf
and only have to add and remove the MODULES entry while working
on a port.

I hope this makes anyone's porting experience less painful, and
thank you, people who helped me with it.  :-)


Reply via email to