$(info) command io redirection

Viewed 74

Can I get standard error redirected from make info command to a file? E.g. if I wanna print compilation command and redirect 2> to a file, the file gets just an empty string but the command inside the info parenthesis is printed, like bellow:

ifdef VERBOSE
  verbose := @cat /tmp/compilation.out
endif

development: $(source)
    # Pipe to cat is just to redirect signals from make to don't exit on error
    @$(info $(CC) -o $(target) $^ $(DEBUG)) 2> /tmp/compilation.out | cat
    $(verbose)
    @cat /tmp/compilation.out >> $(log)
1 Answers

Make variables and functions are expanded by make before it invokes the shell to run the recipe. The results of expansion are passed to the shell.

2> is a shell construct, it's not interpreted by make.

The info make function is defined to write its arguments to stdout, and expand to the empty string. So, when make expands this recipe line:

$(info $(CC) -o $(target) $^ $(DEBUG)) 2> /tmp/compilation.out | cat

First it expands the arguments to info and writes the results to stdout, then it replaces the info function with the empty string, then it invokes the shell with the results; so the shell sees:

 2> /tmp/compilation.out | cat

The short answer is no, there is no way to get make's info function to write output to a file. You'll have to use something the shell knows about, like echo:

@echo '$(CC) -o $(target) $^ $(DEBUG)' 2> /tmp/compilation.out | cat
Related