build 12.3 KB
Newer Older
1 2
#! /bin/sh

3
fmt="SDF"
4

5 6
fullversion=`visit -version 2>&1 | sed 's,.* \([0-9\.]*\),\1,'`
version=${fullversion%%\.*}
Keith Bennett's avatar
Keith Bennett committed
7
[ "$version" -gt 2 ] && version=2
8
tmpdir=.builddir
9

10
clean=0
11
build_type=0
12 13
build_visit_reader=1
build_utilities=0
14
force=0
15 16 17 18
DBG=""
DEBUG=""
PRIVATE="-private"
VERBOSE=""
19
OPTS=""
20
PLUGINDIR=""
21
LDFLAGS=""
22
err=0
23
stop=0
24

25
while getopts crdpnuvfh123i: name
26 27
do
   case $name in
28 29
      c) clean=2 ; OPTS="$OPTS -c";;
      r) clean=1 ; OPTS="$OPTS -r";;
30
      d) DBG="-g -O0"; OPTS="$OPTS -d";
31
         DEBUG="-DCMAKE_BUILD_TYPE=Debug" ;;
32
      p) PRIVATE="-public"; OPTS="$OPTS -p" ;;
33 34
      n) build_visit_reader=0 ;;
      u) build_utilities=1 ;;
35
      v) VERBOSE="VERBOSE=1" ;;
36
      f) force=1 ;;
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
      h) cat <<EOF
The VisIt build script attempts to automate the process of building the SDF
VisIt reader plugin on a variety of platforms. By default it will try three
approaches to building the plugin. First it tries the build environment
supplied by the VisIt installation. If this fails, it will attempt to build a
parallel version of the plugin using the mpi compiler in the current search
path. Finally, it will try just building the serial version of the plugin.

VisIt build script options:
  -c: Clean up files. Do not build anything.
  -r: Rebuild. Clean up files and then build.
  -d: Build with debugging flags enabled.
  -p: Do a "public" build. This passes the "-public" flag on to the VisIt build
      system which copies the binaries into a publically accessible location.
  -n: Don't build the VisIt reader plugin.
  -u: Do build the additional SDF utilities.
53 54
  -i VISITPLUGINDIR:
      Install the reader plugin in the path VISITPLUGINDIR
55
  -v: Build verbosely.
56 57
  -f: Force build. This prevents the build script from checking
      g++ compatibility
58 59 60 61 62
  -1: Perform only the default VisIt build.
  -2: Perform only a parallel VisIt build.
  -3: Perform only a serial VisIt build.
EOF
         exit ;;
63 64 65
      1) build_type=1 ; stop=1 ;;
      2) build_type=2 ; stop=1 ;;
      3) build_type=3 ; stop=1 ;;
66
   i) PLUGINDIR="$OPTARG"
67 68
   esac
done
69 70 71 72

# Find directory containing the actual visit binary
cwd=`pwd`
cmd=`which visit`
73 74 75 76 77
if [ "$cmd"x = x ]; then
  echo ERROR: The command 'visit' was not found in your search PATH
  exit 1
fi

78 79 80 81 82 83 84 85 86 87 88 89 90
i=0
while [ $i -lt 100 ]; do
  visitpath=`dirname $cmd`
  cd "$visitpath"
  [ "$visitpath"x = "."x ] && visitpath=`pwd`
  cmd=`basename $cmd`
  cmd=`readlink $cmd`
  [ "$cmd"x = x ] && break
  i=$((i+1))
done
cd "$cwd"


91
export PATH="$visitpath:$PATH"
92
export CXXFLAGS="-Wno-deprecated $DBG"
93
export CFLAGS="$DBG"
94

95 96
stdlib="$CXXFLAGS"

97 98 99 100 101 102 103
# Auto-detect C++ compiler
cpp=$CXX
[ "$cpp"x = x ] && cpp=$(which c++)
[ "$cpp"x = x ] && cpp=$(which cpp)
[ "$cpp"x = x ] && cpp=$(which g++)
$cpp --version | grep -i clang > /dev/null 2>&1
if [ $? -eq 0 ]; then
104
  stdlib="-stdlib=libstdc++ $CXXFLAGS"
105
fi
106

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
# Sanity check for version 1 or 2 of visit
if [ $clean -ne 2 -a "$version"x != 1x -a "$version"x != 2x ]; then
  echo "ERROR: unable to locate either version 1 or 2 of VisIt"
  echo "The output from 'visit -version' was the following:"
  visit -version
  visit -version 2>&1 | grep 'will be launched' > /dev/null
  if [ $? -eq 0 ]; then
    cat<<EOF
