views:

27

answers:

1

I recently switched from using Makefiles to using Automake, and I can't figure out how to write the following simple if statement using automake:

DEBUG ?= 1
ifeq (${DEBUG},1)
CXXFLAGS:=$(CXXFLAGS) -g
else
CXXFLAGS:=$(CXXFLAGS) -O3 -DNDEBUG
endif

Is this even possible to do if I'm using automake? Since it generates the makefile from automatically, does it make sense writing it in the Makefile template? Or should I try to find some way of adding it the automatically generated Makefile?

+1  A: 

No, you cannot use such a syntax with Automake. There is no exact equivalent for the first two lines.

You could do something close using an Automake conditional (see Usage of Conditionals in the Automake manual for examples), and set DEBUG from ./configure. However I see little point in doing that: if you want to change CXXFLAGS globally, simply alter this variable in configure, not in the Makefile.am.

adl
Do NOT alter CXXFLAGS in your build files. The user of your package has the right to expect that you will not set CXXFLAGS. If you must add flags, use AM_CXXFLAGS, but leave CXXFLAGS alone so that the user may set them as desired/needed.
William Pursell