From a2fb1d0bdd7604cb90519c1ca38540ade25f888d Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Mon, 11 Mar 2019 15:56:40 +0100
Subject: [PATCH] COMP: add wmake rules for Pgi compiler (#1234)

---
 etc/bashrc                          |  2 +-
 etc/config.csh/settings             |  4 ++++
 etc/config.sh/settings              |  4 ++++
 etc/cshrc                           |  2 +-
 src/OSspecific/POSIX/POSIX.C        |  6 ++++++
 wmake/rules/General/Pgi/c           |  7 +++++++
 wmake/rules/General/Pgi/c++         | 13 +++++++++++++
 wmake/rules/General/Pgi/openmp      |  5 +++++
 wmake/rules/linux64Pgi/c            | 14 ++++++++++++++
 wmake/rules/linux64Pgi/c++          | 17 +++++++++++++++++
 wmake/rules/linux64Pgi/c++Debug     |  2 ++
 wmake/rules/linux64Pgi/c++Opt       |  2 ++
 wmake/rules/linux64Pgi/c++Prof      |  2 ++
 wmake/rules/linux64Pgi/cDebug       |  2 ++
 wmake/rules/linux64Pgi/cOpt         |  2 ++
 wmake/rules/linux64Pgi/cProf        |  2 ++
 wmake/rules/linux64Pgi/general      |  9 +++++++++
 wmake/rules/linux64Pgi/mplibOPENMPI |  3 +++
 18 files changed, 96 insertions(+), 2 deletions(-)
 create mode 100644 wmake/rules/General/Pgi/c
 create mode 100644 wmake/rules/General/Pgi/c++
 create mode 100644 wmake/rules/General/Pgi/openmp
 create mode 100644 wmake/rules/linux64Pgi/c
 create mode 100644 wmake/rules/linux64Pgi/c++
 create mode 100644 wmake/rules/linux64Pgi/c++Debug
 create mode 100644 wmake/rules/linux64Pgi/c++Opt
 create mode 100644 wmake/rules/linux64Pgi/c++Prof
 create mode 100644 wmake/rules/linux64Pgi/cDebug
 create mode 100644 wmake/rules/linux64Pgi/cOpt
 create mode 100644 wmake/rules/linux64Pgi/cProf
 create mode 100644 wmake/rules/linux64Pgi/general
 create mode 100644 wmake/rules/linux64Pgi/mplibOPENMPI

diff --git a/etc/bashrc b/etc/bashrc
index a501405811f..e0e3039ae3f 100644
--- a/etc/bashrc
+++ b/etc/bashrc
@@ -71,7 +71,7 @@ export WM_COMPILER_TYPE=system
 
 # [WM_COMPILER] - Compiler:
 # = Gcc | Gcc4[8-9] | Gcc5[1-5] | Gcc6[1-5] | Gcc7[1-4] | Gcc8[12] |
-#   Clang | Clang3[7-9] | Clang[4-6]0 | Icc | Cray | Arm
+#   Clang | Clang3[7-9] | Clang[4-6]0 | Icc | Cray | Arm | Pgi
 export WM_COMPILER=Gcc
 
 # [WM_ARCH_OPTION] - Memory addressing:
diff --git a/etc/config.csh/settings b/etc/config.csh/settings
index 34ecb60d912..47aa3ede721 100644
--- a/etc/config.csh/settings
+++ b/etc/config.csh/settings
@@ -249,6 +249,10 @@ case Arm*:    # Arm system compilers
     setenv WM_CC 'armclang'
     setenv WM_CXX 'armclang++'
     breaksw
+case Pgi*:    # Pgi system compilers
+    setenv WM_CC 'pgcc'
+    setenv WM_CXX 'pgc++'
+    breaksw
 endsw
 
 # Clear prior to sourcing
diff --git a/etc/config.sh/settings b/etc/config.sh/settings
index c331a5ff5f0..149a2d9f10a 100644
--- a/etc/config.sh/settings
+++ b/etc/config.sh/settings
@@ -249,6 +249,10 @@ Arm*)     # Arm system compilers
     export WM_CC='armclang'
     export WM_CXX='armclang++'
     ;;
+Pgi*)     # Pgi system compilers
+    export WM_CC='pgcc'
+    export WM_CXX='pgc++'
+    ;;
 esac
 
 # Clear prior to sourcing
