Updated project files to VS2008 SP1. Removed deprecated features (and warning message...
[xiph/unicode.git] / ogg-python / config_unix.py
blobebe36957af7f747b04015f6e31dd950b56fded7f
1 #!/usr/bin/env python
3 import string
4 import os
5 import sys
7 def msg_checking(msg):
8 print "Checking", msg, "...",
10 def execute(cmd, display = 0):
11 if display:
12 print cmd
13 return os.system(cmd)
15 def run_test(input, flags = ''):
16 try:
17 f = open('_temp.c', 'w')
18 f.write(input)
19 f.close()
20 compile_cmd = '%s -o _temp _temp.c %s' % (os.environ.get('CC', 'cc'),
21 flags)
22 if not execute(compile_cmd):
23 execute('./_temp')
24 finally:
25 execute('rm -f _temp.c _temp')
27 ogg_test_program = '''
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <ogg/ogg.h>
33 int main ()
35 system("touch conf.oggtest");
36 return 0;
38 '''
40 def find_ogg(ogg_prefix = '/usr/local', enable_oggtest = 1):
41 """A rough translation of ogg.m4"""
43 ogg_cflags = []
44 ogg_libs = []
46 ogg_include_dir = ogg_prefix + '/include'
47 ogg_lib_dir = ogg_prefix + '/lib'
48 ogg_libs = 'ogg'
50 msg_checking('for Ogg')
52 if enable_oggtest:
53 execute('rm -f conf.oggtest', 0)
55 try:
56 run_test(ogg_test_program, flags="-I" + ogg_include_dir)
57 if not os.path.isfile('conf.oggtest'):
58 raise RuntimeError, "Did not produce output"
59 execute('rm conf.oggtest', 0)
61 except:
62 print "test program failed"
63 return None
65 print "success"
67 return {'ogg_libs' : ogg_libs,
68 'ogg_lib_dir' : ogg_lib_dir,
69 'ogg_include_dir' : ogg_include_dir}
71 def write_data(data):
72 f = open('Setup', 'w')
73 for item in data.items():
74 f.write('%s = %s\n' % item)
75 f.close()
76 print "Wrote Setup file"
78 def print_help():
79 print '''%s
80 --prefix Give the prefix in which ogg was installed.''' % sys.argv[0]
81 sys.exit(0)
83 def parse_args():
84 data = {}
85 argv = sys.argv
86 for pos in range(len(argv)):
87 if argv[pos] == '--help':
88 print_help()
89 if argv[pos] == '--prefix':
90 pos = pos + 1
91 if len(argv) == pos:
92 print "Prefix needs an argument"
93 sys.exit(1)
94 data['prefix'] = argv[pos]
96 return data
98 def main():
99 args = parse_args()
100 prefix = args.get('prefix', '/usr/local')
102 data = find_ogg(ogg_prefix = prefix)
103 if not data:
104 print "Config failure"
105 sys.exit(1)
106 write_data(data)
108 if __name__ == '__main__':
109 main()