qb: Combine the check_lib and check_lib_cxx functions.

This commit is contained in:
orbea 2017-10-27 13:01:04 -07:00
parent d5448f3261
commit 48db41a112
2 changed files with 72 additions and 94 deletions

View File

@ -41,7 +41,7 @@ fi
add_define_make DYLIB_LIB "$DYLIB" add_define_make DYLIB_LIB "$DYLIB"
check_lib SYSTEMD -lsystemd sd_get_machine_names check_lib '' SYSTEMD -lsystemd sd_get_machine_names
if [ "$HAVE_VIDEOCORE" != "no" ]; then if [ "$HAVE_VIDEOCORE" != "no" ]; then
check_pkgconf VC_TEST bcm_host check_pkgconf VC_TEST bcm_host
@ -49,7 +49,7 @@ if [ "$HAVE_VIDEOCORE" != "no" ]; then
# use fallback if pkgconfig is not available # use fallback if pkgconfig is not available
if [ ! "$VC_TEST_LIBS" ]; then if [ ! "$VC_TEST_LIBS" ]; then
[ -d /opt/vc/lib ] && add_library_dirs /opt/vc/lib && add_library_dirs /opt/vc/lib/GL [ -d /opt/vc/lib ] && add_library_dirs /opt/vc/lib && add_library_dirs /opt/vc/lib/GL
check_lib VIDEOCORE -lbcm_host bcm_host_init "-lvcos -lvchiq_arm" check_lib '' VIDEOCORE -lbcm_host bcm_host_init "-lvcos -lvchiq_arm"
else else
HAVE_VIDEOCORE="$HAVE_VC_TEST" HAVE_VIDEOCORE="$HAVE_VC_TEST"
fi fi
@ -122,7 +122,7 @@ if [ "$HAVE_EGL" != "no" ] && [ "$OS" != 'Win32' ]; then
check_pkgconf EGL "$VC_PREFIX"egl check_pkgconf EGL "$VC_PREFIX"egl
# some systems have EGL libs, but no pkgconfig # some systems have EGL libs, but no pkgconfig
if [ "$HAVE_EGL" = "no" ]; then if [ "$HAVE_EGL" = "no" ]; then
HAVE_EGL=auto; check_lib EGL "-l${VC_PREFIX}EGL $EXTRA_GL_LIBS" HAVE_EGL=auto; check_lib '' EGL "-l${VC_PREFIX}EGL $EXTRA_GL_LIBS"
[ "$HAVE_EGL" = "yes" ] && EGL_LIBS=-l"$VC_PREFIX"EGL [ "$HAVE_EGL" = "yes" ] && EGL_LIBS=-l"$VC_PREFIX"EGL
else else
EGL_LIBS="$EGL_LIBS $EXTRA_GL_LIBS" EGL_LIBS="$EGL_LIBS $EXTRA_GL_LIBS"
@ -130,7 +130,7 @@ if [ "$HAVE_EGL" != "no" ] && [ "$OS" != 'Win32' ]; then
fi fi
if [ "$HAVE_SSA" != "no" ]; then if [ "$HAVE_SSA" != "no" ]; then
check_lib SSA -lass ass_library_init check_lib '' SSA -lass ass_library_init
fi fi
if [ "$HAVE_EXYNOS" != "no" ]; then if [ "$HAVE_EXYNOS" != "no" ]; then
@ -149,8 +149,8 @@ else LIBRETRO="-lretro"
fi fi
[ "$HAVE_DYNAMIC" = 'yes' ] || { [ "$HAVE_DYNAMIC" = 'yes' ] || {
#check_lib RETRO "$LIBRETRO" retro_init "$DYLIB" "Cannot find libretro, did you forget --with-libretro=\"-lretro\"?" #check_lib '' RETRO "$LIBRETRO" retro_init "$DYLIB" "Cannot find libretro, did you forget --with-libretro=\"-lretro\"?"
check_lib RETRO "$LIBRETRO" "$DYLIB" "Cannot find libretro, did you forget --with-libretro=\"-lretro\"?" check_lib '' RETRO "$LIBRETRO" "$DYLIB" "Cannot find libretro, did you forget --with-libretro=\"-lretro\"?"
add_define_make libretro "$LIBRETRO" add_define_make libretro "$LIBRETRO"
} }
@ -173,18 +173,18 @@ if [ "$OS" = 'Win32' ]; then
HAVE_THREAD_STORAGE=yes HAVE_THREAD_STORAGE=yes
HAVE_DYLIB=yes HAVE_DYLIB=yes
else else
check_lib THREADS "$PTHREADLIB" pthread_create check_lib '' THREADS "$PTHREADLIB" pthread_create
if [ "$HAVE_THREADS" = 'yes' ]; then if [ "$HAVE_THREADS" = 'yes' ]; then
check_lib THREAD_STORAGE "$PTHREADLIB" pthread_key_create check_lib '' THREAD_STORAGE "$PTHREADLIB" pthread_key_create
else else
HAVE_THREAD_STORAGE=no HAVE_THREAD_STORAGE=no
fi fi
check_lib DYLIB "$DYLIB" dlopen check_lib '' DYLIB "$DYLIB" dlopen
fi fi
check_lib NETWORKING "$SOCKETLIB" socket "" "$SOCKETHEADER" check_lib '' NETWORKING "$SOCKETLIB" socket "" "$SOCKETHEADER"
if [ "$HAVE_NETWORKING" = 'yes' ]; then if [ "$HAVE_NETWORKING" = 'yes' ]; then
HAVE_GETADDRINFO=auto HAVE_GETADDRINFO=auto
@ -194,7 +194,7 @@ if [ "$HAVE_NETWORKING" = 'yes' ]; then
if [ "$OS" = 'Win32' ]; then if [ "$OS" = 'Win32' ]; then
HAVE_GETADDRINFO=yes HAVE_GETADDRINFO=yes
else else
check_lib GETADDRINFO "$SOCKETLIB" getaddrinfo check_lib '' GETADDRINFO "$SOCKETLIB" getaddrinfo
if [ "$HAVE_GETADDRINFO" != 'yes' ]; then if [ "$HAVE_GETADDRINFO" != 'yes' ]; then
HAVE_SOCKET_LEGACY=yes HAVE_SOCKET_LEGACY=yes
echo "Notice: RetroArch will use legacy socket support" echo "Notice: RetroArch will use legacy socket support"
@ -204,7 +204,7 @@ if [ "$HAVE_NETWORKING" = 'yes' ]; then
HAVE_NETWORKGAMEPAD=yes HAVE_NETWORKGAMEPAD=yes
if [ "$HAVE_MINIUPNPC" != "no" ]; then if [ "$HAVE_MINIUPNPC" != "no" ]; then
check_lib MINIUPNPC "-lminiupnpc" check_lib '' MINIUPNPC "-lminiupnpc"
fi fi
if [ "$HAVE_BUILTINMINIUPNPC" = "yes" ]; then if [ "$HAVE_BUILTINMINIUPNPC" = "yes" ]; then
@ -218,7 +218,7 @@ else
HAVE_CHEEVOS='no' HAVE_CHEEVOS='no'
fi fi
check_lib STDIN_CMD "$CLIB" fcntl check_lib '' STDIN_CMD "$CLIB" fcntl
if [ "$HAVE_NETWORK_CMD" = "yes" ] || [ "$HAVE_STDIN_CMD" = "yes" ]; then if [ "$HAVE_NETWORK_CMD" = "yes" ] || [ "$HAVE_STDIN_CMD" = "yes" ]; then
HAVE_COMMAND='yes' HAVE_COMMAND='yes'
@ -226,7 +226,7 @@ else
HAVE_COMMAND='no' HAVE_COMMAND='no'
fi fi
check_lib GETOPT_LONG "$CLIB" getopt_long check_lib '' GETOPT_LONG "$CLIB" getopt_long
if [ "$HAVE_DYLIB" = 'no' ] && [ "$HAVE_DYNAMIC" = 'yes' ]; then if [ "$HAVE_DYLIB" = 'no' ] && [ "$HAVE_DYNAMIC" = 'yes' ]; then
echo "Error: Dynamic loading of libretro is enabled, but your platform does not appear to have dlopen(), use --disable-dynamic or --with-libretro=\"-lretro\"". echo "Error: Dynamic loading of libretro is enabled, but your platform does not appear to have dlopen(), use --disable-dynamic or --with-libretro=\"-lretro\"".
@ -234,27 +234,27 @@ if [ "$HAVE_DYLIB" = 'no' ] && [ "$HAVE_DYNAMIC" = 'yes' ]; then
fi fi
check_pkgconf ALSA alsa check_pkgconf ALSA alsa
check_lib CACA -lcaca check_lib '' CACA -lcaca
check_header OSS sys/soundcard.h check_header OSS sys/soundcard.h
check_header OSS_BSD soundcard.h check_header OSS_BSD soundcard.h
check_lib OSS_LIB -lossaudio check_lib '' OSS_LIB -lossaudio
if [ "$OS" = 'Linux' ]; then if [ "$OS" = 'Linux' ]; then
HAVE_TINYALSA=yes HAVE_TINYALSA=yes
fi fi
if [ "$OS" = 'Darwin' ]; then if [ "$OS" = 'Darwin' ]; then
check_lib COREAUDIO "-framework AudioUnit" AudioUnitInitialize check_lib '' COREAUDIO "-framework AudioUnit" AudioUnitInitialize
check_lib CORETEXT "-framework CoreText" CTFontCreateWithName check_lib '' CORETEXT "-framework CoreText" CTFontCreateWithName
check_lib COCOA "-framework AppKit" NSApplicationMain check_lib '' COCOA "-framework AppKit" NSApplicationMain
check_lib AVFOUNDATION "-framework AVFoundation" check_lib '' AVFOUNDATION "-framework AVFoundation"
check_lib CORELOCATION "-framework CoreLocation" check_lib '' CORELOCATION "-framework CoreLocation"
check_lib IOHIDMANAGER "-framework IOKit" IOHIDManagerCreate check_lib '' IOHIDMANAGER "-framework IOKit" IOHIDManagerCreate
check_lib AL "-framework OpenAL" alcOpenDevice check_lib '' AL "-framework OpenAL" alcOpenDevice
HAVE_X11=no # X11 breaks on recent OSXes even if present. HAVE_X11=no # X11 breaks on recent OSXes even if present.
HAVE_SDL=no HAVE_SDL=no
else else
check_lib AL -lopenal alcOpenDevice check_lib '' AL -lopenal alcOpenDevice
fi fi
check_pkgconf RSOUND rsound 1.1 check_pkgconf RSOUND rsound 1.1
@ -277,9 +277,9 @@ fi
check_pkgconf LIBUSB libusb-1.0 1.0.16 check_pkgconf LIBUSB libusb-1.0 1.0.16
if [ "$OS" = 'Win32' ]; then if [ "$OS" = 'Win32' ]; then
check_lib DINPUT -ldinput8 check_lib '' DINPUT -ldinput8
check_lib D3D9 -ld3d9 check_lib '' D3D9 -ld3d9
check_lib DSOUND -ldsound check_lib '' DSOUND -ldsound
if [ "$HAVE_DINPUT" != 'no' ]; then if [ "$HAVE_DINPUT" != 'no' ]; then
HAVE_XINPUT=yes HAVE_XINPUT=yes
@ -294,25 +294,25 @@ fi
if [ "$HAVE_OPENGL" != 'no' ] && [ "$HAVE_OPENGLES" != 'yes' ]; then if [ "$HAVE_OPENGL" != 'no' ] && [ "$HAVE_OPENGLES" != 'yes' ]; then
if [ "$OS" = 'Darwin' ]; then if [ "$OS" = 'Darwin' ]; then
check_header OPENGL "OpenGL/gl.h" check_header OPENGL "OpenGL/gl.h"
check_lib OPENGL "-framework OpenGL" check_lib '' OPENGL "-framework OpenGL"
elif [ "$OS" = 'Win32' ]; then elif [ "$OS" = 'Win32' ]; then
check_header OPENGL "GL/gl.h" check_header OPENGL "GL/gl.h"
check_lib OPENGL -lopengl32 check_lib '' OPENGL -lopengl32
else else
check_header OPENGL "GL/gl.h" check_header OPENGL "GL/gl.h"
check_lib OPENGL -lGL check_lib '' OPENGL -lGL
fi fi
if [ "$HAVE_OPENGL" = 'yes' ]; then if [ "$HAVE_OPENGL" = 'yes' ]; then
if [ "$OS" = 'Darwin' ]; then if [ "$OS" = 'Darwin' ]; then
check_lib CG "-framework Cg" cgCreateContext check_lib '' CG "-framework Cg" cgCreateContext
[ "$HAVE_CG" = 'yes' ] && CG_LIBS='-framework Cg' [ "$HAVE_CG" = 'yes' ] && CG_LIBS='-framework Cg'
elif [ "$OS" = 'Win32' ]; then elif [ "$OS" = 'Win32' ]; then
check_lib_cxx CG -lcg cgCreateContext check_lib cxx CG -lcg cgCreateContext
[ "$HAVE_CG" = 'yes' ] && CG_LIBS='-lcg -lcgGL' [ "$HAVE_CG" = 'yes' ] && CG_LIBS='-lcg -lcgGL'
else else
# On some distros, -lCg doesn't link against -lstdc++ it seems ... # On some distros, -lCg doesn't link against -lstdc++ it seems ...
check_lib_cxx CG -lCg cgCreateContext check_lib cxx CG -lCg cgCreateContext
[ "$HAVE_CG" = 'yes' ] && CG_LIBS='-lCg -lCgGL' [ "$HAVE_CG" = 'yes' ] && CG_LIBS='-lCg -lCgGL'
fi fi
@ -331,7 +331,7 @@ if [ "$HAVE_ZLIB" != 'no' ]; then
if [ "$HAVE_ZLIB" = 'no' ]; then if [ "$HAVE_ZLIB" = 'no' ]; then
HAVE_ZLIB='auto' HAVE_ZLIB='auto'
check_lib ZLIB '-lz' check_lib '' ZLIB '-lz'
fi fi
fi fi
@ -358,7 +358,7 @@ else
fi fi
if [ "$OS" != 'Win32' ]; then if [ "$OS" != 'Win32' ]; then
check_lib DYNAMIC "$DYLIB" dlopen check_lib '' DYNAMIC "$DYLIB" dlopen
fi fi
if [ "$HAVE_KMS" != "no" ]; then if [ "$HAVE_KMS" != "no" ]; then
@ -385,7 +385,7 @@ if [ "$HAVE_EGL" = "yes" ]; then
else else
HAVE_OPENGLES=auto; check_pkgconf OPENGLES "$VC_PREFIX"glesv2 HAVE_OPENGLES=auto; check_pkgconf OPENGLES "$VC_PREFIX"glesv2
if [ "$HAVE_OPENGLES" = "no" ]; then if [ "$HAVE_OPENGLES" = "no" ]; then
HAVE_OPENGLES=auto; check_lib OPENGLES "-l${VC_PREFIX}GLESv2 $EXTRA_GL_LIBS" HAVE_OPENGLES=auto; check_lib '' OPENGLES "-l${VC_PREFIX}GLESv2 $EXTRA_GL_LIBS"
add_define_make OPENGLES_LIBS "-l${VC_PREFIX}GLESv2 $EXTRA_GL_LIBS" add_define_make OPENGLES_LIBS "-l${VC_PREFIX}GLESv2 $EXTRA_GL_LIBS"
fi fi
fi fi
@ -393,7 +393,7 @@ if [ "$HAVE_EGL" = "yes" ]; then
if [ "$HAVE_VG" != "no" ]; then if [ "$HAVE_VG" != "no" ]; then
check_pkgconf VG "$VC_PREFIX"vg check_pkgconf VG "$VC_PREFIX"vg
if [ "$HAVE_VG" = "no" ]; then if [ "$HAVE_VG" = "no" ]; then
HAVE_VG=auto; check_lib VG "-l${VC_PREFIX}OpenVG $EXTRA_GL_LIBS" HAVE_VG=auto; check_lib '' VG "-l${VC_PREFIX}OpenVG $EXTRA_GL_LIBS"
[ "$HAVE_VG" = "yes" ] && VG_LIBS=-l"$VC_PREFIX"OpenVG [ "$HAVE_VG" = "yes" ] && VG_LIBS=-l"$VC_PREFIX"OpenVG
fi fi
fi fi
@ -405,14 +405,14 @@ fi
check_pkgconf V4L2 libv4l2 check_pkgconf V4L2 libv4l2
if [ "$OS" = 'Darwin' ]; then if [ "$OS" = 'Darwin' ]; then
check_lib FBO "-framework OpenGL" glFramebufferTexture2D check_lib '' FBO "-framework OpenGL" glFramebufferTexture2D
elif [ "$OS" = 'Win32' ]; then elif [ "$OS" = 'Win32' ]; then
HAVE_FBO=yes HAVE_FBO=yes
else else
if [ "$HAVE_OPENGLES" = "yes" ]; then if [ "$HAVE_OPENGLES" = "yes" ]; then
[ $HAVE_FBO != "no" ] && HAVE_FBO=yes [ $HAVE_FBO != "no" ] && HAVE_FBO=yes
else else
check_lib FBO -lGL glFramebufferTexture2D check_lib '' FBO -lGL glFramebufferTexture2D
fi fi
fi fi
@ -440,7 +440,7 @@ fi
if [ "$HAVE_UDEV" != "no" ]; then if [ "$HAVE_UDEV" != "no" ]; then
check_pkgconf UDEV libudev check_pkgconf UDEV libudev
if [ "$HAVE_UDEV" = "no" ]; then if [ "$HAVE_UDEV" = "no" ]; then
HAVE_UDEV=auto; check_lib UDEV "-ludev" HAVE_UDEV=auto; check_lib '' UDEV "-ludev"
[ "$HAVE_UDEV" = "yes" ] && UDEV_LIBS=-ludev [ "$HAVE_UDEV" = "yes" ] && UDEV_LIBS=-ludev
fi fi
fi fi
@ -451,11 +451,11 @@ check_header PARPORT linux/parport.h
check_header PARPORT linux/ppdev.h check_header PARPORT linux/ppdev.h
if [ "$OS" != 'Win32' ] && [ "$OS" != 'Linux' ]; then if [ "$OS" != 'Win32' ] && [ "$OS" != 'Linux' ]; then
check_lib STRL "$CLIB" strlcpy check_lib '' STRL "$CLIB" strlcpy
fi fi
check_lib STRCASESTR "$CLIB" strcasestr check_lib '' STRCASESTR "$CLIB" strcasestr
check_lib MMAP "$CLIB" mmap check_lib '' MMAP "$CLIB" mmap
check_lib VULKAN -lvulkan vkCreateInstance check_lib '' VULKAN -lvulkan vkCreateInstance
if [ "$HAVE_VULKAN" != 'no' ] && [ ! -e deps/glslang/glslang/README.md ]; then if [ "$HAVE_VULKAN" != 'no' ] && [ ! -e deps/glslang/glslang/README.md ]; then
echo "Warning: glslang submodule not loaded, can't use Vulkan." echo "Warning: glslang submodule not loaded, can't use Vulkan."

