According to what I have read about makefiles, a phony target is any target that does not correspond to an actual filename. My intuition says that a directory as a target would be treated the same as a file.
Why is this important? I have a directory as a target in my makefile. when I have it as a prerequisite to my primary executable, that executable always gets made, whether or not everything is up to date. If I take it out as a prerequisite, my makefile is smart enough to know when things need to be built, but I have the problem of not knowing if the directory needs to be created. According to what I have read about make, any phony targets are not good as prerequisites because make does not know if they are up to date, so they will always rebuild the associated target. Here is an excerpt from my makefile.
$(EXEC_WITH_PATH): ${OBJ_DIR} $(DPEND) $(OBJS)
@echo "--------------------------------------------";
@echo "$(THIS_DIR) $(MACHINE)";
@echo "Linking Shared Library";
@echo "ar -rc $(EXEC_WITH_PATH) INSERT::{OBJS}";
ar -rc $(EXEC_WITH_PATH) $(OBJS);
@echo "--------------------------------------------";
# Make dirs for object code and links
${OBJ_DIR} :
@if [ ! -d ${OBJ_DIR} ]; then \
mkdir ${OBJ_DIR}; \
fi;
So in this case, is ${OBJ_DIR}
, a directory name, a phony target or not?
mkdir -p
, so that it will succeed if the directory already exists, but fail properly if the directory can't be created. – Cascabel