10d9661cdSTzanio# Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at 20d9661cdSTzanio# the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights 30d9661cdSTzanio# reserved. See files LICENSE and NOTICE for details. 40d9661cdSTzanio# 50d9661cdSTzanio# This file is part of CEED, a collection of benchmarks, miniapps, software 60d9661cdSTzanio# libraries and APIs for efficient high-order finite element and spectral 70d9661cdSTzanio# element discretizations for exascale applications. For more information and 80d9661cdSTzanio# source code availability see http://github.com/ceed. 90d9661cdSTzanio# 100d9661cdSTzanio# The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, 110d9661cdSTzanio# a collaborative effort of two U.S. Department of Energy organizations (Office 120d9661cdSTzanio# of Science and the National Nuclear Security Administration) responsible for 130d9661cdSTzanio# the planning and preparation of a capable exascale ecosystem, including 140d9661cdSTzanio# software, applications, hardware, advanced system engineering and early 150d9661cdSTzanio# testbed platforms, in support of the nation's exascale computing imperative. 160d9661cdSTzanio 1781c9eb91SStan TomovCC ?= gcc 1881c9eb91SStan TomovFC = gfortran 19755585ceSStan TomovNVCC = nvcc 20e86995feScamierjs 21e86995feScamierjsNDEBUG ?= 22e86995feScamierjsLDFLAGS ?= 231b58aefaScamierjsLOADLIBES ?= 241b58aefaScamierjsTARGET_ARCH ?= 2532d74c32SThilina RathnayakeUNDERSCORE ?= 1 261b58aefaScamierjs 27*5a9ca9adSVeselin Dobrev# env variable OCCA_DIR can be used too (need OCCA v1.0) 287f5ff99bSVeselin DobrevOCCA_DIR ?= ../occa 29f797d7b2Scamierjs 30*5a9ca9adSVeselin Dobrev# env variable MAGMA_DIR can be used too 31*5a9ca9adSVeselin DobrevMAGMA_DIR ?= ../magma 32*5a9ca9adSVeselin Dobrev# If CUDA_DIR is not set, check for nvcc, or resort to /usr/local/cuda 33*5a9ca9adSVeselin DobrevCUDA_DIR ?= $(or $(patsubst %/,%,$(dir $(patsubst %/,%,$(dir \ 34*5a9ca9adSVeselin Dobrev $(shell which nvcc 2> /dev/null))))),/usr/local/cuda) 3582b77998SStan Tomov 36e86995feScamierjsSANTIZ = -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer 371b58aefaScamierjsCFLAGS = -std=c99 -Wall -Wextra -Wno-unused-parameter -fPIC -MMD -MP -march=native 38bcfdf5e6SJed BrownFFLAGS = -cpp -Wall -Wextra -Wno-unused-parameter -Wno-unused-dummy-argument -fPIC -MMD -MP -march=native 3932d74c32SThilina Rathnayake 404859b599SJed BrownCFLAGS += $(if $(NDEBUG),-O2,-g) 4132d74c32SThilina Rathnayakeifeq ($(UNDERSCORE), 1) 4232d74c32SThilina Rathnayake CFLAGS += -DUNDERSCORE 4332d74c32SThilina Rathnayakeendif 4432d74c32SThilina Rathnayake 4532d74c32SThilina RathnayakeFFLAGS += $(if $(NDEBUG),-O2,-g) 4632d74c32SThilina Rathnayake 4721ae6867ScamierjsCFLAGS += $(if $(NDEBUG),,)#$(SANTIZ)) 4832d74c32SThilina RathnayakeFFLAGS += $(if $(NDEBUG),,)#$(SANTIZ)) 491b58aefaScamierjsLDFLAGS += $(if $(NDEBUG),,)#$(SANTIZ)) 506ea7c6c1SJed BrownCPPFLAGS = -I./include 51582447c9SJed BrownLDLIBS = -lm 5291b7489eSJed BrownOBJDIR := build 536ea7c6c1SJed BrownLIBDIR := lib 546ea7c6c1SJed Brown 55d5217624SJed Brown# Installation variables 56d5217624SJed Brownprefix ?= /usr/local 57d5217624SJed Brownbindir = $(prefix)/bin 58d5217624SJed Brownlibdir = $(prefix)/lib 59d5217624SJed Brownincludedir = $(prefix)/include 60d5217624SJed Brownpkgconfigdir = $(libdir)/pkgconfig 61d5217624SJed BrownINSTALL = install 62d5217624SJed BrownINSTALL_PROGRAM = $(INSTALL) 63d5217624SJed BrownINSTALL_DATA = $(INSTALL) -m644 64d5217624SJed Brown 6569762e1fScamierjsNPROCS := $(shell getconf _NPROCESSORS_ONLN) 6682985883ScamierjsMFLAGS := -j $(NPROCS) --warn-undefined-variables \ 6721ae6867Scamierjs --no-print-directory --no-keep-going 6887e762eaSJed Brown 69bfa078e6SJed BrownPROVE ?= prove 703a1ec3cdSJed BrownPROVE_OPTS ?= -j $(NPROCS) 715c719ab0SJed BrownDARWIN := $(filter Darwin,$(shell uname -s)) 725c719ab0SJed BrownSO_EXT := $(if $(DARWIN),dylib,so) 739df38c42SVeselin Dobrev 746ea7c6c1SJed Brownceed.pc := $(LIBDIR)/pkgconfig/ceed.pc 7591b7489eSJed Brownlibceed := $(LIBDIR)/libceed.$(SO_EXT) 76bae89548SJed Brownlibceed.c := $(wildcard ceed*.c) 7732d74c32SThilina Rathnayake# tests 78746e9b11SJed Browntests.c := $(sort $(wildcard tests/t[0-9][0-9]-*.c)) 7932d74c32SThilina Rathnayaketests.f := $(sort $(wildcard tests/t[0-9][0-9]-*.f)) 8091b7489eSJed Browntests := $(tests.c:tests/%.c=$(OBJDIR)/%) 8132d74c32SThilina Rathnayaketests += $(tests.f:tests/%.f=$(OBJDIR)/%) 8232d74c32SThilina Rathnayake#examples 832c6ea02fSJed Brownexamples.c := $(sort $(wildcard examples/*.c)) 84673d494eSThilina Rathnayakeexamples.f := $(sort $(wildcard examples/*.f)) 8591b7489eSJed Brownexamples := $(examples.c:examples/%.c=$(OBJDIR)/%) 86673d494eSThilina Rathnayakeexamples += $(examples.f:examples/%.f=$(OBJDIR)/%) 8782b77998SStan Tomov# backends/[ref & occa & magma] 88ae3cba82Scamierjsref.c := $(sort $(wildcard backends/ref/*.c)) 89ae3cba82Scamierjsocca.c := $(sort $(wildcard backends/occa/*.c)) 90755585ceSStan Tomovmagma_preprocessor := python backends/magma/gccm.py 91c4acb06bSStan Tomovmagma_pre_src := $(filter-out %_tmp.c, $(wildcard backends/magma/ceed-*.c)) 92c4acb06bSStan Tomovmagma_dsrc := $(wildcard backends/magma/magma_d*.c) 93c4acb06bSStan Tomovmagma_tmp.c := $(magma_pre_src:%.c=%_tmp.c) 94c4acb06bSStan Tomovmagma_tmp.cu := $(magma_pre_src:%.c=%_cuda.cu) 95c4acb06bSStan Tomovmagma_allsrc.c := $(magma_dsrc) $(magma_tmp.c) 96c4acb06bSStan Tomovmagma_allsrc.cu:= $(magma_tmp.cu) 9782985883Scamierjs 989bdc3d68Scamierjs# Output using the 216-color rules mode 9918a724fcScamierjsrule_file = $(notdir $(1)) 10018a724fcScamierjsrule_path = $(patsubst %/,%,$(dir $(1))) 10118a724fcScamierjslast_path = $(notdir $(patsubst %/,%,$(dir $(1)))) 1023c5d0cdfSJed Brownansicolor = $(shell echo $(call last_path,$(1)) | cksum | cut -b1-2 | xargs -IS expr 2 \* S + 17) 103abb87f81Scamierjsemacs_out = @printf " %10s %s/%s\n" $(1) $(call rule_path,$(2)) $(call rule_file,$(2)) 104abb87f81Scamierjscolor_out = @if [ -t 1 ]; then \ 10518a724fcScamierjs printf " %10s \033[38;5;%d;1m%s\033[m/%s\n" \ 1063c5d0cdfSJed Brown $(1) $(call ansicolor,$(2)) \ 10718a724fcScamierjs $(call rule_path,$(2)) $(call rule_file,$(2)); else \ 10818a724fcScamierjs printf " %10s %s\n" $(1) $(2); fi 109f797d7b2Scamierjs# if TERM=dumb, use it, otherwise switch to the term one 110abb87f81Scamierjsoutput = $(if $(TERM:dumb=),$(call color_out,$1,$2),$(call emacs_out,$1,$2)) 11182985883Scamierjs 1129bdc3d68Scamierjs# if V is set to non-nil, turn the verbose mode 11318a724fcScamierjsquiet = $(if $(V),$($(1)),$(call output,$1,$@);$($(1))) 11421ae6867Scamierjs 1159df38c42SVeselin Dobrev.SUFFIXES: 1169df38c42SVeselin Dobrev.SUFFIXES: .c .o .d 11791b7489eSJed Brown.SECONDEXPANSION: # to expand $$(@D)/.DIR 1189df38c42SVeselin Dobrev 119c4acb06bSStan Tomov.SECONDARY: $(magma_tmp.c) $(magma_tmp.cu) 12014c1ded1SStan Tomov 12191b7489eSJed Brown%/.DIR : 12291b7489eSJed Brown @mkdir -p $(@D) 12391b7489eSJed Brown @touch $@ 12491b7489eSJed Brown 12591b7489eSJed Brown.PRECIOUS: %/.DIR 12691b7489eSJed Brown 1276ea7c6c1SJed Brownthis: $(libceed) $(ceed.pc) 1289bdc3d68Scamierjsall:;@$(MAKE) $(MFLAGS) V=$(V) this 1290e439e50SJed Brown 130cbc56ef6SVeselin Dobrev$(libceed) : LDFLAGS += $(if $(DARWIN), -install_name $(abspath $(libceed))) 13169762e1fScamierjs 13287174f08SJed Brownlibceed.c += $(ref.c) 1337f5ff99bSVeselin Dobrevifneq ($(wildcard $(OCCA_DIR)/lib/libocca.*),) 134fc377ca6SJed Brown $(libceed) : LDFLAGS += -L$(OCCA_DIR)/lib -Wl,-rpath,$(abspath $(OCCA_DIR)/lib) 1351a5c4436SJean-Sylvain Camier $(libceed) : LDLIBS += -locca #-lrt -ldl 13687174f08SJed Brown libceed.c += $(occa.c) 13787174f08SJed Brown $(occa.c:%.c=$(OBJDIR)/%.o) : CFLAGS += -I$(OCCA_DIR)/include 13821ae6867Scamierjsendif 13982b77998SStan Tomovifneq ($(wildcard $(MAGMA_DIR)/lib/libmagma.*),) 140*5a9ca9adSVeselin Dobrev CUDA_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(CUDA_DIR)/$d/libcudart.${SO_EXT})) 141*5a9ca9adSVeselin Dobrev CUDA_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(CUDA_LIB_DIR)))) 142*5a9ca9adSVeselin Dobrev ifneq ($(CUDA_LIB_DIR),) 143c4acb06bSStan Tomov magma_allsrc.o = $(magma_allsrc.c:%.c=$(OBJDIR)/%.o) $(magma_allsrc.cu:%.cu=$(OBJDIR)/%.o) 14482b77998SStan Tomov $(libceed) : LDFLAGS += -L$(MAGMA_DIR)/lib -Wl,-rpath,$(abspath $(MAGMA_DIR)/lib) 145c4acb06bSStan Tomov $(tests) $(examples) : LDFLAGS += -L$(MAGMA_DIR)/lib -Wl,-rpath,$(abspath $(MAGMA_DIR)/lib) 146*5a9ca9adSVeselin Dobrev $(libceed) : LDLIBS += -lmagma -L$(CUDA_LIB_DIR) -lcudart 147*5a9ca9adSVeselin Dobrev $(tests) $(examples) : LDLIBS += -lmagma -L$(CUDA_LIB_DIR) -lcudart 148c4acb06bSStan Tomov $(libceed) : $(magma_allsrc.o) 149c4acb06bSStan Tomov libceed.c += $(magma_allsrc.c) 150c4acb06bSStan Tomov libceed.cu += $(magma_allsrc.cu) 151c4acb06bSStan Tomov $(magma_allsrc.c:%.c=$(OBJDIR)/%.o) : CFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include 152c4acb06bSStan Tomov $(magma_allsrc.cu:%.cu=$(OBJDIR)/%.o) : NVCCFLAGS += --compiler-options=-fPIC -DADD_ -I$(MAGMA_DIR)/include -I$(MAGMA_DIR)/magmablas -I$(MAGMA_DIR)/control -I$(CUDA_DIR)/include 15382b77998SStan Tomov endif 154*5a9ca9adSVeselin Dobrevendif 155755585ceSStan Tomov 156755585ceSStan Tomov# generate magma_tmp.c and magma_cuda.cu from magma.c 157c4acb06bSStan Tomov$(magma_tmp.c) $(magma_tmp.cu): $(magma_pre_src) | $$(@D)/.DIR 158755585ceSStan Tomov $(magma_preprocessor) $< 159755585ceSStan Tomov 160755585ceSStan Tomov$(libceed) : $(libceed.c:%.c=$(OBJDIR)/%.o) $(libceed.cu:%.cu=$(OBJDIR)/%.o) | $$(@D)/.DIR 16121ae6867Scamierjs $(call quiet,CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS) 16291b7489eSJed Brown 163b5b03409SJed Brown$(OBJDIR)/%.o : %.c | $$(@D)/.DIR 164b5b03409SJed Brown $(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<) 165ae3cba82Scamierjs 166755585ceSStan Tomov$(OBJDIR)/%.o : %.cu | $$(@D)/.DIR 167755585ceSStan Tomov $(call quiet,NVCC) $(CPPFLAGS) $(NVCCFLAGS) -c -o $@ $(abspath $<) 168755585ceSStan Tomov 169b5b03409SJed Brown$(OBJDIR)/% : tests/%.c | $$(@D)/.DIR 170b5b03409SJed Brown $(call quiet,CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(abspath $<) -lceed $(LDLIBS) 17178b5556aScamierjs 17232d74c32SThilina Rathnayake$(OBJDIR)/% : tests/%.f | $$(@D)/.DIR 173a99eee77SThilina Rathnayake $(call quiet,FC) $(CPPFLAGS) $(FFLAGS) $(LDFLAGS) -o $@ $(abspath $<) -lceed $(LDLIBS) 17432d74c32SThilina Rathnayake 17534fd0bf9SThilina Rathnayake$(OBJDIR)/% : examples/%.c | $$(@D)/.DIR 17634fd0bf9SThilina Rathnayake $(call quiet,CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(abspath $<) -lceed $(LDLIBS) 17791b7489eSJed Brown 178673d494eSThilina Rathnayake$(OBJDIR)/% : examples/%.f | $$(@D)/.DIR 179a99eee77SThilina Rathnayake $(call quiet,FC) $(CPPFLAGS) $(FFLAGS) $(LDFLAGS) -o $@ $(abspath $<) -lceed $(LDLIBS) 180673d494eSThilina Rathnayake 1812c6ea02fSJed Brown$(tests) $(examples) : $(libceed) 182fc377ca6SJed Brown$(tests) $(examples) : LDFLAGS += -Wl,-rpath,$(abspath $(LIBDIR)) -L$(LIBDIR) 1834859b599SJed Brown 184dad465e7SJed Brownrun-% : $(OBJDIR)/% 185b5b03409SJed Brown @tests/tap.sh $(<:build/%=%) 1864859b599SJed Brown 187dad465e7SJed Browntest : $(tests:$(OBJDIR)/%=run-%) $(examples:$(OBJDIR)/%=run-%) 1884859b599SJed Brown 189dad465e7SJed Brownprove : $(tests) $(examples) 190dad465e7SJed Brown $(PROVE) $(PROVE_OPTS) --exec 'tests/tap.sh' $(tests:$(OBJDIR)/%=%) $(examples:$(OBJDIR)/%=%) 191bfa078e6SJed Brown 1922c6ea02fSJed Brownexamples : $(examples) 1932c6ea02fSJed Brown 1946ea7c6c1SJed Brown$(ceed.pc) : pkgconfig-prefix = $(abspath .) 195d5217624SJed Brown$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix) 196d5217624SJed Brown.INTERMEDIATE: $(OBJDIR)/ceed.pc 1976ea7c6c1SJed Brown%/ceed.pc : ceed.pc.template | $$(@D)/.DIR 1986ea7c6c1SJed Brown @sed "s:%prefix%:$(pkgconfig-prefix):" $< > $@ 1990e439e50SJed Brown 200d5217624SJed Browninstall : $(libceed) $(OBJDIR)/ceed.pc 2011e25a746SJed Brown $(INSTALL) -d "$(DESTDIR)$(includedir)" "$(DESTDIR)$(libdir)" "$(DESTDIR)$(pkgconfigdir)" 2021e25a746SJed Brown $(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/" 2031e25a746SJed Brown $(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/" 2041e25a746SJed Brown $(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/" 205d5217624SJed Brown 2067bd3a522STzanio.PHONY: all cln clean print test tst examples astyle install doc 2076e5d1fd9Scamierjscln clean : 2086ea7c6c1SJed Brown $(RM) *.o *.d $(libceed) 2096ea7c6c1SJed Brown $(RM) -r *.dSYM $(OBJDIR) $(LIBDIR)/pkgconfig 210e12c42aaSVeselin Dobrev $(MAKE) -C examples clean 211f3ea3031SVeselin Dobrev $(MAKE) -C examples/mfem clean 2121c615aafSThilina Rathnayake cd examples/nek5000; bash make-nek-examples.sh clean; cd ../..; 213c4acb06bSStan Tomov $(RM) $(magma_tmp.c) $(magma_tmp.cu) backends/magma/*~ backends/magma/*.o 2144859b599SJed Brown 21507838a1cSTzaniodistclean : clean 21607838a1cSTzanio rm -rf doc/html 21707838a1cSTzanio 2180ab95609SJed Browndoc : 2197bd3a522STzanio doxygen Doxyfile 2207bd3a522STzanio 2210dbfdfc5SJed Brownastyle : 2224e3516aeSJed Brown astyle --style=google --indent=spaces=2 --max-code-length=80 \ 2230dbfdfc5SJed Brown --keep-one-line-statements --keep-one-line-blocks --lineend=linux \ 224746e9b11SJed Brown --suffix=none --preserve-date --formatted \ 225ea474a52STzanio *.[ch] tests/*.[ch] backends/*/*.[ch] examples/*.[ch] examples/mfem/*.[ch]pp 2260dbfdfc5SJed Brown 2274859b599SJed Brownprint : 2284859b599SJed Brown @echo $(VAR)=$($(VAR)) 229582447c9SJed Brown 2309df38c42SVeselin Dobrevprint-%: 2319df38c42SVeselin Dobrev $(info [ variable name]: $*) 2329df38c42SVeselin Dobrev $(info [ origin]: $(origin $*)) 2339df38c42SVeselin Dobrev $(info [ value]: $(value $*)) 2349df38c42SVeselin Dobrev $(info [expanded value]: $($*)) 2359df38c42SVeselin Dobrev $(info ) 2369df38c42SVeselin Dobrev @true 2379df38c42SVeselin Dobrev 23843fb898aSJed Brown-include $(libceed.c:%.c=build/%.d) $(tests.c:tests/%.c=build/%.d) 239