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