Merge "SDK: fix emulator to build under Cygwin."
diff --git a/Makefile.android b/Makefile.android
index 267bffe..4faea98 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -80,6 +80,20 @@
 
 endif
 
+# Some CFLAGS below use -Wno-missing-field-initializers but this is not
+# supported on GCC 3.x which is still present under Cygwin.
+# Find out by probing GCC for support of this flag. Note that the test
+# itself only works on GCC 4.x anyway.
+GCC_W_NO_MISSING_FIELD_INITIALIZERS := -Wno-missing-field-initializers
+ifeq ($(HOST_OS),windows)
+  ifeq ($(USE_MINGW),)
+    ifeq (,$(shell gcc -Q --help=warnings 2>/dev/null | grep missing-field-initializers))
+        $(info emulator: Ignoring unsupported GCC flag $(GCC_W_NO_MISSING_FIELD_INITIALIZERS))
+        GCC_W_NO_MISSING_FIELD_INITIALIZERS :=
+    endif
+  endif
+endif
+
 # BUILD_STANDALONE_EMULATOR is only defined when building with
 # the android-rebuild.sh script. The script will also provide
 # adequate values for HOST_CC
@@ -132,7 +146,7 @@
 # Enable warning, except those related to missing field initializers
 # (the QEMU coding style loves using these).
 #
-MY_CFLAGS += -Wall -Wno-missing-field-initializers
+MY_CFLAGS += -Wall $(GCC_W_NO_MISSING_FIELD_INITIALIZERS)
 
 # Needed to build fpu/softfloat-native.h properly
 MY_CFLAGS += -D_GNU_SOURCE=1
diff --git a/Makefile.common b/Makefile.common
index 882d638..e24dd33 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -84,6 +84,7 @@
 EMULATOR_COMMON_CFLAGS += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
 endif
 
+
 ###########################################################
 # Zlib sources
 #
@@ -318,7 +319,7 @@
 AUDIO_CFLAGS  := -I$(LOCAL_PATH)/audio -DHAS_AUDIO
 AUDIO_LDLIBS  :=
 
-common_LOCAL_CFLAGS += -Wall -Wno-missing-field-initializers
+common_LOCAL_CFLAGS += -Wall $(GCC_W_NO_MISSING_FIELD_INITIALIZERS)
 
 ifeq ($(HOST_OS),darwin)
   CONFIG_COREAUDIO ?= yes
@@ -396,7 +397,7 @@
 EMULATOR_LIBQEMU_CFLAGS += $(AUDIO_CFLAGS)
 EMULATOR_LIBQEMU_LDLIBS += $(AUDIO_LDLIBS)
 
-common_LOCAL_CFLAGS += -Wno-missing-field-initializers
+common_LOCAL_CFLAGS += $(GCC_W_NO_MISSING_FIELD_INITIALIZERS)
 
 # migration sources
 #
diff --git a/Makefile.target b/Makefile.target
index 3e45c61..5785b1c 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -313,7 +313,7 @@
     LOCAL_CFLAGS += -I$(QEMU_OPENGLES_INCLUDE)
 endif
 
-LOCAL_CFLAGS += -Wno-missing-field-initializers
+LOCAL_CFLAGS += $(GCC_W_NO_MISSING_FIELD_INITIALIZERS)
 
 LOCAL_STATIC_LIBRARIES := \
     emulator-libqemu \