- state = 'copy'
- names['summary'] = "%s%s $HW_%s" % (names['name'],
- '.' * (32 - len(names['name'])), names['upper'])
- for line in configure_ac.split('\n')[:-1]:
- if state == 'copy':
- if line.find('Enabled hardware drivers') > -1:
- state = 'echo'
- elif state == 'echo':
- m = re.match('echo " - ([^\.]+)', line)
- if m:
- drv_short = m.group(1)
- if drv_short.lower() > names['name'].lower():
- out += tmpl(TMPL_AUTOCONF_SUMMARY)
- state = 'done'
- else:
- # new one at the end
- out += tmpl(TMPL_AUTOCONF_SUMMARY)
- state = 'done'
+ iflevel = 0
+ state = 'extern'
+ first_entry = ''
+ for line in source.split('\n')[:-1]:
+ m = re.match(r'\s*#\s*if(?:def)?\s+HAVE_HW_(\w+)', line)
+ if m:
+ if iflevel == 0:
+ if not first_entry:
+ first_entry = m.group(1)
+ elif m.group(1) == first_entry:
+ # second time we see this, so we're past the externs
+ if state != 'idle':
+ # tack driver on to the end of the list
+ out += tmpl(TMPL_DRIVERS_EXTERN)
+ state = 'pointer'
+ if state == 'extern':
+ if m.group(1) > names['upper']:
+ out += tmpl(TMPL_DRIVERS_EXTERN)
+ state = 'idle'
+ elif state == 'pointer':
+ if m.group(1) > names['upper']:
+ out += tmpl(TMPL_DRIVERS_POINTER)
+ state = 'done'
+ iflevel += 1
+ elif re.match(r'\s*#\s*endif\b', line):
+ iflevel -= 1
+ elif iflevel == 0 and state == 'pointer':
+ # we passed the last entry
+ out += tmpl(TMPL_DRIVERS_POINTER)
+ state = 'done'