10555
|
1 |
#!/usr/bin/env bash
|
8159
|
2 |
#
|
|
3 |
# $Id$
|
9788
|
4 |
# Author: Markus Wenzel, TU Muenchen
|
|
5 |
# License: GPL (GNU GENERAL PUBLIC LICENSE)
|
8159
|
6 |
#
|
|
7 |
# DESCRIPTION: prepare logic session directory
|
|
8 |
|
|
9 |
|
|
10 |
## diagnostics
|
|
11 |
|
10511
|
12 |
PRG="$(basename "$0")"
|
8159
|
13 |
|
|
14 |
function usage()
|
|
15 |
{
|
|
16 |
echo
|
9237
|
17 |
echo "Usage: $PRG [OPTIONS] [LOGIC] NAME"
|
8159
|
18 |
echo
|
|
19 |
echo " Options are:"
|
8198
|
20 |
echo " -I FILE alternative IsaMakefile output"
|
8211
|
21 |
echo " -P include parent logic target"
|
8159
|
22 |
echo " -b setup build mode (session outputs heap image)"
|
|
23 |
echo " -d setup document"
|
|
24 |
echo
|
8194
|
25 |
echo " Prepare session directory, including IsaMakefile, document etc."
|
8199
|
26 |
echo " with parent LOGIC (default ISABELLE_LOGIC=$ISABELLE_LOGIC)"
|
8159
|
27 |
echo
|
|
28 |
exit 1
|
|
29 |
}
|
|
30 |
|
|
31 |
function fail()
|
|
32 |
{
|
|
33 |
echo "$1" >&2
|
|
34 |
exit 2
|
|
35 |
}
|
|
36 |
|
|
37 |
|
|
38 |
## process command line
|
|
39 |
|
|
40 |
# options
|
|
41 |
|
8198
|
42 |
ISAMAKEFILE="IsaMakefile"
|
8211
|
43 |
PARENT=""
|
8159
|
44 |
BUILD=""
|
|
45 |
DOCUMENT=""
|
|
46 |
|
8211
|
47 |
while getopts "I:Pbd" OPT
|
8159
|
48 |
do
|
|
49 |
case "$OPT" in
|
8198
|
50 |
I)
|
|
51 |
ISAMAKEFILE="$OPTARG"
|
|
52 |
;;
|
8211
|
53 |
P)
|
|
54 |
PARENT=true
|
|
55 |
;;
|
8159
|
56 |
b)
|
|
57 |
BUILD=true
|
|
58 |
;;
|
|
59 |
d)
|
|
60 |
DOCUMENT=true
|
|
61 |
;;
|
|
62 |
\?)
|
|
63 |
usage
|
|
64 |
;;
|
|
65 |
esac
|
|
66 |
done
|
|
67 |
|
|
68 |
shift $(($OPTIND - 1))
|
|
69 |
|
|
70 |
|
|
71 |
# args
|
|
72 |
|
|
73 |
|
9788
|
74 |
if [ "$#" -eq 1 ]; then
|
8194
|
75 |
LOGIC="$ISABELLE_LOGIC"
|
8685
|
76 |
DIR_NAME="$1"; shift
|
9788
|
77 |
elif [ "$#" -eq 2 ]; then
|
8194
|
78 |
LOGIC="$1"; shift
|
8685
|
79 |
DIR_NAME="$1"; shift
|
8194
|
80 |
else
|
|
81 |
usage
|
|
82 |
fi
|
8159
|
83 |
|
8685
|
84 |
DIR=$(dirname "$DIR_NAME")
|
|
85 |
NAME=$(basename "$DIR_NAME")
|
8159
|
86 |
|
|
87 |
|
|
88 |
## main
|
|
89 |
|
|
90 |
# IsaMakefile
|
|
91 |
|
8685
|
92 |
mkdir -p "$DIR" || fail "Bad directory: $DIR"
|
|
93 |
cd "$DIR"
|
|
94 |
|
|
95 |
|
8244
|
96 |
DOCUMENT_ROOT=""
|
|
97 |
|
8159
|
98 |
if [ -n "$BUILD" ]; then
|
|
99 |
IMAGES="$NAME"
|
|
100 |
TEST=""
|
|
101 |
TARGET="\$(OUT)/$NAME"
|
8244
|
102 |
ROOT_ML="ROOT.ML"
|
8579
|
103 |
SOURCES="*.thy"
|
8244
|
104 |
[ -n "$DOCUMENT" ] && DOCUMENT_ROOT="document/root.tex"
|
8194
|
105 |
USEDIR="\$(USEDIR) -b -P http://isabelle.in.tum.de/library"
|
8159
|
106 |
else
|
|
107 |
IMAGES=""
|
|
108 |
TEST="$NAME"
|
8211
|
109 |
TARGET="\$(LOG)/$LOGIC-$NAME.gz"
|
8244
|
110 |
ROOT_ML="$NAME/ROOT.ML"
|
8579
|
111 |
SOURCES="$NAME/*.thy"
|
8244
|
112 |
[ -n "$DOCUMENT" ] && DOCUMENT_ROOT="$NAME/document/root.tex"
|
8194
|
113 |
USEDIR="\$(USEDIR)"
|
8159
|
114 |
fi
|
|
115 |
|
8198
|
116 |
if [ "$ISAMAKEFILE" != - -a -f "$ISAMAKEFILE" ]; then
|
|
117 |
echo "keeping $PWD/$ISAMAKEFILE" >&2
|
8159
|
118 |
else
|
|
119 |
{ echo
|
|
120 |
echo "## targets"
|
|
121 |
echo
|
|
122 |
echo "default: $NAME"
|
|
123 |
echo "images: $IMAGES"
|
|
124 |
echo "test: $TEST"
|
|
125 |
echo
|
|
126 |
echo "all: images test"
|
|
127 |
echo
|
|
128 |
echo
|
|
129 |
echo "## global settings"
|
|
130 |
echo
|
|
131 |
echo "SRC = \$(ISABELLE_HOME)/src"
|
|
132 |
echo "OUT = \$(ISABELLE_OUTPUT)"
|
|
133 |
echo "LOG = \$(OUT)/log"
|
8475
|
134 |
echo "USEDIR = \$(ISATOOL) usedir -i true -d dvi ## -D document"
|
8159
|
135 |
echo
|
|
136 |
echo
|
|
137 |
echo "## $NAME"
|
|
138 |
echo ""
|
8162
|
139 |
if [ -n "$PARENT" ]; then
|
|
140 |
echo "$NAME: $LOGIC $TARGET"
|
|
141 |
echo
|
|
142 |
echo "$LOGIC:"
|
|
143 |
echo -e "\t@cd \$(SRC)/$LOGIC; \$(ISATOOL) make $LOGIC"
|
|
144 |
echo
|
8579
|
145 |
echo "$TARGET: \$(OUT)/$LOGIC $ROOT_ML $DOCUMENT_ROOT ## $SOURCES"
|
8194
|
146 |
echo -e "\t@$USEDIR \$(OUT)/$LOGIC $NAME"
|
8162
|
147 |
else
|
|
148 |
echo "$NAME: $TARGET"
|
|
149 |
echo
|
8579
|
150 |
echo "$TARGET: $ROOT_ML $DOCUMENT_ROOT ## $SOURCES"
|
8194
|
151 |
echo -e "\t@$USEDIR $LOGIC $NAME"
|
8162
|
152 |
fi
|
8159
|
153 |
echo
|
|
154 |
echo
|
|
155 |
echo "## clean"
|
|
156 |
echo
|
|
157 |
echo "clean:"
|
|
158 |
echo -e "\t@rm -f $TARGET"
|
|
159 |
echo
|
8198
|
160 |
} | {
|
|
161 |
if [ -z "$ISAMAKEFILE" -o "$ISAMAKEFILE" = - ]; then
|
|
162 |
cat
|
|
163 |
else
|
|
164 |
cat > "$ISAMAKEFILE"
|
|
165 |
fi
|
|
166 |
}
|
8159
|
167 |
fi
|
|
168 |
|
|
169 |
|
|
170 |
# base directory
|
|
171 |
|
|
172 |
if [ -z "$BUILD" ]; then
|
|
173 |
mkdir -p "$NAME" || fail "Bad directory: $PWD/$NAME"
|
|
174 |
cd "$NAME"
|
|
175 |
fi
|
|
176 |
|
|
177 |
if [ -f ROOT.ML ]; then
|
|
178 |
echo "keeping $PWD/ROOT.ML" >&2
|
|
179 |
else
|
|
180 |
echo -e "\n(* use_thy \"YourTheory\"; *)\n" >ROOT.ML
|
|
181 |
fi
|
|
182 |
|
|
183 |
|
|
184 |
# document directory
|
|
185 |
|
|
186 |
if [ -n "$DOCUMENT" ]; then
|
|
187 |
if [ -e document ]; then
|
|
188 |
echo "keeping $PWD/document" >&2
|
|
189 |
else
|
|
190 |
mkdir document || fail "Bad directory: $PWD/document"
|
10423
|
191 |
TITLE=$(echo "$NAME" | tr _ -)
|
8159
|
192 |
cat >document/root.tex <<EOF
|
|
193 |
|
|
194 |
\documentclass[11pt,a4paper]{article}
|
|
195 |
\usepackage{isabelle,isabellesym,pdfsetup}
|
|
196 |
|
10021
|
197 |
%for best-style documents ...
|
|
198 |
\urlstyle{rm}
|
|
199 |
\isabellestyle{it}
|
9656
|
200 |
|
8159
|
201 |
\begin{document}
|
10353
|
202 |
|
10423
|
203 |
\title{$TITLE}\maketitle
|
10308
|
204 |
\tableofcontents
|
10353
|
205 |
|
|
206 |
\parindent 0pt\parskip 0.5ex
|
8159
|
207 |
\input{session}
|
10353
|
208 |
|
|
209 |
%\bibliographystyle{plain}
|
|
210 |
%\bibliography{root}
|
|
211 |
|
8159
|
212 |
\end{document}
|
|
213 |
EOF
|
|
214 |
fi
|
|
215 |
fi
|