Makefile

N

newbiecpp

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!
 
A

Alwyn

newbiecpp said:
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
 
R

Rolf Magnus

newbiecpp said:
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)
 
R

Rui Maciel

newbiecpp said:
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.
 
K

Karthik Kumar

newbiecpp said:
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 ----
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top