I am trying to build a project who's Makefile imports an erlang.mk, that imports other Makefiles and erlang.mks.
In one erlang.mk I have a grep
call inside a conditional in a recipe that looks like this
if grep ^$$dep$$ $(ERLANG_MK_TMP)/deps.log; then \
and that's printing
grep: /home/forrealthough/code/rabbitmq-consistent-hash/.erlang.mk/deps.log: No such file or directory
with a return code of 2. If I put this line just before
if [ ! -f $$ERLANG_MK_TMP/deps.log ]; then echo "File not found!"; fi;\
I get a "File not found!".
The file does exist, I can cat
it from the same directory and run the same if
line without getting a "File not found!". Its permissions are -rw-rw-r--
and I get the same error running make
with or without sudo
.
Why can't my script find this file?
EDIT: I was asked to alter my if
test, so here is the relevant section of my script (this is inside a recipe):
echo file: $(ERLANG_MK_TMP)/deps.log;\
if [ ! -f $(ERLANG_MK_TMP)/deps.log ]; then echo "File not found!"; fi;\
if grep ^$$dep$$ $(ERLANG_MK_TMP)/deps.log; then \
and they print
file: /home/forrealthough/rabbitmq-consistent-hash/.erlang.mk/deps.log
File not found!
grep: /home/forrealthough/rabbitmq-consistent-hash/.erlang.mk/deps.log: No such file or directory
make: *** [erlang.mk:4322: deps] Error 2
Again, the file does exist. grep
returns status code=2, which I checked echoing $$?
, and it runs the else
part of the conditional.
EDIT 2: If I put a ls $(ERLANG_MK_TMP);\
along those other tests it lists every file inside that directory, except deps.log, which, again, is there. This fits other tests I did where I tried to access different files from this script, and deps.log is the only one that couldn't be found.
I have this same script inside this same project being built as a module of a different project (Another Makefile that imports another erlang.mk that tries to build the Makefile of the project I'm working on). There the script can find the file in question, and it runs normally.
CodePudding user response:
$(ERLANG_MK_TMP)
is a make variable. $$ERLANG_MK_TMP
is an (escaped) shell variable. The latter will only have a value if you export the former, it won't have any value if you just assign a make variable in the makefile without exporting it.
Why did you use two different formats here? Why not use:
if [ ! -f $(ERLANG_MK_TMP)/deps.log ]; then ...
?