xref: /libCEED/examples/petsc/Makefile (revision 386a09edbbb27c3428b540af303dc85c95153159)
1777ff853SJeremy L Thompson# Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
2777ff853SJeremy L Thompson# the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
3777ff853SJeremy L Thompson# reserved. See files LICENSE and NOTICE for details.
4777ff853SJeremy L Thompson#
5777ff853SJeremy L Thompson# This file is part of CEED, a collection of benchmarks, miniapps, software
6777ff853SJeremy L Thompson# libraries and APIs for efficient high-order finite element and spectral
7777ff853SJeremy L Thompson# element discretizations for exascale applications. For more information and
8777ff853SJeremy L Thompson# source code availability see http://github.com/ceed.
9777ff853SJeremy L Thompson#
10777ff853SJeremy L Thompson# The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11777ff853SJeremy L Thompson# a collaborative effort of two U.S. Department of Energy organizations (Office
12777ff853SJeremy L Thompson# of Science and the National Nuclear Security Administration) responsible for
13777ff853SJeremy L Thompson# the planning and preparation of a capable exascale ecosystem, including
14777ff853SJeremy L Thompson# software, applications, hardware, advanced system engineering and early
15777ff853SJeremy L Thompson# testbed platforms, in support of the nation's exascale computing imperative.
16777ff853SJeremy L Thompson
17777ff853SJeremy L ThompsonCOMMON ?= ../../common.mk
18777ff853SJeremy L Thompson-include $(COMMON)
19777ff853SJeremy L Thompson
202f4d9adbSJeremy L Thompson# Note: PETSC_ARCH can be undefined or empty for installations which do not use
212f4d9adbSJeremy L Thompson#       PETSC_ARCH - for example when using PETSc installed through Spack.
229f8a8fa0SJed BrownPETSc.pc := $(PETSC_DIR)/$(PETSC_ARCH)/lib/pkgconfig/PETSc.pc
236ea7c6c1SJed BrownCEED_DIR ?= ../..
246ea7c6c1SJed Brownceed.pc := $(CEED_DIR)/lib/pkgconfig/ceed.pc
259f8a8fa0SJed Brown
26c0c38e35SVeselin DobrevCC = $(call pkgconf, --variable=ccompiler $(PETSc.pc) $(ceed.pc))
27e83e87a5SjeremyltCFLAGS = -std=c99 \
28e83e87a5Sjeremylt  $(call pkgconf, --variable=cflags_extra $(PETSc.pc)) \
29e83e87a5Sjeremylt  $(call pkgconf, --cflags-only-other $(PETSc.pc)) \
30e83e87a5Sjeremylt  $(OPT)
31e83e87a5SjeremyltCPPFLAGS = $(call pkgconf, --cflags-only-I $(PETSc.pc) $(ceed.pc)) \
32e83e87a5Sjeremylt  $(call pkgconf, --variable=cflags_dep $(PETSc.pc))
33c0c38e35SVeselin DobrevLDFLAGS = $(call pkgconf, --libs-only-L --libs-only-other $(PETSc.pc) $(ceed.pc))
34c0c38e35SVeselin DobrevLDFLAGS += $(patsubst -L%, $(call pkgconf, --variable=ldflag_rpath $(PETSc.pc))%, $(call pkgconf, --libs-only-L $(PETSc.pc) $(ceed.pc)))
35c0c38e35SVeselin DobrevLDLIBS = $(call pkgconf, --libs-only-l $(PETSc.pc) $(ceed.pc)) -lm
369f8a8fa0SJed Brown
37e83e87a5SjeremyltOBJDIR := build
38e83e87a5SjeremyltSRCDIR := src
39cb32e2e7SValeria Barra
401728c6a1Sjeremyltall: area bps bpsraw bpssphere multigrid
411728c6a1Sjeremylt
42e83e87a5Sjeremyltutils.c := $(sort $(wildcard $(SRCDIR)/*.c))
43636cccdbSjeremyltutils.o = $(utils.c:%.c=$(OBJDIR)/%.o)
44*386a09edSJed Brownlibutils.a: $(utils.o)
45*386a09edSJed Brown	$(call quiet,AR) $(ARFLAGS) $@ $^
46dc7d240cSValeria Barra
47636cccdbSjeremyltarea.c := area.c
48e83e87a5Sjeremyltarea.o = $(area.c:%.c=$(OBJDIR)/%.o)
49*386a09edSJed Brownarea: $(area.o) libutils.a | $(PETSc.pc) $(ceed.pc)
50e83e87a5Sjeremylt	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
51ed264d09SValeria Barra
52636cccdbSjeremyltbps.c := bps.c
53e83e87a5Sjeremyltbps.o = $(bps.c:%.c=$(OBJDIR)/%.o)
54*386a09edSJed Brownbps: $(bps.o) libutils.a | $(PETSc.pc) $(ceed.pc)
55e83e87a5Sjeremylt	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
566c5df90dSjeremylt
57636cccdbSjeremyltbpsraw.c := bpsraw.c
58e83e87a5Sjeremyltbpsraw.o = $(bpsraw.c:%.c=$(OBJDIR)/%.o)
59*386a09edSJed Brownbpsraw: $(bpsraw.o) libutils.a | $(PETSc.pc) $(ceed.pc)
60e83e87a5Sjeremylt	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
61e83e87a5Sjeremylt
62636cccdbSjeremyltbpssphere.c := bpssphere.c
63e83e87a5Sjeremyltbpssphere.o = $(bpssphere.c:%.c=$(OBJDIR)/%.o)
64*386a09edSJed Brownbpssphere: $(bpssphere.o) libutils.a | $(PETSc.pc) $(ceed.pc)
65e83e87a5Sjeremylt	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
66e83e87a5Sjeremylt
67636cccdbSjeremyltmultigrid.c := multigrid.c
68e83e87a5Sjeremyltmultigrid.o = $(multigrid.c:%.c=$(OBJDIR)/%.o)
69*386a09edSJed Brownmultigrid: $(multigrid.o) libutils.a | $(PETSc.pc) $(ceed.pc)
70e83e87a5Sjeremylt	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
71e83e87a5Sjeremylt
72e83e87a5Sjeremylt.SECONDEXPANSION: # to expand $$(@D)/.DIR
73e83e87a5Sjeremylt%/.DIR :
74e83e87a5Sjeremylt	@mkdir -p $(@D)
75e83e87a5Sjeremylt	@touch $@
769f8a8fa0SJed Brown
77777ff853SJeremy L Thompson# Quiet, color output
78777ff853SJeremy L Thompsonquiet ?= $($(1))
79777ff853SJeremy L Thompson
80e83e87a5Sjeremylt$(OBJDIR)/%.o : %.c | $$(@D)/.DIR
81e83e87a5Sjeremylt	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)
82e83e87a5Sjeremylt
8333795f53Sjeremylt# Rules for building the examples
84e83e87a5Sjeremylt#%: %.c
8533795f53Sjeremylt
86c0c38e35SVeselin Dobrevprint: $(PETSc.pc) $(ceed.pc)
879f8a8fa0SJed Brown	$(info CC      : $(CC))
889f8a8fa0SJed Brown	$(info CFLAGS  : $(CFLAGS))
899f8a8fa0SJed Brown	$(info CPPFLAGS: $(CPPFLAGS))
909f8a8fa0SJed Brown	$(info LDFLAGS : $(LDFLAGS))
919f8a8fa0SJed Brown	$(info LDLIBS  : $(LDLIBS))
92c0c38e35SVeselin Dobrev	@true
939f8a8fa0SJed Brown
949f8a8fa0SJed Brownclean:
95*386a09edSJed Brown	$(RM) -r $(OBJDIR) *.vtu area bps bpsraw bpssphere multigrid libutils.a
969f8a8fa0SJed Brown
97c0c38e35SVeselin Dobrev$(PETSc.pc):
9808779805SVeselin Dobrev	$(if $(wildcard $@),,$(error \
996f87d196Sjeremylt	  PETSc config not found at $@. Please set PETSC_DIR and PETSC_ARCH))
100c0c38e35SVeselin Dobrev
1019f8a8fa0SJed Brown.PHONY: all print clean
102c0c38e35SVeselin Dobrev
103c0c38e35SVeselin Dobrevpkgconf = $(shell pkg-config $1 | sed -e 's/^"//g' -e 's/"$$//g')
104e83e87a5Sjeremylt
105e83e87a5Sjeremylt-include $(src.o:%.o=%.d)
106