1include Kbuild 2 3INSTALL_MOD_DIR ?= extra 4INSTALL_MOD_PATH ?= $(DESTDIR) 5 6all: modules 7distclean maintainer-clean: clean 8install: modules_install data_install 9uninstall: modules_uninstall data_uninstall 10check: 11 12.PHONY: all distclean maintainer-clean install uninstall check distdir \ 13 modules modules-Linux modules-FreeBSD modules-unknown \ 14 clean clean-Linux clean-FreeBSD \ 15 modules_install modules_install-Linux modules_install-FreeBSD \ 16 data_install data_install-Linux data_install-FreeBSD \ 17 modules_uninstall modules_uninstall-Linux modules_uninstall-FreeBSD \ 18 data_uninstall data_uninstall-Linux data_uninstall-FreeBSD \ 19 cppcheck cppcheck-Linux cppcheck-FreeBSD 20 21# For FreeBSD, use debug options from ./configure if not overridden. 22export WITH_DEBUG ?= @WITH_DEBUG@ 23export WITH_INVARIANTS ?= @WITH_INVARIANTS@ 24 25# Filter out options that FreeBSD make doesn't understand 26getflags = ( \ 27set -- \ 28 $(filter-out --%,$(firstword $(MFLAGS))) \ 29 $(filter -I%,$(MFLAGS)) \ 30 $(filter -j%,$(MFLAGS)); \ 31fmakeflags=""; \ 32while getopts :deiI:j:knqrstw flag; do \ 33 case $$flag in \ 34 \?) :;; \ 35 :) if [ $$OPTARG = "j" ]; then \ 36 ncpus=$$(sysctl -n kern.smp.cpus 2>/dev/null || :); \ 37 if [ -n "$$ncpus" ]; then fmakeflags="$$fmakeflags -j$$ncpus"; fi; \ 38 fi;; \ 39 d) fmakeflags="$$fmakeflags -dA";; \ 40 *) fmakeflags="$$fmakeflags -$$flag$$OPTARG";; \ 41 esac; \ 42done; \ 43echo $$fmakeflags \ 44) 45FMAKEFLAGS = -C @abs_srcdir@ -f Makefile.bsd $(shell $(getflags)) 46 47ifneq (@abs_srcdir@,@abs_builddir@) 48FMAKEFLAGS += MAKEOBJDIR=@abs_builddir@ 49endif 50 51FMAKE = env -u MAKEFLAGS make $(FMAKEFLAGS) 52 53modules-Linux: 54 mkdir -p $(sort $(dir $(spl-objs) $(spl-))) 55 mkdir -p $(sort $(dir $(zfs-objs) $(zfs-))) 56 $(MAKE) -C @LINUX_OBJ@ $(if @KERNEL_CC@,CC=@KERNEL_CC@) \ 57 $(if @KERNEL_LD@,LD=@KERNEL_LD@) $(if @KERNEL_LLVM@,LLVM=@KERNEL_LLVM@) \ 58 $(if @KERNEL_CROSS_COMPILE@,CROSS_COMPILE=@KERNEL_CROSS_COMPILE@) \ 59 $(if @KERNEL_ARCH@,ARCH=@KERNEL_ARCH@) \ 60 $(if @OBJTOOL_DISABLE_WERROR@,objtool=@abs_top_builddir@/scripts/objtool-wrapper) \ 61 M="$$PWD" @KERNEL_MAKE@ CONFIG_ZFS=m modules 62 63modules-FreeBSD: 64 +$(FMAKE) 65 66modules-unknown: 67 @true 68 69modules: modules-@ac_system@ 70 71clean-Linux: 72 @# Only cleanup the kernel build directories when CONFIG_KERNEL 73 @# is defined. This indicates that kernel modules should be built. 74@CONFIG_KERNEL_TRUE@ $(MAKE) -C @LINUX_OBJ@ M="$$PWD" @KERNEL_MAKE@ clean 75 76 $(RM) @LINUX_SYMBOLS@ Module.markers 77 find . -name '*.ur-safe' -type f -delete 78 79clean-FreeBSD: 80 +$(FMAKE) clean 81 82clean: clean-@ac_system@ 83 84.PHONY: modules_uninstall-Linux-legacy 85modules_uninstall-Linux-legacy: 86 $(RM) -r $(addprefix $(KMODDIR)/$(INSTALL_MOD_DIR)/,spl/ avl/ icp/ lua/ nvpair/ unicode/ zcommon/ zfs/ zstd/) 87 88KMODDIR := $(INSTALL_MOD_PATH)/lib/modules/@LINUX_VERSION@ 89modules_install-Linux: modules_uninstall-Linux-legacy 90 @# Install the kernel modules 91 $(MAKE) -C @LINUX_OBJ@ M="$$PWD" modules_install \ 92 INSTALL_MOD_PATH=$(INSTALL_MOD_PATH) \ 93 INSTALL_MOD_DIR=$(INSTALL_MOD_DIR) \ 94 $(if @KERNEL_ARCH@,ARCH=@KERNEL_ARCH@) \ 95 KERNELRELEASE=@LINUX_VERSION@ 96 @# Remove extraneous build products when packaging 97 if [ -n "$(DESTDIR)" ] && [ "$(DONT_DELETE_MODULES_FILES)" != "1" ]; then \ 98 find $(KMODDIR) -name 'modules.*' -delete; \ 99 fi 100 @# Debian ships tiny fake System.map files that are 101 @# syntactically valid but just say 102 @# "if you want system.map go install this package" 103 @# Naturally, depmod is less than amused by this. 104 @# So if we find it missing or with one of these present, 105 @# we check for the alternate path for the System.map 106 sysmap=$(INSTALL_MOD_PATH)/boot/System.map-@LINUX_VERSION@; \ 107 { [ -f "$$sysmap" ] && [ $$(wc -l < "$$sysmap") -ge 100 ]; } || \ 108 sysmap=$(INSTALL_MOD_PATH)/usr/lib/debug/boot/System.map-@LINUX_VERSION@; \ 109 if [ -f $$sysmap ]; then \ 110 depmod -ae -F $$sysmap @LINUX_VERSION@ -b $(INSTALL_MOD_PATH)/; \ 111 fi 112 113modules_install-FreeBSD: 114 @# Install the kernel modules 115 +$(FMAKE) install 116 117modules_install: modules_install-@ac_system@ 118 119data_install-Linux: 120 @mkdir -p $(DESTDIR)/@prefix@/src/zfs-@VERSION@/@LINUX_VERSION@ 121 cp ../zfs.release ../zfs_config.h @LINUX_SYMBOLS@ $(DESTDIR)/@prefix@/src/zfs-@VERSION@/@LINUX_VERSION@ 122 123data_install-FreeBSD: 124 @ 125 126data_install: data_install-@ac_system@ 127 128modules_uninstall-Linux: modules_uninstall-Linux-legacy 129 @# Uninstall the kernel modules 130 $(RM) $(addprefix $(KMODDIR)/$(INSTALL_MOD_DIR)/,zfs.ko spl.ko) 131 132modules_uninstall-FreeBSD: 133 @false 134 135modules_uninstall: modules_uninstall-@ac_system@ 136 137data_uninstall-Linux: 138 $(RM) $(addprefix $(DESTDIR)/@prefix@/src/zfs-@VERSION@/@LINUX_VERSION@/,zfs.release zfs_config.h @LINUX_SYMBOLS@) 139 140data_uninstall-FreeBSD: 141 @ 142 143data_uninstall: data_uninstall-@ac_system@ 144 145cppcheck-Linux: 146 @CPPCHECK@ -j@CPU_COUNT@ --std=c99 --quiet --force --error-exitcode=2 \ 147 --inline-suppr \ 148 --suppress=unmatchedSuppression \ 149 --suppress=noValidConfiguration \ 150 --enable=warning,information -D_KERNEL \ 151 --include=@LINUX_OBJ@/include/generated/autoconf.h \ 152 --include=@top_builddir@/zfs_config.h \ 153 --config-exclude=@LINUX_OBJ@/include \ 154 -i zstd/lib \ 155 -I @LINUX_OBJ@/include \ 156 -I @top_srcdir@/include/os/linux/kernel \ 157 -I @top_srcdir@/include/os/linux/spl \ 158 -I @top_srcdir@/include/os/linux/zfs \ 159 -I @top_srcdir@/include \ 160 avl icp lua nvpair unicode zcommon zfs zstd os/linux 161 162cppcheck-FreeBSD: 163 @true 164 165cppcheck: cppcheck-@ac_system@ 166 167distdir: 168 cd @srcdir@ && find . -name '*.[chS]' -exec sh -c 'for f; do mkdir -p $$distdir/$${f%/*}; cp @srcdir@/$$f $$distdir/$$f; done' _ {} + 169 cp @srcdir@/Makefile.bsd $$distdir/Makefile.bsd 170 171gen-zstd-symbols: 172 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 173 174check-zstd-symbols: 175 @OBJDUMP@ -t $(addprefix zstd/,$(ZSTD_UPSTREAM_OBJS)) | awk '/file format/ {print} $$2 == "g" && (!/ zfs_/ && !/ __pfx_zfs_/) {++ret; print} END {exit ret}' 176