2

After reading this question, I wrote a Makefile that starts with

CXX=g++
CXXFLAGS= -std=c++17  -Wall -O3 -g

ifeq ( $( shell uname ), "Linux" )
CXXFLAGS += -fopenmp
endif


LIBS= -pthread
INCLUDES = -I.
TARGETS= my targets...

I need to pass the -fopenmp flag only if I'm compiling on linux and not when I'm compiling on Mac.

My problem is that this don't work and the flag never get passed.

ninazzo
  • 547
  • 1
  • 6
  • 17

1 Answers1

2

gmake's syntax is quite sensitive to whitespace (especially gmake macros). Additionally, the output of uname does not include quotes.

This should be:

CXX=g++
CXXFLAGS= -std=c++17  -Wall -O3 -g

ifeq ($(shell uname),Linux)
CXXFLAGS += -fopenmp
endif

zz:
    echo $(CXXFLAGS)

Result:

$ make zz
echo -std=c++17  -Wall -O3 -g -fopenmp
-std=c++17 -Wall -O3 -g -fopenmp
Sam Varshavchik
  • 114,536
  • 5
  • 94
  • 148