1include Kbuild 2 3INSTALL_MOD_DIR ?= extra 4 5SUBDIR_TARGETS = icp lua zstd 6 7all: modules 8distclean maintainer-clean: clean 9install: modules_install 10uninstall: modules_uninstall 11check: 12 13.PHONY: all distclean maintainer-clean install uninstall check distdir \ 14 modules modules-Linux modules-FreeBSD modules-unknown \ 15 clean clean-Linux clean-FreeBSD \ 16 modules_install modules_install-Linux modules_install-FreeBSD \ 17 modules_uninstall modules_uninstall-Linux modules_uninstall-FreeBSD \ 18 cppcheck cppcheck-Linux cppcheck-FreeBSD 19 20# Filter out options that FreeBSD make doesn't understand 21getflags = ( \ 22set -- \ 23 $(filter-out --%,$(firstword $(MFLAGS))) \ 24 $(filter -I%,$(MFLAGS)) \ 25 $(filter -j%,$(MFLAGS)); \ 26fmakeflags=""; \ 27while getopts :deiI:j:knqrstw flag; do \ 28 case $$flag in \ 29 \?) :;; \ 30 :) if [ $$OPTARG = "j" ]; then \ 31 ncpus=$$(sysctl -n kern.smp.cpus 2>/dev/null || :); \ 32 if [ -n "$$ncpus" ]; then fmakeflags="$$fmakeflags -j$$ncpus"; fi; \ 33 fi;; \ 34 d) fmakeflags="$$fmakeflags -dA";; \ 35 *) fmakeflags="$$fmakeflags -$$flag$$OPTARG";; \ 36 esac; \ 37done; \ 38echo $$fmakeflags \ 39) 40FMAKEFLAGS = -C @abs_srcdir@ -f Makefile.bsd $(shell $(getflags)) 41 42ifneq (@abs_srcdir@,@abs_builddir@) 43FMAKEFLAGS += MAKEOBJDIR=@abs_builddir@ 44endif 45FMAKE = env -u MAKEFLAGS make $(FMAKEFLAGS) 46 47modules-Linux: 48 list='$(SUBDIR_TARGETS)'; for targetdir in $$list; do \ 49 $(MAKE) -C $$targetdir; \ 50 done 51 $(MAKE) -C @LINUX_OBJ@ M=`pwd` @KERNEL_MAKE@ CONFIG_ZFS=m modules 52 53modules-FreeBSD: 54 +$(FMAKE) 55 56modules-unknown: 57 @true 58 59modules: modules-@ac_system@ 60 61clean-Linux: 62 @# Only cleanup the kernel build directories when CONFIG_KERNEL 63 @# is defined. This indicates that kernel modules should be built. 64@CONFIG_KERNEL_TRUE@ $(MAKE) -C @LINUX_OBJ@ M=`pwd` @KERNEL_MAKE@ clean 65 66 if [ -f @LINUX_SYMBOLS@ ]; then $(RM) @LINUX_SYMBOLS@; fi 67 if [ -f Module.markers ]; then $(RM) Module.markers; fi 68 69 find . -name '*.ur-safe' -type f -print | xargs $(RM) 70 71clean-FreeBSD: 72 +$(FMAKE) clean 73 74clean: clean-@ac_system@ 75 76modules_install-Linux: 77 @# Install the kernel modules 78 $(MAKE) -C @LINUX_OBJ@ M=`pwd` modules_install \ 79 INSTALL_MOD_PATH=$(DESTDIR)$(INSTALL_MOD_PATH) \ 80 INSTALL_MOD_DIR=$(INSTALL_MOD_DIR) \ 81 KERNELRELEASE=@LINUX_VERSION@ 82 @# Remove extraneous build products when packaging 83 kmoddir=$(DESTDIR)$(INSTALL_MOD_PATH)/lib/modules/@LINUX_VERSION@; \ 84 if [ -n "$(DESTDIR)" ]; then \ 85 find $$kmoddir -name 'modules.*' | xargs $(RM); \ 86 fi 87 sysmap=$(DESTDIR)$(INSTALL_MOD_PATH)/boot/System.map-@LINUX_VERSION@; \ 88 if [ -f $$sysmap ]; then \ 89 depmod -ae -F $$sysmap @LINUX_VERSION@; \ 90 fi 91 92modules_install-FreeBSD: 93 @# Install the kernel modules 94 +$(FMAKE) install 95 96modules_install: modules_install-@ac_system@ 97 98modules_uninstall-Linux: 99 @# Uninstall the kernel modules 100 kmoddir=$(DESTDIR)$(INSTALL_MOD_PATH)/lib/modules/@LINUX_VERSION@; \ 101 for objdir in $(ZFS_MODULES); do \ 102 $(RM) -R $$kmoddir/$(INSTALL_MOD_DIR)/$$objdir; \ 103 done 104 105modules_uninstall-FreeBSD: 106 @false 107 108modules_uninstall: modules_uninstall-@ac_system@ 109 110cppcheck-Linux: 111 @CPPCHECK@ -j@CPU_COUNT@ --std=c99 --quiet --force --error-exitcode=2 \ 112 --inline-suppr --suppress=noValidConfiguration \ 113 --enable=warning,information -D_KERNEL \ 114 --include=@LINUX_OBJ@/include/generated/autoconf.h \ 115 --include=@top_srcdir@/zfs_config.h \ 116 --config-exclude=@LINUX_OBJ@/include \ 117 -I @LINUX_OBJ@/include \ 118 -I @top_srcdir@/include/os/linux/kernel \ 119 -I @top_srcdir@/include/os/linux/spl \ 120 -I @top_srcdir@/include/os/linux/zfs \ 121 -I @top_srcdir@/include \ 122 avl icp lua nvpair spl unicode zcommon zfs zstd os/linux 123 124cppcheck-FreeBSD: 125 @true 126 127cppcheck: cppcheck-@ac_system@ 128 129distdir: 130 (cd @srcdir@ && find $(ZFS_MODULES) os -name '*.[chS]') | \ 131 while read path; do \ 132 mkdir -p $$distdir/$${path%/*}; \ 133 cp @srcdir@/$$path $$distdir/$$path; \ 134 done; \ 135 cp @srcdir@/Makefile.bsd $$distdir/Makefile.bsd 136