Revert "Use libvpx's obj_int_extract and unpack_lib_posix to generate offset header file."

This reverts commit 7686f0ddda717a9e776be0e219f039f68a10f9ed.

BUG=

TBR=andrew@webrtc.org, fischman@webrtc.org,

Review URL: https://webrtc-codereview.appspot.com/8369004

git-svn-id: http://webrtc.googlecode.com/svn/trunk/webrtc@5520 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/build/common.gypi b/build/common.gypi
index d8b958a..e4a4b09 100644
--- a/build/common.gypi
+++ b/build/common.gypi
@@ -25,13 +25,11 @@
             'webrtc_root%': '<(DEPTH)/third_party/webrtc',
             'apk_tests_path%': '<(DEPTH)/third_party/webrtc/build/apk_tests.gyp',
             'modules_java_gyp_path%': '<(DEPTH)/third_party/webrtc/modules/modules_java_chromium.gyp',
-            'gen_core_neon_offsets_gyp%': '<(DEPTH)/third_party/webrtc/modules/audio_processing/gen_core_neon_offsets_chromium.gyp',
           }, {
             'build_with_libjingle%': 0,
             'webrtc_root%': '<(DEPTH)/webrtc',
             'apk_tests_path%': '<(DEPTH)/webrtc/build/apk_test_noop.gyp',
             'modules_java_gyp_path%': '<(DEPTH)/webrtc/modules/modules_java.gyp',
-            'gen_core_neon_offsets_gyp%':'<(DEPTH)/webrtc/modules/audio_processing/gen_core_neon_offsets.gyp',
           }],
         ],
       },
@@ -40,7 +38,7 @@
       'webrtc_root%': '<(webrtc_root)',
       'apk_tests_path%': '<(apk_tests_path)',
       'modules_java_gyp_path%': '<(modules_java_gyp_path)',
-      'gen_core_neon_offsets_gyp%': '<(gen_core_neon_offsets_gyp)',
+
       'webrtc_vp8_dir%': '<(webrtc_root)/modules/video_coding/codecs/vp8',
       'rbe_components_path%': '<(webrtc_root)/modules/remote_bitrate_estimator',
       'include_opus%': 1,
@@ -50,7 +48,6 @@
     'webrtc_root%': '<(webrtc_root)',
     'apk_tests_path%': '<(apk_tests_path)',
     'modules_java_gyp_path%': '<(modules_java_gyp_path)',
-    'gen_core_neon_offsets_gyp%': '<(gen_core_neon_offsets_gyp)',
     'webrtc_vp8_dir%': '<(webrtc_vp8_dir)',
     'include_opus%': '<(include_opus)',
     'rbe_components_path%': '<(rbe_components_path)',
