]> git.sesse.net Git - ffmpeg/blobdiff - configure
configure: Add check_ld() helper function to simplify some expressions
[ffmpeg] / configure
index 784caf85dfd99d7e96f3ec0c3a0c5020aedfd204..5e350983dd81414fd130116437f361d63573f68b 100755 (executable)
--- a/configure
+++ b/configure
@@ -850,6 +850,14 @@ test_ld(){
     test_cmd $ld $LDFLAGS $flags $(ld_o $TMPE) $TMPO $libs $extralibs
 }
 
+check_ld(){
+    log check_ld "$@"
+    name=$1
+    shift
+    disable $name
+    test_ld $@ && enable $name
+}
+
 print_include(){
     hdr=$1
     test "${hdr%.h}" = "${hdr}" &&
@@ -998,6 +1006,14 @@ test_cpp_condition(){
 EOF
 }
 
+check_cpp_condition(){
+    log check_cpp_condition "$@"
+    name=$1
+    shift 1
+    disable $name
+    test_cpp_condition "$@" && enable $name
+}
+
 test_cflags_cpp(){
     log test_cflags_cpp "$@"
     flags=$1
@@ -1121,6 +1137,14 @@ check_compile_assert(){
     test_code cc "$headers" "char c[2 * !!($condition) - 1]" "$@" && enable "$name"
 }
 
+check_cc(){
+    log check_cc "$@"
+    name=$1
+    shift
+    disable "$name"
+    test_code cc "$@" && enable "$name"
+}
+
 require(){
     log require "$@"
     name_version="$1"
@@ -1129,6 +1153,13 @@ require(){
     check_lib $name "$@" || die "ERROR: $name_version not found"
 }
 
+require_cc(){
+    log require_cc "$@"
+    name="$1"
+    shift
+    test_code cc "$@" || die "ERROR: $name failed"
+}
+
 require_header(){
     log require_header "$@"
     headers="$1"
@@ -1197,6 +1228,14 @@ test_host_cpp_condition(){
 EOF
 }
 
+check_host_cpp_condition(){
+    log check_host_cpp_condition "$@"
+    name=$1
+    shift 1
+    disable $name
+    test_host_cpp_condition "$@" && enable $name
+}
+
 cp_if_changed(){
     cmp -s "$1" "$2" && { test "$quiet" != "yes" && echo "$2 is unchanged"; } && return
     mkdir -p "$(dirname $2)"
@@ -4156,18 +4195,12 @@ extern_prefix=${sym%%ff_extern*}
 ! disabled inline_asm && check_inline_asm inline_asm '"" ::'
 
 for restrict_keyword in restrict __restrict__ __restrict ""; do
-    test_cc <<EOF && break
-void foo(char * $restrict_keyword p);
-EOF
+    test_code cc "" "char * $restrict_keyword p" && break
 done
 
-test_cc <<EOF && enable pragma_deprecated
-void foo(void) { _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") }
-EOF
+check_cc pragma_deprecated "" '_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")'
 
-test_cc <<EOF || die "endian test failed"
-unsigned int endian = 'B' << 24 | 'I' << 16 | 'G' << 8 | 'E';
-EOF
+require_cc "endian test" "" "unsigned int endian = 'B' << 24 | 'I' << 16 | 'G' << 8 | 'E'"
 od -t x1 $TMPO | grep -q '42 *49 *47 *45' && enable bigendian
 
 check_gas() {
@@ -4232,18 +4265,18 @@ elif enabled alpha; then
 
 elif enabled arm; then
 
-    enabled msvc && test_cpp_condition stddef.h "defined _M_ARMT" && enable thumb
+    enabled msvc && check_cpp_condition thumb stddef.h "defined _M_ARMT"
     test_cpp_condition stddef.h "defined __thumb__" && enable_weak thumb
     enabled thumb && check_cflags -mthumb || check_cflags -marm
 
-    if test_cpp_condition stddef.h "defined __ARM_PCS_VFP"; then
-        enable vfp_args
-    elif test_cpp_condition stddef.h "defined _M_ARM_FP && _M_ARM_FP >= 30"; then
-        enable vfp_args
+    if check_cpp_condition vfp_args stddef.h "defined __ARM_PCS_VFP"; then
+        :
+    elif check_cpp_condition vfp_args stddef.h "defined _M_ARM_FP && _M_ARM_FP >= 30"; then
+        :
     elif ! test_cpp_condition stddef.h "defined __ARM_PCS || defined __SOFTFP__" && [ $target_os != darwin ]; then
         case "${cross_prefix:-$cc}" in
-            *hardfloat*)         enable vfp_args;   fpabi=vfp ;;
-            *) test_ld <<EOF &&  enable vfp_args && fpabi=vfp || fpabi=soft ;;
+            *hardfloat*) enable vfp_args; fpabi=vfp ;;
+            *) check_ld vfp_args <<EOF && fpabi=vfp || fpabi=soft ;;
 __asm__ (".eabi_attribute 28, 1");
 int main(void) { return 0; }
 EOF
@@ -4318,23 +4351,21 @@ elif enabled ppc; then
         check_cflags -maltivec -mabi=altivec
 
         # check if our compiler supports Motorola AltiVec C API
-        test_code cc altivec.h "vector signed int v1 = (vector signed int) { 0 };
-                                vector signed int v2 = (vector signed int) { 1 };
-                                v1 = vec_add(v1, v2);" ||
-            disable altivec
+        check_cc altivec altivec.h "vector signed int v1 = (vector signed int) { 0 };
+                                    vector signed int v2 = (vector signed int) { 1 };
+                                    v1 = vec_add(v1, v2);"
 
         enabled altivec || warn "Altivec disabled, possibly missing --cpu flag"
     fi
 
     if enabled vsx; then
         check_cflags -mvsx &&
-        test_code cc altivec.h "int v[4] = { 0 };
-                                vector signed int v1 = vec_vsx_ld(0, v);" ||
-            disable vsx
+        check_cc vsx altivec.h "int v[4] = { 0 };
+                                vector signed int v1 = vec_vsx_ld(0, v);"
     fi
 
     if enabled power8; then
-        test_cpp_condition "altivec.h" "defined(_ARCH_PWR8)" || disable power8
+        check_cpp_condition power8 altivec.h "defined(_ARCH_PWR8)"
     fi
 
 elif enabled x86; then
@@ -4411,7 +4442,7 @@ EOF
 
 fi
 
-test_code cc arm_neon.h "int16x8_t test = vdupq_n_s16(0)" && enable intrinsics_neon
+check_cc intrinsics_neon arm_neon.h "int16x8_t test = vdupq_n_s16(0)"
 
 check_ldflags -Wl,--as-needed
 
@@ -4655,8 +4686,7 @@ enabled libwavpack        && require libwavpack wavpack/wavpack.h WavpackOpenFil
 enabled libwebp           && require_pkg_config libwebp libwebp webp/encode.h WebPGetEncoderVersion
 enabled libx264           && require_pkg_config libx264 x264 "stdint.h x264.h" x264_encoder_encode &&
                              require_cpp_condition x264.h "X264_BUILD >= 118" &&
-                             { test_cpp_condition x264.h "X264_MPEG2" &&
-                               enable libx262; }
+                             check_cpp_condition libx262 x264.h "X264_MPEG2"
 enabled libx265           && require_pkg_config libx265 x265 x265.h x265_api_get &&
                              require_cpp_condition x265.h "X265_BUILD >= 57"
 enabled libxavs           && require libxavs "stdint.h xavs.h" xavs_encoder_encode -lxavs
@@ -4696,7 +4726,7 @@ check_lib user32 "windows.h winuser.h" GetShellWindow -luser32
 check_lib vfw32 "windows.h vfw.h" capCreateCaptureWindow -lvfw32
 # check that WM_CAP_DRIVER_CONNECT is defined to the proper value
 # w32api 3.12 had it defined wrong
-test_cpp_condition vfw.h "WM_CAP_DRIVER_CONNECT > WM_USER" && enable vfwcap_defines
+check_cpp_condition vfwcap_defines vfw.h "WM_CAP_DRIVER_CONNECT > WM_USER"
 
 # check for ioctl_meteor.h, ioctl_bt848.h and alternatives
 check_header "dev/bktr/ioctl_meteor.h dev/bktr/ioctl_bt848.h"                   ||
@@ -4746,23 +4776,18 @@ EOF
 
 enabled vaapi && require vaapi va/va.h vaInitialize -lva
 
-enabled vaapi &&
-    test_code cc "va/va.h" "vaCreateSurfaces(0, 0, 0, 0, 0, 0, 0, 0)" ||
-    disable vaapi
-
-enabled vaapi &&
-    check_lib vaapi_drm "va/va.h va/va_drm.h" vaGetDisplayDRM -lva -lva-drm
-
-enabled vaapi &&
-    check_lib vaapi_x11 "va/va.h va/va_x11.h" vaGetDisplay -lva -lva-x11 -lX11
+if enabled vaapi; then
+     require_cc vaapi "va/va.h" "vaCreateSurfaces(0, 0, 0, 0, 0, 0, 0, 0)"
+     check_lib vaapi_drm "va/va.h va/va_drm.h" vaGetDisplayDRM -lva -lva-drm
+     check_lib vaapi_x11 "va/va.h va/va_x11.h" vaGetDisplay -lva -lva-x11 -lX11
+fi
 
 enabled vaapi &&
     test_cpp_condition "va/va.h" "VA_CHECK_VERSION(1, 0, 0)" &&
     enable vaapi_1
 
 enabled vdpau &&
-    test_cpp_condition vdpau/vdpau.h "defined VDP_DECODER_PROFILE_MPEG4_PART2_ASP" ||
-    disable vdpau
+    check_cpp_condition vdpau vdpau/vdpau.h "defined VDP_DECODER_PROFILE_MPEG4_PART2_ASP"
 
 enabled vdpau &&
     check_lib vdpau_x11 "vdpau/vdpau.h vdpau/vdpau_x11.h" vdp_device_create_x11 -lvdpau -lX11
@@ -4807,9 +4832,7 @@ check_disable_warning_headers -Wno-unused-variable
 
 check_objcflags -fobjc-arc && enable objc_arc
 
-test_cc <<EOF && enable blocks_extension
-void (^block)(void);
-EOF
+check_cc blocks_extension "" "void (^block)(void)"
 
 # add some linker flags
 check_ldflags -Wl,--warn-common
@@ -4852,7 +4875,7 @@ enabled xmm_clobber_test &&
                   -Wl,--wrap,sws_scale ||
     disable xmm_clobber_test
 
-test_ld <<EOF && enable proper_dce
+check_ld proper_dce <<EOF
 extern const int array[512];
 static inline int func(void) { return array[0]; }
 int main(void) { return 0; }
@@ -4863,14 +4886,10 @@ if enabled proper_dce; then
     if test_ldflags -Wl,${version_script},$TMPV; then
         append SHFLAGS '-Wl,${version_script},\$(SUBDIR)lib\$(NAME).ver'
         quotes='""'
-        test_cc <<EOF && enable symver_asm_label
-void ff_foo(void) __asm__ ("av_foo@VERSION");
-void ff_foo(void) { ${inline_asm+__asm__($quotes);} }
-EOF
-        test_cc <<EOF && enable symver_gnu_asm
-__asm__(".symver ff_foo,av_foo@VERSION");
-void ff_foo(void) {}
-EOF
+        check_cc symver_asm_label "" "void ff_foo(void) __asm__ ("av_foo@VERSION");
+                                      void ff_foo(void) { ${inline_asm+__asm__($quotes);} }"
+        check_cc symver_gnu_asm   "" "__asm__(".symver ff_foo,av_foo@VERSION");
+                                      void ff_foo(void) {}"
     fi
 fi
 
@@ -4970,7 +4989,7 @@ elif enabled_any msvc icl; then
         disable inline_asm
     fi
     # msvcrt10 x64 incorrectly enables log2, only msvcrt12 (MSVC 2013) onwards actually has log2.
-    test_cpp_condition crtversion.h "_VC_CRT_MAJOR_VERSION >= 12" || disable log2
+    check_cpp_condition log2 crtversion.h "_VC_CRT_MAJOR_VERSION >= 12"
     # The CRT headers contain __declspec(restrict) in a few places, but if redefining
     # restrict, this might break. MSVC 2010 and 2012 fail with __declspec(__restrict)
     # (as it ends up if the restrict redefine is done before including stdlib.h), while