generate_gypi.sh: --disable-avx and --only-config flags

Add two flags to make the script more flexible:
--disable-avx: do not generate AVX and AVX2 sources.
--only-configs: only generate configuration header (i.e. no GN or GYP files).

TESTED=Ran:
./generate_gypi.sh
and verified nothing changed in the checkout.
./generate_gypi.sh --disable-avx
and verified AVX was disabled.
./generate_gypi.sh --only-configs
with a modified .gypi and verified it was not overwritten.

[email protected]

Review URL: https://codereview.chromium.org/1339033002 .
diff --git a/generate_gypi.sh b/generate_gypi.sh
index 08c16d7..d0ce9a5 100755
--- a/generate_gypi.sh
+++ b/generate_gypi.sh
@@ -8,10 +8,13 @@
 # config/platform directories needed to build libvpx.
 # Every time libvpx source code is updated just run this script.
 #
-# For example:
-# $ ./generate_gypi.sh
+# Usage:
+# $ ./generate_gypi.sh [--disable-avx] [--only-configs]
 #
-# And this will update all the .gypi, .gni and config files needed.
+# The following optional flags are supported:
+# --disable-avx : AVX+AVX2 support is disabled.
+# --only-configs: Excludes generation of GN and GYP files (i.e. only
+#                 configuration headers are generated).
 #
 # !!! It's highly recommended to install yasm before running this script.
 
@@ -19,6 +22,25 @@
 BASE_DIR=$(pwd)
 LIBVPX_SRC_DIR="source/libvpx"
 LIBVPX_CONFIG_DIR="source/config"
+unset DISABLE_AVX
+
+for i in "$@"
+do
+case $i in
+  --disable-avx)
+  DISABLE_AVX="--disable-avx --disable-avx2"
+  shift
+  ;;
+  --only-configs)
+  ONLY_CONFIGS=true
+  shift
+  ;;
+  *)
+  echo "Unknown option: $i"
+  exit 1
+  ;;
+esac
+done
 
 # Print license header.
 # $1 - Output base name
@@ -118,7 +140,7 @@
   fi
   echo "      'cflags': [ '-m$4', ]," >> "$2"
   echo "      'xcode_settings': { 'OTHER_CFLAGS': [ '-m$4' ] }," >> "$2"
-  if [[ $4 == avx2 ]]; then
+if [[ -z $DISABLE_AVX && $4 == avx2 ]]; then
   echo "      'msvs_settings': {" >> "$2"
   echo "        'VCCLCompilerTool': {" >> "$2"
   echo "          'EnableEnhancedInstructionSet': '5', # /arch:AVX2" >> "$2"
