dnl CF_MANPAGE_FORMAT version: 17 updated: 2023/01/21 16:49:25
dnl -----------------
dnl Option to allow user to override automatic configuration of manpage format.
dnl There are several special cases:
dnl
dnl	compress - man checks for, can display compressed files
dnl	bzip2 - man checks for, can display bzip2'd files
dnl	gzip - man checks for, can display gzip'd files
dnl	xz - man checks for, can display xz'd files
dnl
dnl	BSDI - files in the cat-directories are suffixed ".0"
dnl	formatted - installer should format (put files in cat-directory)
dnl	catonly - installer should only format, e.g., for a turnkey system.
dnl
dnl There are other configurations which this macro does not test, e.g., HPUX's
dnl compressed manpages (but uncompressed manpages are fine, and HPUX's naming
dnl convention would not match our use).
AC_DEFUN([CF_MANPAGE_FORMAT],
[
AC_REQUIRE([CF_PATHSEP])
AC_MSG_CHECKING(format of man-pages)

AC_ARG_WITH(manpage-format,
	[  --with-manpage-format   specify manpage-format: gzip/compress/bzip2/xz,
                          BSDI/normal and optionally formatted/catonly,
                          e.g., gzip,formatted],
	[MANPAGE_FORMAT=$withval],
	[MANPAGE_FORMAT=unknown])

test -z "$MANPAGE_FORMAT" && MANPAGE_FORMAT=unknown
MANPAGE_FORMAT=`echo "$MANPAGE_FORMAT" | sed -e 's/,/ /g'`

cf_unknown=

case "$MANPAGE_FORMAT" in
(unknown)
	if test -z "$MANPATH" ; then
		MANPATH="/usr/man:/usr/share/man"
	fi

	# look for the 'date' man-page (it is most likely to be installed!)
	MANPAGE_FORMAT=
	cf_preform="no"
	cf_catonly="yes"
	cf_example="date"

	IFS="${IFS:- 	}"; ac_save_ifs="$IFS"; IFS="${IFS}${PATH_SEPARATOR}"
	for cf_dir in $MANPATH; do
		test -z "$cf_dir" && cf_dir=/usr/man
		for cf_name in $cf_dir/man*/$cf_example.[[01]]* $cf_dir/cat*/$cf_example.[[01]]* $cf_dir/man*/$cf_example $cf_dir/cat*/$cf_example
		do
			cf_test=`echo "$cf_name" | sed -e 's/*//'`
			if test "x$cf_test" = "x$cf_name" ; then

				case "$cf_name" in
				(*.bz2) MANPAGE_FORMAT="$MANPAGE_FORMAT bzip2";;
				(*.xz)  MANPAGE_FORMAT="$MANPAGE_FORMAT xz";;
				(*.gz)  MANPAGE_FORMAT="$MANPAGE_FORMAT gzip";;
				(*.Z)   MANPAGE_FORMAT="$MANPAGE_FORMAT compress";;
				(*.0)   MANPAGE_FORMAT="$MANPAGE_FORMAT BSDI";;
				(*)     MANPAGE_FORMAT="$MANPAGE_FORMAT normal";;
				esac

				case "$cf_name" in
				($cf_dir/man*)
					cf_catonly=no
					;;
				($cf_dir/cat*)
					cf_preform=yes
					;;
				esac
				break
			fi

			# if we found a match in either man* or cat*, stop looking
			if test -n "$MANPAGE_FORMAT" ; then
				cf_found=no
				test "$cf_preform" = yes && MANPAGE_FORMAT="$MANPAGE_FORMAT formatted"
				test "$cf_catonly" = yes && MANPAGE_FORMAT="$MANPAGE_FORMAT catonly"
				case "$cf_name" in
				($cf_dir/cat*)
					cf_found=yes
					;;
				esac
				test "$cf_found" = yes && break
			fi
		done
		# only check the first directory in $MANPATH where we find manpages
		if test -n "$MANPAGE_FORMAT" ; then
			break
		fi
	done
	# if we did not find the example, just assume it is normal
	test -z "$MANPAGE_FORMAT" && MANPAGE_FORMAT=normal
	IFS="$ac_save_ifs"
	;;
(*)
	for cf_option in $MANPAGE_FORMAT; do
	case "$cf_option" in
	(xz|bzip2|gzip|compress|BSDI|normal|formatted|catonly)
		;;
	(*)
		cf_unknown="$cf_unknown $cf_option"
		;;
	esac
	done
	;;
esac

AC_MSG_RESULT($MANPAGE_FORMAT)
if test -n "$cf_unknown" ; then
	AC_MSG_WARN(Unexpected manpage-format $cf_unknown)
fi

cf_manpage_format=no
cf_manpage_inboth=no
cf_manpage_so_strip=
cf_manpage_compress=

for cf_item in $MANPAGE_FORMAT
do
case "$cf_item" in
(catonly)
	cf_manpage_format=yes
	cf_manpage_inboth=no
	;;
(formatted)
	cf_manpage_format=yes
	cf_manpage_inboth=yes
	;;
(compress)
	cf_manpage_so_strip="Z"
	cf_manpage_compress=compress
	;;
(gzip)
	cf_manpage_so_strip="gz"
	cf_manpage_compress=gzip
	;;
(bzip2)
	cf_manpage_so_strip="bz2"
	cf_manpage_compress=bzip2
	;;
(xz)
	cf_manpage_so_strip="xz"
	cf_manpage_compress=xz
	;;
esac
done

])dnl
