-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrun.sh
executable file
·207 lines (190 loc) · 5.98 KB
/
run.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
cd `dirname $0`
# Good practice -- exit completely on any bad exit code:
set -e
###############################################################################
# Helper functions for conditionally coloring text.
###############################################################################
function is_mac() {
if [ "$(uname)" == "Darwin" ]; then
return 0 # True!
else
return 1 # False!
fi
}
# Bash function to apply a color to a piece of text.
function colorify() {
if is_mac ; then
cat
else
local words;
words=$(cat)
echo -e "\e[$1m$words\e[0m"
fi
}
###############################################################################
# Bash function to check for a flag in 'args' and remove it.
# Treats 'args' as one long string.
# Returns true if flag was removed.
###############################################################################
args="$@" # Create a mutable copy of the program arguments
function handle_flag(){
flag=$1
local new_args
local got
got=1 # False!
for arg in $args ; do
if [ $arg = $flag ] ; then
args="${args/$flag/}"
got=0 # True!
else
new_args="$new_args $arg"
fi
done
args="$new_args"
return $got # False!
}
##############################################################################
# Eclipse options
# --eclipse/-e: Create eclipse project files
###############################################################################
# Create eclipse-project-files
if handle_flag "--eclipse" || handle_flag "-e" ; then
src=$(pwd)
rm -f CMakeCache.txt
mkdir ../LanartsEclipse -p
cd ../LanartsEclipse
# Eclipse project creation
cmake -Wno-dev -G"Eclipse CDT4 - Unix Makefiles" $src
exit
fi
###############################################################################
# Compiling and setting up runtime directory structure
###############################################################################
# Handle environment-variable setting convenience flags
# These are used to communicate with CMake
# Each flag has an optional shortform, use whichever is preferred.
if handle_flag "--mingw" ; then
export BUILD_MINGW=1
fi
if handle_flag "--headless" ; then
export BUILD_HEADLESS=1
fi
if handle_flag "--small" || handle_flag "-s" ; then
export LANARTS_SMALL=1
fi
if handle_flag "--luajit" || handle_flag "-lj" ; then
export BUILD_LUAJIT=1
fi
if handle_flag "--optimize" || handle_flag "-O" ; then
export BUILD_OPTIMIZE=1
fi
if handle_flag "--sanitize" ; then
export BUILD_SANITIZE=1
fi
if handle_flag "--emscripten" ; then
export BUILD_EMSCRIPTEN=1
fi
if handle_flag "--profile-gen" || handle_flag "--pgen" ; then
export BUILD_OPTIMIZE=1
export BUILD_PROF_GEN=1
fi
# Use --pgen, and then this flag, for optimal performance
if handle_flag "--profile-use" || handle_flag "--puse" ; then
export BUILD_OPTIMIZE=1
export BUILD_PROF_USE=1
fi
# Pick whether to use debug std data-structures for eg std::vector
if handle_flag "--debug-std" ; then
export BUILD_FLAGS="$BUILD_FLAGS -D_GLIBCXX_DEBUG"
fi
# Configure amount of cores used
if [[ -e /proc/cpuinfo ]] ; then
cores=$(grep -c ^processor /proc/cpuinfo)
else
cores=4 # Guess -- may want to manually edit if above fails.
fi
# Helper for managing build directories:
function rm_if_link(){ [ ! -L "$1" ] || rm -f "$1"; }
function build_lanarts(){
BUILD_DIR="build_debug"
if [ $BUILD_OPTIMIZE ] ; then
BUILD_DIR="build_release"
fi
# Specialize build dirs
if [ $BUILD_HEADLESS ] ; then
BUILD_DIR="${BUILD_DIR}_headless"
fi
if [ $BUILD_LUAJIT ] ; then
BUILD_DIR="${BUILD_DIR}_luajit"
fi
if [ $BUILD_SANITIZE ] ; then
BUILD_DIR="${BUILD_DIR}_asan"
fi
if [ $BUILD_PROF_GEN ] ; then
BUILD_DIR="${BUILD_DIR}_profgen"
fi
if [ $BUILD_EMSCRIPTEN ] ; then
BUILD_DIR="${BUILD_DIR}_emscripten"
fi
if [ $BUILD_PROF_USE ] ; then
BUILD_DIR="${BUILD_DIR}_profuse"
fi
if [ $BUILD_MINGW ] ; then
BUILD_DIR="${BUILD_DIR}_mingw"
fi
rm_if_link build
if [ -d build ] ; then
echo "You have a non-symlink build directory. Lanarts has moved to symlinking 'build' to 'build_release' or 'build_debug'. Please rename the build directory to the appropriate one of those." >&2
exit 1
fi
mkdir -p $BUILD_DIR
ln -s $BUILD_DIR build
cd $BUILD_DIR
if [ $BUILD_EMSCRIPTEN ] ; then
emcmake cmake ..
elif [ $BUILD_MINGW ] ; then
if python -mplatform | grep fedora ; then
export BUILD_FEDORA_CROSS=1
mingw32-cmake -Wno-dev .. | colorify '1;33'
else
cmake -DCMAKE_TOOLCHAIN_FILE=mingw-toolchain.cmake -Wno-dev .. | colorify '1;33'
fi
else
cmake -Wno-dev .. | colorify '1;33'
fi
if handle_flag "--clean" ; then
make clean
fi
make -j$((cores+1)) lanarts
cd ../runtime && python2 compile_images.py > compiled/Resources.lua
cd ..
}
# --force/-f: Do not build (use last successful compiled binary)
if ! handle_flag "-f" && ! handle_flag "--force" ; then
if handle_flag "--verbose" || handle_flag "-v" ; then
build_lanarts
else
build_lanarts > /dev/null
fi
fi
# --build/-b: Do not run (build only)
if handle_flag "-b" || handle_flag "--build" ; then
exit
fi
###############################################################################
# Running the game.
###############################################################################
function run_lanarts(){
cd runtime
export vblank_mode=0
if handle_flag "--gdb" || handle_flag "-g" ; then
echo "Wrapping in GDB:" | colorify '1;35'
gdb -silent -x ../debug.gdb --args ../build/src/lanarts $args
else
exec ../build/src/lanarts $args
fi
cd ..
}
# TODO add gdb macro with this line:
#print luaL_loadstring(L, "return debug.traceback()") || lua_pcall(L, 0, 1, 0) || printf(lua_tolstring(L, -1, 0))
run_lanarts