From 202d87d7a66205bcd972b6e9f955efa90a4ab60d Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Mon, 17 Aug 2020 17:45:43 +0100
Subject: [PATCH] MNT: Variables for CUDA compilation, some clean up and
 comments

---
 config/common/buildSettings.mk | 20 ++++++---
 config/common/rules.mk         | 41 ++++++++++---------
 config/common/vars.mk          | 74 +++++++++++++++++++++-------------
 3 files changed, 82 insertions(+), 53 deletions(-)

diff --git a/config/common/buildSettings.mk b/config/common/buildSettings.mk
index 243b565..7b4e0d9 100644
--- a/config/common/buildSettings.mk
+++ b/config/common/buildSettings.mk
@@ -45,6 +45,12 @@ ARCHLDFLAGS =
 # Libraries available for linking by all projects.
 ARCHLIBS =
 
+# Compiler flags for CUDA projects.
+ARCHCUDACXXFLAGS =
+
+# Linker flags for CUDA projects.
+ARCHCUDALDFLAGS =
+
 #####################################################################
 #
 # Darwin specific sys vars and ext libs
@@ -105,12 +111,14 @@ ifneq ($(shell which nvcc), )
   #  - Do not use -pedantic, otherwise *every single line* of
   #    transpiled cuda code will trigger "warning: style of line
   #    directive is a GCC extension".
-  CUDACXXFLAGS  = -I${CUDADIR}/include  \
-                  ${GENCODE_FLAGS}      \
-                  -DARMA_ALLOW_FAKE_GCC \
-                  --compiler-options    \
-                  "$(filter-out -pedantic, ${ARCHCXXFLAGS})"
-  CUDALDFLAGS   = -lcurand -lcudart
+  ARCCUDACXXFLAGS  = -I${CUDADIR}/include  \
+                     -maxrregcount=64      \
+                     ${GENCODE_FLAGS}      \
+                     -DARMA_ALLOW_FAKE_GCC \
+                     --compiler-options    \
+                     "$(filter-out -pedantic, ${ARCHCXXFLAGS})"
+  ARCHCUDALDFLAGS = -L${CUDADIR}/lib \
+                    -L${CUDADIR}/lib/stubs
 
   ifeq ($(SYSTYPE), Darwin)
 
diff --git a/config/common/rules.mk b/config/common/rules.mk
index bc62e0d..76c87ef 100644
--- a/config/common/rules.mk
+++ b/config/common/rules.mk
@@ -1,14 +1,35 @@
-# $Id$
+# Make rules for FSL projects
+#
+# Automatic GNU make rules are used for compiling C and C++ files.
+
 all:
 
 help:
 	@echo " make         Rebuild project targets";
+	@echo " make clean   Remove executables, libraries and object files";
 	@echo " make install Install into your local FSLDEVDIR";
 
 clean:
 	${RM} -f *.o *.a *.so *.exe depend.mk \
       ${XFILES} ${FXFILES} ${SOFILES} ${AFILES} ${TESTXFILES}
 
+insertcopyright:
+	${FSLCONFDIR}/common/insertcopyright * */*
+
+depend:
+	${RM} -f depend.mk
+	${MAKE} depend.mk
+
+depend.mk:
+	@echo Building dependency file depend.mk
+	@for srcfile in `find . -name "*.c" -or -name "*.cc" -or -name "*.cxx" -or -name "*.cpp" -or -name "*.inc" -or -name "*.hpp"` verylongdummyname ; do \
+		if [ -f $$srcfile ] ; then \
+			${CC} -MM ${INCFLAGS} $$srcfile >> depend.mk ; \
+		else \
+			touch depend.mk; \
+		fi \
+	done
+
 install:
 	@${MAKE} "DESTDIR=${FSLDEVDIR}" master-install-script
 
@@ -164,22 +185,4 @@ datainstall:
 		fi; \
 	done
 
-
-insertcopyright:
-	${FSLCONFDIR}/common/insertcopyright * */*
-
-depend:
-	${RM} -f depend.mk
-	${MAKE} depend.mk
-
-depend.mk:
-	@echo Building dependency file depend.mk
-	@for srcfile in `find . -name "*.c" -or -name "*.cc" -or -name "*.cxx" -or -name "*.cpp" -or -name "*.inc" -or -name "*.hpp"` verylongdummyname ; do \
-		if [ -f $$srcfile ] ; then \
-			${CC} -MM ${INCFLAGS} $$srcfile >> depend.mk ; \
-		else \
-			touch depend.mk; \
-		fi \
-	done
-
 include depend.mk
diff --git a/config/common/vars.mk b/config/common/vars.mk
index f84da98..8e72598 100644
--- a/config/common/vars.mk
+++ b/config/common/vars.mk
@@ -7,25 +7,37 @@ PROJNAME =
 
 # Project-specific compiler/linker flags - these
 # can be overridden in the project Makefile.
