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)"
|
11578
|
23 |
echo " -q quiet mode"
|
8159
|
24 |
echo
|
11578
|
25 |
echo " Prepare session directory, including IsaMakefile and document source"
|
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=""
|
11578
|
45 |
QUIET=""
|
8159
|
46 |
|
11578
|
47 |
while getopts "I:Pbq" 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 |
;;
|
11578
|
59 |
q)
|
|
60 |
QUIET=true
|
8159
|
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 |
|
11578
|
90 |
[ -z "$QUIET" ] && echo "Preparing session \"$NAME\" ..."
|
|
91 |
|
|
92 |
|
8159
|
93 |
# IsaMakefile
|
|
94 |
|
8685
|
95 |
mkdir -p "$DIR" || fail "Bad directory: $DIR"
|
|
96 |
cd "$DIR"
|
|
97 |
|
8244
|
98 |
DOCUMENT_ROOT=""
|
|
99 |
|
8159
|
100 |
if [ -n "$BUILD" ]; then
|
|
101 |
IMAGES="$NAME"
|
|
102 |
TEST=""
|
|
103 |
TARGET="\$(OUT)/$NAME"
|
8244
|
104 |
ROOT_ML="ROOT.ML"
|
8579
|
105 |
SOURCES="*.thy"
|
11578
|
106 |
DOCUMENT_ROOT="document/root.tex"
|
8194
|
107 |
USEDIR="\$(USEDIR) -b -P http://isabelle.in.tum.de/library"
|
8159
|
108 |
else
|
|
109 |
IMAGES=""
|
|
110 |
TEST="$NAME"
|
8211
|
111 |
TARGET="\$(LOG)/$LOGIC-$NAME.gz"
|
8244
|
112 |
ROOT_ML="$NAME/ROOT.ML"
|
8579
|
113 |
SOURCES="$NAME/*.thy"
|
11578
|
114 |
DOCUMENT_ROOT="$NAME/document/root.tex"
|
8194
|
115 |
USEDIR="\$(USEDIR)"
|
8159
|
116 |
fi
|
|
117 |
|
8198
|
118 |
if [ "$ISAMAKEFILE" != - -a -f "$ISAMAKEFILE" ]; then
|
11578
|
119 |
echo "keeping $DIR/$ISAMAKEFILE" >&2
|
8159
|
120 |
else
|
|
121 |
{ echo
|
|
122 |
echo "## targets"
|
|
123 |
echo
|
|
124 |
echo "default: $NAME"
|
|
125 |
echo "images: $IMAGES"
|
|
126 |
echo "test: $TEST"
|
|
127 |
echo
|
|
128 |
echo "all: images test"
|
|
129 |
echo
|
|
130 |
echo
|
|
131 |
echo "## global settings"
|
|
132 |
echo
|
|
133 |
echo "SRC = \$(ISABELLE_HOME)/src"
|
|
134 |
echo "OUT = \$(ISABELLE_OUTPUT)"
|
|
135 |
echo "LOG = \$(OUT)/log"
|
11578
|
136 |
echo
|
|
137 |
echo "USEDIR = \$(ISATOOL) usedir -v true -i true -d dvi ## -D document"
|
8159
|
138 |
echo
|
|
139 |
echo
|
|
140 |
echo "## $NAME"
|
|
141 |
echo ""
|
8162
|
142 |
if [ -n "$PARENT" ]; then
|
|
143 |
echo "$NAME: $LOGIC $TARGET"
|
|
144 |
echo
|
|
145 |
echo "$LOGIC:"
|
|
146 |
echo -e "\t@cd \$(SRC)/$LOGIC; \$(ISATOOL) make $LOGIC"
|
|
147 |
echo
|
8579
|
148 |
echo "$TARGET: \$(OUT)/$LOGIC $ROOT_ML $DOCUMENT_ROOT ## $SOURCES"
|
8194
|
149 |
echo -e "\t@$USEDIR \$(OUT)/$LOGIC $NAME"
|
8162
|
150 |
else
|
|
151 |
echo "$NAME: $TARGET"
|
|
152 |
echo
|
11578
|
153 |
echo "$TARGET: ## $ROOT_ML $DOCUMENT_ROOT $SOURCES"
|
8194
|
154 |
echo -e "\t@$USEDIR $LOGIC $NAME"
|
8162
|
155 |
fi
|
8159
|
156 |
echo
|
|
157 |
echo
|
|
158 |
echo "## clean"
|
|
159 |
echo
|
|
160 |
echo "clean:"
|
|
161 |
echo -e "\t@rm -f $TARGET"
|
|
162 |
echo
|
8198
|
163 |
} | {
|
|
164 |
if [ -z "$ISAMAKEFILE" -o "$ISAMAKEFILE" = - ]; then
|
|
165 |
cat
|
|
166 |
else
|
|
167 |
cat > "$ISAMAKEFILE"
|
|
168 |
fi
|
|
169 |
}
|
8159
|
170 |
fi
|
|
171 |
|
|
172 |
|
|
173 |
# base directory
|
|
174 |
|
|
175 |
if [ -z "$BUILD" ]; then
|
11578
|
176 |
mkdir -p "$NAME" || fail "Bad directory: $DIR/$NAME"
|
8159
|
177 |
cd "$NAME"
|
11578
|
178 |
PREFIX="$DIR/$NAME"
|
|
179 |
else
|
|
180 |
PREFIX="$DIR"
|
8159
|
181 |
fi
|
|
182 |
|
|
183 |
if [ -f ROOT.ML ]; then
|
11578
|
184 |
echo "keeping $PREFIX/ROOT.ML" >&2
|
8159
|
185 |
else
|
11578
|
186 |
cat >ROOT.ML <<EOF
|
|
187 |
(*
|
|
188 |
no_document use_thy "ThisTheory";
|
|
189 |
use_thy "ThatTheory";
|
|
190 |
*)
|
|
191 |
EOF
|
8159
|
192 |
fi
|
|
193 |
|
|
194 |
|
|
195 |
# document directory
|
|
196 |
|
11578
|
197 |
#set by configure
|
|
198 |
AUTO_PERL=perl
|
|
199 |
|
|
200 |
if [ -e document ]; then
|
|
201 |
echo "keeping $PREFIX/document" >&2
|
|
202 |
else
|
|
203 |
mkdir document || fail "Bad directory: $PREFIX/document"
|
|
204 |
TITLE=$(echo "$NAME" | tr _ -)
|
|
205 |
AUTHOR=$("$AUTO_PERL" -e "@pw = getpwnam(\"$USER\"); print @pw[5]" | tr _ -)
|
|
206 |
cat >document/root.tex <<EOF
|
8159
|
207 |
|
|
208 |
\documentclass[11pt,a4paper]{article}
|
11578
|
209 |
\usepackage{isabelle,isabellesym}
|
8159
|
210 |
|
11578
|
211 |
% further packages required for unusual symbols (see also isabellesym.sty)
|
|
212 |
%\usepackage{latexsym}
|
|
213 |
%\usepackage{amssymb}
|
|
214 |
%\usepackage[english]{babel}
|
|
215 |
%\usepackage[latin1]{inputenc}
|
|
216 |
%\usepackage[only,bigsqcap]{stmaryrd}
|
|
217 |
%\usepackage{wasysym}
|
|
218 |
%\usepackage{eufrak}
|
|
219 |
|
|
220 |
% this should be the last package used
|
|
221 |
\usepackage{pdfsetup}
|
|
222 |
|
|
223 |
% proper setup for best-style documents
|
10021
|
224 |
\urlstyle{rm}
|
|
225 |
\isabellestyle{it}
|
9656
|
226 |
|
11578
|
227 |
|
8159
|
228 |
\begin{document}
|
10353
|
229 |
|
11578
|
230 |
\title{$TITLE}
|
|
231 |
\author{$AUTHOR}
|
|
232 |
\maketitle
|
|
233 |
|
10308
|
234 |
\tableofcontents
|
10353
|
235 |
|
|
236 |
\parindent 0pt\parskip 0.5ex
|
11578
|
237 |
|
|
238 |
% include generated text of all theories
|
8159
|
239 |
\input{session}
|
10353
|
240 |
|
|
241 |
%\bibliographystyle{plain}
|
|
242 |
%\bibliography{root}
|
|
243 |
|
8159
|
244 |
\end{document}
|
|
245 |
EOF
|
|
246 |
fi
|
11578
|
247 |
|
|
248 |
|
|
249 |
# notes
|
|
250 |
|
|
251 |
if [ -z "$QUIET" ]; then
|
|
252 |
|
|
253 |
cat >&2 <<EOF
|
|
254 |
|
|
255 |
Notes:
|
|
256 |
|
|
257 |
* 'isatool make' processes the session (including document preparation)
|
|
258 |
|
|
259 |
* $PREFIX/ROOT.ML needs to contain ML code to load all theories
|
|
260 |
|
|
261 |
* $PREFIX/document/root.tex contains the LaTeX master document setup
|
|
262 |
|
|
263 |
* $DIR/IsaMakefile contains compilation options and file dependencies
|
|
264 |
|
|
265 |
EOF
|
|
266 |
|
|
267 |
fi
|