forked from AlloSphere-Research-Group/AlloSystem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·73 lines (59 loc) · 1.97 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
#!/bin/sh
# Pass -d to enter debugger mode.
if [ "$(uname -s)" = "Darwin" ]; then
DEBUGGER=lldb
else
DEBUGGER=gdb
fi
# ------------------------------------------------
# You shouldn't need to touch the stuff below.
# Runs the program through the specified debugger if -d is passed.
OPTIND=1
while getopts "d" opt; do
case "$opt" in
d) debugger="$DEBUGGER"
shift
;;
esac
done
# Get the number of processors on OS X; Linux; or MSYS2, or take a best guess.
NPROC=$(grep --count ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu || nproc || echo 2)
# Save one core for the gui.
PROC_FLAG=$((NPROC - 1))
if [ "$#" -eq 0 ]; then
echo Aborting: You must provide a source filename or a directory.
exit 1
fi
# Remove file extension.
FILENAME=$(basename "$1" | sed 's/\.[^.]*$//')
DIRNAME=$(dirname "$1")
# Replace all forward slashes with underscores.
TARGET=$(echo "${DIRNAME}_${FILENAME}_run" | sed 's/\//_/g')
if [ "$DIRNAME" != "." ]; then
# Replace all periods with underscores.
TARGET=$(echo "${TARGET}" | sed 's/\./_/g')
fi
# Change behavior if the target is a file or directory.
if [ -f "$1" ]; then
TARGET_FLAG="-DALLOSYSTEM_BUILD_APP_FILE=$1"
DBUILD_FLAG="-DALLOSYSTEM_BUILD_DIR=0"
echo RUN SCRIPT: Building file "$1".
elif [ -d "$1" ]; then
TARGET_FLAG="-DALLOSYSTEM_BUILD_APP_DIR=$1"
DBUILD_FLAG="-DALLOSYSTEM_BUILD_DIR=1"
echo RUN SCRIPT: Building all files in dir "$1".
else
echo Aborting: "$1" is neither a file nor directory.
exit 1
fi
# Don't pass target as Make flag.
shift
if [ "$MSYSTEM" = "MINGW64" -o "$MSYSTEM" = "MINGW32" ]; then
GENERATOR_FLAG="-GMSYS Makefiles"
fi
if [ -n "$debugger" ]; then
cmake "$GENERATOR_FLAG" "$TARGET_FLAG" "$DBUILD_FLAG" -DRUN_IN_DEBUGGER=1 "-DALLOSYSTEM_DEBUGGER=${debugger}" -DCMAKE_BUILD_TYPE=Debug . > cmake_log.txt
else
cmake "$GENERATOR_FLAG" "$TARGET_FLAG" "$DBUILD_FLAG" -DRUN_IN_DEBUGGER=0 -DCMAKE_BUILD_TYPE=Release -Wno-dev . > cmake_log.txt
fi
make $TARGET -j$PROC_FLAG $*