I have a Makefile for compiling some C source files, and put the output in different Build directory, it looks a bit like the makefile below:
# make variable will be exanded when used (and not at declaration)
OBJECTS:= $(addprefix $(OBJDIR), $(notdir $(patsubst %.c,%.o,$(wildcard $(SRCDIR)/*.c))))
.PHONY: copySourcesOver linkSources sharedLibrary
cp $(SOURCES) $(OBJDIR)/
$(OBJECTS)/%.o : $(OBJECTS)/%.c
gcc -fPIC $< -o $@
gcc -shared -o libshared.so $@
sharedLibrary: copySourcesOver \
Make executes in 2 phases. In the first phase it checks what targets are out-of-date and need updating. In the second phase it executes the commands that updates the targets. That means that it checks that the object files are up to date before it actually copies the source files.
So it checks and determines that the object files are up-to-date THEN it copies the (updated) source files to
There is some good reading on this subject in the docs.