0

I am trying to create a makefile so when calling it the syntax will be make release or make debug.

In order to do so, I have composed the following makefile:

release debug: mode := $@
release debug: build

build:
    *** actual build commands using $(mode) ***

But in the making process, when reaching the build rule, $(mode) seems to be empty.

Is there a better/proper build debug and release binaries?

1 Answers1

0

The '$@' automatic variable is only available when building a target. It does not have a value when a rule is evaluated. As a result '$@' is not set during the execution of the line:

release debug: mode := $@

Consider setting up rules for 'build' and 'release'

release debug:
        $(MAKE) build mode=$@

build:

Or the alternative (which I think is less intuitive, but more efficient):

release: mode=release
debug: mode=debug

build:
    ...
dash-o
  • 13,723
  • 1
  • 10
  • 37