Skip to content

Commit fed0fc3

Browse files
authored
Use fortran compilers for preprocessing instead of cpp (#83)
1 parent c9d8721 commit fed0fc3

2 files changed

Lines changed: 44 additions & 8 deletions

File tree

bld/Makefile

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,24 @@ ifneq ($(MAKECMDGOALS), db_files)
8080
-include $(MACFILE)
8181
endif
8282

83+
#-------------------------------------------------------------------------------
84+
# detect compiler and find argument to preprocess only
85+
#-------------------------------------------------------------------------------
86+
87+
FC_VERSION := $(shell $(FC) --version 2>/dev/null)
88+
89+
ifeq ($(findstring GNU Fortran,$(FC_VERSION)),GNU Fortran)
90+
COMPILER = gfortran
91+
else ifneq ($(findstring Intel,$(FC_VERSION)),) # this matches both ifx and ifort
92+
COMPILER = intel
93+
endif
94+
95+
ifeq ($(COMPILER),gfortran)
96+
FPPFLAG = -cpp -E
97+
else ifeq ($(COMPILER),intel)
98+
FPPFLAG = -fpp -P
99+
endif
100+
83101
#-------------------------------------------------------------------------------
84102
# echo file names, paths, compile flags, etc. used during build
85103
#-------------------------------------------------------------------------------
@@ -113,12 +131,12 @@ $(EXEC): $(OBJS)
113131
cc $(CFLAGS) $(CPPDEFS) $(INCS) $(INCLDIR) $<
114132

115133
.F.o:
116-
$(CPP) $(CPPFLAGS) $(CPPDEFS) $(INCS) $(INCLDIR) $< > $*.f
117-
$(FC) -c $(FFLAGS) $(FIXEDFLAGS) $(INCS) $(INCLDIR) $*.f
134+
$(FC) $(FPPFLAG) $(CPPFLAGS) $(CPPDEFS) $(INCS) $(INCLDIR) $< -o $*.f
135+
$(FC) -c $(FFLAGS) $(FIXEDFLAGS) $(INCS) $(INCLDIR) $*.f
118136

119137
.F90.o:
120-
$(CPP) $(CPPFLAGS) $(CPPDEFS) $(INCS) $(INCLDIR) $< > $*.f90
121-
$(FC) -c $(FFLAGS) $(FREEFLAGS) $(INCS) $(INCLDIR) $*.f90
138+
$(FC) $(FPPFLAG) $(CPPFLAGS) $(CPPDEFS) $(INCS) $(INCLDIR) $< -o $*.f90
139+
$(FC) -c $(FFLAGS) $(FREEFLAGS) $(INCS) $(INCLDIR) $*.f90
122140

123141
mostlyclean:
124142
$(RM) -f *.f *.f90

bld/Makefile.std

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,24 @@ ifneq ($(MAKECMDGOALS), db_files)
8080
-include $(MACFILE)
8181
endif
8282

83+
#-------------------------------------------------------------------------------
84+
# detect compiler and find argument to preprocess only
85+
#-------------------------------------------------------------------------------
86+
87+
FC_VERSION := $(shell $(FC) --version 2>/dev/null)
88+
89+
ifeq ($(findstring GNU Fortran,$(FC_VERSION)),GNU Fortran)
90+
COMPILER = gfortran
91+
else ifneq ($(findstring Intel,$(FC_VERSION)),) # this matches both ifx and ifort
92+
COMPILER = intel
93+
endif
94+
95+
ifeq ($(COMPILER),gfortran)
96+
FPPFLAG = -cpp -E
97+
else ifeq ($(COMPILER),intel)
98+
FPPFLAG = -fpp -P
99+
endif
100+
83101
#-------------------------------------------------------------------------------
84102
# echo file names, paths, compile flags, etc. used during build
85103
#-------------------------------------------------------------------------------
@@ -113,12 +131,12 @@ $(EXEC): $(OBJS)
113131
cc $(CFLAGS) $(CPPDEFS) $(INCS) $(INCLDIR) $<
114132

115133
.F.o:
116-
$(CPP) $(CPPFLAGS) $(CPPDEFS) $(INCS) $(INCLDIR) $< > $*.f
117-
$(FC) -c $(FFLAGS) $(FIXEDFLAGS) $(INCS) $(INCLDIR) $*.f
134+
$(FC) $(FPPFLAG) $(CPPFLAGS) $(CPPDEFS) $(INCS) $(INCLDIR) $< -o $*.f
135+
$(FC) -c $(FFLAGS) $(FIXEDFLAGS) $(INCS) $(INCLDIR) $*.f
118136

119137
.F90.o:
120-
$(CPP) $(CPPFLAGS) $(CPPDEFS) $(INCS) $(INCLDIR) $< > $*.f90
121-
$(FC) -c $(FFLAGS) $(FREEFLAGS) $(INCS) $(INCLDIR) $*.f90
138+
$(FC) $(FPPFLAG) $(CPPFLAGS) $(CPPDEFS) $(INCS) $(INCLDIR) $< -o $*.f90
139+
$(FC) -c $(FFLAGS) $(FREEFLAGS) $(INCS) $(INCLDIR) $*.f90
122140

123141
mostlyclean:
124142
$(RM) -f *.f *.f90

0 commit comments

Comments
 (0)