1

I am trying to set an if test for a specific file in my Makefile to compile it with different flags:

.f90.o:
ifeq ($<,main.f90)
    @echo ok $< 
    $(F90) -c $< -o $@
else
    @echo nope $<
    $(F90) $(F90FLAGS) $(DEBUG) $(INCL) -c $< -o $@
endif

..and despite my efforts I am getting only:

nope main.f90
mpif90 -O2 -g -fbacktrace -fPIC   -c main.f90 -o main.o
  • See: https://stackoverflow.com/questions/62096217/makefile-variable-value-not-available-during-ifeq/62096456#62096456 Automatic variables like `$<` are not available when makefiles are parsed. They're only available when make is running the recipe. – MadScientist Jun 04 '20 at 14:57

1 Answers1

0

The ifeq conditional you have used is processed by Make at parse time, not when the recipe is executed. The macro $< is empty when your script is parsed so your recipe only ever contains the latter two lines.

One solution is to provide two recipes, one for your special case and then a pattern recipe for the rest:

main.o:main.f90
    $(F90) -c $< -o $@

.f90.o:
    $(F90) $(F90FLAGS) $(DEBUG) $(INCL) -c $< -o $@
ste
  • 316
  • 2
  • 7