commit b6160e034f66588dae324311d7e46426cff839da Author: Mikolaj Golub Date: Sat Jan 25 20:05:06 2014 +0200 Make dtrace(1) generate header files so that the same sources can be built either with or without dtrace probes, depending on if WITH_DTRACE is defined. diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_program.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_program.c index a325c42..b413077 100644 --- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_program.c +++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_program.c @@ -560,7 +560,8 @@ dt_header_provider(dtrace_hdl_t *dtp, dt_provider_t *pvp, FILE *out) dt_header_fmt_func(info.dthi_pfname, pvp->pv_desc.dtvd_name); #ifdef __FreeBSD__ - if (fprintf(out, "#include \n\n") < 0) + if (fprintf(out, + "#ifdef WITH_DTRACE\n#include \n#endif\n\n") < 0) return (dt_set_errno(dtp, errno)); #endif if (fprintf(out, "#if _DTRACE_VERSION\n\n") < 0) commit 4606de45452f4bfed72d6afe4f24906e77dde69a Author: Mikolaj Golub Date: Sun Jul 14 20:47:05 2013 +0300 Improvements to bsd.dtrace.mk: - Make makefiles that include bsd.dtrace.mk work when WITH_DTRACE is not defined. - Make it work with DTRACEOBJS containing any number of files. - Make it work when OBJDIR is not current directory. - Force removing old dtrace objects before generating new ones, as dtrace(1) refuses to rewrite them. - Make possible to specify additional dtrace(1) options (e.g. directory paths) via DTRACEFLAGS. diff --git a/share/mk/bsd.dtrace.mk b/share/mk/bsd.dtrace.mk index 518de30f..4c5469d 100644 --- a/share/mk/bsd.dtrace.mk +++ b/share/mk/bsd.dtrace.mk @@ -32,29 +32,34 @@ # You must include this file before bsd.lib.mk or bsd.prog.mk. # -.if defined(WITH_DTRACE) +DTRACEHEADERS= ${DTRACEOBJS:S/o$/h/} +DTRACESRCS= ${DTRACEOBJS:S/o$/d/} +CLEANFILES+= ${DTRACEHEADERS} -CFLAGS+=-DWITH_DTRACE -DTRACEHEADERS=${DTRACEOBJS:S/o$/h/} -DTRACESRCS=${DTRACEOBJS:S/o$/d/} -CLEANFILES+=${DTRACEOBJS} ${DTRACEHEADERS} +.for _DH in ${DTRACEHEADERS} +${_DH}: ${_DH:R}.d + ${DTRACE} ${DTRACEFLAGS} -C -h -s ${.ALLSRC} +.endfor -DPADD+=${LIBELF} -LDADD+=-lelf +beforedepend: ${DTRACEHEADERS} -.if defined(PROG) -_DTRACELINKING=${OBJS} -OBJS+=${DTRACEOBJS} -.else -_DTRACELINKING=${SOBJS} -SOBJS+=${DTRACEOBJS} -.endif +CFLAGS+= -I${.OBJDIR} + +.if defined(WITH_DTRACE) + +CFLAGS+= -DWITH_DTRACE +CLEANFILES+= ${DTRACEOBJS} + +DPADD+= ${LIBELF} +LDADD+= -lelf ${DTRACEOBJS}: -beforedepend: - ${DTRACE} -C -h -s ${DTRACESRCS} -beforelinking: - ${DTRACE} -G -s ${DTRACESRCS} ${_DTRACELINKING:S/${DTRACEOBJS}//} +beforelinking: ${DTRACESRCS} +.if !empty(DTRACESRCS) + @rm -f ${DTRACEOBJS} + ${DTRACE} ${DTRACEFLAGS} -G ${.ALLSRC:M*.d:S/^/-s /} \ + ${.ALLSRC:N*.d:tW:S/${DTRACEOBJS}//} +.endif .endif