Reputation: 148
On Linux, when compiling through Makefile, I get some errors while copying a target:
all: $(TARGET)
$(TARGET): $(OBJ)
$(AR) $(ARFLAGS) $(TARGET) $(OBJ)
chmod 775 $(ETARGET) $(OBJ)
$(shell cp libTrgt.a ../../../../lib)
During this makefile is giving an error
cp: cannot stat `libTrgt.a': No such file or directory,
even though I see it is there in the current directory.
When I split it in two targets, it succeeds and I am not sure why:
all: $(TARGET) COPY
$(TARGET): $(OBJ)
$(AR) $(ARFLAGS) $(TARGET) $(OBJ)
chmod 775 $(ETARGET) $(OBJ)
COPY:
$(shell cp libTrgt.a ../../../../lib)
What is causing the error?
Upvotes: 0
Views: 327
Reputation: 37467
The problem here is that the $(shell ...)
command is executing while parsing the Makefile, whereas the commands to create the library $(AR)
is executing later on.
At the time the copy command is executed, the library file does not exist. Yet.
You should more simply write your Makefile as:
all: $(TARGET)
$(TARGET): $(OBJ)
$(AR) $(ARFLAGS) $(TARGET) $(OBJ)
chmod 775 $(ETARGET) $(OBJ)
cp libTrgt.a ../../../../lib/
Upvotes: 3