Cleanup linux module kbuild files
The linux module can be built either as an external module, or compiled
into the kernel, using copy-builtin. The source and build directories
are slightly different between the two cases, and currently, compiling
into the kernel still refers to some files from the configured ZFS
source tree, instead of the copies inside the kernel source tree. There
is also duplication between copy-builtin, which creates a Kbuild file to
build ZFS inside the kernel tree, and the top-level module/Makefile.in.
Fix this by moving the list of modules and the CFLAGS settings into a
new module/Kbuild.in, which will be used by the kernel kbuild
infrastructure, and using KBUILD_EXTMOD to distinguish the two cases
within the Makefiles, in order to choose appropriate include
directories etc.
Module CFLAGS setting is simplified by using subdir-ccflags-y (available
since 2.6.30) to set them in the top-level Kbuild instead of each
individual module. The disabling of -Wunused-but-set-variable is removed
from the lua and zfs modules. The variable that the Makefile uses is
actually not defined, so this has no effect; and the warning has long
been disabled by the kernel Makefile itself.
The target_cpu definition in module/{zfs,zcommon} is removed as it was
replaced by use of CONFIG_SPARC64 in
commit 70835c5b755e ("Unify target_cpu handling")
os/linux/{spl,zfs} are removed from obj-m, as they are not modules in
themselves, but are included by the Makefile in the spl and zfs module
directories. The vestigial Makefiles in os and os/linux are removed.
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
Closes #10379
Closes #10421
2020-06-08 00:03:12 +03:00
|
|
|
include Kbuild
|
2010-08-26 22:22:58 +04:00
|
|
|
|
2013-02-17 23:05:11 +04:00
|
|
|
INSTALL_MOD_DIR ?= extra
|
2021-10-01 20:44:34 +03:00
|
|
|
INSTALL_MOD_PATH ?= $(DESTDIR)
|
2013-02-17 23:05:11 +04:00
|
|
|
|
2019-09-06 21:26:26 +03:00
|
|
|
all: modules
|
|
|
|
distclean maintainer-clean: clean
|
|
|
|
install: modules_install
|
|
|
|
uninstall: modules_uninstall
|
|
|
|
check:
|
|
|
|
|
Fix tags targets in module/Makefile.in + cleanup
These targets look to have been copied from an automake-generated
Makefile.in, and can't work since none of the auto-generated automake
variables are defined here.
Moreover, ctags has been overridden in the top-level Makefile, so the
target is pointless anyway, and gtags is not a recursive target.
Fix cscopelist by moving it to the top-level Makefile as well, in line
with ctags and etags.
Also, add -a to ctags command as well, otherwise it won't work if more
than one xargs invocation takes place.
Add assembler files to ctags/etags, prune all dotted-dirs, and restrict
the find to files only.
Cleanup: add .PHONY to module/Makefile.in, and fix one recipe with a
missing continuation character.
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
Closes #10493
2020-06-22 05:13:02 +03:00
|
|
|
.PHONY: all distclean maintainer-clean install uninstall check distdir \
|
|
|
|
modules modules-Linux modules-FreeBSD modules-unknown \
|
|
|
|
clean clean-Linux clean-FreeBSD \
|
|
|
|
modules_install modules_install-Linux modules_install-FreeBSD \
|
2021-01-22 23:54:34 +03:00
|
|
|
modules_uninstall modules_uninstall-Linux modules_uninstall-FreeBSD \
|
|
|
|
cppcheck cppcheck-Linux cppcheck-FreeBSD
|
Fix tags targets in module/Makefile.in + cleanup
These targets look to have been copied from an automake-generated
Makefile.in, and can't work since none of the auto-generated automake
variables are defined here.
Moreover, ctags has been overridden in the top-level Makefile, so the
target is pointless anyway, and gtags is not a recursive target.
Fix cscopelist by moving it to the top-level Makefile as well, in line
with ctags and etags.
Also, add -a to ctags command as well, otherwise it won't work if more
than one xargs invocation takes place.
Add assembler files to ctags/etags, prune all dotted-dirs, and restrict
the find to files only.
Cleanup: add .PHONY to module/Makefile.in, and fix one recipe with a
missing continuation character.
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
Closes #10493
2020-06-22 05:13:02 +03:00
|
|
|
|
2021-03-05 23:16:41 +03:00
|
|
|
# For FreeBSD, use debug options from ./configure if not overridden.
|
|
|
|
export WITH_DEBUG ?= @WITH_DEBUG@
|
|
|
|
export WITH_INVARIANTS ?= @WITH_INVARIANTS@
|
|
|
|
|
2020-06-19 20:33:56 +03:00
|
|
|
# Filter out options that FreeBSD make doesn't understand
|
|
|
|
getflags = ( \
|
|
|
|
set -- \
|
|
|
|
$(filter-out --%,$(firstword $(MFLAGS))) \
|
|
|
|
$(filter -I%,$(MFLAGS)) \
|
|
|
|
$(filter -j%,$(MFLAGS)); \
|
|
|
|
fmakeflags=""; \
|
|
|
|
while getopts :deiI:j:knqrstw flag; do \
|
|
|
|
case $$flag in \
|
|
|
|
\?) :;; \
|
|
|
|
:) if [ $$OPTARG = "j" ]; then \
|
|
|
|
ncpus=$$(sysctl -n kern.smp.cpus 2>/dev/null || :); \
|
|
|
|
if [ -n "$$ncpus" ]; then fmakeflags="$$fmakeflags -j$$ncpus"; fi; \
|
|
|
|
fi;; \
|
|
|
|
d) fmakeflags="$$fmakeflags -dA";; \
|
|
|
|
*) fmakeflags="$$fmakeflags -$$flag$$OPTARG";; \
|
|
|
|
esac; \
|
|
|
|
done; \
|
|
|
|
echo $$fmakeflags \
|
|
|
|
)
|
|
|
|
FMAKEFLAGS = -C @abs_srcdir@ -f Makefile.bsd $(shell $(getflags))
|
|
|
|
|
|
|
|
ifneq (@abs_srcdir@,@abs_builddir@)
|
|
|
|
FMAKEFLAGS += MAKEOBJDIR=@abs_builddir@
|
|
|
|
endif
|
2021-03-05 23:16:41 +03:00
|
|
|
|
2020-06-19 20:33:56 +03:00
|
|
|
FMAKE = env -u MAKEFLAGS make $(FMAKEFLAGS)
|
|
|
|
|
2019-09-06 21:26:26 +03:00
|
|
|
modules-Linux:
|
2022-03-31 18:20:50 +03:00
|
|
|
mkdir -p $(sort $(dir $(spl-objs) $(spl-)))
|
|
|
|
mkdir -p $(sort $(dir $(zfs-objs) $(zfs-)))
|
Add support for $KERNEL_{CC,LD,LLVM} variables
Currently, $(CC), $(LD), and $(LLVM) variables aren't passed to kbuild
while building modules. This causes modules to build with the default
GNU GCC toolchain and prevents experimenting with other toolchains such
as CLANG/LLVM. It can also lead to build failure if the CFLAGS/LDFLAGS
passed are incompatible with gcc/ld.
Pass $KERNEL_CC, $KERNEL_LD, and $KERNEL_LLVM as $(CC), $(LD), and
$(LLVM), respectively, to kbuild for each that is defined in the
environment. This should take care of the majority of alternative
toolchain use cases.
Reviewed-by: Damian Szuberski <szuberskidamian@gmail.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Peter Levine <plevine457@gmail.com>
Closes #13046
2022-02-02 08:44:59 +03:00
|
|
|
$(MAKE) -C @LINUX_OBJ@ $(if @KERNEL_CC@,CC=@KERNEL_CC@) \
|
|
|
|
$(if @KERNEL_LD@,LD=@KERNEL_LD@) $(if @KERNEL_LLVM@,LLVM=@KERNEL_LLVM@) \
|
|
|
|
M="$$PWD" @KERNEL_MAKE@ CONFIG_ZFS=m modules
|
2019-09-06 21:26:26 +03:00
|
|
|
|
2020-04-14 21:36:28 +03:00
|
|
|
modules-FreeBSD:
|
2020-06-19 20:33:56 +03:00
|
|
|
+$(FMAKE)
|
2020-04-14 21:36:28 +03:00
|
|
|
|
2019-09-06 21:26:26 +03:00
|
|
|
modules-unknown:
|
|
|
|
@true
|
|
|
|
|
|
|
|
modules: modules-@ac_system@
|
2010-08-26 22:22:58 +04:00
|
|
|
|
2019-09-06 21:26:26 +03:00
|
|
|
clean-Linux:
|
2011-04-06 00:13:01 +04:00
|
|
|
@# Only cleanup the kernel build directories when CONFIG_KERNEL
|
|
|
|
@# is defined. This indicates that kernel modules should be built.
|
2021-12-23 23:57:44 +03:00
|
|
|
@CONFIG_KERNEL_TRUE@ $(MAKE) -C @LINUX_OBJ@ M="$$PWD" @KERNEL_MAKE@ clean
|
2011-04-06 00:13:01 +04:00
|
|
|
|
2021-12-27 04:21:38 +03:00
|
|
|
$(RM) @LINUX_SYMBOLS@ Module.markers
|
|
|
|
find . -name '*.ur-safe' -type f -delete
|
2018-05-14 04:59:02 +03:00
|
|
|
|
2020-04-14 21:36:28 +03:00
|
|
|
clean-FreeBSD:
|
2020-06-19 20:33:56 +03:00
|
|
|
+$(FMAKE) clean
|
2020-04-14 21:36:28 +03:00
|
|
|
|
2019-09-06 21:26:26 +03:00
|
|
|
clean: clean-@ac_system@
|
|
|
|
|
2022-03-31 18:20:50 +03:00
|
|
|
KMODDIR := $(INSTALL_MOD_PATH)/lib/modules/@LINUX_VERSION@
|
2019-09-06 21:26:26 +03:00
|
|
|
modules_install-Linux:
|
2010-09-05 00:26:23 +04:00
|
|
|
@# Install the kernel modules
|
2021-12-23 23:57:44 +03:00
|
|
|
$(MAKE) -C @LINUX_OBJ@ M="$$PWD" modules_install \
|
2021-10-01 20:44:34 +03:00
|
|
|
INSTALL_MOD_PATH=$(INSTALL_MOD_PATH) \
|
2014-10-22 22:02:45 +04:00
|
|
|
INSTALL_MOD_DIR=$(INSTALL_MOD_DIR) \
|
|
|
|
KERNELRELEASE=@LINUX_VERSION@
|
2011-07-20 08:44:07 +04:00
|
|
|
@# Remove extraneous build products when packaging
|
2015-11-20 04:42:41 +03:00
|
|
|
if [ -n "$(DESTDIR)" ]; then \
|
2022-03-31 18:20:50 +03:00
|
|
|
find $(KMODDIR) -name 'modules.*' -delete; \
|
2011-07-20 08:44:07 +04:00
|
|
|
fi
|
2021-12-17 23:43:13 +03:00
|
|
|
@# Debian ships tiny fake System.map files that are
|
|
|
|
@# syntactically valid but just say
|
|
|
|
@# "if you want system.map go install this package"
|
|
|
|
@# Naturally, depmod is less than amused by this.
|
|
|
|
@# So if we find it missing or with one of these present,
|
|
|
|
@# we check for the alternate path for the System.map
|
2021-10-01 20:44:34 +03:00
|
|
|
sysmap=$(INSTALL_MOD_PATH)/boot/System.map-@LINUX_VERSION@; \
|
2021-12-17 23:43:13 +03:00
|
|
|
{ [ -f "$$sysmap" ] && [ $$(wc -l < "$$sysmap") -ge 100 ]; } || \
|
|
|
|
sysmap=$(INSTALL_MOD_PATH)/usr/lib/debug/boot/System.map-@LINUX_VERSION@; \
|
2010-08-26 22:22:58 +04:00
|
|
|
if [ -f $$sysmap ]; then \
|
|
|
|
depmod -ae -F $$sysmap @LINUX_VERSION@; \
|
|
|
|
fi
|
|
|
|
|
2020-04-14 21:36:28 +03:00
|
|
|
modules_install-FreeBSD:
|
|
|
|
@# Install the kernel modules
|
2020-06-19 20:33:56 +03:00
|
|
|
+$(FMAKE) install
|
2020-04-14 21:36:28 +03:00
|
|
|
|
2019-09-06 21:26:26 +03:00
|
|
|
modules_install: modules_install-@ac_system@
|
|
|
|
|
|
|
|
modules_uninstall-Linux:
|
2010-09-05 00:26:23 +04:00
|
|
|
@# Uninstall the kernel modules
|
2022-03-31 18:20:50 +03:00
|
|
|
$(RM) $(addprefix $(KMODDIR)/$(INSTALL_MOD_DIR)/,zfs.ko spl.ko)
|
2010-08-26 22:22:58 +04:00
|
|
|
|
2020-04-14 21:36:28 +03:00
|
|
|
modules_uninstall-FreeBSD:
|
|
|
|
@false
|
|
|
|
|
2019-09-06 21:26:26 +03:00
|
|
|
modules_uninstall: modules_uninstall-@ac_system@
|
|
|
|
|
2021-01-22 23:54:34 +03:00
|
|
|
cppcheck-Linux:
|
|
|
|
@CPPCHECK@ -j@CPU_COUNT@ --std=c99 --quiet --force --error-exitcode=2 \
|
2021-11-02 23:02:57 +03:00
|
|
|
--inline-suppr \
|
|
|
|
--suppress=unmatchedSuppression \
|
|
|
|
--suppress=noValidConfiguration \
|
2021-01-22 23:54:34 +03:00
|
|
|
--enable=warning,information -D_KERNEL \
|
|
|
|
--include=@LINUX_OBJ@/include/generated/autoconf.h \
|
|
|
|
--include=@top_srcdir@/zfs_config.h \
|
|
|
|
--config-exclude=@LINUX_OBJ@/include \
|
2022-03-01 16:36:32 +03:00
|
|
|
-i zstd/lib \
|
2021-01-22 23:54:34 +03:00
|
|
|
-I @LINUX_OBJ@/include \
|
|
|
|
-I @top_srcdir@/include/os/linux/kernel \
|
|
|
|
-I @top_srcdir@/include/os/linux/spl \
|
|
|
|
-I @top_srcdir@/include/os/linux/zfs \
|
|
|
|
-I @top_srcdir@/include \
|
2022-03-31 18:20:50 +03:00
|
|
|
avl icp lua nvpair unicode zcommon zfs zstd os/linux
|
2021-01-22 23:54:34 +03:00
|
|
|
|
|
|
|
cppcheck-FreeBSD:
|
|
|
|
@true
|
|
|
|
|
|
|
|
cppcheck: cppcheck-@ac_system@
|
|
|
|
|
2010-08-26 22:22:58 +04:00
|
|
|
distdir:
|
2022-03-31 18:20:50 +03:00
|
|
|
cd @srcdir@ && find . -name '*.[chS]' -exec sh -c 'for f; do mkdir -p $$distdir/$${f%/*}; cp @srcdir@/$$f $$distdir/$$f; done' _ {} +
|
2020-06-25 21:04:50 +03:00
|
|
|
cp @srcdir@/Makefile.bsd $$distdir/Makefile.bsd
|
2022-03-31 18:20:50 +03:00
|
|
|
|
|
|
|
gen-zstd-symbols:
|
|
|
|
for obj in $(addprefix zstd/,$(ZSTD_UPSTREAM_OBJS)); do echo; echo "/* $${obj#zstd/}: */"; @OBJDUMP@ -t $$obj | awk '$$2 == "g" && !/ zfs_/ {print "#define\t" $$6 " zfs_" $$6}' | sort; done >> zstd/include/zstd_compat_wrapper.h
|
|
|
|
|
|
|
|
check-zstd-symbols:
|
|
|
|
@OBJDUMP@ -t $(addprefix zstd/,$(ZSTD_UPSTREAM_OBJS)) | awk '/file format/ {print} $$2 == "g" && !/ zfs_/ {++ret; print} END {exit ret}'
|