diff --git a/build/generate_asm_header.gypi b/build/generate_asm_header.gypi
new file mode 100644
index 0000000..4600bb1
--- /dev/null
+++ b/build/generate_asm_header.gypi
@@ -0,0 +1,79 @@
+# Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
+#
+# Use of this source code is governed by a BSD-style license
+# that can be found in the LICENSE file in the root of the source
+# tree. An additional intellectual property rights grant can be found
+# in the file PATENTS.  All contributing project authors may
+# be found in the AUTHORS file in the root of the source tree.
+
+# This file is meant to be included into a target to provide an action
+# to generate C header files. These headers include definitions
+# that can be used in ARM assembly files.
+#
+# To use this, create a gyp target with the following form:
+# {
+#   'target_name': 'my_asm_headers_lib',
+#   'type': 'static_library',
+#   'sources': [
+#     'foo.c',
+#     'bar.c',
+#   ],
+#   'includes': ['path/to/this/gypi/file'],
+# }
+#
+# The headers are guaranteed to be generated before any
+# source files, even within this target, are compiled.
+#
+# The 'asm_header_dir' variable specifies the path suffix that output
+# files are generated under.
+
+# TODO(kma): port this block from Android into other build systems.
+{
+  'variables': {
+    'out_dir': '<(SHARED_INTERMEDIATE_DIR)/<(asm_header_dir)',
+    'process_outputs_as_sources': 1,
+    'conditions': [
+      # We only support Android and iOS.
+      ['OS=="android"', {
+        'compiler_to_use':
+          '<!(/bin/echo -n ${ANDROID_GOMA_WRAPPER} <(android_toolchain)/*-gcc)',
+        'compiler_options': '-I<(webrtc_root)/.. -I<@(android_ndk_include) -S',
+        'pattern_to_detect': 'offset_',
+      }],
+      ['OS=="ios"', {
+        'compiler_to_use': 'clang',
+        'compiler_options':
+          '-arch armv7 -I<(webrtc_root)/.. -isysroot $(SDKROOT) -S',
+        'pattern_to_detect': '_offset_',
+      }],
+    ]
+  },
+  'rules': [
+    {
+      'rule_name': 'generate_asm_header',
+      'extension': 'c',
+      'inputs': [
+        'generate_asm_header.py',
+      ],
+      'outputs': [
+        '<(out_dir)/<(RULE_INPUT_ROOT).h',
+      ],
+      'action': [
+        'python',
+        '<(webrtc_root)/build/generate_asm_header.py',
+        '--compiler=<(compiler_to_use)',
+        '--options=<(compiler_options)',
+        '--pattern=<(pattern_to_detect)',
+        '--dir=<(out_dir)',
+        '<(RULE_INPUT_PATH)',
+      ],
+      'message': 'Generating assembly header files',
+      'process_outputs_as_sources': 1,
+    },
+  ],
+  'direct_dependent_settings': {
+    'include_dirs': ['<(out_dir)',],
+  },
+  # This target exports a hard dependency because it generates header files.
+  'hard_dependency': 1,
+}
diff --git a/build/generate_asm_header.py b/build/generate_asm_header.py
new file mode 100644
index 0000000..c159d50
--- /dev/null
+++ b/build/generate_asm_header.py
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
+#
+# Use of this source code is governed by a BSD-style license
+# that can be found in the LICENSE file in the root of the source
+# tree. An additional intellectual property rights grant can be found
+# in the file PATENTS.  All contributing project authors may
+# be found in the AUTHORS file in the root of the source tree.
+
+"""This script is a tool to generate special header files from input
+C source files.
+
+It first assembles the input source files to generate intermediate assembly
+files (*.s). Then it parses the .s files and finds declarations of variables
+whose names start with the string specified as the third argument in the
+command-line, translates the variable names and values into constant defines
+and writes them into header files.
+"""
+
+import os
+import re
+import subprocess
+import sys
+from optparse import OptionParser
+
+def main(argv):
+  parser = OptionParser()
+  usage = 'Usage: %prog [options] input_filename'
+  parser.set_usage(usage)
+  parser.add_option('--compiler', default = 'gcc', help = 'compiler name')
+  parser.add_option('--options', default = '-S', help = 'compiler options')
+  parser.add_option('--pattern', default = 'offset_', help = 'A match pattern'
+                    ' used for searching the relevant constants.')
+  parser.add_option('--dir', default = '.', help = 'output directory')
+  (options, args) = parser.parse_args()
+
+  # Generate complete intermediate and header file names.
+  input_filename = args[0]
+  output_root = (options.dir + '/' +
+      os.path.splitext(os.path.basename(input_filename))[0])
+  interim_filename = output_root + '.s'
+  out_filename = output_root + '.h'
+
+  # Set the shell command with the compiler and options inputs.
+  compiler_command = (options.compiler + " " + options.options + " " +
+      input_filename + " -o " + interim_filename)
+
+  # Run the shell command and generate the intermediate file.
+  subprocess.check_call(compiler_command, shell=True)
+
+  interim_file = open(interim_filename)  # The intermediate file.
+  out_file = open(out_filename, 'w')  # The output header file.
+
+  # Generate the output header file.
+  while True:
+    line = interim_file.readline()
+    if not line: break
+    if line.startswith(options.pattern):
+      # Find name of the next constant and write to the output file.
+      const_name = re.sub(r'^_', '', line.split(':')[0])
+      out_file.write('#define %s ' % const_name)
+
+      # Find value of the constant we just found and write to the output file.
+      line = interim_file.readline()
+      const_value = filter(str.isdigit, line.split(' ')[0])
+      if const_value != '':
+        out_file.write('%s\n' % const_value)
+
+  interim_file.close()
+  out_file.close()
+
+if __name__ == "__main__":
+  main(sys.argv[1:])
diff --git a/modules/audio_processing/audio_processing.gypi b/modules/audio_processing/audio_processing.gypi
index dd5a586..ed62a8a 100644
--- a/modules/audio_processing/audio_processing.gypi
+++ b/modules/audio_processing/audio_processing.gypi
@@ -12,7 +12,6 @@
       '<(webrtc_root)/common_audio/common_audio.gyp:common_audio',
       '<(webrtc_root)/system_wrappers/source/system_wrappers.gyp:system_wrappers',
     ],
