]> sigrok.org Git - sigrok-util.git/blobdiff - source/new-driver
new-driver: Update to match recent drivers API changes.
[sigrok-util.git] / source / new-driver
index dea8a1fb26a5ab900326046e02f855f3567207a0..6d77220fc9ad41128525dbd6b21e9ecc117e9630 100755 (executable)
@@ -28,19 +28,13 @@ import socket
 import datetime
 
 TMPL_AUTOCONF_DRIVER = "DRIVER([${name}], [${short}])\n"
-TMPL_AUTOCONF_AM_CONDITIONAL = """\
-AM_CONDITIONAL(HW_${upper}, test x$HW_${upper} = xyes)
-if test "x$HW_${upper}" = "xyes"; then
-       AC_DEFINE(HAVE_HW_${upper}, 1, [${name} support])
-fi
-
-"""
+TMPL_AUTOCONF_DRIVER2 = "DRIVER2([HW_${upper}], [$HW_${upper}], [HAVE_HW_${upper}])\n"
 
 TMPL_HWMAKE_DRIVERLIB = """if HW_${upper}
 libsigrok_la_SOURCES += \\
-       hardware/${short}/protocol.h \\
-       hardware/${short}/protocol.c \\
-       hardware/${short}/api.c
+       src/hardware/${short}/protocol.h \\
+       src/hardware/${short}/protocol.c \\
+       src/hardware/${short}/api.c
 endif
 """
 TMPL_DRIVERS_EXTERN = """\
@@ -50,7 +44,7 @@ extern SR_PRIV struct sr_dev_driver ${lib}_driver_info;
 """
 TMPL_DRIVERS_POINTER = """\
 #ifdef HAVE_HW_${upper}
-       &${lib}_driver_info,
+       (DRVS) {&${lib}_driver_info, NULL},
 #endif
 """
 FILE_DRV_API = 'drv-api.c'
@@ -73,7 +67,7 @@ def new_driver():
     tmp = tempfile.mkdtemp()
     try:
         os.chdir(tmp)
-        process = Popen("git clone " + LIBSR, shell=True, stderr=PIPE)
+        process = Popen("git clone --depth=1 " + LIBSR, shell=True, stderr=PIPE)
         out, err = process.communicate()
         if process.returncode:
             raise Exception(err.decode())
@@ -88,7 +82,7 @@ def new_driver():
     shutil.rmtree(tmp)
 
 
-# add DRIVER and AM_CONDITIONAL/AC_DEFINE entries to configure.ac
+# add DRIVER and DRIVER2 entries to configure.ac
 def do_autoconf(gitdir):
     cacpath = gitdir + 'configure.ac'
     configure_ac = open(cacpath).read()
@@ -107,18 +101,18 @@ def do_autoconf(gitdir):
                     state = 'automake'
                     active = False
         elif state == 'automake':
-            m = re.match('AM_CONDITIONAL\(HW_([^,]+)', line)
+            m = re.match('DRIVER2\(\[([^\]]+)', line)
             if m:
                 active = True
             else:
-                submatch = re.match('(if|\s*AC_DEFINE|fi|$)', line)
+                submatch = re.match('DRIVER2\(\[([^\]]+)', line)
                 if active and submatch is None:
-                    # we're past the conditionals
-                    out += tmpl(TMPL_AUTOCONF_AM_CONDITIONAL)
+                    # we're past the DRIVER2 list
+                    out += tmpl(TMPL_AUTOCONF_DRIVER2)
                     state = 'done'
             if active:
-                if (m and m.group(1) > names['upper']):
-                    out += tmpl(TMPL_AUTOCONF_AM_CONDITIONAL)
+                if (m and m.group(1) > 'HW_' + names['upper']):
+                    out += tmpl(TMPL_AUTOCONF_DRIVER2)
                     state = 'done'
         out += line + '\n'
     if state != 'done':
@@ -128,7 +122,7 @@ def do_autoconf(gitdir):
 
 # add HAVE_HW_ extern and pointers to drivers.c
 def do_drivers(gitdir):
-    path = gitdir + 'drivers.c'
+    path = gitdir + 'src/drivers.c'
     source = open(path).read()
     out = ''
     state = 'extern'
@@ -179,7 +173,7 @@ def do_automake(gitdir):
                 if drv_short > names['upper']:
                     out += tmpl(TMPL_HWMAKE_DRIVERLIB)
                     state = 'done'
-            elif not re.match('(libsigrok_la_SOURCES|\s*hardware/|endif)', line):
+            elif not re.match('(libsigrok_la_SOURCES|\s*src/hardware/|endif)', line):
                 print("[%s]" % line.strip())
                 # we passed the last entry
                 out += tmpl(TMPL_HWMAKE_DRIVERLIB)
@@ -191,7 +185,7 @@ def do_automake(gitdir):
 
 
 def do_driverskel(gitdir):
-    drvdir = gitdir + 'hardware/' + names['short']
+    drvdir = gitdir + 'src/hardware/' + names['short']
     os.mkdir(drvdir)
     open(drvdir + '/api.c', 'w').write(tmpl_file(FILE_DRV_API))
     open(drvdir + '/protocol.c', 'w').write(tmpl_file(FILE_DRV_PROTOCOL))
@@ -200,9 +194,9 @@ def do_driverskel(gitdir):
 
 def make_patch(gitdir):
     os.chdir(gitdir)
-    command('git add hardware/' + names['short'])
+    command('git add src/hardware/' + names['short'])
     cmd = 'git commit -m "%s: Initial driver skeleton." ' % names['short']
-    cmd += 'configure.ac Makefile.am drivers.c hardware/' + names['short']
+    cmd += 'configure.ac Makefile.am src/drivers.c src/hardware/' + names['short']
     command(cmd)
     cmd = "git format-patch HEAD~1"
     out, err = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE).communicate()
@@ -250,7 +244,6 @@ if scriptdir.split('/')[-2:] != ['sigrok-util', 'source']:
        sys.exit(1)
 
 LIBSR = 'git://sigrok.org/libsigrok'
-LIBSR = 'file:///home/bert/sigrok/libsigrok'
 TMPLDIR = scriptdir
 
 if len(sys.argv) < 2: