1# Note: PETSC_ARCH can be undefined or empty for installations which do not use 2# PETSC_ARCH - for example when using PETSc installed through Spack. 3PETSc.pc := $(PETSC_DIR)/$(PETSC_ARCH)/lib/pkgconfig/PETSc.pc 4CEED_DIR ?= ../.. 5ceed.pc := $(CEED_DIR)/lib/pkgconfig/ceed.pc 6 7CC = $(call pkgconf, --variable=ccompiler $(PETSc.pc) $(ceed.pc)) 8CFLAGS = -std=c99 $(call pkgconf, --variable=cflags_extra $(PETSc.pc)) $(call pkgconf, --cflags-only-other $(PETSc.pc)) $(OPT) -D__DIR__=\"$(dir $(abspath $(lastword $<)))\" 9CPPFLAGS = $(call pkgconf, --cflags-only-I $(PETSc.pc) $(ceed.pc)) 10LDFLAGS = $(call pkgconf, --libs-only-L --libs-only-other $(PETSc.pc) $(ceed.pc)) 11LDFLAGS += $(patsubst -L%, $(call pkgconf, --variable=ldflag_rpath $(PETSc.pc))%, $(call pkgconf, --libs-only-L $(PETSc.pc) $(ceed.pc))) 12LDLIBS = $(call pkgconf, --libs-only-l $(PETSc.pc) $(ceed.pc)) -lm 13 14area.c := area.c 15area := $(area.c:%.c=%) 16 17bps.c := bps.c 18bps := $(bps.c:%.c=%) 19 20bpsraw.c := bpsraw.c 21bpsraw := $(bpsraw.c:%.c=%) 22 23bpssphere.c := bpssphere.c 24bpssphere := $(bpssphere.c:%.c=%) 25 26multigrid.c := multigrid.c 27multigrid := $(multigrid.c:%.c=%) 28 29all: $(area) $(bps) $(bpsraw) $(bpssphere) $(multigrid) 30$(area): | $(PETSc.pc) $(ceed.pc) 31$(bps): | $(PETSc.pc) $(ceed.pc) 32$(bpsraw): | $(PETSc.pc) $(ceed.pc) 33$(bpssphere): | $(PETSc.pc) $(ceed.pc) 34$(multigrid): | $(PETSc.pc) $(ceed.pc) 35 36# Rules for building the examples 37%: %.c 38 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(CEED_LDFLAGS) $(abspath $<) -o $@ \ 39 $(LDLIBS) 40 41print: $(PETSc.pc) $(ceed.pc) 42 $(info CC : $(CC)) 43 $(info CFLAGS : $(CFLAGS)) 44 $(info CPPFLAGS: $(CPPFLAGS)) 45 $(info LDFLAGS : $(LDFLAGS)) 46 $(info LDLIBS : $(LDLIBS)) 47 @true 48 49clean: 50 $(RM) $(area) $(bps) $(bpsraw) $(bpssphere) $(multigrid) 51 52$(PETSc.pc): 53 $(if $(wildcard $@),,$(error \ 54 PETSc config not found at $@. Please set PETSC_DIR and PETSC_ARCH)) 55 56.PHONY: all print clean 57 58pkgconf = $(shell pkg-config $1 | sed -e 's/^"//g' -e 's/"$$//g') 59