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