dnl CF_LIB_RULES version: 86 updated: 2015/11/07 20:01:34
dnl ------------
dnl Append definitions and rules for the given models to the subdirectory
dnl Makefiles, and the recursion rule for the top-level Makefile.  If the
dnl subdirectory is a library-source directory, modify the Libs_To_Make list in
dnl the corresponding makefile to list the models that we'll generate.
dnl
dnl For shared libraries, make a list of symbolic links to construct when
dnl generating each library.  The convention used for Linux is the simplest
dnl one:
dnl	lib<name>.so	->
dnl	lib<name>.so.<major>	->
dnl	lib<name>.so.<maj>.<minor>
dnl
dnl Note: Libs_To_Make is mixed case, since it is not a pure autoconf variable.
AC_DEFUN([CF_LIB_RULES],
[
cf_prefix=$LIB_PREFIX
AC_REQUIRE([CF_SUBST_NCURSES_VERSION])

case $cf_cv_shlib_version in
(cygdll|msysdll|mingw)
	TINFO_NAME=$TINFO_ARG_SUFFIX
	TINFO_SUFFIX=.dll
	;;
esac

if test -n "$TINFO_SUFFIX" ; then
	case $TINFO_SUFFIX in
	(tw*)
		TINFO_NAME="${TINFO_NAME}tw${EXTRA_SUFFIX}"
		TINFO_SUFFIX=`echo $TINFO_SUFFIX | sed 's/^tw'$EXTRA_SUFFIX'//'`
		;;
	(t*)
		TINFO_NAME="${TINFO_NAME}t${EXTRA_SUFFIX}"
		TINFO_SUFFIX=`echo $TINFO_SUFFIX | sed 's/^t'$EXTRA_SUFFIX'//'`
		;;
	(w*)
		TINFO_NAME="${TINFO_NAME}w${EXTRA_SUFFIX}"
		TINFO_SUFFIX=`echo $TINFO_SUFFIX | sed 's/^w'$EXTRA_SUFFIX'//'`
		;;
	esac
fi

for cf_dir in $SRC_SUBDIRS
do
	if test ! -d $srcdir/$cf_dir ; then
		continue
	elif test -f $srcdir/$cf_dir/modules; then

		SHARED_LIB=
		Libs_To_Make=
		cf_awk_program=
		if test -n "${cf_cv_abi_version}" && test "x${cf_cv_abi_version}" != "x5"
		then
			cf_awk_program="$cf_awk_program\
/deprecated in ABI${cf_cv_abi_version}/ { next; }\
{ sub(\"NCURSES([[WT]]+)?\", \"&${cf_cv_abi_version}\"); }\
"
		fi

		if test "x$WILDCARD_SYMS" = xno
		then
			cf_awk_program="$cf_awk_program\
/[[ 	]]_\\*;/ { skip=1; next; }\
"
		fi

		if test "x$cf_awk_program" != "x"
		then
			cat >>$cf_dir/Makefile <<CF_EOF

# Generated by CF_LIB_RULES
resulting.map: $UNALTERED_SYMS
	$AWK 'BEGIN { skip = 1; last=""; } \
$cf_awk_program \
{ if ( last != "" && ( skip == 0 || \[$]\[$]0 !~ /}/ ) ) { print last; }\
 skip = 0; last = \[$]\[$]0; } \
END { print last; }' < $UNALTERED_SYMS >\[$]@

distclean::
	rm -f resulting.map
CF_EOF
		fi

		for cf_item in $cf_LIST_MODELS
		do
			CF_LIB_SUFFIX($cf_item,cf_suffix,cf_depsuf)
			cf_libname=$cf_dir
			test "$cf_dir" = c++ && cf_libname=ncurses++
			if test $cf_item = shared ; then
				if test -n "${LIB_SUFFIX}"
				then
					cf_shared_suffix=`echo "$cf_suffix" | sed 's/^'"${USE_LIB_SUFFIX}"'//'`
				else
					cf_shared_suffix="$cf_suffix"
				fi
				if test "$cf_cv_do_symlinks" = yes ; then
					cf_version_name=

					case "$cf_cv_shlib_version" in
					(rel)
						cf_version_name=REL_VERSION
						;;
					(abi)
						cf_version_name=ABI_VERSION
						;;
					esac

					if test -n "$cf_version_name"
					then
						case "$cf_cv_system_name" in
						(darwin*)
							# "w", etc?
							cf_suffix="${USE_LIB_SUFFIX}"'.${'$cf_version_name'}'"$cf_shared_suffix"
							;;
						(*)
							cf_suffix="$cf_suffix"'.${'$cf_version_name'}'
							;;
						esac
					fi
					if test -n "${USE_LIB_SUFFIX}"
					then
						cf_shared_suffix=`echo "$cf_suffix" | sed 's/^'"${USE_LIB_SUFFIX}"'//'`
					else
						cf_shared_suffix="$cf_suffix"
					fi
				fi
				# cygwin needs import library, and has unique naming convention
				# use autodetected ${cf_prefix} for import lib and static lib, but
				# use 'cyg' prefix for shared lib.
				case $cf_cv_shlib_version in
				(cygdll)
					cf_cygsuf=`echo "$cf_suffix" | sed -e 's/\.dll/\${ABI_VERSION}.dll/'`
					cf_add_lib="../lib/cyg${cf_libname}${cf_cygsuf}"
					;;
				(msysdll)
					cf_cygsuf=`echo "$cf_suffix" | sed -e 's/\.dll/\${ABI_VERSION}.dll/'`
					cf_add_lib="../lib/msys-${cf_libname}${cf_cygsuf}"
					;;
				(mingw)
					cf_cygsuf=`echo "$cf_suffix" | sed -e 's/\.dll/\${ABI_VERSION}.dll/'`
					cf_add_lib="../lib/lib${cf_libname}${cf_cygsuf}"
					;;
				(*)
					cf_add_lib=
					;;
				esac
				if test -n "$cf_add_lib"
				then
					Libs_To_Make="$Libs_To_Make $cf_add_lib"
					continue
				fi
			fi
			cf_add_lib="../lib/${cf_prefix}${cf_libname}${cf_suffix}"
			Libs_To_Make="$Libs_To_Make $cf_add_lib"
		done

		if test $cf_dir = ncurses ; then
			cf_subsets="$LIB_SUBSETS"
			cf_r_parts="$cf_subsets"
			cf_liblist="$Libs_To_Make"

			while test -n "$cf_r_parts"
			do
				cf_l_parts=`echo "$cf_r_parts" |sed -e 's/ .*$//'`
				cf_r_parts=`echo "$cf_r_parts" |sed -e 's/^[[^ ]]* //'`
				if test "$cf_l_parts" != "$cf_r_parts" ; then
					cf_add_lib=
					case $cf_l_parts in
					(*termlib*)
						cf_add_lib=`echo $cf_liblist |sed -e s%${LIB_NAME}${USE_LIB_SUFFIX}%${TINFO_LIB_SUFFIX}%g`
						;;
					(*ticlib*)
						cf_add_lib=`echo $cf_liblist |sed -e s%${LIB_NAME}${USE_LIB_SUFFIX}%${TICS_LIB_SUFFIX}%g`
						;;
					(*)
						break
						;;
					esac
					if test -n "$cf_add_lib"; then
						Libs_To_Make="$cf_add_lib $Libs_To_Make"
					fi
				else
					break
				fi
			done
		else
			cf_subsets=`echo "$LIB_SUBSETS" | sed -e 's/^termlib.* //'`
		fi

		if test $cf_dir = c++; then
			if test "x$with_shared_cxx" != xyes && test -n "$cf_shared_suffix"; then
				cf_list=
				for cf_item in $Libs_To_Make
				do
					case $cf_item in
					(*.a)
						;;
					(*)
						cf_item=`echo "$cf_item" | sed -e "s,"$cf_shared_suffix",.a,"`
						;;
					esac
					for cf_test in $cf_list
					do
						if test "$cf_test" = "$cf_item"
						then
							cf_LIST_MODELS=`echo "$cf_LIST_MODELS" | sed -e 's/normal//'`
							cf_item=
							break
						fi
					done
					test -n "$cf_item" && cf_list="$cf_list $cf_item"
				done
				Libs_To_Make="$cf_list"
			fi
		fi

		sed -e "s%@Libs_To_Make@%$Libs_To_Make%" \
		    -e "s%@SHARED_LIB@%$SHARED_LIB%" \
			$cf_dir/Makefile >$cf_dir/Makefile.out
		mv $cf_dir/Makefile.out $cf_dir/Makefile

		$AWK -f $srcdir/mk-0th.awk \
			libname="${cf_dir}${LIB_SUFFIX}" subsets="$LIB_SUBSETS" ticlib="$TICS_LIB_SUFFIX" termlib="$TINFO_LIB_SUFFIX" \
			$srcdir/$cf_dir/modules >>$cf_dir/Makefile

		for cf_subset in $cf_subsets
		do
			cf_subdirs=
			for cf_item in $cf_LIST_MODELS
			do

			echo "Appending rules for ${cf_item} model (${cf_dir}: ${cf_subset})"
			CF_UPPER(cf_ITEM,$cf_item)

			CXX_MODEL=$cf_ITEM
			if test "$CXX_MODEL" = SHARED; then
				case $cf_cv_shlib_version in
				(cygdll|msysdll|mingw)
					test "x$with_shared_cxx" = xno && CF_VERBOSE(overriding CXX_MODEL to SHARED)
					with_shared_cxx=yes
					;;
				(*)
					test "x$with_shared_cxx" = xno && CXX_MODEL=NORMAL
					;;
				esac
			fi

			CF_LIB_SUFFIX($cf_item,cf_suffix,cf_depsuf)
			CF_OBJ_SUBDIR($cf_item,cf_subdir)

			# Test for case where we build libtinfo with a different name.
			cf_libname=$cf_dir
			if test $cf_dir = ncurses ; then
				case $cf_subset in
				(*base*)
					cf_libname=${cf_libname}$USE_LIB_SUFFIX
					;;
				(*termlib*)
					cf_libname=$TINFO_LIB_SUFFIX
					;;
				(ticlib*)
					cf_libname=$TICS_LIB_SUFFIX
					;;
				esac
			elif test $cf_dir = c++ ; then
				cf_libname=ncurses++$USE_LIB_SUFFIX
			else
				cf_libname=${cf_libname}$USE_LIB_SUFFIX
			fi
			if test -n "${USE_ARG_SUFFIX}" ; then
				# undo $USE_LIB_SUFFIX add-on in CF_LIB_SUFFIX
				cf_suffix=`echo $cf_suffix |sed -e "s%^${USE_LIB_SUFFIX}%%"`
			fi

			# These dependencies really are for development, not
			# builds, but they are useful in porting, too.
			cf_depend="../include/ncurses_cfg.h"
			if test "$srcdir" = "."; then
				cf_reldir="."
			else
				cf_reldir="\${srcdir}"
			fi

			if test -f $srcdir/$cf_dir/$cf_dir.priv.h; then
				cf_depend="$cf_depend $cf_reldir/$cf_dir.priv.h"
			elif test -f $srcdir/$cf_dir/curses.priv.h; then
				cf_depend="$cf_depend $cf_reldir/curses.priv.h"
			fi

 			cf_dir_suffix=
 			old_cf_suffix="$cf_suffix"
 			if test "$cf_cv_shlib_version_infix" = yes ; then
			if test -n "$USE_LIB_SUFFIX" ; then
				case $USE_LIB_SUFFIX in
				(tw*)
					cf_libname=`echo $cf_libname | sed 's/tw'$EXTRA_SUFFIX'$//'`
					cf_suffix=`echo $cf_suffix | sed 's/^tw'$EXTRA_SUFFIX'//'`
					cf_dir_suffix=tw$EXTRA_SUFFIX
					;;
				(t*)
					cf_libname=`echo $cf_libname | sed 's/t'$EXTRA_SUFFIX'$//'`
					cf_suffix=`echo $cf_suffix | sed 's/^t'$EXTRA_SUFFIX'//'`
					cf_dir_suffix=t$EXTRA_SUFFIX
					;;
				(w*)
					cf_libname=`echo $cf_libname | sed 's/w'$EXTRA_SUFFIX'$//'`
					cf_suffix=`echo $cf_suffix | sed 's/^w'$EXTRA_SUFFIX'//'`
					cf_dir_suffix=w$EXTRA_SUFFIX
					;;
				(*)
					cf_libname=`echo $cf_libname | sed 's/'$EXTRA_SUFFIX'$//'`
					cf_suffix=`echo $cf_suffix | sed 's/^'$EXTRA_SUFFIX'//'`
					cf_dir_suffix=$EXTRA_SUFFIX
					;;
				esac
			fi
 			fi

			$AWK -f $srcdir/mk-1st.awk \
				name=${cf_libname}${cf_dir_suffix} \
				traces=$LIB_TRACING \
				MODEL=$cf_ITEM \
				CXX_MODEL=$CXX_MODEL \
				model=$cf_subdir \
				prefix=$cf_prefix \
				suffix=$cf_suffix \
				subset=$cf_subset \
				driver=$cf_cv_term_driver \
				SymLink="$LN_S" \
				TermlibRoot=$TINFO_NAME \
				TermlibSuffix=$TINFO_SUFFIX \
				ShlibVer=$cf_cv_shlib_version \
				ShlibVerInfix=$cf_cv_shlib_version_infix \
				ReLink=${cf_cv_do_relink:-no} \
				DoLinks=$cf_cv_do_symlinks \
				rmSoLocs=$cf_cv_rm_so_locs \
				ldconfig="$LDCONFIG" \
				overwrite=$WITH_OVERWRITE \
				depend="$cf_depend" \
				host="$host" \
				libtool_version="$LIBTOOL_VERSION" \
				$srcdir/$cf_dir/modules >>$cf_dir/Makefile

			cf_suffix="$old_cf_suffix"

			for cf_subdir2 in $cf_subdirs lib
			do
				test $cf_subdir = $cf_subdir2 && break
			done
			test "${cf_subset}.${cf_subdir2}" != "${cf_subset}.${cf_subdir}" && \
			$AWK -f $srcdir/mk-2nd.awk \
				name=$cf_dir \
				traces=$LIB_TRACING \
				MODEL=$cf_ITEM \
				model=$cf_subdir \
				subset=$cf_subset \
				srcdir=$srcdir \
				echo=$WITH_ECHO \
				crenames=$cf_cv_prog_CC_c_o \
				cxxrenames=$cf_cv_prog_CXX_c_o \
				$srcdir/$cf_dir/modules >>$cf_dir/Makefile
			cf_subdirs="$cf_subdirs $cf_subdir"
			done
		done
	fi

	echo '	cd '$cf_dir' && ${MAKE} ${TOP_MFLAGS} [$]@' >>Makefile
done

for cf_dir in $SRC_SUBDIRS
do
	if test ! -d $srcdir/$cf_dir ; then
		continue
	fi

	if test -f $cf_dir/Makefile ; then
		case "$cf_dir" in
		(Ada95)
			echo 'libs \' >> Makefile
			echo 'install.libs \' >> Makefile
			echo 'uninstall.libs ::' >> Makefile
			echo '	cd '$cf_dir' && ${MAKE} ${TOP_MFLAGS} [$]@' >> Makefile
			;;
		esac
	fi

	if test -f $srcdir/$cf_dir/modules; then
		echo >> Makefile
		if test -f $srcdir/$cf_dir/headers; then
cat >> Makefile <<CF_EOF
install.includes \\
uninstall.includes \\
CF_EOF
		fi
if test "$cf_dir" != "c++" ; then
echo 'lint \' >> Makefile
fi
cat >> Makefile <<CF_EOF
libs \\
lintlib \\
install.libs \\
uninstall.libs \\
install.$cf_dir \\
uninstall.$cf_dir ::
	cd $cf_dir && \${MAKE} \${TOP_MFLAGS} \[$]@
CF_EOF
	elif test -f $srcdir/$cf_dir/headers; then
cat >> Makefile <<CF_EOF

libs \\
install.libs \\
uninstall.libs \\
install.includes \\
uninstall.includes ::
	cd $cf_dir && \${MAKE} \${TOP_MFLAGS} \[$]@
CF_EOF
fi
done

if test "x$cf_with_db_install" = xyes; then
cat >> Makefile <<CF_EOF

install.libs uninstall.libs \\
install.data uninstall.data ::
$MAKE_TERMINFO	cd misc && \${MAKE} \${TOP_MFLAGS} \[$]@
CF_EOF
else
cat >> Makefile <<CF_EOF

install.libs uninstall.libs ::
	cd misc && \${MAKE} \${TOP_MFLAGS} \[$]@
CF_EOF
fi

if test "x$cf_with_manpages" = xyes; then
cat >> Makefile <<CF_EOF

install.man \\
uninstall.man ::
	cd man && \${MAKE} \${TOP_MFLAGS} \[$]@
CF_EOF
fi

cat >> Makefile <<CF_EOF

distclean ::
	rm -f config.cache config.log config.status Makefile include/ncurses_cfg.h
	rm -f headers.sh headers.sed mk_shared_lib.sh
	rm -f edit_man.* man_alias.*
	rm -rf \${DIRS_TO_MAKE}
CF_EOF

# Special case: tack's manpage lives in its own directory.
if test "x$cf_with_manpages" = xyes; then
if test -d tack ; then
if test -f $srcdir/$tack.h; then
cat >> Makefile <<CF_EOF

install.man \\
uninstall.man ::
	cd tack && \${MAKE} \${TOP_MFLAGS} \[$]@
CF_EOF
fi
fi
fi

dnl If we're installing into a subdirectory of /usr/include, etc., we should
dnl prepend the subdirectory's name to the "#include" paths.  It won't hurt
dnl anything, and will make it more standardized.  It's awkward to decide this
dnl at configuration because of quoting, so we'll simply make all headers
dnl installed via a script that can do the right thing.

rm -f headers.sed headers.sh

dnl ( generating this script makes the makefiles a little tidier :-)
echo creating headers.sh
cat >headers.sh <<CF_EOF
#! $SHELL
# This shell script is generated by the 'configure' script.  It is invoked in a
# subdirectory of the build tree.  It generates a sed-script in the parent
# directory that is used to adjust includes for header files that reside in a
# subdirectory of /usr/include, etc.
PRG=""
while test \[$]# != 3
do
PRG="\$PRG \[$]1"; shift
done
DST=\[$]1
REF=\[$]2
SRC=\[$]3
TMPSRC=\${TMPDIR:-/tmp}/\`basename \$SRC\`\$\$
TMPSED=\${TMPDIR:-/tmp}/headers.sed\$\$
echo installing \$SRC in \$DST
CF_EOF

if test $WITH_CURSES_H = yes; then
	cat >>headers.sh <<CF_EOF
case \$DST in
(/*/include/*)
	END=\`basename \$DST\`
	for i in \`cat \$REF/../*/headers |fgrep -v "#"\`
	do
		NAME=\`basename \$i\`
		echo "s/<\$NAME>/<\$END\/\$NAME>/" >> \$TMPSED
	done
	;;
(*)
	echo "" >> \$TMPSED
	;;
esac
CF_EOF

else
	cat >>headers.sh <<CF_EOF
case \$DST in
(/*/include/*)
	END=\`basename \$DST\`
	for i in \`cat \$REF/../*/headers |fgrep -v "#"\`
	do
		NAME=\`basename \$i\`
		if test "\$NAME" = "curses.h"
		then
			echo "s/<curses.h>/<ncurses.h>/" >> \$TMPSED
			NAME=ncurses.h
		fi
		echo "s/<\$NAME>/<\$END\/\$NAME>/" >> \$TMPSED
	done
	;;
(*)
	echo "s/<curses.h>/<ncurses.h>/" >> \$TMPSED
	;;
esac
CF_EOF
fi
cat >>headers.sh <<CF_EOF
rm -f \$TMPSRC
sed -f \$TMPSED \$SRC > \$TMPSRC
NAME=\`basename \$SRC\`
CF_EOF
if test $WITH_CURSES_H != yes; then
	cat >>headers.sh <<CF_EOF
test "\$NAME" = "curses.h" && NAME=ncurses.h
CF_EOF
fi
cat >>headers.sh <<CF_EOF
# Just in case someone gzip'd manpages, remove the conflicting copy.
test -f \$DST/\$NAME.gz && rm -f \$DST/\$NAME.gz

eval \$PRG \$TMPSRC \$DST/\$NAME
rm -f \$TMPSRC \$TMPSED
CF_EOF

chmod 0755 headers.sh

for cf_dir in $SRC_SUBDIRS
do
	if test ! -d $srcdir/$cf_dir ; then
		continue
	fi

	if test -f $srcdir/$cf_dir/headers; then
		$AWK -f $srcdir/mk-hdr.awk \
			subset="$LIB_SUBSETS" \
			compat="$WITH_CURSES_H" \
			$srcdir/$cf_dir/headers >>$cf_dir/Makefile
	fi

	if test -f $srcdir/$cf_dir/modules; then
		if test "$cf_dir" != "c++" ; then
			cat >>$cf_dir/Makefile <<"CF_EOF"
depend : ${AUTO_SRC}
	makedepend -- ${CPPFLAGS} -- ${C_SRC}

# DO NOT DELETE THIS LINE -- make depend depends on it.
CF_EOF
		fi
	fi
done
AC_SUBST(Libs_To_Make)
])dnl
