Reputation: 640
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 ;)
Upvotes: 0
Views: 121
Reputation: 17383
Every command in make is executed in a new subshell for each command line. This means that the commands
cd initfs_root
tar --format ustar --exclude-vcs -cf ../initfs.tar ./
are executed in two different subshells. The tar
command is therefore not executed with the initfs_root
directory as its working directory.
You can avoid this by combining the two into one commandline:
cd initfs_root; tar --format ustar --exclude-vcs -cf ../initfs.tar ./
By the way, be careful if any files you are trying to tar
have spaces in their path or name. Those will be split into multiple names in the variable $INITFS_FILES
and your mechanism will break.
Upvotes: 5