-    'shared_generated_dir': '<(SHARED_INTERMEDIATE_DIR)/audio_processing/asm_offsets',
   },
   'targets': [
     {
@@ -195,15 +194,12 @@
         'conditions': [
           ['OS=="android" or OS=="ios"', {
             'dependencies': [
-              '<(gen_core_neon_offsets_gyp):*',
+              'audio_processing_offsets',
             ],
             'sources': [
               'aecm/aecm_core_neon.S',
               'ns/nsx_core_neon.S',
             ],
-            'include_dirs': [
-              '<(shared_generated_dir)',
-            ],
             'sources!': [
               'aecm/aecm_core_neon.c',
               'ns/nsx_core_neon.c',
@@ -212,6 +208,22 @@
           }],
         ],
       }],
+      'conditions': [
+        ['OS=="android" or OS=="ios"', {
+          'targets': [{
+            'target_name': 'audio_processing_offsets',
+            'type': 'none',
+            'sources': [
+              'aecm/aecm_core_neon_offsets.c',
+              'ns/nsx_core_neon_offsets.c',
+            ],
+            'variables': {
+              'asm_header_dir': 'asm_offsets',
+            },
+            'includes': ['../../build/generate_asm_header.gypi',],
+          }],
+        }],
+      ],
     }],
   ],
 }
