8

I want to write some conditionals in a Makefile, following the guide at http://sunsite.ualberta.ca/Documentation/Gnu/make-3.79/html_chapter/make_7.html#SEC72. However, I get the error Makefile:219: *** missing separator. Stop., where line 219 is the line with the ifeq statement. The three lines with the -$(FC) do start with a tab.

I'm using GNU Make 3.81. Any help is greatly appreciated!

[...]

mod: $(MODBIN)

$(MODBIN): $(MODSRC)
ifeq($(FC),gfortran)
    -$(FC) $(MODFLAGS) -J$(INCPATH) $(INCLUDE) -c -o $@ $(subst $(BUILDPATH),$(MODPATH),$*).f90 $(NETCDFLDFLAGS)
else ifeq($(FC),ifort)
    -$(FC) $(MODFLAGS) -module $(INCPATH) $(INCLUDE) -c -o $@ $(subst $(BUILDPATH),$(MODPATH),$*).f90 $(NETCDFLDFLAGS)
else ifeq ($(FC),xlf2003_r)
    -$(FC) $(MODFLAGS) -qmoddir=$(INCPATH) $(INCLUDE) -c -o $@ $(subst $(BUILDPATH),$(MODPATH),$*).f90 $(NETCDFLDFLAGS)
endif

io: $(IOBIN)

[...]

EDIT: Following the advice by @sagar-sakre, I changed to this:

[...]
mod: $(MODBIN)

$(MODBIN): $(MODSRC)
    ifeq($(B3dC),gfortran)
    -$(FC) $(MODFLAGS) -J$(INCPATH) $(INCLUDE) -c -o $@ $(subst $(BUILDPATH),$(MODPATH),$*).f90 $(NETCDFLDFLAGS)
    else ifeq($(B3dC),ifort)
    -$(FC) $(MODFLAGS) -module $(INCPATH) $(INCLUDE) -c -o $@ $(subst $(BUILDPATH),$(MODPATH),$*).f90 $(NETCDFLDFLAGS)
    else ifeq ($(B3dC),xlf2003_r)
    -$(FC) $(MODFLAGS) -qmoddir=$(INCPATH) $(INCLUDE) -c -o $@ $(subst $(BUILDPATH),$(MODPATH),$*).f90 $(NETCDFLDFLAGS)
    endif endif endif

io: $(IOBIN)
[...]

However, now I get this error:

ifeq(xlf,gfortran)
/bin/sh: -c: line 0: syntax error near unexpected token `xlf,gfortran'
/bin/sh: -c: line 0: `ifeq(xlf,gfortran)'
make: *** [build/basic.o] Error 2

So still something's wrong here ...

andreas-h
  • 10,679
  • 18
  • 60
  • 78

1 Answers1

17

There should be a [space] after ifeq

mod: $(MODBIN)
$(MODBIN): $(MODSRC)
ifeq ($(FC),gfortran)
    -$(FC) $(MODFLAGS) -J$(INCPATH) $(INCLUDE) -c -o $@ $(subst
    $(BUILDPATH),$(MODPATH),$*).f90 $(NETCDFLDFLAGS)
else ifeq ($(FC),ifort)
    -$(FC) $(MODFLAGS) -module $(INCPATH) $(INCLUDE) -c -o $@ $(subst
    $(BUILDPATH),$(MODPATH),$*).f90 $(NETCDFLDFLAGS)
else ifeq ($(FC),xlf2003_r)
     -$(FC) $(MODFLAGS) -qmoddir=$(INCPATH) $(INCLUDE) -c -o $@ $(subst 
     $(BUILDPATH),$(MODPATH),$*).f90 $(NETCDFLDFLAGS)
endif

General Makefile would be

target:dependencies
ifeq ( parm1, parm2)
 [TAB]   operation
else
 [TAB]   operation
endif
Ben Fulton
  • 3,988
  • 3
  • 19
  • 35
Sagar Sakre
  • 2,336
  • 22
  • 31
  • thanks! this got me one step farther, but not to the goal yet. Now I get a *syntax error*. See my updated post. – andreas-h May 27 '13 at 09:43