It looks as if the visit command in your PATH has been built from source and
not installed. 3rd party plugins are not supported for this configuration.
You need to install visit properly by cd'ing to the visitX.X.X/src directory
and typing either "make install" or "make package". The latter command will
create a zipped archive which you can then unpack to the desired location.
EOF
  fi
  exit 1
fi

125 126 127 128 129 130 131 132 133 134 135
copy_cmake_files () {
  [ -d $tmpdir ] || mkdir -p $tmpdir
  cp MISC/v2.13.3_ub18/* $tmpdir
  sed 's,${VISIT_INCLUDE_DIR}/VisItMacros.cmake,'$tmpdir'/VisItMacros.cmake,' \
      MISC/v2.13.3_ub18/PluginVsInstall.cmake > $tmpdir/PluginVsInstall.cmake
  sed 's,INCLUDE(".*\(/[^/]*\),INCLUDE("'$tmpdir'\1,' \
      CMakeLists.txt > $tmpdir/tmp
  mv $tmpdir/tmp CMakeLists.txt
  setup=$tmpdir/PluginVsInstall.cmake
}

136
buildit () {
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
  err=0

  purge=0
  buildver="$build_type -- $fullversion"
  oldbuildver=""
  [ -r $tmpdir/buildver ] && oldbuildver=`cat $tmpdir/buildver`
  if [ "$oldbuildver"x != "$buildver"x ]; then
    purge=1
    rm -rf $tmpdir
    mkdir -p $tmpdir
    echo "$buildver" > $tmpdir/buildver
    rm -rf CMake* cmake* Makefile
  else
    echo "No need to purge"
  fi

  if [ "$version"x = x ]; then
    echo "Unable to build. Please add visit to your \$PATH"
    exit 1
  fi

158 159 160
  (cd ../C/src
   sh gen_commit_string.sh .)

161
  if [ $purge -ne 0 ]; then
162 163 164 165
    xml2info -clobber $PRIVATE ${fmt}${version}.xml

    if [ $version -eq 1 ]; then
      xml2makefile -clobber $PRIVATE ${fmt}${version}.xml
166
      if [ "`uname -m`"x = "x86_64x" ]; then
167 168
        sed "s,\(^CXXFLAGS.*\),\1 -m32 $DBG\\
CFLAGS=\$(CFLAGSORIG) -m32 $DBG\\
169 170
PY_CXXFLAGS=-I\$(TOPDIR)/include/python,;s,\(^LDFLAGS.*\),\1 -m32 $DBG," \
    Makefile > .Makefile.tmp
171
        \mv -f .Makefile.tmp Makefile
172
      fi
173
      if [ $build_type -eq 2 ]; then
174 175 176 177
        sed "s,\(^CXXFLAGS.*\),\1\\
CXX=mpic++\\
CC=mpicc," Makefile > .Makefile.tmp
        \mv -f .Makefile.tmp Makefile
178
      elif [ $build_type -eq 3 ]; then
179 180 181
        grep -v "^EPARDSO" Makefile > .Makefile.tmp
        \mv -f .Makefile.tmp Makefile
      fi
182 183
    else
      xml2cmake -clobber $PRIVATE ${fmt}${version}.xml
184
      if [ -n "$PLUGINDIR" ] ; then
185
         # Change the VisIt plugin directory
186 187 188
         sed '/VISIT_PLUGIN_DIR/ s;".*";"'$PLUGINDIR'";' \
             CMakeLists.txt > $tmpdir/tmp
         \mv -f $tmpdir/tmp CMakeLists.txt
189 190 191 192 193 194 195

         # Add directories to the runtime path.
         # This avoids having to set LD_LIBRARY_PATH in the bash environment
         # to find sdf_extension.so.
         # Assume that it is one level up from the VisIt plugin directory.
         # FIXME: This should be configurable.
         RPATH=$(dirname $PLUGINDIR)
196 197 198 199 200
         sed '/PROJECT/ a\
LIST(APPEND CMAKE_INSTALL_RPATH "'"$RPATH"'")\
SET(CMAKE_BUILD_WITH_INSTALL_RPATH ON)\
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)' CMakeLists.txt > $tmpdir/tmp
         \mv -f $tmpdir/tmp CMakeLists.txt
201
      fi
202
      setup=$(grep -w PluginVsInstall.cmake CMakeLists.txt | cut -f2 -d\")
203 204 205 206
      rm -f include lib
      inc=$(dirname $setup)
      ln -s $inc .
      ln -s $(dirname $inc)/lib .
207
      ln -s $(dirname $inc)/archives .
208 209 210
      if [ ! -f $setup ]; then
        copy_cmake_files
      fi
211
      if [ $build_type -ne 2 ]; then
212
        build_cxx=$(grep CMAKE_CXX_COMPILER $setup \
213 214 215 216
            | head -1 | cut -f2- -d\/ | cut -f1 -d\))
        if [ -x $build_cxx ]; then
          export CXX=$build_cxx
        fi
217
        build_cc=$(grep CMAKE_C_COMPILER $setup \
218 219 220 221 222
            | head -1 | cut -f2- -d\/ | cut -f1 -d\))
        if [ -x $build_cc ]; then
          export CC=$build_cc
        fi
      fi
223 224 225 226 227 228
      grep -w clang $setup > /dev/null
      if [ $? -ne 0 ]; then
        # If using clang when original was compiled with gcc, then we need
        # to add a flag for stdlib
        export CXXFLAGS="$stdlib"
      fi
229 230
      for f in `grep -w INCLUDE CMakeLists.txt | cut -f2 -d\( | \
          cut -f1 -d\) | tr -d \"`; do
231
        base=`basename $f`
232 233
        com1=vtkCommonDataModel
        com2=vtkCommonExecutionModel
234
        sed 's/\([;"]'$com1'-\)\([^;]*\)/\1\2;'$com2'-\2/;
CFSA's avatar
CFSA committed
235
             s,${VISIT_LIBRARY_DIR}/${VISIT_LIBRARY_DIR}${VISIT_LIBRARY_DIR},,g;
236
             s,[^; "]*/Users[^;]*/,,g' \
237
            $f > $tmpdir/tmp
CFSA's avatar
CFSA committed
238 239 240
        grep -Fv -e cognomen_LIB_DEPENDS -e mpicom_LIB_DEPENDS \
            $tmpdir/tmp > $tmpdir/$base
        rm $tmpdir/tmp
241
        if [ $build_type -eq 2 ]; then
242 243
          sed 's/\([;"]\)[^;]*libmpi[^;]*;/\1/g;
               s/\([;"]\)[^;]*libopen-[^;]*;/\1/g;
244
               s,[^; "]*/Users[^;]*/,,g;
CFSA's avatar
CFSA committed
245
               s,${VISIT_LIBRARY_DIR}/${VISIT_LIBRARY_DIR}${VISIT_LIBRARY_DIR},,g;
246
               s/\([;"]\)[^;]*general[^;]*;/\1/g' $f > $tmpdir/tmp
CFSA's avatar
CFSA committed
247 248 249 250
          grep -Fv -e cognomen_LIB_DEPENDS -e mpicom_LIB_DEPENDS \
              -e 'CMAKE_CXX_COMPILER ' -e 'CMAKE_C_COMPILER ' \
              -e 'VISIT_PARALLEL_LIBS ' $tmpdir/tmp > $tmpdir/$base
          rm $tmpdir/tmp
251
        elif [ $build_type -eq 3 ]; then
252 253
          sed 's/\([;"]\)[^;]*libmpi[^;]*;/\1/g;
               s/\([;"]\)[^;]*libopen-[^;]*;/\1/g;
CFSA's avatar
CFSA committed
254
               s,${VISIT_LIBRARY_DIR}/${VISIT_LIBRARY_DIR}${VISIT_LIBRARY_DIR},,g;
255
               s,\(${VISIT_LIBRARY_DIR}/\).*/\([^/;]*;\),\1\2,g;
256
               s,[^; "]*/Users[^;]*/,,g' $f > $tmpdir/tmp
CFSA's avatar
CFSA committed
257 258 259
          grep -Fv -e cognomen_LIB_DEPENDS -e mpicom_LIB_DEPENDS \
              -e 'VISIT_PARALLEL ' $tmpdir/tmp > $tmpdir/$base
          rm $tmpdir/tmp
260 261
        fi
        sed 's,\(INCLUDE(["]*\)'$f'\(["]*\),\1'$tmpdir/$base'\2,' \
262 263 264
            CMakeLists.txt > $tmpdir/tmp
        mv $tmpdir/tmp CMakeLists.txt
      done
265
      setup=$(grep -w PluginVsInstall.cmake CMakeLists.txt | cut -f2 -d\")
266 267 268 269 270 271 272
      # Fixup the cmake file for broken versions of VisIt
      if [ $fullversion = "2.7.2." -o $fullversion = "2.7.3." ]; then
        sed 's/\(.*GET currentDefs\)/if (currentDefs)\
\1/;
           s/\(ENDIF(${firstItem}.*\)/\1\
endif()/' $setup > $tmpdir/tmp
        mv $tmpdir/tmp $setup
273 274 275 276 277 278 279 280 281 282
      else
        fpath=/Applications/VisIt.app/Contents/Resources/${fullversion%%.}/
        sed 's,EAVL_INCLUDE_DIR /Users.*/eavl/[^/]*/\(.*\)),EAVL_INCLUDE_DIR \
 '$fpath'\1/eavl/include),;
           s,BOOST_INCLUDE_DIR /Users.*/boost/[^/]*/\(.*\)),BOOST_INCLUDE_DIR \
 '$fpath'\1/boost/include),;
           s,EAVL_LIBRARY_DIR /Users.*/eavl/[^/]*/\(.*\)/lib),EAVL_LIBRARY_DIR \
 '$fpath'\1/archives),' \
           $setup > $tmpdir/tmp
        mv $tmpdir/tmp $setup
283
      fi
284
    fi
285 286 287 288
    cmake $DEBUG .
    # FIXME: This is to workaround incorrect cmake output
    ofile=CMakeFiles/ESDFDatabase_par.dir/build.make
    if [ -e $ofile ]; then
289 290 291
      sed '/lib64\/librt\.so/ d;
           /lib64\/libpthread\.so/ d;
           /linux-x86_64\/lib\/librt\.so/ d;
292 293 294
           /linux-x86_64\/lib\/libpthread\.so/ d' $ofile > $tmpdir/tmp
      mv $tmpdir/tmp $ofile
    fi
295
  fi
296

297
  gnu=$(grep CXX_COMPILER_ID CMakeFiles/*/CMakeCXXCompiler.cmake | grep GNU)
298
  if [ $force -eq 0 -a "$gnu"x != x ]; then
299 300 301 302 303 304 305
    # Test for compatible version

    setup=$(grep -w PluginVsInstall.cmake CMakeLists.txt | cut -f2 -d\")
    gxxver=$(grep -A10 'compiler version information' $setup | grep g++ \
             | head -1 | cut -f2 -d\) | cut -f2 -d' ' | cut -f1 -d\.)
    cxxver=$(grep CXX_COMPILER_VERSION CMakeFiles/*/CMakeCXXCompiler.cmake \
             | cut -f2 -d\" | cut -f1 -d\.)
306 307 308 309 310 311
    if [ "$gxxver"x != x ]; then
      if [ $cxxver -ne $gxxver ]; then
        echo "ERROR: g++ version is incompatible with VisIt"
        echo "The reader must be compiled using g++ $gxxver.x"
        return 1
      fi
312 313 314
    fi
  fi

315 316
  if [ $clean -ge 1 ] ; then make clean ; fi
  make $VERBOSE
317 318 319 320 321 322 323
  err=$?

  if [ $err -eq 0 ]; then
    echo
    echo "VisIt ${fmt} reader successfully built.${srl}"
  fi

324
  if [ $stop -ne 0 ] ; then exit $err; fi
325
  return $err
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
}

build_default () {
  srl=""
  build_type=1
  buildit
  err=$?
}

build_parallel () {
  srl=""
  build_type=2
  # Execute in a subshell to stop CC being altered in the current shell.
  (export CC=mpicc
  export CXX=mpicxx
  buildit)
  err=$?
}

build_serial () {
  srl=" (Serial version only)."
  build_type=3
  buildit
  err=$?
}

get_old_build_type () {
  type=1
  [ -r $tmpdir/buildver ] && type=`cut -c1 $tmpdir/buildver`
  return $type
356 357
}

358
if [ $clean -ge 1 ]; then
359
  make clean > /dev/null 2>&1
360
  rm -rf CMake* cmake* Makefile ${fmt}*Info.C ${fmt}*Info.h $tmpdir
361 362 363 364 365
  if [ $clean -ge 2 ] ; then
     exit
  fi
fi
if [ $build_visit_reader -eq 1 ]; then
366
  sh gen_commit_string.sh .
367
  echo "#define SDF_READER_BUILD_DATE \"`date`\"" > build_date.h
368

369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
  if [ $build_type -eq 1 ]; then
    build_default
  elif [ $build_type -eq 2 ]; then
    build_parallel
  elif [ $build_type -eq 3 ]; then
    build_serial
  else
    get_old_build_type
    tried=$?
    if [ $tried -eq 1 ]; then
      build_default
    elif [ $tried -eq 2 ]; then
      build_parallel
    elif [ $tried -eq 3 ]; then
      build_serial
    fi
385

386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
    if [ $err -ne 0 -a $tried -ne 1 ]; then
      echo
      echo "Trying again with default"
      build_default
    fi
    if [ $err -ne 0 -a $tried -ne 2 ]; then
      echo
      echo "Trying again with mpicc"
      build_parallel
    fi
    if [ $err -ne 0 -a $tried -ne 3 ]; then
      echo
      echo "Trying again without parallel reader."
      build_serial
    fi
401
  fi
402 403 404 405 406

  if [ $err -ne 0 ]; then
    echo "ERROR: Failed to build VisIt reader."
    exit 1
  fi
407
fi