Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is wrong with this Makefile

Tags:

c

makefile

I have the following makefile. If I do make USE_44=1 USE_O=1 for example, I receive the following error.

makefile:21: *** missing separator, where line 21 is elif ($(USE_S), 1).

Note that if I do make USE_44=1, it compiles fine.

Can someone tell me what is the problem here and how can I fix it?

USE_44 = 0
USE_IO = 0
USE_O = 0
USE_S = 0
USE_F = 0
USE_I = 0
USE_WL = 0

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

CXXFILES = main.cpp jacobcalc.cpp linkup.cpp slave1.cpp jacobcalc2.cpp slave2.cpp laplacalc.cpp multi.cpp subblock.cpp replication.cpp hash.cpp

CXXFLAGS := -std=c++0x -O3 -o

ifeq ($(USE_O), 1)
    CXXFLAGS += progo -DWITHOUT_LOCKS -DWITHOUT_BARRIERS -DWITHOUT_MPROTECT 
elif ($(USE_S), 1)
    CXXFLAGS += progs -DWITHOUT_LOCKS -DWITHOUT_BARRIERS -DWITHOUT_MPROTECT -DSINGLE
elif ($(USE_F), 1)
    CXXFLAGS += progf -DNEGLECT_DET_LOCKS 
elif ($(USE_I), 1)
    CXXFLAGS += progi -DWITH_INSTR
elif ($(USE_WL), 1)
    CXXFLAGS += progwl -DWITHOUT_LOCKS 
else
    CXXFLAGS += prog
endif

ifeq ($(USE_IO), 1)
    CXXFLAGS += -DWITHOUT_IO
endif

#CFLAGS := $(CFLAGS) -Wall -W -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wdisabled-optimization
#CFLAGS := $(CFLAGS) -Wpadded -Winline -Wpointer-arith -Wsign-compare -Wendif-labels prog
LIBS := -lm -lpthread 

all:
    $(CXX) $(CXXFILES) $(LIBS) $(CXXFLAGS)

clean:
    rm -f prog* *.o
like image 1000
MetallicPriest Avatar asked Dec 03 '22 07:12

MetallicPriest


2 Answers

The correct way to use conditionals is outlined in the make documentation.

  conditional-directive
  text-if-one-is-true
  else conditional-directive
  text-if-true
  else
  text-if-false
  endif

elif is unrecognized. If you'd instead typed else ifeq(...) it should all be good.

like image 200
Linus Kleen Avatar answered Dec 22 '22 06:12

Linus Kleen


Try with:

ifeq ($(USE_O), 1)
   ...
else ifeq ($(USE_S), 1)
   ...
endif

That's the correct syntax according the the conditional syntax docs for GNU Make.

like image 33
Mat Avatar answered Dec 22 '22 07:12

Mat