-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.sh
executable file
·65 lines (54 loc) · 1.35 KB
/
driver.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
#!/bin/sh
set -eu
# Find the source directory
cwd="$(pwd)"
cd "$(dirname "$0")"
srcdir="$(pwd)"
cd "${cwd}"
# Parse command line options
if [ $# -ne 4 ]; then
echo "Usage: $0 <year> <day> <puzzle> <input-file>" >&2
exit 1
fi
# Parse and validate command line options"
year="$1"
day="$2"
num="$3"
input="$4"
if [ ! -d "${srcdir}/${year}" ]; then
echo "Year of puzzles ${year} does not exist" >&2
exit 2
fi
if [ ${#day} -eq 1 ]; then
day="0${day}"
fi
if [ ${#num} -eq 1 ]; then
num="0${num}"
fi
puzzle_src="${srcdir}/${year}/puzzle-${day}-${num}.cc"
puzzle="puzzle-${year}-${day}-${num}"
exe="build/puzzle-${year}-${day}-${num}"
if [ ! -e "${puzzle_src}" ]; then
echo "Unable to find puzzle sources for ${year}-12-${day} number ${num}" >&2
exit 2
fi
# Rebuild the executable we want to run.
if [ ! -d "build" ]; then
opts=
if [ "$(uname -s)" = "Darwin" ]; then
if [ "$(uname -m)" = "arm64" ]; then
opts="-DOPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl"
else
opts="-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl"
fi
fi
cmake -Bbuild -S "${srcdir}" ${opts}
fi
cmake --build build --target "${puzzle}"
# And run the executable - using the driver if necessary.
driver="${srcdir}/${year}/driver-${day}-${num}.sh"
if [ -e "${driver}" ]; then
sh "${driver}" "${exe}" "${input}"
else
"${exe}" <"${input}"
fi