1include Kbuild 2 3INSTALL_MOD_DIR ?= extra 4INSTALL_MOD_PATH ?= $(DESTDIR) 5 6SUBDIR_TARGETS = icp lua zstd 7 8all: modules 9distclean maintainer-clean: clean 10install: modules_install 11uninstall: modules_uninstall 12check: 13 14.PHONY: all distclean maintainer-clean install uninstall check distdir \ 15 modules modules-Linux modules-FreeBSD modules-unknown \ 16 clean clean-Linux clean-FreeBSD \ 17 modules_install modules_install-Linux modules_install-FreeBSD \ 18 modules_uninstall modules_uninstall-Linux modules_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 list='$(SUBDIR_TARGETS)'; for targetdir in $$list; do \ 55 $(MAKE) -C $$targetdir; \ 56 done 57 $(MAKE) -C @LINUX_OBJ@ M=`pwd` @KERNEL_MAKE@ CONFIG_ZFS=m modules 58 59modules-FreeBSD: 60 +$(FMAKE) 61 62modules-unknown: 63 @true 64 65modules: modules-@ac_system@ 66 67clean-Linux: 68 @# Only cleanup the kernel build directories when CONFIG_KERNEL 69 @# is defined. This indicates that kernel modules should be built. 70@CONFIG_KERNEL_TRUE@ $(MAKE) -C @LINUX_OBJ@ M=`pwd` @KERNEL_MAKE@ clean 71 72 if [ -f @LINUX_SYMBOLS@ ]; then $(RM) @LINUX_SYMBOLS@; fi 73 if [ -f Module.markers ]; then $(RM) Module.markers; fi 74 75 find . -name '*.ur-safe' -type f -print | xargs $(RM) 76 77clean-FreeBSD: 78 +$(FMAKE) clean 79 80clean: clean-@ac_system@ 81 82modules_install-Linux: 83 @# Install the kernel modules 84 $(MAKE) -C @LINUX_OBJ@ M=`pwd` modules_install \ 85 INSTALL_MOD_PATH=$(INSTALL_MOD_PATH) \ 86 INSTALL_MOD_DIR=$(INSTALL_MOD_DIR) \ 87 KERNELRELEASE=@LINUX_VERSION@ 88 @# Remove extraneous build products when packaging 89 kmoddir=$(INSTALL_MOD_PATH)/lib/modules/@LINUX_VERSION@; \ 90 if [ -n "$(DESTDIR)" ]; then \ 91 find $$kmoddir -name 'modules.*' | xargs $(RM); \ 92 fi 93 sysmap=$(INSTALL_MOD_PATH)/boot/System.map-@LINUX_VERSION@; \ 94 if [ -f $$sysmap ]; then \ 95 depmod -ae -F $$sysmap @LINUX_VERSION@; \ 96 fi 97 98modules_install-FreeBSD: 99 @# Install the kernel modules 100 +$(FMAKE) install 101 102modules_install: modules_install-@ac_system@ 103 104modules_uninstall-Linux: 105 @# Uninstall the kernel modules 106 kmoddir=$(INSTALL_MOD_PATH)/lib/modules/@LINUX_VERSION@; \ 107 for objdir in $(ZFS_MODULES); do \ 108 $(RM) -R $$kmoddir/$(INSTALL_MOD_DIR)/$$objdir; \ 109 done 110 111modules_uninstall-FreeBSD: 112 @false 113 114modules_uninstall: modules_uninstall-@ac_system@ 115 116cppcheck-Linux: 117 @CPPCHECK@ -j@CPU_COUNT@ --std=c99 --quiet --force --error-exitcode=2 \ 118 --inline-suppr \ 119 --suppress=unmatchedSuppression \ 120 --suppress=noValidConfiguration \ 121 --enable=warning,information -D_KERNEL \ 122 --include=@LINUX_OBJ@/include/generated/autoconf.h \ 123 --include=@top_srcdir@/zfs_config.h \ 124 --config-exclude=@LINUX_OBJ@/include \ 125 -I @LINUX_OBJ@/include \ 126 -I @top_srcdir@/include/os/linux/kernel \ 127 -I @top_srcdir@/include/os/linux/spl \ 128 -I @top_srcdir@/include/os/linux/zfs \ 129 -I @top_srcdir@/include \ 130 avl icp lua nvpair spl unicode zcommon zfs zstd os/linux 131 132cppcheck-FreeBSD: 133 @true 134 135cppcheck: cppcheck-@ac_system@ 136 137distdir: 138 (cd @srcdir@ && find $(ZFS_MODULES) os -name '*.[chS]') | \ 139 while read path; do \ 140 mkdir -p $$distdir/$${path%/*}; \ 141 cp @srcdir@/$$path $$distdir/$$path; \ 142 done; \ 143 cp @srcdir@/Makefile.bsd $$distdir/Makefile.bsd 144