-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile
executable file
·156 lines (122 loc) · 4.09 KB
/
compile
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env bash
# bin/compile <build-dir> <cache-dir>
# fail fast
set -e
# debug
# set -x
shopt -s extglob
function error() {
echo " ! $*" >&2
exit 1
}
function indent() {
c='s/^/ /'
case $(uname) in
Darwin) sed -l "$c";;
*) sed -u "$c";;
esac
}
function build() {
echo ----------------------------------------------------------------------
echo Building $@...
echo ----------------------------------------------------------------------
echo
pushd $1
./configure --prefix=$VENDOR_DIR/$2 ${@:3} > /dev/null 2>&1
echo "configure finished"
make
echo "make finished"
make install > /dev/null 2>&1
echo "install finished"
make clean > /dev/null 2>&1
echo "clean finished"
popd > /dev/null
echo
echo
# add to libraries and pkg-config
export LD_LIBRARY_PATH="$VENDOR_DIR/$2/lib:$LD_LIBRARY_PATH"
export PKG_CONFIG_PATH="$VENDOR_DIR/$2/lib/pkgconfig:$PKG_CONFIG_PATH"
}
function download() {
if [ ! -f "$2" ]; then
echo Downloading $2...
curl $1 -o $2 -s -S
else
echo Got $2...
fi
}
# clean up leaking environment
unset GIT_DIR
# parse and derive params
BUILD_DIR=$1
CACHE_DIR="$2/vendor"
LP_DIR=`cd $(dirname $0); cd ..; pwd`
BUILDPACK_DIR="$(dirname $(dirname $0))"
# config
BUILD_PACK_VERSION="20130729"
GCC_VERSION="4.3"
GLIBC_VERSION="2.7"
#R_VERSION="2.15.1"
R_VERSION="3.1.0"
S3_BUCKET="heroku-buildpack-r"
#R_BINARIES="http://${S3_BUCKET}.s3.amazonaws.com/R-${R_VERSION}-binaries-${BUILD_PACK_VERSION}.tar.gz"
R_BINARIES="https://s3.amazonaws.com/r-buildpack/R-3.1.0-binaries-20140629-2201.tar.gz"
VENDOR_DIR="$BUILD_DIR/vendor"
R_HOME="$VENDOR_DIR/R"
CRAN_MIRROR="http://cran.revolutionanalytics.com"
mkdir -p $CACHE_DIR
# vendor R into the slug
echo "Vendoring R $R_VERSION" | indent
# download and unpack binaries
echo "Downloading and unpacking R binaries" | indent
mkdir -p $VENDOR_DIR && mkdir -p /app/vendor
curl $R_BINARIES -s -o r_binaries.tar.gz
tar xzf r_binaries.tar.gz -C $VENDOR_DIR
rm r_binaries.tar.gz
echo "Directory created, R pulled, unpacked" | indent
# need to copy the binaries to /app/vendor so that R works
cp -R $VENDOR_DIR/gcc-$GCC_VERSION /app/vendor/gcc-$GCC_VERSION
cp -R $VENDOR_DIR/glibc-$GLIBC_VERSION /app/vendor/glibc-$GLIBC_VERSION
#cp -R $VENDOR_DIR/readline /app/vendor/readline
cp -R $VENDOR_DIR/R /app/vendor/R
echo "Stuff copied" | indent
# R needs to know where gfortran and glibc header files are
export PATH=/app/vendor/R/bin:/app/vendor/gcc-$GCC_VERSION/bin:$PATH
export LDFLAGS="-L/app/vendor/gcc-$GCC_VERSION/lib64/"
export CPPFLAGS="-I/app/vendor/glibc-$GLIBC_VERSION/string/ -I/app/vendor/glibc-$GLIBC_VERSION/time"
export R_HOME=/app/vendor/R
export R_INCLUDE=$R_HOME/lib64/R/include
export LD_LIBRARY_PATH="/lib:/usr/lib:$R_HOME/lib64:$LD_LIBRARY_PATH"
ln -s /usr/lib/libreadline.so $R_HOME/lib64/libreadline.so.5 2>&1
echo "variables set" | indent
# copy over environment
mkdir -p $BUILD_DIR/.profile.d
cp "$BUILDPACK_DIR/bin/r_environment.sh" $BUILD_DIR/.profile.d/r_environment.sh
echo "environment copied" | indent
# prevent warnings
mkdir -p /app/vendor/R/lib64/R/doc/html
touch /app/vendor/R/lib64/R/doc/html/R.css
# install dependencies from CRAN
echo "Executing init.r script" | indent
# set the CRAN mirror and run the init.r program
R -s <<RPROG
Sys.setenv(BUILD_DIR="$BUILD_DIR")
setwd("$BUILD_DIR")
r <- getOption("repos");
print(r)
r["CRAN"] <- "$CRAN_MIRROR";
options(repos=r);
`cat $BUILD_DIR/init.r`
RPROG
#cat indent
echo "R $R_VERSION successfully installed" | indent
# need to copy binaries back so that any installed packages are included in the slug
rm -rf $VENDOR_DIR && mkdir -p $VENDOR_DIR
cp -R /app/vendor/gcc-$GCC_VERSION $VENDOR_DIR/gcc-$GCC_VERSION
cp -R /app/vendor/glibc-$GLIBC_VERSION $VENDOR_DIR/glibc-$GLIBC_VERSION
cp -R /app/vendor/R $VENDOR_DIR/R
# HACK
cp $VENDOR_DIR/gcc-$GCC_VERSION/lib64/* $VENDOR_DIR/R/lib64/R/lib
# remove unneeded files to make slug smaller
pushd $VENDOR_DIR/gcc-$GCC_VERSION > /dev/null && rm -rf !(lib64) && popd > /dev/null
pushd $VENDOR_DIR/glibc-$GLIBC_VERSION > /dev/null && rm -rf !(string|time) && popd > /dev/null