8 log_name
= 'config.log'
9 if os
.path
.isfile(log_name
):
13 log_file
= open(log_name
, 'a')
21 def msg_checking(msg
):
22 print "Checking", msg
, "...",
25 write_log("Execute: %s" % cmd
)
26 full_cmd
= '%s 1>>%s 2>&1' % (cmd
, log_name
)
27 return os
.system(full_cmd
)
29 def run_test(input, flags
= ''):
31 f
= open('_temp.c', 'w')
34 compile_cmd
= '%s -o _temp _temp.c %s' % (os
.environ
.get('CC', 'cc'),
36 write_log("executing test: %s" % compile_cmd
)
37 if not execute(compile_cmd
):
41 execute('rm -f _temp.c _temp')
43 ogg_test_program
= '''
51 system("touch conf.oggtest");
56 def find_ogg(ogg_prefix
= '/usr/local', enable_oggtest
= 1):
57 """A rough translation of ogg.m4"""
59 ogg_include_dir
= ogg_prefix
+ '/include'
60 ogg_lib_dir
= ogg_prefix
+ '/lib'
63 msg_checking('for Ogg')
66 execute('rm -f conf.oggtest')
69 run_test(ogg_test_program
, flags
="-I" + ogg_include_dir
)
70 if not os
.path
.isfile('conf.oggtest'):
71 raise RuntimeError, "Did not produce output"
72 execute('rm conf.oggtest')
75 print "test program failed"
80 return {'ogg_libs' : ogg_libs
,
81 'ogg_lib_dir' : ogg_lib_dir
,
82 'ogg_include_dir' : ogg_include_dir
}
85 vorbis_test_program
= '''
89 #include <vorbis/codec.h>
93 system("touch conf.vorbistest");
98 def find_vorbis(ogg_data
,
99 vorbis_prefix
= '/usr/local',
100 enable_vorbistest
= 1):
101 """A rough translation of vorbis.m4"""
103 ogg_libs
= ogg_data
['ogg_libs']
104 ogg_lib_dir
= ogg_data
['ogg_lib_dir']
105 ogg_include_dir
= ogg_data
['ogg_include_dir']
107 vorbis_include_dir
= vorbis_prefix
+ '/include'
108 vorbis_lib_dir
= vorbis_prefix
+ '/lib'
109 vorbis_libs
= 'vorbis vorbisfile vorbisenc'
111 msg_checking('for Vorbis')
113 if enable_vorbistest
:
114 execute('rm -f conf.vorbistest')
117 run_test(vorbis_test_program
,
118 flags
= "-I%s -I%s" % (vorbis_include_dir
,
120 if not os
.path
.isfile('conf.vorbistest'):
121 raise RuntimeError, "Did not produce output"
122 execute('rm conf.vorbistest')
125 print "test program failed"
130 return {'vorbis_libs' : vorbis_libs
,
131 'vorbis_lib_dir' : vorbis_lib_dir
,
132 'vorbis_include_dir' : vorbis_include_dir
}
134 def write_data(data
):
135 f
= open('Setup', 'w')
136 for item
in data
.items():
137 f
.write('%s = %s\n' % item
)
139 print "Wrote Setup file"
143 --prefix Give the prefix in which vorbis was installed.
144 --with-ogg-dir [dir] Give the directory for ogg files
145 (separated by a space)
146 --with-vorbis-dir [dir] Give the directory for vorbis files''' % sys
.argv
[0]
150 def arg_check(data
, argv
, pos
, arg_type
, key
):
151 "Register an command line arg which takes an argument"
153 print arg_type
, "needs an argument"
155 data
[key
] = argv
[pos
]
159 for pos
in range(len(argv
)):
160 if argv
[pos
] == '--help':
162 if argv
[pos
] == '--with-ogg-dir':
164 arg_check(data
, argv
, pos
, "Ogg dir", 'ogg_prefix')
165 if argv
[pos
] == '--with-vorbis-dir':
167 arg_check(data
, argv
, pos
, "Vorbis dir", 'vorbis_prefix')
168 if argv
[pos
] == '--prefix':
170 arg_check(data
, argv
, pos
, "Prefix", 'prefix')
176 prefix
= args
.get('prefix', '/usr/local')
177 vorbis_prefix
= args
.get('vorbis_prefix', prefix
)
178 ogg_prefix
= args
.get('ogg_prefix', prefix
)
180 data
= find_ogg(ogg_prefix
= ogg_prefix
)
182 print "Config failure"
185 vorbis_data
= find_vorbis(ogg_data
= data
,
186 vorbis_prefix
= vorbis_prefix
)
188 print "Config failure"
190 data
.update(vorbis_data
)
194 if __name__
== '__main__':