Makefile

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • newbiecpp

    #1

    Makefile

    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!


  • Alwyn

    #2
    Re: Makefile

    In article <yDlYc.3487$hq5 .2435@trndny09> , newbiecpp
    <newbiecpp@yaho o.com> wrote:
    [color=blue]
    > 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.[/color]

    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

    Comment

    • Rolf Magnus

      #3
      Re: Makefile

      newbiecpp wrote:
      [color=blue]
      > I am very sorry to post this one because I know it is out of topic but
      > I cannot find the proper news group.[/color]

      What about gnu.utils.help?
      [color=blue]
      > 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.[/color]

      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.
      [color=blue]
      > I appreciate any help or direct me to the right new groups.[/color]

      Done. (xpost & f'up to gnu.utils.help)

      Comment

      • Rui Maciel

        #4
        Re: Makefile

        newbiecpp wrote:[color=blue]
        > 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![/color]

        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.

        Comment

        • Karthik Kumar

          #5
          [OT] Re: Makefile

          newbiecpp wrote:
          [color=blue]
          > 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!
          >
          >[/color]
          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 ----

          Comment

          Working...