-# add HAVE_HW_ extern and pointers to drivers.c
-def do_drivers(gitdir):
- path = gitdir + 'src/drivers.c'
- source = open(path).read()
- out = ''
- state = 'extern'
- first_entry = ''
- for line in source.split('\n')[:-1]:
- m = re.match('#ifdef HAVE_HW_(.*)', line)
- if m:
- 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'
- elif state == 'pointer' and not re.match('(\s*&|#endif|$)', line):
- # we passed the last entry
- out += tmpl(TMPL_DRIVERS_POINTER)
- state = 'done'
- out += line + '\n'
- if state != 'done':
- raise Exception('No "HAVE_HW_*" markers found in drivers.c' + state)
- open(path, 'w').write(out)
-
-