summaryrefslogtreecommitdiffstats
path: root/bin/build
blob: 5f1425dd6f5938179badb803d8694368b309b913 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/python

import os,sys,subprocess
from multiprocessing import cpu_count

if 'INROOT_DIR' not in os.environ:
    print "INROOT_DIR not set; run under inroot"
    sys.exit(1)
root = os.environ['INROOT_DIR']
if os.path.isdir('/lib64'):
    libdir=os.path.join(root, 'lib64')
else:
    libdir=os.path.join(root, 'lib')
configargs=['--prefix=' + root, '--libdir=' + libdir]
configargs.extend(sys.argv[1:])
if not os.path.exists('configure'):
    if os.path.exists('autogen.sh'):
        args = ['autogen.sh']
        args.extend(configargs)
        subprocess.check_call(args, stdout=sys.stdout, stderr=sys.stderr)
    else:
        subprocess.check_call(['autoreconf', '-f', '-i'], stdout=sys.stdout, stderr=sys.stderr)
        args = ['./configure']
        args.extend(configargs)
        subprocess.check_call(args, stdout=sys.stdout, stderr=sys.stderr)
prefix_matches=True
if os.path.exists('config.log'):
    previous_prefix = None
    f = open('config.log')
    for line in f:
        if line.startswith('prefix=\''):
            previous_prefix = line[8:-2]
            break
    f.close()
    if previous_prefix != root:
        print "Reruning configure due to prefix change (%r -> %r)" % (root, previous_prefix)
        prefix_matches=False

if not os.path.exists('Makefile') or not prefix_matches:
    args = ['./configure']
    args.extend(configargs)
    subprocess.check_call(args, stdout=sys.stdout, stderr=sys.stderr)

logfile_path = '/tmp/build-%s.log' % (os.path.basename(os.getcwd()),)
logfile = open(logfile_path, 'w')
subprocess.Popen(['make', '-j', '%d' % (cpu_count() * 2, )],
                 stdout=logfile, stderr=logfile)
os.execlp('tail', 'tail', '--lines=2000', '-f', logfile_path)