1 #!/usr/bin/env python 2 # 3 # Copyright (C) 2011-2012 The Android Open Source Project 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 # 17 18 import datetime 19 20 import re 21 import sys 22 23 def extract_config(f): 24 conf_patt = re.compile('# Configurations') 25 split_patt = re.compile('#={69}') 26 var_patt = re.compile('libbcc_([A-Z_]+)\\s*:=\\s*([01])') 27 28 STATE_PRE_CONFIG = 0 29 STATE_FOUND_CONFIG = 1 30 STATE_IN_CONFIG = 2 31 32 state = STATE_PRE_CONFIG 33 34 for line in f: 35 if state == STATE_PRE_CONFIG: 36 if conf_patt.match(line.strip()): 37 print '#ifndef BCC_CONFIG_FROM_MK_H' 38 print '#define BCC_CONFIG_FROM_MK_H' 39 state = STATE_FOUND_CONFIG 40 41 elif state == STATE_FOUND_CONFIG: 42 if split_patt.match(line.strip()): 43 # Start reading the configuration 44 print '/* BEGIN USER CONFIG */' 45 state = STATE_IN_CONFIG 46 47 elif state == STATE_IN_CONFIG: 48 match = var_patt.match(line.strip()) 49 if match: 50 print '#define', match.group(1), match.group(2) 51 52 elif split_patt.match(line.strip()): 53 # Stop reading the configuration 54 print '/* END USER CONFIG */' 55 print '#endif // BCC_CONFIG_FROM_MK_H' 56 break 57 58 def main(): 59 if len(sys.argv) != 1: 60 print >> sys.stderr, 'USAGE:', sys.argv[0] 61 sys.exit(1) 62 63 extract_config(sys.stdin) 64 65 66 if __name__ == '__main__': 67 main() 68