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