6

我想按照http://sunsite.ualberta.ca/Documentation/Gnu/make-3.79/html_chapter/make_7.html#SEC72上的指南在 Makefile 中编写一些条件。但是,我收到错误Makefile:219: *** missing separator. Stop.,其中第 219 行是ifeq语句所在的行。带有 do 的三行以-$(FC)制表符开头。

我正在使用 GNU Make 3.81。任何帮助是极大的赞赏!

[...]

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)

[...]

编辑:按照@sagar-sakre 的建议,我改为:

[...]
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)
[...]

但是,现在我收到此错误:

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

所以这里还是有问题...

4

1 回答 1

14

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

一般 Makefile 将是

target:dependencies
ifeq ( parm1, parm2)
 [TAB]   operation
else
 [TAB]   operation
endif
于 2013-05-27T09:28:45.440 回答