forked from elastic/ml-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_env.sh
executable file
·208 lines (169 loc) · 5.33 KB
/
set_env.sh
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/bash
#
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. Licensed under the Elastic License;
# you may not use this file except in compliance with the Elastic License.
#
# Set up a build environment, to ensure repeatable builds
umask 0002
# Modify some limits (soft limits only, hence -S)
ulimit -S -c unlimited
ulimit -S -n 1024
# Set $CPP_SRC_HOME to be an absolute path to this script's location, as
# different builds will come from different repositories and go to different
# staging areas
MY_DIR=`dirname "$BASH_SOURCE"`
export CPP_SRC_HOME=`cd "$MY_DIR" && pwd`
# Platform
case `uname` in
Darwin)
SIMPLE_PLATFORM=macosx
BUNDLE_PLATFORM=darwin-x86_64
;;
Linux)
if ldd --version 2>&1 | grep musl > /dev/null ; then
SIMPLE_PLATFORM=linux-musl
BUNDLE_PLATFORM=linux-musl-x86_64
else
SIMPLE_PLATFORM=linux
if [ -z "$CPP_CROSS_COMPILE" ] ; then
BUNDLE_PLATFORM=linux-x86_64
else
if [ "$CPP_CROSS_COMPILE" = macosx ] ; then
BUNDLE_PLATFORM=darwin-x86_64
else
echo "Cannot cross compile to $CPP_CROSS_COMPILE"
exit 1
fi
fi
fi
;;
MINGW*)
SIMPLE_PLATFORM=windows
BUNDLE_PLATFORM=windows-x86_64
;;
*)
echo `uname 2>&1` "- unsupported operating system"
exit 2
;;
esac
CPP_DISTRIBUTION_HOME="$CPP_SRC_HOME/build/distribution"
export CPP_PLATFORM_HOME="$CPP_DISTRIBUTION_HOME/platform/$BUNDLE_PLATFORM"
# Logical filesystem root
unset ROOT
if [ "$SIMPLE_PLATFORM" = "windows" ] ; then
if [ -z "$LOCAL_DRIVE" ] ; then
ROOT=/c
else
ROOT=/$LOCAL_DRIVE
fi
export ROOT
fi
# Compiler
unset COMPILER_PATH
if [ "$SIMPLE_PLATFORM" = "windows" ] ; then
# We have to use 8.3 names for directories with spaces in the names, as some
# tools won't quote paths with spaces correctly
PFX86_DIR=`cd $ROOT && cygpath -m -s "Program Files (x86)"`
MSVC_DIR=`cd $ROOT/$PFX86_DIR && cygpath -m -s "Microsoft Visual Studio"`
WIN_KITS_DIR=`cd $ROOT/$PFX86_DIR && cygpath -m -s "Windows Kits"`
VCVER=`/bin/ls -1 $ROOT/$PFX86_DIR/$MSVC_DIR/2017/Professional/VC/Tools/MSVC | tail -1`
# NB: Some SDK tools are 32 bit only, hence the 64 bit SDK bin directory
# is followed by the 32 bit SDK bin directory
COMPILER_PATH=$ROOT/$PFX86_DIR/$MSVC_DIR/2017/Professional/VC/Tools/MSVC/$VCVER/bin/HostX64/x64:$ROOT/$PFX86_DIR/$MSVC_DIR/2017/Professional/Common7/IDE:$ROOT/$PFX86_DIR/$WIN_KITS_DIR/8.0/bin/x64:$ROOT/$PFX86_DIR/$WIN_KITS_DIR/8.0/bin/x86
fi
# Git
unset GIT_HOME
if [ -d "$ROOT/usr/local/git" ] ; then
GIT_HOME=$ROOT/usr/local/git
fi
# Paths
case $SIMPLE_PLATFORM in
linux)
PATH=/usr/local/gcc73/bin:/usr/bin:/bin:/usr/local/gcc73/sbin:/usr/sbin:/sbin
;;
linux-musl)
PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
;;
macosx)
PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
;;
windows)
PATH=/mingw64/bin:/usr/bin:/bin:$ROOT/Windows/System32:$ROOT/Windows
PATH=$ROOT/usr/local/bin:$ROOT/usr/local/sbin:$PATH
;;
esac
if [ ! -z "$GIT_HOME" ] ; then
PATH=$GIT_HOME/bin:$PATH
fi
if [ ! -z "$COMPILER_PATH" ] ; then
PATH=$COMPILER_PATH:$PATH
fi
# Library paths
case $SIMPLE_PLATFORM in
linux)
export LD_LIBRARY_PATH=/usr/local/gcc73/lib64:/usr/local/gcc73/lib:/usr/lib:/lib
;;
linux-musl)
export LD_LIBRARY_PATH=/usr/local/lib64:/usr/local/lib:/usr/lib:/lib
;;
windows)
# On Windows there's no separate library path - $PATH is used
PATH=$CPP_PLATFORM_HOME/bin:$PATH:$ROOT/usr/local/lib
;;
esac
# do not cache in Jenkins
if [ -z "$JOB_NAME" ] ; then
# check if CCACHE is available and use it if it's found
if [ -d "/usr/lib/ccache" ] ; then
PATH=/usr/lib/ccache/:$PATH
# on Mac it should be /usr/local/lib when installed with brew
elif [ -d "/usr/local/lib/ccache" ] ; then
PATH=/usr/local/lib/ccache/:$PATH
fi
fi
export PATH
# GNU make
case $SIMPLE_PLATFORM in
linux*)
MAKE=`which make`
;;
macosx|windows)
MAKE=`which gnumake`
;;
esac
export MAKE
# Localisation - don't use any locale specific functionality
export LC_ALL=C
# Unset environment variables that affect the choice of compiler/linker, or
# where the compiler/linker look for dependencies - we only want what's in our
# Makefiles
unset CPP
unset CC
unset CXX
unset LD
unset CPPFLAGS
unset CFLAGS
unset CXXFLAGS
unset LDFLAGS
if [ "$SIMPLE_PLATFORM" = "windows" ] ; then
unset INCLUDE
unset LIBPATH
else
unset CPATH
unset C_INCLUDE_PATH
unset CPLUS_INCLUDE_PATH
unset LIBRARY_PATH
fi
# Tell the build to keep going under Jenkins so that we get as many errors as
# possible from an automated build (Jenkins sets $JOB_NAME)
if [ -n "$JOB_NAME" ] ; then
export ML_KEEP_GOING=1
fi
# Finally, switch off debug if we are not in Jenkins doing the debug build
if [[ ! "$JOB_NAME" == *Debug* ]] ; then
unset ML_DEBUG
echo "Building $JOB_NAME with ML_DEBUG unset"
else
echo "Building $JOB_NAME with ML_DEBUG=$ML_DEBUG"
fi