1 | #!/usr/bin/env python |
---|
2 | # |
---|
3 | # buildconf.py: Runs Autotools on a project. |
---|
4 | # |
---|
5 | # Copyright 2004 Edward Rudd and Paul Querna |
---|
6 | # |
---|
7 | # Licensed under the Apache License, Version 2.0 (the "License"); |
---|
8 | # you may not use this file except in compliance with the License. |
---|
9 | # You may obtain a copy of the License at |
---|
10 | # |
---|
11 | # http://www.apache.org/licenses/LICENSE-2.0 |
---|
12 | # |
---|
13 | # Unless required by applicable law or agreed to in writing, software |
---|
14 | # distributed under the License is distributed on an "AS IS" BASIS, |
---|
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
16 | # See the License for the specific language governing permissions and |
---|
17 | # limitations under the License. |
---|
18 | # |
---|
19 | |
---|
20 | import os |
---|
21 | import sys |
---|
22 | import popen2 |
---|
23 | from optparse import OptionParser |
---|
24 | |
---|
25 | cmd = {} |
---|
26 | |
---|
27 | def run_cmd(command, args=""): |
---|
28 | global cmd |
---|
29 | rp = popen2.Popen4("%s %s" % (cmd[command], args)) |
---|
30 | sout = rp.fromchild.readlines() |
---|
31 | for line in sout: |
---|
32 | sys.stdout.write(line) |
---|
33 | rv = rp.wait() |
---|
34 | if rv != 0: |
---|
35 | print "Error: '%s %s' returned %d" % (cmd[command], args, rv) |
---|
36 | sys.exit(-1) |
---|
37 | |
---|
38 | def select_cmd(command, list, args = "--version"): |
---|
39 | global cmd |
---|
40 | cmd[command] = None |
---|
41 | for x in list: |
---|
42 | # rv = os.spawnlp(os.P_WAIT, x, args) |
---|
43 | rp = popen2.Popen4("%s %s" % (x, args)) |
---|
44 | rv = rp.wait() |
---|
45 | if rv == 0: |
---|
46 | cmd[command] = x |
---|
47 | break |
---|
48 | if cmd[command] == None: |
---|
49 | print "Errpr: Could not find suitable version for '%s', tried running: %s" % (command, list) |
---|
50 | sys.exit(-1) |
---|
51 | |
---|
52 | parser = OptionParser() |
---|
53 | |
---|
54 | parser.add_option("--libtoolize", action="store_true", dest="libtoolize", default=False) |
---|
55 | parser.add_option("--aclocal", action="store_true", dest="aclocal", default=False) |
---|
56 | parser.add_option("--automake", action="store_true", dest="automake", default=False) |
---|
57 | parser.add_option("--autoconf", action="store_true", dest="autoconf", default=False) |
---|
58 | parser.add_option("--autoheader", action="store_true", dest="autoheader", default=False) |
---|
59 | |
---|
60 | (options, args) = parser.parse_args() |
---|
61 | |
---|
62 | if options.libtoolize: |
---|
63 | select_cmd("libtoolize", ['libtoolize14','glibtoolize','libtoolize']) |
---|
64 | if options.aclocal: |
---|
65 | select_cmd("aclocal", ['aclocal-1.9','aclocal-1.8','aclocal-1.7','aclocal-1.6','aclocal']) |
---|
66 | if options.autoheader: |
---|
67 | select_cmd("autoheader", ['autoheader259','autoheader257','autoheader']) |
---|
68 | if options.automake: |
---|
69 | select_cmd("automake", ['automake-1.9','automake-1.8','automake-1.7','automake-1.6','automake']) |
---|
70 | if options.autoconf: |
---|
71 | select_cmd("autoconf", ['autoconf259','autoconf257','autoconf']) |
---|
72 | |
---|
73 | if options.libtoolize: |
---|
74 | run_cmd("libtoolize", "--force --copy") |
---|
75 | if options.aclocal: |
---|
76 | run_cmd("aclocal", "-I m4") |
---|
77 | if options.autoheader: |
---|
78 | run_cmd("autoheader") |
---|
79 | if options.automake: |
---|
80 | run_cmd("automake", "--add-missing --copy --foreign") |
---|
81 | if options.autoconf: |
---|
82 | run_cmd("autoconf") |
---|
83 | |
---|