#! /bin/sh
# Call: make-nq-image [all] [lispview] [x-windows] 
#       where all      selects recompiling everything (if not specified, then
#                      only updated sources are compiled)
#             lispview  compiles nq with lispview
#             x-windows compiles nq with x-windows (xbatch)
#       The default is to compile only updated sources under both lispview and
#       x-windows.

FORCED=":new-source-and-dependents"  
LISPVIEW=    # = lispview if lispview should be recompiled
XWINDOWS=xwindows    # = xwindows if x-windows should be recompiled

QR_DIR="/v/ai/v5/qr"

for i 
do
   case $i in
       all)           FORCED=":all" ;;
#       lispview)      LISPVIEW=lispview ;;
#       x-windows)     XWINDOWS=xwindows ;;
       make-nq-image) ;;
       *)             echo Usage: make-nq-image [all] [lispview] [x-windows] ;
		      exit 1 ;;
   esac
done

#if [ -z "$LISPVIEW" -a -z "$XWINDOWS" ]
#then
#   LISPVIEW=lispview ; XWINDOWS=xwindows
#fi

if [ "$FORCED" = ":all" ]
then
   RECOMPMSG="and recompiling all files"
else
   RECOMPMSG="and recompiling updated files"
fi

# In what follows, FEATURE contains a string representing the keyword
# to push onto the *features* list and IMAGEEXT contains a (possibly empty)
# string that contains the extension to the image name.

for i in $LISPVIEW $XWINDOWS
do
    if [ "$i" ]
    then
       case $i in
	lispview)  FEATURE=":pos-lispview" ; IMAGEEXT="_lispview" ;;
	xwindows)  FEATURE=":x-windows" ; IMAGEEXT= ;;
       esac
       echo Making NQ image for $i $RECOMPMSG
       lisp -n \
	    -eval "(proclaim '(optimize (compilation-speed 0)))" \
	    -eval "(progn \
#	              (load \"/lusr/lang/lisp/clos\") \
		      (load \"${QR_DIR}/c-lisp/logical-pathnames.lisp\") \
                      (load \"${QR_DIR}/c-lisp/new-defsystem.lisp\")     \
                      (load \"${QR_DIR}/c-lisp/defsystem-patches.lisp\"))" \
	    -eval "(setq mk::*central-registry* \"${QR_DIR}/sys-site/\")" \
	    -eval "(pushnew $FEATURE *features*)" \
	-eval "(with-deferred-warnings
		  (operate-on-system 'nq :compile :force $FORCED))" \
	-eval "(disksave \"${QR_DIR}/nq/nq_x_lcl4.0$IMAGEEXT\" :full-gc T)" \
	-quit
    fi
done



