1*3d8e8822SJeremy L Thompson# Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors 2*3d8e8822SJeremy L Thompson# All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3777ff853SJeremy L Thompson# 4*3d8e8822SJeremy L Thompson# SPDX-License-Identifier: BSD-2-Clause 5777ff853SJeremy L Thompson# 6*3d8e8822SJeremy L Thompson# This file is part of CEED: http://github.com/ceed 7777ff853SJeremy L Thompson 8777ff853SJeremy L ThompsonCOMMON ?= ../../common.mk 9777ff853SJeremy L Thompson-include $(COMMON) 10777ff853SJeremy L Thompson 112f4d9adbSJeremy L Thompson# Note: PETSC_ARCH can be undefined or empty for installations which do not use 122f4d9adbSJeremy L Thompson# PETSC_ARCH - for example when using PETSc installed through Spack. 139f8a8fa0SJed BrownPETSc.pc := $(PETSC_DIR)/$(PETSC_ARCH)/lib/pkgconfig/PETSc.pc 146ea7c6c1SJed BrownCEED_DIR ?= ../.. 156ea7c6c1SJed Brownceed.pc := $(CEED_DIR)/lib/pkgconfig/ceed.pc 169f8a8fa0SJed Brown 17c0c38e35SVeselin DobrevCC = $(call pkgconf, --variable=ccompiler $(PETSc.pc) $(ceed.pc)) 18e83e87a5SjeremyltCFLAGS = -std=c99 \ 19e83e87a5Sjeremylt $(call pkgconf, --variable=cflags_extra $(PETSc.pc)) \ 20e83e87a5Sjeremylt $(call pkgconf, --cflags-only-other $(PETSc.pc)) \ 21e83e87a5Sjeremylt $(OPT) 22e83e87a5SjeremyltCPPFLAGS = $(call pkgconf, --cflags-only-I $(PETSc.pc) $(ceed.pc)) \ 23e83e87a5Sjeremylt $(call pkgconf, --variable=cflags_dep $(PETSc.pc)) 24c0c38e35SVeselin DobrevLDFLAGS = $(call pkgconf, --libs-only-L --libs-only-other $(PETSc.pc) $(ceed.pc)) 25c0c38e35SVeselin DobrevLDFLAGS += $(patsubst -L%, $(call pkgconf, --variable=ldflag_rpath $(PETSc.pc))%, $(call pkgconf, --libs-only-L $(PETSc.pc) $(ceed.pc))) 26c0c38e35SVeselin DobrevLDLIBS = $(call pkgconf, --libs-only-l $(PETSc.pc) $(ceed.pc)) -lm 279f8a8fa0SJed Brown 28e83e87a5SjeremyltOBJDIR := build 29e83e87a5SjeremyltSRCDIR := src 30cb32e2e7SValeria Barra 311728c6a1Sjeremyltall: area bps bpsraw bpssphere multigrid 321728c6a1Sjeremylt 33e83e87a5Sjeremyltutils.c := $(sort $(wildcard $(SRCDIR)/*.c)) 34636cccdbSjeremyltutils.o = $(utils.c:%.c=$(OBJDIR)/%.o) 35386a09edSJed Brownlibutils.a: $(utils.o) 36386a09edSJed Brown $(call quiet,AR) $(ARFLAGS) $@ $^ 37dc7d240cSValeria Barra 38636cccdbSjeremyltarea.c := area.c 39e83e87a5Sjeremyltarea.o = $(area.c:%.c=$(OBJDIR)/%.o) 40386a09edSJed Brownarea: $(area.o) libutils.a | $(PETSc.pc) $(ceed.pc) 41e83e87a5Sjeremylt $(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@ 42ed264d09SValeria Barra 43636cccdbSjeremyltbps.c := bps.c 44e83e87a5Sjeremyltbps.o = $(bps.c:%.c=$(OBJDIR)/%.o) 45386a09edSJed Brownbps: $(bps.o) libutils.a | $(PETSc.pc) $(ceed.pc) 46e83e87a5Sjeremylt $(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@ 476c5df90dSjeremylt 48636cccdbSjeremyltbpsraw.c := bpsraw.c 49e83e87a5Sjeremyltbpsraw.o = $(bpsraw.c:%.c=$(OBJDIR)/%.o) 50386a09edSJed Brownbpsraw: $(bpsraw.o) libutils.a | $(PETSc.pc) $(ceed.pc) 51e83e87a5Sjeremylt $(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@ 52e83e87a5Sjeremylt 53636cccdbSjeremyltbpssphere.c := bpssphere.c 54e83e87a5Sjeremyltbpssphere.o = $(bpssphere.c:%.c=$(OBJDIR)/%.o) 55386a09edSJed Brownbpssphere: $(bpssphere.o) libutils.a | $(PETSc.pc) $(ceed.pc) 56e83e87a5Sjeremylt $(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@ 57e83e87a5Sjeremylt 58636cccdbSjeremyltmultigrid.c := multigrid.c 59e83e87a5Sjeremyltmultigrid.o = $(multigrid.c:%.c=$(OBJDIR)/%.o) 60386a09edSJed Brownmultigrid: $(multigrid.o) libutils.a | $(PETSc.pc) $(ceed.pc) 61e83e87a5Sjeremylt $(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@ 62e83e87a5Sjeremylt 63e83e87a5Sjeremylt.SECONDEXPANSION: # to expand $$(@D)/.DIR 64e83e87a5Sjeremylt%/.DIR : 65e83e87a5Sjeremylt @mkdir -p $(@D) 66e83e87a5Sjeremylt @touch $@ 679f8a8fa0SJed Brown 68777ff853SJeremy L Thompson# Quiet, color output 69777ff853SJeremy L Thompsonquiet ?= $($(1)) 70777ff853SJeremy L Thompson 71e83e87a5Sjeremylt$(OBJDIR)/%.o : %.c | $$(@D)/.DIR 72e83e87a5Sjeremylt $(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<) 73e83e87a5Sjeremylt 7433795f53Sjeremylt# Rules for building the examples 75e83e87a5Sjeremylt#%: %.c 7633795f53Sjeremylt 77c0c38e35SVeselin Dobrevprint: $(PETSc.pc) $(ceed.pc) 789f8a8fa0SJed Brown $(info CC : $(CC)) 799f8a8fa0SJed Brown $(info CFLAGS : $(CFLAGS)) 809f8a8fa0SJed Brown $(info CPPFLAGS: $(CPPFLAGS)) 819f8a8fa0SJed Brown $(info LDFLAGS : $(LDFLAGS)) 829f8a8fa0SJed Brown $(info LDLIBS : $(LDLIBS)) 83c0c38e35SVeselin Dobrev @true 849f8a8fa0SJed Brown 859f8a8fa0SJed Brownclean: 86386a09edSJed Brown $(RM) -r $(OBJDIR) *.vtu area bps bpsraw bpssphere multigrid libutils.a 879f8a8fa0SJed Brown 88c0c38e35SVeselin Dobrev$(PETSc.pc): 8908779805SVeselin Dobrev $(if $(wildcard $@),,$(error \ 906f87d196Sjeremylt PETSc config not found at $@. Please set PETSC_DIR and PETSC_ARCH)) 91c0c38e35SVeselin Dobrev 929f8a8fa0SJed Brown.PHONY: all print clean 93c0c38e35SVeselin Dobrev 94c0c38e35SVeselin Dobrevpkgconf = $(shell pkg-config $1 | sed -e 's/^"//g' -e 's/"$$//g') 95e83e87a5Sjeremylt 96e83e87a5Sjeremylt-include $(src.o:%.o=%.d) 97