xref: /libCEED/examples/petsc/Makefile (revision 1728c6a1410b975dbe09703a1f1803dc36f35afc)
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
40*1728c6a1Sjeremyltall: area bps bpsraw bpssphere multigrid
41*1728c6a1Sjeremylt
42e83e87a5Sjeremyltutils.c := $(sort $(wildcard $(SRCDIR)/*.c))
43636cccdbSjeremyltutils.o = $(utils.c:%.c=$(OBJDIR)/%.o)
44*1728c6a1Sjeremyltutils: $(utils.o)
45dc7d240cSValeria Barra
46636cccdbSjeremyltarea.c := area.c
47e83e87a5Sjeremyltarea.o = $(area.c:%.c=$(OBJDIR)/%.o)
48*1728c6a1Sjeremyltarea: $(area.o) $(utils.o) | utils $(PETSc.pc) $(ceed.pc)
49e83e87a5Sjeremylt	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
50ed264d09SValeria Barra
51636cccdbSjeremyltbps.c := bps.c
52e83e87a5Sjeremyltbps.o = $(bps.c:%.c=$(OBJDIR)/%.o)
53*1728c6a1Sjeremyltbps: $(bps.o) $(utils.o) | utils $(PETSc.pc) $(ceed.pc)
54e83e87a5Sjeremylt	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
556c5df90dSjeremylt
56636cccdbSjeremyltbpsraw.c := bpsraw.c
57e83e87a5Sjeremyltbpsraw.o = $(bpsraw.c:%.c=$(OBJDIR)/%.o)
58*1728c6a1Sjeremyltbpsraw: $(bpsraw.o) $(utils.o) | utils $(PETSc.pc) $(ceed.pc)
59e83e87a5Sjeremylt	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
60e83e87a5Sjeremylt
61636cccdbSjeremyltbpssphere.c := bpssphere.c
62e83e87a5Sjeremyltbpssphere.o = $(bpssphere.c:%.c=$(OBJDIR)/%.o)
63*1728c6a1Sjeremyltbpssphere: $(bpssphere.o) $(utils.o) | utils $(PETSc.pc) $(ceed.pc)
64e83e87a5Sjeremylt	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
65e83e87a5Sjeremylt
66636cccdbSjeremyltmultigrid.c := multigrid.c
67e83e87a5Sjeremyltmultigrid.o = $(multigrid.c:%.c=$(OBJDIR)/%.o)
68*1728c6a1Sjeremyltmultigrid: $(multigrid.o) $(utils.o) | utils $(PETSc.pc) $(ceed.pc)
69e83e87a5Sjeremylt	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
70e83e87a5Sjeremylt
71e83e87a5Sjeremylt.SECONDEXPANSION: # to expand $$(@D)/.DIR
72e83e87a5Sjeremylt%/.DIR :
73e83e87a5Sjeremylt	@mkdir -p $(@D)
74e83e87a5Sjeremylt	@touch $@
759f8a8fa0SJed Brown
76777ff853SJeremy L Thompson# Quiet, color output
77777ff853SJeremy L Thompsonquiet ?= $($(1))
78777ff853SJeremy L Thompson
79e83e87a5Sjeremylt$(OBJDIR)/%.o : %.c | $$(@D)/.DIR
80e83e87a5Sjeremylt	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)
81e83e87a5Sjeremylt
8233795f53Sjeremylt# Rules for building the examples
83e83e87a5Sjeremylt#%: %.c
8433795f53Sjeremylt
85c0c38e35SVeselin Dobrevprint: $(PETSc.pc) $(ceed.pc)
869f8a8fa0SJed Brown	$(info CC      : $(CC))
879f8a8fa0SJed Brown	$(info CFLAGS  : $(CFLAGS))
889f8a8fa0SJed Brown	$(info CPPFLAGS: $(CPPFLAGS))
899f8a8fa0SJed Brown	$(info LDFLAGS : $(LDFLAGS))
909f8a8fa0SJed Brown	$(info LDLIBS  : $(LDLIBS))
91c0c38e35SVeselin Dobrev	@true
929f8a8fa0SJed Brown
939f8a8fa0SJed Brownclean:
94e83e87a5Sjeremylt	$(RM) -r $(OBJDIR) *.vtu area bps bpsraw bpssphere multigrid
959f8a8fa0SJed Brown
96c0c38e35SVeselin Dobrev$(PETSc.pc):
9708779805SVeselin Dobrev	$(if $(wildcard $@),,$(error \
986f87d196Sjeremylt	  PETSc config not found at $@. Please set PETSC_DIR and PETSC_ARCH))
99c0c38e35SVeselin Dobrev
1009f8a8fa0SJed Brown.PHONY: all print clean
101c0c38e35SVeselin Dobrev
102c0c38e35SVeselin Dobrevpkgconf = $(shell pkg-config $1 | sed -e 's/^"//g' -e 's/"$$//g')
103e83e87a5Sjeremylt
104e83e87a5Sjeremylt-include $(src.o:%.o=%.d)
105