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