diff --git a/setup.py b/setup.py
index b05a68a2a6d8203fb376780fd8a2e2428047f222..2a745190571df95c5e2d0b89138ebfe3b32c0469 100644
--- a/setup.py
+++ b/setup.py
@@ -111,10 +111,10 @@ src_file_list = ['field',
                  'scope_timer']
 
 header_list = (['cpp/base.hpp'] +
+               ['cpp/fftw_interface.hpp'] +
+               ['cpp/bfps_timer.hpp'] +
                ['cpp/' + fname + '.hpp'
-                for fname in src_file_list] + 
-               ['cpp/fftw_interface.hpp'] + 
-               ['cpp/bfps_timer.hpp'])
+                for fname in src_file_list])
 
 with open('MANIFEST.in', 'w') as manifest_in_file:
     for fname in (['bfps/cpp/' + ff + '.cpp' for ff in src_file_list] +
@@ -191,30 +191,71 @@ def compile_bfps_library(
             protocol = 2)
     return None
 
+import distutils.cmd
 
-from distutils.command.build import build as DistutilsBuild
-from distutils.command.install import install as DistutilsInstall
-
-class CustomBuild(DistutilsBuild):
+class CompileLibCommand(distutils.cmd.Command):
     description = 'Compile bfps library.'
     user_options = [
             ('timing-output=', None, 'Toggle timing output.'),
             ]
     def initialize_options(self):
         self.timing_output = 0
+        return None
     def finalize_options(self):
         self.timing_output = (int(self.timing_output) == 1)
+        return None
     def run(self):
-        compile_bfps_library(
-                use_timingoutput = self.timing_output,
-                extra_compile_args = extra_compile_args)
-        DistutilsBuild.run(self)
+        if not os.path.isdir('obj'):
+            os.makedirs('obj')
+            need_to_compile = True
+        if not os.path.isfile('bfps/libbfps.a'):
+            need_to_compile = True
+        else:
+            ofile = 'bfps/libbfps.a'
+            libtime = datetime.datetime.fromtimestamp(os.path.getctime(ofile))
+            latest = libtime
+            for fname in header_list:
+                latest = max(latest,
+                             datetime.datetime.fromtimestamp(os.path.getctime('bfps/' + fname)))
+            need_to_compile = (latest > libtime)
+        eca = extra_compile_args
+        if self.timing_output:
+            eca += ['-DUSE_TIMINGOUTPUT']
+        for fname in src_file_list:
+            ifile = 'bfps/cpp/' + fname + '.cpp'
+            ofile = 'obj/' + fname + '.o'
+            if not os.path.exists(ofile):
+                need_to_compile_file = True
+            else:
+                need_to_compile_file = (need_to_compile or
+                                        (datetime.datetime.fromtimestamp(os.path.getctime(ofile)) <
+                                         datetime.datetime.fromtimestamp(os.path.getctime(ifile))))
+            if need_to_compile_file:
+                command_strings = [compiler, '-c']
+                command_strings += ['bfps/cpp/' + fname + '.cpp']
+                command_strings += ['-o', 'obj/' + fname + '.o']
+                command_strings += eca
+                command_strings += ['-I' + idir for idir in include_dirs]
+                command_strings.append('-Ibfps/cpp/')
+                print(' '.join(command_strings))
+                subprocess.check_call(command_strings)
+        command_strings = ['ar', 'rvs', 'bfps/libbfps.a']
+        command_strings += ['obj/' + fname + '.o' for fname in src_file_list]
+        print(' '.join(command_strings))
+        subprocess.check_call(command_strings)
 
-# this custom install leads to a broken installation. no idea why...
-class CustomInstall(DistutilsInstall):
-    def run(self):
-        compile_bfps_library()
-        DistutilsInstall.run(self)
+        ### save compiling information
+        pickle.dump(
+                {'include_dirs' : include_dirs,
+                 'library_dirs' : library_dirs,
+                 'compiler'     : compiler,
+                 'extra_compile_args' : eca,
+                 'libraries' : libraries,
+                 'install_date' : now,
+                 'VERSION' : VERSION,
+                 'git_revision' : git_revision},
+                open('bfps/install_info.pickle', 'wb'),
+                protocol = 2)
         return None
 
 from setuptools import setup
@@ -223,7 +264,7 @@ setup(
         name = 'bfps',
         packages = ['bfps'],
         install_requires = ['numpy>=1.8', 'h5py>=2.2.1'],
-        cmdclass={'build' : CustomBuild},
+        cmdclass={'compile_library' : CompileLibCommand},
         package_data = {'bfps': header_list + ['libbfps.a',
                                                'install_info.pickle']},
         entry_points = {