1ccaff030SJeremy L Thompson# Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC. 2ccaff030SJeremy L Thompson# Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707. 3ccaff030SJeremy L Thompson# All Rights reserved. See files LICENSE and NOTICE for details. 4ccaff030SJeremy L Thompson# 5ccaff030SJeremy L Thompson# This file is part of CEED, a collection of benchmarks, miniapps, software 6ccaff030SJeremy L Thompson# libraries and APIs for efficient high-order finite element and spectral 7ccaff030SJeremy L Thompson# element discretizations for exascale applications. For more information and 8ccaff030SJeremy L Thompson# source code availability see http://github.com/ceed. 9ccaff030SJeremy L Thompson# 10ccaff030SJeremy L Thompson# The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, 11ccaff030SJeremy L Thompson# a collaborative effort of two U.S. Department of Energy organizations (Office 12ccaff030SJeremy L Thompson# of Science and the National Nuclear Security Administration) responsible for 13ccaff030SJeremy L Thompson# the planning and preparation of a capable exascale ecosystem, including 14ccaff030SJeremy L Thompson# software, applications, hardware, advanced system engineering and early 15ccaff030SJeremy L Thompson# testbed platforms, in support of the nation's exascale computing imperative. 16ccaff030SJeremy L Thompson 17ccaff030SJeremy L Thompson# Note: PETSC_ARCH can be undefined or empty for installations which do not use 18ccaff030SJeremy L Thompson# PETSC_ARCH - for example when using PETSc installed through Spack. 19ccaff030SJeremy L ThompsonPETSc.pc := $(PETSC_DIR)/$(PETSC_ARCH)/lib/pkgconfig/PETSc.pc 20ccaff030SJeremy L ThompsonCEED_DIR ?= ../.. 21ccaff030SJeremy L Thompsonceed.pc := $(CEED_DIR)/lib/pkgconfig/ceed.pc 22ccaff030SJeremy L Thompson 23ccaff030SJeremy L ThompsonCC = $(call pkgconf, --variable=ccompiler $(PETSc.pc) $(ceed.pc)) 24ccaff030SJeremy L ThompsonCFLAGS = -std=c99 \ 25ccaff030SJeremy L Thompson $(call pkgconf, --variable=cflags_extra $(PETSc.pc)) \ 26ccaff030SJeremy L Thompson $(call pkgconf, --cflags-only-other $(PETSc.pc)) \ 27*28b8c626SJed Brown $(OPT) 28*28b8c626SJed BrownCPPFLAGS = $(call pkgconf, --cflags-only-I $(PETSc.pc) $(ceed.pc)) \ 29*28b8c626SJed Brown $(call pkgconf, --variable=cflags_dep $(PETSc.pc)) 30ccaff030SJeremy L ThompsonLDFLAGS = $(call pkgconf, --libs-only-L --libs-only-other $(PETSc.pc) $(ceed.pc)) 31ccaff030SJeremy L ThompsonLDFLAGS += $(patsubst -L%, $(call pkgconf, --variable=ldflag_rpath $(PETSc.pc))%, $(call pkgconf, --libs-only-L $(PETSc.pc) $(ceed.pc))) 32ccaff030SJeremy L ThompsonLDLIBS = $(call pkgconf, --libs-only-l $(PETSc.pc) $(ceed.pc)) -lm 33ccaff030SJeremy L Thompson 34ccaff030SJeremy L ThompsonOBJDIR := build 35ccaff030SJeremy L ThompsonSRCDIR := src 36ccaff030SJeremy L Thompson 37ccaff030SJeremy L Thompsonsrc.c := elasticity.c $(sort $(wildcard $(SRCDIR)/*.c)) 38ccaff030SJeremy L Thompsonsrc.o = $(src.c:%.c=$(OBJDIR)/%.o) 39ccaff030SJeremy L Thompson 40ccaff030SJeremy L Thompsonall: elasticity 41ccaff030SJeremy L Thompson 42ccaff030SJeremy L Thompsonelasticity: $(src.o) | $(PETSc.pc) $(ceed.pc) 43*28b8c626SJed Brown $(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@ 44ccaff030SJeremy L Thompson 45ccaff030SJeremy L Thompson.SECONDEXPANSION: # to expand $$(@D)/.DIR 46ccaff030SJeremy L Thompson%/.DIR : 47ccaff030SJeremy L Thompson @mkdir -p $(@D) 48ccaff030SJeremy L Thompson @touch $@ 49ccaff030SJeremy L Thompson 50ccaff030SJeremy L Thompson# Output using the 216-color rules mode 51ccaff030SJeremy L Thompsonrule_file = $(notdir $(1)) 52ccaff030SJeremy L Thompsonrule_path = $(patsubst %/,%,$(dir $(1))) 53ccaff030SJeremy L Thompsonlast_path = $(notdir $(patsubst %/,%,$(dir $(1)))) 54ccaff030SJeremy L Thompsonansicolor = $(shell echo $(call last_path,$(1)) | cksum | cut -b1-2 | xargs -IS expr 2 \* S + 17) 55ccaff030SJeremy L Thompsonemacs_out = @printf " %10s %s/%s\n" $(1) $(call rule_path,$(2)) $(call rule_file,$(2)) 56ccaff030SJeremy L Thompsoncolor_out = @if [ -t 1 ]; then \ 57ccaff030SJeremy L Thompson printf " %10s \033[38;5;%d;1m%s\033[m/%s\n" \ 58ccaff030SJeremy L Thompson $(1) $(call ansicolor,$(2)) \ 59ccaff030SJeremy L Thompson $(call rule_path,$(2)) $(call rule_file,$(2)); else \ 60ccaff030SJeremy L Thompson printf " %10s %s\n" $(1) $(2); fi 61ccaff030SJeremy L Thompson# if TERM=dumb, use it, otherwise switch to the term one 62ccaff030SJeremy L Thompsonoutput = $(if $(TERM:dumb=),$(call color_out,$1,$2),$(call emacs_out,$1,$2)) 63ccaff030SJeremy L Thompson 64ccaff030SJeremy L Thompson# if V is set to non-nil, turn the verbose mode 65ccaff030SJeremy L Thompsonquiet = $(if $(V),$($(1)),$(call output,$1,$@);$($(1))) 66ccaff030SJeremy L Thompson 67ccaff030SJeremy L Thompson$(OBJDIR)/%.o : %.c | $$(@D)/.DIR 68ccaff030SJeremy L Thompson $(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<) 69ccaff030SJeremy L Thompson 70ccaff030SJeremy L Thompson# Rules for building the examples 71ccaff030SJeremy L Thompson#%: %.c 72ccaff030SJeremy L Thompson 73ccaff030SJeremy L Thompsonprint: $(PETSc.pc) $(ceed.pc) 74ccaff030SJeremy L Thompson $(info CC : $(CC)) 75ccaff030SJeremy L Thompson $(info CFLAGS : $(CFLAGS)) 76ccaff030SJeremy L Thompson $(info CPPFLAGS: $(CPPFLAGS)) 77ccaff030SJeremy L Thompson $(info LDFLAGS : $(LDFLAGS)) 78ccaff030SJeremy L Thompson $(info LDLIBS : $(LDLIBS)) 79ccaff030SJeremy L Thompson @true 80ccaff030SJeremy L Thompson 81ccaff030SJeremy L Thompsonclean: 82ccaff030SJeremy L Thompson $(RM) -r $(OBJDIR) elasticity 83ccaff030SJeremy L Thompson 84ccaff030SJeremy L Thompson$(PETSc.pc): 85ccaff030SJeremy L Thompson $(if $(wildcard $@),,$(error \ 86ccaff030SJeremy L Thompson PETSc config not found at $@. Please set PETSC_DIR and PETSC_ARCH)) 87ccaff030SJeremy L Thompson 88ccaff030SJeremy L Thompson.PHONY: all print clean 89ccaff030SJeremy L Thompson 90ccaff030SJeremy L Thompsonpkgconf = $(shell pkg-config $1 | sed -e 's/^"//g' -e 's/"$$//g') 91ccaff030SJeremy L Thompson 92ccaff030SJeremy L Thompson-include $(src.o:%.o=%.d) 93