[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Creating an obj/ directory?
From: |
Paul Smith |
Subject: |
Re: Creating an obj/ directory? |
Date: |
Fri, 02 Sep 2011 01:40:56 -0400 |
On Thu, 2011-09-01 at 22:53 -0400, Jeffrey Walton wrote:
> Hi All,
>
> I'm working with a project that has a modest tree structure. The *.o
> files are currently being placed next to their *.cpp counterparts. I
> would like to move them to an obj/ directory, maintaining the same
> structure.
> The problem is that our CPP build rule is getting in the way ('don't
> know how to make X'):
>
> .cpp.o:
> $(CXX) $(CXXFLAGS) $(INCLUDES) -fpic -c $< -o $@
You cannot use a suffix rule to define targets and source files in
different directories: they're just not powerful enough. The stem of
the files must be character-for-character identical between them.
That's why GNU make supports pattern rules. Rewrite your rule as:
obj/%.o : %.cpp
$(CXX) $(CXXFLAGS) $(INCLUDES) -fpic -c $< -o $@
Look up pattern rules in the GNU make manual for full details.
--
-------------------------------------------------------------------------------
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