xref: /freebsd/sys/contrib/openzfs/config/zfs-build.m4 (revision 6c05f3a74f30934ee60919cc97e16ec69b542b06)
1AC_DEFUN([ZFS_AC_LICENSE], [
2	AC_MSG_CHECKING([zfs author])
3	AC_MSG_RESULT([$ZFS_META_AUTHOR])
4
5	AC_MSG_CHECKING([zfs license])
6	AC_MSG_RESULT([$ZFS_META_LICENSE])
7])
8
9AC_DEFUN([ZFS_AC_DEBUG_ENABLE], [
10	DEBUG_CFLAGS="-Werror"
11	DEBUG_CPPFLAGS="-DDEBUG -UNDEBUG"
12	DEBUG_LDFLAGS=""
13	DEBUG_ZFS="_with_debug"
14	WITH_DEBUG="true"
15	AC_DEFINE(ZFS_DEBUG, 1, [zfs debugging enabled])
16
17	KERNEL_DEBUG_CFLAGS="-Werror"
18	KERNEL_DEBUG_CPPFLAGS="-DDEBUG -UNDEBUG"
19])
20
21AC_DEFUN([ZFS_AC_DEBUG_DISABLE], [
22	DEBUG_CFLAGS=""
23	DEBUG_CPPFLAGS="-UDEBUG -DNDEBUG"
24	DEBUG_LDFLAGS=""
25	DEBUG_ZFS="_without_debug"
26	WITH_DEBUG=""
27
28	KERNEL_DEBUG_CFLAGS=""
29	KERNEL_DEBUG_CPPFLAGS="-UDEBUG -DNDEBUG"
30])
31
32dnl #
33dnl # When debugging is enabled:
34dnl # - Enable all ASSERTs (-DDEBUG)
35dnl # - Promote all compiler warnings to errors (-Werror)
36dnl #
37dnl # (If INVARIANTS is detected, we need to force DEBUG, or strange panics
38dnl # can ensue.)
39dnl #
40AC_DEFUN([ZFS_AC_DEBUG], [
41	AC_MSG_CHECKING([whether assertion support will be enabled])
42	AC_ARG_ENABLE([debug],
43		[AS_HELP_STRING([--enable-debug],
44		[Enable compiler and code assertions @<:@default=no@:>@])],
45		[],
46		[enable_debug=no])
47
48	AS_CASE(["x$enable_debug"],
49		["xyes"],
50		[ZFS_AC_DEBUG_ENABLE],
51		["xno"],
52		[ZFS_AC_DEBUG_DISABLE],
53		[AC_MSG_ERROR([Unknown option $enable_debug])])
54
55	AS_CASE(["x$enable_invariants"],
56		["xyes"],
57		[],
58		["xno"],
59		[],
60		[ZFS_AC_DEBUG_INVARIANTS_DETECT])
61
62	AS_CASE(["x$enable_invariants"],
63		["xyes"],
64		[ZFS_AC_DEBUG_ENABLE],
65		["xno"],
66		[],
67		[AC_MSG_ERROR([Unknown option $enable_invariants])])
68
69	AC_SUBST(DEBUG_CFLAGS)
70	AC_SUBST(DEBUG_CPPFLAGS)
71	AC_SUBST(DEBUG_LDFLAGS)
72	AC_SUBST(DEBUG_ZFS)
73	AC_SUBST(WITH_DEBUG)
74
75	AC_SUBST(KERNEL_DEBUG_CFLAGS)
76	AC_SUBST(KERNEL_DEBUG_CPPFLAGS)
77
78	AC_MSG_RESULT([$enable_debug])
79])
80
81AC_DEFUN([ZFS_AC_DEBUGINFO_ENABLE], [
82	DEBUG_CFLAGS="$DEBUG_CFLAGS -g -fno-inline $NO_IPA_SRA"
83
84	KERNEL_DEBUG_CFLAGS="$KERNEL_DEBUG_CFLAGS -fno-inline $KERNEL_NO_IPA_SRA"
85	KERNEL_MAKE="$KERNEL_MAKE CONFIG_DEBUG_INFO=y"
86
87	DEBUGINFO_ZFS="_with_debuginfo"
88])
89
90AC_DEFUN([ZFS_AC_DEBUGINFO_DISABLE], [
91	DEBUGINFO_ZFS="_without_debuginfo"
92])
93
94AC_DEFUN([ZFS_AC_DEBUGINFO], [
95	AC_MSG_CHECKING([whether debuginfo support will be forced])
96	AC_ARG_ENABLE([debuginfo],
97		[AS_HELP_STRING([--enable-debuginfo],
98		[Force generation of debuginfo @<:@default=no@:>@])],
99		[],
100		[enable_debuginfo=no])
101
102	AS_CASE(["x$enable_debuginfo"],
103		["xyes"],
104		[ZFS_AC_DEBUGINFO_ENABLE],
105		["xno"],
106		[ZFS_AC_DEBUGINFO_DISABLE],
107		[AC_MSG_ERROR([Unknown option $enable_debuginfo])])
108
109	AC_SUBST(DEBUG_CFLAGS)
110	AC_SUBST(DEBUGINFO_ZFS)
111
112	AC_SUBST(KERNEL_DEBUG_CFLAGS)
113	AC_SUBST(KERNEL_MAKE)
114
115	AC_MSG_RESULT([$enable_debuginfo])
116])
117
118dnl #
119dnl # Disabled by default, provides basic memory tracking.  Track the total
120dnl # number of bytes allocated with kmem_alloc() and freed with kmem_free().
121dnl # Then at module unload time if any bytes were leaked it will be reported
122dnl # on the console.
123dnl #
124AC_DEFUN([ZFS_AC_DEBUG_KMEM], [
125	AC_MSG_CHECKING([whether basic kmem accounting is enabled])
126	AC_ARG_ENABLE([debug-kmem],
127		[AS_HELP_STRING([--enable-debug-kmem],
128		[Enable basic kmem accounting @<:@default=no@:>@])],
129		[],
130		[enable_debug_kmem=no])
131
132	AS_IF([test "x$enable_debug_kmem" = xyes], [
133		KERNEL_DEBUG_CPPFLAGS="${KERNEL_DEBUG_CPPFLAGS} -DDEBUG_KMEM"
134		DEBUG_KMEM_ZFS="_with_debug_kmem"
135	], [
136		DEBUG_KMEM_ZFS="_without_debug_kmem"
137	])
138
139	AC_SUBST(KERNEL_DEBUG_CPPFLAGS)
140	AC_SUBST(DEBUG_KMEM_ZFS)
141
142	AC_MSG_RESULT([$enable_debug_kmem])
143])
144
145dnl #
146dnl # Disabled by default, provides detailed memory tracking.  This feature
147dnl # also requires --enable-debug-kmem to be set.  When enabled not only will
148dnl # total bytes be tracked but also the location of every kmem_alloc() and
149dnl # kmem_free().  When the module is unloaded a list of all leaked addresses
150dnl # and where they were allocated will be dumped to the console.  Enabling
151dnl # this feature has a significant impact on performance but it makes finding
152dnl # memory leaks straight forward.
153dnl #
154AC_DEFUN([ZFS_AC_DEBUG_KMEM_TRACKING], [
155	AC_MSG_CHECKING([whether detailed kmem tracking is enabled])
156	AC_ARG_ENABLE([debug-kmem-tracking],
157		[AS_HELP_STRING([--enable-debug-kmem-tracking],
158		[Enable detailed kmem tracking  @<:@default=no@:>@])],
159		[],
160		[enable_debug_kmem_tracking=no])
161
162	AS_IF([test "x$enable_debug_kmem_tracking" = xyes], [
163		KERNEL_DEBUG_CPPFLAGS="${KERNEL_DEBUG_CPPFLAGS} -DDEBUG_KMEM_TRACKING"
164		DEBUG_KMEM_TRACKING_ZFS="_with_debug_kmem_tracking"
165	], [
166		DEBUG_KMEM_TRACKING_ZFS="_without_debug_kmem_tracking"
167	])
168
169	AC_SUBST(KERNEL_DEBUG_CPPFLAGS)
170	AC_SUBST(DEBUG_KMEM_TRACKING_ZFS)
171
172	AC_MSG_RESULT([$enable_debug_kmem_tracking])
173])
174
175AC_DEFUN([ZFS_AC_DEBUG_INVARIANTS_DETECT_FREEBSD], [
176	AS_IF([sysctl -n kern.conftxt | grep -Fqx $'options\tINVARIANTS'],
177		[enable_invariants="yes"],
178		[enable_invariants="no"])
179])
180
181AC_DEFUN([ZFS_AC_DEBUG_INVARIANTS_DETECT], [
182	AM_COND_IF([BUILD_FREEBSD],
183		[ZFS_AC_DEBUG_INVARIANTS_DETECT_FREEBSD],
184		[enable_invariants="no"])
185])
186
187dnl #
188dnl # Detected for the running kernel by default, enables INVARIANTS features
189dnl # in the FreeBSD kernel module.  This feature must be used when building
190dnl # for a FreeBSD kernel with "options INVARIANTS" in the KERNCONF and must
191dnl # not be used when the INVARIANTS option is absent.
192dnl #
193AC_DEFUN([ZFS_AC_DEBUG_INVARIANTS], [
194	AC_MSG_CHECKING([whether FreeBSD kernel INVARIANTS checks are enabled])
195	AC_ARG_ENABLE([invariants],
196		[AS_HELP_STRING([--enable-invariants],
197		[Enable FreeBSD kernel INVARIANTS checks [[default: detect]]])],
198		[], [ZFS_AC_DEBUG_INVARIANTS_DETECT])
199
200	AS_IF([test "x$enable_invariants" = xyes],
201		[WITH_INVARIANTS="true"],
202		[WITH_INVARIANTS=""])
203	AC_SUBST(WITH_INVARIANTS)
204
205	AC_MSG_RESULT([$enable_invariants])
206])
207
208AC_DEFUN([ZFS_AC_CONFIG_ALWAYS], [
209	AX_COUNT_CPUS([])
210	AC_SUBST(CPU_COUNT)
211
212	ZFS_AC_CONFIG_ALWAYS_CC_NO_CLOBBERED
213	ZFS_AC_CONFIG_ALWAYS_CC_INFINITE_RECURSION
214	ZFS_AC_CONFIG_ALWAYS_KERNEL_CC_INFINITE_RECURSION
215	ZFS_AC_CONFIG_ALWAYS_CC_IMPLICIT_FALLTHROUGH
216	ZFS_AC_CONFIG_ALWAYS_CC_FRAME_LARGER_THAN
217	ZFS_AC_CONFIG_ALWAYS_CC_NO_FORMAT_TRUNCATION
218	ZFS_AC_CONFIG_ALWAYS_CC_NO_FORMAT_ZERO_LENGTH
219	ZFS_AC_CONFIG_ALWAYS_CC_FORMAT_OVERFLOW
220	ZFS_AC_CONFIG_ALWAYS_CC_NO_OMIT_FRAME_POINTER
221	ZFS_AC_CONFIG_ALWAYS_CC_NO_IPA_SRA
222	ZFS_AC_CONFIG_ALWAYS_KERNEL_CC_NO_IPA_SRA
223	ZFS_AC_CONFIG_ALWAYS_CC_ASAN
224	ZFS_AC_CONFIG_ALWAYS_CC_UBSAN
225	ZFS_AC_CONFIG_ALWAYS_TOOLCHAIN_SIMD
226	ZFS_AC_CONFIG_ALWAYS_SYSTEM
227	ZFS_AC_CONFIG_ALWAYS_ARCH
228	ZFS_AC_CONFIG_ALWAYS_PYTHON
229	ZFS_AC_CONFIG_ALWAYS_PYZFS
230	ZFS_AC_CONFIG_ALWAYS_SED
231	ZFS_AC_CONFIG_ALWAYS_CPPCHECK
232	ZFS_AC_CONFIG_ALWAYS_SHELLCHECK
233	ZFS_AC_CONFIG_ALWAYS_PARALLEL
234])
235
236AC_DEFUN([ZFS_AC_CONFIG], [
237
238        dnl # Remove the previous build test directory.
239        rm -Rf build
240
241	ZFS_CONFIG=all
242	AC_ARG_WITH([config],
243		AS_HELP_STRING([--with-config=CONFIG],
244		[Config file 'kernel|user|all|srpm']),
245		[ZFS_CONFIG="$withval"])
246	AC_ARG_ENABLE([linux-builtin],
247		[AS_HELP_STRING([--enable-linux-builtin],
248		[Configure for builtin in-tree kernel modules @<:@default=no@:>@])],
249		[],
250		[enable_linux_builtin=no])
251
252	AC_MSG_CHECKING([zfs config])
253	AC_MSG_RESULT([$ZFS_CONFIG]);
254	AC_SUBST(ZFS_CONFIG)
255
256	ZFS_AC_CONFIG_ALWAYS
257
258	AM_COND_IF([BUILD_LINUX], [
259		AC_ARG_VAR([TEST_JOBS], [simultaneous jobs during configure])
260		if test "x$ac_cv_env_TEST_JOBS_set" != "xset"; then
261			TEST_JOBS=$CPU_COUNT
262		fi
263		AC_SUBST(TEST_JOBS)
264	])
265
266	ZFS_INIT_SYSV=
267	ZFS_INIT_SYSTEMD=
268	ZFS_WANT_MODULES_LOAD_D=
269
270	case "$ZFS_CONFIG" in
271		kernel) ZFS_AC_CONFIG_KERNEL ;;
272		user)	ZFS_AC_CONFIG_USER   ;;
273		all)    ZFS_AC_CONFIG_USER
274			ZFS_AC_CONFIG_KERNEL ;;
275		dist)                        ;;
276		srpm)                        ;;
277		*)
278		AC_MSG_RESULT([Error!])
279		AC_MSG_ERROR([Bad value "$ZFS_CONFIG" for --with-config,
280		              user kernel|user|all|srpm]) ;;
281	esac
282
283	AM_CONDITIONAL([INIT_SYSV],           [test "x$ZFS_INIT_SYSV" = "xyes"])
284	AM_CONDITIONAL([INIT_SYSTEMD],        [test "x$ZFS_INIT_SYSTEMD" = "xyes"])
285	AM_CONDITIONAL([WANT_MODULES_LOAD_D], [test "x$ZFS_WANT_MODULES_LOAD_D" = "xyes"])
286
287	AM_CONDITIONAL([CONFIG_USER],
288	    [test "$ZFS_CONFIG" = user -o "$ZFS_CONFIG" = all])
289	AM_CONDITIONAL([CONFIG_KERNEL],
290	    [test "$ZFS_CONFIG" = kernel -o "$ZFS_CONFIG" = all] &&
291	    [test "x$enable_linux_builtin" != xyes ])
292	AM_CONDITIONAL([CONFIG_QAT],
293	    [test "$ZFS_CONFIG" = kernel -o "$ZFS_CONFIG" = all] &&
294	    [test "x$qatsrc" != x ])
295	AM_CONDITIONAL([WANT_DEVNAME2DEVID], [test "x$user_libudev" = xyes ])
296	AM_CONDITIONAL([WANT_MMAP_LIBAIO], [test "x$user_libaio" = xyes ])
297	AM_CONDITIONAL([PAM_ZFS_ENABLED], [test "x$enable_pam" = xyes])
298])
299
300dnl #
301dnl # Check for rpm+rpmbuild to build RPM packages.  If these tools
302dnl # are missing it is non-fatal but you will not be able to build
303dnl # RPM packages and will be warned if you try too.
304dnl #
305dnl # By default the generic spec file will be used because it requires
306dnl # minimal dependencies.  Distribution specific spec files can be
307dnl # placed under the 'rpm/<distribution>' directory and enabled using
308dnl # the --with-spec=<distribution> configure option.
309dnl #
310AC_DEFUN([ZFS_AC_RPM], [
311	RPM=rpm
312	RPMBUILD=rpmbuild
313
314	AC_MSG_CHECKING([whether $RPM is available])
315	AS_IF([tmp=$($RPM --version 2>/dev/null)], [
316		RPM_VERSION=$(echo $tmp | $AWK '/RPM/ { print $[3] }')
317		HAVE_RPM=yes
318		AC_MSG_RESULT([$HAVE_RPM ($RPM_VERSION)])
319	],[
320		HAVE_RPM=no
321		AC_MSG_RESULT([$HAVE_RPM])
322	])
323
324	AC_MSG_CHECKING([whether $RPMBUILD is available])
325	AS_IF([tmp=$($RPMBUILD --version 2>/dev/null)], [
326		RPMBUILD_VERSION=$(echo $tmp | $AWK '/RPM/ { print $[3] }')
327		HAVE_RPMBUILD=yes
328		AC_MSG_RESULT([$HAVE_RPMBUILD ($RPMBUILD_VERSION)])
329	],[
330		HAVE_RPMBUILD=no
331		AC_MSG_RESULT([$HAVE_RPMBUILD])
332	])
333
334	RPM_DEFINE_COMMON='--define "$(DEBUG_ZFS) 1"'
335	RPM_DEFINE_COMMON=${RPM_DEFINE_COMMON}' --define "$(DEBUGINFO_ZFS) 1"'
336	RPM_DEFINE_COMMON=${RPM_DEFINE_COMMON}' --define "$(DEBUG_KMEM_ZFS) 1"'
337	RPM_DEFINE_COMMON=${RPM_DEFINE_COMMON}' --define "$(DEBUG_KMEM_TRACKING_ZFS) 1"'
338	RPM_DEFINE_COMMON=${RPM_DEFINE_COMMON}' --define "$(ASAN_ZFS) 1"'
339	RPM_DEFINE_COMMON=${RPM_DEFINE_COMMON}' --define "$(UBSAN_ZFS) 1"'
340
341	AS_IF([test "x$enable_debuginfo" = xyes], [
342		RPM_DEFINE_COMMON=${RPM_DEFINE_COMMON}' --define "__strip /bin/true"'
343	])
344
345	RPM_DEFINE_UTIL=' --define "_initconfdir $(initconfdir)"'
346
347	dnl # Make the next three RPM_DEFINE_UTIL additions conditional, since
348	dnl # their values may not be set when running:
349	dnl #
350	dnl #	./configure --with-config=srpm
351	dnl #
352	AS_IF([test -n "$dracutdir" ], [
353		RPM_DEFINE_UTIL=${RPM_DEFINE_UTIL}' --define "_dracutdir $(dracutdir)"'
354	])
355	AS_IF([test -n "$udevdir" ], [
356		RPM_DEFINE_UTIL=${RPM_DEFINE_UTIL}' --define "_udevdir $(udevdir)"'
357	])
358	AS_IF([test -n "$udevruledir" ], [
359		RPM_DEFINE_UTIL=${RPM_DEFINE_UTIL}' --define "_udevruledir $(udevruledir)"'
360	])
361	AS_IF([test -n "$bashcompletiondir" ], [
362		RPM_DEFINE_UTIL=${RPM_DEFINE_UTIL}' --define "_bashcompletiondir $(bashcompletiondir)"'
363	])
364	RPM_DEFINE_UTIL=${RPM_DEFINE_UTIL}' $(DEFINE_SYSTEMD)'
365	RPM_DEFINE_UTIL=${RPM_DEFINE_UTIL}' $(DEFINE_PYZFS)'
366	RPM_DEFINE_UTIL=${RPM_DEFINE_UTIL}' $(DEFINE_PAM)'
367	RPM_DEFINE_UTIL=${RPM_DEFINE_UTIL}' $(DEFINE_PYTHON_VERSION)'
368	RPM_DEFINE_UTIL=${RPM_DEFINE_UTIL}' $(DEFINE_PYTHON_PKG_VERSION)'
369
370	dnl # Override default lib directory on Debian/Ubuntu systems.  The
371	dnl # provided /usr/lib/rpm/platform/<arch>/macros files do not
372	dnl # specify the correct path for multiarch systems as described
373	dnl # by the packaging guidelines.
374	dnl #
375	dnl # https://wiki.ubuntu.com/MultiarchSpec
376	dnl # https://wiki.debian.org/Multiarch/Implementation
377	dnl #
378	AS_IF([test "$DEFAULT_PACKAGE" = "deb"], [
379		MULTIARCH_LIBDIR="lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)"
380		RPM_DEFINE_UTIL=${RPM_DEFINE_UTIL}' --define "_lib $(MULTIARCH_LIBDIR)"'
381		AC_SUBST(MULTIARCH_LIBDIR)
382	])
383
384	dnl # Make RPM_DEFINE_KMOD additions conditional on CONFIG_KERNEL,
385	dnl # since the values will not be set otherwise. The spec files
386	dnl # provide defaults for them.
387	dnl #
388	RPM_DEFINE_KMOD='--define "_wrong_version_format_terminate_build 0"'
389	AM_COND_IF([CONFIG_KERNEL], [
390		RPM_DEFINE_KMOD=${RPM_DEFINE_KMOD}' --define "kernels $(LINUX_VERSION)"'
391		RPM_DEFINE_KMOD=${RPM_DEFINE_KMOD}' --define "ksrc $(LINUX)"'
392		RPM_DEFINE_KMOD=${RPM_DEFINE_KMOD}' --define "kobj $(LINUX_OBJ)"'
393		RPM_DEFINE_KMOD=${RPM_DEFINE_KMOD}' --define "kernel_cc KERNEL_CC=$(KERNEL_CC)"'
394		RPM_DEFINE_KMOD=${RPM_DEFINE_KMOD}' --define "kernel_ld KERNEL_LD=$(KERNEL_LD)"'
395		RPM_DEFINE_KMOD=${RPM_DEFINE_KMOD}' --define "kernel_llvm KERNEL_LLVM=$(KERNEL_LLVM)"'
396		RPM_DEFINE_KMOD=${RPM_DEFINE_KMOD}' --define "kernel_cross_compile KERNEL_CROSS_COMPILE=$(KERNEL_CROSS_COMPILE)"'
397		RPM_DEFINE_KMOD=${RPM_DEFINE_KMOD}' --define "kernel_arch KERNEL_ARCH=$(KERNEL_ARCH)"'
398	])
399
400	RPM_DEFINE_DKMS=''
401
402	SRPM_DEFINE_COMMON='--define "build_src_rpm 1"'
403	SRPM_DEFINE_UTIL=
404	SRPM_DEFINE_KMOD=
405	SRPM_DEFINE_DKMS=
406
407	RPM_SPEC_DIR="rpm/generic"
408	AC_ARG_WITH([spec],
409		AS_HELP_STRING([--with-spec=SPEC],
410		[Spec files 'generic|redhat']),
411		[RPM_SPEC_DIR="rpm/$withval"])
412
413	AC_MSG_CHECKING([whether spec files are available])
414	AC_MSG_RESULT([yes ($RPM_SPEC_DIR/*.spec.in)])
415
416	AC_SUBST(HAVE_RPM)
417	AC_SUBST(RPM)
418	AC_SUBST(RPM_VERSION)
419
420	AC_SUBST(HAVE_RPMBUILD)
421	AC_SUBST(RPMBUILD)
422	AC_SUBST(RPMBUILD_VERSION)
423
424	AC_SUBST(RPM_SPEC_DIR)
425	AC_SUBST(RPM_DEFINE_UTIL)
426	AC_SUBST(RPM_DEFINE_KMOD)
427	AC_SUBST(RPM_DEFINE_DKMS)
428	AC_SUBST(RPM_DEFINE_COMMON)
429	AC_SUBST(SRPM_DEFINE_UTIL)
430	AC_SUBST(SRPM_DEFINE_KMOD)
431	AC_SUBST(SRPM_DEFINE_DKMS)
432	AC_SUBST(SRPM_DEFINE_COMMON)
433])
434
435dnl #
436dnl # Check for dpkg+dpkg-buildpackage to build DEB packages.  If these
437dnl # tools are missing it is non-fatal but you will not be able to build
438dnl # DEB packages and will be warned if you try too.
439dnl #
440AC_DEFUN([ZFS_AC_DPKG], [
441	DPKG=dpkg
442	DPKGBUILD=dpkg-buildpackage
443
444	AC_MSG_CHECKING([whether $DPKG is available])
445	AS_IF([tmp=$($DPKG --version 2>/dev/null)], [
446		DPKG_VERSION=$(echo $tmp | $AWK '/Debian/ { print $[7] }')
447		HAVE_DPKG=yes
448		AC_MSG_RESULT([$HAVE_DPKG ($DPKG_VERSION)])
449	],[
450		HAVE_DPKG=no
451		AC_MSG_RESULT([$HAVE_DPKG])
452	])
453
454	AC_MSG_CHECKING([whether $DPKGBUILD is available])
455	AS_IF([tmp=$($DPKGBUILD --version 2>/dev/null)], [
456		DPKGBUILD_VERSION=$(echo $tmp | \
457		    $AWK '/Debian/ { print $[4] }' | cut -f-4 -d'.')
458		HAVE_DPKGBUILD=yes
459		AC_MSG_RESULT([$HAVE_DPKGBUILD ($DPKGBUILD_VERSION)])
460	],[
461		HAVE_DPKGBUILD=no
462		AC_MSG_RESULT([$HAVE_DPKGBUILD])
463	])
464
465	AC_SUBST(HAVE_DPKG)
466	AC_SUBST(DPKG)
467	AC_SUBST(DPKG_VERSION)
468
469	AC_SUBST(HAVE_DPKGBUILD)
470	AC_SUBST(DPKGBUILD)
471	AC_SUBST(DPKGBUILD_VERSION)
472	AC_SUBST([CFGOPTS], ["$CFGOPTS"])
473])
474
475dnl #
476dnl # Until native packaging for various different packing systems
477dnl # can be added the least we can do is attempt to use alien to
478dnl # convert the RPM packages to the needed package type.  This is
479dnl # a hack but so far it has worked reasonable well.
480dnl #
481AC_DEFUN([ZFS_AC_ALIEN], [
482	ALIEN=alien
483
484	AC_MSG_CHECKING([whether $ALIEN is available])
485	AS_IF([tmp=$($ALIEN --version 2>/dev/null)], [
486		ALIEN_VERSION=$(echo $tmp | $AWK '{ print $[3] }')
487		ALIEN_MAJOR=$(echo ${ALIEN_VERSION} | $AWK -F'.' '{ print $[1] }')
488		ALIEN_MINOR=$(echo ${ALIEN_VERSION} | $AWK -F'.' '{ print $[2] }')
489		ALIEN_POINT=$(echo ${ALIEN_VERSION} | $AWK -F'.' '{ print $[3] }')
490		HAVE_ALIEN=yes
491		AC_MSG_RESULT([$HAVE_ALIEN ($ALIEN_VERSION)])
492	],[
493		HAVE_ALIEN=no
494		AC_MSG_RESULT([$HAVE_ALIEN])
495	])
496
497	AC_SUBST(HAVE_ALIEN)
498	AC_SUBST(ALIEN)
499	AC_SUBST(ALIEN_VERSION)
500	AC_SUBST(ALIEN_MAJOR)
501	AC_SUBST(ALIEN_MINOR)
502	AC_SUBST(ALIEN_POINT)
503])
504
505dnl #
506dnl # Using the VENDOR tag from config.guess set the default
507dnl # package type for 'make pkg': (rpm | deb | tgz)
508dnl #
509AC_DEFUN([ZFS_AC_DEFAULT_PACKAGE], [
510	AC_MSG_CHECKING([os distribution])
511	AC_ARG_WITH([vendor],
512		[AS_HELP_STRING([--with-vendor],
513			[Distribution vendor @<:@default=check@:>@])],
514		[with_vendor=$withval],
515		[with_vendor=check])
516	AS_IF([test "x$with_vendor" = "xcheck"],[
517		if test -f /etc/alpine-release ; then
518			VENDOR=alpine ;
519		elif test -f /etc/arch-release ; then
520			VENDOR=arch ;
521		elif test -f /etc/artix-release ; then
522			VENDOR=artix ;
523		elif test -f /etc/fedora-release ; then
524			VENDOR=fedora ;
525		elif test -f /bin/freebsd-version ; then
526			VENDOR=freebsd ;
527		elif test -f /etc/gentoo-release ; then
528			VENDOR=gentoo ;
529		elif test -f /etc/lunar.release ; then
530			VENDOR=lunar ;
531		elif test -f /etc/openEuler-release ; then
532			VENDOR=openeuler ;
533		elif test -f /etc/SuSE-release ; then
534			VENDOR=sles ;
535		elif test -f /etc/slackware-version ; then
536			VENDOR=slackware ;
537		elif test -f /etc/toss-release ; then
538			VENDOR=toss ;
539		elif test -f /etc/lsb-release ; then
540			VENDOR=ubuntu ;
541		# put debian and redhat last as derivatives may have also their file
542		elif test -f /etc/debian_version ; then
543			VENDOR=debian ;
544		elif test -f /etc/redhat-release ; then
545			VENDOR=redhat ;
546		else
547			VENDOR= ;
548		fi],
549		[ test "x${with_vendor}" != x],[
550			VENDOR="$with_vendor" ],
551		[ VENDOR= ; ]
552	)
553	AC_MSG_RESULT([$VENDOR])
554	AC_SUBST(VENDOR)
555
556	AC_MSG_CHECKING([default package type])
557	case "$VENDOR" in
558		alpine|arch|artix|gentoo|lunar|slackware)
559			DEFAULT_PACKAGE=tgz  ;;
560		debian|ubuntu)
561			DEFAULT_PACKAGE=deb  ;;
562		freebsd)
563			DEFAULT_PACKAGE=pkg  ;;
564		*)
565		# fedora|openeuler|redhat|sles|toss
566			DEFAULT_PACKAGE=rpm  ;;
567	esac
568	AC_MSG_RESULT([$DEFAULT_PACKAGE])
569	AC_SUBST(DEFAULT_PACKAGE)
570
571	AC_MSG_CHECKING([default init directory])
572	case "$VENDOR" in
573		freebsd)    initdir=$sysconfdir/rc.d  ;;
574		*)          initdir=$sysconfdir/init.d;;
575	esac
576	AC_MSG_RESULT([$initdir])
577	AC_SUBST(initdir)
578
579	AC_MSG_CHECKING([default shell])
580	case "$VENDOR" in
581		alpine|gentoo)	DEFAULT_INIT_SHELL=/sbin/openrc-run
582				IS_SYSV_RC=false	;;
583		artix)		DEFAULT_INIT_SHELL=/usr/bin/openrc-run
584				IS_SYSV_RC=false	;;
585		*)		DEFAULT_INIT_SHELL=/bin/sh
586				IS_SYSV_RC=true		;;
587	esac
588
589	AC_MSG_RESULT([$DEFAULT_INIT_SHELL])
590	AC_SUBST(DEFAULT_INIT_SHELL)
591	AC_SUBST(IS_SYSV_RC)
592
593	AC_MSG_CHECKING([default nfs server init script])
594	AS_IF([test "$VENDOR" = "debian"],
595		[DEFAULT_INIT_NFS_SERVER="nfs-kernel-server"],
596		[DEFAULT_INIT_NFS_SERVER="nfs"]
597	)
598	AC_MSG_RESULT([$DEFAULT_INIT_NFS_SERVER])
599	AC_SUBST(DEFAULT_INIT_NFS_SERVER)
600
601	AC_MSG_CHECKING([default init config directory])
602	case "$VENDOR" in
603		alpine|artix|gentoo)
604			initconfdir=/etc/conf.d
605			;;
606		fedora|openeuler|redhat|sles|toss)
607			initconfdir=/etc/sysconfig
608			;;
609		freebsd)
610			initconfdir=$sysconfdir/rc.conf.d
611			;;
612		*)
613		# debian|ubuntu
614			initconfdir=/etc/default
615			;;
616	esac
617	AC_MSG_RESULT([$initconfdir])
618	AC_SUBST(initconfdir)
619
620	AC_MSG_CHECKING([whether initramfs-tools is available])
621	if test -d /usr/share/initramfs-tools ; then
622		RPM_DEFINE_INITRAMFS='--define "_initramfs 1"'
623		AC_MSG_RESULT([yes])
624	else
625		RPM_DEFINE_INITRAMFS=''
626		AC_MSG_RESULT([no])
627	fi
628	AC_SUBST(RPM_DEFINE_INITRAMFS)
629
630	AC_MSG_CHECKING([default bash completion directory])
631	case "$VENDOR" in
632		alpine|arch|artix|debian|gentoo|ubuntu)
633			bashcompletiondir=/usr/share/bash-completion/completions
634			;;
635		freebsd)
636			bashcompletiondir=$sysconfdir/bash_completion.d
637			;;
638		*)
639			bashcompletiondir=/etc/bash_completion.d
640			;;
641	esac
642	AC_MSG_RESULT([$bashcompletiondir])
643	AC_SUBST(bashcompletiondir)
644
645])
646
647dnl #
648dnl # Default ZFS package configuration
649dnl #
650AC_DEFUN([ZFS_AC_PACKAGE], [
651	ZFS_AC_DEFAULT_PACKAGE
652	AS_IF([test x$VENDOR != xfreebsd], [
653		ZFS_AC_RPM
654		ZFS_AC_DPKG
655		ZFS_AC_ALIEN
656	])
657])
658