dnl CF_MAN_PAGES version: 61 updated: 2025/02/15 19:13:25
dnl ------------
dnl Try to determine if the man-pages on the system are compressed, and if
dnl so, what format is used.  Use this information to construct a script that
dnl will install man-pages.
AC_DEFUN([CF_MAN_PAGES],
[
CF_HELP_MESSAGE(Options to Specify How Manpages are Installed:)
CF_MANPAGE_FORMAT
CF_MANPAGE_RENAMES
CF_MANPAGE_SYMLINKS
CF_MANPAGE_TBL

if test "$prefix" = "NONE" ; then
	cf_prefix="$ac_default_prefix"
else
	cf_prefix="$prefix"
fi

test ! -d man && mkdir man

cf_edit_man=./edit_man.sh
cf_man_alias=`pwd`/man_alias.sed

cat >$cf_edit_man <<CF_EOF
#! $SHELL
# this script is generated by the configure-script CF_MAN_PAGES macro.

prefix="$cf_prefix"
datarootdir="$datarootdir"
datadir="$datadir"

NCURSES_MAJOR="$NCURSES_MAJOR"
NCURSES_MINOR="$NCURSES_MINOR"
NCURSES_PATCH="$NCURSES_PATCH"

NCURSES_OSPEED="$NCURSES_OSPEED"
TERMINFO="$TERMINFO"
TERMINFO_DIRS="$TERMINFO_DIRS"

INSTALL="$INSTALL"
INSTALL_DATA="$INSTALL_DATA"

transform="$program_transform_name"

TMP=\${TMPDIR:=/tmp}/man\$\$
trap "rm -f \$TMP; exit 1" 1 2 3 15
trap "rm -f \$TMP" 0

form=\[$]1
shift || exit 1

verb=\[$]1
shift || exit 1

mandir=\[$]1
shift || exit 1

srcdir=\[$]1
top_srcdir=\[$]srcdir/..
shift || exit 1

if test "\$form" = normal ; then
	if test "$cf_manpage_format" = yes ; then
	if test "$cf_manpage_inboth" = no ; then
		$SHELL "\[$]0" format "\$verb" "\$mandir" "\$srcdir" "\[$]@"
		exit $?
	fi
	fi
	cf_subdir=\$mandir/man
	cf_tables=$MANPAGE_TBL
else
	cf_subdir=\$mandir/cat
	cf_tables=yes
fi

# process the list of source-files
for i in "\[$]@" ; do
case \$i in
(*.orig|*.rej) ;;
(*.[[0-9]]*)
	section=\`expr "\$i" : '.*\\.\\([[0-9]]\\)[[xm]]*'\`;
	if test "\$verb" = installing ; then
	if test ! -d "\$cf_subdir\${section}" ; then
		mkdir -p "\$cf_subdir\$section"
	fi
	fi

	# replace variables in man page
	if test ! -f "$cf_man_alias" ; then
cat >>$cf_man_alias <<-CF_EOF2
		s,@DATADIR@,\$datadir,g
		s,@TERMINFO@,\${TERMINFO:="no default value"},g
		s,@TERMINFO_DIRS@,\${TERMINFO_DIRS:="no default value"},g
		s,@NCURSES_MAJOR@,\${NCURSES_MAJOR:="no default value"},g
		s,@NCURSES_MINOR@,\${NCURSES_MINOR:="no default value"},g
		s,@NCURSES_PATCH@,\${NCURSES_PATCH:="no default value"},g
		s,@NCURSES_OSPEED@,\${NCURSES_OSPEED:="no default value"},g
CF_EOF
	ifelse($1,,,[
	for cf_name in $1
	do
		cf_NAME=`echo "$cf_name" | sed y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%`
		cf_name=`echo "$cf_name" | sed "$program_transform_name"`
cat >>$cf_edit_man <<-CF_EOF
		s,@$cf_NAME@,$cf_name,g
CF_EOF
	done
	])
cat >>$cf_edit_man <<CF_EOF
CF_EOF2
		echo "...made $cf_man_alias"
	fi

	aliases=
	cf_source=\`basename "\$i"\`
	cf_full_alias=\$cf_source
	test ! -f "\$cf_full_alias" && cf_full_alias="\$srcdir/\$cf_full_alias"
	if test ! -f "\$cf_full_alias" ; then
		echo ".. skipped \$cf_source"
		continue
	fi
CF_EOF

if test "$MANPAGE_ALIASES" != no ; then
cat >>$cf_edit_man <<CF_EOF
	nCurses=ignore.3x
	cf_part_alias=\`echo \$cf_full_alias| sed -e 's,^.*/,,'\`
	test "$with_curses_h" = yes && nCurses=ncurses.3x
	aliases=\`sed -f "\$top_srcdir/man/manlinks.sed" "\$cf_full_alias" |sed -f "$cf_man_alias" | sort -u; test "\$cf_part_alias" = "\$nCurses" && echo curses\`
CF_EOF
fi

if test "$MANPAGE_RENAMES" = no ; then
cat >>$cf_edit_man <<CF_EOF
	# perform program transformations for section 1 man pages
	if test \$section = 1 ; then
		cf_target=\$cf_subdir\${section}/\`echo \$cf_source|sed "\${transform}"\`
	else
		cf_target=\$cf_subdir\${section}/\$cf_source
	fi
CF_EOF
else
cat >>$cf_edit_man <<CF_EOF
	cf_target=\`grep "^\$cf_source" $MANPAGE_RENAMES | $AWK '{print \[$]2}'\`
	if test -z "\$cf_target" ; then
		echo "? missing rename for \$cf_source"
		cf_target="\$cf_source"
	fi
	cf_target="\$cf_subdir\${section}/\${cf_target}"

CF_EOF
fi

cat >>$cf_edit_man <<CF_EOF
	sed	-f "$cf_man_alias" \\
CF_EOF

if test "$MANPAGE_RENAMES" != no ; then
cat >>$cf_edit_man <<CF_EOF
		< "\$i" | sed -f `pwd`/edit_man.sed >\$TMP
CF_EOF
else
cat >>$cf_edit_man <<CF_EOF
		< "\$i" >\$TMP
CF_EOF
fi

cat >>$cf_edit_man <<CF_EOF
if test \$cf_tables = yes ; then
	tbl \$TMP >\$TMP.out
	mv \$TMP.out \$TMP
fi
CF_EOF

if test "$with_overwrite" != yes ; then
cat >>$cf_edit_man <<CF_EOF
	sed -e "/\\#[    ]*include/s,<curses.h,<ncurses$LIB_SUFFIX/curses.h," \
	    -e "/\\#[    ]*include/s,<term.h,<ncurses$LIB_SUFFIX/term.h," \
	  < \$TMP >\$TMP.out
	mv \$TMP.out \$TMP
CF_EOF
fi

if test "$with_curses_h" != yes ; then
cat >>$cf_edit_man <<CF_EOF
	sed -e "/\\#[    ]*include/s,curses.h,ncurses.h," \
	  < \$TMP >\$TMP.out
	mv \$TMP.out \$TMP
CF_EOF
fi

cat >>$cf_edit_man <<CF_EOF
	if test "\$form" = format ; then
		nroff -man \$TMP >\$TMP.out
		mv \$TMP.out \$TMP
	fi
CF_EOF

if test -n "$cf_manpage_compress" ; then
cat >>$cf_edit_man <<CF_EOF
	if test "\$verb" = installing ; then
	if ( "$cf_manpage_compress" $cf_manpage_coptions -f \$TMP )
	then
		mv \$TMP.$cf_manpage_so_strip \$TMP
	fi
	fi
	cf_target="\$cf_target.$cf_manpage_so_strip"
CF_EOF
fi

case "$MANPAGE_FORMAT" in
(*BSDI*)
cat >>$cf_edit_man <<CF_EOF
	if test "\$form" = format ; then
		# BSDI installs only .0 suffixes in the cat directories
		cf_target="\`echo \$cf_target|sed -e 's/\\.[[1-9]]\\+[[a-z]]*/.0/'\`"
	fi
CF_EOF
  ;;
esac

cat >>$cf_edit_man <<CF_EOF
	suffix=\`basename "\$cf_target" | sed -e 's%^[[^.]]*%%'\`
	extra_suffix=
	if test -n "$EXTRA_SUFFIX" ; then
		case \$cf_target in
		(*${EXTRA_SUFFIX}\$suffix)
			extra_suffix="$EXTRA_SUFFIX"
			;;
		esac
	fi
	if test "\$verb" = installing ; then
		echo "\$verb \$cf_target"
		\$INSTALL_DATA \$TMP "\$cf_target"
		test -d "\$cf_subdir\${section}" &&
		test -n "\$aliases" && (
			cd "\$cf_subdir\${section}" && (
				cf_source=\`echo "\$cf_target" |sed -e 's%^.*/\\([[^/]][[^/]]*/[[^/]][[^/]]*$\\)%\\1%'\`
				test -n "$cf_manpage_so_strip" && cf_source=\`echo "\$cf_source" |sed -e 's%\\.$cf_manpage_so_strip\$%%'\`
				cf_target=\`basename "\$cf_target"\`
				for cf_alias in \$aliases
				do
					if test "\$section" = 1 ; then
						cf_alias=\`echo "\$cf_alias" |sed "\${transform}"\`
					fi
					cf_alias="\${cf_alias}\${extra_suffix}"

					if test "$MANPAGE_SYMLINKS" = yes ; then
						if test -f "\$cf_alias\${suffix}" ; then
							if ( cmp -s "\$cf_target" "\$cf_alias\${suffix}" )
							then
								continue
							fi
						fi
						echo ".. \$verb alias \$cf_alias\${suffix}"
CF_EOF
case "x$LN_S" in
(*-f)
cat >>$cf_edit_man <<CF_EOF
						$LN_S "\$cf_target" "\$cf_alias\${suffix}"
CF_EOF
	;;
(*)
cat >>$cf_edit_man <<CF_EOF
						rm -f "\$cf_alias\${suffix}"
						$LN_S "\$cf_target" "\$cf_alias\${suffix}"
CF_EOF
	;;
esac
cat >>$cf_edit_man <<CF_EOF
					elif test "\$cf_target" != "\$cf_alias\${suffix}" ; then
						echo ".so \$cf_source" >\$TMP
CF_EOF
if test -n "$cf_manpage_compress" ; then
cat >>$cf_edit_man <<CF_EOF
						if test -n "$cf_manpage_so_strip" ; then
							"$cf_manpage_compress" $cf_manpage_coptions -f \$TMP
							mv \$TMP.$cf_manpage_so_strip \$TMP
						fi
CF_EOF
fi
cat >>$cf_edit_man <<CF_EOF
						echo ".. \$verb alias \$cf_alias\${suffix}"
						rm -f "\$cf_alias\${suffix}"
						\$INSTALL_DATA \$TMP "\$cf_alias\${suffix}"
					fi
				done
			)
		)
	elif test "\$verb" = removing ; then
		test -f "\$cf_target" && (
			echo "\$verb \$cf_target"
			rm -f "\$cf_target"
		)
		test -d "\$cf_subdir\${section}" &&
		test -n "\$aliases" && (
			cd "\$cf_subdir\${section}" && (
				for cf_alias in \$aliases
				do
					if test "\$section" = 1 ; then
						cf_alias=\`echo "\$cf_alias" |sed "\${transform}"\`
					fi
					cf_alias="\${cf_alias}\${extra_suffix}"

					echo ".. \$verb alias \$cf_alias\${suffix}"
					rm -f "\$cf_alias\${suffix}"
				done
			)
		)
	else
#		echo ".hy 0"
		cat \$TMP
	fi
	;;
esac
done

if test "$cf_manpage_inboth" = yes ; then
if test "\$form" != format ; then
	$SHELL "\[$]0" format "\$verb" "\$mandir" "\$srcdir" "\[$]@"
fi
fi

exit 0
CF_EOF
chmod 755 "$cf_edit_man"

])dnl
