diff options
author | Arvind Sankar <[email protected]> | 2020-06-19 13:33:56 -0400 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2020-06-24 18:18:41 -0700 |
commit | 33982eb24c615f78b8f6b5f54c6acb6c29cbf6e3 (patch) | |
tree | f2b0a90f80a9ce0a5c9dcb718915b7fc0e49bd7e | |
parent | f21de6883fa53b83c065aaa1aca7122afafb3c90 (diff) |
Support out-of-tree kmod build on FreeBSD
If srcdir != builddir, pass down MAKEOBJDIR to the FreeBSD make to
support out-of-tree builds.
Also allow passing all the gmake options that FreeBSD make understands
to support useful flags like -k, -n, -q etc, and detect the number of
CPUs if -j was specified without an argument.
Reviewed-by: Ryan Moeller <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Arvind Sankar <[email protected]>
Closes #10493
-rw-r--r-- | module/Makefile.in | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/module/Makefile.in b/module/Makefile.in index 3485649dc..6df0f5636 100644 --- a/module/Makefile.in +++ b/module/Makefile.in @@ -10,16 +10,41 @@ install: modules_install uninstall: modules_uninstall check: +# Filter out options that FreeBSD make doesn't understand +getflags = ( \ +set -- \ + $(filter-out --%,$(firstword $(MFLAGS))) \ + $(filter -I%,$(MFLAGS)) \ + $(filter -j%,$(MFLAGS)); \ +fmakeflags=""; \ +while getopts :deiI:j:knqrstw flag; do \ + case $$flag in \ + \?) :;; \ + :) if [ $$OPTARG = "j" ]; then \ + ncpus=$$(sysctl -n kern.smp.cpus 2>/dev/null || :); \ + if [ -n "$$ncpus" ]; then fmakeflags="$$fmakeflags -j$$ncpus"; fi; \ + fi;; \ + d) fmakeflags="$$fmakeflags -dA";; \ + *) fmakeflags="$$fmakeflags -$$flag$$OPTARG";; \ + esac; \ +done; \ +echo $$fmakeflags \ +) +FMAKEFLAGS = -C @abs_srcdir@ -f Makefile.bsd $(shell $(getflags)) + +ifneq (@abs_srcdir@,@abs_builddir@) +FMAKEFLAGS += MAKEOBJDIR=@abs_builddir@ +endif +FMAKE = env -u MAKEFLAGS make $(FMAKEFLAGS) + modules-Linux: list='$(SUBDIR_TARGETS)'; for targetdir in $$list; do \ $(MAKE) -C $$targetdir; \ done $(MAKE) -C @LINUX_OBJ@ M=`pwd` @KERNEL_MAKE@ CONFIG_ZFS=m modules -# Only pass down gmake -j flag, if used. modules-FreeBSD: - flags="$$(echo $$MAKEFLAGS | awk -v RS=' ' /^-j/)"; \ - env MAKEFLAGS="" make $${flags} -f Makefile.bsd + +$(FMAKE) modules-unknown: @true @@ -37,8 +62,7 @@ clean-Linux: find . -name '*.ur-safe' -type f -print | xargs $(RM) clean-FreeBSD: - flags="$$(echo $$MAKEFLAGS | awk -v RS=' ' /^-j/)"; \ - env MAKEFLAGS="" make $${flags} -f Makefile.bsd clean + +$(FMAKE) clean clean: clean-@ac_system@ @@ -87,8 +111,7 @@ cscopelist-am: $(am__tagged_files) modules_install-FreeBSD: @# Install the kernel modules - flags="$$(echo $$MAKEFLAGS | awk -v RS=' ' /^-j/)"; \ - env MAKEFLAGS="" make $${flags} -f Makefile.bsd install + +$(FMAKE) install modules_install: modules_install-@ac_system@ |