os=$(uname)case $os inFreeBSD) libdl=;;Linux) libdl=-ldl;;Haiku) libdl=;;*) echo "Unsupported OS: $os"; exit 1;;esactestdir=${testdir-testdir}/$(basename $0)rm -rf $testdirmkdir -p $testdircd $testdir# test_run_ok <program> <expected return value>test_run_ok(){# exists?if [ ! -f $1 ]; thenexit 1ficase $os inFreeBSD|Linux) export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH;;Haiku) export LIBRARY_PATH=.:$LIBRARY_PATH;;*) echo "Unsupported OS: $os"; exit 1;;esac# run$1retval=$?if [ $retval != $2 ]; thenecho "test_run_ok: $1: return value: $retval, expected: $2"exit 1fi}compile_lib(){gcc -shared -Wl,--no-as-needed -D_GNU_SOURCE -fPIC $@}compile_lib_dl(){compile_lib $@ $libdl}compile_program(){gcc -Wl,--no-as-needed $@ -D_GNU_SOURCE -Wl,-rpath,.,--export-dynamic}compile_program_dl(){compile_program $@ $libdl}