1ROOTDIR = $(abspath $(dir $(firstword $(MAKEFILE_LIST))))
2DEPDIR = ../../..
3SRCDIR = .
4INCDIR = .
5BLDDIR = obj
6OUTDIR = .
7
8CXXFLAGS = $(NULL)
9CFLAGS = $(NULL)
10DFLAGS = $(NULL)
11
12BLAS = 0
13OMP = 1
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)/mlp_example_f32 $(OUTDIR)/mlp_example_bf16
50
51.PHONY: all
52all: $(XFILES)
53
54.PHONY: compile
55compile: $(OBJECTS) $(FTNOBJS)
56
57$(OUTDIR)/mlp_example_f32: $(OUTDIR)/.make $(BLDDIR)/mlp_example_f32-c.o $(LIBDEP) $(EXTDEP)
58	$(LD) -o $@ $(BLDDIR)/mlp_example_f32-c.o $(call cleanld,$(EXTLIB) $(MAINLIB) $(SLDFLAGS) $(LDFLAGS) $(CLDFLAGS))
59
60$(OUTDIR)/mlp_example_bf16: $(OUTDIR)/.make $(BLDDIR)/mlp_example_bf16-c.o $(LIBDEP) $(EXTDEP)
61	$(LD) -o $@ $(BLDDIR)/mlp_example_bf16-c.o $(call cleanld,$(EXTLIB) $(MAINLIB) $(SLDFLAGS) $(LDFLAGS) $(CLDFLAGS))
62
63$(BLDDIR)/%-cpp.o: $(SRCDIR)/%.cpp .state $(BLDDIR)/.make $(HEADERS) Makefile $(DEPDIR)/Makefile.inc
64	$(CXX) $(DFLAGS) $(IFLAGS) $(CXXFLAGS) $(CTARGET) -c $< -o $@
65
66$(BLDDIR)/%-c.o: $(SRCDIR)/%.c .state $(BLDDIR)/.make $(HEADERS) Makefile $(DEPDIR)/Makefile.inc
67	$(CC) $(DFLAGS) $(IFLAGS) $(CFLAGS) $(CTARGET) -c $< -o $@
68
69.PHONY: clean
70clean:
71ifneq ($(call qapath,$(BLDDIR)),$(ROOTDIR))
72ifneq ($(call qapath,$(BLDDIR)),$(call qapath,.))
73	@rm -rf $(BLDDIR)
74endif
75endif
76ifneq (,$(wildcard $(BLDDIR))) # still exists
77	@rm -f $(OBJECTS) $(OBJECTX) $(FTNOBJS) $(FTNOBJX) *__genmod.* fit.log *.dat
78	@rm -f $(BLDDIR)/*.gcno $(BLDDIR)/*.gcda $(BLDDIR)/*.gcov
79endif
80	@rm -f .make .state
81
82.PHONY: realclean
83realclean: clean
84ifneq ($(call qapath,$(OUTDIR)),$(ROOTDIR))
85ifneq ($(call qapath,$(OUTDIR)),$(call qapath,.))
86	@rm -rf $(OUTDIR)
87endif
88endif
89ifneq (,$(wildcard $(OUTDIR))) # still exists
90	@rm -f $(OUTDIR)/libxsmm.$(DLIBEXT) $(OUTDIR)/*.stackdump
91	@rm -f $(XFILES) $(MODULES)
92endif
93
94