Make And Conditions


Table of Contents

conditions in Make 
conditions in Make 
Conditional Syntax 
Makefile and Conditional Arguement Lists 
Makefile and Conditional Arguement Lists 
Conditional including Make file 
Solution 
Including Other Makefiles 
The `shell' Function 
Conditional Parts of Makefiles 

conditions in Make 

Newsgroups: comp.unix.questions
>Can I use conditions in make file?
>
>E.g.:
>
>        [ ${TAG} = tag1 ] && {
>         do this
>         do that
>        }
>
>How can I achive the above behavior?

The action (tab-indented) lines in the file are passed to the shell after a small amount of processing on make's part. To do the above, you need to:

  • double-up any $'s which are supposed to be interpreted by the shell
  • end each line of a compound statement with a
  • pretend that the <\><newline> pair was not there and add semicolons (;s) as needed

you want make to be expanding), then the above example becomes:

[ $${TAG} = tag1 ] && { \
  do this; \
  do that; \
}

just remove one of the $s.)

Ken Pizzini

conditions in Make 

Example 1. File: Makefile

test:
        [ $${TAG} = tag1 ] && { \
          echo "action 1!"; \
          echo "action 2!"; \
          }

[Tip]

!!

$ export TAG=tag1
$ make
[ ${TAG} = tag1 ] && { \
  echo "action 1!"; \
  echo "action 2!"; \
  }
action 1!
action 2!

Conditional Syntax 

All instances of conditional syntax are parsed immediately, in their entirety; this includes the `ifdef', `ifeq', `ifndef', and `ifneq' forms.