1# Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC. 2# Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707. 3# All Rights reserved. See files LICENSE and NOTICE for details. 4# 5# This file is part of CEED, a collection of benchmarks, miniapps, software 6# libraries and APIs for efficient high-order finite element and spectral 7# element discretizations for exascale applications. For more information and 8# source code availability see http://github.com/ceed. 9# 10# The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, 11# a collaborative effort of two U.S. Department of Energy organizations (Office 12# of Science and the National Nuclear Security Administration) responsible for 13# the planning and preparation of a capable exascale ecosystem, including 14# software, applications, hardware, advanced system engineering and early 15# testbed platforms, in support of the nation's exascale computing imperative. 16 17CC ?= gcc 18FC ?= gfortran 19 20# ASAN must be left empty if you don't want to use it 21ASAN ?= 22NDEBUG ?= 1 23 24LDFLAGS ?= 25UNDERSCORE ?= 1 26 27# OCCA_DIR env variable should point to OCCA master (github.com/libocca/occa) 28OCCA_DIR ?= ../occa 29 30# Warning: SANTIZ options still don't run with /gpu/occa 31# export LSAN_OPTIONS=suppressions=.asanignore 32AFLAGS = -fsanitize=address #-fsanitize=undefined -fno-omit-frame-pointer 33 34CFLAGS = -std=c99 -Wall -Wextra -Wno-unused-parameter -fPIC -MMD -MP -O2 -g 35FFLAGS = -cpp -Wall -Wextra -Wno-unused-parameter -Wno-unused-dummy-argument -fPIC -MMD -MP 36 37CFLAGS += $(if $(NDEBUG),-DNDEBUG=1) 38 39ifeq ($(UNDERSCORE), 1) 40 CFLAGS += -DUNDERSCORE 41endif 42 43FFLAGS += $(if $(NDEBUG),-O2 -DNDEBUG,-g) 44 45CFLAGS += $(if $(ASAN),$(AFLAGS)) 46FFLAGS += $(if $(ASAN),$(AFLAGS)) 47LDFLAGS += $(if $(ASAN),$(AFLAGS)) 48CPPFLAGS = -I./include 49LDLIBS = -lm 50OBJDIR := build 51LIBDIR := lib 52 53# Installation variables 54prefix ?= /usr/local 55bindir = $(prefix)/bin 56libdir = $(prefix)/lib 57okldir = $(prefix)/lib/okl 58includedir = $(prefix)/include 59pkgconfigdir = $(libdir)/pkgconfig 60INSTALL = install 61INSTALL_PROGRAM = $(INSTALL) 62INSTALL_DATA = $(INSTALL) -m644 63 64# Get number of processors of the machine 65NPROCS := $(shell getconf _NPROCESSORS_ONLN) 66# prepare make options to run in parallel 67MFLAGS := -j $(NPROCS) --warn-undefined-variables \ 68 --no-print-directory --no-keep-going 69 70PROVE ?= prove 71PROVE_OPTS ?= -j $(NPROCS) 72DARWIN := $(filter Darwin,$(shell uname -s)) 73SO_EXT := $(if $(DARWIN),dylib,so) 74 75ceed.pc := $(LIBDIR)/pkgconfig/ceed.pc 76libceed := $(LIBDIR)/libceed.$(SO_EXT) 77libceed.c := $(wildcard ceed*.c) 78 79# Tests 80tests.c := $(sort $(wildcard tests/t[0-9][0-9]-*.c)) 81tests.f := $(sort $(wildcard tests/t[0-9][0-9]-*.f)) 82tests := $(tests.c:tests/%.c=$(OBJDIR)/%) 83ctests := $(tests) 84tests += $(tests.f:tests/%.f=$(OBJDIR)/%) 85#examples 86examples.c := $(sort $(wildcard examples/*.c)) 87examples.f := $(sort $(wildcard examples/*.f)) 88examples := $(examples.c:examples/%.c=$(OBJDIR)/%) 89examples += $(examples.f:examples/%.f=$(OBJDIR)/%) 90# backends/[ref & occa] 91ref.c := $(sort $(wildcard backends/ref/*.c)) 92occa.c := $(sort $(wildcard backends/occa/*.c)) 93 94# Output using the 216-color rules mode 95rule_file = $(notdir $(1)) 96rule_path = $(patsubst %/,%,$(dir $(1))) 97last_path = $(notdir $(patsubst %/,%,$(dir $(1)))) 98ansicolor = $(shell echo $(call last_path,$(1)) | cksum | cut -b1-2 | xargs -IS expr 2 \* S + 17) 99emacs_out = @printf " %10s %s/%s\n" $(1) $(call rule_path,$(2)) $(call rule_file,$(2)) 100color_out = @if [ -t 1 ]; then \ 101 printf " %10s \033[38;5;%d;1m%s\033[m/%s\n" \ 102 $(1) $(call ansicolor,$(2)) \ 103 $(call rule_path,$(2)) $(call rule_file,$(2)); else \ 104 printf " %10s %s\n" $(1) $(2); fi 105# if TERM=dumb, use it, otherwise switch to the term one 106output = $(if $(TERM:dumb=),$(call color_out,$1,$2),$(call emacs_out,$1,$2)) 107 108# if V is set to non-nil, turn the verbose mode 109quiet = $(if $(V),$($(1)),$(call output,$1,$@);$($(1))) 110 111.SUFFIXES: 112.SUFFIXES: .c .o .d 113.SECONDEXPANSION: # to expand $$(@D)/.DIR 114 115%/.DIR : 116 @mkdir -p $(@D) 117 @touch $@ 118 119.PRECIOUS: %/.DIR 120 121this: $(libceed) $(ceed.pc) 122# run 'this' target in parallel 123all:;@$(MAKE) $(MFLAGS) V=$(V) this 124 125$(libceed) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed))) 126 127libceed.c += $(ref.c) 128ifneq ($(wildcard $(OCCA_DIR)/lib/libocca.*),) 129 $(libceed) : LDFLAGS += -L$(OCCA_DIR)/lib -Wl,-rpath,$(abspath $(OCCA_DIR)/lib) 130 $(libceed) : LDLIBS += -locca 131 libceed.c += $(occa.c) 132 $(occa.c:%.c=$(OBJDIR)/%.o) : CFLAGS += -I$(OCCA_DIR)/include 133endif 134$(libceed) : $(libceed.c:%.c=$(OBJDIR)/%.o) | $$(@D)/.DIR 135 $(call quiet,CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS) 136 137$(OBJDIR)/%.o : %.c | $$(@D)/.DIR 138 $(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<) 139 140$(OBJDIR)/% : tests/%.c | $$(@D)/.DIR 141 $(call quiet,CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(abspath $<) -lceed $(LDLIBS) 142 143$(OBJDIR)/% : tests/%.f | $$(@D)/.DIR 144 $(call quiet,FC) $(CPPFLAGS) $(FFLAGS) $(LDFLAGS) -o $@ $(abspath $<) -lceed $(LDLIBS) 145 146$(OBJDIR)/% : examples/%.c | $$(@D)/.DIR 147 $(call quiet,CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(abspath $<) -lceed $(LDLIBS) 148 149$(OBJDIR)/% : examples/%.f | $$(@D)/.DIR 150 $(call quiet,FC) $(CPPFLAGS) $(FFLAGS) $(LDFLAGS) -o $@ $(abspath $<) -lceed $(LDLIBS) 151 152$(tests) $(examples) : $(libceed) 153$(tests) $(examples) : LDFLAGS += -Wl,-rpath,$(abspath $(LIBDIR)) -L$(LIBDIR) 154 155run-% : $(OBJDIR)/% 156 @tests/tap.sh $(<:build/%=%) 157 158test : $(tests:$(OBJDIR)/%=run-%) $(examples:$(OBJDIR)/%=run-%) 159# run test target in parallel 160tst : ;@$(MAKE) $(MFLAGS) V=$(V) test 161# CPU C tests only for backend % 162ctc-% : $(ctests);@$(foreach tst,$(ctests),$(tst) /cpu/$*;) 163 164prove : $(tests) $(examples) 165 $(PROVE) $(PROVE_OPTS) --exec 'tests/tap.sh' $(tests:$(OBJDIR)/%=%) $(examples:$(OBJDIR)/%=%) 166# run prove target in parallel 167prv : ;@$(MAKE) $(MFLAGS) V=$(V) prove 168 169examples : $(examples) 170 171$(ceed.pc) : pkgconfig-prefix = $(abspath .) 172$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix) 173.INTERMEDIATE : $(OBJDIR)/ceed.pc 174%/ceed.pc : ceed.pc.template | $$(@D)/.DIR 175 @sed "s:%prefix%:$(pkgconfig-prefix):" $< > $@ 176 177# The occa executable is not linked with RPATH by default, so we need it to find its libocca.so 178OCCA := $(if $(DARWIN),DYLD_LIBRARY_PATH,LD_LIBRARY_PATH)=$(OCCA_DIR)/lib $(OCCA_DIR)/bin/occa 179OKL_KERNELS := $(wildcard backends/occa/*.okl) 180 181okl-cache : 182 $(OCCA) cache ceed $(OKL_KERNELS) 183 184okl-clear: 185 $(OCCA) clear -y -l ceed 186 187install : $(libceed) $(OBJDIR)/ceed.pc 188 $(INSTALL) -d "$(DESTDIR)$(includedir)" "$(DESTDIR)$(libdir)" "$(DESTDIR)$(okldir)" "$(DESTDIR)$(pkgconfigdir)" 189 $(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/" 190 $(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/" 191 $(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/" 192 $(INSTALL_DATA) $(OKL_KERNELS) "$(DESTDIR)$(okldir)/" 193 194.PHONY : all cln clean print test tst prove prv examples style install doc okl-cache okl-clear 195 196cln clean : 197 $(RM) *.o *.d $(libceed) 198 $(RM) -r *.dSYM $(OBJDIR) $(LIBDIR)/pkgconfig 199 $(MAKE) -C examples clean 200 $(MAKE) -C examples/mfem clean 201 (cd examples/nek5000 && bash make-nek-examples.sh clean) 202 203distclean : clean 204 rm -rf doc/html 205 206doc : 207 doxygen Doxyfile 208 209style : 210 astyle --style=google --indent=spaces=2 --max-code-length=80 \ 211 --keep-one-line-statements --keep-one-line-blocks --lineend=linux \ 212 --suffix=none --preserve-date --formatted \ 213 *.[ch] tests/*.[ch] backends/*/*.[ch] examples/*.[ch] examples/mfem/*.[ch]pp 214 215print : 216 @echo $(VAR)=$($(VAR)) 217 218print-% : 219 $(info [ variable name]: $*) 220 $(info [ origin]: $(origin $*)) 221 $(info [ value]: $(value $*)) 222 $(info [expanded value]: $($*)) 223 $(info ) 224 @true 225 226-include $(libceed.c:%.c=build/%.d) $(tests.c:tests/%.c=build/%.d) 227