distutils question

J

Joachim Dahl

I am trying to make a customized install script for an extension module
using the distutils.ccompiler class.

I want to embed an existing makefile for the C libraries into the Python
setup script, but I am not sure what's the right way to do it...

E.g., say I want to compile a project as:

gcc -Ddef1 -c foo.c -o foo_def1.o
gcc -Ddef2 -c foo.c -o foo_def2.o
gcc foo_def1.o foo_def2.o -o myext_module.o

How would I do that using distutils? It doesn't seem to be possible with
the normal core.setup method, and distutils.ccompiler seems to be the
best option, but I couldn't get it working...

Hopefully someone the list can enlighten me.
Thanks!
Joachim
 
J

Jorgen Grahn

I am trying to make a customized install script for an extension module
using the distutils.ccompiler class.

I want to embed an existing makefile for the C libraries into the Python
setup script, but I am not sure what's the right way to do it...

E.g., say I want to compile a project as:

gcc -Ddef1 -c foo.c -o foo_def1.o
gcc -Ddef2 -c foo.c -o foo_def2.o
gcc foo_def1.o foo_def2.o -o myext_module.o

How would I do that using distutils? It doesn't seem to be possible with
the normal core.setup method, and distutils.ccompiler seems to be the
best option, but I couldn't get it working...

When I once had to do such an abomination, I started my setup.py with code
which created renamed copies of the master source file (if they didn't
already exist and were newer than the source) and then let normal C
compilation take place,

/Jorgen

[1] For bizarre reasons, I had to import three identical *.pyd modules into
one Python program under different names, so the *pyd files and their
init methods had to have distinct names. Don't ask why.
 
F

Fredrik Lundh

Joachim said:
E.g., say I want to compile a project as:

gcc -Ddef1 -c foo.c -o foo_def1.o
gcc -Ddef2 -c foo.c -o foo_def2.o
gcc foo_def1.o foo_def2.o -o myext_module.o

How would I do that using distutils? It doesn't seem to be possible with
the normal core.setup method, and distutils.ccompiler seems to be the
best option, but I couldn't get it working...

easy: add a new C file (e.g. myext_module.c) that includes "foo.c"
twice (using define/undef/ifdef), and compile the new file instead.

almost as easy: change foo.c so it includes itself.

</F>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top