diff --git a/etc/cshrc b/etc/cshrc
index 39cbff0077e..098d8856986 100644
--- a/etc/cshrc
+++ b/etc/cshrc
@@ -73,7 +73,7 @@ setenv WM_COMPILER_TYPE system
 
 # [WM_COMPILER] - Compiler:
 # = Gcc | Gcc4[8-9] | Gcc5[1-5] | Gcc6[1-5] | Gcc7[1-4] | Gcc8[12] |
-#   Clang | Clang3[7-9] | Clang[4-6]0 | Icc | Cray | Arm
+#   Clang | Clang3[7-9] | Clang[4-6]0 | Icc | Cray | Arm | Pgi
 setenv WM_COMPILER Gcc
 
 # [WM_ARCH_OPTION] - Memory addressing:
diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C
index a57ec119497..d888ccfcb89 100644
--- a/src/OSspecific/POSIX/POSIX.C
+++ b/src/OSspecific/POSIX/POSIX.C
@@ -65,6 +65,12 @@ Description
 #ifdef darwin
     #include <mach-o/dyld.h>
 #else
+
+    // PGI does not have __int128_t
+    #ifdef __PGIC__
+        #define __ILP32__
+    #endif
+
     #include <link.h>
 #endif
 
diff --git a/wmake/rules/General/Pgi/c b/wmake/rules/General/Pgi/c
new file mode 100644
index 00000000000..861c12bdb15
--- /dev/null
+++ b/wmake/rules/General/Pgi/c
@@ -0,0 +1,7 @@
+SUFFIXES += .c
+
+cc          = pgcc
+
+cDBUG       =
+cOPT        = -O2
+cWARN       =
diff --git a/wmake/rules/General/Pgi/c++ b/wmake/rules/General/Pgi/c++
new file mode 100644
index 00000000000..39a8ec884f2
--- /dev/null
+++ b/wmake/rules/General/Pgi/c++
@@ -0,0 +1,13 @@
+SUFFIXES += .C .cc .cpp .cxx
+
+CC          = pgc++ -std=c++11
+
+c++DBUG     =
+c++OPT      = -O2
+ptFLAGS     = -DNoRepository
+
+# - Standard warnings
+# - Less restrictive warnings (may be needed for flex++, CGAL, etc.)
+
+c++WARN     =
+c++LESSWARN =
diff --git a/wmake/rules/General/Pgi/openmp b/wmake/rules/General/Pgi/openmp
new file mode 100644
index 00000000000..cd007d15291
--- /dev/null
+++ b/wmake/rules/General/Pgi/openmp
@@ -0,0 +1,5 @@
+# Flags for compiling/linking openmp
+# The USE_OMP is for OpenFOAM-specific use (general use is _OPENMP)
+
+COMP_OPENMP = -DUSE_OMP -fopenmp
+LINK_OPENMP = -lgomp
diff --git a/wmake/rules/linux64Pgi/c b/wmake/rules/linux64Pgi/c
new file mode 100644
index 00000000000..3a9204233eb
--- /dev/null
+++ b/wmake/rules/linux64Pgi/c
@@ -0,0 +1,14 @@
+include $(GENERAL_RULES)/Pgi/c
+
+cc          = pgcc -m64
+
+include $(DEFAULT_RULES)/c$(WM_COMPILE_OPTION)
+
+cFLAGS      = $(GFLAGS) $(cWARN) $(cOPT) $(cDBUG) $(LIB_HEADER_DIRS) -fPIC
+
+ctoo        = $(WM_SCHEDULER) $(cc) $(cFLAGS) -c $< -o $@
+
+LINK_LIBS   = $(cDBUG)
+
+LINKLIBSO   = $(cc) -shared
+LINKEXE     = $(cc) -Xlinker --add-needed -Xlinker -z -Xlinker nodefs
diff --git a/wmake/rules/linux64Pgi/c++ b/wmake/rules/linux64Pgi/c++
new file mode 100644
index 00000000000..4fc97794e8a
--- /dev/null
+++ b/wmake/rules/linux64Pgi/c++
@@ -0,0 +1,17 @@
+include $(GENERAL_RULES)/Pgi/c++
+
+CC          = pgc++ -std=c++11 -m64
+
+include $(DEFAULT_RULES)/c++$(WM_COMPILE_OPTION)
+
+c++FLAGS    = $(GFLAGS) $(c++WARN) $(c++OPT) $(c++DBUG) $(ptFLAGS) $(LIB_HEADER_DIRS) -fPIC
+
+Ctoo        = $(WM_SCHEDULER) $(CC) $(c++FLAGS) -c $< -o $@
+cxxtoo      = $(Ctoo)
+cctoo       = $(Ctoo)
+cpptoo      = $(Ctoo)
+
+LINK_LIBS   = $(c++DBUG)
+
+LINKLIBSO   = $(CC) $(c++FLAGS) -shared
+LINKEXE     = $(CC) $(c++FLAGS) -Xlinker --add-needed
diff --git a/wmake/rules/linux64Pgi/c++Debug b/wmake/rules/linux64Pgi/c++Debug
new file mode 100644
index 00000000000..48f0b6643e1
--- /dev/null
+++ b/wmake/rules/linux64Pgi/c++Debug
@@ -0,0 +1,2 @@
+c++DBUG     = -g -DFULLDEBUG
+c++OPT      = -O0
diff --git a/wmake/rules/linux64Pgi/c++Opt b/wmake/rules/linux64Pgi/c++Opt
new file mode 100644
index 00000000000..2aedabd6280
--- /dev/null
+++ b/wmake/rules/linux64Pgi/c++Opt
@@ -0,0 +1,2 @@
+c++DBUG     =
+c++OPT      = -O3
diff --git a/wmake/rules/linux64Pgi/c++Prof b/wmake/rules/linux64Pgi/c++Prof
new file mode 100644
index 00000000000..3bda4dad55e
--- /dev/null
+++ b/wmake/rules/linux64Pgi/c++Prof
@@ -0,0 +1,2 @@
+c++DBUG    = -pg
+c++OPT     = -O2
diff --git a/wmake/rules/linux64Pgi/cDebug b/wmake/rules/linux64Pgi/cDebug
new file mode 100644
index 00000000000..7b7adf10dea
--- /dev/null
+++ b/wmake/rules/linux64Pgi/cDebug
@@ -0,0 +1,2 @@
+cDBUG       = -g -DFULLDEBUG
+cOPT        = -O0
diff --git a/wmake/rules/linux64Pgi/cOpt b/wmake/rules/linux64Pgi/cOpt
new file mode 100644
index 00000000000..17318709f1f
--- /dev/null
+++ b/wmake/rules/linux64Pgi/cOpt
@@ -0,0 +1,2 @@
+cDBUG       =
+cOPT        = -O3
diff --git a/wmake/rules/linux64Pgi/cProf b/wmake/rules/linux64Pgi/cProf
new file mode 100644
index 00000000000..ca3ac9bf5f0
--- /dev/null
+++ b/wmake/rules/linux64Pgi/cProf
@@ -0,0 +1,2 @@
+cDBUG       = -pg
+cOPT        = -O2
diff --git a/wmake/rules/linux64Pgi/general b/wmake/rules/linux64Pgi/general
new file mode 100644
index 00000000000..91cca018b67
--- /dev/null
+++ b/wmake/rules/linux64Pgi/general
@@ -0,0 +1,9 @@
+CPP        = cpp -traditional-cpp $(GFLAGS)
+
+PROJECT_LIBS = -l$(WM_PROJECT) -ldl
+
+include $(GENERAL_RULES)/standard
+## include $(GENERAL_RULES)/Pgi/openmp
+
+include $(DEFAULT_RULES)/c
+include $(DEFAULT_RULES)/c++
diff --git a/wmake/rules/linux64Pgi/mplibOPENMPI b/wmake/rules/linux64Pgi/mplibOPENMPI
new file mode 100644
index 00000000000..0faf49ed1e5
--- /dev/null
+++ b/wmake/rules/linux64Pgi/mplibOPENMPI
@@ -0,0 +1,3 @@
+PFLAGS     = -DMPICH_SKIP_MPICXX -DOMPI_SKIP_MPICXX
+PINC       = -I$(MPI_ARCH_PATH)/include
+PLIBS      = -L$(MPI_ARCH_PATH)/lib$(WM_COMPILER_LIB_ARCH) -L$(MPI_ARCH_PATH)/lib -lmpi
-- 
GitLab