1# -*- mode: makefile -*- 2 3# This sample (GNU) Makefile can be used to compile PETSc applications with a single 4# source file and can be easily modified to compile multi-file applications. 5# It relies on pkg_config tool, and PETSC_DIR and PETSC_ARCH variables. 6# Copy this file to your source directory as "Makefile" and modify as needed. 7# 8# For example - a single source file can be compiled with: 9# 10# $ cd src/snes/tutorials/ 11# $ make -f $PETSC_DIR/share/petsc/Makefile.user ex17 12# 13# The following variable must either be a path to petsc.pc or just "petsc" if petsc.pc 14# has been installed to a system location or can be found in PKG_CONFIG_PATH. 15petsc.pc := $(PETSC_DIR)/$(PETSC_ARCH)/lib/pkgconfig/petsc.pc 16 17# Additional libraries that support pkg-config can be added to the list of PACKAGES below. 18PACKAGES := $(petsc.pc) 19 20CC := $(shell pkg-config --variable=ccompiler $(PACKAGES)) 21CXX := $(shell pkg-config --variable=cxxcompiler $(PACKAGES)) 22FC := $(shell pkg-config --variable=fcompiler $(PACKAGES)) 23CFLAGS_OTHER := $(shell pkg-config --cflags-only-other $(PACKAGES)) 24CFLAGS := $(shell pkg-config --variable=cflags_extra $(PACKAGES)) $(CFLAGS_OTHER) 25CXXFLAGS := $(shell pkg-config --variable=cxxflags_extra $(PACKAGES)) $(CFLAGS_OTHER) 26FFLAGS := $(shell pkg-config --variable=fflags_extra $(PACKAGES)) 27CPPFLAGS := $(shell pkg-config --cflags-only-I $(PACKAGES)) 28LDFLAGS := $(shell pkg-config --libs-only-L --libs-only-other $(PACKAGES)) 29LDFLAGS += $(patsubst -L%, $(shell pkg-config --variable=ldflag_rpath $(PACKAGES))%, $(shell pkg-config --libs-only-L $(PACKAGES))) 30LDLIBS := $(shell pkg-config --libs-only-l $(PACKAGES)) -lm 31 32print: 33 @echo CC=$(CC) 34 @echo CXX=$(CXX) 35 @echo FC=$(FC) 36 @echo CFLAGS=$(CFLAGS) 37 @echo CXXFLAGS=$(CXXFLAGS) 38 @echo FFLAGS=$(FFLAGS) 39 @echo CPPFLAGS=$(CPPFLAGS) 40 @echo LDFLAGS=$(LDFLAGS) 41 @echo LDLIBS=$(LDLIBS) 42 43# Many suffixes are covered by implicit rules, but you may need to write custom rules 44# such as these if you use suffixes that do not have implicit rules. 45# https://www.gnu.org/software/make/manual/html_node/Catalogue-of-Rules.html#Catalogue-of-Rules 46% : %.F90 47 $(LINK.F) -o $@ $^ $(LDLIBS) 48%.o: %.F90 49 $(COMPILE.F) $(OUTPUT_OPTION) $< 50% : %.cxx 51 $(LINK.cc) -o $@ $^ $(LDLIBS) 52%.o: %.cxx 53 $(COMPILE.cc) $(OUTPUT_OPTION) $< 54 55# For a multi-file case, suppose you have the source files a.F90, b.c, and c.cxx 56# (with a program statement appearing in a.F90 or main() appearing in the C or 57# C++ source). This can be built by uncommenting the following two lines. 58# 59# app : a.o b.o c.o 60# $(LINK.F) -o $@ $^ $(LDLIBS) 61 62# If the file c.cxx needs to link with a C++ standard library -lstdc++ , then 63# you'll need to add it explicitly. It can go in the rule above or be added to 64# a target-specific variable by uncommenting the line below. 65# 66# app : LDLIBS += -lstdc++ 67