3

I see that in some recipes in Makefiles, the commands are prefixed with a “-“. For example:

Recipe A (the "-" in "-if")

-if test "X$(topdir)" != "X$(BUILD_DIR)" ; then \
            $(RM) parser-built y.tab.c y.tab.h ; \
        fi

Recipe B

( cd $(DOCDIR) && $(MAKE) $(MFLAGS) $@ )
( cd builtins && $(MAKE) $(MFLAGS) $@ )
-( cd $(SDIR) && $(MAKE) $(MFLAGS) $@ )
-for libdir in ${LIB_SUBDIRS}; do \
    (cd $$libdir && test -f Makefile && $(MAKE) $(MFLAGS) $@) ;\
done
-( cd $(PO_DIR) ; $(MAKE) $(MFLAGS) DESTDIR=$(DESTDIR) $@ )
$(RM) $(CREATED_SUPPORT)

Recipe C

-size $(Program)

Been trying to understand what they are, but can’t find anything in both bash shell and GNU make manuals. Does anyone know what they mean? Is it a feature of Bash or Make?

P.S.: Also, what do the brackets mean? eg. -( … )

forgodsakehold
  • 870
  • 10
  • 26

1 Answers1

2

The parentheses are a shell feature and execute the command in a subshell. This allows you to e.g. modify environment variables temporarily or run multiple commands in background. Here, it is used to change the working directory temporarily (via cd) without affecting subsequent commands. In this case, this could also be achieved by passing -C to the make command. Calling make from make is called "recursive make" and is somewhat problematic (Google "recursive make considered harmful").

Erlkoenig
  • 2,664
  • 1
  • 9
  • 18