[sane-devel] [hpoj-devel] detecting sane-backends lib and etc directories

David Paschal paschal@rcsis.com
Wed, 10 Jul 2002 04:09:52 -0700


Hi.  Could somebody please review the following algorithm for detecting
where sane-backends lib and etc directories are installed and let me know
if there are any problems with it?  This is for installing the external
"hpoj" backend (http://hpoj.sourceforge.net), by setting a symlink from
.../lib/sane/libsane-hpoj.so.1 to where libsane-hpoj.so* is really
installed, and appending the line "hpoj" to dll.conf if necessary.

The actual configure.in code I wrote is included at the end of this
message, but I'll summarize it here:

- Look for the file libsane-dll.so in the following places:
  - the directory specified by "./configure --with-sane-backend=<DIR>"
  - parsed "-L' switch from `sane-config --ldflags' with "/sane" appended
  - `sane-config --exec-prefix`/lib/sane
  - `sane-config --prefix`/lib/sane
  - /usr/local/lib/sane
  - /usr/lib/sane
  - /usr/X11*/lib/sane

- Look for the file dll.conf in the following places:
  - the directory specified by "./configure --with-sane-etc=<DIR>"
  - the environment variable $SANE_CONFIG_DIR
  - `sane-config --prefix`/etc/sane.d
  - `sane-config --exec-prefix`/etc/sane.d
  - /etc/sane.d
  - /usr/local/etc/sane.d
  - /usr/etc/sane.d

For example, is anybody aware of any other paths where distributions
might install the .so and .conf files?

Thanks,
David



###########################################################################

# Check for SANE (needed to install libsane-hpoj backend).

AC_ARG_WITH(sane-backend,[  --with-sane-backend=DIR specifies path to SANE 
backend libraries])
AC_ARG_WITH(sane-etc,[  --with-sane-etc=DIR     specifies path to SANE 
configuration files])

AC_MSG_CHECKING(for SANE backend directory)
unset SANE_BACKEND_DIR
if test "$with_sane_backend" != no ; then
	unset SANE_BACKEND_DIR_POSSIBILITIES
	if test "$with_sane_backend" != yes ; then
		SANE_BACKEND_DIR_POSSIBILITIES=$with_sane_backend
	fi

	foo=`sane-config --ldflags 2>/dev/null`
	foo=${foo#-L}
	foo=${foo%% *}
	if test -n "$foo" ; then
		SANE_BACKEND_DIR_POSSIBILITIES="$SANE_BACKEND_DIR_POSSIBILITIES $foo/sane"
	fi

	foo=`sane-config --exec-prefix 2>/dev/null`
	if test -n "$foo" ; then
		SANE_BACKEND_DIR_POSSIBILITIES="$SANE_BACKEND_DIR_POSSIBILITIES 
$foo/lib/sane"
	fi

	foo=`sane-config --prefix 2>/dev/null`
	if test -n "$foo" ; then
		SANE_BACKEND_DIR_POSSIBILITIES="$SANE_BACKEND_DIR_POSSIBILITIES 
$foo/lib/sane"
	fi

	SANE_BACKEND_DIR_POSSIBILITIES="$SANE_BACKEND_DIR_POSSIBILITIES 
/usr/local/lib/sane /usr/lib/sane /usr/X11*/lib/sane"

	for dir in $SANE_BACKEND_DIR_POSSIBILITIES ; do
		if test -f $dir/libsane-dll.so ; then
			SANE_BACKEND_DIR=$dir
			break
		fi
	done
fi
if test -n "$SANE_BACKEND_DIR" ; then
	AC_MSG_RESULT($SANE_BACKEND_DIR)
else
	if test "$with_sane_backend" = no ; then
		AC_MSG_RESULT(check not done)
	else
		AC_MSG_RESULT(no: try \"$0 --with-sane-backend=<dir>\")
	fi
fi

AC_MSG_CHECKING(for SANE configuration files)
unset SANE_ETC_DIR
if test "$with_sane_etc" != no ; then
	unset SANE_ETC_DIR_POSSIBILITIES
	if test "$with_sane_etc" != yes ; then
		SANE_ETC_DIR_POSSIBILITIES=$with_sane_etc
	fi

	SANE_ETC_DIR_POSSIBILITIES="$SANE_ETC_DIR_POSSIBILITIES $SANE_CONFIG_DIR"

	foo=`sane-config --prefix 2>/dev/null`
	if test -n "$foo" ; then
		SANE_ETC_DIR_POSSIBILITIES="$SANE_ETC_DIR_POSSIBILITIES $foo/etc/sane.d"
	fi

	foo=`sane-config --exec-prefix 2>/dev/null`
	if test -n "$foo" ; then
		SANE_ETC_DIR_POSSIBILITIES="$SANE_ETC_DIR_POSSIBILITIES $foo/etc/sane.d"
	fi

	SANE_ETC_DIR_POSSIBILITIES="$SANE_ETC_DIR_POSSIBILITIES /etc/sane.d 
/usr/local/etc/sane.d /usr/etc/sane.d"

	for dir in $SANE_ETC_DIR_POSSIBILITIES ; do
		if test -f $dir/dll.conf ; then
			SANE_ETC_DIR=$dir
			break
		fi
	done
fi
if test -n "$SANE_ETC_DIR" ; then
	AC_MSG_RESULT($SANE_ETC_DIR)
else
	if test "$with_sane_etc" = no ; then
		AC_MSG_RESULT(check not done)
	else
		AC_MSG_RESULT(no: try \"$0 --with-sane-etc=<dir>\")
	fi
fi

if test -z "$SANE_BACKEND_DIR" -o -z "$SANE_ETC_DIR" ; then
	unset SANE_BACKEND_DIR
	unset SANE_ETC_DIR

	AC_MSG_RESULT(*** SANE scanning support will not be installed ***)
fi

###########################################################################

AC_SUBST(SANE_BACKEND_DIR)
AC_SUBST(SANE_ETC_DIR)