e18d9ffa98545ca16fab9ccfece768b931cea020
[mass-build.git] / build_system.py
1 import os, subprocess
2
3 '''A build system has three methods: "configure" (with optionak "force" parameter), "build" and "install"'''
4
5 # Compile, build, and install cmake projects:
6 class CMake:
7         def __init__(self, sourceFolder, buildFolder, config):
8                 self.sourceFolder = os.path.abspath(sourceFolder)
9                 self.buildFolder = os.path.abspath(buildFolder)
10                 self.installDir = config.installDir
11                 self.buildType = config.buildType
12                 self.jobs = config.jobs
13                 self.buildCmdPrefix = config.buildCmdPrefix
14                 self.installCmdPrefix = config.installCmdPrefix
15         
16         def configure(self, force=False):
17                 print "Configuring",self.sourceFolder
18                 if not os.path.exists(self.buildFolder): os.makedirs(self.buildFolder)
19                 os.chdir(self.buildFolder)
20                 # check if we actually need to work
21                 cacheFile = 'CMakeCache.txt'
22                 if os.path.exists(cacheFile) and os.path.exists('Makefile') and not force: return
23                 # yes we do! make sure we start clean, and then go ahead
24                 if os.path.exists(cacheFile): os.remove(cacheFile)
25                 os.putenv('PKG_CONFIG_PATH', os.path.join(self.installDir, 'lib', 'pkgconfig')) # I found no way to do this within cmake
26                 subprocess.check_call(['cmake', self.sourceFolder, '-DCMAKE_BUILD_TYPE='+self.buildType, '-DCMAKE_INSTALL_PREFIX='+self.installDir])
27                 os.unsetenv('PKG_CONFIG_PATH')
28         
29         def build(self):
30                 print "Building",self.sourceFolder
31                 os.chdir(self.buildFolder)
32                 subprocess.check_call(self.buildCmdPrefix + ['make', '-j'+str(self.jobs)])
33         
34         def install(self):
35                 print "Installing",self.sourceFolder
36                 os.chdir(self.buildFolder)
37                 subprocess.check_call(self.installCmdPrefix + ['make', 'install'])
38
39 # TODO: class Debian, which creates & install a debian package