summaryrefslogtreecommitdiff
path: root/configure
blob: 39e07e0956aab9fc317333acdd9c9f2339ad0221 (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
#!/usr/bin/env bash

set -euo pipefail

CONFIG_FILE=$1

if [ -z ${CONFIG_FILE} ]; then
    abort 'You need to specify an output path for the configuration file'
fi

# Make sure we clear all colors
trap '>&2 echo -en "\033[0m"' TERM INT

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

if [ -e "`pwd`/.git" ]; then
    info "This build is within a git repository"
    export MASON_DIR="`pwd`/.mason"
    export PATH="${MASON_DIR}:${PATH}"
else
    info "This build is NOT within a git repository"
    which mason || abort "You must install mason to build mapbox-gl-native (https://github.com/mapbox/mason)"
    export MASON_DIR="$(dirname $(readlink $(which mason)))"
fi

# You can override the function for a particular set of flags by defining a
# print_XXX_flags function in your dependencies.sh file
function print_flags {
    local NAME=$1; shift
    if [ "$(type -t print_${NAME}_flags)" = 'function' ]; then
        print_${NAME}_flags
    else
        local VERSION=`echo "${NAME}_VERSION" | tr "[:lower:]-." "[:upper:]__"`
        if [ ! -z ${!VERSION:-} ] ; then
            mason install ${NAME} ${!VERSION}
            for FLAGS in "$@" ; do
                CONFIG+="    '${NAME}_${FLAGS}%': $(quote_flags $(mason ${FLAGS} ${NAME} ${!VERSION})),"$LN
            done
        else
            warn "* Not using ${NAME}"
        fi
    fi
}

function print_default_flags {
    :
}

function print_opengl_flags {
    CONFIG+="    'opengl_cflags%': [],"$LN
    CONFIG+="    'opengl_ldflags%': [],"$LN
}

# Load dependencies
source platform/${MASON_PLATFORM}/scripts/configure.sh
if [ -e platform/${MASON_PLATFORM}/scripts/${MASON_PLATFORM_VERSION}/configure.sh ]; then
    source platform/${MASON_PLATFORM}/scripts/${MASON_PLATFORM_VERSION}/configure.sh
fi

PYTHON=`which python || abort 'Cannot find python'`

>&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': [],
"

print_default_flags

CONFIG+="  },"$LN
CONFIG+="  'variables': {"$LN

print_opengl_flags

print_flags boost cflags
print_flags boost_libprogram_options static_libs
print_flags openssl static_libs cflags ldflags
print_flags libcurl static_libs cflags ldflags
print_flags glfw static_libs cflags ldflags
print_flags libpng static_libs cflags ldflags
print_flags libjpeg-turbo static_libs cflags ldflags
print_flags sqlite static_libs cflags ldflags
print_flags libuv static_libs cflags ldflags
print_flags zlib static_libs cflags ldflags
print_flags nunicode static_libs cflags ldflags
print_flags libzip static_libs cflags ldflags
print_flags geojsonvt static_libs cflags ldflags
print_flags variant static_libs cflags ldflags
print_flags rapidjson static_libs cflags ldflags
print_flags gtest static_libs cflags ldflags
print_flags pixelmatch static_libs cflags ldflags
print_flags webp static_libs cflags ldflags
print_flags jni.hpp static_libs cflags ldflags

CONFIG+="  }
}
"

mkdir -p $(dirname "${CONFIG_FILE}")
echo "${CONFIG}" > ${CONFIG_FILE}
cat ${CONFIG_FILE}