Ongoing work (moving to another machine)
[xiph/unicode.git] / ao-python / config_unix.py
blob7dd07046cae85ebc33125744ee830b37ff7e3c61
1 #!/usr/bin/env python
3 import string
4 import os
5 import sys
7 log_name = 'config.log'
8 if os.path.isfile(log_name):
9 os.unlink(log_name)
11 def write_log(msg):
12 log_file = open(log_name, 'a')
13 log_file.write(msg)
14 log_file.write('\n')
15 log_file.close()
17 def exit(code=0):
18 sys.exit(code)
20 def msg_checking(msg):
21 print "Checking", msg, "...",
23 def execute(cmd):
24 write_log("Execute: %s" % cmd)
25 full_cmd = '%s 1>>%s 2>&1' % (cmd, log_name)
26 return os.system(full_cmd)
28 def run_test(input, flags = ''):
29 try:
30 f = open('_temp.c', 'w')
31 f.write(input)
32 f.close()
33 compile_cmd = '%s -o _temp _temp.c %s' % (os.environ.get('CC', 'cc'),
34 flags)
35 write_log("executing test: %s" % compile_cmd)
36 if not execute(compile_cmd):
37 execute('./_temp')
38 finally:
39 execute('rm -f _temp.c _temp')
41 ao_test_program = '''
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <string.h>
45 #include <ao/ao.h>
47 int main ()
49 system("touch conf.aotest");
50 return 0;
52 '''
54 def find_ao(ao_prefix = '/usr/local', enable_aotest = 1):
55 """A rough translation of ao.m4"""
57 ao_cflags = []
58 ao_libs = []
60 ao_include_dir = ao_prefix + '/include'
61 ao_lib_dir = ao_prefix + '/lib'
62 ao_libs = 'ao'
64 msg_checking('for Ao')
66 if enable_aotest:
67 execute('rm -f conf.aotest')
69 try:
70 run_test(ao_test_program, "-I" + ao_include_dir)
71 if not os.path.isfile('conf.aotest'):
72 raise RuntimeError, "Did not produce output"
73 execute('rm conf.aotest')
75 except Exception, e:
76 print "test program failed"
77 return None
79 print "success"
81 return {'ao_libs' : ao_libs,
82 'ao_lib_dir' : ao_lib_dir,
83 'ao_include_dir' : ao_include_dir}
85 def write_data(data):
86 f = open('Setup', 'w')
87 for item in data.items():
88 f.write('%s = %s\n' % item)
89 f.close()
90 print "Wrote Setup file"
92 def print_help():
93 print '''%s
94 --prefix Give the prefix in which ao was installed
95 (separated by a space)''' % sys.argv[0]
96 exit()
98 def parse_args():
99 def arg_check(data, argv, pos, arg_type, key):
100 "Register an command line arg which takes an argument"
101 if len(argv) == pos:
102 print arg_type, "needs an argument"
103 exit(1)
104 data[key] = argv[pos]
106 data = {}
107 argv = sys.argv
108 for pos in range(len(argv)):
109 if argv[pos] == '--help':
110 print_help()
111 if argv[pos] == '--prefix':
112 pos = pos + 1
113 arg_check(data, argv, pos, "Ao Prefix", 'prefix')
114 return data
116 def main():
117 args = parse_args()
118 prefix = args.get('prefix', '/usr/local')
120 data = find_ao(ao_prefix = prefix)
121 if not data:
122 print "Config failure"
123 exit(1)
124 write_data(data)
126 if __name__ == '__main__':
127 main()