1#
2# make -j 16 sopt popt ssmp psmp
3#
4# will now perform a parallel build of 4 cp2k executables
5#
6SHELL = /bin/sh
7#
8# the home dir is taken from the current directory.
9ifeq ($(CP2KHOME),)
10CP2KHOME     := $(abspath $(shell pwd))
11export CP2KHOME
12endif
13
14ifneq ($(SPACK_COMPILER_SPEC),)
15 # SPACK_COMPILER_SPEC is set when running in a Spack build-env
16 XARCH         := $(shell spack arch)-$(shell echo $${SPACK_COMPILER_SPEC%%@*})
17else
18 XARCH         := local
19endif
20
21export VERSION=sopt
22
23MAKEFILE     := $(CP2KHOME)/Makefile
24ARCHDIR      := $(CP2KHOME)/arch
25DOXYGENDIR   := $(CP2KHOME)/doc/doxygen
26DATA_DIR     := $(CP2KHOME)/data
27MAINEXEDIR   := $(CP2KHOME)/exe
28MAINLIBDIR   := $(CP2KHOME)/lib
29MAINOBJDIR   := $(CP2KHOME)/obj
30MAINTSTDIR   := $(CP2KHOME)/regtesting
31PRETTYOBJDIR := $(CP2KHOME)/obj/prettified
32DOXIFYOBJDIR := $(CP2KHOME)/obj/doxified
33TOOLSRC      := $(CP2KHOME)/tools
34SRCDIR       := $(CP2KHOME)/src
35EXEDIR       := $(MAINEXEDIR)/$(XARCH)
36REVISION     := $(shell $(CP2KHOME)/tools/build_utils/get_revision_number $(SRCDIR))
37
38EXTSDIR      := exts
39EXTSHOME     := $(CP2KHOME)/$(EXTSDIR)
40EXTSPACKAGES := $(shell cd $(EXTSHOME) ; find * -maxdepth 0 -type d )
41
42PYTHON       := /usr/bin/env python
43
44# Common Targets ============================================================
45default_target: all
46
47# Discover programs =========================================================
48ifeq ($(ALL_EXE_FILES),)
49export ALL_EXE_FILES := $(sort $(shell $(TOOLSRC)/build_utils/discover_programs.py $(SRCDIR)))
50endif
51EXE_NAMES := $(basename $(notdir $(ALL_EXE_FILES)))
52
53# Once we are down to a single version ======================================
54# this only happens on stage 3 and 4
55ifneq ($(ONEVERSION),)
56MODDEPS = "lower"
57include $(ARCHDIR)/$(XARCH).$(ONEVERSION)
58LIBDIR  := $(MAINLIBDIR)/$(XARCH)/$(ONEVERSION)
59LIBEXTSDIR := $(LIBDIR)/$(EXTSDIR)
60OBJDIR  := $(MAINOBJDIR)/$(XARCH)/$(ONEVERSION)
61OBJEXTSDIR := $(OBJDIR)/$(EXTSDIR)
62OBJEXTSINCL := $(foreach dir,$(EXTSPACKAGES),-I'$(OBJEXTSDIR)/$(dir)')
63TSTDIR     := $(MAINTSTDIR)/$(XARCH)/$(ONEVERSION)
64ifeq ($(NVCC),)
65EXE_NAMES := $(basename $(notdir $(filter-out %.cu, $(ALL_EXE_FILES))))
66endif
67ifneq ($(LD_SHARED),)
68 ARCHIVE_EXT := .so
69else
70 ARCHIVE_EXT := .a
71endif
72include $(EXTSHOME)/Makefile.inc
73endif
74
75# Declare PHONY targets =====================================================
76.PHONY : $(VERSION) $(EXE_NAMES) \
77         dirs makedep default_target all \
78         toolversions extversions extclean libcp2k cp2k_shell exts python-bindings \
79         doxify doxifyclean \
80         pretty prettyclean doxygen/clean doxygen \
81         install clean realclean distclean mrproper help \
82         test testbg testclean testrealclean \
83         data \
84	 $(EXTSPACKAGES)
85
86# Discover files and directories ============================================
87ALL_SRC_DIRS := $(shell find $(SRCDIR) -type d ! -name preprettify | awk '{printf("%s:",$$1)}')
88ALL_PREPRETTY_DIRS = $(shell find $(SRCDIR) -type d -name preprettify)
89
90ALL_PKG_FILES  = $(shell find $(SRCDIR) ! -path "*/preprettify/*" -name "PACKAGE")
91OBJ_SRC_FILES  = $(shell cd $(SRCDIR); find . ! -path "*/preprettify/*" -name "*.F")
92OBJ_SRC_FILES += $(shell cd $(SRCDIR); find . ! -path "*/preprettify/*" ! -path "*/python*" -name "*.c")
93OBJ_SRC_FILES += $(shell cd $(SRCDIR); find . ! -path "*/preprettify/*" -name "*.cpp")
94OBJ_SRC_FILES += $(shell cd $(SRCDIR); find . ! -path "*/preprettify/*" -name "*.cxx")
95OBJ_SRC_FILES += $(shell cd $(SRCDIR); find . ! -path "*/preprettify/*" -name "*.cc")
96ifneq ($(NVCC),)
97OBJ_SRC_FILES += $(shell cd $(SRCDIR); find . ! -path "*/preprettify/*" -name "*.cu")
98endif
99
100# Included files used by Fypp preprocessor and standard includes
101INCLUDED_SRC_FILES = $(filter-out base_uses.f90, $(notdir $(shell find $(SRCDIR) ! -path "*/preprettify/*" -name "*.f90")))
102
103# Include also source files which won't compile into an object file
104ALL_SRC_FILES  = $(strip $(subst $(NULL) .,$(NULL) $(SRCDIR),$(NULL) $(OBJ_SRC_FILES)))
105ALL_SRC_FILES += $(filter-out base_uses.f90, $(shell find $(SRCDIR) ! -path "*/preprettify/*" -name "*.f90"))
106ALL_SRC_FILES += $(shell find $(SRCDIR) ! -path "*/preprettify/*" -name "*.h")
107ALL_SRC_FILES += $(shell find $(SRCDIR) ! -path "*/preprettify/*" -name "*.hpp")
108ALL_SRC_FILES += $(shell find $(SRCDIR) ! -path "*/preprettify/*" -name "*.hxx")
109ALL_SRC_FILES += $(shell find $(SRCDIR) ! -path "*/preprettify/*" -name "*.hcc")
110
111ALL_OBJECTS        = $(addsuffix .o, $(basename $(notdir $(OBJ_SRC_FILES))))
112ALL_EXE_OBJECTS    = $(addsuffix .o, $(EXE_NAMES))
113ALL_NONEXE_OBJECTS = $(filter-out $(ALL_EXE_OBJECTS), $(ALL_OBJECTS))
114
115# stage 1: Call make recursively with each element in $(VERSION) as a target,
116#          The actual target is stored in ORIG_TARGET.
117#          Make can then parallelize over multiple versions targets.
118ifeq ($(ONEVERSION),)
119ORIG_TARGET = default_target
120
121fes:
122	@+$(MAKE) --no-print-directory -f $(MAKEFILE) $(VERSION) ORIG_TARGET=graph
123
124$(EXE_NAMES) all toolversions extversions extclean libcp2k cp2k_shell exts $(EXTSPACKAGES) python-bindings test testbg:
125	@+$(MAKE) --no-print-directory -f $(MAKEFILE) $(VERSION) ORIG_TARGET=$@
126
127# stage 2: Store the version target in $(ONEVERSION),
128#          Call make recursively with $(ORIG_TARGET) as target.
129$(VERSION) :
130	@+$(MAKE) --no-print-directory -f $(MAKEFILE) $(ORIG_TARGET) ORIG_TARGET="" VERSION="" ONEVERSION=$@
131
132else
133
134# stage 3: Include arch-file, create dirs, and run makedep.py for given $(ONEVERSION).
135#          Afterwards, call make recursively again with -C $(OBJDIR) and INCLUDE_DEPS=true
136ifeq ($(INCLUDE_DEPS),)
137$(EXE_NAMES): makedep | dirs exts
138	@+$(MAKE) --no-print-directory -C $(OBJDIR) -f $(MAKEFILE) $(EXEDIR)/$@.$(ONEVERSION) INCLUDE_DEPS=true
139
140all: makedep | dirs exts
141	@+$(MAKE) --no-print-directory -C $(OBJDIR) -f $(MAKEFILE) all INCLUDE_DEPS=true
142
143# foreground testing, compilation happens in do_regtest
144test: dirs
145	cd $(TSTDIR); $(TOOLSRC)/regtesting/do_regtest -quick -arch $(XARCH) -version $(ONEVERSION) -cp2kdir ../../../  $(TESTOPTS)
146
147# background testing, compilation happens here
148testbg: dirs makedep all
149	@+$(MAKE) --no-print-directory -C $(TSTDIR) -f $(MAKEFILE) testbg INCLUDE_DEPS=true
150
151libcp2k: makedep | dirs exts
152	@+$(MAKE) --no-print-directory -C $(OBJDIR) -f $(MAKEFILE) $(LIBDIR)/libcp2k$(ARCHIVE_EXT) INCLUDE_DEPS=true
153
154python-bindings: libcp2k
155	@cd $(SRCDIR)/start/python ; \
156		env CC='$(CC)' LDSHARED='$(LD) -shared' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS) $(LDFLAGS_C) $(LIBS)' \
157			$(PYTHON) setup.py build_ext \
158				--build-temp="$(OBJDIR)/python" \
159				--build-lib="$(LIBDIR)/python" \
160				--library-dirs="$(LIBDIR)" \
161				--libraries="$(patsubst -l%,%,$(filter -l%,$(LIBS)))"
162
163exts: $(EXTSPACKAGES)
164
165dirs:
166	@mkdir -p $(OBJDIR)
167	@mkdir -p $(OBJEXTSDIR)
168	@mkdir -p $(LIBDIR)
169	@mkdir -p $(LIBEXTSDIR)
170	@mkdir -p $(EXEDIR)
171	@mkdir -p $(TSTDIR)
172
173toolversions:
174ifneq ($(FC),)
175	@echo "=========== FC ($(ONEVERSION)) ==========="
176ifeq (Cray,$(shell $(CC) -V 2>&1 | head -n1 | cut -d' ' -f1))
177	$(FC) -V
178else ifeq (IBM,$(shell $(CC) -qversion 2>&1 | head -n1 | cut -d' ' -f1))
179	$(FC) -qversion
180else
181	$(FC) --version
182endif
183endif
184ifneq ($(CC),)
185	@echo "=========== CC ($(ONEVERSION)) ==========="
186ifeq (Cray,$(shell $(CC) -V 2>&1 | head -n1 | cut -d' ' -f1))
187	$(CC) -V
188else ifeq (IBM,$(shell $(CC) -qversion 2>&1 | head -n1 | cut -d' ' -f1))
189	$(CC) -qversion
190else
191	$(CC) --version
192endif
193endif
194ifneq ($(NVCC),)
195	@echo "========== NVCC ($(ONEVERSION)) =========="
196	$(NVCC) --version
197	@echo ""
198endif
199ifneq ($(AR),)
200	@echo "=========== AR ($(ONEVERSION)) ==========="
201	$(firstword $(AR)) V
202	@echo ""
203endif
204	@echo "========== Make ($(ONEVERSION)) =========="
205	$(MAKE) --version
206	@echo ""
207	@echo "========= Python ($(ONEVERSION)) ========="
208	$(PYTHON) --version
209
210else
211
212# Force CP2K recompilations if exts are updated
213$(ALL_OBJECTS): $(EXTSDEPS_MOD)
214$(ALL_EXE_OBJECTS): $(EXTSDEPS_LIB)
215
216# stage 4: Include $(OBJDIR)/all.dep, expand target all and libcp2k, and perform actual build.
217all: $(foreach e, $(EXE_NAMES) cp2k_shell, $(EXEDIR)/$(e).$(ONEVERSION))
218$(LIBDIR)/libcp2k$(ARCHIVE_EXT) : $(ALL_NONEXE_OBJECTS)
219
220$(EXEDIR)/cp2k_shell.$(ONEVERSION): $(EXEDIR)/cp2k.$(ONEVERSION)
221	cd $(EXEDIR); ln -sf cp2k.$(ONEVERSION) cp2k_shell.$(ONEVERSION)
222
223testbg:
224	@echo "testing: $(ONEVERSION) : full log in $(TSTDIR)/regtest.log "
225	@$(TOOLSRC)/regtesting/do_regtest -nobuild $(XARCH) -version $(ONEVERSION) -cp2kdir ../../../  $(TESTOPTS) >& $(TSTDIR)/regtest.log
226	@cat `grep 'regtesting location error_summary file:' $(TSTDIR)/regtest.log | awk '{print $$NF}'`
227	@cat `grep 'regtesting location summary file:' $(TSTDIR)/regtest.log | awk '{print $$NF}'`
228	@grep "Number of FAILED  tests 0" $(TSTDIR)/regtest.log >& /dev/null
229	@grep "Number of WRONG   tests 0" $(TSTDIR)/regtest.log >& /dev/null
230
231endif
232endif
233
234OTHER_HELP += "test : run the regression tests"
235OTHER_HELP += "testbg : run the regression tests in background"
236
237OTHER_HELP += "toolversions : Print versions of build tools"
238
239OTHER_HELP += "extversions : Print versions of external modules"
240OTHER_HELP += "extclean : Clean build of external modules"
241
242#   extract help text from doxygen "\brief"-tag
243help:
244	@echo "=================== Binaries ===================="
245	@echo "all                         Builds all executables (default target)"
246	@for i in $(ALL_EXE_FILES); do \
247	basename  $$i | sed 's/^\(.*\)\..*/\1/' | awk '{printf "%-28s", $$1}'; \
248	grep "brief" $$i | head -n 1 | sed 's/^.*\\brief\s*//'; \
249	done
250	@echo "libcp2k                     Builds CP2K as a single library archive"
251	@echo "cp2k_shell                  Creates symlink for backward compatibility"
252	@echo ""
253	@echo "===================== Tools ====================="
254	@printf "%s\n" $(TOOL_HELP) | awk -F ':' '{printf "%-28s%s\n", $$1, $$2}'
255	@echo ""
256	@echo "================= Other Targets ================="
257	@printf "%s\n" $(OTHER_HELP) | awk -F ':' '{printf "%-28s%s\n", $$1, $$2}'
258	@echo "help                         Print this help text"
259
260#
261# so far CP2K does not install, but give a hint to the user
262#
263install:
264	@echo ""
265	@echo "The CP2K executable is $(foreach v, $(VERSION), $(EXEDIR)/cp2k.$(v))"
266	@echo ""
267OTHER_HELP += "install : Print installation help"
268
269#
270# delete the intermediate files, but not the libraries and executables, or created directories.
271# Most useful to save space on the disk or e.g. for recompiles with PGO that still needs the .gcda files in the objdir
272#
273# To avoid printing out all non-gcda files within a directory with 'make clean',
274# a list of all non-gcda file extensions within a directory is first created with the get_extensions macro,
275# and a wildcard expression is then used to remove the appropriate files
276# cleaning stuff ============================================================
277define get_extensions
278	$(shell test -d $(1) && find $(1) -type f -name "*.*" ! -name "*.gcda" | sed 's|.*\.||' | sort -u)
279endef
280clean:
281	@echo rm -rf $(foreach v, $(VERSION), $(MAINOBJDIR)/$(XARCH)/$(v))
282	@$(foreach v, $(VERSION), $(foreach ext, $(call get_extensions, $(MAINOBJDIR)/$(XARCH)/$(v)/), $(shell rm -rf $(MAINOBJDIR)/$(XARCH)/$(v)/*.$(ext))))
283	rm -rf $(foreach v, $(VERSION), $(MAINLIBDIR)/$(XARCH)/$(v))
284OTHER_HELP += "clean : Remove intermediate object and mod files, but not the libraries and executables, for given XARCH and VERSION"
285
286execlean:
287	rm -rf $(foreach v, $(VERSION), $(EXEDIR)/*.$(v))
288OTHER_HELP += "execlean : Remove the executables, for given XARCH and VERSION"
289
290#
291# delete the intermediate files, the programs and libraries and anything that might be in the objdir or libdir directory
292# Use this if you want to fully rebuild an executable (for a given compiler and or VERSION)
293#
294realclean: extclean clean execlean
295	rm -rf $(foreach v, $(VERSION), $(MAINOBJDIR)/$(XARCH)/$(v))
296	rm -rf $(foreach v, $(VERSION), $(MAINLIBDIR)/$(XARCH)/$(v))
297OTHER_HELP += "realclean : Remove all files for given XARCH and VERSION"
298
299testclean:
300	rm -rf $(foreach v, $(VERSION), $(MAINTSTDIR)/$(XARCH)/$(v)/TEST-*)
301OTHER_HELP += "testclean : Remove all TEST-* files for given XARCH and VERSION"
302
303testrealclean: testclean
304	rm -rf $(foreach v, $(VERSION), $(MAINTSTDIR)/$(XARCH)/$(v)/LAST-*)
305OTHER_HELP += "testrealclean : Remove all LAST-* and TEST-* files for given XARCH and VERSION"
306
307#
308# Remove all files from previous builds
309#
310distclean: prettyclean doxifyclean testrealclean
311	rm -rf $(DOXYGENDIR) $(MAINEXEDIR) $(MAINOBJDIR) $(MAINLIBDIR) $(MAINTSTDIR)
312OTHER_HELP += "distclean : Remove all files from previous builds"
313
314# Prettyfier stuff ==========================================================
315vpath %.pretty $(PRETTYOBJDIR)
316
317pretty: $(addprefix $(PRETTYOBJDIR)/, $(ALL_OBJECTS:.o=.pretty)) $(addprefix $(PRETTYOBJDIR)/, $(INCLUDED_SRC_FILES:.f90=.pretty_included))
318TOOL_HELP += "pretty : Reformat all source files in a pretty way."
319
320prettyclean:
321	-rm -rf $(PRETTYOBJDIR) $(ALL_PREPRETTY_DIRS)
322TOOL_HELP += "prettyclean : Remove prettify marker files and preprettify directories"
323
324$(PRETTYOBJDIR)/%.pretty: %.F $(DOXIFYOBJDIR)/%.doxified
325	@mkdir -p $(PRETTYOBJDIR)
326	cd $(dir $<); $(TOOLSRC)/prettify/prettify.py --do-backup --backup-dir=$(PRETTYOBJDIR) $(notdir $<)
327	@touch $@
328
329$(PRETTYOBJDIR)/%.pretty_included: %.f90 $(DOXIFYOBJDIR)/%.doxified_included
330	@mkdir -p $(PRETTYOBJDIR)
331	cd $(dir $<); $(TOOLSRC)/prettify/prettify.py --do-backup --backup-dir=$(PRETTYOBJDIR) $(notdir $<)
332	@touch $@
333
334$(PRETTYOBJDIR)/%.pretty: %.c $(DOXIFYOBJDIR)/%.doxified
335#   TODO: call indent here?
336	@mkdir -p $(PRETTYOBJDIR)
337	@touch $@
338
339$(PRETTYOBJDIR)/%.pretty: %.cpp $(DOXIFYOBJDIR)/%.doxified
340#   TODO: call indent here?
341	@mkdir -p $(PRETTYOBJDIR)
342	@touch $@
343
344# Doxyifier stuff ===========================================================
345vpath %.doxified $(DOXIFYOBJDIR)
346
347doxify: $(addprefix $(DOXIFYOBJDIR)/, $(ALL_OBJECTS:.o=.doxified)) $(addprefix $(DOXIFYOBJDIR)/, $(INCLUDED_SRC_FILES:.f90=.doxified_included))
348TOOL_HELP += "doxify : Autogenerate doxygen headers for subroutines"
349
350doxifyclean:
351	-rm -rf $(DOXIFYOBJDIR)
352TOOL_HELP += "doxifyclean : Remove doxify marker files"
353
354$(DOXIFYOBJDIR)/%.doxified: %.F
355	$(TOOLSRC)/doxify/doxify.sh $<
356	@mkdir -p $(DOXIFYOBJDIR)
357	@touch $@
358
359$(DOXIFYOBJDIR)/%.doxified_included: %.f90
360	$(TOOLSRC)/doxify/doxify.sh $<
361	@mkdir -p $(DOXIFYOBJDIR)
362	@touch $@
363
364$(DOXIFYOBJDIR)/%.doxified: %.c
365	@mkdir -p $(DOXIFYOBJDIR)
366	@touch $@
367
368$(DOXIFYOBJDIR)/%.doxified: %.cpp
369	@mkdir -p $(DOXIFYOBJDIR)
370	@touch $@
371
372# doxygen stuff =============================================================
373doxygen/clean:
374	-rm -rf $(DOXYGENDIR)
375TOOL_HELP += "doxygen/clean : Remove the generated doxygen documentation"
376
377# Automatic source code documentation using Doxygen
378# Prerequisites:
379# - stable doxygen release 1.5.4 (Oct. 27, 2007)
380# - graphviz (2.16.1)
381# - webdot (2.16)
382#
383doxygen: doxygen/clean
384	@mkdir -p $(DOXYGENDIR)
385	@mkdir -p $(DOXYGENDIR)/html
386	@echo "<html><body>Sorry, the Doxygen documentation is currently being updated. Please try again in a few minutes.</body></html>" > $(DOXYGENDIR)/html/index.html
387	cp $(ALL_SRC_FILES) $(DOXYGENDIR)
388	@for i in $(DOXYGENDIR)/*.F ; do mv $${i}  $${i%%.*}.f90; done ;
389	@sed -e "s/#revision#/$(REVISION)/" $(TOOLSRC)/doxify/Doxyfile.template >$(DOXYGENDIR)/Doxyfile
390	cd $(DOXYGENDIR); doxygen ./Doxyfile 2>&1 | tee ./html/doxygen.out
391TOOL_HELP += "doxygen : Generate the doxygen documentation"
392
393# data stuff ================================================================
394data: data/POTENTIAL
395	@:
396
397data/POTENTIAL: data/GTH_POTENTIALS data/HF_POTENTIALS data/NLCC_POTENTIALS data/ALL_POTENTIALS
398	@echo "(re-)generating $@ ..."
399	@cat $^ > $@
400
401OTHER_HELP += "data : (re-)generate merged data files (e.g. data/POTENTIALS)"
402
403# automatic dependency generation ===========================================
404MAKEDEPMODE = "normal"
405ifeq ($(HACKDEP),yes)
406MAKEDEPMODE = "hackdep"
407else
408 ifneq ($(MC),)
409 MAKEDEPMODE = "mod_compiler"
410 endif
411endif
412
413# this happens on stage 3
414makedep: $(ALL_SRC_FILES) $(ALL_PKG_FILES) dirs
415ifeq ($(LD_SHARED),)
416	@echo "Removing stale archives for $(ONEVERSION) ... "
417	@$(TOOLSRC)/build_utils/check_archives.py $(firstword $(AR)) $(SRCDIR) $(LIBDIR)
418endif
419	@echo "Resolving dependencies for $(ONEVERSION) ... "
420	@$(TOOLSRC)/build_utils/makedep.py $(OBJDIR)/all.dep cp2k $(MODDEPS) $(MAKEDEPMODE) $(ARCHIVE_EXT) $(SRCDIR) $(OBJ_SRC_FILES)
421
422# on stage 4, load the rules generated by makedep.py
423ifeq ($(INCLUDE_DEPS), true)
424include $(OBJDIR)/all.dep
425endif
426
427
428# ================= Stuff need for compiling (stage 4) ======================
429# These rules are executed in a recursive call to make -C $(OBJDIR)
430# The change of $(CURDIR) allows to find targets without abs paths and vpaths.
431
432
433### Slave rules ###
434vpath %.F     $(ALL_SRC_DIRS)
435vpath %.h     $(ALL_SRC_DIRS)
436vpath %.f90   $(ALL_SRC_DIRS)
437vpath %.cu    $(ALL_SRC_DIRS)
438vpath %.c     $(ALL_SRC_DIRS)
439vpath %.cpp   $(ALL_SRC_DIRS)
440vpath %.cxx   $(ALL_SRC_DIRS)
441vpath %.cc    $(ALL_SRC_DIRS)
442
443#
444# Add additional dependency of cp2k_info.F to git-HEAD.
445# Ensuring that cp2k prints the correct source code revision number in its banner.
446#
447GIT_REF := ${MAINOBJDIR}/git-ref
448
449# use a force (fake) target to always rebuild this file but have Make consider this updated
450# iff it was actually rewritten (a .PHONY target is always considered new)
451$(GIT_REF): FORCE
452	echo $(REVISION) > "$@.tmp"
453	@cmp "$@.tmp" "$@" || mv -f "$@.tmp" "$@"
454
455FORCE: ;
456
457cp2k_info.o: $(GIT_REF)
458
459# Add some practical metadata about the build.
460FCFLAGS += -D__COMPILE_ARCH="\"$(XARCH)\""\
461           -D__COMPILE_DATE="\"$(shell date)\""\
462           -D__COMPILE_HOST="\"$(shell hostname)\""\
463           -D__COMPILE_REVISION="\"$(strip $(REVISION))\""\
464           -D__DATA_DIR="\"$(DATA_DIR)\""
465
466# $(FCLOGPIPE) can be used to store compiler output, e.g. warnings, for each F-file separately.
467# This is used e.g. by the convention checker.
468
469FYPPFLAGS ?= -n
470
471%.o: %.F
472	$(TOOLSRC)/build_utils/fypp $(FYPPFLAGS) $< $*.F90
473	$(FC) -c $(FCFLAGS) -D__SHORT_FILE__="\"$(subst $(SRCDIR)/,,$<)\"" -I'$(dir $<)' $(OBJEXTSINCL) $*.F90 $(FCLOGPIPE)
474
475%.o: %.c
476	$(CC) -c $(CFLAGS) $<
477
478%.o: %.cpp
479	$(CXX) -c $(CXXFLAGS) $<
480
481ifneq ($(LIBDIR),)
482$(LIBDIR)/%:
483ifneq ($(LD_SHARED),)
484	@echo "Creating shared library $@"
485	@$(LD_SHARED) $(LDFLAGS) -o $(@:.a=.so) $^ $(LIBS)
486else
487	@echo "Updating archive $@"
488	@$(AR) $@ $?
489endif
490ifneq ($(RANLIB),)
491	@$(RANLIB) $@
492endif
493endif
494
495%.o: %.cu
496	$(NVCC) -c $(NVFLAGS) $<
497
498
499# module compiler magic =====================================================
500ifeq ($(MC),)
501#
502# here we cheat... this tells make that .mod can be generated from .o (this holds in CP2K) by doing nothing
503# it avoids recompilation if .o is more recent than .F, but .mod is older than .F
504# (because it didn't change, as e.g. g95 can do)
505#
506# this is problematic if the module names are uppercase e.g. KINDS.mod (because this rule expands to kinds.mod)
507#
508%.mod: %.o
509	@true
510else
511#
512# if MC is defined, it is our 'module compiler' which generates the .mod file from the source file
513# it is useful in a two-stage compile.
514#
515%.mod: %.F
516	$(MC) -c $(FCFLAGS) -D__SHORT_FILE__="\"$(subst $(SRCDIR)/,,$<)\"" $<
517endif
518
519#EOF
520