forked from epicatization/heroku-buildpack-imagemagick-heif
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathcompile
80 lines (63 loc) · 2.05 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
#!/usr/bin/env bash
# bin/compile <build-dir> <cache-dir>
set -e
BUILD_DIR=$1
CACHE_DIR=$2
BUILDPACK_NAME=imagemagick
BINARY_NAME=imagemagick-${STACK}.tar.gz
BIN_DIR=$(cd "$(dirname "$0")"; pwd) # absolute path
ROOT_DIR=$(dirname "$BIN_DIR")
function indent() {
c='s/^/ /'
case $(uname) in
Darwin) sed -l "$c";;
*) sed -u "$c";;
esac
}
arrow() {
sed -u 's/^/-----> /'
}
function vendor() {
binary="$1"
path="$2"
if [ ! -f "$binary" ]; then
echo "Binary file '${binary}' not found for stack ${STACK}" | indent
exit 1
fi
echo "Fetching $binary" | indent
mkdir -p $path
tar -xz -f $binary -C $path
if [ -d "$path/bin" ]; then
export PATH=$path/bin:$PATH
fi
if [ -d "$path/lib/pkgconfig" ]; then
# pkg-config should handle compiler options (if used)
export PKG_CONFIG_PATH="$path/lib/pkgconfig:$PKG_CONFIG_PATH"
fi
# standard paths
export CPPPATH="$path/include:$CPPPATH"
export CPATH="$path/include:$CPATH"
export LIBRARY_PATH="$path/lib:$LIBRARY_PATH"
export LD_LIBRARY_PATH="$path/lib:$LD_LIBRARY_PATH"
}
echo "Vendoring binaries" | arrow
vendor "${ROOT_DIR}/build/${BINARY_NAME}" "$BUILD_DIR/vendor/imagemagick"
echo "Configuring build environment" | arrow
cat <<EOF > export
export PATH="/app/bin:/app/vendor/imagemagick/bin:$PATH:\$PATH"
export LD_LIBRARY_PATH="\$LD_LIBRARY_PATH:$LD_LIBRARY_PATH"
export LIBRARY_PATH="\$LIBRARY_PATH:$LIBRARY_PATH"
export PKG_CONFIG_PATH="\$PKG_CONFIG_PATH:$PKG_CONFIG_PATH"
export CPPPATH="\$CPPPATH:$CPPPATH"
export CPATH="\$CPATH:$CPATH"
EOF
echo "Building runtime environment" | arrow
mkdir -p $BUILD_DIR/.profile.d
cat <<EOF > $BUILD_DIR/.profile.d/$BUILDPACK_NAME.sh
export PATH="/app/bin:/app/vendor/imagemagick/bin:\$PATH"
export LD_LIBRARY_PATH="\$LD_LIBRARY_PATH:${LD_LIBRARY_PATH//$BUILD_DIR//app}"
export LIBRARY_PATH="\$LIBRARY_PATH:${LIBRARY_PATH//$BUILD_DIR//app}"
export PKG_CONFIG_PATH="\$PKG_CONFIG_PATH:${PKG_CONFIG_PATH//$BUILD_DIR//app}"
export CPPPATH="\$CPPPATH:${CPPPATH//$BUILD_DIR//app}"
export CPATH="\$CPATH:${CPATH//$BUILD_DIR//app}"
EOF