build 12.2 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%%\.*}
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 158
  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

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

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

         # 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)
193 194 195 196 197
         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
198
      fi
199
      setup=$(grep -w PluginVsInstall.cmake CMakeLists.txt | cut -f2 -d\")
200 201 202 203
      rm -f include lib
      inc=$(dirname $setup)
      ln -s $inc .
      ln -s $(dirname $inc)/lib .
204
      ln -s $(dirname $inc)/archives .
205 206 207
      if [ ! -f $setup ]; then
        copy_cmake_files
      fi
208
      if [ $build_type -ne 2 ]; then
209
        build_cxx=$(grep CMAKE_CXX_COMPILER $setup \
210 211 212 213
            | head -1 | cut -f2- -d\/ | cut -f1 -d\))
        if [ -x $build_cxx ]; then
          export CXX=$build_cxx
        fi
214
        build_cc=$(grep CMAKE_C_COMPILER $setup \
215 216 217 218 219
            | head -1 | cut -f2- -d\/ | cut -f1 -d\))
        if [ -x $build_cc ]; then
          export CC=$build_cc
        fi
      fi
220 221 222 223 224 225
      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
226 227
      for f in `grep -w INCLUDE CMakeLists.txt | cut -f2 -d\( | \
          cut -f1 -d\) | tr -d \"`; do
228
        base=`basename $f`
229 230
        com1=vtkCommonDataModel
        com2=vtkCommonExecutionModel
231
        sed 's/\([;"]'$com1'-\)\([^;]*\)/\1\2;'$com2'-\2/;
232
             s,${VISIT_LIBRARY_DIR}/${VISIT_LIBRARY_DIR}${VISIT_LIBRARY_DIR},,g;
233
             s,[^; "]*/Users[^;]*/,,g' \
234
            $f > $tmpdir/tmp
235 236 237
        grep -Fv -e cognomen_LIB_DEPENDS -e mpicom_LIB_DEPENDS \
            $tmpdir/tmp > $tmpdir/$base
        rm $tmpdir/tmp
238
        if [ $build_type -eq 2 ]; then
239 240
          sed 's/\([;"]\)[^;]*libmpi[^;]*;/\1/g;
               s/\([;"]\)[^;]*libopen-[^;]*;/\1/g;
241
               s,[^; "]*/Users[^;]*/,,g;
242
               s,${VISIT_LIBRARY_DIR}/${VISIT_LIBRARY_DIR}${VISIT_LIBRARY_DIR},,g;
243
               s/\([;"]\)[^;]*general[^;]*;/\1/g' $f > $tmpdir/tmp
244 245 246 247
          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
248
        elif [ $build_type -eq 3 ]; then
249 250
          sed 's/\([;"]\)[^;]*libmpi[^;]*;/\1/g;
               s/\([;"]\)[^;]*libopen-[^;]*;/\1/g;
251
               s,${VISIT_LIBRARY_DIR}/${VISIT_LIBRARY_DIR}${VISIT_LIBRARY_DIR},,g;
252
               s,\(${VISIT_LIBRARY_DIR}/\).*/\([^/;]*;\),\1\2,g;
253
               s,[^; "]*/Users[^;]*/,,g' $f > $tmpdir/tmp
254 255 256
          grep -Fv -e cognomen_LIB_DEPENDS -e mpicom_LIB_DEPENDS \
              -e 'VISIT_PARALLEL ' $tmpdir/tmp > $tmpdir/$base
          rm $tmpdir/tmp
257 258
        fi
        sed 's,\(INCLUDE(["]*\)'$f'\(["]*\),\1'$tmpdir/$base'\2,' \
259 260 261
            CMakeLists.txt > $tmpdir/tmp
        mv $tmpdir/tmp CMakeLists.txt
      done
262
      setup=$(grep -w PluginVsInstall.cmake CMakeLists.txt | cut -f2 -d\")
263 264 265 266 267 268 269
      # 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
270 271 272 273 274 275 276 277 278 279
      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
280
      fi
281
    fi
282 283 284 285
    cmake $DEBUG .
    # FIXME: This is to workaround incorrect cmake output
    ofile=CMakeFiles/ESDFDatabase_par.dir/build.make
    if [ -e $ofile ]; then
286 287 288
      sed '/lib64\/librt\.so/ d;
           /lib64\/libpthread\.so/ d;
           /linux-x86_64\/lib\/librt\.so/ d;
289 290 291
           /linux-x86_64\/lib\/libpthread\.so/ d' $ofile > $tmpdir/tmp
      mv $tmpdir/tmp $ofile
    fi
292
  fi
293

294
  gnu=$(grep CXX_COMPILER_ID CMakeFiles/*/CMakeCXXCompiler.cmake | grep GNU)
295
  if [ $force -eq 0 -a "$gnu"x != x ]; then
296 297 298 299 300 301 302
    # 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\.)
303 304 305 306 307 308
    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
309 310 311
    fi
  fi

312 313
  if [ $clean -ge 1 ] ; then make clean ; fi
  make $VERBOSE
314 315 316 317 318 319 320
  err=$?

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

321
  if [ $stop -ne 0 ] ; then exit $err; fi
322
  return $err
323 324 325 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
}

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
353 354
}

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

366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
  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
382

383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
    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
398
  fi
399 400 401 402 403

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