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 24pwd = $(patsubst %/,%,$(dir $(abspath $(firstword $(MAKEFILE_LIST))))) 25 26SANTIZ = -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer 27CFLAGS = -std=c99 -Wall -Wextra -Wno-unused-parameter -fPIC -MMD -MP -march=native 28CFLAGS += $(if $(NDEBUG),,)#$(SANTIZ)) 29CFLAGS += $(if $(NDEBUG),-O2,-g) 30LDFLAGS += $(if $(NDEBUG),,)#$(SANTIZ)) 31CPPFLAGS = -I. -I$(OCCA_DIR)/include 32LDLIBS = -lm 33LDLIBS += -L$(OCCA_DIR)/lib -locca -lrt -ldl 34OBJDIR := build 35LIBDIR := . 36NPROCS := $(shell getconf _NPROCESSORS_ONLN) 37MFLAGS := -j $(NPROCS) --warn-undefined-variables \ 38 --no-print-directory --quiet --no-keep-going 39 40PROVE ?= prove 41DARWIN := $(filter Darwin,$(shell uname -s)) 42SO_EXT := $(if $(DARWIN),dylib,so) 43 44libceed := $(LIBDIR)/libceed.$(SO_EXT) 45libceed.c := $(wildcard ceed*.c) 46tests.c := $(sort $(wildcard tests/t[0-9][0-9]-*.c)) 47tests := $(tests.c:tests/%.c=$(OBJDIR)/%) 48examples.c := $(sort $(wildcard examples/*.c)) 49examples := $(examples.c:examples/%.c=$(OBJDIR)/%) 50# backends/[ref & occa] 51ref.c := $(sort $(wildcard backends/ref/*.c)) 52ref := $(ref.c:backends/ref/%.c=$(OBJDIR)/%) 53occa.c := $(sort $(wildcard backends/occa/*.c)) 54occa := $(occa.c:backends/occa/%.c=$(OBJDIR)/%) 55 56# OUTPUT rules # 57COLOR_OFFSET = 3 58COLOR = $(shell echo $(rule_path)|cksum|cut -b1-2) 59rule_path = $(notdir $(patsubst %/,%,$(dir $<))) 60rule_file = $(basename $(notdir $@)) 61rule_dumb = @echo -e $(rule_path)/$(rule_file) 62rule_xterm = @echo -e \\e[38\;5\;$(shell echo $(COLOR)+$(COLOR_OFFSET)|bc -l)\;1m\ 63 $(rule_path)\\033[m/\\033[\m$(rule_file)\\033[m 64output = $(rule_${TERM}) 65 66.SUFFIXES: 67.SUFFIXES: .c .o .d 68.SECONDEXPANSION: # to expand $$(@D)/.DIR 69 70%/.DIR : 71 @mkdir -p $(@D) 72 @touch $@ 73 74.PRECIOUS: %/.DIR 75 76all dbg:;$(MAKE) $(MFLAGS) $(libceed) $(tests) 77opt:;NDEBUG=1 $(MAKE) $(MFLAGS) $(libceed) $(tests) 78 79$(libceed) : $(libceed.c:%.c=$(OBJDIR)/%.o) $(ref.c:%.c=$(OBJDIR)/%.o) $(occa.c:%.c=$(OBJDIR)/%.o);$(output) 80 $(CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS) 81 82$(OBJDIR)/%.o : $(pwd)/%.c | $$(@D)/.DIR;$(output) 83 $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $^ 84 85$(OBJDIR)/%.o : $(pwd)/backends/ref/%.c | $$(@D)/.DIR;$(output) 86 $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $^ 87 88$(OBJDIR)/%.o : $(pwd)/backends/occa/%.c | $$(@D)/.DIR;$(output) 89 $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $^ 90 91$(OBJDIR)/%.o : $(pwd)/tests/%.c | $$(@D)/.DIR;$(output) 92 $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -c -o $@ $^ $(LDLIBS) 93 94$(OBJDIR)/%.o : $(pwd)/examples/%.c | $$(@D)/.DIR;$(output) 95 $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $^ 96 97$(tests) $(examples) : $(libceed) 98$(tests) $(examples) : LDFLAGS += -Wl,-rpath,$(LIBDIR) -L$(LIBDIR) 99$(OBJDIR)/t% : tests/t%.c $(libceed) 100$(OBJDIR)/ex% : examples/ex%.c $(libceed) 101 102run-t% : $(OBJDIR)/t% 103 tests/tap.sh $(<:build/%=%) 104 105test : $(tests:$(OBJDIR)/t%=run-t%) 106tst:;@$(MAKE) $(MFLAGS) test 107 108prove : $(tests) 109 $(PROVE) -j $(NPROCS) --exec 'tests/tap.sh' $(tests:$(OBJDIR)/%=%) 110 111examples : $(examples) 112 113.PHONY: clean print test examples astyle 114cln clean : 115 $(RM) *.o $(OBJDIR)/*.o *.d $(OBJDIR)/*.d $(libceed) $(tests) 116 $(RM) -r *.dSYM $(OBJDIR)/backends 117 118### ASTYLE ### 119ASTYLE = astyle --options=.astylerc 120FORMAT_FILES = $(foreach dir,. tests examples occa,$(dir)/*.[ch]) 121style: 122 @if ! $(ASTYLE) $(FORMAT_FILES) | grep Formatted; then\ 123 echo "No source files were changed.";\ 124 fi 125 126print : 127 @echo $(VAR)=$($(VAR)) 128 129print-%: 130 $(info [ variable name]: $*) 131 $(info [ origin]: $(origin $*)) 132 $(info [ value]: $(value $*)) 133 $(info [expanded value]: $($*)) 134 $(info ) 135 @true 136 137-include $(libceed.c:%.c=%.d) $(tests.c:%.c=%.d) 138