-USRLDFLAGS  =
-USRINCFLAGS =
-USRCFLAGS   =
-USRCXXFLAGS =
-LIBS        =
+
+USRLDFLAGS      = # Project-specific linker flags
+USRINCFLAGS     = # Project-specific include directories
+USRCFLAGS       = # Project-specific compiler flags for C projects
+USRCXXFLAGS     = # Project-specific compiler flags for C++ projects
+LIBS            = # Project-specific libraries to link against for C
+                  # and C++ projects - these are incorporated into the
+                  # final LDFLAGS, below.
+USRCUDACXXFLAGS = # Project-specific compiler flags for CUDA projects
+USRCUDALDFLAGS  = # Project-specific linker flags for CUDA projects
+CUDALIBS        = # Project-specific libraries to link against for CUDA
+                  # projects - these are incorporated into the final
+                  # CUDALDFLAGS, below.
 
 # Project outputs - these variables control
 # what gets installed from a project. The
-# values given below are the defaults -
-# they may be customised/overridden in
-# project Makefiles
-HFILES    = *.h
-AFILES    = *.a
-SOFILES   = *.so
-XFILES    =
-SCRIPTS   =
-PYFILES   = *.py
-TCLFILES  = *.tcl
-TESTXILES =
+# values given below are the defaults - they
+# may be customised/overridden in project
+# Makefiles.
+HFILES    = *.h    # installed into $FSLDIR/include/$PROJNAME/
+AFILES    = *.a    # installed into $FSLDIR/lib/
+SOFILES   = *.so   # installed into $FSLDIR/lib/
+XFILES    =        # installed into $FSLDIR/bin/
+SCRIPTS   =        # installed into $FSLDIR/bin/
+RUNTCLS   =        # link to Runtcl created in $FSLDIR/bin/ which assumes
+                   # that <file>.tcl has been installed into
+                   # $FSLDIR/tcl/
+PYFILES   = *.py   # installed into $FSLDIR/etc/fsl/python/$PROJNAME/
+TCLFILES  = *.tcl  # installed into $FSLDIR/tcl/
+DATAFILES =        # installed into $FSLDIR/data/$PROJNAME/
+TESTXILES =        # not currently used
 
 # Final install destinations
 # for project outputs
@@ -52,22 +64,28 @@ INCFLAGS = ${USRINCFLAGS} -I. -I${DEVINCDIR} -I${INCDIR}
 #############################
 
 # Ignore flags provided by the environment
-CFLAGS   =
-CXXFLAGS =
-CPPFLAGS =
-LDFLAGS  =
+CFLAGS       =
+CXXFLAGS     =
+CPPFLAGS     =
+CUDACXXFLAGS =
+LDFLAGS      =
+CUDALDFLAGS  =
 
 # All projects must use these flags for
 # compilation/linking, using the form:
 #
-# $(CXX) $(CXXFLAGS) <project flags/files> $(LDFLAGS)
-# $(CC)  $(CFLAGS)   <project flags/files> $(LDFLAGS)
+# $(CC)   $(CFLAGS)       <project flags/files> $(LDFLAGS)
+# $(CXX)  $(CXXFLAGS)     <project flags/files> $(LDFLAGS)
+# $(NVCC) $(CUDACXXFLAGS) <project flags/files> $(LDFLAGS) $(CUDALDFLAGS)
 #
 # LDFLAGS *must* come at the end, to ensure proper linking.
 
-LDFLAGS      += ${ARCHLDFLAGS} ${USRLDFLAGS} \
-                -L. -L${DEVLIBDIR} -L${LIBDIR} \
-                ${LIBS} ${ARCHLIBS}
-CFLAGS       += ${ARCHCFLAGS}   ${USRCFLAGS}   ${INCFLAGS}
-CXXFLAGS     += ${ARCHCXXFLAGS} ${USRCXXFLAGS} ${INCFLAGS}
-CUDACXXFLAGS +=                                ${INCFLAGS}
+LDFLAGS       += ${ARCHLDFLAGS} ${USRLDFLAGS} \
+                 -L. -L${DEVLIBDIR} -L${LIBDIR} \
+                  ${LIBS} ${ARCHLIBS}
+CUDALDFLAGS   += ${ARCHCUDALDFLAGS} ${USRCUDALDFLAGS} \
+                 -L. -L${DEVLIBDIR} -L${LIBDIR} \
+                 ${CUDALIBS}
+CFLAGS        += ${ARCHCFLAGS}       ${USRCFLAGS}       ${INCFLAGS}
+CXXFLAGS      += ${ARCHCXXFLAGS}     ${USRCXXFLAGS}     ${INCFLAGS}
+CUDACXXFLAGS  += ${ARCHCUDACXXFLAGS} ${USRCUDACXXFLAGS} ${INCFLAGS}
-- 
GitLab