From e64e4837d2347bc878a2479e10ea10509c89648e Mon Sep 17 00:00:00 2001 From: Samuel Audet Date: Sat, 26 Sep 2015 22:57:41 +0900 Subject: [PATCH] * Provide `cppbuild.sh` script for Caffe that includes all dependencies (pull #77) --- CHANGELOG.md | 1 + caffe/cppbuild.sh | 153 ++++++++++++++++++++++++++-------------------- cppbuild.sh | 1 + 3 files changed, 90 insertions(+), 65 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f372f139a7a..f5ddc1d66f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ + * Provide `cppbuild.sh` script for Caffe that includes all dependencies ([pull #77](https://github.com/bytedeco/javacpp-presets/pull/77)) * Upgrade presets for Caffe, CUDA 7.5, cuDNN 3, FFmpeg 2.8, LLVM 3.7.0, Tesseract 3.04 * Include `motion_vector.h`, `fifo.h`, and `audio_fifo.h` header files in the `avutil` module of FFmpeg ([issue #79](https://github.com/bytedeco/javacpp-presets/issues/79)) * Add presets for Chilitags, thanks to Chris Walters for the financial contribution diff --git a/caffe/cppbuild.sh b/caffe/cppbuild.sh index 2f58e15149e..dadb63ec250 100755 --- a/caffe/cppbuild.sh +++ b/caffe/cppbuild.sh @@ -7,50 +7,79 @@ if [[ -z "$PLATFORM" ]]; then exit fi -if [[ $PLATFORM == windows* ]]; then - echo TODO -else - GLOG=0.3.4 - GFLAGS=2.1.2 - PROTO=2.6.1 - LEVELDB=1.18 - SNAPPY=1.1.3 - LMDB=0.9.15 - BOOST=1_57_0 # also change the download link, 1.58 incompatible with OSX - HDF5=1.8.15-patch1 - BLAS=0.2.14 - MAKEJ="${MAKEJ:-4}" - - download https://github.com/google/glog/archive/v$GLOG.tar.gz v$GLOG.tar.gz - download https://github.com/gflags/gflags/archive/v$GFLAGS.tar.gz v$GFLAGS.tar.gz - download https://github.com/google/protobuf/releases/download/v$PROTO/protobuf-$PROTO.tar.gz protobuf-$PROTO.tar.gz - download https://github.com/google/leveldb/archive/v$LEVELDB.tar.gz v$LEVELDB.tar.gz - download https://github.com/google/snappy/releases/download/$SNAPPY/snappy-$SNAPPY.tar.gz snappy-$SNAPPY.tar.gz - download https://github.com/LMDB/lmdb/archive/LMDB_$LMDB.tar.gz LMDB_$LMDB.tar.gz - download http://iweb.dl.sourceforge.net/project/boost/boost/1.57.0/boost_$BOOST.tar.gz boost_$BOOST.tar.gz - download http://www.hdfgroup.org/ftp/HDF5/current/src/hdf5-$HDF5.tar.bz2 hdf5-$HDF5.tar.bz2 - download https://github.com/xianyi/OpenBLAS/archive/v$BLAS.tar.gz v$BLAS.tar.gz - - mkdir -p $PLATFORM - cd $PLATFORM - INSTALL_PATH=`pwd` - mkdir -p include - mkdir -p lib - - echo "Decompressing archives" - tar --totals -xzf ../v$GLOG.tar.gz - tar --totals -xzf ../v$GFLAGS.tar.gz - tar --totals -xzf ../protobuf-$PROTO.tar.gz - tar --totals -xzf ../v$LEVELDB.tar.gz - tar --totals -xzf ../snappy-$SNAPPY.tar.gz - tar --totals -xzf ../LMDB_$LMDB.tar.gz - tar --totals -xzf ../boost_$BOOST.tar.gz - tar --totals -xjf ../hdf5-$HDF5.tar.bz2 - tar --totals -xzf ../v$BLAS.tar.gz -fi +case $PLATFORM in + linux-x86) + export CPU_ONLY=1 + export CC="gcc -m32" + export CXX="g++ -m32" + export BINARY=32 + export BLAS=open + ;; + linux-x86_64) + export CC="gcc -m64" + export CXX="g++ -m64" + export BINARY=64 + export BLAS=open + ;; + macosx-*) + export CC="clang" + export CXX="clang++" + export LDFLAGS="-undefined dynamic_lookup" + export BINARY=64 + export BLAS=atlas + ;; + *) + echo "Error: Platform \"$PLATFORM\" is not supported" + return 0 + ;; +esac + +GLOG=0.3.4 +GFLAGS=2.1.2 +PROTO=2.6.1 +LEVELDB=1.18 +SNAPPY=1.1.3 +LMDB=0.9.15 +BOOST=1_57_0 # 1.58 incompatible with OSX +HDF5=1.8.15-patch1 +OPENBLAS=0.2.14 +CAFFE_VERSION=master + +download https://github.com/google/glog/archive/v$GLOG.tar.gz glog-$GLOG.tar.gz +download https://github.com/gflags/gflags/archive/v$GFLAGS.tar.gz gflags-$GFLAGS.tar.gz +download https://github.com/google/protobuf/releases/download/v$PROTO/protobuf-$PROTO.tar.gz protobuf-$PROTO.tar.gz +download https://github.com/google/leveldb/archive/v$LEVELDB.tar.gz leveldb-$LEVELDB.tar.gz +download https://github.com/google/snappy/releases/download/$SNAPPY/snappy-$SNAPPY.tar.gz snappy-$SNAPPY.tar.gz +download https://github.com/LMDB/lmdb/archive/LMDB_$LMDB.tar.gz lmdb-LMDB_$LMDB.tar.gz +download http://iweb.dl.sourceforge.net/project/boost/boost/${BOOST//_/.}/boost_$BOOST.tar.gz boost_$BOOST.tar.gz +download http://www.hdfgroup.org/ftp/HDF5/current/src/hdf5-$HDF5.tar.bz2 hdf5-$HDF5.tar.bz2 +download https://github.com/xianyi/OpenBLAS/archive/v$OPENBLAS.tar.gz OpenBLAS-$OPENBLAS.tar.gz +download https://github.com/BVLC/caffe/archive/master.tar.gz caffe-$CAFFE_VERSION.tar.gz + +mkdir -p $PLATFORM +cd $PLATFORM +INSTALL_PATH=`pwd` +mkdir -p include lib bin + +OPENCV_PATH="$INSTALL_PATH/../../../opencv/cppbuild/$PLATFORM/" + +echo "Decompressing archives" +tar --totals -xzf ../glog-$GLOG.tar.gz +tar --totals -xzf ../gflags-$GFLAGS.tar.gz +tar --totals -xzf ../protobuf-$PROTO.tar.gz +tar --totals -xzf ../leveldb-$LEVELDB.tar.gz +tar --totals -xzf ../snappy-$SNAPPY.tar.gz +tar --totals -xzf ../lmdb-LMDB_$LMDB.tar.gz +tar --totals -xzf ../boost_$BOOST.tar.gz +tar --totals -xjf ../hdf5-$HDF5.tar.bz2 +tar --totals -xzf ../OpenBLAS-$OPENBLAS.tar.gz +tar --totals -xzf ../caffe-$CAFFE_VERSION.tar.gz + +export CFLAGS="-fPIC" +export CXXFLAGS="-fPIC" cd glog-$GLOG -./configure --prefix=$INSTALL_PATH +./configure "--prefix=$INSTALL_PATH" --disable-shared make -j $MAKEJ make install cd .. @@ -58,42 +87,42 @@ cd .. cd gflags-$GFLAGS mkdir -p build cd build -export CXXFLAGS="-fPIC" && cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=$INSTALL_PATH .. +"$CMAKE" -DBUILD_SHARED_LIBS=OFF "-DCMAKE_INSTALL_PREFIX=$INSTALL_PATH" .. make -j $MAKEJ make install cd ../.. cd protobuf-$PROTO -./configure --prefix=$INSTALL_PATH +./configure "--prefix=$INSTALL_PATH" --disable-shared make -j $MAKEJ make install cd .. cd leveldb-$LEVELDB make -j $MAKEJ -cp -a libleveldb.* $INSTALL_PATH/lib -cp -a include/leveldb $INSTALL_PATH/include/ +cp -a libleveldb.a "$INSTALL_PATH/lib" +cp -a include/leveldb "$INSTALL_PATH/include/" cd .. cd snappy-$SNAPPY -./configure --prefix=$INSTALL_PATH +./configure "--prefix=$INSTALL_PATH" --disable-shared make -j $MAKEJ make install cd .. cd lmdb-LMDB_$LMDB/libraries/liblmdb -make -j $MAKEJ +make -j $MAKEJ "CC=$CC" "XCFLAGS=$CFLAGS" "CPPFLAGS=$CXXFLAGS" cp -a lmdb.h ../../../include/ -cp -a liblmdb.so ../../../lib/ +cp -a liblmdb.a ../../../lib/ cd ../../.. cd boost_$BOOST ./bootstrap.sh --with-libraries=system,thread -./b2 install --prefix=$INSTALL_PATH +./b2 install "--prefix=$INSTALL_PATH" address-model=$BINARY link=static "cxxflags=$CXXFLAGS" cd .. cd hdf5-$HDF5 -./configure --prefix=$INSTALL_PATH +./configure "--prefix=$INSTALL_PATH" --disable-shared make -j $MAKEJ make install cd .. @@ -101,26 +130,20 @@ cd .. # OSX has Accelerate if [[ $PLATFORM != macosx-* ]]; then # blas (requires fortran, e.g. sudo yum install gcc-gfortran) - cd OpenBLAS-$BLAS + cd OpenBLAS-$OPENBLAS # CentOS compiler version can't compile AVX2 instructions, TODO update compiler - make -j $MAKEJ NO_AVX2=1 - make install PREFIX=$INSTALL_PATH - cd .. + make -j $MAKEJ "CC=$CC" BINARY=$BINARY NO_AVX2=1 NO_SHARED=1 + make install "PREFIX=$INSTALL_PATH" NO_SHARED=1 + cd .. fi -CAFFE_VERSION=master -download https://github.com/BVLC/caffe/archive/master.zip ../caffe-$CAFFE_VERSION.zip -unzip ../caffe-$CAFFE_VERSION.zip cd caffe-$CAFFE_VERSION - cp Makefile.config.example Makefile.config -printf "\n" >> Makefile.config -printf "INCLUDE_DIRS += ../include ../../../../opencv/cppbuild/linux-x86_64/include\n" >> Makefile.config -printf "LIBRARY_DIRS += ../lib ../../../../opencv/cppbuild/linux-x86_64/lib\n" >> Makefile.config -printf "BLAS := open\n" >> Makefile.config export PATH=../bin:$PATH -export LD_LIBRARY_PATH=../lib:$LD_LIBRARY_PATH -CC="gcc -m64" CXX="g++ -m64" BLAS=open DISTRIBUTE_DIR=.. make -j $MAKEJ lib +export CXXFLAGS="-I../include -I$OPENCV_PATH/include" +export NVCCFLAGS="-I../include -I$OPENCV_PATH/include" +export LINKFLAGS="-L../lib -L$OPENCV_PATH/lib" +make -j $MAKEJ BLAS=$BLAS DISTRIBUTE_DIR=.. lib # Manual deploy to avoid Caffe's python build mkdir -p ../include/caffe/proto cp -a include/caffe/* ../include/caffe/ diff --git a/cppbuild.sh b/cppbuild.sh index 86394f41448..d06df1e0eb1 100755 --- a/cppbuild.sh +++ b/cppbuild.sh @@ -3,6 +3,7 @@ set -eu [[ -z ${CMAKE:-} ]] && CMAKE=cmake +[[ -z ${MAKEJ:-} ]] && MAKEJ=4 KERNEL=(`uname -s | tr [A-Z] [a-z]`) ARCH=(`uname -m | tr [A-Z] [a-z]`)