Blame SOURCES/dlopen.sh

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