1

For example, I am trying to test whether this works in my makefile preamble:

ifneq (,$(shell latexmk --version 2>/dev/null))
    echo Works
else
    echo Does not Works
endif

all:
    do things...

Which does the error:

*** recipe commences before first target.  Stop.

Then, how to prints things outside rules?

Makefile does not allow commands outside rules, or outside result:=$(shell ...).

Evandro Coan
  • 8,560
  • 11
  • 83
  • 144

2 Answers2

4

In GNU Make there are $(info ...), $(warning ...) and $(error ...) built-in functions. Note that syntactically they are text substitutions, yet their return value is always an empty string (except $(error ...) which never returns), as it's with $(eval ...) etc. So they could be used almost everywhere.

Yet another option is $(file >/dev/stdout,...) (under Windows use "con").

Matt
  • 13,674
  • 1
  • 18
  • 27
0

After I found this question, https://unix.stackexchange.com/questions/464754/how-to-see-from-which-file-descriptor-output-is-coming

I think this kinda works:

ifneq (,$(shell latexmk --version 2>/dev/null))
    useless := $(shell echo Works 1>&2)
else
    useless := $(shell echo Does not Works 1>&2)
    useless := $(error exiting...)
endif

all:
    echo Hey sister, do you still believe in love I wonder...

Bonus:

  1. Can I make a makefile abort outside of a rule?
Evandro Coan
  • 8,560
  • 11
  • 83
  • 144