xref: /libCEED/examples/petsc/Makefile (revision 28f1e9f5007ebb4143767e9346c12f0b912c29da)
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
14bps.c := bps.c
15bps := $(bps.c:%.c=%)
16
17bpsdmplex.c := bpsdmplex.c
18bpsdmplex := $(bpsdmplex.c:%.c=%)
19
20multigrid.c := multigrid.c
21multigrid := $(multigrid.c:%.c=%)
22
23all: $(bps) $(bpsdmplex) $(multigrid)
24$(bps): | $(PETSc.pc) $(ceed.pc)
25$(bpsdmplex): | $(PETSc.pc) $(ceed.pc)
26$(multigrid): | $(PETSc.pc) $(ceed.pc)
27
28# Rules for building the examples
29%: %.c
30	$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(abspath $<) -o $@ \
31	  $(LDLIBS)
32
33print: $(PETSc.pc) $(ceed.pc)
34	$(info CC      : $(CC))
35	$(info CFLAGS  : $(CFLAGS))
36	$(info CPPFLAGS: $(CPPFLAGS))
37	$(info LDFLAGS : $(LDFLAGS))
38	$(info LDLIBS  : $(LDLIBS))
39	@true
40
41clean:
42	$(RM) $(bps) $(bpsdmplex) $(multigrid)
43
44$(PETSc.pc):
45	$(if $(wildcard $@),,$(error \
46	  PETSc config not found at $@. Please set PETSC_DIR and PETSC_ARCH))
47
48.PHONY: all print clean
49
50pkgconf = $(shell pkg-config $1 | sed -e 's/^"//g' -e 's/"$$//g')
51