By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,192 Members | 852 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,192 IT Pros & Developers. It's quick & easy.

Makefile

P: n/a
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!
Jul 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
In article <yDlYc.3487$hq5.2435@trndny09>, newbiecpp
<ne*******@yahoo.com> 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
Jul 22 '05 #2

P: n/a
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)

Jul 22 '05 #3

P: n/a
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.
Jul 22 '05 #4

P: n/a
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 ----
Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.