Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile ifeq problem

I am trying to use ifeq in my rule pattern and I have problems with it. This is the rule I am having trouble with:

$(OBJS): $(OBJDIR)/%.o : ../%.c
    @mkdir -p $(dir $@)
    ifeq(mcc.exe,$(CC))
        o_file:=$(shell echo $@ | sed -e 's/\/cygdrive\///' | sed -e 's/\([a-zA-Z]\)/\1:/')
        $(CC) $(CFLAGS) $< -o $(o_file)
    else
        $(CC) $(CFLAGS) $< -o $@
    endif

When I run this, I get:

"/bin/sh: -c: line 0: syntax error near unexpected token `mcc.exe,mcc.exe'
/bin/sh: -c: line 0: `ifeq(mcc.exe,mcc.exe)'"

But, when I don't use indention, then I get : "Makefile:77: * missing separator. Stop."

I am using GNU make 3.81 on Cygwin. Whole issue with the ifeq comes from the fact that I have same Makefile for two toolchains and one of them (mcc.exe) can not cope with the /cygdrive/c/.../something paths, but instead there should be c:/.../something path. If you know any other way to work around this, I would be also very grateful!

Thank you in advance!

like image 994
Nikola Avatar asked Apr 19 '11 09:04

Nikola


1 Answers

The lines containing ifeq..., else, and endif should not start with a tab. If they do they are treated as part of the recipe and sent to the shell; this leads to the syntax error you get from /bin/sh; see the make manual for an example.

I'm not exactly sure why you get an error when you don't use indentation. Perhaps you can't define a variable in a recipe like this?

Edit: I see you've found the answer. So, no indentation, and a space between ifeq and the parenthesis.

like image 192
eriktous Avatar answered Sep 21 '22 09:09

eriktous