-
Notifications
You must be signed in to change notification settings - Fork 12
/
build.py
executable file
·68 lines (56 loc) · 2.48 KB
/
build.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
import argparse
import subprocess
import os
parser = argparse.ArgumentParser(description='Package binary builder')
parser.add_argument('-p', '--package', required=True, choices=['binutils',
'coreutils', 'findutils'], dest = 'package', help='the package to be built')
parser.add_argument('-v', '--version', dest='version', default='', help='package version')
parser.add_argument('-o', '--out-dir', dest='out_dir', help='output binary directory')
parser.add_argument('-O', '--optimization', type=int,
dest='optimization', help='compiler optimization')
info = {}
info['binutils'] = ['binutils-%s.tar.gz', '2.24',
'http://ftp.gnu.org/gnu/binutils/binutils-%s.tar.gz',
'-xzf', '-Wno-error=deprecated-declarations']
info['coreutils'] = ['coreutils-%s.tar.xz', '8.23',
'http://ftp.gnu.org/gnu/coreutils/coreutils-%s.tar.xz',
'-xf', '']
info['findutils'] = ['findutils-%s.tar.gz', '4.4.2',
'http://ftp.gnu.org/pub/gnu/findutils/findutils-%s.tar.gz',
'-xzf', '']
def build(package, version, optimization=0, out_dir=os.path.join(os.getcwd(),
'bin')):
if version == '':
name, version, url, untar_arg, extra = info[package]
else:
name, _, url, untar_arg, extra = info[package]
url = url % version
name = name % version
untar_dir = "%s-%s" % (package, version)
flag = '\"-gdwarf-4 -O%d -m64 %s\"' % (optimization, extra)
prefix = '/tmp/%s' % untar_dir
print "Downloading package from %s..." % url
subprocess.call(['wget', url])
print "Uncompress package %s..." % name
subprocess.call(['tar', untar_arg, name])
os.chdir(untar_dir)
cmd = ['CFLAGS=%s' % flag, 'CXXFLAGS=%s' % flag, './configure',
'--prefix=%s' % prefix]
cmd_str = ' '.join(cmd)
subprocess.call(cmd_str, shell=True)
# For coreutils, one might need to reinstall libselinux by:
# apt-get install libselinux1-dev:i386
subprocess.call(['make'])
subprocess.call(['make', 'install'])
bin_dir = os.path.join(prefix, 'bin')
if os.path.exists(out_dir):
print 'Warning: output directory "%s" exists, append binaries into the directory.' % out_dir
cmd = ['cp', "%s/*" % bin_dir, "%s/." % out_dir]
else:
cmd = ['mv', bin_dir, out_dir]
cmd_str = ' '.join(cmd)
subprocess.call(cmd_str, shell=True)
if __name__ == '__main__':
args = parser.parse_args()
build(args.package, args.version)