makefileswitch-statement

Good way to do a "switch" in a Makefile


I'm experimenting with an updated build system at work; currently, I'm trying to find a good way to set compiler & flags depending on the target platform.

What I would like to do is something like

switch $(PLATFORM)_$(BUILD_TYPE)
  case "Linux_x86_release"
     CFLAGS = -O3
  case "Linux_x86_debug"
     CFLAGS = -O0 -g
  case "ARM_release"
     CC = armcc
     AR = armlink
     CFLAGS = -O2 -fx
     ...

which is not supported by GNU Make. Now, my first thought was to just do

-include $(PLATFORM)_$(BUILD_TYPE)

which is a pretty decent solution, however, it makes it hard to get an overview of what differs between files, not to mention that I'm looking forward to writing & maintaining a good 60-80 files, each containing a set of variable definitions.

Does anyone happen to know a better way to accomplish this? I.e. setting a set of flags and other options based on another variable?


Solution

  • Switching to a system which does it for you (automake/autoconf) may be simpler...