Index: Makefile
===================================================================
--- Makefile	(revision 45521d2a2d96b210bd7ccd6e855c8093bcfde60e)
+++ Makefile	(revision 8d09036dba68f1b646c23d7167f967761c5fbaed)
@@ -29,5 +29,5 @@
 
 build_python:
-	python ./setup.py generate $(ENABLE_DOUBLE) build
+	python ./setup.py build_ext $(ENABLE_DOUBLE)
 
 test_python: export LD_LIBRARY_PATH=$(PWD)/build/src
@@ -73,5 +73,5 @@
 
 build_python3:
-	python3 ./setup.py generate $(ENABLE_DOUBLE) build
+	python3 ./setup.py build_ext $(ENABLE_DOUBLE)
 
 clean_python3:
Index: python/lib/moresetuptools.py
===================================================================
--- python/lib/moresetuptools.py	(revision 45521d2a2d96b210bd7ccd6e855c8093bcfde60e)
+++ python/lib/moresetuptools.py	(revision 8d09036dba68f1b646c23d7167f967761c5fbaed)
@@ -128,7 +128,8 @@
         distutils.command.clean.clean.run(self)
 
-class GenerateCommand(distutils.cmd.Command):
-    description = 'generate gen/gen-*.c files from ../src/aubio.h'
-    user_options = [
+from distutils.command.build_ext import build_ext as _build_ext
+class build_ext(_build_ext):
+
+    user_options = _build_ext.user_options + [
             # The format is (long option, short option, description).
             ('enable-double', None, 'use HAVE_AUBIO_DOUBLE=1 (default: 0)'),
@@ -136,7 +137,9 @@
 
     def initialize_options(self):
+        _build_ext.initialize_options(self)
         self.enable_double = False
 
     def finalize_options(self):
+        _build_ext.finalize_options(self)
         if self.enable_double:
             self.announce(
@@ -144,5 +147,22 @@
                     level=distutils.log.INFO)
 
-    def run(self):
-        self.announce( 'Generating code', level=distutils.log.INFO)
-        generated_object_files = generate_external(header, output_path, usedouble=self.enable_double)
+    def build_extension(self, extension):
+        if self.enable_double:
+            extension.define_macros += [('HAVE_AUBIO_DOUBLE', 1)]
+        if os.path.isfile('src/aubio.h'):
+            # if aubio headers are found in this directory
+            add_local_aubio_header(extension)
+            # was waf used to build the shared lib?
+            if os.path.isdir(os.path.join('build','src')):
+                # link against build/src/libaubio, built with waf
+                add_local_aubio_lib(extension)
+            else:
+                # add libaubio sources and look for optional deps with pkg-config
+                add_local_aubio_sources(extension, usedouble=self.enable_double)
+        else:
+            # look for aubio headers and lib using pkg-config
+            add_system_aubio(extension)
+        # generate files python/gen/*.c, python/gen/aubio-generated.h
+        extension.sources += generate_external(header, output_path, overwrite = False,
+                usedouble=self.enable_double)
+        return _build_ext.build_extension(self, extension)
Index: setup.py
===================================================================
--- setup.py	(revision 45521d2a2d96b210bd7ccd6e855c8093bcfde60e)
+++ setup.py	(revision 8d09036dba68f1b646c23d7167f967761c5fbaed)
@@ -48,18 +48,6 @@
 
 if os.path.isfile('src/aubio.h'):
-    # if aubio headers are found in this directory
-    add_local_aubio_header(aubio_extension)
-    # was waf used to build the shared lib?
-    if os.path.isdir(os.path.join('build','src')):
-        # link against build/src/libaubio, built with waf
-        add_local_aubio_lib(aubio_extension)
-    else:
-        # add libaubio sources and look for optional deps with pkg-config
-        add_local_aubio_sources(aubio_extension)
-        __version__ += 'a2' # pypi version
-else:
-    # look for aubio headers and lib using pkg-config
-    add_system_aubio(aubio_extension)
-
+    if not os.path.isdir(os.path.join('build','src')):
+        __version__ += 'a2' # python only version
 
 classifiers = [
@@ -77,12 +65,4 @@
     'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
     ]
-
-from distutils.command.build_ext import build_ext as _build_ext
-class build_ext(_build_ext):
-
-    def build_extension(self, extension):
-        # generate files python/gen/*.c, python/gen/aubio-generated.h
-        extension.sources += generate_external(header, output_path, overwrite = False)
-        return _build_ext.build_extension(self, extension)
 
 distrib = setup(name='aubio',
@@ -105,5 +85,4 @@
     cmdclass = {
         'clean': CleanGenerated,
-        'generate': GenerateCommand,
         'build_ext': build_ext,
         },
