I feel like this is a fairly common problem, but I cannot find the answer in my specific situation anywhere. I have a target like so:
initfs.tar: $(INITFS_FILES)
rm -f ./initfs.tar
cd initfs_root
tar --format ustar --exclude-vcs -cf ../initfs.tar ./
INITFS_FILES is defined:
INITFS_FILES:=$(shell find ./initfs_root/ -not -path '*/.*/*' -not -name '.*' -type f)
Every time I call make initfs.tar, this target is run. No files are being touched in the initfs_root directory (and all files are found using that find command). initfs.tar is, indeed, created.
Does anyone have any idea as to why this is happening? It doesn’t make sense, to me, and according to all other posts which I have come across on the internet and my current expertise, I have everything correct (although, obviously, my expertise is lacking in the Makefile area 😉
Every command in make is executed in a new subshell for each command line. This means that the commands
are executed in two different subshells. The
tarcommand is therefore not executed with theinitfs_rootdirectory as its working directory.You can avoid this by combining the two into one commandline:
By the way, be careful if any files you are trying to
tarhave spaces in their path or name. Those will be split into multiple names in the variable$INITFS_FILESand your mechanism will break.