1ROOTDIR = $(abspath $(dir $(firstword $(MAKEFILE_LIST)))) 2DEPDIR = ../.. 3SRCDIR = . 4INCDIR = . 5BLDDIR = obj 6OUTDIR = . 7 8CXXFLAGS = $(NULL) 9CFLAGS = $(NULL) 10DFLAGS = -DLIBXSMM_BLAS_CONST 11 12BLAS = 1 13OMP = 1 14SYM = 1 15 16# explore AVX/ARCH=native 17SSE = 0 18 19# include common Makefile artifacts 20include $(DEPDIR)/Makefile.inc 21 22# necessary include directories 23IFLAGS += -I$(call quote,$(INCDIR)) 24IFLAGS += -I$(call quote,$(DEPDIR)/include) 25 26OUTNAME := $(shell basename "$(ROOTDIR)") 27HEADERS := $(wildcard $(INCDIR)/*.h) $(wildcard $(INCDIR)/*.hpp) $(wildcard $(INCDIR)/*.hxx) $(wildcard $(INCDIR)/*.hh) \ 28 $(wildcard $(SRCDIR)/*.h) $(wildcard $(SRCDIR)/*.hpp) $(wildcard $(SRCDIR)/*.hxx) $(wildcard $(SRCDIR)/*.hh) \ 29 $(DEPDIR)/include/libxsmm_source.h 30CPPSRCS := $(wildcard $(SRCDIR)/*.cpp) 31CXXSRCS := $(wildcard $(SRCDIR)/*.cxx) 32CCXSRCS := $(wildcard $(SRCDIR)/*.cc) 33CSOURCS := $(wildcard $(SRCDIR)/*.c) 34CPPOBJS := $(patsubst %,$(BLDDIR)/%,$(notdir $(CPPSRCS:.cpp=-cpp.o))) 35CXXOBJS := $(patsubst %,$(BLDDIR)/%,$(notdir $(CXXSRCS:.cxx=-cxx.o))) 36CCXOBJS := $(patsubst %,$(BLDDIR)/%,$(notdir $(CCXSRCS:.cc=-cc.o))) 37COBJCTS := $(patsubst %,$(BLDDIR)/%,$(notdir $(CSOURCS:.c=-c.o))) 38ifneq (,$(strip $(FC))) 39FXXSRCS := $(wildcard $(SRCDIR)/*.f) 40F77SRCS := $(wildcard $(SRCDIR)/*.F) 41F90SRCS := $(wildcard $(SRCDIR)/*.f90) $(wildcard $(SRCDIR)/*.F90) 42FXXOBJS := $(patsubst %,$(BLDDIR)/%,$(notdir $(FXXSRCS:.f=-f.o))) 43F77OBJS := $(patsubst %,$(BLDDIR)/%,$(notdir $(F77SRCS:.F=-f77.o))) 44F90OBJS := $(patsubst %,$(BLDDIR)/%,$(notdir $(F90SRCS:.f90=-f90.o))) 45F90OBJS := $(patsubst %,$(BLDDIR)/%,$(notdir $(F90OBJS:.F90=-f90.o))) 46endif 47SOURCES := $(CPPSRCS) $(CXXSRCS) $(CCXSRCS) $(CSOURCS) 48OBJECTS := $(CPPOBJS) $(CXXOBJS) $(CCXOBJS) $(COBJCTS) 49FTNSRCS := $(FXXSRCS) $(F77SRCS) $(F90SRCS) 50MODULES := $(addsuffix .mod,$(basename $(FTNSRCS))) $(addsuffix .modmic,$(basename $(FTNSRCS))) 51FTNOBJS := $(FXXOBJS) $(F77OBJS) $(F90OBJS) 52XFILES := $(OUTDIR)/$(OUTNAME)_smm $(OUTDIR)/$(OUTNAME)_tensor 53 54ifneq (0,$(EIGEN)) 55ifeq (,$(strip $(EIGENROOT))) 56 ifneq (,$(wildcard $(DEPDIR)/../eigen*/Eigen/Dense)) 57 EIGENROOT = $(lastword $(sort $(wildcard $(DEPDIR)/../eigen*))) 58 else ifneq (,$(wildcard $(HOME)/eigen*/Eigen/Dense)) 59 EIGENROOT = $(lastword $(sort $(wildcard $(HOME)/eigen*))) 60 else ifneq (,$(wildcard /usr/include/eigen3/Eigen/Dense)) 61 EIGENROOT = /usr/include/eigen3 62 else ifneq (,$(wildcard /usr/local/opt/eigen/include/eigen3/Eigen/Dense)) 63 EIGENROOT = /usr/local/opt/eigen/include/eigen3 64 endif 65endif 66endif 67 68ifneq (,$(EIGENROOT)) 69 DFLAGS += -D__EIGEN 70 IFLAGS += -I$(call quote,$(EIGENROOT)) 71 EIGEN ?= 1 72 ifneq (0,$(MKL)) 73 DFLAGS += -DEIGEN_USE_MKL_ALL 74 endif 75 ifneq (0,$(shell echo "$$((1 < $(BLAS) || 1 < $(EIGEN)))")) 76 DFLAGS += -DEIGEN_USE_THREADS 77 else 78 DFLAGS += -DEIGEN_DONT_PARALLELIZE 79 endif 80 ifneq (,$(wildcard $(EIGENROOT)/unsupported/Eigen/CXX11/ThreadPool)) 81 DFLAGS += -D__EIGEN_UNSUPPORTED 82 endif 83else 84 EIGEN := 0 85endif 86 87.PHONY: all 88all: $(XFILES) 89 90.PHONY: compile 91compile: $(OBJECTS) $(FTNOBJS) 92 93# no need to link against any of LIBXSMM's libraries since the sample code uses header-only LIBXSMM 94$(OUTDIR)/$(OUTNAME)_smm: $(OUTDIR)/.make $(BLDDIR)/$(OUTNAME)_smm-cpp.o $(DEPDIR)/include/libxsmm_source.h 95 $(LD) -o $@ $(BLDDIR)/$(OUTNAME)_smm-cpp.o $(SLDFLAGS) $(LDFLAGS) $(CLDFLAGS) 96 97# no need to link against any of LIBXSMM's libraries since the sample code uses header-only LIBXSMM 98$(OUTDIR)/$(OUTNAME)_tensor: $(OUTDIR)/.make $(BLDDIR)/$(OUTNAME)_tensor-cpp.o $(DEPDIR)/include/libxsmm_source.h 99 $(LD) -o $@ $(BLDDIR)/$(OUTNAME)_tensor-cpp.o $(SLDFLAGS) $(LDFLAGS) $(CLDFLAGS) 100 101$(BLDDIR)/%-cpp.o: $(SRCDIR)/%.cpp .state $(BLDDIR)/.make $(HEADERS) Makefile $(DEPDIR)/Makefile.inc 102 $(CXX) $(DFLAGS) $(IFLAGS) $(CXXFLAGS) $(CTARGET) -c $< -o $@ 103 104$(BLDDIR)/%-c.o: $(SRCDIR)/%.c .state $(BLDDIR)/.make $(HEADERS) Makefile $(DEPDIR)/Makefile.inc 105 $(CC) $(DFLAGS) $(IFLAGS) $(CFLAGS) $(CTARGET) -c $< -o $@ 106 107$(BLDDIR)/%-f.o: $(SRCDIR)/%.f .state $(BLDDIR)/.make Makefile $(DEPDIR)/Makefile.inc 108 $(FC) $(FCMTFLAGS) $(DFLAGS) $(IFLAGS) $(FCFLAGS) $(FTARGET) -c $< -o $@ 109 110$(BLDDIR)/%-f90.o: $(SRCDIR)/%.f90 .state $(BLDDIR)/.make Makefile $(DEPDIR)/Makefile.inc 111 $(FC) $(FCMTFLAGS) $(DFLAGS) $(IFLAGS) $(FCFLAGS) $(FTARGET) -c $< -o $@ 112 113$(BLDDIR)/%-f90.o: $(SRCDIR)/%.F90 .state $(BLDDIR)/.make Makefile $(DEPDIR)/Makefile.inc 114 $(FC) $(FCMTFLAGS) $(DFLAGS) $(IFLAGS) $(FCFLAGS) $(FTARGET) -c $< -o $@ 115 116$(BLDDIR)/%-f77.o: $(SRCDIR)/%.F .state $(BLDDIR)/.make Makefile $(DEPDIR)/Makefile.inc 117 $(FC) $(FCMTFLAGS) $(DFLAGS) $(IFLAGS) $(FCFLAGS) $(FTARGET) -c $< -o $@ 118 119.PHONY: clean 120clean: 121ifneq ($(call qapath,$(BLDDIR)),$(ROOTDIR)) 122ifneq ($(call qapath,$(BLDDIR)),$(call qapath,.)) 123 @rm -rf $(BLDDIR) 124endif 125endif 126ifneq (,$(wildcard $(BLDDIR))) # still exists 127 @rm -f $(OBJECTS) $(OBJECTX) $(FTNOBJS) $(FTNOBJX) *__genmod.* fit.log *.dat 128 @rm -f $(BLDDIR)/*.gcno $(BLDDIR)/*.gcda $(BLDDIR)/*.gcov 129endif 130 @rm -f .make .state 131 132.PHONY: realclean 133realclean: clean 134ifneq ($(call qapath,$(OUTDIR)),$(ROOTDIR)) 135ifneq ($(call qapath,$(OUTDIR)),$(call qapath,.)) 136 @rm -rf $(OUTDIR) 137endif 138endif 139ifneq (,$(wildcard $(OUTDIR))) # still exists 140 @rm -f $(OUTDIR)/libxsmm.$(DLIBEXT) $(OUTDIR)/*.stackdump 141 @rm -f $(XFILES) $(MODULES) 142endif 143 144