Commits

Lisandro Dalcin committed 4337b13

Add support for GNU Make builds following petsc-dev

Comments (0)

Files changed (3)

   find_path (PETSC_INCLUDE_CONF petscconf.h HINTS "${PETSC_DIR}" PATH_SUFFIXES "${PETSC_ARCH}/include" "include" NO_DEFAULT_PATH)
   mark_as_advanced (PETSC_INCLUDE_DIR PETSC_INCLUDE_CONF)
   set (PETSC_INCLUDES ${PETSC_INCLUDE_CONF} ${PETSC_INCLUDE_DIR} CACHE PATH "PETSc include paths" FORCE)
-  set (PETSC_DEFINITIONS "-D__INSDIR__=" CACHE STRING "PETSc preprocesor definitions" FORCE)
-  mark_as_advanced (PETSC_DEFINITIONS)
   find_library (PETSC_LIBRARIES NAMES petsc HINTS "${PETSC_DIR}" PATH_SUFFIXES "${PETSC_ARCH}/lib" "lib" NO_DEFAULT_PATH)
   include (${PETSC_DIR}/${PETSC_ARCH}/conf/PETScConfig.cmake)
   mark_as_advanced (PETSC_CLANGUAGE_Cxx)
 include_directories (${PETSC_INCLUDES} ${PETSC_PACKAGE_INCLUDES}
                     "${PetIGA_SOURCE_DIR}/${PETSC_ARCH}/include"
                     "${PetIGA_SOURCE_DIR}/include")
-add_definitions (${PETSC_DEFINITIONS})
 
 set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PetIGA_BINARY_DIR}/lib"     CACHE PATH "Output directory for PetIGA archives")
 set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PetIGA_BINARY_DIR}/lib"     CACHE PATH "Output directory for PetIGA libraries")
