1# Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors 2# All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3# 4# SPDX-License-Identifier: BSD-2-Clause 5# 6# This file is part of CEED: http://github.com/ceed 7 8COMMON ?= ../../common.mk 9-include $(COMMON) 10 11# Note: PETSC_ARCH can be undefined or empty for installations which do not use 12# PETSC_ARCH - for example when using PETSc installed through Spack. 13PETSc.pc := $(PETSC_DIR)/$(PETSC_ARCH)/lib/pkgconfig/PETSc.pc 14CEED_DIR ?= ../.. 15ceed.pc := $(CEED_DIR)/lib/pkgconfig/ceed.pc 16 17CC = $(call pkgconf, --variable=ccompiler $(PETSc.pc) $(ceed.pc)) 18CFLAGS = -std=c99 \ 19 $(call pkgconf, --variable=cflags_extra $(PETSc.pc)) \ 20 $(call pkgconf, --cflags-only-other $(PETSc.pc)) \ 21 $(OPT) 22CPPFLAGS = $(call pkgconf, --cflags-only-I $(PETSc.pc) $(ceed.pc)) \ 23 $(call pkgconf, --variable=cflags_dep $(PETSc.pc)) 24LDFLAGS = $(call pkgconf, --libs-only-L --libs-only-other $(PETSc.pc) $(ceed.pc)) 25LDFLAGS += $(patsubst -L%, $(call pkgconf, --variable=ldflag_rpath $(PETSc.pc))%, $(call pkgconf, --libs-only-L $(PETSc.pc) $(ceed.pc))) 26LDLIBS = $(call pkgconf, --libs-only-l $(PETSc.pc) $(ceed.pc)) -lm 27 28OBJDIR := build 29SRCDIR := src 30 31all: area bps bpsraw bpssphere dmswarm multigrid 32 33utils.c := $(sort $(wildcard $(SRCDIR)/*.c)) 34utils.o = $(utils.c:%.c=$(OBJDIR)/%.o) 35libutils.a: $(utils.o) 36 $(call quiet,AR) $(ARFLAGS) $@ $^ 37 38area.c := area.c 39area.o = $(area.c:%.c=$(OBJDIR)/%.o) 40area: $(area.o) libutils.a | $(PETSc.pc) $(ceed.pc) 41 $(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@ 42 43bps.c := bps.c 44bps.o = $(bps.c:%.c=$(OBJDIR)/%.o) 45bps: $(bps.o) libutils.a | $(PETSc.pc) $(ceed.pc) 46 $(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@ 47 48bpsraw.c := bpsraw.c 49bpsraw.o = $(bpsraw.c:%.c=$(OBJDIR)/%.o) 50bpsraw: $(bpsraw.o) libutils.a | $(PETSc.pc) $(ceed.pc) 51 $(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@ 52 53bpssphere.c := bpssphere.c 54bpssphere.o = $(bpssphere.c:%.c=$(OBJDIR)/%.o) 55bpssphere: $(bpssphere.o) libutils.a | $(PETSc.pc) $(ceed.pc) 56 $(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@ 57 58dmswarm.c := dmswarm.c 59dmswarm.o = $(dmswarm.c:%.c=$(OBJDIR)/%.o) 60dmswarm: $(dmswarm.o) libutils.a | $(PETSc.pc) $(ceed.pc) 61 $(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@ 62 63multigrid.c := multigrid.c 64multigrid.o = $(multigrid.c:%.c=$(OBJDIR)/%.o) 65multigrid: $(multigrid.o) libutils.a | $(PETSc.pc) $(ceed.pc) 66 $(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@ 67 68.SECONDEXPANSION: # to expand $$(@D)/.DIR 69%/.DIR : 70 @mkdir -p $(@D) 71 @touch $@ 72 73# Quiet, color output 74quiet ?= $($(1)) 75 76$(OBJDIR)/%.o : %.c | $$(@D)/.DIR 77 $(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<) 78 79# Rules for building the examples 80#%: %.c 81 82print: $(PETSc.pc) $(ceed.pc) 83 $(info CC : $(CC)) 84 $(info CFLAGS : $(CFLAGS)) 85 $(info CPPFLAGS: $(CPPFLAGS)) 86 $(info LDFLAGS : $(LDFLAGS)) 87 $(info LDLIBS : $(LDLIBS)) 88 @true 89 90clean: 91 $(RM) -r $(OBJDIR) *.vtu area bps bpsraw bpssphere dmswarm multigrid libutils.a 92 93$(PETSc.pc): 94 $(if $(wildcard $@),,$(error \ 95 PETSc config not found at $@. Please set PETSC_DIR and PETSC_ARCH)) 96 97.PHONY: all print clean 98 99pkgconf = $(shell pkg-config $1 | sed -e 's/^"//g' -e 's/"$$//g') 100 101-include $(src.o:%.o=%.d) 102