-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_day.sh
111 lines (84 loc) · 2.11 KB
/
build_day.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
#!/bin/sh
is_sourced() {
if [ -n "$ZSH_VERSION" ]; then
case $ZSH_EVAL_CONTEXT in *:file:*) return 0;; esac
else # Add additional POSIX-compatible shell names here, if needed.
case ${0##*/} in dash|-dash|bash|-bash|ksh|-ksh|sh|-sh) return 0;; esac
fi
return 1 # NOT sourced.
}
if ! `is_sourced`; then
echo "use as '. $0 [hs]'"
echo exit 1
fi
LANGUAGE=$1
YEAR=`date '+%Y'`
DAY=`date '+%d'`
FOLDER=./$YEAR/Day$DAY/
mkdir -p $FOLDER
touch $FOLDER/shortinput.txt
case $LANGUAGE in
"hs")
cat <<EOF > $FOLDER/Day$DAY.$LANGUAGE
module Main where
import Data.Bits
import Data.List
import Data.List.Split
import Data.List.Unique
import Data.Matrix (Matrix, (!))
import Data.Matrix qualified as Mat
import Data.Set (Set)
import Data.Set qualified as S
import Data.Tuple.Extra
import Debug.Trace
import System.Environment
import Text.Regex.TDFA ((=~))
-- TODO: Cleanup imports after day done
type Input = [String]
type Output = Int
parseInput :: String -> Input
parseInput = lines
part1 :: Input -> Output
part1 input = -1
part2 :: Input -> Output
part2 input = -1
main :: IO ()
main = do
args <- getArgs
content <- readFile (last args)
let input = parseInput content
print input
print $ part1 input
print $ part2 input
EOF
cat <<EOF > $FOLDER/Makefile
CONTAINER_NAME=haskell-aoc
SRC=./Day$DAY.hs
TARGET=Day$DAY
all: \$(TARGET)
\$(TARGET): \$(SRC)
ghc -O3 \$(SRC)
profile: \$(SRC)
clean:
\$(RM) ./Day$DAY ./Day$DAY.o ./Day$DAY.hi
setup: \$(SRC)
docker cp \$(SRC) \$(CONTAINER_NAME):/home/haskell/Main.hs
docker cp input.txt \$(CONTAINER_NAME):/home/haskell/input.txt
docker cp shortinput.txt \$(CONTAINER_NAME):/home/haskell/shortinput.txt
profiling: setup
docker exec -it \$(CONTAINER_NAME) cabal build --enable-profiling
docker exec -it \$(CONTAINER_NAME) ./profile input.txt
run: setup
docker exec -it \$(CONTAINER_NAME) cabal build
docker exec -it \$(CONTAINER_NAME) ./run input.txt
.PHONY: all \$(TARGET) clean setup profiling run
EOF
;;
"")
echo "No language specified"
;;
*)
echo "Unknown language specified"
;;
esac
cd $FOLDER