commit 11de6aa1092b689d55fb05b613a5b17bdaed22ad
Author: Christopher Szymczyk <cszymczyk@supra-elektronik.com>
Date:   Tue Feb 16 07:52:33 2016 -0800

    mips patch

diff --git a/cerbero/enums.py b/cerbero/enums.py
index f1fcfd2..bdff6ba 100644
--- a/cerbero/enums.py
+++ b/cerbero/enums.py
@@ -35,6 +35,7 @@ class Architecture:
     ARMv7 = 'armv7'
     ARMv7S = 'armv7s'
     ARM64 = 'arm64'
+    MIPS = 'mips'
 
     @staticmethod
     def is_arm(arch):
diff --git a/config/android.config b/config/android.config
index 82227db..65b3d9c 100644
--- a/config/android.config
+++ b/config/android.config
@@ -47,6 +47,20 @@ elif target_arch == Architecture.ARM64:
                 break
         if toolchain_path:
             break
+elif target_arch == Architecture.MIPS:
+    tools_prefix = 'mipsel-linux-android'
+    host = "mipsel-linux-android"
+    _arch = 'mips'
+
+    for tc_version in ['4.9', '4.8', '4.7', '4.6']:
+        for tc_arch in ['linux-x86', 'linux-x86_64']:
+            tmp = '%s/toolchains/mipsel-linux-android-%s/prebuilt/%s/bin' % (toolchain_prefix, tc_version, tc_arch)
+            if os.path.exists(tmp):
+                toolchain_path = tmp
+		toolchain_version = tc_version
+                break
+        if toolchain_path:
+            break
 elif target_arch == Architecture.X86:
     tools_prefix = 'i686-linux-android'
     host = "i686-linux-android"
@@ -128,7 +142,9 @@ if target_arch in [Architecture.ARM, Architecture.ARMv7, Architecture.ARM64]:
         ldflags += "-march=armv7-a -Wl,--fix-cortex-a8 "
 elif target_arch == Architecture.X86:
     cflags += ' -march=i686 -fomit-frame-pointer -fstrict-aliasing -funswitch-loops -finline-limit=300'
-
+elif target_arch == Architecture.MIPS:
+    cflags += ' -march=mips32r2 -fomit-frame-pointer -fstrict-aliasing -funswitch-loops -finline-limit=300'
+    ldflags += ' -march=mips32r2 '
 
 # Toolchain environment
 os.environ['CPPFLAGS'] = '--sysroot=%s -I%s/usr/include %s' % (sysroot, sysroot, defines)
@@ -140,10 +156,15 @@ def cmd(command):
     return '%s-%s' % (tools_prefix, command)
 
 os.environ['CC']= '%s%s' % (ccache, cmd('gcc'))
-os.environ['CC'] += ' -fuse-ld=%s' % ldvariant
+if target_arch != Architecture.MIPS:
+	os.environ['CC'] += ' -fuse-ld=%s' % ldvariant
 os.environ['CXX']= '%s%s' % (ccache, cmd('g++'))
-os.environ['CXX'] += ' -fuse-ld=%s' % ldvariant
-os.environ['LD']= cmd('ld.%s' % ldvariant)
+if target_arch != Architecture.MIPS:
+	os.environ['CXX'] += ' -fuse-ld=%s' % ldvariant
+if target_arch == Architecture.MIPS:
+	os.environ['LD']= cmd('ld')
+else:
+	os.environ['LD']= cmd('ld.%s' % ldvariant)
 os.environ['CPP']= cmd('cpp')
 os.environ['RANLIB']= cmd('ranlib')
 os.environ['AR']= cmd('ar')
diff --git a/config/cross-android-mips.cbc b/config/cross-android-mips.cbc
new file mode 100644
index 0000000..cf7d023
--- /dev/null
+++ b/config/cross-android-mips.cbc
@@ -0,0 +1,9 @@
+import os
+from cerbero.config import Platform, Architecture, Distro, DistroVersion
+
+target_platform = Platform.ANDROID
+target_distro = Distro.ANDROID
+target_distro_version = DistroVersion.ANDROID_GINGERBREAD
+target_arch = Architecture.MIPS
+
+#variants = ['nodebug']
diff --git a/recipes/gnustl.recipe b/recipes/gnustl.recipe
index 7276fe0..dc71b0f 100644
--- a/recipes/gnustl.recipe
+++ b/recipes/gnustl.recipe
@@ -3,6 +3,7 @@ import shutil
 
 from cerbero.tools.libtool import LibtoolLibrary
 from cerbero.tools.pkgconfig import PkgConfigWritter
