help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Makefile with a dynamic target


From: Paul Smith
Subject: Re: Makefile with a dynamic target
Date: Sun, 09 Oct 2011 10:57:41 -0400

On Sun, 2011-10-09 at 01:36 -0700, msaqib wrote:
> What I would like to achieve is
> to build a generic Makefile, so that if I type 
> 
> make foo
> 
> It will read foo.cpp and compile it to a file called foo. Now, I should be
> able to create any new source file (perhaps new1.cpp) and not have to change
> the Makefile and still get the file compiled by typing make new1.cpp.

You don't need a makefile at all for that.  make has builtin rules which
allow it to build a program "foo" from a source file "foo.cpp" (or
"foo.c" or "foo.f" or whatever).

All you need a makefile for is to reset flags variables.

Note that "CC" is a C compiler.  "CXX" is the C++ compiler.  So if you
have a makefile in your directory like this:

        $ cat Makefile
        CXX = g++
        CXXFLAGS = -Wall -O2
        LDLIBS = -lncurses

that's all you need.  Just run "make foo", "make new1", or whatever.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.mad-scientist.net
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist




reply via email to

[Prev in Thread] Current Thread [Next in Thread]