[x264-devel] Recognize cygwin as itself when not targeting mingw

Steven Walters git at videolan.org
Thu Mar 24 06:38:35 CET 2011


x264 | branch: master | Steven Walters <kemuri9 at gmail.com> | Wed Mar  2 21:31:27 2011 -0500| [372ba94b66c25c49a8d9c924413cbb09d4fa4805] | committer: Jason Garrett-Glaser

Recognize cygwin as itself when not targeting mingw
Also fix broken thread detection on cygwin.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=372ba94b66c25c49a8d9c924413cbb09d4fa4805
---

 common/cpu.c |    5 ++++-
 configure    |   29 ++++++++++++++++++-----------
 2 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/common/cpu.c b/common/cpu.c
index a6bc121..2d43e85 100644
--- a/common/cpu.c
+++ b/common/cpu.c
@@ -358,9 +358,12 @@ int x264_cpu_num_processors( void )
 #if !HAVE_THREAD
     return 1;
 
-#elif defined(_WIN32)
+#elif SYS_WINDOWS
     return x264_pthread_num_processors_np();
 
+#elif SYS_CYGWIN
+    return sysconf( _SC_NPROCESSORS_ONLN );
+
 #elif SYS_LINUX
     unsigned int bit;
     int np;
diff --git a/configure b/configure
index e4c7729..aea0367 100755
--- a/configure
+++ b/configure
@@ -395,13 +395,18 @@ case $host_os in
         LDFLAGS="$LDFLAGS -lm"
         ;;
     cygwin*)
-        SYS="WINDOWS"
         EXE=".exe"
-        DEVNULL="NUL"
         if cc_check "" -mno-cygwin; then
             CFLAGS="$CFLAGS -mno-cygwin"
             LDFLAGS="$LDFLAGS -mno-cygwin"
         fi
+        if cpp_check "" "" "defined(__CYGWIN32__)" ; then
+            define HAVE_MALLOC_H
+            SYS="CYGWIN"
+        else
+            SYS="WINDOWS"
+            DEVNULL="NUL"
+        fi
         ;;
     mingw*)
         SYS="WINDOWS"
@@ -454,7 +459,7 @@ case $host_cpu in
         fi
         if [ "$SYS" = MACOSX ]; then
             ASFLAGS="$ASFLAGS -f macho -DPREFIX"
-        elif [ "$SYS" = WINDOWS ]; then
+        elif [ "$SYS" = WINDOWS -o "$SYS" = CYGWIN ]; then
             ASFLAGS="$ASFLAGS -f win32 -DPREFIX"
             LDFLAGS="$LDFLAGS -Wl,--large-address-aware"
         else
@@ -566,14 +571,14 @@ fi
 
 if [ $asm = auto -a \( $ARCH = X86 -o $ARCH = X86_64 \) ] ; then
     if ! as_check "vpaddw xmm0, xmm0, xmm0" ; then
-        VER=`($AS --version || echo no assembler) 2>$DEVNULL | head -n 1`
+        VER=`($AS --version || echo no assembler) 2>/dev/null | head -n 1`
         echo "Found $VER"
         echo "Minimum version is yasm-0.7.0"
         echo "If you really want to compile without asm, configure with --disable-asm."
         exit 1
     fi
     if ! cc_check '' '' '__asm__("pabsw %xmm0, %xmm0");' ; then
-        VER=`(${cross_prefix}as --version || echo no gnu as) 2>$DEVNULL | head -n 1`
+        VER=`(${cross_prefix}as --version || echo no gnu as) 2>/dev/null | head -n 1`
         echo "Found $VER"
         echo "Minimum version is binutils-2.17"
         echo "Your compiler can't handle inline SSSE3 asm."
@@ -607,7 +612,7 @@ define SYS_$SYS
 # skip endianness check for Intel Compiler, as all supported platforms are little. the -ipo flag will also cause the check to fail
 if [ $compiler = GNU ]; then
     echo "int i[2] = {0x42494745,0}; double f[2] = {0x1.0656e6469616ep+102,0};" > conftest.c
