Makefile

Discussion in 'C++' started by newbiecpp, Aug 29, 2004.

  1. newbiecpp

    newbiecpp Guest

    I am very sorry to post this one because I know it is out of topic but I
    cannot find the proper news group. I understand that most senior C++
    programmers know makefile very well. My question is GNU makefile support
    command line argument?

    I want to write a makefile so that when you invoke "make test", the makefile
    will compile test like this:

    $project = "command line argument, i.e., test";

    $project : ($project).cpp
    g++ -ggdb -o $project ($project).cpp

    I cannot figure it out how I can get $project=test, the test is from command
    line argument. I appreciate any help or direct me to the right new groups.

    Thanks in advance!
     
    newbiecpp, Aug 29, 2004
    #1
    1. Advertising

  2. newbiecpp

    Alwyn Guest

    In article <yDlYc.3487$hq5.2435@trndny09>, newbiecpp
    <> wrote:

    > I am very sorry to post this one because I know it is out of topic but I
    > cannot find the proper news group. I understand that most senior C++
    > programmers know makefile very well. My question is GNU makefile support
    > command line argument?
    >
    > I want to write a makefile so that when you invoke "make test", the makefile
    > will compile test like this:
    >
    > $project = "command line argument, i.e., test";
    >
    > $project : ($project).cpp
    > g++ -ggdb -o $project ($project).cpp
    >
    > I cannot figure it out how I can get $project=test, the test is from command
    > line argument. I appreciate any help or direct me to the right new groups.


    If your project is so simple, with just one source file to make the
    executable. you don't even need a make file for that. You just type
    'make test', and it will instruct the compiler to build executable
    'test' from 'test.cc'.

    For example:

    ~/Scrap $ ls
    newton.caml test.cc
    ~/Scrap $ cat test.cc
    int main()
    {
    }
    ~/Scrap $ make test
    g++ test.cc -o test
    ~/Scrap $ ls
    newton.caml test test.cc
    ~/Scrap $ rm test
    ~/Scrap $ make test CXXFLAGS=-g
    g++ -g test.cc -o test
    ~/Scrap $

    HTH

    Alwyn
     
    Alwyn, Aug 29, 2004
    #2
    1. Advertising

  3. newbiecpp

    Rolf Magnus Guest

    newbiecpp wrote:

    > I am very sorry to post this one because I know it is out of topic but
    > I cannot find the proper news group.


    What about gnu.utils.help?

    > I understand that most senior C++ programmers know makefile very well.
    > My question is GNU makefile support command line argument?
    >
    > I want to write a makefile so that when you invoke "make test", the
    > makefile will compile test like this:
    >
    > $project = "command line argument, i.e., test";
    >
    > $project : ($project).cpp
    > g++ -ggdb -o $project ($project).cpp
    >
    > I cannot figure it out how I can get $project=test, the test is from
    > command line argument.


    If you add a command line argument like "test", make will try to find a
    target with that name and build it. So to do the above, you'd need to
    create a wildcard target that does the right thing. Your above example
    is even be built-in to gnu make. Just try the following Makefile:

    CXX = g++
    CXXFLAGS = -ggdb

    On a "make test", it should just do what you asked for above.

    > I appreciate any help or direct me to the right new groups.


    Done. (xpost & f'up to gnu.utils.help)
     
    Rolf Magnus, Aug 29, 2004
    #3
  4. newbiecpp

    Rui Maciel Guest

    newbiecpp wrote:
    > I am very sorry to post this one because I know it is out of topic but I
    > cannot find the proper news group. I understand that most senior C++
    > programmers know makefile very well. My question is GNU makefile support
    > command line argument?
    >
    > I want to write a makefile so that when you invoke "make test", the makefile
    > will compile test like this:
    >
    > $project = "command line argument, i.e., test";
    >
    > $project : ($project).cpp
    > g++ -ggdb -o $project ($project).cpp
    >
    > I cannot figure it out how I can get $project=test, the test is from command
    > line argument. I appreciate any help or direct me to the right new groups.
    >
    > Thanks in advance!


    Why not set up a makefile variable for the project name and alter it as
    you see fit? It may not be a solution involving command line arguments
    but apparently it achieves the same thing.
     
    Rui Maciel, Aug 30, 2004
    #4
  5. [OT] Re: Makefile

    newbiecpp wrote:

    > I am very sorry to post this one because I know it is out of topic but I
    > cannot find the proper news group. I understand that most senior C++
    > programmers know makefile very well. My question is GNU makefile support
    > command line argument?
    >
    > I want to write a makefile so that when you invoke "make test", the makefile
    > will compile test like this:
    >
    > $project = "command line argument, i.e., test";
    >
    > $project : ($project).cpp
    > g++ -ggdb -o $project ($project).cpp
    >
    > I cannot figure it out how I can get $project=test, the test is from command
    > line argument. I appreciate any help or direct me to the right new groups.
    >
    > Thanks in advance!
    >
    >

    This has more to do with understanding makefiles than C++ ( Hence
    flagging the msg as o.t. ).

    make test essentially means a target (test is the target).

    Refer to the make utility manual to get this done.
    --
    Karthik.
    ------------ And now a word from our sponsor ----------------------
    For a quality mail server, try SurgeMail, easy to install,
    fast, efficient and reliable. Run a million users on a standard
    PC running NT or Unix without running out of power, use the best!
    ---- See http://netwinsite.com/sponsor/sponsor_surgemail.htm ----
     
    Karthik Kumar, Sep 1, 2004
    #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. MACEI'S
    Replies:
    0
    Views:
    1,348
    MACEI'S
    Jul 10, 2003
  2. Karthik
    Replies:
    0
    Views:
    398
    Karthik
    Apr 29, 2004
  3. Karthik
    Replies:
    0
    Views:
    634
    Karthik
    Apr 29, 2004
  4. Replies:
    16
    Views:
    1,147
  5. Java Makefile

    , Dec 15, 2005, in forum: Java
    Replies:
    23
    Views:
    3,744
    Jean-Francois Briere
    Dec 27, 2005
Loading...

Share This Page