xref: /libCEED/examples/petsc/Makefile (revision 4e015973f3c9f2e3adbb5b892ef639de661995f7)
1# Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
2# the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
3# reserved. See files LICENSE and NOTICE for details.
4#
5# This file is part of CEED, a collection of benchmarks, miniapps, software
6# libraries and APIs for efficient high-order finite element and spectral
7# element discretizations for exascale applications. For more information and
8# source code availability see http://github.com/ceed.
9#
10# The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11# a collaborative effort of two U.S. Department of Energy organizations (Office
12# of Science and the National Nuclear Security Administration) responsible for
13# the planning and preparation of a capable exascale ecosystem, including
14# software, applications, hardware, advanced system engineering and early
15# testbed platforms, in support of the nation's exascale computing imperative.
16
17COMMON ?= ../../common.mk
18-include $(COMMON)
19
20# Note: PETSC_ARCH can be undefined or empty for installations which do not use
21#       PETSC_ARCH - for example when using PETSc installed through Spack.
22PETSc.pc := $(PETSC_DIR)/$(PETSC_ARCH)/lib/pkgconfig/PETSc.pc
23CEED_DIR ?= ../..
24ceed.pc := $(CEED_DIR)/lib/pkgconfig/ceed.pc
25
26CC = $(call pkgconf, --variable=ccompiler $(PETSc.pc) $(ceed.pc))
27CFLAGS = -std=c99 \
28  $(call pkgconf, --variable=cflags_extra $(PETSc.pc)) \
29  $(call pkgconf, --cflags-only-other $(PETSc.pc)) \
30  $(OPT)
31CPPFLAGS = $(call pkgconf, --cflags-only-I $(PETSc.pc) $(ceed.pc)) \
32  $(call pkgconf, --variable=cflags_dep $(PETSc.pc))
33LDFLAGS = $(call pkgconf, --libs-only-L --libs-only-other $(PETSc.pc) $(ceed.pc))
34LDFLAGS += $(patsubst -L%, $(call pkgconf, --variable=ldflag_rpath $(PETSc.pc))%, $(call pkgconf, --libs-only-L $(PETSc.pc) $(ceed.pc)))
35LDLIBS = $(call pkgconf, --libs-only-l $(PETSc.pc) $(ceed.pc)) -lm
36
37OBJDIR := build
38SRCDIR := src
39
40utils.c := $(sort $(wildcard $(SRCDIR)/*.c))
41utils.o = $(utils.c:%.c=$(OBJDIR)/%.o)
42
43all: area bps bpsraw bpssphere multigrid
44
45area.c := area.c
46area.o = $(area.c:%.c=$(OBJDIR)/%.o)
47area: $(area.o) $(utils.o) | $(PETSc.pc) $(ceed.pc)
48	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
49
50bps.c := bps.c
51bps.o = $(bps.c:%.c=$(OBJDIR)/%.o)
52bps: $(bps.o) $(utils.o) | $(PETSc.pc) $(ceed.pc)
53	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
54
55bpsraw.c := bpsraw.c
56bpsraw.o = $(bpsraw.c:%.c=$(OBJDIR)/%.o)
57bpsraw: $(bpsraw.o) $(utils.o) | $(PETSc.pc) $(ceed.pc)
58	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
59
60bpssphere.c := bpssphere.c
61bpssphere.o = $(bpssphere.c:%.c=$(OBJDIR)/%.o)
62bpssphere: $(bpssphere.o) $(utils.o) | $(PETSc.pc) $(ceed.pc)
63	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
64
65multigrid.c := multigrid.c
66multigrid.o = $(multigrid.c:%.c=$(OBJDIR)/%.o)
67multigrid: $(multigrid.o) $(utils.o) | $(PETSc.pc) $(ceed.pc)
68	$(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@
69
70.SECONDEXPANSION: # to expand $$(@D)/.DIR
71%/.DIR :
72	@mkdir -p $(@D)
73	@touch $@
74
75# Quiet, color output
76quiet ?= $($(1))
77
78$(OBJDIR)/%.o : %.c | $$(@D)/.DIR
79	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)
80
81# Rules for building the examples
82#%: %.c
83
84print: $(PETSc.pc) $(ceed.pc)
85	$(info CC      : $(CC))
86	$(info CFLAGS  : $(CFLAGS))
87	$(info CPPFLAGS: $(CPPFLAGS))
88	$(info LDFLAGS : $(LDFLAGS))
89	$(info LDLIBS  : $(LDLIBS))
90	@true
91
92clean:
93	$(RM) -r $(OBJDIR) *.vtu area bps bpsraw bpssphere multigrid
94
95$(PETSc.pc):
96	$(if $(wildcard $@),,$(error \
97	  PETSc config not found at $@. Please set PETSC_DIR and PETSC_ARCH))
98
99.PHONY: all print clean
100
101pkgconf = $(shell pkg-config $1 | sed -e 's/^"//g' -e 's/"$$//g')
102
103-include $(src.o:%.o=%.d)
104