Sun Studio 12: Fortran Programming Guide

3.1.5 Suffix Rules in make

To make writing a makefile easier, make will use its own default rules depending on the suffix of a target file.

The default rules are in the file /usr/share/lib/make/make.rules. When recognizing default suffix rules, make passes as arguments any flags specified by the FFLAGS macro, the -c flag, and the name of the source file to be compiled. Also, the make.rules file uses the name assigned by the FC macro as the name of the Fortran compiler to be used.

The example below demonstrates this rule twice:


FC = f95
OBJ = pattern.o computepts.o startupcore.o
FFLAGS=–u
pattern: $(OBJ)
      f95 $(OBJ) -lcore95 -lcore -lsunwindow \
      -lpixrect -o pattern
pattern.o: pattern.f commonblock
      f95 $(FFLAGS) -c pattern.f
computepts.o: computepts.f commonblock
startupcore.o: startupcore.f

make uses default rules to compile computepts.f and startupcore.f.

There are default suffix rules for .f90 files that will invoke the f95 compiler.

However, unless you define the FC macro to be f95, the default suffix rules for .f and .F files call f77 and not f95.

Furthermore, there are no suffix rules currently defined for .f95 and .F95 files, and .mod Fortran 95 module files will invoke the Modula compiler. To remedy this requires creating your own local copy of the make.rules file in the directory in which make is called, and modifying the file to add .f95 and .F95 suffix rules, and delete the suffix rules for .mod. See the make(1S) man page for details.