904b9f
#!/bin/sh
904b9f
904b9f
tempdir=`mktemp -d /tmp/dlopenXXXXXX`
904b9f
test -n "$tempdir" || exit 1
904b9f
cat >> $tempdir/dlopen.c << _EOF
904b9f
#include <dlfcn.h>
904b9f
#include <stdio.h>
904b9f
#include <limits.h>
904b9f
#include <sys/stat.h>
904b9f
/* Simple program to see if dlopen() would succeed. */
904b9f
int main(int argc, char **argv)
904b9f
{
904b9f
	int i;
904b9f
	struct stat st;
904b9f
	char buf[PATH_MAX];
904b9f
	for (i = 1; i < argc; i++) {
904b9f
		if (dlopen(argv[i], RTLD_NOW)) {
904b9f
			fprintf(stdout, "dlopen() of \"%s\" succeeded.\n",
904b9f
				argv[i]);
904b9f
		} else {
904b9f
			snprintf(buf, sizeof(buf), "./%s", argv[i]);
904b9f
			if ((stat(buf, &st) == 0) && dlopen(buf, RTLD_NOW)) {
904b9f
				fprintf(stdout, "dlopen() of \"./%s\" "
904b9f
					"succeeded.\n", argv[i]);
904b9f
			} else {
904b9f
				fprintf(stdout, "dlopen() of \"%s\" failed: "
904b9f
					"%s\n", argv[i], dlerror());
904b9f
				return 1;
904b9f
			}
904b9f
		}
904b9f
	}
904b9f
	return 0;
904b9f
}
904b9f
_EOF
904b9f
904b9f
for arg in $@ ; do
904b9f
	case "$arg" in
904b9f
	"")
904b9f
		;;
904b9f
	-I*|-D*|-f*|-m*|-g*|-O*|-W*)
904b9f
		cflags="$cflags $arg"
904b9f
		;;
904b9f
	-l*|-L*)
904b9f
		ldflags="$ldflags $arg"
904b9f
		;;
904b9f
	/*)
904b9f
		modules="$modules $arg"
904b9f
		;;
904b9f
	*)
904b9f
		modules="$modules $arg"
904b9f
		;;
904b9f
	esac
904b9f
done
904b9f
904b9f
${CC:-gcc} $RPM_OPT_FLAGS $CFLAGS -o $tempdir/dlopen $cflags $tempdir/dlopen.c $ldflags -ldl
904b9f
904b9f
retval=0
904b9f
for module in $modules ; do
904b9f
	case "$module" in
904b9f
	"")
904b9f
		;;
904b9f
	/*)
904b9f
		$tempdir/dlopen "$module"
904b9f
		retval=$?
904b9f
		;;
904b9f
	*)
904b9f
		$tempdir/dlopen ./"$module"
904b9f
		retval=$?
904b9f
		;;
904b9f
	esac
904b9f
done
904b9f
904b9f
rm -f $tempdir/dlopen $tempdir/dlopen.c
904b9f
rmdir $tempdir
904b9f
exit $retval