xref: /petsc/gmakefile (revision b20fdbb7553396225066375608129ac135b5f21f)
1# -*- mode: makefile-gmake -*-
2
3include $(PETSC_DIR)/conf/variables
4
5OBJDIR := $(PETSC_ARCH)/obj-gmake
6LIBDIR := $(PETSC_ARCH)/lib
7
8all : $(LIBDIR)/libpetsc.so
9
10.SECONDEXPANSION:		# to expand $$(@D)/.DIR
11
12ifeq ($(V),)
13  quiet_HELP := "Use \"$(MAKE) V=1\" to see the verbose compile lines.\n"
14  quiet = @printf $(quiet_HELP)$(eval quiet_HELP:=)"  $1$2 $@\n"; $($1)
15else ifeq ($(V),0)		# Same, but do not print any help
16  quiet = @printf "  $1$2 $@\n"; $($1)
17else				# Show the full command line
18  quiet = $($1)
19endif
20
21$(PETSC_ARCH)/conf/files :
22	$(PYTHON) conf/gmakegen.py PETSC_ARCH=$(PETSC_ARCH)
23
24-include $(PETSC_ARCH)/conf/files
25
26ifeq ($(PETSC_LANGUAGE),CXXONLY)
27  cc_name := CXX
28else
29  cc_name := CC
30endif
31
32PETSC_DEPFLAGS.c := -MMD -MP
33PETSC_DEPFLAGS.cxx := -MMD -MP
34PETSC_DEPFLAGS.F := -MMD -MP
35
36PETSC_COMPILE.c = $(call quiet,$(cc_name)) -c $(PCC_FLAGS) $(CFLAGS) $(CCPPFLAGS) $(PETSC_DEPFLAGS.c)
37PETSC_COMPILE.cxx = $(call quiet,CXX) -c $(PCC_FLAGS) $(CFLAGS) $(CCPPFLAGS) $(PETSC_DEPFLAGS.cxx)
38PETSC_COMPILE.cu = $(call quiet,CUDAC) -c $(CUDAC_FLAGS) --compiler-options="$(PCC_FLAGS) $(CXXFLAGS) $(CCPPFLAGS)"
39PETSC_GENDEPS.cu = $(call quiet,CUDAC,.dep) --generate-dependencies $(CUDAC_FLAGS) --compiler-options="$(PCC_FLAGS) $(CXXFLAGS) $(CCPPFLAGS)"
40PETSC_COMPILE.F = $(call quiet,FC) -c $(FC_FLAGS) $(FFLAGS) $(FCPPFLAGS) $(PETSC_DEPFLAGS.F)
41
42pkgs := sys vec mat dm ksp snes ts
43langs := c cu cxx F
44allobj := $(foreach pkg, $(pkgs), $(foreach lang, $(langs), $($(pkg)srcs.$(lang):%.$(lang)=$(OBJDIR)/%.o)))
45
46$(LIBDIR)/libpetsc.so : $(allobj) | $$(@D)/.DIR
47	$(call quiet,CLINKER) -shared -o $@ $^ $(PETSC_EXTERNAL_LIB_BASIC)
48
49$(OBJDIR)/%.o : %.c | $$(@D)/.DIR
50	$(PETSC_COMPILE.c) $< -o $@
51
52$(OBJDIR)/%.o : %.cxx | $$(@D)/.DIR
53	$(PETSC_COMPILE.cxx) $< -o $@
54
55$(OBJDIR)/%.o : %.cu | $$(@D)/.DIR
56	$(PETSC_COMPILE.cu) $< -o $@ # Compile first so that if there is an error, it comes from a normal compile
57	@$(PETSC_GENDEPS.cu) $< -o $(@:%.o=%.d) # Generate the dependencies for later
58
59$(OBJDIR)/%.o : %.F | $$(@D)/.DIR
60	$(PETSC_COMPILE.F) $< -o $@
61
62%/.DIR :
63	@mkdir -p $(@D)
64	@touch $@
65
66.PRECIOUS: %/.DIR
67
68.PHONY: clean all print
69
70clean:
71	rm -rf $(OBJDIR) $(LIBDIR)/libpetsc* $(PETSC_ARCH)/conf/files
72
73# make print VAR=the-variable
74print:
75	@echo $($(VAR))
76
77allobj.d := $(allobj:%.o=%.d)
78# Tell make that allobj.d are all up to date.  Without this, the include
79# below has quadratic complexity, taking more than one second for a
80# do-nothing build of PETSc (much worse for larger projects)
81$(allobj.d) : ;
82
83-include $(allobj.d)
84