summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 334d33e1d7227423065bf2083ffaaaf49db033d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Maintainer : Daniel Bermond < yahoo-com: danielbermond >
# Contributor: Micah Chambers <micahc.vt@gmail.com>

pkgname=caffe
pkgver=rc5
pkgrel=3
pkgdesc="A deep learning framework made with expression, speed, and modularity in mind (gpu enabled)"
arch=('x86_64')
url="http://caffe.berkeleyvision.org/"
license=('BSD')
depends=( # binary repositories:
          'boost-libs' 'protobuf' 'google-glog' 'gflags' 'hdf5' 'opencv' 'leveldb'
          'lmdb' 'cuda' 'python2' 'boost' 'cython2' 'python2-h5py' 'ipython2'
          'python2-matplotlib' 'python2-networkx' 'python2-nose' 'python2-numpy'
          'python2-pandas' 'python2-protobuf' 'python2-gflags' 'python2-scikit-learn'
          'python2-scipy' 'python2-pydot'
          # AUR:
          'openblas-lapack' 'python2-leveldb' 'python2-scikit-image')
makedepends=('doxygen' 'texlive-core')
conflicts=('caffe-git' 'caffe-cpu' 'caffe-cpu-git' 'caffe-dr-git' 'caffe-mnc-dr-git'
           'caffe2' 'caffe2-git' 'caffe2-cpu' 'caffe2-cpu-git')
source=("${pkgname}-${pkgver}.tar.gz"::"https://github.com/BVLC/${pkgname}/archive/rc.tar.gz")
noextract=("${pkgname}-${pkgver}.tar.gz")
sha256sums=('7da46e2802c5d85e41aeda79bf27e907fc317fb1ecf96800403f4a57f1cd0dfb')

prepare() {
    # extract source file to a directory in the format $pkgname-$pkgver
    mkdir -p "${pkgname}-${pkgver}"
    cd "${pkgname}-${pkgver}"
    tar xf ../"${pkgname}-${pkgver}.tar.gz" --strip 1
    
    # compile fix: add 'opencv_imgcodecs' library to Makefile
    sed -i '/opencv_imgproc/s/$/ opencv_imgcodecs/' Makefile
    
    # prepare to configure options in Makefile.config
    cp -f Makefile.config.example Makefile.config
    
    # use gcc5 (gcc6 do not work)
    sed -i '/CUSTOM_CXX/s/^#[[:space:]]//;/CUSTOM_CXX/s/$/-5/' Makefile.config
    
    # set CUDA directory
    sed -i '/CUDA_DIR/s/\/usr\/local\/cuda/\/opt\/cuda/' Makefile.config
    
    # use newer CUDA version
    sed -i '/#-gencode arch=compute_50/s/#//g' Makefile.config
    
    # set OpenBLAS as the BLAS provider and adjust its directories
    sed -i '/BLAS[[:space:]]\:=[[:space:]]atlas/s/atlas/open/'                Makefile.config
    sed -i 's/.*BLAS_INCLUDE[[:space:]]\:=.*/BLAS_INCLUDE := \/usr\/include/' Makefile.config
    sed -i 's/.*BLAS_LIB[[:space:]]\:=.*/BLAS_LIB := \/usr\/lib/'             Makefile.config
    
    # python2 settings
    _pyinc_line="$(sed -n '/PYTHON_INCLUDE[[:space:]]\:=[[:space:]]\/usr/=' Makefile.config)"
    sed -i "$((_pyinc_line+1))s/dist/site/" Makefile.config
    
    # python3 settings
    #     if you want to try python3 _instead_ of python2 (currently not working):
    #         - uncomment this block
    #         - comment the python2 block
    #         - change python2 depends and optdepends to python3
    #         - NOTE: do not enable both python2 and python3 blocks. choose only one.
    #_pyinc_line="$(sed -n '/PYTHON_INCLUDE[[:space:]]\:=[[:space:]]\/usr/=' Makefile.config)"
    #sed -i "$((_pyinc_line))s/2\.7/3.6m/"                                 Makefile.config
    #sed -i "$((_pyinc_line+1))s/2\.7/3.6/;$((_pyinc_line+1))s/dist/site/" Makefile.config
}

build() {
    cd "${pkgname}-${pkgver}"
    msg2 "Building target 'all'..."
    make all
    msg2 "Building target 'pycaffe'..."
    make pycaffe
    msg2 "Building target 'docs'..."
    make docs
    msg2 "Building target 'distribute'..."
    make distribute
}

package() {
    # directories creation
    mkdir -p "${pkgdir}/usr/bin"
    mkdir -p "${pkgdir}/usr/include/caffe/"{proto,test,util}
    mkdir -p "${pkgdir}/usr/lib/python2.7/site-packages/caffe/"{imagenet,proto}
    mkdir -p "${pkgdir}/usr/share/"{doc/"${pkgname}"/search,licenses/"${pkgname}"}
    
    cd "${pkgname}-${pkgver}/distribute"
    
    # binaries
    cd bin
    install -D -m755 * "${pkgdir}/usr/bin"
    
    # libraries
    cd ../lib
    install -D -m755 *.so "${pkgdir}/usr/lib"
    
    # includes
    cd ../include/caffe
    install -D -m644 *.hpp "${pkgdir}/usr/include/caffe"
    for _dir in proto test util
    do
        cd "${srcdir}/${pkgname}-${pkgver}/distribute/include/caffe/${_dir}"
        install -D -m644 * "${pkgdir}/usr/include/caffe/${_dir}"
    done
    
    # python
    cd ../../../python
    install -D -m755 *.py "${pkgdir}/usr/bin"
    rm -rf python # remove duplicated 'python' folder
    
    cd caffe
    for _file in *
    do
        [ -d "$_file" ] && continue # skip directories
        _mode="$(stat --format '%a' "$_file")"
        install -D -m"$_mode" "$_file" "${pkgdir}/usr/lib/python2.7/site-packages/caffe"
    done
    
    for _dir in imagenet proto
    do
        cd "${srcdir}/${pkgname}-${pkgver}/distribute/python/caffe/$_dir"
        for _file in *
        do
            _mode="$(stat --format '%a' "$_file")"
            install -D -m"$_mode" "$_file" "${pkgdir}/usr/lib/python2.7/site-packages/caffe/${_dir}"
        done
    done
    
    # docs
    cd ../../../../doxygen/html
    for _file in *
    do
        [ -d "$_file" ] && continue # skip directories
        install -D -m644 "$_file" "${pkgdir}/usr/share/doc/${pkgname}"
    done
    cd search
    install -D -m644 * "${pkgdir}/usr/share/doc/${pkgname}/search"
    
    # license
    cd "${srcdir}/${pkgname}-${pkgver}"
    install -D -m644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}"
}