python/lib/gen_external.py: sort generated files
[aubio.git] / python / lib / gen_external.py
index 8d5be2d..d46c1f5 100644 (file)
@@ -14,7 +14,6 @@ skip_objects = [
   'pvoc',
   'filter',
   'filterbank',
-  #'resampler',
   # AUBIO_UNSTABLE
   'hist',
   'parameter',
@@ -75,10 +74,12 @@ def get_preprocessor():
 
     return cpp_cmd
 
-def get_cpp_objects(header=header):
+def get_cpp_objects(header=header, usedouble=False):
     cpp_cmd = get_preprocessor()
 
     macros = [('AUBIO_UNSTABLE', 1)]
+    if usedouble:
+        macros += [('HAVE_AUBIO_DOUBLE', 1)]
 
     if not os.path.isfile(header):
         raise Exception("could not find include file " + header)
@@ -119,11 +120,8 @@ def get_cpp_objects(header=header):
 
     return cpp_output, cpp_objects
 
-def generate_external(header=header, output_path=output_path, usedouble=False, overwrite=True):
-    if not os.path.isdir(output_path): os.mkdir(output_path)
-    elif not overwrite: return glob.glob(os.path.join(output_path, '*.c'))
-    sources_list = []
-    cpp_output, cpp_objects = get_cpp_objects(header)
+
+def analyze_cpp_output(cpp_objects, cpp_output):
     lib = {}
 
     for o in cpp_objects:
@@ -153,8 +151,9 @@ def generate_external(header=header, output_path=output_path, usedouble=False, o
                 else:
                     #print "no idea what to do about", fn
                     lib[shortname]['other'].append(fn)
+    return lib
 
-    """
+def print_cpp_output_results(lib, cpp_output):
     for fn in cpp_output:
         found = 0
         for o in lib:
@@ -162,7 +161,7 @@ def generate_external(header=header, output_path=output_path, usedouble=False, o
                 if fn in lib[o][family]:
                     found = 1
         if found == 0:
-            print "missing", fn
+            print ("missing", fn)
 
     for o in lib:
         for family in lib[o]:
@@ -171,9 +170,19 @@ def generate_external(header=header, output_path=output_path, usedouble=False, o
             elif len(lib[o][family]) == 1:
                 print ( "{:15s} {:10s} {:s}".format(o, family, lib[o][family][0] ) )
             else:
-                print ( "{:15s} {:10s} {:d}".format(o, family, len(lib[o][family]) ) )
-    """
+                print ( "{:15s} {:10s} {:s}".format(o, family, lib[o][family] ) )
+
 
+def generate_external(header=header, output_path=output_path, usedouble=False, overwrite=True):
+    if not os.path.isdir(output_path): os.mkdir(output_path)
+    elif not overwrite: return sorted(glob.glob(os.path.join(output_path, '*.c')))
+
+    cpp_output, cpp_objects = get_cpp_objects(header, usedouble=usedouble)
+
+    lib = analyze_cpp_output(cpp_objects, cpp_output)
+    # print_cpp_output_results(lib, cpp_output)
+
+    sources_list = []
     try:
         from .gen_code import MappedObject
     except (SystemError, ValueError):
@@ -239,7 +248,7 @@ void add_generated_objects( PyObject *m );
         print ("wrote %s" % output_file )
         # no need to add header to list of sources
 
-    return sources_list
+    return sorted(sources_list)
 
 if __name__ == '__main__':
     if len(sys.argv) > 1: header = sys.argv[1]