[Distutils] Example of "config" command
Greg Ward
gward@python.net
Tue, 20 Jun 2000 22:47:29 -0400
Oh, here's an example of how easy it is to autoconfigure Python
extensions now. This is taken from examples/mxdatetime_setup.py;
here're the essentials 'run()' method of the "config_mxDateTime" command
class:
def run (self):
have = {}
have['strftime'] = self.check_func('strftime', ['time.h'])
have['strptime'] = self.check_func('strptime', ['time.h'])
have['timegm'] = self.check_func('timegm', ['time.h'])
define = []
undef = []
for name in have.keys(): # ('strftime', 'strptime', 'timegm'):
macro_name = 'HAVE_' + string.upper(name)
if have[name]:
define.append((macro_name, None))
else:
undef.append(macro_name)
Note that the bulk of the code is the bureaucracy of figuring out which
macros to define, ie. generateing HAVE_STRFTIME and friends. Obviously
this could (and should) be taken care of by the standard "config"
command; we'll get there!
Here's the output of "setup.py config" (very noisy because --noisy and
--dump-source are both enabled by default for now):
running config
compiling '_configtest.c':
#include <time.h>
int main () {
strftime;
}
gcc -c -g -O2 -fPIC _configtest.c -o _configtest.o
gcc _configtest.o -o _configtest
success!
removing: _configtest.c _configtest.o _configtest
compiling '_configtest.c':
#include <time.h>
int main () {
strptime;
}
gcc -c -g -O2 -fPIC _configtest.c -o _configtest.o
_configtest.c: In function `main':
_configtest.c:4: `strptime' undeclared (first use in this function)
_configtest.c:4: (Each undeclared identifier is reported only once
_configtest.c:4: for each function it appears in.)
failure.
removing: _configtest.c _configtest.o
compiling '_configtest.c':
#include <time.h>
int main () {
timegm;
}
gcc -c -g -O2 -fPIC _configtest.c -o _configtest.o
gcc _configtest.o -o _configtest
success!
removing: _configtest.c _configtest.o _configtest
macros to define: [('HAVE_STRFTIME', None), ('HAVE_TIMEGM', None)]
macros to undefine: ['HAVE_STRPTIME']
Note that ('HAVE_STRFTIME', None) means "-DHAVE_STRFTIME" -- i.e. define
the macro without any particular value. No, I don't know why
'strptime()' isn't showing up, but at least it demonstrates a failure
case.
Greg
--
Greg Ward - geek-on-the-loose gward@python.net
http://starship.python.net/~gward/
Save energy: be apathetic.