Hello list,
I'm a little confused by the .PATH.o target in makefiles. For
the record I'm running on a snapshot from the 29th of June
(amd64).
I have the following file structure:
./Makefile
./port.c
./cheese.c
./Makefile
./objects/
./include/
./include/port.h
I have the following makefile:
=========================================
.SUFFIXES: .o .c .h
.INCLUDES: .h
.PATH.h: include
.PATH.o: objects
OBJ_DIR=objects
CFLAGS=-Iinclude
happiness: cheese.o \
port.o
gcc $(CFLAGS) -o happiness \
$(OBJ_DIR)/cheese.o \
$(OBJ_DIR)/port.o
port.o: port.c port.h
gcc -c $(CFLAGS) -o $(OBJ_DIR)/port.o port.c
cheese.o: cheese.c port.h
gcc -c $(CFLAGS) -o $(OBJ_DIR)/cheese.o cheese.c
========================================
If I run make, I get the following output:
gcc -c -Iinclude -o objects/cheese.o cheese.c
gcc -c -Iinclude -o objects/port.o port.c
gcc -Iinclude -o happiness objects/cheese.o objects/port.o
which is fine, dandy and what I expect. If I run make again
however, I get the same result. running "make -d m" indicates
that it isn't finding port.o or cheese.o in the objects
directory, it is only looking in the current directory.
Prefixing port.o/cheese.o with $(OBJ_DIR) results in their
targets not being found. Adding $(OBJ_DIR) as a prefix to all
.o files seem a little verbose.
I thought that specifying .PATH.o in the manner above would
mean that make would interpret port.o as $(.PATH.o)/port.o
whether it be a dependency or a target. I have read the man
page (hence I know that .PATH.o exists) but I can't see why
what I have shouldn't work.
It seems obvious to me that I'm missing something, but I can't
see what it is. Could somebody explain it to me, or suggest
how I could patch the above makefile to make use of .PATH.o?
Thanks,
Patsy
It appears to be able to find port.h (removing .PATH.h causes
a "non-existant" error).