+from cerbero.utils import messages as m
 
 class Recipe(recipe.Recipe):
     name = 'gnustl'
@@ -24,6 +25,10 @@ class Recipe(recipe.Recipe):
     def prepare(self):
         if self.config.target_platform != Platform.ANDROID:
             raise InvalidRecipeError(self, "Invalid platform")
+        else:
+            m.message(_("Building the following recipes: *********************"))
+            m.message(_("Building the following recipes: %s") % self.config.toolchain_prefix)
+            m.message(_("Building the following recipes: %s") % self.config.toolchain_version)
 
     def install(self):
         stl_prefix = os.path.join(self.config.toolchain_prefix, 'sources',
@@ -38,6 +43,8 @@ class Recipe(recipe.Recipe):
             stl_libdir = os.path.join(stl_prefix, 'libs', 'arm64-v8a')
         elif self.config.target_arch == Architecture.ARM:
             stl_libdir = os.path.join(stl_prefix, 'libs', 'armeabi')
+        elif self.config.target_arch == Architecture.MIPS:
+            stl_libdir = os.path.join(stl_prefix, 'libs', 'mips')
         else:
             raise FatalError("Unsupported Android architecture %s" % self.config.target_arch)
         libdir = os.path.join(self.config.prefix, 'lib')
diff --git a/recipes/libmad.recipe b/recipes/libmad.recipe
index 7d326c0..e7dd618 100644
--- a/recipes/libmad.recipe
+++ b/recipes/libmad.recipe
@@ -26,7 +26,8 @@ class Recipe(recipe.Recipe):
             self.patches += ['libmad/0004-Remove-clang-unsupported-compiler-flags.patch']
         elif self.config.target_platform == Platform.ANDROID:
             if Architecture.is_arm(self.config.target_arch):
-                # Disable thumb mode to get the optimizations compiled properly
+               # Disable thumb mode to get the optimizations compiled properly
                 self.new_env['CFLAGS'] = os.environ['CFLAGS'].replace('-mthumb', '')
             if self.config.target_arch == Architecture.X86:
                 self.new_env['CFLAGS'] = os.environ['CFLAGS'] + ' -fno-stack-protector'
+
diff --git a/recipes/libmad/0005-imp_constraint.patch b/recipes/libmad/0005-imp_constraint.patch
new file mode 100644
index 0000000..903ae03
--- /dev/null
+++ b/recipes/libmad/0005-imp_constraint.patch
@@ -0,0 +1,34 @@
+diff -u -r a/apps/codecs/libmad/fixed.h b/apps/codecs/libmad/fixed.h
+--- a/fixed.h
++++ b/fixed.h
+@@ -292,6 +292,21 @@
+ 
+ # elif defined(FPM_MIPS)
+ 
++#if defined (__GNUC__) && defined (__GNUC_MINOR__) 
++#define __GNUC_PREREQ(maj, min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) 
++#else 
++#define __GNUC_PREREQ(maj, min)  0 
++#endif 
++
++#if __GNUC_PREREQ(4,4) 
++typedef unsigned int u64_di_t __attribute__ ((mode (DI))); 
++# define MAD_F_MLX(hi, lo, x, y) \
++do { \
++   u64_di_t __ll = (u64_di_t) (x) * (y); \
++   hi = __ll >> 32; \
++   lo = __ll; \
++}while(0)
++#else
+ /*
+  * This MIPS version is fast and accurate; the disposition of the least
+  * significant bit depends on OPT_ACCURACY via mad_f_scale64().
+@@ -321,6 +336,8 @@
+          : "%r" ((x) >> 12), "r" ((y) >> 16))
+ #  define MAD_F_MLZ(hi, lo)  ((mad_fixed_t) (lo))
+ # endif
++
++#endif /* __GNU_PREREQ(4,4) */ 
+ 
+ # if defined(OPT_SPEED)
+ #  define mad_f_scale64(hi, lo)  \
diff --git a/recipes/libvpx.recipe b/recipes/libvpx.recipe
index 966822a..0a2182b 100644
--- a/recipes/libvpx.recipe
+++ b/recipes/libvpx.recipe
@@ -15,7 +15,8 @@ class Recipe(recipe.Recipe):
                     "--libdir=%(libdir)s %(options)s"
     configure_options = "--enable-pic --as=yasm --disable-unit-tests --size-limit=16384x16384 "\
                         "--enable-postproc --enable-multi-res-encoding --enable-temporal-denoising "\
-                        "--enable-vp9-temporal-denoising --enable-vp9-postproc "
+                        "--enable-vp9-temporal-denoising --enable-vp9-postproc "\
+                        "--disable-examples --disable-docs"
     add_host_build_target = False
     supports_cache_variables = False
     can_use_configure_cache = False
@@ -27,6 +28,8 @@ class Recipe(recipe.Recipe):
                'libvpx/0005-build-Remove-broken-custom-android-toolchain-usage.patch',
                'libvpx/0006-configure-Add-Android-ARM64-support.patch',
                'libvpx/0006-Don-t-embed-bitcode-on-iOS-until-we-support-that-pro.patch',
+               'libvpx/0009-configure-mips.patch',
+               'libvpx/0010-androidmk-mips.patch',
                ]
 
     files_libs = ['libvpx']
