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 19# Filter out options that FreeBSD make doesn't understand 20getflags = ( \ 21set -- \ 22 $(filter-out --%,$(firstword $(MFLAGS))) \ 23 $(filter -I%,$(MFLAGS)) \ 24 $(filter -j%,$(MFLAGS)); \ 25fmakeflags=""; \ 26while getopts :deiI:j:knqrstw flag; do \ 27 case $$flag in \ 28 \?) :;; \ 29 :) if [ $$OPTARG = "j" ]; then \ 30 ncpus=$$(sysctl -n kern.smp.cpus 2>/dev/null || :); \ 31 if [ -n "$$ncpus" ]; then fmakeflags="$$fmakeflags -j$$ncpus"; fi; \ 32 fi;; \ 33 d) fmakeflags="$$fmakeflags -dA";; \ 34 *) fmakeflags="$$fmakeflags -$$flag$$OPTARG";; \ 35 esac; \ 36done; \ 37echo $$fmakeflags \ 38) 39FMAKEFLAGS = -C @abs_srcdir@ -f Makefile.bsd $(shell $(getflags)) 40 41ifneq (@abs_srcdir@,@abs_builddir@) 42FMAKEFLAGS += MAKEOBJDIR=@abs_builddir@ 43endif 44FMAKE = env -u MAKEFLAGS make $(FMAKEFLAGS) 45 46modules-Linux: 47 list='$(SUBDIR_TARGETS)'; for targetdir in $$list; do \ 48 $(MAKE) -C $$targetdir; \ 49 done 50 $(MAKE) -C @LINUX_OBJ@ M=`pwd` @KERNEL_MAKE@ CONFIG_ZFS=m modules 51 52modules-FreeBSD: 53 +$(FMAKE) 54 55modules-unknown: 56 @true 57 58modules: modules-@ac_system@ 59 60clean-Linux: 61 @# Only cleanup the kernel build directories when CONFIG_KERNEL 62 @# is defined. This indicates that kernel modules should be built. 63@CONFIG_KERNEL_TRUE@ $(MAKE) -C @LINUX_OBJ@ M=`pwd` @KERNEL_MAKE@ clean 64 65 if [ -f @LINUX_SYMBOLS@ ]; then $(RM) @LINUX_SYMBOLS@; fi 66 if [ -f Module.markers ]; then $(RM) Module.markers; fi 67 68 find . -name '*.ur-safe' -type f -print | xargs $(RM) 69 70clean-FreeBSD: 71 +$(FMAKE) clean 72 73clean: clean-@ac_system@ 74 75modules_install-Linux: 76 @# Install the kernel modules 77 $(MAKE) -C @LINUX_OBJ@ M=`pwd` modules_install \ 78 INSTALL_MOD_PATH=$(DESTDIR)$(INSTALL_MOD_PATH) \ 79 INSTALL_MOD_DIR=$(INSTALL_MOD_DIR) \ 80 KERNELRELEASE=@LINUX_VERSION@ 81 @# Remove extraneous build products when packaging 82 kmoddir=$(DESTDIR)$(INSTALL_MOD_PATH)/lib/modules/@LINUX_VERSION@; \ 83 if [ -n "$(DESTDIR)" ]; then \ 84 find $$kmoddir -name 'modules.*' | xargs $(RM); \ 85 fi 86 sysmap=$(DESTDIR)$(INSTALL_MOD_PATH)/boot/System.map-@LINUX_VERSION@; \ 87 if [ -f $$sysmap ]; then \ 88 depmod -ae -F $$sysmap @LINUX_VERSION@; \ 89 fi 90 91modules_install-FreeBSD: 92 @# Install the kernel modules 93 +$(FMAKE) install 94 95modules_install: modules_install-@ac_system@ 96 97modules_uninstall-Linux: 98 @# Uninstall the kernel modules 99 kmoddir=$(DESTDIR)$(INSTALL_MOD_PATH)/lib/modules/@LINUX_VERSION@; \ 100 for objdir in $(ZFS_MODULES); do \ 101 $(RM) -R $$kmoddir/$(INSTALL_MOD_DIR)/$$objdir; \ 102 done 103 104modules_uninstall-FreeBSD: 105 @false 106 107modules_uninstall: modules_uninstall-@ac_system@ 108 109distdir: 110 (cd @srcdir@ && find $(ZFS_MODULES) os -name '*.[chS]') | \ 111 while read path; do \ 112 mkdir -p $$distdir/$${path%/*}; \ 113 cp @srcdir@/$$path $$distdir/$$path; \ 114 done; \ 115 cp @srcdir@/Makefile.bsd $$distdir/Makefile.bsd 116