Python in Makefile Question

Discussion in 'Python' started by Dan Bishop, Feb 11, 2005.

  1. Dan Bishop

    Dan Bishop Guest

    Efrat Regev wrote:
    > Hello,
    >
    > I'd like to ask a question concerning a python script in a

    makefile.
    > Suppose I have a C++ project (sorry for raising this in a Python

    newsgroup),
    > with some makefile for it. Before compiling the code, I'd like to

    check that
    > there are no C++ convention violations (e.g., identifiers beginning

    with an
    > underscore). So my makefile looks something like this:
    >
    > target: ...
    > verify.py
    > $(CC) ...
    >
    > verify.py is a python script that checks for convention violations,

    i.e.,
    > its first line is
    >
    > #! /usr/bin/env python
    >
    > I can't figure out the following:
    > 1. How can I get the python script to return a value to make, so that

    if it
    > decides that there are convention violations make will fail?


    raise SystemExit(1)

    > 2. How can I pass information from the makefile to the python script,

    e.g.,
    > the base directory to check?


    Use command-line arguments. The Python equivalent of "argv" is
    "sys.argv".
    Dan Bishop, Feb 11, 2005
    #1
    1. Advertising

  2. Efrat Regev wrote:
    > 1. How can I get the python script to return a value to make, so that if it
    > decides that there are convention violations make will fail?


    You can set the return code of your Python script through sys.exit (3)

    > 2. How can I pass information from the makefile to the python script, e.g.,
    > the base directory to check?


    Python side:
    Commandline arguments can be read through the list sys.argv. Parsing of
    commandline options can be done with the module optparse.

    Makefile side:
    I don't know if there is a special variable in GNU make for the
    directory of the current target. Why don't you set the default for the
    directory option to the current directory? Most Makefiles won't work
    anyway if they are called from a different directory.

    Daniel
    Daniel Dittmar, Feb 11, 2005
    #2
    1. Advertising

  3. Dan Bishop

    Efrat Regev Guest

    Hello,

    I'd like to ask a question concerning a python script in a makefile.
    Suppose I have a C++ project (sorry for raising this in a Python newsgroup),
    with some makefile for it. Before compiling the code, I'd like to check that
    there are no C++ convention violations (e.g., identifiers beginning with an
    underscore). So my makefile looks something like this:

    target: ...
    verify.py
    $(CC) ...

    verify.py is a python script that checks for convention violations, i.e.,
    its first line is

    #! /usr/bin/env python

    I can't figure out the following:
    1. How can I get the python script to return a value to make, so that if it
    decides that there are convention violations make will fail?
    2. How can I pass information from the makefile to the python script, e.g.,
    the base directory to check?

    Thanks,

    Efrat
    Efrat Regev, Feb 11, 2005
    #3
  4. Dan Bishop

    Efrat Regev Guest

    "Efrat Regev" <> wrote in message
    news:...
    > Hello,
    >
    > I'd like to ask a question concerning a python script in a makefile.
    > ...



    Many thanks for the very useful (and very quick) answers!

    Efrat
    Efrat Regev, Feb 11, 2005
    #4
  5. Re: Python in Makefile Question. try A.A.P

    Another option would be to move from Makefiles to AAP, the build
    mechanism for vim. We did just that, and are very happy with it. Aap is
    python based, so the kind of question you have is very easily handled
    within the 'aap' file.

    http://www.a-a-p.org/

    Aap has the advantage that you don't need to define the dependencies
    yourself, it understands C files, and does the work for you. Our
    Makefile shrunk by a factor of 5 after converting to aap.

    Highly recommended.

    Bart van Deenen.
    Bart van Deenen, Feb 11, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matthias Pieroth

    Makefile question

    Matthias Pieroth, Mar 4, 2004, in forum: C++
    Replies:
    3
    Views:
    340
    Jorge Rivera
    Mar 5, 2004
  2. Replies:
    0
    Views:
    1,520
  3. Replies:
    0
    Views:
    402
  4. Replies:
    3
    Views:
    923
    Nick Vargish
    Apr 20, 2005
  5. Replies:
    1
    Views:
    710
Loading...

Share This Page