help-make
[Top][All Lists]
Advanced

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

Makefile with a dynamic target


From: msaqib
Subject: Makefile with a dynamic target
Date: Sun, 9 Oct 2011 01:36:11 -0700 (PDT)

I am not sure how to phrase this, which is probably why I didn't find a
solution to this on the web or the archive. 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. So,
the Makefile should be dynamic anc generic. All I have right now is the
following, which is obviously wrong, because it tries to compile all .cpp
files in the current directory and link them. I don't want that. My programs
are short and stand alone, single file programs.


CC = g++
CFLAGS = -Wall -O2
COMPILE = $(CC) $(CFLAGS) -c
OBJFILES := $(patsubst %.cpp,%,$(wildcard *.cpp))
LIBS = -lncurses
all: myprog

myprog: $(OBJFILES)
        $(CC) -o myprog $(OBJFILES)

%.o: %.cpp
        $(COMPILE) -o $@ $< $(LIBS)

Thanks and best regards
-- 
View this message in context: 
http://old.nabble.com/Makefile-with-a-dynamic-target-tp32618272p32618272.html
Sent from the Gnu - Make - Help mailing list archive at Nabble.com.




reply via email to

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