From a9c1939eeb36372872f3258a9ae7259a564332c3 Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Sun, 22 Dec 2019 00:43:07 -0600 Subject: [PATCH] FBSD: Use GENERIC kernel headers by default Currently, if --with-bsd-kernel-build is not specified during configure, we do not set KERNBUILDDIR during the libafs build at all. This means that we do not use an opt_global.h during the build. For the GENERIC kernel, in the past this has worked well enough to produce a working kernel module, but with FreeBSD 12, the GENERIC kernel turns on the VIMAGE option by default. If our kernel module is built without VIMAGE defined, our kernel module cannot be loaded into GENERIC, since VIMAGE changes the definitions of some symbols that we use (for example, trying to load such a libafs fails with the message "link_elf_obj: symbol in_ifaddrhead undefined"). To allow the build to work by default for GENERIC kernels, without needing any additional configure flags, change the libafs Makefile to use the headers for the GENERIC kernel if no kernel build dir is given. To do this, we create a directory in our build tree and generate the opt_*.h headers in there (using config(8)), and specify that directory as the kernel build dir. This approach only works for GENERIC kernels, of course, but that is the most common scenario. Users that want to build for a custom kernel configuration still need to specify the actual kernel build dir with --with-bsd-kernel-build. Change-Id: If716d3f8ded9596d8e5e98bf2e58888921fc5f7f Reviewed-on: https://gerrit.openafs.org/14001 Tested-by: BuildBot Reviewed-by: Benjamin Kaduk --- src/libafs/MakefileProto.FBSD.in | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/libafs/MakefileProto.FBSD.in b/src/libafs/MakefileProto.FBSD.in index be7d2708e1..8a2a369e7f 100644 --- a/src/libafs/MakefileProto.FBSD.in +++ b/src/libafs/MakefileProto.FBSD.in @@ -60,13 +60,33 @@ WARNS= 1 # We have some sketchy code that redeclares prototypes CWARNFLAGS+= -Wno-redundant-decls +GEN_KBLD_DIR=@abs_builddir@/kconf-GENERIC +AFS_OS_CLEAN=$(GEN_KBLD_DIR) + +# Starting with FreeBSD 12, opt_global.h is effectively required to build, even +# for the GENERIC kernel. Normally this would be provided in the kernel build +# dir (--with-bsd-kernel-build). If that dir was not specified, we can still +# get the needed header files if we assume that the user is building for the +# GENERIC kernel. So if we don't have a kernel build dir, generate the header +# files in GEN_KBLD_DIR by using config(8), and specify that as the +# KERNBUILDDIR. This won't always work, of course, but it has a chance at +# working for the most common setups (when the user isn't using some custom +# kernel). The kernel headers, of course, we assume are in $(KSRC). +$(GEN_KBLD_DIR): + -mkdir $(GEN_KBLD_DIR) + cd $(KSRC)/$(MACHINE)/conf && \ + /usr/sbin/config -d $(GEN_KBLD_DIR) GENERIC + # setup for bsd.kmod.mk infrastructure .PATH: ${TOP_SRCDIR}/afs/FBSD KMODDIR=/boot/modules KERN_DEBUGDIR=/usr/lib/debug KMOD= libafs SYSDIR= ${KSRC} -.if !empty(KBLD) + +.if empty(KBLD) +KERNBUILDDIR=$(GEN_KBLD_DIR) +.else KERNBUILDDIR=${KBLD} .endif @@ -83,7 +103,7 @@ DESTDIRS = single_destdir # generating headers and objects in this directory, which we want in $(KOBJ). # We also need the install target from bsd.kmod.mk in $(KOBJ), but the one # from Makefile.common in this directory. A prime candidate for cleanup. -setup: +setup: $(KERNBUILDDIR) -mkdir $(KOBJ) -$(RM) $(KOBJ)/Makefile $(KOBJ)/Makefile.common $(CP) Makefile $(KOBJ)/Makefile