Showing the changes to python/lib (2 of 5 files). Show all
Unified · Split
| @@ -1,4 +1,4 @@ | |||
| 1 | import os | 1 | import os, glob |
| 2 | 2 | ||
| 3 | header = """// this file is generated! do not modify | 3 | header = """// this file is generated! do not modify |
| 4 | #include "aubio-types.h" | 4 | #include "aubio-types.h" |
| @@ -66,8 +66,9 @@ def get_cpp_objects(): · 61 unmodified lines | |||
| 66 | 66 | ||
| 67 | return cpp_output, cpp_objects | 67 | return cpp_output, cpp_objects |
| 68 | 68 | ||
| 69 | def generate_external(output_path, usedouble = False): | 69 | def generate_external(output_path, usedouble = False, overwrite = True): |
| 70 | if not os.path.isdir(output_path): os.mkdir(output_path) | 70 | if not os.path.isdir(output_path): os.mkdir(output_path) |
| 71 | elif overwrite == False: return glob.glob(os.path.join(output_path, '*.c')) | ||
| 71 | sources_list = [] | 72 | sources_list = [] |
| 72 | cpp_output, cpp_objects = get_cpp_objects() | 73 | cpp_output, cpp_objects = get_cpp_objects() |
| 73 | lib = {} | 74 | lib = {} |
| @@ -160,10 +161,17 @@ void add_generated_objects ( PyObject *m ) · 86 unmodified lines | |||
| 160 | sources_list.append(output_file) | 161 | sources_list.append(output_file) |
| 161 | 162 | ||
| 162 | objlist = "".join(["extern PyTypeObject Py_%sType;\n" % p for p in lib]) | 163 | objlist = "".join(["extern PyTypeObject Py_%sType;\n" % p for p in lib]) |
| 163 | out = """ | 164 | out = """// generated list of objects created with gen_external.py |
| 164 | // generated list of objects created with gen_external.py | ||
| 165 | #include <Python.h> | ||
| 166 | 165 | ||
| 166 | #include <Python.h> | ||
| 167 | """ | ||
| 168 | if usedouble: | ||
| 169 | out += """ | ||
| 170 | #ifndef HAVE_AUBIO_DOUBLE | ||
| 171 | #define HAVE_AUBIO_DOUBLE 1 | ||
| 172 | #endif | ||
| 173 | """ | ||
| 174 | out += """ | ||
| 167 | {objlist} | 175 | {objlist} |
| 168 | int generated_objects ( void ); | 176 | int generated_objects ( void ); |
| 169 | void add_generated_objects( PyObject *m ); | 177 | void add_generated_objects( PyObject *m ); |
| @@ -0,0 +1,30 @@ | |||
| 1 | import distutils, os, subprocess | ||
| 2 | import setuptools.command.build_py | ||
| 3 | import distutils.command.clean | ||
| 4 | from distutils.dir_util import remove_tree | ||
| 5 | |||
| 6 | class CleanGenerated(distutils.command.clean.clean): | ||
| 7 | def run(self): | ||
| 8 | remove_tree('gen') | ||
| 9 | distutils.command.clean.clean.run(self) | ||
| 10 | |||
| 11 | class GenerateCommand(distutils.cmd.Command): | ||
| 12 | description = 'generate gen/gen-*.c files from ../src/aubio.h' | ||
| 13 | user_options = [ | ||
| 14 | # The format is (long option, short option, description). | ||
| 15 | ('enable-double', None, 'use HAVE_AUBIO_DOUBLE=1 (default: 0)'), | ||
| 16 | ] | ||
| 17 | |||
| 18 | def initialize_options(self): | ||
| 19 | self.enable_double = False | ||
| 20 | |||
| 21 | def finalize_options(self): | ||
| 22 | if self.enable_double: | ||
| 23 | self.announce( | ||
| 24 | 'will generate code for aubio compiled with HAVE_AUBIO_DOUBLE=1', | ||
| 25 | level=distutils.log.INFO) | ||
| 26 | |||
| 27 | def run(self): | ||
| 28 | self.announce( 'Generating code', level=distutils.log.INFO) | ||
| 29 | from .gen_external import generate_external | ||
| 30 | generated_object_files = generate_external('gen', usedouble = self.enable_double) | ||