add option to call autogen.sh
[auto-debuild.git] / auto_debuild.py
index bee82caa859df4fc1759e937bc038a1a4fb8136b..640ac4fd67aaa36b28a9d671c5a0f0be6f20d69b 100755 (executable)
@@ -16,7 +16,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
-import os, shutil, stat, time, subprocess, sys, shlex, tempfile, argparse
+import os, shutil, stat, time, subprocess, sys, shlex, tempfile, argparse, multiprocessing
 from collections import OrderedDict
 
 # a dict with some useful additional getters which can convert types and handle one-element lists like their single member
@@ -105,7 +105,7 @@ class RulesFile:
                print(file=f)
                print(".PHONY: build", file=f) # there may be a directory called "build"
                print(file=f)
-               print("build %:", file=f) # need to mention "build" here again explicitly so PHONY takes effect
+               print("%:", file=f)
                # write proper dh call
                dh = self.dh
                if self.dhWith:
@@ -138,6 +138,7 @@ def automakeRules(r, config):
        #  and HOST_GNU_TYPE are equal, and if they are not, add a --host parameter)
        r.dh += ["--buildsystem=autoconf", "--builddirectory="+config.getstr('buildDir')]
        r.rules['auto_configure'] = [
+        (safeCall(*config['autogen']) + " && " if 'autogen' in config else '') +
                safeCall("mkdir", "-p", buildDir),
                safeCall("cd", buildDir) + " && " +
                'BUILD_TYPE=$$(dpkg-architecture -qDEB_BUILD_GNU_TYPE) && ' + # doing the expansion beforehand ensures that we cancel if it fails
@@ -177,25 +178,23 @@ def commandInBuildEnv(config, command):
 
 def getArchitecture(config):
        cmd = commandInBuildEnv(config, ['dpkg-architecture', '-qDEB_HOST_ARCH'])
-       with subprocess.Popen(cmd, stdout=subprocess.PIPE) as p:
-               res = p.communicate()[0] # get only stdout
-               if p.returncode != 0: raise Exception("Querying dpkg for the architecture failed")
-       return res[0:len(res)-1] # chop of the \n at the end
+       output = subprocess.check_output(cmd)
+       return output.decode('utf-8').strip('\n') # chop off the \n at the end
 
 def writeDependency(f, name, list):
        if len(list):
                print(name+": "+', '.join(list), file=f)
 
+# actual work functions
 def deleteDebianFolder():
        if os.path.islink('debian'):
                target = os.readlink('debian')
                if os.path.exists(target):
                        shutil.rmtree(target)
                os.remove('debian')
-       else:
+       elif os.path.exists('debian'):
                shutil.rmtree('debian')
 
-# actual work functions
 def createDebianFiles(config):
        if not isinstance(config, ConfigDict):
                config = ConfigDict(config)
@@ -209,7 +208,7 @@ def createDebianFiles(config):
        version = config.getstr('version') # version name excluding epoch (used for filenames)
        fullVersion = str(config.getint('epoch'))+':'+version if 'epoch' in config else version # version name including epoch
        dbgPackage = config.getbool('dbgPackage', False)
-       parallelJobs = config.getint('parallelJobs', 2)
+       parallelJobs = config.getint('parallelJobs', multiprocessing.cpu_count()+1)
        packageArchitecture = config.getstr('architecture', 'any')
        withPython2 = config.getbool('withPython2', False)
        withSIP = config.getbool('withSIP', False)