From 7b598bae81409e6d8c5d1441bb015ed54f4adb83 Mon Sep 17 00:00:00 2001 From: eschnett Date: Mon, 8 Dec 2014 22:01:13 +0000 Subject: Build FFTW3 at build time git-svn-id: http://svn.cactuscode.org/projects/ExternalLibraries/FFTW3/trunk@43 325d7946-0b50-4e3b-902a-3a8d69fbdfa6 --- configuration.ccl | 5 +- configure.sh | 205 ----------------------------------------------------- src/build.sh | 65 +++++++++++++++++ src/detect.sh | 151 +++++++++++++++++++++++++++++++++++++++ src/make.code.deps | 7 ++ 5 files changed, 227 insertions(+), 206 deletions(-) delete mode 100644 configure.sh create mode 100755 src/build.sh create mode 100755 src/detect.sh create mode 100644 src/make.code.deps diff --git a/configuration.ccl b/configuration.ccl index 7ffab25..13aa5ff 100644 --- a/configuration.ccl +++ b/configuration.ccl @@ -2,7 +2,10 @@ PROVIDES FFTW3 { - SCRIPT configure.sh + SCRIPT src/detect.sh LANG bash OPTIONS FFTW3_DIR FFTW3_INSTALL_DIR FFTW3_LIBS } + +# Pass configuration options to build script +REQUIRES FFTW3 diff --git a/configure.sh b/configure.sh deleted file mode 100644 index be84a07..0000000 --- a/configure.sh +++ /dev/null @@ -1,205 +0,0 @@ -#! /bin/bash - -################################################################################ -# Prepare -################################################################################ - -# Set up shell -if [ "$(echo ${VERBOSE} | tr '[:upper:]' '[:lower:]')" = 'yes' ]; then - set -x # Output commands -fi -set -e # Abort on errors - - -################################################################################ -# Search -################################################################################ - -if [ -z "${FFTW3_DIR}" ]; then - echo "BEGIN MESSAGE" - echo "FFTW3 selected, but FFTW3_DIR not set. Checking some places..." - echo "END MESSAGE" - - DIRS="/usr /usr/local /usr/local/packages /usr/local/apps /opt/local ${HOME} c:/packages" - for dir in $DIRS; do - DIRS="$DIRS $dir/fftw3" - done - for dir in $DIRS; do - # libraries might have different file extensions - for libext in a so dylib; do - # libraries can be in /lib or /lib64 - for libdir in lib64 lib/x86_64-linux-gnu lib lib/i386-linux-gnu lib/arm-linux-gnueabihf; do - FILES="include/fftw3.h $libdir/libfftw3.$libext" - # assume this is the one and check all needed files - FFTW3_DIR="$dir" - for file in $FILES; do - # discard this directory if one file was not found - if [ ! -r "$dir/$file" ]; then - unset FFTW3_DIR - break - fi - done - # don't look further if all files have been found - if [ -n "$FFTW3_DIR" ]; then - break - fi - done - # don't look further if all files have been found - if [ -n "$FFTW3_DIR" ]; then - break - fi - done - # don't look further if all files have been found - if [ -n "$FFTW3_DIR" ]; then - break - fi - done - - if [ -z "$FFTW3_DIR" ]; then - echo "BEGIN MESSAGE" - echo "FFTW3 not found" - echo "END MESSAGE" - else - echo "BEGIN MESSAGE" - echo "Found FFTW3 in ${FFTW3_DIR}" - echo "END MESSAGE" - fi -fi - - - -################################################################################ -# Build -################################################################################ - -if [ -z "${FFTW3_DIR}" \ - -o "$(echo "${FFTW3_DIR}" | tr '[a-z]' '[A-Z]')" = 'BUILD' ] -then - echo "BEGIN MESSAGE" - echo "Using bundled FFTW3..." - echo "END MESSAGE" - - # check for required tools. Do this here so that we don't require them when - # using the system library - if [ x$TAR = x ] ; then - echo 'BEGIN ERROR' - echo 'Could not find tar command. Please make sure that (gnu) tar is present' - echo 'and that the TAR variable is set to its location.' - echo 'END ERROR' - exit 1 - fi - #if [ x$PATCH = x ] ; then - # echo 'BEGIN ERROR' - # echo 'Could not find patch command. Please make sure that (gnu) tar is present' - # echo 'and that the PATCH variable is set to its location.' - # echo 'END ERROR' - # exit 1 - #fi - - # Set locations - THORN=FFTW3 - NAME=fftw-3.3.3 - SRCDIR="$(dirname $0)" - BUILD_DIR=${SCRATCH_BUILD}/build/${THORN} - if [ -z "${FFTW3_INSTALL_DIR}" ]; then - INSTALL_DIR=${SCRATCH_BUILD}/external/${THORN} - else - echo "BEGIN MESSAGE" - echo "Installing FFTW3 into ${FFTW3_INSTALL_DIR}" - echo "END MESSAGE" - INSTALL_DIR=${FFTW3_INSTALL_DIR} - fi - DONE_FILE=${SCRATCH_BUILD}/done/${THORN} - FFTW3_DIR=${INSTALL_DIR} - - if [ -e ${DONE_FILE} -a ${DONE_FILE} -nt ${SRCDIR}/dist/${NAME}.tar.gz \ - -a ${DONE_FILE} -nt ${SRCDIR}/configure.sh ] - then - echo "BEGIN MESSAGE" - echo "FFTW3 has already been built; doing nothing" - echo "END MESSAGE" - else - echo "BEGIN MESSAGE" - echo "Building FFTW3" - echo "END MESSAGE" - - # Build in a subshell - ( - exec >&2 # Redirect stdout to stderr - if [ "$(echo ${VERBOSE} | tr '[:upper:]' '[:lower:]')" = 'yes' ]; then - set -x # Output commands - fi - set -e # Abort on errors - cd ${SCRATCH_BUILD} - - # Set up environment - export LDFLAGS="$(echo $LDFLAGS $(for libdir in $LIBDIRS; do echo '' -L$libdir -Wl,-rpath,$libdir; done | sed -e 's/ -L-/ -/g;s/ -Wl,-rpath,-/ -/g'))" - export LIBS="$(echo $(for lib in $LIBS; do echo '' -l$lib; done | sed -e 's/ -l-/ -/g'))" - unset RPATH - if echo '' ${ARFLAGS} | grep 64 >/dev/null 2>&1; then - export OBJECT_MODE=64 - fi - - echo "FFTW3: Preparing directory structure..." - mkdir build external done 2> /dev/null || true - rm -rf ${BUILD_DIR} ${INSTALL_DIR} - mkdir ${BUILD_DIR} ${INSTALL_DIR} - - echo "FFTW3: Unpacking archive..." - pushd ${BUILD_DIR} - ${TAR?} xzf ${SRCDIR}/dist/${NAME}.tar.gz - - echo "FFTW3: Configuring..." - cd ${NAME} - ./configure --prefix=${FFTW3_DIR} - - echo "FFTW3: Building..." - ${MAKE} - - echo "FFTW3: Installing..." - ${MAKE} install - popd - - echo "FFTW3: Cleaning up..." - rm -rf ${BUILD_DIR} - - date > ${DONE_FILE} - echo "FFTW3: Done." - ) - if (( $? )); then - echo 'BEGIN ERROR' - echo 'Error while building FFTW3. Aborting.' - echo 'END ERROR' - exit 1 - fi - fi - -fi - - - -################################################################################ -# Configure Cactus -################################################################################ - -# Set options -if [ "${FFTW3_DIR}" != 'NO_BUILD' ]; then - : ${FFTW3_INC_DIRS="${FFTW3_DIR}/include"} - : ${FFTW3_LIB_DIRS="${FFTW3_DIR}/lib"} -fi -: ${FFTW3_LIBS='fftw3'} - -FFTW3_INC_DIRS="$(${CCTK_HOME}/lib/sbin/strip-incdirs.sh ${FFTW3_INC_DIRS})" -FFTW3_LIB_DIRS="$(${CCTK_HOME}/lib/sbin/strip-libdirs.sh ${FFTW3_LIB_DIRS})" - -# Pass options to Cactus -echo "BEGIN MAKE_DEFINITION" -echo "FFTW3_DIR = ${FFTW3_DIR}" -echo "FFTW3_INC_DIRS = ${FFTW3_INC_DIRS}" -echo "FFTW3_LIB_DIRS = ${FFTW3_LIB_DIRS}" -echo "FFTW3_LIBS = ${FFTW3_LIBS}" -echo "END MAKE_DEFINITION" - -echo 'INCLUDE_DIRECTORY $(FFTW3_INC_DIRS)' -echo 'LIBRARY_DIRECTORY $(FFTW3_LIB_DIRS)' -echo 'LIBRARY $(FFTW3_LIBS)' diff --git a/src/build.sh b/src/build.sh new file mode 100755 index 0000000..74a5b05 --- /dev/null +++ b/src/build.sh @@ -0,0 +1,65 @@ +#! /bin/bash + +################################################################################ +# Build +################################################################################ + +# Set up shell +if [ "$(echo ${VERBOSE} | tr '[:upper:]' '[:lower:]')" = 'yes' ]; then + set -x # Output commands +fi +set -e # Abort on errors + + + +# Set locations +THORN=FFTW3 +NAME=fftw-3.3.3 +SRCDIR="$(dirname $0)" +BUILD_DIR=${SCRATCH_BUILD}/build/${THORN} +if [ -z "${FFTW3_INSTALL_DIR}" ]; then + INSTALL_DIR=${SCRATCH_BUILD}/external/${THORN} +else + echo "BEGIN MESSAGE" + echo "Installing FFTW3 into ${FFTW3_INSTALL_DIR}" + echo "END MESSAGE" + INSTALL_DIR=${FFTW3_INSTALL_DIR} +fi +DONE_FILE=${SCRATCH_BUILD}/done/${THORN} +FFTW3_DIR=${INSTALL_DIR} + +# Set up environment +# export LDFLAGS="$(echo $LDFLAGS $(for libdir in $LIBDIRS; do echo '' -L$libdir -Wl,-rpath,$libdir; done | sed -e 's/ -L-/ -/g;s/ -Wl,-rpath,-/ -/g'))" +# export LIBS="$(echo $(for lib in $LIBS; do echo '' -l$lib; done | sed -e 's/ -l-/ -/g'))" +unset LIBS +unset RPATH +if echo '' ${ARFLAGS} | grep 64 >/dev/null 2>&1; then + export OBJECT_MODE=64 +fi + +echo "FFTW3: Preparing directory structure..." +cd ${SCRATCH_BUILD} +mkdir build external done 2> /dev/null || true +rm -rf ${BUILD_DIR} ${INSTALL_DIR} +mkdir ${BUILD_DIR} ${INSTALL_DIR} + +echo "FFTW3: Unpacking archive..." +pushd ${BUILD_DIR} +${TAR?} xzf ${SRCDIR}/../dist/${NAME}.tar.gz + +echo "FFTW3: Configuring..." +cd ${NAME} +./configure --prefix=${FFTW3_DIR} + +echo "FFTW3: Building..." +${MAKE} + +echo "FFTW3: Installing..." +${MAKE} install +popd + +echo "FFTW3: Cleaning up..." +rm -rf ${BUILD_DIR} + +date > ${DONE_FILE} +echo "FFTW3: Done." diff --git a/src/detect.sh b/src/detect.sh new file mode 100755 index 0000000..d79f14d --- /dev/null +++ b/src/detect.sh @@ -0,0 +1,151 @@ +#! /bin/bash + +################################################################################ +# Prepare +################################################################################ + +# Set up shell +if [ "$(echo ${VERBOSE} | tr '[:upper:]' '[:lower:]')" = 'yes' ]; then + set -x # Output commands +fi +set -e # Abort on errors + + +################################################################################ +# Search +################################################################################ + +if [ -z "${FFTW3_DIR}" ]; then + echo "BEGIN MESSAGE" + echo "FFTW3 selected, but FFTW3_DIR not set. Checking some places..." + echo "END MESSAGE" + + DIRS="/usr /usr/local /usr/local/packages /usr/local/apps /opt/local ${HOME} c:/packages" + for dir in $DIRS; do + DIRS="$DIRS $dir/fftw3" + done + for dir in $DIRS; do + # libraries might have different file extensions + for libext in a so dylib; do + # libraries can be in /lib or /lib64 + for libdir in lib64 lib/x86_64-linux-gnu lib lib/i386-linux-gnu lib/arm-linux-gnueabihf; do + FILES="include/fftw3.h $libdir/libfftw3.$libext" + # assume this is the one and check all needed files + FFTW3_DIR="$dir" + for file in $FILES; do + # discard this directory if one file was not found + if [ ! -r "$dir/$file" ]; then + unset FFTW3_DIR + break + fi + done + # don't look further if all files have been found + if [ -n "$FFTW3_DIR" ]; then + break + fi + done + # don't look further if all files have been found + if [ -n "$FFTW3_DIR" ]; then + break + fi + done + # don't look further if all files have been found + if [ -n "$FFTW3_DIR" ]; then + break + fi + done + + if [ -z "$FFTW3_DIR" ]; then + echo "BEGIN MESSAGE" + echo "FFTW3 not found" + echo "END MESSAGE" + else + echo "BEGIN MESSAGE" + echo "Found FFTW3 in ${FFTW3_DIR}" + echo "END MESSAGE" + fi +fi + + + +################################################################################ +# Build +################################################################################ + +if [ -z "${FFTW3_DIR}" \ + -o "$(echo "${FFTW3_DIR}" | tr '[a-z]' '[A-Z]')" = 'BUILD' ] +then + echo "BEGIN MESSAGE" + echo "Using bundled FFTW3..." + echo "END MESSAGE" + + # Check for required tools. Do this here so that we don't require + # them when using the system library. + if [ "x$TAR" = x ] ; then + echo 'BEGIN ERROR' + echo 'Could not find tar command.' + echo 'Please make sure that the (GNU) tar command is present,' + echo 'and that the TAR variable is set to its location.' + echo 'END ERROR' + exit 1 + fi + if [ "x$PATCH" = x ] ; then + echo 'BEGIN ERROR' + echo 'Could not find patch command.' + echo 'Please make sure that the patch command is present,' + echo 'and that the PATCH variable is set to its location.' + echo 'END ERROR' + exit 1 + fi + + # Set locations + THORN=FFTW3 + BUILD_DIR=${SCRATCH_BUILD}/build/${THORN} + if [ -z "${FFTW3_INSTALL_DIR}" ]; then + INSTALL_DIR=${SCRATCH_BUILD}/external/${THORN} + else + echo "BEGIN MESSAGE" + echo "Installing FFTW3 into ${FFTW3_INSTALL_DIR}" + echo "END MESSAGE" + INSTALL_DIR=${FFTW3_INSTALL_DIR} + fi + FFTW3_DIR=${INSTALL_DIR} +else + THORN=FFTW3 + DONE_FILE=${SCRATCH_BUILD}/done/${THORN} + mkdir ${SCRATCH_BUILD}/done 2> /dev/null || true + date > ${DONE_FILE} +fi + + + +################################################################################ +# Configure Cactus +################################################################################ + +# Pass configuration options to build script +echo "BEGIN MAKE_DEFINITION" +echo "FFTW3_INSTALL_DIR = ${FFTW3_INSTALL_DIR}" +echo "END MAKE_DEFINITION" + +# Set options +if [ "${FFTW3_DIR}" != 'NO_BUILD' ]; then + : ${FFTW3_INC_DIRS="${FFTW3_DIR}/include"} + : ${FFTW3_LIB_DIRS="${FFTW3_DIR}/lib"} +fi +: ${FFTW3_LIBS='fftw3'} + +FFTW3_INC_DIRS="$(${CCTK_HOME}/lib/sbin/strip-incdirs.sh ${FFTW3_INC_DIRS})" +FFTW3_LIB_DIRS="$(${CCTK_HOME}/lib/sbin/strip-libdirs.sh ${FFTW3_LIB_DIRS})" + +# Pass options to Cactus +echo "BEGIN MAKE_DEFINITION" +echo "FFTW3_DIR = ${FFTW3_DIR}" +echo "FFTW3_INC_DIRS = ${FFTW3_INC_DIRS}" +echo "FFTW3_LIB_DIRS = ${FFTW3_LIB_DIRS}" +echo "FFTW3_LIBS = ${FFTW3_LIBS}" +echo "END MAKE_DEFINITION" + +echo 'INCLUDE_DIRECTORY $(FFTW3_INC_DIRS)' +echo 'LIBRARY_DIRECTORY $(FFTW3_LIB_DIRS)' +echo 'LIBRARY $(FFTW3_LIBS)' diff --git a/src/make.code.deps b/src/make.code.deps new file mode 100644 index 0000000..ad4e290 --- /dev/null +++ b/src/make.code.deps @@ -0,0 +1,7 @@ +# Main make.code.deps file for thorn FFTW3 + +export FFTW3_INSTALL_DIR + +$(CCTK_TARGET) $(OBJS) $(SRCS:%=%.d): $(SCRATCH_BUILD)/done/$(THORN) +$(SCRATCH_BUILD)/done/$(THORN): $(SRCDIR)/build.sh + +$(SRCDIR)/build.sh -- cgit v1.2.3