xref: /libCEED/examples/petsc/Makefile (revision e83e87a50f1b2e8810b376a735430565127e4d25)
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))
27*e83e87a5SjeremyltCFLAGS = -std=c99 \
28*e83e87a5Sjeremylt  $(call pkgconf, --variable=cflags_extra $(PETSc.pc)) \
29*e83e87a5Sjeremylt  $(call pkgconf, --cflags-only-other $(PETSc.pc)) \
30*e83e87a5Sjeremylt  $(OPT)
31*e83e87a5SjeremyltCPPFLAGS = $(call pkgconf, --cflags-only-I $(PETSc.pc) $(ceed.pc)) \
32*e83e87a5Sjeremylt  $(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
37*e83e87a5SjeremyltOBJDIR := build
38*e83e87a5SjeremyltSRCDIR := src
39cb32e2e7SValeria Barra
40*e83e87a5Sjeremyltutils.c := $(sort $(wildcard $(SRCDIR)/*.c))
419f8a8fa0SJed Brown
42*e83e87a5Sjeremyltall: area bps bpsraw bpssphere multigrid
43dc7d240cSValeria Barra
44*e83e87a5Sjeremyltarea.c := area.c $(utils.c)
45*e83e87a5Sjeremyltarea.o = $(area.c:%.c=$(OBJDIR)/%.o)
46*e83e87a5Sjeremyltarea: $(area.o) | $(PETSc.pc) $(ceed.pc)
47*e83e87a5Sjeremylt	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
48ed264d09SValeria Barra
49*e83e87a5Sjeremyltbps.c := bps.c $(utils.c)
50*e83e87a5Sjeremyltbps.o = $(bps.c:%.c=$(OBJDIR)/%.o)
51*e83e87a5Sjeremyltbps: $(bps.o) | $(PETSc.pc) $(ceed.pc)
52*e83e87a5Sjeremylt	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
536c5df90dSjeremylt
54*e83e87a5Sjeremyltbpsraw.c := bpsraw.c $(utils.c)
55*e83e87a5Sjeremyltbpsraw.o = $(bpsraw.c:%.c=$(OBJDIR)/%.o)
56*e83e87a5Sjeremyltbpsraw: $(bpsraw.o) | $(PETSc.pc) $(ceed.pc)
57*e83e87a5Sjeremylt	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
58*e83e87a5Sjeremylt
59*e83e87a5Sjeremyltbpssphere.c := bpssphere.c $(utils.c)
60*e83e87a5Sjeremyltbpssphere.o = $(bpssphere.c:%.c=$(OBJDIR)/%.o)
61*e83e87a5Sjeremyltbpssphere: $(bpssphere.o) | $(PETSc.pc) $(ceed.pc)
62*e83e87a5Sjeremylt	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
63*e83e87a5Sjeremylt
64*e83e87a5Sjeremyltmultigrid.c := multigrid.c $(utils.c)
65*e83e87a5Sjeremyltmultigrid.o = $(multigrid.c:%.c=$(OBJDIR)/%.o)
66*e83e87a5Sjeremyltmultigrid: $(multigrid.o) | $(PETSc.pc) $(ceed.pc)
67*e83e87a5Sjeremylt	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
68*e83e87a5Sjeremylt
69*e83e87a5Sjeremylt.SECONDEXPANSION: # to expand $$(@D)/.DIR
70*e83e87a5Sjeremylt%/.DIR :
71*e83e87a5Sjeremylt	@mkdir -p $(@D)
72*e83e87a5Sjeremylt	@touch $@
739f8a8fa0SJed Brown
74777ff853SJeremy L Thompson# Quiet, color output
75777ff853SJeremy L Thompsonquiet ?= $($(1))
76777ff853SJeremy L Thompson
77*e83e87a5Sjeremylt$(OBJDIR)/%.o : %.c | $$(@D)/.DIR
78*e83e87a5Sjeremylt	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)
79*e83e87a5Sjeremylt
8033795f53Sjeremylt# Rules for building the examples
81*e83e87a5Sjeremylt#%: %.c
8233795f53Sjeremylt
83c0c38e35SVeselin Dobrevprint: $(PETSc.pc) $(ceed.pc)
849f8a8fa0SJed Brown	$(info CC      : $(CC))
859f8a8fa0SJed Brown	$(info CFLAGS  : $(CFLAGS))
869f8a8fa0SJed Brown	$(info CPPFLAGS: $(CPPFLAGS))
879f8a8fa0SJed Brown	$(info LDFLAGS : $(LDFLAGS))
889f8a8fa0SJed Brown	$(info LDLIBS  : $(LDLIBS))
89c0c38e35SVeselin Dobrev	@true
909f8a8fa0SJed Brown
919f8a8fa0SJed Brownclean:
92*e83e87a5Sjeremylt	$(RM) -r $(OBJDIR) *.vtu area bps bpsraw bpssphere multigrid
939f8a8fa0SJed Brown
94c0c38e35SVeselin Dobrev$(PETSc.pc):
9508779805SVeselin Dobrev	$(if $(wildcard $@),,$(error \
966f87d196Sjeremylt	  PETSc config not found at $@. Please set PETSC_DIR and PETSC_ARCH))
97c0c38e35SVeselin Dobrev
989f8a8fa0SJed Brown.PHONY: all print clean
99c0c38e35SVeselin Dobrev
100c0c38e35SVeselin Dobrevpkgconf = $(shell pkg-config $1 | sed -e 's/^"//g' -e 's/"$$//g')
101*e83e87a5Sjeremylt
102*e83e87a5Sjeremylt-include $(src.o:%.o=%.d)
103