Paul Smith wrote:
On Wed, 2016-06-29 at 14:03 -0400, LMH wrote:
#create build directory if it doesn't exist
$(BDIR):
@mkdir -p $(BDIR)
all: $(BDIR)/SMD2_i386.exe
Here you've created a target $(BDIR), but your "all" target depends
only on the object file $(BDIR)/SMD2_i386.exe.
Since nothing depends on the actual target $(BDIR), make will never try
to build that target.
In order for this to work you'd need to define the directory as a
prerequisite of the target which needs it, which in this case is
$(BDIR)/SMD2_i386.exe, so you'd need to write:
$(BDIR)/SMD2_i386.exe : <other prereqs> $(BDIR)
However, you should generally not have targets depend on directories,
because make treats them just like any other file when it checks
modification times; however directories do not act like normal files
when it comes to modification times.
I usually just use:
$(shell mkdir -p $(BDIR))
but other people prefer order-only prerequisites:
$(BDIR)/SMD2_i386.exe : <other prereqs> | $(BDIR)
(note the extra "|" there). Check the GNU make manual for details.
Note these are all specific to GNU make and not portable to other versions of
make.
Going back through older versions of some of my makefiles, I find that I used to have
an "archdir" target defined along with the code to create the build directory.
archdir: ${BDIR}
${BDIR}:
@mkdir -p $(BDIR)
The archdir target was included in the all target like,
all: archdir $(BDIR)/SMD2_i386.exe
Somewhere along the line, this archdir target seems to have been left out and I guess
this is where I started having problems in cases where the build directory didn't
already exist. The build directory likely did exist in many cases, so I probably
didn't notice right away or thought it was a problem esoteric to the OS I was booted
into.
If you don't mind my asking, how does the above "archdir" solution compare with what
you suggested as far as defining $(BDIR) as a prerequisite for $(BDIR)/SMD2_i386.exe?
Is there any difference?
Your shell solution is simpler than mine in that it doesn't need to actually check if
the directory exists and just suppresses the error message if it does. I am wondering
if there is any value to actually making the check, but I can't think of any off hand.
LMH
_______________________________________________
Help-make mailing list
Help-make@gnu.org
https://lists.gnu.org/mailman/listinfo/help-make