5

What does "$$?" mean in below Makefile snippet?

$(PROGS): FORCE
    @cd $(BUILD_DIRECTORY_PATH)/$@; \
    mkdir -p obj; \
    $(MAKE) || exit "$$?"; \  <====== HERE

ADD 1

I guess it means exit "$?" in bash since $$ in makefile escapes to $.

But what does exit "$?" mean then?

smwikipedia
  • 61,609
  • 92
  • 309
  • 482
  • 3
    Exit with the return code of the previous command. Try searching on symbolhound if you have trouble googling code. i.e http://symbolhound.com/?q=exit+%24%3F+bash – 123 Jul 26 '16 at 13:49
  • 1
    @123 Many thanks! *Symbolhound* is simply awesome for coders! I found the answer! – smwikipedia Jul 26 '16 at 13:58

2 Answers2

9

$? is the return code when a program exits or finishes. Therefore, in your line

$(MAKE) || exit "$$?"

It will execute $(MAKE). If this program does not finish correctly, it will have a return code different from 0 and then the exit "$$?" will be executed. which will make the current process to exit to shell with the same return code as the $(MAKE) program, which you will be able to show executing echo $? in the shell.

AwkMan
  • 670
  • 6
  • 18
1

Said another way, $$? is the Makefile equivalent of $?. In Make, to escape $? you need to use $$?. More info: Shell status codes in make


Not that you've asked, but I generally tell folks to avoid Make. If you have a choice:

  1. Install pipx . Project URL: https://pypa.github.io/pipx/ .
  2. Use pipx to install invoke (pipx install invoke). Project URL: https://github.com/pyinvoke/invoke
  3. Use Python instead of strange Make syntax.
blong
  • 2,815
  • 8
  • 44
  • 110