On Wed, 27 Nov 2013, Diego Biurrun wrote:
---
This is a draft I have had lying around for some time.
Comments welcome ...
configure | 111 +++++++++++++++++++++++++++++++++++++++++---------------------
1 file changed, 73 insertions(+), 38 deletions(-)
diff --git a/configure b/configure
index 7918e96..ae714df 100755
--- a/configure
+++ b/configure
@@ -708,6 +708,13 @@ check_cpp(){
check_cmd $cc $CPPFLAGS $CFLAGS "$@" $(cc_e $TMPO) $TMPC
}
+check_host_cpp(){
+ log check_host_cpp "$@"
+ cat > $TMPC
+ log_file $TMPC
+ check_cmd $host_cc $HOSTCPPFLAGS $HOSTCFLAGS "$@" $(hostcc_e $TMPO) $TMPC
+}
+
as_o(){
eval printf '%s\\n' $AS_O
}
@@ -869,6 +876,19 @@ check_cpp_condition(){
EOF
}
+check_host_cpp_condition(){
+ log check_host_cpp_condition "$@"
+ header=$1
+ condition=$2
+ shift 2
+ check_host_cpp "$@" <<EOF
+#include <$header>
+#if !($condition)
+#error "unsatisfied condition: $condition"
+#endif
+EOF
+}
+
check_lib(){
log check_lib "$@"
header="$1"
@@ -986,6 +1006,10 @@ require_pkg_config(){
add_extralibs $(get_safe ${pkg}_libs)
}
+hostcc_e(){
+ eval printf '%s\\n' $HOSTCC_E
+}
+
hostcc_o(){
eval printf '%s\\n' $HOSTCC_O
}
@@ -2056,11 +2080,12 @@ LD_O='-o $@'
LD_LIB='-l%'
LD_PATH='-L'
HOSTCC_C='-c'
+HOSTCC_E='-E -o $@'
HOSTCC_O='-o $@'
HOSTLD_O='-o $@'
host_cflags='-O3 -g'
-host_cppflags='-D_ISOC99_SOURCE -D_XOPEN_SOURCE=600'
+host_cppflags='-D_ISOC99_SOURCE'
host_libs='-lm'
host_cflags_filter=echo
host_ldflags_filter=echo
@@ -3355,45 +3380,52 @@ esac
# determine libc flavour
-# uclibc defines __GLIBC__, so it needs to be checked before glibc.
-if check_cpp_condition features.h "defined __UCLIBC__"; then
- libc_type=uclibc
- add_cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600
-elif check_cpp_condition features.h "defined __GLIBC__"; then
- libc_type=glibc
- add_cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600
-# MinGW headers can be installed on Cygwin, so check for newlib first.
-elif check_cpp_condition newlib.h "defined _NEWLIB_VERSION"; then
- libc_type=newlib
- add_cppflags -U__STRICT_ANSI__
-elif check_header _mingw.h; then
- libc_type=mingw
- check_cpp_condition _mingw.h \
- "defined (__MINGW64_VERSION_MAJOR) || (__MINGW32_MAJOR_VERSION > 3) ||
\
- (__MINGW32_MAJOR_VERSION == 3 && __MINGW32_MINOR_VERSION >= 15)" ||
- die "ERROR: MinGW runtime version must be >= 3.15."
- add_cppflags -U__STRICT_ANSI__
-elif check_func_headers stdlib.h _get_doserrno; then
- libc_type=msvcrt
- add_compat strtod.o strtod=avpriv_strtod
- add_compat msvcrt/snprintf.o snprintf=avpriv_snprintf \
- _snprintf=avpriv_snprintf \
- vsnprintf=avpriv_vsnprintf
- # The MSVC 2010 headers (Win 7.0 SDK) set _WIN32_WINNT to
- # 0x601 by default unless something else is set by the user.
- # This can easily lead to us detecting functions only present
- # in such new versions and producing binaries requiring windows 7.0.
- # Therefore explicitly set the default to XP unless the user has
- # set something else on the command line.
- check_cpp_condition stdlib.h "defined(_WIN32_WINNT)" || add_cppflags
-D_WIN32_WINNT=0x0502
-elif check_cpp_condition stddef.h "defined __KLIBC__"; then
- libc_type=klibc
-elif check_cpp_condition sys/cdefs.h "defined __BIONIC__"; then
- libc_type=bionic
- add_compat strtod.o strtod=avpriv_strtod
-fi
+probe_libc(){
+ pfx=$1
+ # uclibc defines __GLIBC__, so it needs to be checked before glibc.
+ if check_${pfx}cpp_condition features.h "defined __UCLIBC__"; then
+ eval ${pfx}libc_type=uclibc
+ add_${pfx}cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600
+ elif check_${pfx}cpp_condition features.h "defined __GLIBC__"; then
+ eval ${pfx}libc_type=glibc
+ add_${pfx}cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600
+ # MinGW headers can be installed on Cygwin, so check for newlib first.
+ elif check_${pfx}cpp_condition newlib.h "defined _NEWLIB_VERSION"; then
+ eval ${pfx}libc_type=newlib
+ add_${pfx}cppflags -U__STRICT_ANSI__
+ elif check_${pfx}header _mingw.h; then
+ eval ${pfx}libc_type=mingw
+ mingw_condition="defined (__MINGW64_VERSION_MAJOR) || (__MINGW32_MAJOR_VERSION > 3) ||
(__MINGW32_MAJOR_VERSION == 3 && __MINGW32_MINOR_VERSION >= 15)"
+ check_${pfx}cpp_condition _mingw.h "defined $mingw_condition " ||
+ die "ERROR: MinGW runtime version must be >= 3.15."
Any technical reason to split out mingw_condition into a separate variable
here, or is it just an unrelated refactoring you're doing at the same time
(which raises a few questions for a reviewer)? If there's no pressing need
for it (keeping lines short is not enough, when it comes to a nontrivial
change as this one), I'd rather have it kept as before, to reduce the
amount of changes here. It can always be refactored in a separate commit
with an adequate explanation.
+ add_${pfx}cppflags -U__STRICT_ANSI__
+ elif check_${pfx}func_headers stdlib.h _get_doserrno; then
+ eval ${pfx}libc_type=msvcrt
+ add_compat strtod.o strtod=avpriv_strtod
+ add_compat msvcrt/snprintf.o snprintf=avpriv_snprintf \
+ _snprintf=avpriv_snprintf \
+ vsnprintf=avpriv_vsnprintf
Things like add_compat here (and below) should only be done if this is the
target libc, not if it's the host one. In general, every single action
(add/set/whatever) in this needs to include $pfx in one way or another,
otherwise it's doing something wrong.
+ # The MSVC 2010 headers (Win 7.0 SDK) set _WIN32_WINNT to
+ # 0x601 by default unless something else is set by the user.
+ # This can easily lead to us detecting functions only present
+ # in such new versions and producing binaries requiring windows 7.0.
+ # Therefore explicitly set the default to XP unless the user has
+ # set something else on the command line.
+ check_${pfx}cpp_condition stdlib.h "defined(_WIN32_WINNT)" ||
+ add_${pfx}cppflags -D_WIN32_WINNT=0x0502
+ elif check_${pfx}cpp_condition stddef.h "defined __KLIBC__"; then
+ eval ${pfx}libc_type=klibc
+ elif check_${pfx}cpp_condition sys/cdefs.h "defined __BIONIC__"; then
+ eval ${pfx}libc_type=bionic
+ add_compat strtod.o strtod=avpriv_strtod
+ fi
+}
+
+probe_libc
+probe_libc host_
test -n "$libc_type" && enable $libc_type
+test -n "$host_libc_type" && enable $host_libc_type
Not quite. We can't just do "enable $host_libc_type", because we've got
things like "log2_deps=!msvcrt" - what if target is something random (e.g.
crosscompiling) but the host libc happens to be msvcrt?
I'd say it only makes sense to "enable" the target libc (for use in deps
or other checks later), and not enable the host libc at all (requiring
tests that check for it to check for host_libc_type = "msvcrt"), or enable
this one with a different pattern (e.g. "enable host_$host_libc_type").
All in all, it doesn't seem to be all that bad any longer - it might even
be doable to get this in shape.
// Martin
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel