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