[DTrace-devel] [PATCH v3 RE-REVIEW NEEDED] build: support kernel builds with or without object directory
Kris Van Hees
kris.van.hees at oracle.com
Wed Nov 8 16:27:33 UTC 2023
It should be possible to build DTrace against kernel headers provided in
a variety of ways. They can be provided as installed kernel header
packages with combined or separated generated and standard headers, and
linked from /lib/modules/<kernelv-version> or simply available as
directory hierarchies elsewhere on the system.
It should also be possible to build DTrace against kernel headers that
are found in a locally built kernel, whether it is installed or not.
This patch provides a cleanup for the build system to accomplish this
with minimal configuration.
Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
Reviewed-by: Nick Alcock <nick.alcock at oracle.com>
---
GNUmakefile | 21 ++++++++++++++-------
libdtrace/Build | 21 ++++++++++-----------
2 files changed, 24 insertions(+), 18 deletions(-)
diff --git a/GNUmakefile b/GNUmakefile
index 54a3c48c..2ffd4c49 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -3,7 +3,7 @@
# Build files in subdirectories are included by this file.
#
# Oracle Linux DTrace.
-# Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2023, 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.
@@ -65,12 +65,19 @@ UNPRIV_HOME ?= /run/initramfs
# pathnames), and about the pieces of the pathname before and after the kernel
# version (so it can build include paths).
-KERNELS=$(shell uname -r)
-KERNELDIRPREFIX=/lib/modules
-KERNELODIR=
-# This allows you to build using a locally installed kernel built with O= by
-# just specifying KERNELODIR=relative/path/to/your/kernel/o/dir.
-KERNELDIRSUFFIX=$(if $(KERNELODIR),/source,/build)
+# Headers for installed kernels should be found automatically by the build
+# logic. For local builds, one should specify KERNELSRCDIR as the source
+# location of the kernel tree, and KERNELOBJDIR as the location of the object
+# tree. If the kernel was built within the source tree, KERNELOBJDIR need not
+# be specified.
+
+KERNELS = $(shell uname -r)
+KERNELMODDIR = /lib/modules
+
+ifdef KERNELSRCDIR
+KERNELOBJDIR ?= $(KERNELSRCDIR)
+endif
+
KERNELARCH := $(subst sparc64,sparc,$(subst aarch64,arm64,$(subst x86_64,x86,$(ARCH))))
# Paths.
diff --git a/libdtrace/Build b/libdtrace/Build
index 7dc2d5d6..7149a06b 100644
--- a/libdtrace/Build
+++ b/libdtrace/Build
@@ -166,6 +166,8 @@ $(objdir)/dlibs/.dir.stamp:
define dlib-kernel-ver-template
$(objdir)/dlibs/$(shell printf %s $(1) | sed -e 's/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*$$/\1.\2.\3/')/%.d: override SHORTKERNELVER := $(shell printf %s $(1) | sed -e 's/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*$$/\1.\2.\3/' | awk -F. '{ print $$1 * 1000 * 1000 + $$2 * 1000 + $$3 }')
$(objdir)/dlibs/$(shell printf %s $(1) | sed -e 's/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*$$/\1.\2.\3/')/%.d: override KERNELVER := $(1)
+$(objdir)/dlibs/$(shell printf %s $(1) | sed -e 's/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*$$/\1.\2.\3/')/%.d: override KERNELSRCDIR ?= $(KERNELMODDIR)/$(1)/source
+$(objdir)/dlibs/$(shell printf %s $(1) | sed -e 's/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*$$/\1.\2.\3/')/%.d: override KERNELOBJDIR ?= KERNELMODDIR)/$(1)/build
endef
$(foreach kernel,$(KERNELS),$(eval $(call dlib-kernel-ver-template,$(kernel))))
@@ -178,17 +180,14 @@ $(m4-dlib-targets): $(objdir)/dlibs/%.d: $$(foreach name,$$(notdir %.d.in), \
$(objdir)/dlibs/.dir.stamp
$(call describe-target,M4,$<)
$(PREPROCESS) -P -x c -Ilibdtrace/$(ARCHINC) \
- -I$(KERNELDIRPREFIX)/$(KERNELVER)$(KERNELDIRSUFFIX)/arch/$(KERNELARCH)/include \
- $(if $(KERNELODIR),-I$(KERNELDIRPREFIX)/$(KERNELVER)$(KERNELDIRSUFFIX)/$(KERNELODIR)/arch/$(KERNELARCH)/include/generated/uapi) \
- -I$(KERNELDIRPREFIX)/$(KERNELVER)$(KERNELDIRSUFFIX)/$(KERNELODIR)/arch/$(KERNELARCH)/include/generated/uapi \
- $(if $(KERNELODIR),-I$(KERNELDIRPREFIX)/$(KERNELVER)$(KERNELDIRSUFFIX)/$(KERNELODIR)/arch/$(KERNELARCH)include/generated) \
- -I$(KERNELDIRPREFIX)/$(KERNELVER)$(KERNELDIRSUFFIX)/$(KERNELODIR)/arch/$(KERNELARCH)/include/generated \
- $(if $(KERNELODIR),-I$(KERNELDIRPREFIX)/$(KERNELVER)$(KERNELDIRSUFFIX)/$(KERNELODIR)/include) \
- -I$(KERNELDIRPREFIX)/$(KERNELVER)$(KERNELDIRSUFFIX)/include \
- -I$(KERNELDIRPREFIX)/$(KERNELVER)$(KERNELDIRSUFFIX)/arch/$(KERNELARCH)/include/uapi \
- $(if $(KERNELODIR),-I$(KERNELDIRPREFIX)/$(KERNELVER)$(KERNELDIRSUFFIX)/$(KERNELODIR)/include/generated/uapi) \
- -I$(KERNELDIRPREFIX)/$(KERNELVER)$(KERNELDIRSUFFIX)/$(KERNELODIR)/include/generated/uapi \
- -I$(KERNELDIRPREFIX)/$(KERNELVER)$(KERNELDIRSUFFIX)/include/uapi \
+ -I$(KERNELSRCDIR)/arch/$(KERNELARCH)/include \
+ -I$(KERNELOBJDIR)/arch/$(KERNELARCH)/include/generated/uapi \
+ -I$(KERNELOBJDIR)/arch/$(KERNELARCH)/include/generated \
+ -I$(KERNELOBJDIR)/include \
+ -I$(KERNELSRCDIR)/include \
+ -I$(KERNELSRCDIR)/arch/$(KERNELARCH)/include/uapi \
+ -I$(KERNELOBJDIR)/include/generated/uapi \
+ -I$(KERNELSRCDIR)/include/uapi \
-D_KERNEL -D__KERNEL__ $(basename $(basename $<)).m4 2>$@.h.err | grep -v '^# [0-9]' | tee $@.h | \
m4 --prefix-builtins -DSUBST_KERNEL=$(SHORTKERNELVER) -DSUBST_ARCH=$(KERNELARCH) $(libdtrace-build_DIR)def-start.m4 \
$(libdtrace-build_DIR)def-replace.m4 - $(libdtrace-build_DIR)/d-subst.m4 \
--
2.40.1
More information about the DTrace-devel
mailing list