aboutsummaryrefslogtreecommitdiffstats
path: root/m4/buildconf.py
blob: 9ba621f4e0f1bd1a4abb066164f45f975147b1cf (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
#
#  buildconf.py: Runs Autotools on a project.
#
#  Copyright 2004 Edward Rudd and Paul Querna
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#

import os
import sys
import popen2
from optparse import OptionParser

cmd = {}

def run_cmd(command, args=""):
	global cmd
	rp = popen2.Popen4("%s %s" % (cmd[command], args))
	sout = rp.fromchild.readlines()
	for line in sout:
		sys.stdout.write(line)
	rv = rp.wait()
	if rv != 0:
		print "Error: '%s %s' returned %d" % (cmd[command], args, rv)
		sys.exit(-1)

def select_cmd(command, list, args = "--version"):
	global cmd
	cmd[command] = None
	for x in list:
		# rv = os.spawnlp(os.P_WAIT, x, args)
		rp = popen2.Popen4("%s %s" % (x, args))
		rv = rp.wait()
		if rv == 0:
			cmd[command] = x
			break
	if cmd[command] == None:
		print "Errpr: Could not find suitable version for '%s', tried running: %s" % (command, list)
		sys.exit(-1)		

parser = OptionParser()

parser.add_option("--libtoolize", action="store_true", dest="libtoolize", default=False)
parser.add_option("--aclocal", action="store_true", dest="aclocal", default=False)
parser.add_option("--automake", action="store_true", dest="automake", default=False)
parser.add_option("--autoconf", action="store_true", dest="autoconf", default=False)
parser.add_option("--autoheader", action="store_true", dest="autoheader", default=False)

(options, args) = parser.parse_args()

if options.libtoolize:
	select_cmd("libtoolize", ['libtoolize14','glibtoolize','libtoolize']) 
if options.aclocal:
	select_cmd("aclocal", ['aclocal-1.9','aclocal-1.8','aclocal-1.7','aclocal-1.6','aclocal']) 
if options.autoheader:
	select_cmd("autoheader", ['autoheader259','autoheader257','autoheader']) 
if options.automake:
	select_cmd("automake", ['automake-1.9','automake-1.8','automake-1.7','automake-1.6','automake']) 
if options.autoconf:
	select_cmd("autoconf", ['autoconf259','autoconf257','autoconf']) 

if options.libtoolize:
	run_cmd("libtoolize", "--force --copy") 
if options.aclocal:
	run_cmd("aclocal", "-I m4") 
if options.autoheader:
	run_cmd("autoheader") 
if options.automake:
	run_cmd("automake", "--add-missing --copy --foreign") 
if options.autoconf:
	run_cmd("autoconf")