+# -*- mode: makefile-gmake -*-
+
+include ./conf/petigavariables
+PETIGA_DIR ?= $(CURDIR)
+
+OBJDIR := $(PETSC_ARCH)/obj
+MODDIR := $(PETSC_ARCH)/include
+LIBDIR := $(abspath $(PETSC_ARCH)/lib)
+
+libpetiga_shared := $(LIBDIR)/libpetiga.$(SL_LINKER_SUFFIX)
+libpetiga_static := $(LIBDIR)/libpetiga.$(AR_LIB_SUFFIX)
+libpetiga := $(if $(filter-out no,$(BUILDSHAREDLIB)),$(libpetiga_shared),$(libpetiga_static))
+
+pkgs := petiga
+srcs-petiga.c   := $(wildcard src/*.c)
+srcs-petiga.cxx := $(wildcard src/*.cxx)
+srcs-petiga.F90 := $(wildcard src/*.F90)
+
+all : $(libpetiga)
+
+.SECONDEXPANSION: # to expand $$(@D)/.DIR
+
+# workarround old cygwin versions
+ifeq ($(PETSC_CYGWIN_BROKEN_PIPE),1)
+ifeq ($(shell basename $(AR)),ar)
+  V ?= 1
+endif
+endif
+ifeq ($(V),)
+  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, but do not print any help
+  quiet = @printf "  %10s %s\n" "$1$2" "$@"; $($1)
+else			# Show the full command line
+  quiet = $($1)
+endif
+
+ifeq ($(PETSC_LANGUAGE),CXXONLY)
+  pcc := CXX
+else
+  pcc := CC
+endif
+
+PETSC_COMPILE.c   = $(call quiet,$(pcc)) -c $(PCC_FLAGS) $(CFLAGS) $(CCPPFLAGS) $(C_DEPFLAGS)
+PETSC_COMPILE.cxx = $(call quiet,CXX) -c $(PCC_FLAGS) $(CFLAGS) $(CCPPFLAGS) $(CXX_DEPFLAGS)
+PETSC_COMPILE.F   = $(call quiet,FC) -c $(FC_FLAGS) $(FFLAGS) $(FCPPFLAGS) $(FC_DEPFLAGS)
+
+langs := c cxx F90
+concatlangs = $(foreach lang, $(langs), $(srcs-$(1).$(lang):%.$(lang)=$(OBJDIR)/%.o))
+srcs.o := $(foreach pkg, $(pkgs), $(call concatlangs,$(pkg)))
+
+$(libpetiga_shared) : $(srcs.o) | $$(@D)/.DIR
+	$(call quiet,CLINKER) -shared -o $@ $^ $(PETSC_LIB)
+ifneq ($(DSYMUTIL),true)
+	$(call quiet,DSYMUTIL) $@
+endif
+
+$(libpetiga_static) : obj := $(srcs.o)
+%.$(AR_LIB_SUFFIX) : $$(obj) | $$(@D)/.DIR
+ifeq ($(findstring win32fe lib,$(AR)),)
+	@$(RM) $@
+	$(call quiet,AR) $(AR_FLAGS) $@ $^
+	$(call quiet,RANLIB) $@
+else
+	@$(RM) $@ $@.args
+	@cygpath -w $^ > $@.args
+	$(call quiet,AR) $(AR_FLAGS) $@ @$@.args
+	@$(RM) $@.args
+endif
+
+$(OBJDIR)/%.o : %.c | $$(@D)/.DIR
+	$(PETSC_COMPILE.c) $< -o $@
+
+$(OBJDIR)/%.o : %.cxx | $$(@D)/.DIR
+	$(PETSC_COMPILE.cxx) $< -o $@
+
+$(OBJDIR)/%.o : %.F90 | $(MODDIR)/.DIR $$(@D)/.DIR
+ifneq ($(FC_MODULE_OUTPUT_FLAG),)
+	$(PETSC_COMPILE.F) $< -o $@ $(FC_MODULE_OUTPUT_FLAG)$(MODDIR)
+else
+	cd $(MODDIR) && $(FC) -c $(FC_FLAGS) $(FFLAGS) $(FCPPFLAGS) $(FC_DEPFLAGS) ../../$< -o ../../$@
+endif
+
+# Hack: manual dependencies on object files
+petiga.mod.o:= $(OBJDIR)/src/petigaftn.o
+srcs-petiga.F90.o = $(srcs-petiga.F90:%.F90=$(OBJDIR)/%.o)
+$(filter-out $(petiga.mod.o),$(srcs-petiga.F90.o)): | $(petiga.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
+
+clean:
+	@$(RM) -r $(OBJDIR) $(LIBDIR)/libpetiga.* $(MODDIR)/petiga.mod
+
+# make print VAR=the-variable
+print:
+	@echo $($(VAR))
+
+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)
 include ${PETIGA_DIR}/conf/petigatest
 
 all:
-	@if [ -f ${PETIGA_DIR}/${PETSC_ARCH}/CMakeCache.txt ]; then \
+	@if [ "${MAKE_IS_GNUMAKE}" != "" ]; then \
+	${OMAKE} all-gmake  PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETIGA_DIR=${PETIGA_DIR}; \
+	elif [ -f ${PETIGA_DIR}/${PETSC_ARCH}/CMakeCache.txt ]; then \
 	${OMAKE} all-cmake  PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETIGA_DIR=${PETIGA_DIR}; else \
 	${OMAKE} all-legacy PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETIGA_DIR=${PETIGA_DIR}; fi;
 .PHONY: all
            ${PETIGA_DIR}/${PETSC_ARCH}/lib
 .PHONY: arch-tree
 
+
 #
-# Legacy build
+# GNU Make build
 #
-legacy-build: arch-tree deletelibs deletemods build
-all-legacy: chk_petsc_dir chk_petiga_dir arch-tree
+ifdef OMAKE_PRINTDIR
+GMAKE = ${OMAKE_PRINTDIR}
+else
+GMAKE = ${OMAKE}
+endif
+gmake-build:
+	@cd ${PETIGA_DIR} && ${GMAKE} -f gmakefile -j ${MAKE_NP}
+gmake-clean:
+	@cd ${PETIGA_DIR} && ${GMAKE} -f gmakefile clean
+all-gmake: chk_petsc_dir chk_petiga_dir arch-tree
 	-@echo "============================================="
-	-@echo "Building PetIGA"
+	-@echo "Building PetIGA (GNU Make build)"
 	-@echo "Using PETIGA_DIR=${PETIGA_DIR}"
 	-@echo "Using PETSC_DIR=${PETSC_DIR}"
 	-@echo "Using PETSC_ARCH=${PETSC_ARCH}"
 	-@echo "============================================="
-	-@echo "Beginning to build PetIGA library"
-	@${OMAKE} legacy-build PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETIGA_DIR=${PETIGA_DIR} 2>&1 | tee ./${PETSC_ARCH}/conf/make.log
-	-@echo "Completed building PetIGA library"
+	@${GMAKE} gmake-build PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETIGA_DIR=${PETIGA_DIR} 2>&1 | tee -a ${PETSC_ARCH}/conf/make.log
 	-@echo "============================================="
-.PHONY: legacy-build all-legacy
+.PHONY: gmake-build gmake-clean all-gmake
+
 
 #
 # CMake build
 ifeq (${PETSC_LANGUAGE},CXXONLY)
 cmake_cc_clang=-DPETSC_CLANGUAGE_Cxx:STRING='YES'
 cmake_cc_path =-DCMAKE_CXX_COMPILER:FILEPATH=${CXX}
-cmake_cc_flags=-DCMAKE_CXX_FLAGS:STRING='${PCC_FLAGS} ${CFLAGS} ${PETSCFLAGS} ${CPP_FLAGS} ${CPPFLAGS}'
+cmake_cc_flags=-DCMAKE_CXX_FLAGS:STRING='${PCC_FLAGS} ${CFLAGS} ${CCPPFLAGS}'
 else
 cmake_cc_clang=-DPETSC_CLANGUAGE_Cxx:STRING='NO'
 cmake_cc_path =-DCMAKE_C_COMPILER:FILEPATH=${CC}
-cmake_cc_flags=-DCMAKE_C_FLAGS:STRING='${PCC_FLAGS} ${CFLAGS} ${PETSCFLAGS} ${CPP_FLAGS} ${CPPFLAGS}'
+cmake_cc_flags=-DCMAKE_C_FLAGS:STRING='${PCC_FLAGS} ${CFLAGS} ${CCPPFLAGS}'
 endif
 ifneq (${FC},)
 cmake_fc_path =-DCMAKE_Fortran_COMPILER:FILEPATH=${FC}
-cmake_fc_flags=-DCMAKE_Fortran_FLAGS:STRING='${FC_FLAGS} ${FFLAGS} ${PETSCFLAGS} ${FPP_FLAGS} ${FPPFLAGS}'
+cmake_fc_flags=-DCMAKE_Fortran_FLAGS:STRING='${FC_FLAGS} ${FFLAGS} ${FCPPFLAGS}'
 endif
 cmake_cc=${cmake_cc_path} ${cmake_cc_flags} ${cmake_cc_clang}
 cmake_fc=${cmake_fc_path} ${cmake_fc_flags}
 	@${MKDIR} ${PETIGA_DIR}/${PETSC_ARCH}
 	@cd ${PETIGA_DIR}/${PETSC_ARCH} && ${CMAKE} ${PETIGA_DIR} ${cmake_cc} ${cmake_fc}
 cmake-boot: ${PETIGA_DIR}/${PETSC_ARCH}/CMakeCache.txt
-cmake-build: cmake-boot
-	@cd ${PETIGA_DIR}/${PETSC_ARCH} && ${OMAKE} -j ${MAKE_NP}
-cmake-clean:
+cmake-down:
 	-@${RM} -r ${PETIGA_DIR}/${PETSC_ARCH}/CMakeCache.txt
 	-@${RM} -r ${PETIGA_DIR}/${PETSC_ARCH}/CMakeFiles
 	-@${RM} -r ${PETIGA_DIR}/${PETSC_ARCH}/Makefile
 	-@${RM} -r ${PETIGA_DIR}/${PETSC_ARCH}/cmake_install.cmake
+cmake-build: cmake-boot
+	@cd ${PETIGA_DIR}/${PETSC_ARCH} && ${OMAKE} -j ${MAKE_NP}
+	-@if [ "${DSYMUTIL}" != "true" ]; then \
+        ${DSYMUTIL} ${INSTALL_LIB_DIR}/libpetiga.${SL_LINKER_SUFFIX}; fi
+cmake-clean:
+	@cd ${PETIGA_DIR}/${PETSC_ARCH} && ${OMAKE} clean
 all-cmake: chk_petsc_dir chk_petiga_dir arch-tree
 	-@echo "============================================="
 	-@echo "Building PetIGA (CMake build)"
 	-@echo "============================================="
 	@${OMAKE} cmake-build PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETIGA_DIR=${PETIGA_DIR} 2>&1 | tee ./${PETSC_ARCH}/conf/make.log
 	-@echo "============================================="
-.PHONY: cmake-boot cmake-build cmake-clean all-cmake
+.PHONY: cmake-boot cmake-build cmake-down cmake-clean all-cmake
+
+
+#
+# Legacy build
+#
+legacy-build: arch-tree deletelibs deletemods build
+all-legacy: chk_petsc_dir chk_petiga_dir arch-tree
+	-@echo "============================================="
+	-@echo "Building PetIGA (legacy build)"
+	-@echo "Using PETIGA_DIR=${PETIGA_DIR}"
+	-@echo "Using PETSC_DIR=${PETSC_DIR}"
+	-@echo "Using PETSC_ARCH=${PETSC_ARCH}"
+	-@echo "============================================="
+	-@echo "Beginning to build PetIGA library"
+	@${OMAKE} legacy-build PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETIGA_DIR=${PETIGA_DIR} 2>&1 | tee ./${PETSC_ARCH}/conf/make.log
+	-@echo "Completed building PetIGA library"
+	-@echo "============================================="
+.PHONY: legacy-build all-legacy
 
 #
 # Check if PETSC_DIR variable specified is valid
 	-@${OMAKE} shared_nomesg PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETIGA_DIR=${PETIGA_DIR} \
 		   | (${GREP} -vE "making shared libraries in" || true) \
 		   | (${GREP} -vE "==========================" || true)
+	-@if [ "${DSYMUTIL}" != "true" ]; then \
+        ${DSYMUTIL} ${INSTALL_LIB_DIR}/libpetiga.${SL_LINKER_SUFFIX}; fi
+
 .PHONY: build compile ranlib shlibs
 
 # Delete PetIGA library
 	@echo '<MENU>' >> docs/html/index.html
 	@ls -1 docs/html | grep .html | grep -v index.html | sed -e 's%^\(.*\).html$$%<LI><A HREF="\1.html">\1</A>%g' >> docs/html/index.html
 	@echo '</MENU>' >> docs/html/index.html
+.PHONY: doc
 
 alletags:
 	-@${PYTHON} ${PETSC_DIR}/bin/maint/generateetags.py