1# Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at 2# the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights 3# 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 20NDEBUG ?= 21LDFLAGS ?= 22LOADLIBES ?= 23TARGET_ARCH ?= 24UNDERSCORE ?= 1 25 26# env variable OCCA_DIR should point to OCCA-1.0 branch 27OCCA_DIR ?= ../occa 28 29# env variable MAGMA_DIR should point to MAGMA branch 30MAGMA_DIR ?= ../../magma 31CUDA_DIR ?= /usr/local/cuda 32 33SANTIZ = -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer 34CFLAGS = -std=c99 -Wall -Wextra -Wno-unused-parameter -fPIC -MMD -MP -march=native 35FFLAGS = -cpp -Wall -Wextra -Wno-unused-parameter -Wno-unused-dummy-argument -fPIC -MMD -MP -march=native 36 37CFLAGS += $(if $(NDEBUG),-O2,-g) 38ifeq ($(UNDERSCORE), 1) 39 CFLAGS += -DUNDERSCORE 40endif 41 42FFLAGS += $(if $(NDEBUG),-O2,-g) 43 44CFLAGS += $(if $(NDEBUG),,)#$(SANTIZ)) 45FFLAGS += $(if $(NDEBUG),,)#$(SANTIZ)) 46LDFLAGS += $(if $(NDEBUG),,)#$(SANTIZ)) 47CPPFLAGS = -I./include 48LDLIBS = -lm 49OBJDIR := build 50LIBDIR := lib 51 52# Installation variables 53prefix ?= /usr/local 54bindir = $(prefix)/bin 55libdir = $(prefix)/lib 56includedir = $(prefix)/include 57pkgconfigdir = $(libdir)/pkgconfig 58INSTALL = install 59INSTALL_PROGRAM = $(INSTALL) 60INSTALL_DATA = $(INSTALL) -m644 61 62NPROCS := $(shell getconf _NPROCESSORS_ONLN) 63MFLAGS := -j $(NPROCS) --warn-undefined-variables \ 64 --no-print-directory --no-keep-going 65 66PROVE ?= prove 67PROVE_OPTS ?= -j $(NPROCS) 68DARWIN := $(filter Darwin,$(shell uname -s)) 69SO_EXT := $(if $(DARWIN),dylib,so) 70 71ceed.pc := $(LIBDIR)/pkgconfig/ceed.pc 72libceed := $(LIBDIR)/libceed.$(SO_EXT) 73libceed.c := $(wildcard ceed*.c) 74# tests 75tests.c := $(sort $(wildcard tests/t[0-9][0-9]-*.c)) 76tests.f := $(sort $(wildcard tests/t[0-9][0-9]-*.f)) 77tests := $(tests.c:tests/%.c=$(OBJDIR)/%) 78tests += $(tests.f:tests/%.f=$(OBJDIR)/%) 79#examples 80examples.c := $(sort $(wildcard examples/*.c)) 81examples.f := $(sort $(wildcard examples/*.f)) 82examples := $(examples.c:examples/%.c=$(OBJDIR)/%) 83examples += $(examples.f:examples/%.f=$(OBJDIR)/%) 84# backends/[ref & occa & magma] 85ref.c := $(sort $(wildcard backends/ref/*.c)) 86occa.c := $(sort $(wildcard backends/occa/*.c)) 87magma.c := $(sort $(wildcard backends/magma/*.c)) 88 89# Output using the 216-color rules mode 90rule_file = $(notdir $(1)) 91rule_path = $(patsubst %/,%,$(dir $(1))) 92last_path = $(notdir $(patsubst %/,%,$(dir $(1)))) 93ansicolor = $(shell echo $(call last_path,$(1)) | cksum | cut -b1-2 | xargs -IS expr 2 \* S + 17) 94emacs_out = @printf " %10s %s/%s\n" $(1) $(call rule_path,$(2)) $(call rule_file,$(2)) 95color_out = @if [ -t 1 ]; then \ 96 printf " %10s \033[38;5;%d;1m%s\033[m/%s\n" \ 97 $(1) $(call ansicolor,$(2)) \ 98 $(call rule_path,$(2)) $(call rule_file,$(2)); else \ 99 printf " %10s %s\n" $(1) $(2); fi 100# if TERM=dumb, use it, otherwise switch to the term one 101output = $(if $(TERM:dumb=),$(call color_out,$1,$2),$(call emacs_out,$1,$2)) 102 103# if V is set to non-nil, turn the verbose mode 104quiet = $(if $(V),$($(1)),$(call output,$1,$@);$($(1))) 105 106.SUFFIXES: 107.SUFFIXES: .c .o .d 108.SECONDEXPANSION: # to expand $$(@D)/.DIR 109 110%/.DIR : 111 @mkdir -p $(@D) 112 @touch $@ 113 114.PRECIOUS: %/.DIR 115 116this: $(libceed) $(ceed.pc) 117all:;@$(MAKE) $(MFLAGS) V=$(V) this 118 119$(libceed) : LDFLAGS += $(if $(DARWIN), -install_name $(abspath $(libceed))) 120 121libceed.c += $(ref.c) 122ifneq ($(wildcard $(OCCA_DIR)/lib/libocca.*),) 123 $(libceed) : LDFLAGS += -L$(OCCA_DIR)/lib -Wl,-rpath,$(abspath $(OCCA_DIR)/lib) 124 $(libceed) : LDLIBS += -locca #-lrt -ldl 125 libceed.c += $(occa.c) 126 $(occa.c:%.c=$(OBJDIR)/%.o) : CFLAGS += -I$(OCCA_DIR)/include 127endif 128ifneq ($(wildcard $(MAGMA_DIR)/lib/libmagma.*),) 129 $(libceed) : LDFLAGS += -L$(MAGMA_DIR)/lib -Wl,-rpath,$(abspath $(MAGMA_DIR)/lib) 130 $(libceed) : LDLIBS += -lmagma 131 $(libceed) : $(magma.o) 132 libceed.c += $(magma.c) 133 $(magma.c:%.c=$(OBJDIR)/%.o) : CFLAGS += -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include 134endif 135$(libceed) : $(libceed.c:%.c=$(OBJDIR)/%.o) | $$(@D)/.DIR 136 $(call quiet,CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS) 137 138$(OBJDIR)/%.o : %.c | $$(@D)/.DIR 139 $(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<) 140 141$(OBJDIR)/% : tests/%.c | $$(@D)/.DIR 142 $(call quiet,CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(abspath $<) -lceed $(LDLIBS) 143 144$(OBJDIR)/% : tests/%.f | $$(@D)/.DIR 145 $(call quiet,FC) $(CPPFLAGS) $(FFLAGS) $(LDFLAGS) -o $@ $(abspath $<) -lceed $(LDLIBS) 146 147$(OBJDIR)/% : examples/%.c | $$(@D)/.DIR 148 $(call quiet,CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(abspath $<) -lceed $(LDLIBS) 149 150$(OBJDIR)/% : examples/%.f | $$(@D)/.DIR 151 $(call quiet,FC) $(CPPFLAGS) $(FFLAGS) $(LDFLAGS) -o $@ $(abspath $<) -lceed $(LDLIBS) 152 153$(tests) $(examples) : $(libceed) 154$(tests) $(examples) : LDFLAGS += -Wl,-rpath,$(abspath $(LIBDIR)) -L$(LIBDIR) 155 156run-% : $(OBJDIR)/% 157 @tests/tap.sh $(<:build/%=%) 158 159test : $(tests:$(OBJDIR)/%=run-%) $(examples:$(OBJDIR)/%=run-%) 160 161prove : $(tests) $(examples) 162 $(PROVE) $(PROVE_OPTS) --exec 'tests/tap.sh' $(tests:$(OBJDIR)/%=%) $(examples:$(OBJDIR)/%=%) 163 164examples : $(examples) 165 166$(ceed.pc) : pkgconfig-prefix = $(abspath .) 167$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix) 168.INTERMEDIATE: $(OBJDIR)/ceed.pc 169%/ceed.pc : ceed.pc.template | $$(@D)/.DIR 170 @sed "s:%prefix%:$(pkgconfig-prefix):" $< > $@ 171 172install : $(libceed) $(OBJDIR)/ceed.pc 173 $(INSTALL) -d "$(DESTDIR)$(includedir)" "$(DESTDIR)$(libdir)" "$(DESTDIR)$(pkgconfigdir)" 174 $(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/" 175 $(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/" 176 $(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/" 177 178.PHONY: all cln clean print test tst examples astyle install doc 179cln clean : 180 $(RM) *.o *.d $(libceed) 181 $(RM) -r *.dSYM $(OBJDIR) $(LIBDIR)/pkgconfig 182 $(MAKE) -C examples clean 183 $(MAKE) -C examples/mfem clean 184 cd examples/nek5000; bash make-nek-examples.sh clean; cd ../..; 185 186distclean : clean 187 rm -rf doc/html 188 189doc : 190 doxygen Doxyfile 191 192astyle : 193 astyle --style=google --indent=spaces=2 --max-code-length=80 \ 194 --keep-one-line-statements --keep-one-line-blocks --lineend=linux \ 195 --suffix=none --preserve-date --formatted \ 196 *.[ch] tests/*.[ch] backends/*/*.[ch] examples/*.[ch] examples/mfem/*.[ch]pp 197 198print : 199 @echo $(VAR)=$($(VAR)) 200 201print-%: 202 $(info [ variable name]: $*) 203 $(info [ origin]: $(origin $*)) 204 $(info [ value]: $(value $*)) 205 $(info [expanded value]: $($*)) 206 $(info ) 207 @true 208 209-include $(libceed.c:%.c=build/%.d) $(tests.c:tests/%.c=build/%.d) 210