1ROOTDIR = $(abspath $(dir $(firstword $(MAKEFILE_LIST)))) 2DEPDIR = ../../.. 3SRCDIR = . 4INCDIR = . 5BLDDIR = obj 6OUTDIR = . 7 8CXXFLAGS = $(NULL) 9CFLAGS = $(NULL) 10DFLAGS = $(NULL) 11 12BLAS = 0 13OMP = 0 14SYM = 1 15 16# include common Makefile artifacts 17include $(DEPDIR)/Makefile.inc 18 19# necessary include directories 20IFLAGS += -I$(call quote,$(INCDIR)) 21IFLAGS += -I$(call quote,$(DEPDIR)/include) 22 23OUTNAME := $(shell basename "$(ROOTDIR)") 24HEADERS := $(wildcard $(INCDIR)/*.h) $(wildcard $(INCDIR)/*.hpp) $(wildcard $(INCDIR)/*.hxx) $(wildcard $(INCDIR)/*.hh) \ 25 $(wildcard $(SRCDIR)/*.h) $(wildcard $(SRCDIR)/*.hpp) $(wildcard $(SRCDIR)/*.hxx) $(wildcard $(SRCDIR)/*.hh) \ 26 $(DEPDIR)/include/libxsmm_source.h 27CPPSRCS := $(wildcard $(SRCDIR)/*.cpp) 28CXXSRCS := $(wildcard $(SRCDIR)/*.cxx) 29CCXSRCS := $(wildcard $(SRCDIR)/*.cc) 30CSOURCS := $(wildcard $(SRCDIR)/*.c) 31CPPOBJS := $(patsubst %,$(BLDDIR)/%,$(notdir $(CPPSRCS:.cpp=-cpp.o))) 32CXXOBJS := $(patsubst %,$(BLDDIR)/%,$(notdir $(CXXSRCS:.cxx=-cxx.o))) 33CCXOBJS := $(patsubst %,$(BLDDIR)/%,$(notdir $(CCXSRCS:.cc=-cc.o))) 34COBJCTS := $(patsubst %,$(BLDDIR)/%,$(notdir $(CSOURCS:.c=-c.o))) 35ifneq (,$(strip $(FC))) 36FXXSRCS := $(wildcard $(SRCDIR)/*.f) 37F77SRCS := $(wildcard $(SRCDIR)/*.F) 38F90SRCS := $(wildcard $(SRCDIR)/*.f90) $(wildcard $(SRCDIR)/*.F90) 39FXXOBJS := $(patsubst %,$(BLDDIR)/%,$(notdir $(FXXSRCS:.f=-f.o))) 40F77OBJS := $(patsubst %,$(BLDDIR)/%,$(notdir $(F77SRCS:.F=-f77.o))) 41F90OBJS := $(patsubst %,$(BLDDIR)/%,$(notdir $(F90SRCS:.f90=-f90.o))) 42F90OBJS := $(patsubst %,$(BLDDIR)/%,$(notdir $(F90OBJS:.F90=-f90.o))) 43endif 44SOURCES := $(CPPSRCS) $(CXXSRCS) $(CCXSRCS) $(CSOURCS) 45OBJECTS := $(CPPOBJS) $(CXXOBJS) $(CCXOBJS) $(COBJCTS) 46FTNSRCS := $(FXXSRCS) $(F77SRCS) $(F90SRCS) 47MODULES := $(addsuffix .mod,$(basename $(FTNSRCS))) $(addsuffix .modmic,$(basename $(FTNSRCS))) 48FTNOBJS := $(FXXOBJS) $(F77OBJS) $(F90OBJS) 49XFILES := $(OUTDIR)/$(OUTNAME) $(OUTDIR)/$(OUTNAME)f 50 51.PHONY: all 52all: $(XFILES) 53 54.PHONY: compile 55compile: $(OBJECTS) $(FTNOBJS) 56 57ifneq (,$(strip $(FC))) 58ifneq (0,$(shell echo "$$((3>$(GCC) || 40600<=$(FC_VERSION_NUM)))")) 59$(OUTDIR)/$(OUTNAME)f: $(OUTDIR)/.make $(FTNOBJS) $(FORTDEP) $(LIBDEP) $(EXTDEP) 60 $(FLD) -o $@ $(FTNOBJS) $(FORTLIB) $(EXTLIB) $(MAINLIB) $(FCMTFLAGS) $(SLDFLAGS) $(LDFLAGS) $(FLDFLAGS) $(ELDFLAGS) 61else 62.PHONY: $(OUTDIR)/$(OUTNAME)f 63endif 64else 65.PHONY: $(OUTDIR)/$(OUTNAME)f 66endif 67 68$(OUTDIR)/$(OUTNAME): $(OUTDIR)/.make $(OBJECTS) $(LIBDEP) 69 $(LD) -o $@ $(OBJECTS) $(MAINLIB) $(SLDFLAGS) $(LDFLAGS) $(CLDFLAGS) 70 71$(BLDDIR)/%-cpp.o: $(SRCDIR)/%.cpp .state $(BLDDIR)/.make $(HEADERS) Makefile $(DEPDIR)/Makefile.inc 72 $(CXX) $(DFLAGS) $(IFLAGS) $(CXXFLAGS) $(CTARGET) -c $< -o $@ 73 74$(BLDDIR)/%-c.o: $(SRCDIR)/%.c .state $(BLDDIR)/.make $(HEADERS) Makefile $(DEPDIR)/Makefile.inc 75 $(CC) $(DFLAGS) $(IFLAGS) $(CFLAGS) $(CTARGET) -c $< -o $@ 76 77$(BLDDIR)/%-f.o: $(SRCDIR)/%.f .state $(BLDDIR)/.make Makefile $(DEPDIR)/Makefile.inc 78 $(FC) $(FCMTFLAGS) $(DFLAGS) $(IFLAGS) $(FCFLAGS) $(FTARGET) -c $< -o $@ 79 80$(BLDDIR)/%-f90.o: $(SRCDIR)/%.f90 .state $(BLDDIR)/.make Makefile $(DEPDIR)/Makefile.inc 81 $(FC) $(FCMTFLAGS) $(DFLAGS) $(IFLAGS) $(FCFLAGS) $(FTARGET) -c $< -o $@ 82 83$(BLDDIR)/%-f90.o: $(SRCDIR)/%.F90 .state $(BLDDIR)/.make Makefile $(DEPDIR)/Makefile.inc 84 $(FC) $(FCMTFLAGS) $(DFLAGS) $(IFLAGS) $(FCFLAGS) $(FTARGET) -c $< -o $@ 85 86$(BLDDIR)/%-f77.o: $(SRCDIR)/%.F .state $(BLDDIR)/.make Makefile $(DEPDIR)/Makefile.inc 87 $(FC) $(FCMTFLAGS) $(DFLAGS) $(IFLAGS) $(FCFLAGS) $(FTARGET) -c $< -o $@ 88 89.PHONY: clean 90clean: 91ifneq ($(call qapath,$(BLDDIR)),$(ROOTDIR)) 92ifneq ($(call qapath,$(BLDDIR)),$(call qapath,.)) 93 @rm -rf $(BLDDIR) 94endif 95endif 96ifneq (,$(wildcard $(BLDDIR))) # still exists 97 @rm -f $(OBJECTS) $(OBJECTX) $(FTNOBJS) $(FTNOBJX) *__genmod.* fit.log *.dat 98 @rm -f $(BLDDIR)/*.gcno $(BLDDIR)/*.gcda $(BLDDIR)/*.gcov 99endif 100 @rm -f .make .state 101 102.PHONY: realclean 103realclean: clean 104ifneq ($(call qapath,$(OUTDIR)),$(ROOTDIR)) 105ifneq ($(call qapath,$(OUTDIR)),$(call qapath,.)) 106 @rm -rf $(OUTDIR) 107endif 108endif 109ifneq (,$(wildcard $(OUTDIR))) # still exists 110 @rm -f $(OUTDIR)/libxsmm.$(DLIBEXT) $(OUTDIR)/*.stackdump 111 @rm -f $(XFILES) $(MODULES) 112endif 113 114