diff --git a/webrtc/build/generate_asm_header.gypi b/webrtc/build/generate_asm_header.gypi new file mode 100644 index 0000000000..7afba7da78 --- /dev/null +++ b/webrtc/build/generate_asm_header.gypi @@ -0,0 +1,64 @@ +# 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': { + 'gen_header': '<(DEPTH)/webrtc/build/generate_asm_header.py', + 'out_dir': '<(SHARED_INTERMEDIATE_DIR)/<(asm_header_dir)', + 'process_outputs_as_sources': 1, + }, + 'rules': [ + { + 'rule_name': 'generate_asm_header', + 'extension': 'c', + 'inputs': [ + '<(gen_header)', + ], + 'outputs': [ + '<(out_dir)/<(RULE_INPUT_ROOT).h', + ], + 'action': [ + 'python', + '<(gen_header)', + '--compiler=$(CC)', # Specifiy the compiler. + '--options=-I.. -I<@(android_ndk_include) -S', # Compiler options. + '--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/webrtc/build/generate_asm_header.py b/webrtc/build/generate_asm_header.py index 7d275efb81..69862617a2 100644 --- a/webrtc/build/generate_asm_header.py +++ b/webrtc/build/generate_asm_header.py @@ -8,34 +8,53 @@ # in the file PATENTS. All contributing project authors may # be found in the AUTHORS file in the root of the source tree. -"""This script generates a C header file of offsets from an ARM assembler file. +"""This script is a tool to generate special header files from input +C source files. -It parses an ARM assembler generated .S file, finds declarations of variables +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 a header file. +command-line, translates the variable names and values into constant defines +and writes them into header files. """ +import os import sys - -def usage(): - print("Usage: generate_asm_header.py " + - " ") - sys.exit(1) +import subprocess +from optparse import OptionParser def main(argv): - if len(argv) != 3: - usage() + parser = OptionParser() + usage = 'Usage: %prog [options] input_file' + 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() - infile = open(argv[0]) - outfile = open(argv[1], 'w') + # Generate complete intermediate and header file names. + input_file_name = os.path.basename(args[0]) + file_base_name = os.path.splitext(input_file_name)[0] + interim_file = options.dir + "/" + file_base_name + '.s' + out_file = interim_file.replace('.s', '.h') + # Set the shell command with the compiler and options inputs. + compiler_command = (options.compiler + " " + options.options + " " + args[0] + + " -o " + interim_file) + # Run the shell command and generate the intermediate file. + subprocess.check_call(compiler_command, shell=True) + + infile = open(interim_file) # The intermediate file. + outfile = open(out_file, 'w') # The output header file. + + # Generate the output header file. for line in infile: # Iterate though all the lines in the input file. - if line.startswith(argv[2]): + if line.startswith(options.pattern): outfile.write('#define ') outfile.write(line.split(':')[0]) # Write the constant name. outfile.write(' ') - if line.find('.word') >= 0: outfile.write(line.split('.word')[1]) # Write the constant value.