-
Notifications
You must be signed in to change notification settings - Fork 0
/
gmakefile
178 lines (139 loc) · 5.59 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
# -*- mode: makefile-gmake -*-
TDYCORE_DIR ?= $(CURDIR)
include ./lib/tdycore/conf/variables
OBJDIR := $(PETSC_ARCH)/obj
MODDIR := $(PETSC_ARCH)/include
LIBDIR := $(abspath $(PETSC_ARCH)/lib)
libtdycore_shared := $(LIBDIR)/libtdycore.$(SL_LINKER_SUFFIX)
libtdycore_static := $(LIBDIR)/libtdycore.$(AR_LIB_SUFFIX)
libtdycore := $(if $(filter-out no,$(BUILDSHAREDLIB)),$(libtdycore_shared),$(libtdycore_static))
pkgs := tdycore
srcs-tdycore.c := $(wildcard src/fv/share/*.c src/fv/mpfao/*.c src/fv/fvtpf/*.c src/fe/*.c src/materials/*.c src/*.c src/f90-mod/*.c)
srcs-tdycore.cxx := $(wildcard src/*.cxx)
srcs-tdycore.F90 := $(wildcard src/f90-mod/*.F90)
all : $(libtdycore)
.SECONDEXPANSION: # to expand $$(@D)/.DIR
# check missing Fortran compiler
ifeq ($(FC),)
$(info GNU Make build requires PETSc with Fortran support)
$(info Try using CMake build with 'make all-cmake')
$(error '')
endif
# workaround old Cygwin versions
ifeq ($(PETSC_CYGWIN_BROKEN_PIPE),1)
ifeq ($(shell basename $(AR)),ar)
V ?= 1
endif
endif
ifeq ($(V),) # Print help and short compile line
quiet_HELP := "Use \"$(MAKE) V=1\" to see the verbose compile lines.\n"
quiet = @printf $(quiet_HELP)$(eval quiet_HELP:=)" %10s %s\n" "$1$2" "$@"; $($1)
else ifeq ($(V),0) # Same as previous, but do not print any help
quiet = @printf " %10s %s\n" "$1$2" "$@"; $($1)
else # Show the full command line
quiet = $($1)
endif
pcc = $(if $(findstring CONLY,$(PETSC_LANGUAGE)),CC,CXX)
COMPILE.c = $(call quiet,$(pcc)) $(PCC_FLAGS) $(CFLAGS) $(CCPPFLAGS) $(C_DEPFLAGS) -c
COMPILE.cxx = $(call quiet,CXX) $(CXX_FLAGS) $(CFLAGS) $(CCPPFLAGS) $(CXX_DEPFLAGS) -c
ifneq ($(FC_MODULE_OUTPUT_FLAG),)
COMPILE.fc = $(call quiet,FC) $(FC_FLAGS) $(FFLAGS) $(FCPPFLAGS) $(FC_DEPFLAGS) $(FC_MODULE_OUTPUT_FLAG)$(MODDIR) -c
else
FCMOD = cd $(MODDIR) && $(FC)
COMPILE.fc = $(call quiet,FCMOD) $(FC_FLAGS) $(FFLAGS) $(FCPPFLAGS) $(FC_DEPFLAGS) -c
endif
langs := c cxx F90
concatlangs = $(foreach lang, $(langs), $(srcs-$(1).$(lang):%.$(lang)=$(OBJDIR)/%.o))
srcs.o := $(foreach pkg, $(pkgs), $(call concatlangs,$(pkg)))
.SECONDARY: $(srcs.o)
$(libtdycore_shared) : objs := $(sort $(srcs.o))
$(libtdycore_shared) : libs := $(PETSC_LIB)
$(libtdycore_static) : objs := $(sort $(srcs.o))
%.$(SL_LINKER_SUFFIX) : $$(objs) | $$(@D)/.DIR
$(call quiet,CLINKER) -shared -o $@ $^ $(libs)
ifneq ($(DSYMUTIL),true)
$(call quiet,DSYMUTIL) $@
endif
%.$(AR_LIB_SUFFIX) : $$(objs) | $$(@D)/.DIR
ifeq ($(findstring win32fe lib,$(AR)),)
@$(RM) $@
$(call quiet,AR) $(AR_FLAGS) $@ $^
$(call quiet,RANLIB) $@
else
@$(RM) $@ [email protected]
@cygpath -w $^ > [email protected]
$(call quiet,AR) $(AR_FLAGS) $@ @[email protected]
@$(RM) [email protected]
endif
$(OBJDIR)/%.o : %.c | $$(@D)/.DIR
$(COMPILE.c) $(abspath $<) -o $@
$(OBJDIR)/%.o : %.cxx | $$(@D)/.DIR
$(COMPILE.cxx) $(abspath $<) -o $@
$(OBJDIR)/%.o : %.F90 | $$(@D)/.DIR $(MODDIR)/.DIR
$(COMPILE.fc) $(abspath $<) -o $(if $(FCMOD),$(abspath $@),$@)
TEST.c = \
demo/steady/steady.c \
demo/transient/transient.c
TEST.F90 = \
demo/transient/transient_mpfaof90.F90 \
demo/transient/transient_snes_mpfaof90.F90
# Demo executables
$(TEST.c:%.c=%.o) : %.o : %.c
$(COMPILE.c) $(abspath $<) -o $@
$(TEST.c:%.c=%) : demo/% : demo/%.o $$^ $(libtdycore)
$(call quiet,CLINKER) -o $@ $^ $(TDYCORE_LIB) $(LIBS)
$(TEST.F90:%.F90=%.o) : MODDIR = $(PETSC_ARCH)/obj/demo-modules
$(TEST.F90:%.F90=%.o) : %.o : %.F90 $(libtdycore) | $$(@D)/.DIR $$(MODDIR)/.DIR
$(COMPILE.fc) $(abspath $<) -o $(if $(FCMOD),$(abspath $@),$@)
$(TEST.F90:%.F90=%) : demo/% : demo/%.o $$^ $(libtdycore)
$(call quiet,FLINKER) -o $@ $^ $(TDYCORE_LIB) $(LIBS)
# Hack: manual dependencies on object files
tdycore.mod.o:= $(OBJDIR)/src/tdycore.o
srcs-tdycore.F90.o = $(srcs-tdycore.F90:%.F90=$(OBJDIR)/%.o)
$(filter-out $(tdycore.mod.o),$(srcs-tdycore.F90.o)): | $(tdycore.mod.o)
%/.DIR :
@$(MKDIR) $(@D)
@touch $@
.PRECIOUS: %/.DIR
.SUFFIXES: # Clear .SUFFIXES because we don't use implicit rules
.DELETE_ON_ERROR: # Delete likely-corrupt target file if rule fails
.PHONY: all clean print print-%
clean:
@$(RM) -r $(OBJDIR) $(LIBDIR)/libtdycore.* $(MODDIR)/tdycore.mod
testname = test-$(subst _,-,$(basename $(notdir $(1))))
ALLTESTS = $(foreach path,$(TEST.c) $(TEST.F90),$(call testname,$(path)))
# Set target-specific variables for each test
define target_specific_var
$(call testname,$(1)) : DEMO_EXE = $(basename $(1))
endef
$(foreach demo_src,$(TEST.c) $(TEST.F90),$(eval $(call target_specific_var,$(demo_src))))
$(ALLTESTS) : test-% : $$(DEMO_EXE)
+@$(MAKE) -C regression_tests $@
# CMocka support for unit tests (via pkg-config).
CMOCKA_CFLAGS := $(shell pkg-config cmocka --cflags --silence-errors)
CMOCKA_LDFLAGS := $(shell pkg-config cmocka --libs --silence-errors)
ifneq ($(CMOCKA_LDFLAGS),) # begin unit tests
# Unit test source files
UTEST.c = \
src/tests/test_tdyinit.c \
src/tests/test_mesh_labels.c \
# Compile the unit tests
$(UTEST.c:%.c=%.o) : %.o : %.c src/tests/tdycore_tests.h
$(COMPILE.c) $(CMOCKA_CFLAGS) -Isrc/tests $(abspath $<) -o $@
# Link the unit tests into executables
$(UTEST.c:%.c=%) : % : %.o $$^ $(libtdycore)
$(call quiet,CLINKER) -o $@ $^ $(CMOCKA_LDFLAGS) $(TDYCORE_LIB) $(LIBS)
unit-tests : % : $(UTEST.c:%.c=%)
+@find src -name "test_*" -executable -exec env MPIEXEC="$(MPIEXEC)" ./src/tests/run_unit_tests.sh {} \+
UNITTESTS=unit-tests
endif # cmocka unit tests
test : $(UNITTESTS) $(ALLTESTS)
# make print VAR=the-variable
print : ; @echo $($(VAR))
# make print-VARIABLE
print-% : ; @echo $* = $($*)
allobj.d := $(srcs.o:%.o=%.d)
# Tell make that allobj.d are all up to date. Without
# this, the include below has quadratic complexity.
$(allobj.d) : ;
-include $(allobj.d)