xref: /freebsd/sys/contrib/openzfs/module/Makefile.in (revision 1323ec57)
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 td in $$list; do $(MAKE) -C $$td; done
55	$(MAKE) -C @LINUX_OBJ@ $(if @KERNEL_CC@,CC=@KERNEL_CC@) \
56		$(if @KERNEL_LD@,LD=@KERNEL_LD@) $(if @KERNEL_LLVM@,LLVM=@KERNEL_LLVM@) \
57		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	$(RM) @LINUX_SYMBOLS@ Module.markers
73	find . -name '*.ur-safe' -type f -delete
74
75clean-FreeBSD:
76	+$(FMAKE) clean
77
78clean: clean-@ac_system@
79
80modules_install-Linux:
81	@# Install the kernel modules
82	$(MAKE) -C @LINUX_OBJ@ M="$$PWD" modules_install \
83		INSTALL_MOD_PATH=$(INSTALL_MOD_PATH) \
84		INSTALL_MOD_DIR=$(INSTALL_MOD_DIR) \
85		KERNELRELEASE=@LINUX_VERSION@
86	@# Remove extraneous build products when packaging
87	kmoddir=$(INSTALL_MOD_PATH)/lib/modules/@LINUX_VERSION@; \
88	if [ -n "$(DESTDIR)" ]; then \
89		find $$kmoddir -name 'modules.*' -delete; \
90	fi
91	@# Debian ships tiny fake System.map files that are
92	@# syntactically valid but just say
93	@# "if you want system.map go install this package"
94	@# Naturally, depmod is less than amused by this.
95	@# So if we find it missing or with one of these present,
96	@# we check for the alternate path for the System.map
97	sysmap=$(INSTALL_MOD_PATH)/boot/System.map-@LINUX_VERSION@; \
98	{ [ -f "$$sysmap" ] && [ $$(wc -l < "$$sysmap") -ge 100 ]; } || \
99		sysmap=$(INSTALL_MOD_PATH)/usr/lib/debug/boot/System.map-@LINUX_VERSION@; \
100	if [ -f $$sysmap ]; then \
101		depmod -ae -F $$sysmap @LINUX_VERSION@; \
102	fi
103
104modules_install-FreeBSD:
105	@# Install the kernel modules
106	+$(FMAKE) install
107
108modules_install: modules_install-@ac_system@
109
110modules_uninstall-Linux:
111	@# Uninstall the kernel modules
112	kmoddir=$(INSTALL_MOD_PATH)/lib/modules/@LINUX_VERSION@; \
113	for objdir in $(ZFS_MODULES); do \
114		$(RM) -R $$kmoddir/$(INSTALL_MOD_DIR)/$$objdir; \
115	done
116
117modules_uninstall-FreeBSD:
118	@false
119
120modules_uninstall: modules_uninstall-@ac_system@
121
122cppcheck-Linux:
123	@CPPCHECK@ -j@CPU_COUNT@ --std=c99 --quiet --force --error-exitcode=2 \
124		--inline-suppr \
125		--suppress=unmatchedSuppression \
126		--suppress=noValidConfiguration \
127		--enable=warning,information -D_KERNEL \
128		--include=@LINUX_OBJ@/include/generated/autoconf.h \
129		--include=@top_srcdir@/zfs_config.h \
130		--config-exclude=@LINUX_OBJ@/include \
131		-i zstd/lib \
132		-I @LINUX_OBJ@/include \
133		-I @top_srcdir@/include/os/linux/kernel \
134		-I @top_srcdir@/include/os/linux/spl \
135		-I @top_srcdir@/include/os/linux/zfs \
136		-I @top_srcdir@/include \
137		avl icp lua nvpair spl unicode zcommon zfs zstd os/linux
138
139cppcheck-FreeBSD:
140	@true
141
142cppcheck: cppcheck-@ac_system@
143
144distdir:
145	(cd @srcdir@ && find $(ZFS_MODULES) os -name '*.[chS]') | \
146	while read path; do \
147		mkdir -p $$distdir/$${path%/*}; \
148		cp @srcdir@/$$path $$distdir/$$path; \
149	done; \
150	cp @srcdir@/Makefile.bsd $$distdir/Makefile.bsd
151