-    $CC $CFLAGS conftest.c -c -o conftest.o 2>$DEVNULL || die "endian test failed"
+    $CC $CFLAGS conftest.c -c -o conftest.o 2>/dev/null || die "endian test failed"
     if (${cross_prefix}strings -a conftest.o | grep -q BIGE) && (${cross_prefix}strings -a conftest.o | grep -q FPendian) ; then
         define WORDS_BIGENDIAN
     elif !(${cross_prefix}strings -a conftest.o | grep -q EGIB && ${cross_prefix}strings -a conftest.o | grep -q naidnePF) ; then
@@ -661,6 +666,7 @@ if [ "$thread" = "posix" ]; then
     define HAVE_POSIXTHREAD
 fi
 if [ "$thread" = "win32" ]; then
+    # cygwin does not support win32 threads
     if [ "$SYS" = "WINDOWS" ]; then
         define HAVE_WIN32THREAD
     else
@@ -687,7 +693,7 @@ fi
 
 if [ "$swscale" = "auto" ] ; then
     swscale="no"
-    if ${cross_prefix}pkg-config --exists libswscale 2>$DEVNULL; then
+    if ${cross_prefix}pkg-config --exists libswscale 2>/dev/null; then
         SWSCALE_LIBS="$SWSCALE_LIBS $(${cross_prefix}pkg-config --libs libswscale)"
         SWSCALE_CFLAGS="$SWSCALE_CFLAGS $(${cross_prefix}pkg-config --cflags libswscale)"
     fi
@@ -710,7 +716,7 @@ fi
 
 if [ "$lavf" = "auto" ] ; then
     lavf="no"
-    if ${cross_prefix}pkg-config --exists libavformat libavcodec libswscale 2>$DEVNULL; then
+    if ${cross_prefix}pkg-config --exists libavformat libavcodec libswscale 2>/dev/null; then
         LAVF_LIBS="$LAVF_LIBS $(${cross_prefix}pkg-config --libs libavformat libavcodec libavutil libswscale)"
         LAVF_CFLAGS="$LAVF_CFLAGS $(${cross_prefix}pkg-config --cflags libavformat libavcodec libavutil libswscale)"
     fi
@@ -739,7 +745,7 @@ if [ "$ffms" = "auto" ] ; then
     ffms_major="2"; ffms_minor="14"; ffms_micro="0"; ffms_bump="0"
     ffms="no"
 
-    if ${cross_prefix}pkg-config --exists ffms2 2>$DEVNULL; then
+    if ${cross_prefix}pkg-config --exists ffms2 2>/dev/null; then
         FFMS2_LIBS="$FFMS2_LIBS $(${cross_prefix}pkg-config --libs ffms2)"
         FFMS2_CFLAGS="$FFMS2_CFLAGS $(${cross_prefix}pkg-config --cflags ffms2)"
     fi
@@ -803,7 +809,8 @@ fi
 
 if [ "$avs" = "auto" ] ; then
     avs="no"
-    if [ $SYS = WINDOWS ] && cc_check extras/avisynth_c.h ; then
+    # cygwin can use avisynth if it can use LoadLibrary
+    if [ $SYS = WINDOWS ] || ([ $SYS = CYGWIN ] && cc_check windows.h "" "LoadLibrary(0);") ; then
         avs="yes"
         define HAVE_AVS
     fi
@@ -956,7 +963,7 @@ fi
 
 if [ "$shared" = "yes" ]; then
     API=$(grep '#define X264_BUILD' < x264.h | cut -f 3 -d ' ')
-    if [ "$SYS" = "WINDOWS" ]; then
+    if [ "$SYS" = "WINDOWS" -o "$SYS" = "CYGWIN" ]; then
         echo "SONAME=libx264-$API.dll" >> config.mak
         if [ $compiler = ICL ]; then
             echo 'IMPLIBNAME=libx264.dll.lib' >> config.mak



More information about the x264-devel mailing list