"""
TMPL_AUTOCONF_AC_CONFIG_FILES = "\t\t hardware/${short}/Makefile\n"
TMPL_AUTOCONF_SUMMARY = 'echo " - ${summary}"\n'
-TMPL_HWMAKE_SUBDIR = '\t${short}'
+
TMPL_HWMAKE_DRIVERLIB = """if HW_${upper}
-libsigrokhardware_la_LIBADD += ${short}/libsigrok_hw_${lib}.la
+libsigrok_la_SOURCES += \
+ hardware/${short}/protocol.h \
+ hardware/${short}/protocol.c \
+ hardware/${short}/api.c
endif
"""
&${lib}_driver_info,
#endif
"""
-FILE_DRV_MAKEFILE = 'drv-Makefile.am'
FILE_DRV_API = 'drv-api.c'
FILE_DRV_PROTOCOL = 'drv-protocol.c'
FILE_DRV_PROTOCOL_H = 'drv-protocol.h'
raise Exception('AC_ARG_ENABLE markers not found in configure.ac')
configure_ac = out
- # add driver Makefile to AC_CONFIG_FILES
- out = ''
- state = 'copy'
- for line in configure_ac.split('\n')[:-1]:
- if state == 'copy':
- if line.find("AC_CONFIG_FILES([Makefile") > -1:
- state = 'acconf'
- elif state == 'acconf':
- m = re.match('\t\t hardware/([^/]+)/Makefile', line)
- if m:
- drv_short = m.group(1)
- if drv_short.lower() > names['short']:
- out += tmpl(TMPL_AUTOCONF_AC_CONFIG_FILES)
- state = 'done'
- else:
- # new one at the end
- out += tmpl(TMPL_AUTOCONF_AC_CONFIG_FILES)
- state = 'done'
- out += line + '\n'
- if state != 'done':
- raise Exception('AC_CONFIG_FILES marker not found in configure.ac')
- configure_ac = out
-
# add summary line
out = ''
state = 'copy'
def do_hwmake(gitdir):
- path = gitdir + 'hardware/Makefile.am'
+ path = gitdir + 'Makefile.am'
hwmake = open(path).read()
- # add SUBDIRS entry
+ # add entry at correct place in Makefile
out = ''
state = 'copy'
for line in hwmake.split('\n')[:-1]:
if state == 'copy':
- if line.find('SUBDIRS =') > -1:
- state = 'subdirs'
- elif state == 'subdirs':
- m = re.match('\t([^ \\\]+\s*\\\)', line)
- if m:
- drv_short = m.group(1)
- if drv_short.lower() > names['short']:
- out += tmpl(TMPL_HWMAKE_SUBDIR) + ' \\\n'
- state = 'driverlib'
- else:
- out += tmpl(TMPL_HWMAKE_SUBDIR) + ' \\\n'
+ if line.find('# Hardware drivers') > -1:
state = 'driverlib'
elif state == 'driverlib':
m = re.match('if [A-Z]{2}_(.*)$', line)
out += tmpl(TMPL_HWMAKE_DRIVERLIB)
state = 'done'
out += line + '\n'
- if state == 'driverlib':
- # reached end of file, add it in here
- out += tmpl(TMPL_HWMAKE_DRIVERLIB).strip()
- elif state != 'done':
- raise Exception('markers not found in hardware/Makefile.am')
+ if state != 'done':
+ raise Exception('markers not found in Makefile.am')
hwmake = out
open(path, 'w').write(hwmake)
def do_driverskel(gitdir):
drvdir = gitdir + 'hardware/' + names['short']
os.mkdir(drvdir)
- open(drvdir + '/Makefile.am', 'w').write(tmpl_file(FILE_DRV_MAKEFILE))
open(drvdir + '/api.c', 'w').write(tmpl_file(FILE_DRV_API))
open(drvdir + '/protocol.c', 'w').write(tmpl_file(FILE_DRV_PROTOCOL))
open(drvdir + '/protocol.h', 'w').write(tmpl_file(FILE_DRV_PROTOCOL_H))
os.chdir(gitdir)
command('git add hardware/' + names['short'])
cmd = 'git commit -m "%s: Initial driver skeleton." ' % names['short']
- cmd += 'configure.ac hwdriver.c hardware/Makefile.am hardware/' + names['short']
+ cmd += 'configure.ac Makefile.am hwdriver.c hardware/' + names['short']
command(cmd)
cmd = "git format-patch HEAD~1"
out, err = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE).communicate()