Well, yes, but your question isn't quite right.
Make is good at finding things there and using them to make things here, but not the other way around. VPATH and vpath tell make where to look for the things it needs, but there is no corresponding directive to put the things it makes somewhere other than the current directory.
If you want your object files (OBJECTS = ant.o bee.o) to go into another directory like $(OBJDIR), there are basically three ways to do it.
- Build them here and move them by hand (this one will almost certainly get you in trouble):
$(OBJECTS): %.o: %.c
gcc -c $< -o $@
mv $@ $(OBJDIR)
or equivalently, go there and build them:
$(OBJECTS): %.o: %.c
cd $(OBJDIR) ; gcc -c $< -o $@
- Specify the path and build them in place (probably the best for a beginner):
FULLOBJECTS = $(addprefix $(OBJDIR)/,$(OBJECTS))
$(FULLOBJECTS): $(OBJDIR)/%.o: %.c
gcc -c $< -o $@
- Call Make there (powerful, but very tricky):
$(OBJECTS):
$(MAKE) -C $(OBJDIR) $@