#
# Oracle Linux DTrace.
# Copyright (c) 2011, 2024, 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.

uts_DIR := $(current-dir)

# dtrace.h and dtrace_types.h are unique to this userspace tree, and serve to
# provide the userspace versions of types defined distincty by the kernel.

SYS_HEADERS_INSTALL := common/sys/dtrace.h \
                       common/sys/dtrace_types.h

# sdt*.h are used by programs that contain USDT probes that want to define
# probes by hand rather than using dtrace -h.  SystemTap has another header
# with the same name, so we install these out of the way and provide a
# pkg-config file to pull them in.

PROBE_HEADERS_INSTALL := common/sys/sdt.h \
                         common/sys/usdt.h \
                         common/sys/usdt_gennote.h \
                         common/sys/usdt_internal.h \
                         common/sys/usdt_note_defs.h

# The pkg-config files undergo a few translations with sed before installation.

SHARE_PKG_CONFIG_INSTALL := dtrace.pc dtrace_sdt.pc

install::
	mkdir -p $(INSTINCLUDEDIR)/sys
	$(call describe-install-target,$(INSTINCLUDEDIR)/sys,$(notdir $(SYS_HEADERS_INSTALL)))
	cd $(uts_DIR) && install -m 644 $(SYS_HEADERS_INSTALL) $(INSTINCLUDEDIR)/sys
	mkdir -p $(INSTSDTINCLUDEDIR)/sys
	$(call describe-install-target,$(INSTSDTINCLUDEDIR)/sys,$(notdir $(PROBE_HEADERS_INSTALL)))
	cd $(uts_DIR) && install -m 644 $(PROBE_HEADERS_INSTALL) $(INSTSDTINCLUDEDIR)/sys
	mkdir -p $(INSTPKGCONFIGDIR)
	$(call describe-install-target,$(INSTPKGCONFIGDIR),$(SHARE_PKG_CONFIG_INSTALL))
	for name in $(SHARE_PKG_CONFIG_INSTALL); do \
		(cd $(uts_DIR) && \
		    sed -e 's,@SDTINCLUDEDIR@,$(SDTINCLUDEDIR),g;' \
			-e 's,@INCLUDEDIR@,$(INCLUDEDIR),g;' \
			-e 's,@LIBDIR@,$(LIBDIR),g;' \
			-e 's,@VERSION@,$(VERSION),g;' \
			-e 's,@DTRACE@,$(SBINDIR)/dtrace,g' < \
			$${name}.in > $(INSTPKGCONFIGDIR)/$$name;) \
	done
