MetallicPriest
MetallicPriest

Reputation: 30765

What is wrong with this makefile

At the top of my makefile I have the following.

USE_44 = 0
ifeq($(USE_44), 0)
    CXX = g++
else
    CXX = g++44
endif

But I get the error

makefile:2: *** missing separator.  Stop.

what wrong am I doing here?

Upvotes: 2

Views: 318

Answers (2)

Maxim Egorushkin
Maxim Egorushkin

Reputation: 136266

GNU make has a very useful yet often overlooked feature called computed variable names. Using this feature allows to avoid conditionals and make the code shorter and more readable:

USE_44 := 0
cxx.0 := g++
cxx.1 := g++44
CXX := ${cxx.${USE_44}} 

Normally though, you want to accept the compiler name from the user and set compiler options depending on the version:

CXX := g++
cxx_version_ := $(subst ., ,$(shell ${CXX} -dumpversion))
cxx_major_ := $(word 1,${cxx_version_})
cxx_minor_ := $(word 2,${cxx_version_})

cxxflags.4 := -Wno-multichar
cxxflags.4.3 := ${cxxflags.4} -march=native -fdiagnostics-show-option
cxxflags.4.4 := ${cxxflags.4.3} -Werror=return-type -Werror=reorder
cxxflags.4.5 := ${cxxflags.4.4}
CXXFLAGS := ${cxxflags.${cxx_major_}.${cxx_minor_}}

$(info g++ version is ${cxx_major_}.${cxx_minor_})
$(info g++ options are ${CXXFLAGS})

Output:

$ make
g++ version is 4.5
g++ options are -Wno-multichar -march=native -fdiagnostics-show-option -Werror=return-type -Werror=reorder
make: *** No targets.  Stop.

Upvotes: 2

MetallicPriest
MetallicPriest

Reputation: 30765

A space was required after ifeq. That solved the problem.

Upvotes: 6

Related Questions