xref: /libCEED/examples/petsc/Makefile (revision 9dbcead6862c6d965f40afcd1255316d96af311a)
13d8e8822SJeremy L Thompson# Copyright (c) 2017-2022, 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))
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
31*9dbcead6SJeremy 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
58*9dbcead6SJeremy L Thompsondmswarm.c := dmswarm.c
59*9dbcead6SJeremy L Thompsondmswarm.o = $(dmswarm.c:%.c=$(OBJDIR)/%.o)
60*9dbcead6SJeremy L Thompsondmswarm: $(dmswarm.o) libutils.a | $(PETSc.pc) $(ceed.pc)
61*9dbcead6SJeremy L Thompson	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
62*9dbcead6SJeremy L Thompson
63636cccdbSjeremyltmultigrid.c := multigrid.c
64e83e87a5Sjeremyltmultigrid.o = $(multigrid.c:%.c=$(OBJDIR)/%.o)
65386a09edSJed Brownmultigrid: $(multigrid.o) libutils.a | $(PETSc.pc) $(ceed.pc)
66e83e87a5Sjeremylt	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
67e83e87a5Sjeremylt
68e83e87a5Sjeremylt.SECONDEXPANSION: # to expand $$(@D)/.DIR
69e83e87a5Sjeremylt%/.DIR :
70e83e87a5Sjeremylt	@mkdir -p $(@D)
71e83e87a5Sjeremylt	@touch $@
729f8a8fa0SJed Brown
73777ff853SJeremy L Thompson# Quiet, color output
74777ff853SJeremy L Thompsonquiet ?= $($(1))
75777ff853SJeremy L Thompson
76e83e87a5Sjeremylt$(OBJDIR)/%.o : %.c | $$(@D)/.DIR
77e83e87a5Sjeremylt	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)
78e83e87a5Sjeremylt
7933795f53Sjeremylt# Rules for building the examples
80e83e87a5Sjeremylt#%: %.c
8133795f53Sjeremylt
82c0c38e35SVeselin Dobrevprint: $(PETSc.pc) $(ceed.pc)
839f8a8fa0SJed Brown	$(info CC      : $(CC))
849f8a8fa0SJed Brown	$(info CFLAGS  : $(CFLAGS))
859f8a8fa0SJed Brown	$(info CPPFLAGS: $(CPPFLAGS))
869f8a8fa0SJed Brown	$(info LDFLAGS : $(LDFLAGS))
879f8a8fa0SJed Brown	$(info LDLIBS  : $(LDLIBS))
88c0c38e35SVeselin Dobrev	@true
899f8a8fa0SJed Brown
909f8a8fa0SJed Brownclean:
91*9dbcead6SJeremy L Thompson	$(RM) -r $(OBJDIR) *.vtu area bps bpsraw bpssphere dmswarm multigrid libutils.a
929f8a8fa0SJed Brown
93c0c38e35SVeselin Dobrev$(PETSc.pc):
9408779805SVeselin Dobrev	$(if $(wildcard $@),,$(error \
956f87d196Sjeremylt	  PETSc config not found at $@. Please set PETSC_DIR and PETSC_ARCH))
96c0c38e35SVeselin Dobrev
979f8a8fa0SJed Brown.PHONY: all print clean
98c0c38e35SVeselin Dobrev
99c0c38e35SVeselin Dobrevpkgconf = $(shell pkg-config $1 | sed -e 's/^"//g' -e 's/"$$//g')
100e83e87a5Sjeremylt
101e83e87a5Sjeremylt-include $(src.o:%.o=%.d)
102