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 <[email protected]>          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


_______________________________________________
Help-make mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/help-make

Reply via email to