?RCS: Copyright (c) 2016 Tony Cook
?RCS:
?RCS: You may distribute under the terms of either the GNU General Public
?RCS: License or the Artistic License, as specified in the README file.
?RCS:
?MAKE:dtraceobject dtracexnolibs: usedtrace dtrace cc ccflags optimize \
		Compile cat rm_try
?MAKE:	-pick add $@ %<
?S:dtraceobject:
?S:	Whether we need to build an object file with the dtrace tool.
?S:.
?S:dtracexnolibs:
?S:	Whether dtrace accepts -xnolibs.  If available we call dtrace -h
?S:	and dtrace -G with -xnolibs to allow dtrace to run in a jail on
?S:	FreeBSD.
?S:.
?F: !perldtrace.h
?T:xnolibs
: Probe whether dtrace builds an object, as newer Illumos requires an input
: object file that uses at least one of the probes defined in the .d file
case "$usedtrace" in
$define)
    case "$dtracexnolibs" in
    $define|true|[yY]*)
        dtracexnolibs=$define
	$dtrace -h -xnolibs -s ../perldtrace.d -o perldtrace.h
	;;
    ' '|'')
        if $dtrace -h -xnolibs -s ../perldtrace.d -o perldtrace.h 2>&1 ; then
	     dtracexnolibs=$define
	     echo "Your dtrace accepts -xnolibs"
	elif $dtrace -h -s ../perldtrace.d -o perldtrace.h 2>&1 ; then
	     dtracexnolibs=$undef
	     echo "Your dtrace doesn't accept -xnolibs"
	else
             echo "Your dtrace doesn't work at all, try building without dtrace support" >&4
	     exit 1
	fi
	;;
    *)
        dtracexnolibs=$undef
	$dtrace -h -s ../perldtrace.d -o perldtrace.h
	;;
    esac
    case $dtracexnolibs in
    $define) xnolibs=-xnolibs ;;
    *) xnolibs= ;;
    esac

    case "$dtraceobject" in
    $define|true|[yY]*)
        dtraceobject=$define
        ;;
    ' '|'')
        $cat >try.c <<EOM
#include "perldtrace.h"
int main(void) {
    PERL_LOADED_FILE("dummy");
    return 0;
}
EOM
        dtraceobject=$undef
        if $cc -c -o try.o $optimize $ccflags try.c \
                    && $dtrace -G $xnolibs -s ../perldtrace.d try.o >/dev/null 2>&1; then
                dtraceobject=$define
            echo "Your dtrace builds an object file"
        fi
        ;;
    *) dtraceobject=$undef ;;
    esac
    $rm_try perldtrace.o perldtrace.h
esac

