lib/Tools/mkdir
author wenzelm
Fri, 28 Jan 2000 15:26:51 +0100
changeset 8162 020e384e67dd
parent 8159 64c272504383
child 8194 0c5d9d23b715
permissions -rwxr-xr-x
-p option;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8159
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
     1
#!/bin/bash
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
     2
#
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
     3
# $Id$
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
     4
#
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
     5
# DESCRIPTION: prepare logic session directory
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
     6
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
     7
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
     8
## diagnostics
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
     9
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    10
PRG=$(basename $0)
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    11
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    12
function usage()
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    13
{
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    14
  echo
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    15
  echo "Usage: $PRG LOGIC NAME"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    16
  echo
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    17
  echo "  Options are:"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    18
  echo "    -b           setup build mode (session outputs heap image)"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    19
  echo "    -d           setup document"
8162
020e384e67dd -p option;
wenzelm
parents: 8159
diff changeset
    20
  echo "    -p           include parent logic target"
8159
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    21
  echo
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    22
  echo "  Prepare logic session directory, including IsaMakefile, document etc."
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    23
  echo
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    24
  exit 1
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    25
}
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    26
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    27
function fail()
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    28
{
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    29
  echo "$1" >&2
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    30
  exit 2
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    31
}
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    32
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    33
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    34
## process command line
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    35
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    36
# options
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    37
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    38
BUILD=""
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    39
DOCUMENT=""
8162
020e384e67dd -p option;
wenzelm
parents: 8159
diff changeset
    40
PARENT=""
8159
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    41
8162
020e384e67dd -p option;
wenzelm
parents: 8159
diff changeset
    42
while getopts "bdp" OPT
8159
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    43
do
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    44
  case "$OPT" in
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    45
    b)
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    46
      BUILD=true
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    47
      ;;
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    48
    d)
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    49
      DOCUMENT=true
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    50
      ;;
8162
020e384e67dd -p option;
wenzelm
parents: 8159
diff changeset
    51
    p)
020e384e67dd -p option;
wenzelm
parents: 8159
diff changeset
    52
      PARENT=true
020e384e67dd -p option;
wenzelm
parents: 8159
diff changeset
    53
      ;;
8159
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    54
    \?)
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    55
      usage
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    56
      ;;
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    57
  esac
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    58
done
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    59
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    60
shift $(($OPTIND - 1))
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    61
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    62
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    63
# args
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    64
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    65
[ $# -ne 2 ] && usage
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    66
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    67
LOGIC="$1"; shift
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    68
NAME="$1"; shift
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    69
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    70
[ -z "$SESSION" ] && SESSION=$(basename $NAME)
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    71
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    72
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    73
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    74
## main
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    75
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    76
# IsaMakefile
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    77
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    78
if [ -n "$BUILD" ]; then
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    79
  IMAGES="$NAME"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    80
  TEST=""
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    81
  TARGET="\$(OUT)/$NAME"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    82
  USEDIR="usedir -b"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    83
else
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    84
  IMAGES=""
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    85
  TEST="$NAME"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    86
  TARGET="\$(LOG)/$NAME.gz"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    87
  USEDIR="usedir"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    88
fi
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    89
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    90
if [ -f IsaMakefile ]; then
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    91
  echo "keeping $PWD/IsaMakefile" >&2
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    92
else
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    93
  { echo
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    94
    echo "## targets"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    95
    echo
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    96
    echo "default: $NAME"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    97
    echo "images: $IMAGES"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    98
    echo "test: $TEST"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
    99
    echo
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   100
    echo "all: images test"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   101
    echo
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   102
    echo
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   103
    echo "## global settings"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   104
    echo
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   105
    echo "SRC = \$(ISABELLE_HOME)/src"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   106
    echo "OUT = \$(ISABELLE_OUTPUT)"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   107
    echo "LOG = \$(OUT)/log"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   108
    echo "INFO = \$(ISABELLE_BROWSER_INFO)"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   109
    echo
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   110
    echo
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   111
    echo "## $NAME"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   112
    echo ""
8162
020e384e67dd -p option;
wenzelm
parents: 8159
diff changeset
   113
    if [ -n "$PARENT" ]; then
020e384e67dd -p option;
wenzelm
parents: 8159
diff changeset
   114
      echo "$NAME: $LOGIC $TARGET"
020e384e67dd -p option;
wenzelm
parents: 8159
diff changeset
   115
      echo
020e384e67dd -p option;
wenzelm
parents: 8159
diff changeset
   116
      echo "$LOGIC:"
020e384e67dd -p option;
wenzelm
parents: 8159
diff changeset
   117
      echo -e "\t@cd \$(SRC)/$LOGIC; \$(ISATOOL) make $LOGIC"
020e384e67dd -p option;
wenzelm
parents: 8159
diff changeset
   118
      echo
020e384e67dd -p option;
wenzelm
parents: 8159
diff changeset
   119
      echo "$TARGET: \$(OUT)/$LOGIC     ## add $NAME sources here"
020e384e67dd -p option;
wenzelm
parents: 8159
diff changeset
   120
      echo -e "\t@\$(ISATOOL) $USEDIR \$(OUT)/$LOGIC $NAME"
020e384e67dd -p option;
wenzelm
parents: 8159
diff changeset
   121
    else
020e384e67dd -p option;
wenzelm
parents: 8159
diff changeset
   122
      echo "$NAME: $TARGET"
020e384e67dd -p option;
wenzelm
parents: 8159
diff changeset
   123
      echo
020e384e67dd -p option;
wenzelm
parents: 8159
diff changeset
   124
      echo "$TARGET:                    ## add $NAME sources here"
020e384e67dd -p option;
wenzelm
parents: 8159
diff changeset
   125
      echo -e "\t@\$(ISATOOL) $USEDIR $LOGIC $NAME"
020e384e67dd -p option;
wenzelm
parents: 8159
diff changeset
   126
    fi
8159
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   127
    echo
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   128
    echo
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   129
    echo "## clean"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   130
    echo
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   131
    echo "clean:"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   132
    echo -e "\t@rm -f $TARGET"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   133
    echo
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   134
  } >IsaMakefile
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   135
fi
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   136
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   137
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   138
# base directory
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   139
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   140
if [ -z "$BUILD" ]; then
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   141
  mkdir -p "$NAME" || fail "Bad directory: $PWD/$NAME"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   142
  cd "$NAME"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   143
fi
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   144
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   145
if [ -f ROOT.ML ]; then
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   146
  echo "keeping $PWD/ROOT.ML" >&2
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   147
else
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   148
  echo -e "\n(* use_thy \"YourTheory\"; *)\n" >ROOT.ML
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   149
fi
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   150
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   151
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   152
# document directory
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   153
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   154
if [ -n "$DOCUMENT" ]; then
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   155
  if [ -e document ]; then
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   156
    echo "keeping $PWD/document" >&2
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   157
  else
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   158
    mkdir document || fail "Bad directory: $PWD/document"
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   159
    cat >document/root.tex <<EOF
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   160
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   161
\documentclass[11pt,a4paper]{article}
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   162
\usepackage{isabelle,isabellesym,pdfsetup}
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   163
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   164
\begin{document}
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   165
\input{session}
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   166
\end{document}
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   167
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   168
EOF
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   169
  fi
64c272504383 mkdir: prepare logic session directory;
wenzelm
parents:
diff changeset
   170
fi