1# -*- mode: makefile-gmake -*- 2include petscdir.mk 3 4# If $(PETSC_ARCH) is empty, this defines it and PETSC_DIR 5include ./$(PETSC_ARCH)/lib/petsc/conf/petscvariables 6include ./lib/petsc/conf/variables 7 8OBJDIR := $(PETSC_ARCH)/obj 9LIBDIR := $(PETSC_ARCH)/lib 10 11pkgs := sys vec mat dm ksp snes ts tao 12 13# $(call SONAME_FUNCTION,libfoo,abiversion) 14SONAME_FUNCTION ?= $(1).$(SL_LINKER_SUFFIX).$(2) 15# $(call SL_LINKER_FUNCTION,libfoo,abiversion,libversion) 16SL_LINKER_FUNCTION ?= -shared -Wl,-soname,$(call SONAME_FUNCTION,$(notdir $(1)),$(2)) 17 18PETSC_VERSION_MAJOR := $(shell awk '/define PETSC_VERSION_MAJOR/{print $$3;}' ./include/petscversion.h) 19PETSC_VERSION_MINOR := $(shell awk '/define PETSC_VERSION_MINOR/{print $$3;}' ./include/petscversion.h) 20PETSC_VERSION_SUBMINOR := $(shell awk '/define PETSC_VERSION_SUBMINOR/{print $$3;}' ./include/petscversion.h) 21PETSC_VERSION_RELEASE := $(shell awk '/define PETSC_VERSION_RELEASE/{print $$3;}' ./include/petscversion.h) 22 23libpetsc_abi_version := $(PETSC_VERSION_MAJOR).$(if $(filter $(PETSC_VERSION_RELEASE), 0 -2 -3 -4 -5),0)$(PETSC_VERSION_MINOR) 24libpetsc_lib_version := $(libpetsc_abi_version).$(PETSC_VERSION_SUBMINOR) 25soname_function = $(call SONAME_FUNCTION,$(1),$(libpetsc_abi_version)) 26libname_function = $(call SONAME_FUNCTION,$(1),$(libpetsc_lib_version)) 27absbasename_all = $(basename $(basename $(basename $(basename $(abspath $(1))))))# arch/lib/libpetsc.so.3.8.0 -> /path/to/arch/lib/libpetsc 28sl_linker_args = $(call SL_LINKER_FUNCTION,$(call absbasename_all,$@),$(libpetsc_abi_version),$(libpetsc_lib_version)) 29 30libpetsc_shared := $(LIBDIR)/libpetsc.$(SL_LINKER_SUFFIX) 31libpetsc_soname := $(call soname_function,$(LIBDIR)/libpetsc) 32libpetsc_libname := $(call libname_function,$(LIBDIR)/libpetsc) 33libpetsc_static := $(LIBDIR)/libpetsc.$(AR_LIB_SUFFIX) 34libpetscpkgs_shared := $(foreach pkg, $(pkgs), $(LIBDIR)/libpetsc$(pkg).$(SL_LINKER_SUFFIX)) 35libpetscpkgs_soname := $(foreach pkg, $(pkgs), $(call soname_function,$(LIBDIR)/libpetsc$(pkg))) 36libpetscpkgs_libname := $(foreach pkg, $(pkgs), $(call libname_function,$(LIBDIR)/libpetsc$(pkg))) 37libpetscpkgs_static := $(foreach pkg, $(pkgs), $(LIBDIR)/libpetsc$(pkg).$(AR_LIB_SUFFIX)) 38 39ifeq ($(PETSC_WITH_EXTERNAL_LIB),) 40 libpetscall_shared := $(libpetscpkgs_shared) 41 libpetscall_soname := $(libpetscpkgs_soname) 42 libpetscall_libname := $(libpetscpkgs_libname) 43 libpetscall_static := $(libpetscpkgs_static) 44else 45 libpetscall_shared := $(libpetsc_shared) 46 libpetscall_soname := $(libpetsc_soname) 47 libpetscall_libname := $(libpetsc_libname) 48 libpetscall_static := $(libpetsc_static) 49endif 50libpetscall := $(if $(filter-out no,$(BUILDSHAREDLIB)),$(libpetscall_shared),$(libpetscall_static)) 51 52generated := $(PETSC_ARCH)/lib/petsc/conf/files 53 54libs : $(libpetscall) 55 56.PHONY: libs 57 58.SECONDEXPANSION: # to expand $$(@D)/.DIR 59 60# Test framework includes rules and variables relevant to both build and test 61include ./gmakefile.test # This must be below the all target because it includes rules 62 63$(generated) : $(petscconf) $(petscvariables) config/gmakegen.py 64 $(PYTHON) ./config/gmakegen.py --petsc-arch=$(PETSC_ARCH) 65 66# Skip including generated files (which triggers rebuilding them) when we're just going to clean anyway. 67ifneq ($(filter-out help clean check info gmakeinfo,$(MAKECMDGOALS:clean%=clean)),) 68include $(generated) 69endif 70 71# implies shared libraries with MS compilers 72ifeq ($(PETSC_DLL_EXPORTS),1) 73$(OBJDIR)/%.o : CCPPFLAGS+=-Dpetsc_EXPORTS 74$(OBJDIR)/%.o : CXXCPPFLAGS+=-Dpetsc_EXPORTS 75$(OBJDIR)/%.o : CUDACPPFLAGS+=-Dpetsc_EXPORTS 76endif 77 78langs := F F90 cxx c 79ifneq ($(CUDAC),) 80langs += cu 81endif 82ifneq ($(HIPC),) 83langs += hip.cpp 84endif 85ifneq ($(SYCLC),) 86langs += sycl.cxx 87endif 88ifneq ($(KOKKOS_LIB),) 89langs += kokkos.cxx 90endif 91 92concatlang = $(foreach lang, $(langs), $(srcs-$(1).$(lang):src/%.$(lang)=$(OBJDIR)/%.o)) 93srcs.o := $(foreach pkg, $(pkgs), $(call concatlang,$(pkg))) 94srcs.tidy := $(foreach pkg, $(pkgs), $(srcs-$(pkg).c:src/%.c=$(OBJDIR)/%.tidy)) 95concatlangsrc = $(foreach lang, $(langs), $(srcs-$(1).$(lang))) 96csrc := $(foreach pkg, $(pkgs), $(srcs-$(pkg).c)) 97showcsrc: 98 -@echo $(csrc) 99 100define SHARED_RECIPE_DLL 101 @$(RM) $@ dllcmd.${PETSC_ARCH} 102 @cygpath -w $^ > dllcmd.${PETSC_ARCH} 103 $(call quiet,CLINKER) $(sl_linker_args) -o $@ @dllcmd.${PETSC_ARCH} $(PETSC_EXTERNAL_LIB_BASIC) 104 @$(RM) dllcmd.${PETSC_ARCH} 105endef 106 107define SHARED_RECIPE_ATFILE 108 $(file > $@.args,$^) 109 $(call quiet,CLINKER) $(sl_linker_args) -o $@ @$@.args $(PETSC_EXTERNAL_LIB_BASIC) 110 @$(RM) $@.args 111endef 112 113define SHARED_RECIPE_DEFAULT 114 $(call quiet,CLINKER) $(sl_linker_args) -o $@ $^ $(PETSC_EXTERNAL_LIB_BASIC) 115endef 116 117GMAKE4 = $(if $(findstring 3.99,$(firstword $(sort 3.99 $(MAKE_VERSION)))),1,) 118SHARED_RECIPE = $(if $(findstring -LD,$(SL_LINKER_FUNCTION)),$(SHARED_RECIPE_DLL),$(if $(PCC_AT_FILE),$(if $(GMAKE4),$(SHARED_RECIPE_ATFILE),$(SHARED_RECIPE_DEFAULT)),$(SHARED_RECIPE_DEFAULT))) 119 120# with-single-library=1 (default) 121$(libpetsc_libname) : $(srcs.o) | $$(@D)/.DIR 122 $(SHARED_RECIPE) 123ifneq ($(DSYMUTIL),true) 124 $(call quiet,DSYMUTIL) $@ 125endif 126 127$(libpetsc_static) : obj := $(srcs.o) 128 129define ARCHIVE_RECIPE_WIN32FE_LIB 130 @$(RM) $@ $@.args 131 @cygpath -w $^ > $@.args 132 $(call quiet,AR) $(AR_FLAGS) $@ @$@.args 133 @$(RM) $@.args 134endef 135 136define ARCHIVE_RECIPE_ARGFILE 137 @$(RM) $@ 138 $(file > $@.args,$^) 139 $(call quiet,AR) $(AR_FLAGS) $@ @$@.args 140 @$(RM) $@.args 141 $(call quiet,RANLIB) $@ 142endef 143 144define ARCHIVE_RECIPE_DEFAULT 145 @$(RM) $@ 146 $(call quiet,AR) $(AR_FLAGS) $@ $^ 147 $(call quiet,RANLIB) $@ 148endef 149 150%.$(AR_LIB_SUFFIX) : $$(obj) | $$(@D)/.DIR 151 $(if $(findstring win_lib,$(AR)),$(ARCHIVE_RECIPE_WIN32FE_LIB),$(if $(findstring yes,$(AR_ARGFILE)),$(if $(GMAKE4),$(ARCHIVE_RECIPE_ARGFILE),$(ARCHIVE_RECIPE_DEFAULT)),$(ARCHIVE_RECIPE_DEFAULT))) 152 153# with-single-library=0 154libpkg = $(foreach pkg, $1, $(LIBDIR)/libpetsc$(pkg).$(SL_LINKER_SUFFIX)) 155define pkg_template 156 $(LIBDIR)/libpetsc$(1).$(AR_LIB_SUFFIX) : $(call concatlang,$(1)) 157 $(call libname_function,$(LIBDIR)/libpetsc$(1)) : $(call concatlang,$(1)) 158endef 159$(foreach pkg,$(pkgs),$(eval $(call pkg_template,$(pkg)))) 160$(call libname_function,$(LIBDIR)/libpetscvec) : libdep := $(call libpkg,sys) 161$(call libname_function,$(LIBDIR)/libpetscmat) : libdep := $(call libpkg,vec sys) 162$(call libname_function,$(LIBDIR)/libpetscdm) : libdep := $(call libpkg,mat vec sys) 163$(call libname_function,$(LIBDIR)/libpetscksp) : libdep := $(call libpkg,dm mat vec sys) 164$(call libname_function,$(LIBDIR)/libpetscsnes) : libdep := $(call libpkg,ksp dm mat vec sys) 165$(call libname_function,$(LIBDIR)/libpetscts) : libdep := $(call libpkg,snes ksp dm mat vec sys) 166$(call libname_function,$(LIBDIR)/libpetsctao) : libdep := $(call libpkg,snes ksp dm mat vec sys) 167 168# The package libraries technically depend on each other (not just in an order-only way), but only 169# ABI changes like new or removed symbols requires relinking the dependent libraries. ABI should 170# only occur when a header is changed, which would trigger recompilation and relinking anyway. 171# RELINK=1 causes dependent libraries to be relinked anyway. 172ifeq ($(RELINK),1) 173 libdep_true = $$(libdep) 174 libdep_order = 175else 176 libdep_true = 177 libdep_order = $$(libdep) 178endif 179$(libpetscpkgs_libname) : $(libdep_true) | $(libdep_order) $$(@D)/.DIR 180 $(SHARED_RECIPE) 181ifneq ($(DSYMUTIL),true) 182 $(call quiet,DSYMUTIL) $@ 183endif 184 185%.$(SL_LINKER_SUFFIX) : $(call libname_function,%) | $(call soname_function,%) 186 @ln -sf $(notdir $<) $@ 187 188$(call soname_function,%) : $(call libname_function,%) 189 @ln -sf $(notdir $<) $@ 190 191.PRECIOUS: $(call soname_function,%) 192 193$(OBJDIR)/%.o : src/%.sycl.cxx | $$(@D)/.DIR 194 $(PETSC_COMPILE.sycl.cxx) $(abspath $<) -o $@ 195 196$(OBJDIR)/%.o : src/%.c | $$(@D)/.DIR 197 $(PETSC_COMPILE.c) $(abspath $<) -o $@ 198 199$(OBJDIR)/%.o : src/%.kokkos.cxx | $$(@D)/.DIR 200 $(PETSC_COMPILE.kokkos.cxx) $(abspath $<) -o $@ 201 202$(OBJDIR)/%.o : src/%.cxx | $$(@D)/.DIR 203 $(PETSC_COMPILE.cxx) $(abspath $<) -o $@ 204 205$(OBJDIR)/%.o : src/%.hip.cpp | $$(@D)/.DIR 206 $(PETSC_COMPILE.hip.cpp) $(abspath $<) -o $@ 207 208$(OBJDIR)/%.o : src/%.cu | $$(@D)/.DIR 209 $(PETSC_COMPILE.cu) $(abspath $<) -o $@ # Compile first so that if there is an error, it comes from a normal compile 210 @$(PETSC_GENDEPS.cu) $(abspath $<) -o $(@:%.o=%.d) # Generate the dependencies for later 211 212FCMOD = cd 213$(OBJDIR)/%.o : src/%.F | $$(@D)/.DIR 214ifeq ($(FC_MODULE_OUTPUT_FLAG),) 215 $(call quiet,FCMOD) $(MODDIR) && $(FC) -c $(FC_FLAGS) $(FFLAGS) $(FCPPFLAGS) $(FC_DEPFLAGS) $(abspath $<) -o $(abspath $@) 216else 217 $(PETSC_COMPILE.F) $(abspath $<) -o $@ $(FC_MODULE_OUTPUT_FLAG)$(MODDIR) 218endif 219 -@$(GFORTRAN_DEP_CLEANUP) 220 221$(OBJDIR)/%.o : src/%.F90 | $$(@D)/.DIR 222ifeq ($(FC_MODULE_OUTPUT_FLAG),) 223 $(call quiet,FCMOD) $(MODDIR) && $(FC) -c $(FC_FLAGS) $(FFLAGS) $(FCPPFLAGS) $(FC_DEPFLAGS) $(abspath $<) -o $(abspath $@) 224else 225 $(PETSC_COMPILE.F) $(abspath $<) -o $@ $(FC_MODULE_OUTPUT_FLAG)$(MODDIR) 226endif 227 -@$(GFORTRAN_DEP_CLEANUP) 228 229# Combine with Jacob's massive lint project? 230# Only works with ./configure --with-mpi=0 since clang-tidy cannot find MPI include files (love MPI compiler wrappers, the worse thing to come from MPI) 231$(OBJDIR)/%.tidy : src/%.c | $$(@D)/.DIR 232 clang-tidy --checks="-*analyzer*,-*diagnostic*,bugprone-too-small-loop-variable" $(abspath $<) -- ${CCPPFLAGS} -Wno-implicit-function-declaration -Wno-error=implicit-function-declaration 233 234clang-tidy: $(srcs.tidy) 235 236# Hack: manual dependencies on object files 237ifeq ($(MPI_IS_MPIUNI),1) 238 MPIUNI_MOD := $(MODDIR)/mpiuni.mod 239 $(OBJDIR)/sys/mpiuni/fsrc/somempifort.o : $(OBJDIR)/sys/mpiuni/f90-mod/mpiunimod.o 240endif 241$(OBJDIR)/sys/f90-mod/petscsysmod.o : $(if $(MPIUNI_MOD),$(OBJDIR)/sys/mpiuni/f90-mod/mpiunimod.o) 242$(OBJDIR)/vec/f90-mod/petscvecmod.o : $(OBJDIR)/sys/f90-mod/petscsysmod.o 243$(OBJDIR)/mat/f90-mod/petscmatmod.o : $(OBJDIR)/vec/f90-mod/petscvecmod.o 244$(OBJDIR)/dm/f90-mod/petscdmmod.o : $(OBJDIR)/mat/f90-mod/petscmatmod.o 245$(OBJDIR)/dm/f90-mod/petscdmdamod.o : $(OBJDIR)/dm/f90-mod/petscdmmod.o 246$(OBJDIR)/dm/f90-mod/petscdmplexmod.o : $(OBJDIR)/dm/f90-mod/petscdmmod.o 247$(OBJDIR)/dm/f90-mod/petscdmswarmmod.o : $(OBJDIR)/dm/f90-mod/petscdmmod.o 248$(OBJDIR)/ksp/f90-mod/petsckspdefmod.o : $(OBJDIR)/dm/f90-mod/petscdmplexmod.o 249$(OBJDIR)/ksp/f90-mod/petscpcmod.o : $(OBJDIR)/ksp/f90-mod/petsckspdefmod.o 250$(OBJDIR)/ksp/f90-mod/petsckspmod.o : $(OBJDIR)/ksp/f90-mod/petscpcmod.o 251$(OBJDIR)/snes/f90-mod/petscsnesmod.o : $(OBJDIR)/ksp/f90-mod/petsckspmod.o 252$(OBJDIR)/ts/f90-mod/petsctsmod.o : $(OBJDIR)/snes/f90-mod/petscsnesmod.o 253$(OBJDIR)/tao/f90-mod/petsctaomod.o : $(OBJDIR)/ts/f90-mod/petsctsmod.o 254# F2003 interface 255$(OBJDIR)/sys/objects/f2003-src/fsrc/optionenum.o : $(OBJDIR)/sys/f90-mod/petscsysmod.o 256$(OBJDIR)/sys/classes/bag/f2003-src/fsrc/bagenum.o : $(OBJDIR)/sys/f90-mod/petscsysmod.o 257 258# all sources should get recompiled when petscvariables changes (i.e when configure is rerun or when petscvariables is manually edited.) 259$(srcs.o) : $(petscvariables) 260 261.PHONY: clean all print clang-tidy 262 263clean: 264 ${RM} -r $(OBJDIR) $(LIBDIR)/libpetsc* $(MODDIR)/petsc*.mod $(MPIUNI_MOD) $(generated) 265 266# make print VAR=the-variable 267print: 268 $(info $($(VAR))) 269 @true 270 271 272allobj.d := $(srcs.o:%.o=%.d) 273# Tell make that allobj.d are all up to date. Without this, the include 274# below has quadratic complexity, taking more than one second for a 275# do-nothing build of PETSc (much worse for larger projects) 276$(allobj.d) : ; 277 278gmakeinfo: 279 -@echo "==========================================" 280 -@echo " " 281 -@echo "See documentation/faq.html and documentation/bugreporting.html" 282 -@echo "for help with installation problems. Please send EVERYTHING" 283 -@echo "printed out below when reporting problems. Please check the" 284 -@echo "mailing list archives and consider subscribing." 285 -@echo " " 286 -@echo " https://petsc.org/release/community/mailing/" 287 -@echo " " 288 -@echo "==========================================" 289 -@echo Starting make run on `hostname` at `date +'%a, %d %b %Y %H:%M:%S %z'` 290 -@echo Machine characteristics: `uname -a` 291 -@echo "-----------------------------------------" 292 -@echo "Using PETSc directory: ${PETSC_DIR}" 293 -@echo "Using PETSc arch: ${PETSC_ARCH}" 294 -@echo "-----------------------------------------" 295 -@grep "define PETSC_VERSION" ${PETSC_DIR}/include/petscversion.h | ${SED} "s/........//" | head -n 7 296 -@echo "-----------------------------------------" 297 -@echo "Using configure Options: ${CONFIGURE_OPTIONS}" 298 -@echo "Using configuration flags:" 299 -@grep "\#define " ${PETSCCONF_H} | tail -n +2 300 -@echo "-----------------------------------------" 301 -@echo "Using C compile: ${PETSC_CCOMPILE_SINGLE}" 302 -@if [ "${MPICC_SHOW}" != "" ]; then \ 303 printf "mpicc -show: %b\n" "${MPICC_SHOW}";\ 304 fi; \ 305 printf "C compiler version: %b\n" "${C_VERSION}"; \ 306 if [ "${CXX}" != "" ]; then \ 307 echo "Using C++ compile: ${PETSC_CXXCOMPILE_SINGLE}";\ 308 if [ "${MPICXX_SHOW}" != "" ]; then \ 309 printf "mpicxx -show: %b\n" "${MPICXX_SHOW}"; \ 310 fi;\ 311 printf "C++ compiler version: %b\n" "${Cxx_VERSION}"; \ 312 fi 313 -@if [ "${FC}" != "" ]; then \ 314 echo "Using Fortran compile: ${PETSC_FCOMPILE_SINGLE}";\ 315 if [ "${MPIFC_SHOW}" != "" ]; then \ 316 printf "mpif90 -show: %b\n" "${MPIFC_SHOW}"; \ 317 fi; \ 318 printf "Fortran compiler version: %b\n" "${FC_VERSION}"; \ 319 fi 320 -@if [ "${CUDAC}" != "" ]; then \ 321 echo "Using CUDA compile: ${PETSC_CUCOMPILE_SINGLE}";\ 322 fi 323 -@if [ "${CLANGUAGE}" = "CXX" ]; then \ 324 echo "Using C++ compiler to compile PETSc";\ 325 fi 326 -@echo "-----------------------------------------" 327 -@echo "Using C/C++ linker: ${PCC_LINKER}" 328 -@echo "Using C/C++ flags: ${PCC_LINKER_FLAGS}" 329 -@if [ "${FC}" != "" ]; then \ 330 echo "Using Fortran linker: ${FC_LINKER}";\ 331 echo "Using Fortran flags: ${FC_LINKER_FLAGS}";\ 332 fi 333 -@echo "-----------------------------------------" 334 -@echo "Using system modules: ${LOADEDMODULES}" 335 -@if [ "${MPI_IS_MPIUNI}" = "1" ]; then \ 336 echo Using mpi.h: mpiuni; \ 337 else \ 338 TESTDIR=`mktemp -q -d -t petscmpi-XXXXXXXX` && \ 339 echo '#include <mpi.h>' > $${TESTDIR}/mpitest.c && \ 340 BUF=`${CPP} ${PETSC_CPPFLAGS} ${PETSC_CC_INCLUDES} $${TESTDIR}/mpitest.c |grep 'mpi\.h' | ( head -1 ; cat > /dev/null )` && \ 341 echo Using mpi.h: $${BUF}; ${RM} -rf $${TESTDIR}; \ 342 fi 343 -@echo "-----------------------------------------" 344 -@echo "Using libraries: ${PETSC_LIB}" 345 -@echo "------------------------------------------" 346 -@echo "Using mpiexec: ${MPIEXEC}" 347 -@echo "------------------------------------------" 348 -@echo "Using MAKE: ${MAKE}" 349 -@echo "Default MAKEFLAGS: MAKE_NP:${MAKE_NP} MAKE_LOAD:${MAKE_LOAD} MAKEFLAGS:${MAKEFLAGS}" 350 -@echo "==========================================" 351 352-include $(allobj.d) 353