1ROOTDIR = $(abspath $(dir $(firstword $(MAKEFILE_LIST)))) 2DEPDIR = ../.. 3SRCDIR = . 4INCDIR = . 5BLDDIR = obj 6OUTDIR = . 7 8CXXFLAGS = $(NULL) 9CFLAGS = $(NULL) 10DFLAGS = $(NULL) 11 12# Fortran code here does not allow for PEDANTIC=2 13override PEDANTIC = 1 14BLAS = 1 15OMP = 1 16SYM = 1 17 18# include common Makefile artifacts 19include $(DEPDIR)/Makefile.inc 20 21# necessary include directories 22IFLAGS += -I$(call quote,$(INCDIR)) 23IFLAGS += -I$(call quote,$(DEPDIR)/include) 24 25OUTNAME := $(shell basename "$(ROOTDIR)") 26HEADERS := $(wildcard $(INCDIR)/*.h) $(wildcard $(INCDIR)/*.hpp) $(wildcard $(INCDIR)/*.hxx) $(wildcard $(INCDIR)/*.hh) \ 27 $(wildcard $(SRCDIR)/*.h) $(wildcard $(SRCDIR)/*.hpp) $(wildcard $(SRCDIR)/*.hxx) $(wildcard $(SRCDIR)/*.hh) \ 28 $(DEPDIR)/include/libxsmm_source.h 29CPPSRCS := $(wildcard $(SRCDIR)/*.cpp) 30CXXSRCS := $(wildcard $(SRCDIR)/*.cxx) 31CCXSRCS := $(wildcard $(SRCDIR)/*.cc) 32CSOURCS := $(wildcard $(SRCDIR)/*.c) 33CPPOBJS := $(patsubst %,$(BLDDIR)/%,$(notdir $(CPPSRCS:.cpp=-cpp.o))) 34CXXOBJS := $(patsubst %,$(BLDDIR)/%,$(notdir $(CXXSRCS:.cxx=-cxx.o))) 35CCXOBJS := $(patsubst %,$(BLDDIR)/%,$(notdir $(CCXSRCS:.cc=-cc.o))) 36COBJCTS := $(patsubst %,$(BLDDIR)/%,$(notdir $(CSOURCS:.c=-c.o))) 37ifneq (,$(strip $(FC))) 38FXXSRCS := $(wildcard $(SRCDIR)/*.f) 39F77SRCS := $(wildcard $(SRCDIR)/*.F) 40F90SRCS := $(wildcard $(SRCDIR)/*.f90) $(wildcard $(SRCDIR)/*.F90) 41FXXOBJS := $(patsubst %,$(BLDDIR)/%,$(notdir $(FXXSRCS:.f=-f.o))) 42F77OBJS := $(patsubst %,$(BLDDIR)/%,$(notdir $(F77SRCS:.F=-f77.o))) 43F90OBJS := $(patsubst %,$(BLDDIR)/%,$(notdir $(F90SRCS:.f90=-f90.o))) 44F90OBJS := $(patsubst %,$(BLDDIR)/%,$(notdir $(F90OBJS:.F90=-f90.o))) 45endif 46SOURCES := $(CPPSRCS) $(CXXSRCS) $(CCXSRCS) $(CSOURCS) 47OBJECTS := $(CPPOBJS) $(CXXOBJS) $(CCXOBJS) $(COBJCTS) 48FTNSRCS := $(FXXSRCS) $(F77SRCS) $(F90SRCS) 49MODULES := $(addsuffix .mod,$(basename $(FTNSRCS))) $(addsuffix .modmic,$(basename $(FTNSRCS))) 50FTNOBJS := $(FXXOBJS) $(F77OBJS) $(F90OBJS) 51XFILES := $(OUTDIR)/$(OUTNAME) 52 53# specfem example specific 54MODULES += my_libxsmm.mod constants.mod specfem_par.mod my_libxsmm.modmic constants.modmic specfem_par.modmic 55DFLAGS += -DFORCE_VECTORIZATION 56 57# OpenMP directives support 58ifneq (0,$(OMP)) 59DFLAGS += -DUSE_OPENMP 60endif 61 62# fixes library paths: substitutes path name from ../mkl/lib/intel64/.. to ../mkl/lib/mic/.. 63ifneq (0,$(KNC)) 64ifneq (0,$(MPSS)) 65lib_intel := mkl/lib/intel64 66lib_mic := mkl/lib/mic 67LDFLAGS_MIC = $(subst $(lib_intel),$(lib_mic),$(LDFLAGS)) 68endif 69endif 70 71## 72## targets 73## 74 75.PHONY: all 76all: $(XFILES) 77 78.PHONY: compile 79compile: $(OBJECTS) $(FTNOBJS) 80 81ifneq (,$(strip $(FC))) 82$(OUTDIR)/specfem: $(OUTDIR)/.make $(FTNOBJS) $(LIBDEP) 83ifneq (0,$(KNC)) 84ifneq (0,$(MPSS)) 85 @echo "" 86 @echo "building MIC/KNC version" 87 @echo "" 88 $(FLD) -o $@ -mmic $(FTNOBJS) $(FORTLIB) $(MAINLIB) $(FCMTFLAGS) $(SLDFLAGS) $(LDFLAGS_MIC) $(FLDFLAGS) $(ELDFLAGS) 89endif 90endif 91ifeq (0,$(KNC)) 92ifeq (0,$(MPSS)) 93 @echo "" 94 @echo "building host version" 95 @echo "" 96 $(FLD) -o $@ $(FTNOBJS) $(FORTLIB) $(MAINLIB) $(FCMTFLAGS) $(SLDFLAGS) $(LDFLAGS) $(FLDFLAGS) $(ELDFLAGS) 97endif 98endif 99else 100.PHONY: $(OUTDIR)/specfem 101endif 102 103.PHONY: clean 104clean: 105ifneq ($(call qapath,$(BLDDIR)),$(ROOTDIR)) 106ifneq ($(call qapath,$(BLDDIR)),$(call qapath,.)) 107 @rm -rf $(BLDDIR) 108endif 109endif 110ifneq (,$(wildcard $(BLDDIR))) # still exists 111 @rm -f $(OBJECTS) $(OBJECTX) $(FTNOBJS) $(FTNOBJX) *__genmod.* fit.log *.dat 112 @rm -f $(BLDDIR)/*.gcno $(BLDDIR)/*.gcda $(BLDDIR)/*.gcov 113endif 114 @rm -f .make .state 115 116.PHONY: realclean 117realclean: clean 118ifneq ($(call qapath,$(OUTDIR)),$(ROOTDIR)) 119ifneq ($(call qapath,$(OUTDIR)),$(call qapath,.)) 120 @rm -rf $(OUTDIR) 121endif 122endif 123ifneq (,$(wildcard $(OUTDIR))) # still exists 124 @rm -f $(OUTDIR)/libxsmm.$(DLIBEXT) $(OUTDIR)/*.stackdump 125 @rm -f $(XFILES) $(MODULES) 126endif 127 128## 129## dependencies 130## 131$(BLDDIR)/compute_forces_Dev-f90.o: $(BLDDIR)/specfem-f90.o 132$(BLDDIR)/compute_forces_noDev-f90.o: $(BLDDIR)/specfem-f90.o 133$(BLDDIR)/compute_forces_xsmm_dispatch-f90.o: $(BLDDIR)/specfem-f90.o 134$(BLDDIR)/compute_forces_xsmm_prefetch-f90.o: $(BLDDIR)/specfem-f90.o 135$(BLDDIR)/compute_forces_xsmm_static-f90.o: $(BLDDIR)/specfem-f90.o 136 137## 138## rules 139## 140ifneq (,$(strip $(FC))) 141ifneq (0,$(KNC)) 142ifneq (0,$(MPSS)) 143$(BLDDIR)/%-f90.o: $(SRCDIR)/%.f90 .state $(BLDDIR)/.make Makefile $(DEPDIR)/Makefile.inc 144 $(FC) $(FCMTFLAGS) $(DFLAGS) $(IFLAGS) $(FCFLAGS) -mmic -c $< -o $@ 145 146$(BLDDIR)/%-f90.o: $(SRCDIR)/%.F90 .state $(BLDDIR)/.make Makefile $(DEPDIR)/Makefile.inc 147 $(FC) $(FCMTFLAGS) $(DFLAGS) $(IFLAGS) $(FCFLAGS) -mmic -c $< -o $@ 148endif 149endif 150ifeq (0,$(KNC)) 151ifeq (0,$(MPSS)) 152$(BLDDIR)/%-f90.o: $(SRCDIR)/%.f90 .state $(BLDDIR)/.make Makefile $(DEPDIR)/Makefile.inc 153 $(FC) $(FCMTFLAGS) $(DFLAGS) $(IFLAGS) $(FCFLAGS) $(FTARGET) -c $< -o $@ 154 155$(BLDDIR)/%-f90.o: $(SRCDIR)/%.F90 .state $(BLDDIR)/.make Makefile $(DEPDIR)/Makefile.inc 156 $(FC) $(FCMTFLAGS) $(DFLAGS) $(IFLAGS) $(FCFLAGS) $(FTARGET) -c $< -o $@ 157endif 158endif 159endif 160 161