#!/usr/bin/env bash
# make-roslisp-image IMAGE_NAME
# Creates or overwrites a file IMAGE_NAME containing the Lisp image that includes Roslisp
# Will be used as an intermediate file when making individual executables for ROS nodes

if [[ $# == 1 ]]; then
    
    # Force certain files to be recompiled
    touch `rospack find roslisp`/msg.lisp
    touch `rospack find roslisp`/utils/hash-utils.lisp

    sbcl --noinform --userinit "`rospack find roslisp`/scripts/roslisp-sbcl-init" --eval "(setf sb-ext:*invoke-debugger-hook* #'(lambda (a b) (declare (ignore b)) (format t \"Roslisp compilation dying due to error ~a\" a) (sb-ext:quit :unix-status 70)))" --eval "(handler-bind ((warning #'(lambda (c) (format t \"~&Ignoring warning ~a\" c) (muffle-warning)))) (asdf:operate 'asdf:load-op ':roslisp))" --eval "(setf sb-ext:*invoke-debugger-hook* #'roslisp:standalone-exec-debug-hook roslisp:*running-from-command-line* t)" --eval "(sb-ext:save-lisp-and-die \"$1\")"
    touch `rospack find roslisp`/msg.lisp
    touch `rospack find roslisp`/utils/hash-utils.lisp
else
    echo "Usage: make-roslisp-image IMAGE_NAME"
fi