diff --git a/modules/audio_processing/gen_core_neon_offsets.gyp b/modules/audio_processing/gen_core_neon_offsets.gyp
deleted file mode 100644
index 55c7968..0000000
--- a/modules/audio_processing/gen_core_neon_offsets.gyp
+++ /dev/null
@@ -1,45 +0,0 @@
-# Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
-#
-# Use of this source code is governed by a BSD-style license
-# that can be found in the LICENSE file in the root of the source
-# tree. An additional intellectual property rights grant can be found
-# in the file PATENTS.  All contributing project authors may
-# be found in the AUTHORS file in the root of the source tree.
-
-{
-  'includes': ['lib_core_neon_offsets.gypi'],
-  'targets' : [
-    {
-      'target_name': 'gen_nsx_core_neon_offsets_h',
-      'type': 'none',
-      'dependencies': [
-        'lib_core_neon_offsets',
-        '<(DEPTH)/third_party/libvpx/libvpx.gyp:libvpx_obj_int_extract#host',
-      ],
-      'sources': ['<(shared_generated_dir)/nsx_core_neon_offsets.o',],
-      'variables' : {
-        'unpack_lib_name':'nsx_core_neon_offsets.o',
-      },
-      'includes': [
-        '../../../third_party/libvpx/unpack_lib_posix.gypi',
-        '../../../third_party/libvpx/obj_int_extract.gypi',
-      ],
-    },
-    {
-      'target_name': 'gen_aecm_core_neon_offsets_h',
-      'type': 'none',
-      'dependencies': [
-        'lib_core_neon_offsets',
-        '<(DEPTH)/third_party/libvpx/libvpx.gyp:libvpx_obj_int_extract#host',
-      ],
-      'variables': {
-        'unpack_lib_name':'aecm_core_neon_offsets.o',
-      },
-      'sources': ['<(shared_generated_dir)/aecm_core_neon_offsets.o',],
-      'includes': [
-        '../../../third_party/libvpx/unpack_lib_posix.gypi',
-        '../../../third_party/libvpx/obj_int_extract.gypi',
-      ],
-    },
-  ],
-}
diff --git a/modules/audio_processing/gen_core_neon_offsets_chromium.gyp b/modules/audio_processing/gen_core_neon_offsets_chromium.gyp
deleted file mode 100644
index d8c1832..0000000
--- a/modules/audio_processing/gen_core_neon_offsets_chromium.gyp
+++ /dev/null
@@ -1,45 +0,0 @@
-# Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
-#
-# Use of this source code is governed by a BSD-style license
-# that can be found in the LICENSE file in the root of the source
-# tree. An additional intellectual property rights grant can be found
-# in the file PATENTS.  All contributing project authors may
-# be found in the AUTHORS file in the root of the source tree.
-
-{
-  'includes': ['lib_core_neon_offsets.gypi'],
-  'targets' : [
-    {
-      'target_name': 'gen_nsx_core_neon_offsets_h',
-      'type': 'none',
-      'dependencies': [
-        'lib_core_neon_offsets',
-        '<(DEPTH)/third_party/libvpx/libvpx.gyp:libvpx_obj_int_extract#host',
-      ],
-      'sources': ['<(INTERMEDIATE_DIR)/nsx_core_neon_offsets.o',],
-      'variables' : {
-        'unpack_lib_name':'nsx_core_neon_offsets.o',
-      },
-      'includes': [
-        '../../../../third_party/libvpx/unpack_lib_posix.gypi',
-        '../../../../third_party/libvpx/obj_int_extract.gypi',
-      ],
-    },
-    {
-      'target_name': 'gen_aecm_core_neon_offsets_h',
-      'type': 'none',
-      'dependencies': [
-        'lib_core_neon_offsets',
-        '<(DEPTH)/third_party/libvpx/libvpx.gyp:libvpx_obj_int_extract#host',
-      ],
-      'variables': {
-        'unpack_lib_name':'aecm_core_neon_offsets.o',
-      },
-      'sources': ['<(INTERMEDIATE_DIR)/aecm_core_neon_offsets.o',],
-      'includes': [
-        '../../../../third_party/libvpx/unpack_lib_posix.gypi',
-        '../../../../third_party/libvpx/obj_int_extract.gypi',
-      ],
-    },
-  ],
-}
diff --git a/modules/audio_processing/lib_core_neon_offsets.gypi b/modules/audio_processing/lib_core_neon_offsets.gypi
deleted file mode 100644
index 42ec9ac..0000000
--- a/modules/audio_processing/lib_core_neon_offsets.gypi
+++ /dev/null
@@ -1,51 +0,0 @@
-# Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
-#
-# Use of this source code is governed by a BSD-style license
-# that can be found in the LICENSE file in the root of the source
-# tree. An additional intellectual property rights grant can be found
-# in the file PATENTS.  All contributing project authors may
-# be found in the AUTHORS file in the root of the source tree.
-
-# This file has common information for gen_core_neon_offsets.gyp
-# and gen_core_neon_offsets_chromium.gyp
-{
-  'variables': {
-    'variables' : {
-      'lib_intermediate_name': '',
-      'conditions' : [
-        ['android_webview_build==1', {
-          'lib_intermediate_name' : '<(android_src)/$(call intermediates-dir-for, STATIC_LIBRARIES, lib_core_neon_offsets)/lib_core_neon_offsets.a',
-        }],
-      ],
-    },
-    'shared_generated_dir': '<(SHARED_INTERMEDIATE_DIR)/audio_processing/asm_offsets',
-    'output_dir': '<(shared_generated_dir)',
-    'output_format': 'cheader',
-    'unpack_lib_search_path_list': [
-      '-a', '<(PRODUCT_DIR)/lib_core_neon_offsets.a',
-      '-a', '<(LIB_DIR)/webrtc/modules/audio_processing/lib_core_neon_offsets.a',
-      '-a', '<(LIB_DIR)/third_party/webrtc/modules/audio_processing/lib_core_neon_offsets.a',
-      '-a', '<(lib_intermediate_name)',
-    ],
-    'unpack_lib_output_dir':'<(shared_generated_dir)',
-  },
-  'includes': [
-    '../../build/common.gypi',
-  ],
-  'conditions': [
-    ['((target_arch=="arm" and arm_version==7) or target_arch=="armv7") and (OS=="android" or OS=="ios")', {
-      'targets' : [
-        {
-          'target_name': 'lib_core_neon_offsets',
-          'type': 'static_library',
-          'android_unmangled_name': 1,
-          'hard_dependency': 1,
-          'sources': [
-            'ns/nsx_core_neon_offsets.c',
-            'aecm/aecm_core_neon_offsets.c',
-          ],
-        },
-      ],
-    }],
-  ],
-}