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