Platform-specific compile flags in setup.py?
Alex Martelli
aleax at mac.com
Sun Mar 4 22:14:24 EST 2007
Nikita the Spider <NikitaTheSpider at gmail.com> wrote:
> Hi all,
> I'm a newbie when it comes to distributing C-based Python modules. I'm
> just now sharing my first with the rest of the world (it's actually V.
> Marangozov's shared memory module for IPC) and I've learned that the
> module needs a different set of compile flags for Linux than for my Mac.
> My question is this: is there a convention or standard that says where
> platform-specific compile flags should reside? I could put them in
> setup.py,
If you need, specifically, *compile-flags*, then setup.py is a good
place for them (also linker-flags &c).
> OTOH I know that within the .C file I can add something like
> this:
> #ifdef __FreeBSD__
> #include <machine/param.h> /* for system definition of PAGE_SIZE */
> #endif
This is NOT a "compile-flag" -- it's a reasonable C technique, though.
> That works, but for maximum Python programmer-friendliness I should
> perhaps put the complexity in setup.py rather than in a .C file.
>
> Opinions appreciated.
My opinion: flags in setup.py, conditional includes (&c) in the .c or .h
file[s].
If you can do something either way: if you know platform X will ALWAYS
want that something, "hard-code" it in the .c or .h; if you want to make
it easier to change for Python programmers, then put it in the setup.py.
Alex
More information about the Python-list
mailing list