0

I found that I can use ifneq in makefile and I tried to compare 0 and the output of command stat:

@for f in `find $(PATH_PAGES) -name *.hbs`; do \
    ifneq "`stat -c '%Y' $$f`" "0";
        //some code here
    endif
done

But in terminal I've got an error: ifneq: command not found

Is there a different way to compare this or maybe I'm doing something wrong?

Ivan Shcherbakov
  • 2,633
  • 2
  • 15
  • 10
  • 3
    `-c` is not a portable option to stat, so I'm guessing that you are using it to determine if the file has been modified. `make` is pretty good at comparing timestamps to determine if a dependency is out of date, and it would probably be better to let `make` evaluate the timestamps. Also, you will need line continuations (and probably more semi-colons), since make will treat multiple lines as multiple commands. – William Pursell Jul 11 '13 at 13:51
  • So, how can I let `make` determine timestamps? There is a command in that loop and `make` always call this command on each file, even if this file hasn't been modified. So in that loop I use `touch` to change timestamp and now I want to compare time after timestamp that I use `touch --date="1970-01-01 03:00" $$f;` and 0. I know It's awful solution but I need to edit that makefile and this is my first day with all that makes and makefiles) – Ivan Shcherbakov Jul 11 '13 at 14:00

3 Answers3

4

In this case you don't want to use Make's ifneq, because it does text substitution before handing over the command to the shell, but you have a shell loop that needs to do different things in each iteration depending on the output of a shell command.

Use the shell if instead:

if [ "`stat -c '%Y' $$f`" != "0" ]; then
    //some code here
fi
legoscia
  • 39,593
  • 22
  • 116
  • 167
3

If you want to use makefile's if condition then there should not be [TAB] before the if statement because if you specify [TAB] then it is treated as shell command thats why you are getting error that ifneq:command not found its not there in shell.

May be this Conditionals in Makefile: missing separator error? can help in getting better understanding with makefiles

Community
  • 1
  • 1
Sagar Sakre
  • 2,336
  • 22
  • 31
0

I found that I needed to prepend the if with a @, and backslashes proved to be necessary as well -

@if [ "`stat -c '%Y' $$f`" != "0" ]; then\
    echo hello world;\
fi
skwidbreth
  • 7,888
  • 11
  • 58
  • 105