$ make VPATH=.. -C objects -f../Makefile
This method allows you to change nothing in the Makefile, but it does not always work. The current directory is different, so if there are any include files with a path relative to it, sometimes it is necessary for the compiler to specify the path to search for them. For example, if the c-file is also an intermediate target, as with lex and yacc .
$ CFLAGS=-I.. make VPATH=.. -C objects -f../Makefile
In the Makefile itself, CFLAGS must be changed using += to preserve both assignments.
All new files are created in objects, but if there are already object files in the current directory and they are newer than the sources, they will be used for linking. To ensure that target and intermediate target files are not searched by VPATH , you can use the vpath directive inside the Makefile to selectively expand the source search. I suggest the following preparation for the start of the Makefile:
SRC := $(dir $(lastword $(MAKEFILE_LIST)))# каталог где находится этот Makefile (если до этой директивы не было include) # для компиляции из другого каталога (где будут временные файлы и результат) vpath %.c $(SRC) vpath %.h $(SRC) vpath Makefile $(SRC)
Now you can compile with the command:
make -C objects -f../Makefile