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