Reputation: 3892
i have little problem with making a make file, this is the code :
SHELL = /bin/sh
CC := gcc
CFLAGS := -Wall
VPATH = src:obj
HEADERS := parser.h
dirs = out obj
%.o : mkdirs %.c $(HEADERS)
$(CC) -c $(word 2,$^) -o obj/$@
all : parser.o
ar cr out/libsip.a $<
clean :
rm -f -r $(dirs)
mkdirs :
mkdir -p $(dirs)
when i try to execute make i get this error :
mkdir -p out obj
gcc -c src/parser.c -o obj/parser.o
ar cr out/libsip.a parser.o
file parser.o not found
i don't understand why parser.o don't get replaced by the right path, i used automatic variable
Upvotes: 1
Views: 319
Reputation: 80931
%.o : mkdirs %.c $(HEADERS)
$(CC) -c $(word 2,$^) -o obj/$@
all : parser.o
ar cr out/libsip.a $<
You are telling make to create a parser.o
file in the current directory.
Your %.o
rule then creates the file in the obj
directory not the current directory.
The ar
command then can't find it.
VPATH
is for finding prerequisites. If obj/parser.o
already existed then make would find it for the all
target I believe.
See How Not to Use VPATH.
Upvotes: 1