1 2os=$(uname) 3 4case $os in 5 FreeBSD) libdl=;; 6 Linux) libdl=-ldl;; 7 Haiku) libdl=;; 8 *) echo "Unsupported OS: $os"; exit 1;; 9esac 10 11testdir=${testdir-testdir}/$(basename $0) 12 13rm -rf $testdir 14mkdir -p $testdir 15cd $testdir 16 17# test_run_ok <program> <expected return value> 18test_run_ok() 19{ 20 # exists? 21 if [ ! -f $1 ]; then 22 exit 1 23 fi 24 25 case $os in 26 FreeBSD|Linux) export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH;; 27 Haiku) export LIBRARY_PATH=.:$LIBRARY_PATH;; 28 *) echo "Unsupported OS: $os"; exit 1;; 29 esac 30 31 # run 32 $1 33 retval=$? 34 if [ $retval != $2 ]; then 35 echo "test_run_ok: $1: return value: $retval, expected: $2" 36 exit 1 37 fi 38} 39 40compile_lib() 41{ 42 gcc -shared -Wl,--no-as-needed -D_GNU_SOURCE -fPIC $@ 43} 44 45compile_lib_dl() 46{ 47 compile_lib $@ $libdl 48} 49 50compile_program() 51{ 52 gcc -Wl,--no-as-needed $@ -D_GNU_SOURCE -Wl,-rpath,.,--export-dynamic 53} 54 55compile_program_dl() 56{ 57 compile_program $@ $libdl 58} 59