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