Define macro when invoking setup.py

J

Jason

I'd like to be able switch between building my C extension with a
certain preprocessor macro defined or not defined. I'm using the
rudimentary distutils setup.py example given here:

http://docs.python.org/extending/building.html

Is there a command line option that distutils.core.setup() will
interpret for me, like the "-D" option for gcc? Or do I need to do
something more complicated? (I had a brief look at the
distutils.command.build_* docs... but they're pretty sparse.)
 
J

Jason

You were looking at the wrong manual. Readhttp://docs.python.org/distutils/setupscript.html#preprocessor-options

Extension(...,
          define_macros=[('NDEBUG', '1'),
                         ('HAVE_STRFTIME', None)],
          undef_macros=['HAVE_FOO', 'HAVE_BAR'])

Note that define_macros requires a list of tuples each having two members..

But can they be selected or set from the command line, so I can do,
say, "setup.py build -DDEBUG=1"?

— Jason
 
J

Jason

But can they be selected or set from the command line, so I can do,
say, "setup.py build -DDEBUG=1"?

Just answered my own question: there's an option for "build_ext" (NOT
"build") that allows this.

Thanks,
Jason
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top