@@ -50,6 +53,8 @@ class Recipe(recipe.Recipe):
             arch = 'armv7s'
         elif self.config.target_arch == Architecture.ARM64:
             arch = 'arm64'
+        elif self.config.target_arch == Architecture.MIPS:
+            arch = 'mips'
 
         self.new_env['LD'] = os.environ.get('CC', 'gcc')
         if self.config.target_platform == Platform.DARWIN:
@@ -88,6 +93,8 @@ class Recipe(recipe.Recipe):
                 self.new_env['CFLAGS'] = os.environ['CFLAGS'].replace('-mthumb', '')
             elif self.config.target_arch in [Architecture.ARMv7, Architecture.X86, Architecture.ARM64, Architecture.X86_64]:
                 pass
+            elif self.config.target_arch == Architecture.MIPS:
+                arch = 'mips32'
             else:
                 raise FatalError("Unsupported Android architecture %s" % self.config.target_arch)
             self.config_sh = 'LD=$CC ./configure'
diff --git a/recipes/libvpx/0009-configure-mips.patch b/recipes/libvpx/0009-configure-mips.patch
new file mode 100644
index 0000000..fa33b61
--- /dev/null
+++ b/recipes/libvpx/0009-configure-mips.patch
@@ -0,0 +1,11 @@
+--- a/configure
++++ b/configure
+@@ -102,6 +102,7 @@ all_platforms="${all_platforms} mips32-android-gcc"
+ all_platforms="${all_platforms} armv7-win32-vs11"
+ all_platforms="${all_platforms} armv7-win32-vs12"
+ all_platforms="${all_platforms} mips32-linux-gcc"
++all_platforms="${all_platforms} mips32-android-gcc"
+ all_platforms="${all_platforms} ppc32-darwin8-gcc"
+ all_platforms="${all_platforms} ppc32-darwin9-gcc"
+ all_platforms="${all_platforms} ppc32-linux-gcc"-- 
+
diff --git a/recipes/libvpx/0010-androidmk-mips.patch b/recipes/libvpx/0010-androidmk-mips.patch
new file mode 100644
index 0000000..5e9eb02
--- /dev/null
+++ b/recipes/libvpx/0010-androidmk-mips.patch
@@ -0,0 +1,106 @@
+diff --git a/build/make/Android.mk b/build/make/Android.mk
+index 48a0dd7..369c2a5 100644
+--- a/build/make/Android.mk
++++ b/build/make/Android.mk
+@@ -53,12 +53,20 @@
+ ASM_CNV_PATH_LOCAL := $(TARGET_ARCH_ABI)/ads2gas
+ ASM_CNV_PATH := $(LOCAL_PATH)/$(ASM_CNV_PATH_LOCAL)
+ 
+-# Makefiles created by the libvpx configure process
+-# This will need to be fixed to handle x86.
++# Use the makefiles generated by upstream configure to determine which files to
++# build. Also set any architecture-specific flags.
+ ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
+   include $(CONFIG_DIR)libs-armv7-android-gcc.mk
+-else
++  LOCAL_ARM_MODE := arm
++else ifeq  ($(TARGET_ARCH_ABI),armeabi)
+   include $(CONFIG_DIR)libs-armv5te-android-gcc.mk
++  LOCAL_ARM_MODE := arm
++else ifeq ($(TARGET_ARCH_ABI),x86)
++  include $(CONFIG_DIR)libs-x86-android-gcc.mk
++else ifeq ($(TARGET_ARCH_ABI),mips)
++  include $(CONFIG_DIR)libs-mips-android-gcc.mk
++else
++  $(error Not a supported TARGET_ARCH_ABI: $(TARGET_ARCH_ABI))
+ endif
+ 
+ # Rule that is normally in Makefile created by libvpx
+@@ -72,9 +80,12 @@
+ # Include the list of files to be built
+ include $(LIBVPX_PATH)/libs.mk
+ 
+-# Want arm, not thumb, optimized
+-LOCAL_ARM_MODE := arm
++# Optimise the code. May want to revisit this setting in the future.
+ LOCAL_CFLAGS := -O3
++
++# For x86, include the source code in the search path so it will find files
++# like x86inc.asm and x86_abi_support.asm
++LOCAL_ASMFLAGS := -I$(LIBVPX_PATH)
+ 
+ # -----------------------------------------------------------------------------
+ # Template  : asm_offsets_template
+@@ -109,7 +120,7 @@
+ 	@grep $(OFFSET_PATTERN) $$< | tr -d '\#' | $(CONFIG_DIR)$(ASM_CONVERSION) > $$@
+ endef
+ 
+-# Use ads2gas script to convert from RVCT format to GAS format.  This passes
++# Use ads2gas script to convert from RVCT format to GAS format.  This
+ #  puts the processed file under $(ASM_CNV_PATH).  Local clean rule
+ #  to handle removing these
+ ifeq ($(CONFIG_VP8_ENCODER), yes)
+@@ -146,18 +157,26 @@
+ 
+ # Pull out assembly files, splitting NEON from the rest.  This is
+ # done to specify that the NEON assembly files use NEON assembler flags.
+-CODEC_SRCS_ASM_ALL = $(filter %.asm.s, $(CODEC_SRCS_UNIQUE))
+-CODEC_SRCS_ASM = $(foreach v, \
+-                 $(CODEC_SRCS_ASM_ALL), \
+-                 $(if $(findstring neon,$(v)),,$(v)))
++# x86 assembly matches %.asm, arm matches %.asm.s
++
++# x86:
++
++CODEC_SRCS_ASM_X86 = $(filter %.asm, $(CODEC_SRCS_UNIQUE))
++LOCAL_SRC_FILES += $(foreach file, $(CODEC_SRCS_ASM_X86), libvpx/$(file))
++
++# arm:
++CODEC_SRCS_ASM_ARM_ALL = $(filter %.asm.s, $(CODEC_SRCS_UNIQUE))
++CODEC_SRCS_ASM_ARM = $(foreach v, \
++                     $(CODEC_SRCS_ASM_ARM_ALL), \
++                     $(if $(findstring neon,$(v)),,$(v)))
+ CODEC_SRCS_ASM_ADS2GAS = $(patsubst %.s, \
+                          $(ASM_CNV_PATH_LOCAL)/libvpx/%.s, \
+-                         $(CODEC_SRCS_ASM))
++                         $(CODEC_SRCS_ASM_ARM))
+ LOCAL_SRC_FILES += $(CODEC_SRCS_ASM_ADS2GAS)
+ 
+ ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
+   CODEC_SRCS_ASM_NEON = $(foreach v, \
+-                        $(CODEC_SRCS_ASM_ALL),\
++                        $(CODEC_SRCS_ASM_ARM_ALL),\
+                         $(if $(findstring neon,$(v)),$(v),))
+   CODEC_SRCS_ASM_NEON_ADS2GAS = $(patsubst %.s, \
+                                 $(ASM_CNV_PATH_LOCAL)/libvpx/%.s, \
+@@ -189,6 +208,10 @@
+ endif
+ $(foreach file, $(LOCAL_SRC_FILES), $(LOCAL_PATH)/$(file)): vpx_scale_rtcd.h
+ 
++ifeq ($(TARGET_ARCH_ABI),x86)
++$(foreach file, $(LOCAL_SRC_FILES), $(LOCAL_PATH)/$(file)): vpx_config.asm
++endif
++
+ .PHONY: clean
+ clean:
+ 	@echo "Clean: ads2gas files [$(TARGET_ARCH_ABI)]"
+diff --git a/test/android/README b/test/android/README
+index 6840d91..4a1adcf 100644
+--- a/test/android/README
++++ b/test/android/README
+@@ -3,7 +3,7 @@
+ ./libvpx/configure --target=armv7-android-gcc --enable-external-build \
+   --enable-postproc --disable-install-srcs --enable-multi-res-encoding \
+   --enable-temporal-denoising --disable-unit-tests --disable-install-docs \
+-  --disable-examples --disable-runtime-cpu-detect --sdk=$NDK
++  --disable-examples --disable-runtime-cpu-detect --sdk-path=$NDK
