summaryrefslogtreecommitdiff
path: root/configure
blob: afb94d4795cf8a5f71358e3ce1da01f49c6a133c (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
142
143
144
145
146
147
#!/usr/bin/env bash

set -e
set -o pipefail
shopt -s expand_aliases

CONFIG_FILE=${1:-config.gypi}

function finish {
    >&2 echo -en "\033[0m";
}
trap finish EXIT

# Install node
if [[ ! -d ~/.nvm ]]; then
    git clone --depth 1 https://github.com/creationix/nvm.git ~/.nvm
fi
set +u
. ~/.nvm/nvm.sh
if [ ! `nvm use 0.10 > /dev/null; echo $?` = 0 ]; then
    >&2 echo -en "\033[1m\033[32m* "
    nvm install 0.10
    >&2 echo -en "\033[0m";
else
    >&2 echo -en "\033[1m\033[32m* "
    nvm use 0.10
    >&2 echo -en "\033[0m";
fi

# Install mason
if [[ ! -d ~/.mason ]]; then
    >&2 echo -e "\033[1m\033[32m* Installing Mason\033[0m"
    git clone https://github.com/mapbox/mason.git ~/.mason
fi
alias mason='~/.mason/mason'


case $MASON_PLATFORM in
    'ios')
        SQLITE_VERSION=system
        LIBPNG_VERSION=1.6.13
        LIBUV_VERSION=0.10.28
        ZLIB_VERSION=system
        BOOST_VERSION=system
        ;;
    *)
        GLFW_VERSION=a21f2377
        SQLITE_VERSION=system
        LIBPNG_VERSION=system
        LIBCURL_VERSION=system
        LIBUV_VERSION=0.10.28
        ZLIB_VERSION=system
        BOOST_VERSION=system
        ;;
esac

function abort { >&2 echo -e "\033[1m\033[31m$1\033[0m"; exit 1; }

NODE=`which node || abort 'Cannot find node'`
NPM=`which npm || abort 'Cannot find npm'`
PYTHON=`which python || abort 'Cannot find python'`

>&2 echo -en "\033[1m\033[32m* Using npm "
>&2 ${NPM} --version
>&2 echo -en "\033[0m";

>&2 echo -en "\033[1m\033[32m* Using "
>&2 ${PYTHON} --version
>&2 echo -en "\033[0m";

function quote_flags {
    ${PYTHON} -c "import sys, re; print filter(None, re.split('(?<!-framework)\s+', ' '.join(sys.argv[1:])))" "$@"
}

LN=$'\n'

CONFIG="# Do not edit. Generated by the configure script.
{
  'target_defaults': {
    'cflags': [],
    'default_configuration': 'Release',
    'defines': [],
    'include_dirs': [],
    'libraries': []
  },
  'variables': {
    'node': '${NODE}',
    'npm': '${NPM}',
    'python': '${PYTHON}',
"

if [ ! -z ${BOOST_VERSION} ]; then
    mason install boost ${BOOST_VERSION}
    CONFIG+="    'boost_root': '$(mason prefix boost ${BOOST_VERSION})',"$LN
fi

if [ ! -z ${LIBCURL_VERSION} ]; then
    mason install libcurl ${LIBCURL_VERSION}
    CONFIG+="    'curl_static_libs': $(quote_flags $(mason static_libs libcurl ${LIBCURL_VERSION})),"$LN
    CONFIG+="    'curl_cflags': $(quote_flags $(mason cflags libcurl ${LIBCURL_VERSION})),"$LN
    CONFIG+="    'curl_ldflags': $(quote_flags $(mason ldflags libcurl ${LIBCURL_VERSION})),"$LN
else
    CONFIG+="    'curl_static_libs': [],"$LN
fi

if [ ! -z ${GLFW_VERSION} ]; then
    mason install glfw ${GLFW_VERSION}
    CONFIG+="    'glfw3_static_libs': $(quote_flags $(mason static_libs glfw ${GLFW_VERSION})),"$LN
    CONFIG+="    'glfw3_cflags': $(quote_flags $(mason cflags glfw ${GLFW_VERSION})),"$LN
    CONFIG+="    'glfw3_ldflags': $(quote_flags $(mason ldflags glfw ${GLFW_VERSION})),"$LN
fi

if [ ! -z ${LIBPNG_VERSION} ]; then
    mason install libpng ${LIBPNG_VERSION}
    CONFIG+="    'png_static_libs': $(quote_flags $(mason static_libs libpng ${LIBPNG_VERSION})),"$LN
    CONFIG+="    'png_cflags': $(quote_flags $(mason cflags libpng ${LIBPNG_VERSION})),"$LN
    CONFIG+="    'png_ldflags': $(quote_flags $(mason ldflags libpng ${LIBPNG_VERSION})),"$LN
fi

if [ ! -z ${SQLITE_VERSION} ]; then
    mason install sqlite ${SQLITE_VERSION}
    CONFIG+="    'sqlite3_static_libs': $(quote_flags $(mason static_libs sqlite ${SQLITE_VERSION})),"$LN
    CONFIG+="    'sqlite3_cflags': $(quote_flags $(mason cflags sqlite ${SQLITE_VERSION})),"$LN
    CONFIG+="    'sqlite3_ldflags': $(quote_flags $(mason ldflags sqlite ${SQLITE_VERSION})),"$LN
fi

if [ ! -z ${LIBUV_VERSION} ]; then
    mason install libuv ${LIBUV_VERSION}
    CONFIG+="    'uv_static_libs': $(quote_flags $(mason static_libs libuv ${LIBUV_VERSION})),"$LN
    CONFIG+="    'uv_cflags': $(quote_flags $(mason cflags libuv ${LIBUV_VERSION})),"$LN
    CONFIG+="    'uv_ldflags': $(quote_flags $(mason ldflags libuv ${LIBUV_VERSION})),"$LN
fi

if [ ! -z ${ZLIB_VERSION} ]; then
    mason install zlib ${ZLIB_VERSION}
    CONFIG+="    'zlib_static_libs': $(quote_flags $(mason static_libs zlib ${ZLIB_VERSION})),"$LN
    CONFIG+="    'zlib_cflags': $(quote_flags $(mason cflags zlib ${ZLIB_VERSION})),"$LN
    CONFIG+="    'zlib_ldflags': $(quote_flags $(mason ldflags zlib ${ZLIB_VERSION})),"$LN
fi

CONFIG+="  }
}
"

echo "${CONFIG}" > ${CONFIG_FILE}

cat ${CONFIG_FILE}