xref: /libCEED/examples/petsc/Makefile (revision d4cc18453651bd0f94c1a2e078b2646a92dafdcc)
1*9ba83ac0SJeremy L Thompson# Copyright (c) 2017-2026, Lawrence Livermore National Security, LLC and other CEED contributors
23d8e8822SJeremy L Thompson# All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3777ff853SJeremy L Thompson#
43d8e8822SJeremy L Thompson# SPDX-License-Identifier: BSD-2-Clause
5777ff853SJeremy L Thompson#
63d8e8822SJeremy 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))
18d4f9124cSJed BrownCFLAGS = -std=c11 \
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
319dbcead6SJeremy L Thompsonall: area bps bpsraw bpssphere dmswarm 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
5878f7fce3SZach Atkinsbpsswarm.c := bpsswarm.c
5978f7fce3SZach Atkinsbpsswarm.o = $(bpsswarm.c:%.c=$(OBJDIR)/%.o)
6078f7fce3SZach Atkinsbpsswarm: $(bpsswarm.o) libutils.a | $(PETSc.pc) $(ceed.pc)
6178f7fce3SZach Atkins	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
6278f7fce3SZach Atkins
6378f7fce3SZach Atkins
649dbcead6SJeremy L Thompsondmswarm.c := dmswarm.c
659dbcead6SJeremy L Thompsondmswarm.o = $(dmswarm.c:%.c=$(OBJDIR)/%.o)
669dbcead6SJeremy L Thompsondmswarm: $(dmswarm.o) libutils.a | $(PETSc.pc) $(ceed.pc)
679dbcead6SJeremy L Thompson	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
689dbcead6SJeremy L Thompson
69636cccdbSjeremyltmultigrid.c := multigrid.c
70e83e87a5Sjeremyltmultigrid.o = $(multigrid.c:%.c=$(OBJDIR)/%.o)
71386a09edSJed Brownmultigrid: $(multigrid.o) libutils.a | $(PETSc.pc) $(ceed.pc)
72e83e87a5Sjeremylt	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
73e83e87a5Sjeremylt
74e83e87a5Sjeremylt.SECONDEXPANSION: # to expand $$(@D)/.DIR
75e83e87a5Sjeremylt%/.DIR :
76e83e87a5Sjeremylt	@mkdir -p $(@D)
77e83e87a5Sjeremylt	@touch $@
789f8a8fa0SJed Brown
79777ff853SJeremy L Thompson# Quiet, color output
80777ff853SJeremy L Thompsonquiet ?= $($(1))
81777ff853SJeremy L Thompson
82e83e87a5Sjeremylt$(OBJDIR)/%.o : %.c | $$(@D)/.DIR
83e83e87a5Sjeremylt	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)
84e83e87a5Sjeremylt
8533795f53Sjeremylt# Rules for building the examples
86e83e87a5Sjeremylt#%: %.c
8733795f53Sjeremylt
88c0c38e35SVeselin Dobrevprint: $(PETSc.pc) $(ceed.pc)
899f8a8fa0SJed Brown	$(info CC      : $(CC))
909f8a8fa0SJed Brown	$(info CFLAGS  : $(CFLAGS))
919f8a8fa0SJed Brown	$(info CPPFLAGS: $(CPPFLAGS))
929f8a8fa0SJed Brown	$(info LDFLAGS : $(LDFLAGS))
939f8a8fa0SJed Brown	$(info LDLIBS  : $(LDLIBS))
94c0c38e35SVeselin Dobrev	@true
959f8a8fa0SJed Brown
969f8a8fa0SJed Brownclean:
979dbcead6SJeremy L Thompson	$(RM) -r $(OBJDIR) *.vtu area bps bpsraw bpssphere dmswarm multigrid libutils.a
989f8a8fa0SJed Brown
99c0c38e35SVeselin Dobrev$(PETSc.pc):
10008779805SVeselin Dobrev	$(if $(wildcard $@),,$(error \
1016f87d196Sjeremylt	  PETSc config not found at $@. Please set PETSC_DIR and PETSC_ARCH))
102c0c38e35SVeselin Dobrev
1039f8a8fa0SJed Brown.PHONY: all print clean
104c0c38e35SVeselin Dobrev
105c0c38e35SVeselin Dobrevpkgconf = $(shell pkg-config $1 | sed -e 's/^"//g' -e 's/"$$//g')
106e83e87a5Sjeremylt
107e83e87a5Sjeremylt-include $(src.o:%.o=%.d)
108