@@ -183,12 +205,12 @@
   if [ 0 -ne ${#sse4_1_sources} ]; then
     write_target_definition sse4_1_sources[@] "$2" libvpx_intrinsics_sse4_1 sse4.1
   fi
-  if [ 0 -ne ${#avx_sources} ]; then
+  if [[ -z $DISABLE_AVX && 0 -ne ${#avx_sources} ]]; then
     #write_target_definition avx_sources[@] "$2" libvpx_intrinsics_avx avx
     echo "ERROR: Uncomment avx sections in libvpx.gyp"
     exit 1
   fi
-  if [ 0 -ne ${#avx2_sources} ]; then
+  if [[ -z $DISABLE_AVX && 0 -ne ${#avx2_sources} ]]; then
     write_target_definition avx2_sources[@] "$2" libvpx_intrinsics_avx2 avx2
   fi
 
@@ -267,8 +289,10 @@
     write_gni sse3_sources $2_sse3 "$BASE_DIR/libvpx_srcs.gni"
     write_gni ssse3_sources $2_ssse3 "$BASE_DIR/libvpx_srcs.gni"
     write_gni sse4_1_sources $2_sse4_1 "$BASE_DIR/libvpx_srcs.gni"
-    write_gni avx_sources $2_avx "$BASE_DIR/libvpx_srcs.gni"
-    write_gni avx2_sources $2_avx2 "$BASE_DIR/libvpx_srcs.gni"
+    if [ -z "$DISABLE_AVX" ]; then
+      write_gni avx_sources $2_avx "$BASE_DIR/libvpx_srcs.gni"
+      write_gni avx2_sources $2_avx2 "$BASE_DIR/libvpx_srcs.gni"
+    fi
   else
     local c_sources=$(echo "$source_list" | egrep '.(c|h)$')
     local assembly_sources=$(echo -e "$source_list\n$intrinsic_list" | \
@@ -341,28 +365,28 @@
 
   $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \
     --arch=$2 \
-    --sym=vp8_rtcd \
+    --sym=vp8_rtcd $DISABLE_AVX \
     --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
     $BASE_DIR/$LIBVPX_SRC_DIR/vp8/common/rtcd_defs.pl \
     > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vp8_rtcd.h
 
   $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \
     --arch=$2 \
-    --sym=vp9_rtcd \
+    --sym=vp9_rtcd $DISABLE_AVX \
     --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
     $BASE_DIR/$LIBVPX_SRC_DIR/vp9/common/vp9_rtcd_defs.pl \
     > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vp9_rtcd.h
 
   $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \
     --arch=$2 \
-    --sym=vpx_scale_rtcd \
+    --sym=vpx_scale_rtcd $DISABLE_AVX \
     --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
     $BASE_DIR/$LIBVPX_SRC_DIR/vpx_scale/vpx_scale_rtcd.pl \
     > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_scale_rtcd.h
 
   $BASE_DIR/$LIBVPX_SRC_DIR/build/make/rtcd.pl \
     --arch=$2 \
-    --sym=vpx_dsp_rtcd \
+    --sym=vpx_dsp_rtcd $DISABLE_AVX \
     --config=$BASE_DIR/$TEMP_DIR/libvpx.config \
     $BASE_DIR/$LIBVPX_SRC_DIR/vpx_dsp/vpx_dsp_rtcd_defs.pl \
     > $BASE_DIR/$LIBVPX_CONFIG_DIR/$1/vpx_dsp_rtcd.h
@@ -377,7 +401,7 @@
 function gen_config_files {
   ./configure $2 > /dev/null
 
-  # Disable HAVE_UNISTD_H as it causes vp8 to try to detect how many cpus 
+  # Disable HAVE_UNISTD_H as it causes vp8 to try to detect how many cpus
   # available, which doesn't work from iniside a sandbox on linux.
   ( echo '/HAVE_UNISTD_H/s/[01]/0/' ; echo 'w' ; echo 'q' ) | ed -s vpx_config.h
 
@@ -402,7 +426,7 @@
 cd $TEMP_DIR
 
 echo "Generate config files."
-all_platforms="--enable-external-build --enable-postproc --disable-install-srcs --enable-multi-res-encoding --enable-temporal-denoising --disable-unit-tests --disable-install-docs --disable-examples --enable-vp9-temporal-denoising --enable-vp9-postproc --size-limit=16384x16384"
+all_platforms="--enable-external-build --enable-postproc --disable-install-srcs --enable-multi-res-encoding --enable-temporal-denoising --disable-unit-tests --disable-install-docs --disable-examples --enable-vp9-temporal-denoising --enable-vp9-postproc --size-limit=16384x16384 $DISABLE_AVX"
 gen_config_files linux/ia32 "--target=x86-linux-gcc --disable-ccache --enable-pic --enable-realtime-only ${all_platforms}"
 gen_config_files linux/x64 "--target=x86_64-linux-gcc --disable-ccache --enable-pic --enable-realtime-only ${all_platforms}"
 gen_config_files linux/arm "--target=armv6-linux-gcc --enable-pic --enable-realtime-only --disable-install-bins --disable-install-libs --disable-edsp ${all_platforms}"
@@ -463,68 +487,70 @@
 ./configure --target=generic-gnu > /dev/null
 make_clean
 
-# Remove existing .gni file.
-rm -rf $BASE_DIR/libvpx_srcs.gni
-write_license $BASE_DIR/libvpx_srcs.gni
+if [ -z $ONLY_CONFIGS ]; then
+  # Remove existing .gni file.
+  rm -rf $BASE_DIR/libvpx_srcs.gni
+  write_license $BASE_DIR/libvpx_srcs.gni
 
-echo "Generate X86 source list."
-config=$(print_config linux/ia32)
-make_clean
-make libvpx_srcs.txt target=libs $config > /dev/null
-convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_x86
+  echo "Generate X86 source list."
+  config=$(print_config linux/ia32)
+  make_clean
+  make libvpx_srcs.txt target=libs $config > /dev/null
+  convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_x86
 
-# Copy vpx_version.h. The file should be the same for all platforms.
-cp vpx_version.h $BASE_DIR/$LIBVPX_CONFIG_DIR
+  # Copy vpx_version.h. The file should be the same for all platforms.
+  cp vpx_version.h $BASE_DIR/$LIBVPX_CONFIG_DIR
 
-echo "Generate X86_64 source list."
-config=$(print_config linux/x64)
-make_clean
-make libvpx_srcs.txt target=libs $config > /dev/null
-convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_x86_64
+  echo "Generate X86_64 source list."
+  config=$(print_config linux/x64)
+  make_clean
+  make libvpx_srcs.txt target=libs $config > /dev/null
+  convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_x86_64
 
-echo "Generate ARM source list."
-config=$(print_config linux/arm)
-make_clean
-make libvpx_srcs.txt target=libs $config > /dev/null
-convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_arm
+  echo "Generate ARM source list."
+  config=$(print_config linux/arm)
+  make_clean
+  make libvpx_srcs.txt target=libs $config > /dev/null
+  convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_arm
 
-echo "Generate ARM NEON source list."
-config=$(print_config linux/arm-neon)
-make_clean
-make libvpx_srcs.txt target=libs $config > /dev/null
-convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_arm_neon
+  echo "Generate ARM NEON source list."
+  config=$(print_config linux/arm-neon)
+  make_clean
+  make libvpx_srcs.txt target=libs $config > /dev/null
+  convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_arm_neon
 
-echo "Generate ARM NEON CPU DETECT source list."
-config=$(print_config linux/arm-neon-cpu-detect)
-make_clean
-make libvpx_srcs.txt target=libs $config > /dev/null
-convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_arm_neon_cpu_detect
+  echo "Generate ARM NEON CPU DETECT source list."
+  config=$(print_config linux/arm-neon-cpu-detect)
+  make_clean
+  make libvpx_srcs.txt target=libs $config > /dev/null
+  convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_arm_neon_cpu_detect
 
-echo "Generate ARM64 source list."
-config=$(print_config linux/arm64)
-make_clean
-make libvpx_srcs.txt target=libs $config > /dev/null
-convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_arm64
+  echo "Generate ARM64 source list."
+  config=$(print_config linux/arm64)
+  make_clean
+  make libvpx_srcs.txt target=libs $config > /dev/null
+  convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_arm64
 
-echo "Generate MIPS source list."
-config=$(print_config_basic linux/mipsel)
-make_clean
-make libvpx_srcs.txt target=libs $config > /dev/null
-convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_mips
+  echo "Generate MIPS source list."
+  config=$(print_config_basic linux/mipsel)
+  make_clean
+  make libvpx_srcs.txt target=libs $config > /dev/null
+  convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_mips
 
-echo "MIPS64 source list is identical to MIPS source list. No need to generate it."
+  echo "MIPS64 source list is identical to MIPS source list. No need to generate it."
 
-echo "Generate NaCl source list."
-config=$(print_config_basic nacl)
-make_clean
-make libvpx_srcs.txt target=libs $config > /dev/null
-convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_nacl
+  echo "Generate NaCl source list."
+  config=$(print_config_basic nacl)
+  make_clean
+  make libvpx_srcs.txt target=libs $config > /dev/null
+  convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_nacl
 
-echo "Generate GENERIC source list."
-config=$(print_config_basic linux/generic)
-make_clean
-make libvpx_srcs.txt target=libs $config > /dev/null
-convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_generic
+  echo "Generate GENERIC source list."
+  config=$(print_config_basic linux/generic)
+  make_clean
+  make libvpx_srcs.txt target=libs $config > /dev/null
+  convert_srcs_to_project_files libvpx_srcs.txt libvpx_srcs_generic
+fi
 
 echo "Remove temporary directory."
 cd $BASE_DIR