# Oracle Linux DTrace.
# Copyright (c) 2011, 2025, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at
# http://oss.oracle.com/licenses/upl.

TEST_UTILS = workload_kernel workload_user showUSDT print-stack-layout
TEST_SCRIPTS = check_result.sh clean_probes.sh cpc_get_events.sh cpc_temp_skip_bug.sh perf_count_event.sh workload_analyze_loop.sh workload_get_iterations.sh get_remote.sh

define test-util-template
CMDS += $(1)
$(1)_DIR := $(current-dir)
$(1)_TARGET = $(1)
$(1)_SOURCES = $(1).c
$(1)_POST := link-test-util
$(1)_CFLAGS := -Ilibdtrace -Ilibproc -Ilibcommon
$(1)_NOCFLAGS := --coverage
$(1)_NOLDFLAGS := --coverage
$(1)_DEPS = libdtrace.so
$(1)_LIBS = -L$(objdir) -ldtrace

clean::
	rm -f test/utils/$(1)
endef

define link-test-util
	rm -f test/utils/$(notdir $(1))
	ln -s $(1) test/utils/$(notdir $(1))
endef

$(foreach util,$(TEST_UTILS),$(eval $(call test-util-template,$(util))))

# The showUSDT utility needs to be linked against libelf, and should not be
# linked against libdtrace.
showUSDT_DEPS = libcommon.a
showUSDT_LIBS = -lelf -L$(objdir) -lcommon

# The print-stack-layout utility needs dt_impl.h which needs dt_git_version.h.
print-stack-layout_SRCDEPS := $(objdir)/dt_git_version.h

# Install the showUSDT utility in $(DOCDIR); do not count on this utility to
# always be present --- it is only included there to assist in early debugging of
# the (semi-new) USDT feature.
install::
	mkdir -p $(INSTDOCDIR)
	$(call describe-install-target,$(INSTDOCDIR),showUSDT)
	install -m 755 test/utils/showUSDT $(INSTDOCDIR)

install-test::
	$(call describe-install-target,$(INSTTESTDIR)/test/utils,$(TEST_UTILS) $(TEST_SCRIPTS) include-test.d libctf.r.p)
	mkdir -p $(INSTTESTDIR)/test/utils
	install -m 755 $(addprefix test/utils/,$(TEST_UTILS)) $(INSTTESTDIR)/test/utils
	install -m 755 $(addprefix test/utils/,$(TEST_SCRIPTS)) $(INSTTESTDIR)/test/utils
	install -m 644 test/utils/include-test.d $(INSTTESTDIR)/test/utils
	install -m 755 test/utils/libctf.r.p $(INSTTESTDIR)/test/utils
