diff --git a/CHANGELOG.md b/CHANGELOG.md index 430b92ae1c44aa2ae7b3ee047fd0f0e2bed4556d..9e79de8f91f2963694902913c4b045d7a87da086 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # FSL base project changelog +## 2112.1 (Monday 13th December 2021) + +* Adjust the `depend.mk` rule to support automatic dependency generation for + `.cu` CUDA source files. + + ## 2112.0 (Saturday 11th December 2021) * Add `-pthread` to the standard C++ compiler flags for `g++`. diff --git a/config/buildSettings.mk b/config/buildSettings.mk index 6876b77be299e077c78f3b5ed272606b22ab3322..a090a61dd58fe8d1de688f76d7fb441b77d939b5 100644 --- a/config/buildSettings.mk +++ b/config/buildSettings.mk @@ -176,7 +176,7 @@ endif # CUDA projects. nvcc must be on the $PATH, or $NVCC must be set. # ##################################################################### -NVCC ?= $(shell which nvcc) +NVCC ?= $(shell which nvcc 2> /dev/null) ifneq (${NVCC}, ) # NVCC, GENCODEFLAGS, NVCCFLAGS, NVCCLDFLAGS, diff --git a/config/depend.sh b/config/depend.sh new file mode 100755 index 0000000000000000000000000000000000000000..224219cbedde024f2062aff69833c4dd3754d5e1 --- /dev/null +++ b/config/depend.sh @@ -0,0 +1,55 @@ +#!/bin/sh +# +# This script is called by the depend.mk rule defined in +# $FSLDIR/config/rules.mk. +# +# It is assumed that this script is executed from a +# project directory (i.e. the project directory is the cwd). +# +# Automatically generate Make rules and dependencies for +# all source files in the project. This creates a file +# called depend.mk which contains a rule for every object +# file to be compiled, which has all header files +# that the source file includes as dependencies. If +# object files are to be saved into a separate build +# directory, the project Makefile should set the BUILDDIR +# variable. +# +# If the NVCC environment variable is set to a nvcc compiler, +# rules are generated for CUDA .cu files. If CUDA object files +# are to be saved into a separate build directory, the project +# Makefile should set the CUDABUILDDIR variable. +set -e + +echo "Building dependency file depend.mk" + +srcfiles=`find -name "*.c" -or -name "*.cc" -or -name "*.cxx" -or -name "*.cpp" -or -name "*.inc" -or -name "*.hpp" -or -name "*.cu"` + +for srcfile in ${srcfiles} dummyname; do + + if [ -f "${srcfile}" ]; then + srcfile="${srcfile#./}" + prefix="${srcfile%.*}" + basename="${prefix##*/}" + objfile="${basename}.o" + depfile="${basename}.mk" + + # if nvcc is present, use it for .cu files + if [ "${srcfile%.cu}" = "${prefix}" ]; then + if [ -f "${NVCC}" ]; then + ${NVCC} -MM -MT "${CUDABUILDDIR}${objfile}" -MF "${depfile}" \ + ${CPPFLAGS} ${INCFLAGS} "${srcfile}" > /dev/null 2>&1 + fi + else + ${CC} -MM -MT "${BUILDDIR}${objfile}" -MF "${depfile}" \ + ${CPPFLAGS} ${INCFLAGS} "${srcfile}" > /dev/null 2>&1 + fi + if [ -f "${depfile}" ]; then + cat "${depfile}" >> depend.mk + rm -f "${depfile}" + fi + + else + touch depend.mk + fi +done diff --git a/config/rules.mk b/config/rules.mk index df832a3948feab95ab2243a46282d899956b9175..edc95e460da65457c0520619db7b9d39b2135899 100644 --- a/config/rules.mk +++ b/config/rules.mk @@ -21,20 +21,14 @@ depend: ${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 \ - basename="$${srcfile%.*}" ; \ - basename="$${basename#./}" ; \ - objfile="$${basename}.o" ; \ - depfile="$${basename}.mk" ; \ - ${CC} -MM -MT "${BUILDDIR}$${objfile}" -MF "$${depfile}" ${CPPFLAGS} ${INCFLAGS} "$${srcfile}" > /dev/null; \ - cat "$${depfile}" >> depend.mk ; \ - rm -f "$${depfile}" ; \ - else \ - touch depend.mk; \ - fi \ - done + @NVCC="${NVCC}" \ + CC="${CC}" \ + CPPFLAGS="${CPPFLAGS}" \ + INCFLAGS="${INCFLAGS}" \ + BUILDDIR="${BUILDDIR}" \ + CUDABUILDDIR="${CUDABUILDDIR}" \ + ${FSLCONFDIR}/depend.sh + install: @${MAKE} "DESTDIR=${FSLDEVDIR}" master-install-script