View File

@ -23,74 +23,52 @@ add_library_dirs()
LIBRARY_DIRS="${LIBRARY_DIRS#* }" LIBRARY_DIRS="${LIBRARY_DIRS#* }"
} }
check_lib() #$1 = HAVE_$1 $2 = lib $3 = function in lib $4 = extralibs $5 = headers check_lib() # $1 = language $2 = HAVE_$2 $3 = lib $4 = function in lib $5 = extralibs $6 = headers $7 = critical error message [checked only if non-empty]
{ tmpval="$(eval echo \$HAVE_$1)" { tmpval="$(eval echo \$HAVE_$2)"
[ "$tmpval" = 'no' ] && return 0 [ "$tmpval" = 'no' ] && return 0
if [ "$3" ]; then if [ "$1" = cxx ]; then
ECHOBUF="Checking function $3 in ${2% }" COMPILER="$CXX"
if [ "$5" ]; then TEMP_CODE="$TEMP_CXX"
printf %s\\n "$5" "int main(void) { void *p = (void*)$3; return 0; }" > $TEMP_C TEST_C="extern \"C\" { void $4(void); } int main() { $4(); }"
else
COMPILER="$CC"
TEMP_CODE="$TEMP_C"
TEST_C="void $4(void); int main(void) { $4(); return 0; }"
fi
if [ "$4" ]; then
ECHOBUF="Checking function $4 in ${3% }"
if [ "$6" ]; then
printf %s\\n "$6" "int main(void) { void *p = (void*)$4; return 0; }" > "$TEMP_CODE"
else else
echo "void $3(void); int main(void) { $3(); return 0; }" > $TEMP_C echo "$TEST_C" > "$TEMP_CODE"
fi fi
else else
ECHOBUF="Checking existence of ${2% }" ECHOBUF="Checking existence of ${3% }"
echo "int main(void) { return 0; }" > $TEMP_C echo "int main(void) { return 0; }" > "$TEMP_CODE"
fi fi
answer='no' answer='no'
# echo -n "$ECHOBUF" # echo -n "$ECHOBUF"
"$CC" -o \ "$COMPILER" -o \
"$TEMP_EXE" \ "$TEMP_EXE" \
"$TEMP_C" \ "$TEMP_CODE" \
$INCLUDE_DIRS \ $INCLUDE_DIRS \
$LIBRARY_DIRS \ $LIBRARY_DIRS \
$(printf %s "$4") \ $(printf %s "$5") \
$CFLAGS \ $CFLAGS \
$LDFLAGS \ $LDFLAGS \
$(printf %s "$2") >>config.log 2>&1 && answer='yes' $(printf %s "$3") >>config.log 2>&1 && answer='yes'
eval HAVE_$1="$answer"; echo "$ECHOBUF ... $answer" eval HAVE_$2="$answer"; echo "$ECHOBUF ... $answer"
rm "$TEMP_C" "$TEMP_EXE" >/dev/null 2>&1 rm "$TEMP_CODE" "$TEMP_EXE" >/dev/null 2>&1
[ "$tmpval" = 'yes' ] && [ "$answer" = 'no' ] && {
echo "Forced to build with library $2, but cannot locate. Exiting ..."
exit 1
}
return 0
}
check_lib_cxx() #$1 = HAVE_$1 $2 = lib $3 = function in lib $4 = extralibs $5 = critical error message [checked only if non-empty]
{ tmpval="$(eval echo \$HAVE_$1)"
[ "$tmpval" = 'no' ] && return 0
if [ "$3" ]; then
ECHOBUF="Checking function $3 in ${2% }"
echo "extern \"C\" { void $3(void); } int main() { $3(); }" > $TEMP_CXX
else
ECHOBUF="Checking existence of ${2% }"
echo "int main() { return 0; }" > $TEMP_CXX
fi
answer='no'
# echo -n "$ECHOBUF"
"$CXX" -o \
"$TEMP_EXE" \
"$TEMP_CXX" \
$INCLUDE_DIRS \
$LIBRARY_DIRS \
$(printf %s "$4") \
$CFLAGS \
$LDFLAGS \
$(printf %s "$2") >>config.log 2>&1 && answer='yes'
eval HAVE_$1="$answer"; echo "$ECHOBUF ... $answer"
rm "$TEMP_CXX" "$TEMP_EXE" >/dev/null 2>&1
[ "$answer" = 'no' ] && { [ "$answer" = 'no' ] && {
[ "$5" ] && { echo "$5"; exit 1;} [ "$7" ] && { echo "$7"; exit 1;}
[ "$tmpval" = 'yes' ] && { [ "$tmpval" = 'yes' ] && {
echo "Forced to build with library $2, but cannot locate. Exiting ..." echo "Forced to build with library $3, but cannot locate. Exiting ..."
exit 1 exit 1
} }
} }
return 0 return 0