Created
November 11, 2010 17:48
-
-
Save kosh04/672880 to your computer and use it in GitHub Desktop.
util/link.lsp モジュールを便利にするラッパースクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# newlisp_link.sh - util/link.lsp モジュールを便利にするラッパースクリプト | |
# NOTE: | |
# - 引数がひとつずれる | |
# -- $ newlisp hello.lsp arg1 arg2 => ("newlisp" "hello.lsp" "arg1" "arg2") | |
# -- $ ./hello arg1 arg2 => ("./hello" "arg1" "arg2") | |
# - encryptされたスクリプトを読み込む場合はinit.lspを読み込まない | |
# >>> src/newlisp.c:loadStartup() | |
# - 64bitシステムではどうやらlink.lspが利用できないらしい | |
fatal() { | |
echo "$1" 1>&2 | |
exit 1 | |
} | |
usage() { | |
echo "Usage: $0 [-o newExe] [-l linkFile] [-x orgExe] source" | |
exit 2 | |
} | |
while getopts o:l:x:d OPT; do | |
case $OPT in | |
o|+o ) DST=$OPTARG;; | |
l|-l ) LINKFILE=$OPTARG;; | |
x|+x ) NEWLISP=$OPTARG;; | |
d|+d ) DEBUG=true;; | |
\? ) usage;; | |
esac | |
done | |
shift `expr $OPTIND - 1` | |
OPTIND=1 | |
if [ $# -eq 0 ]; then | |
usage | |
fi | |
SRC=$1 | |
: ${DST:=`basename ${SRC%.lsp}`} # /path/to/XXX.lsp -> XXX | |
: ${NEWLISP:=/usr/bin/newlisp} | |
: ${LINKFILE:=/usr/share/newlisp/util/link.lsp} | |
if [ -L $NEWLISP ]; then | |
NEWLISP=`readlink -e $NEWLISP` | |
fi | |
if [ $DEBUG ]; then | |
cat <<-EOF | |
SRC=$SRC | |
DST=$DST | |
NEWLISP=$NEWLISP | |
LINKFILE=$LINKFILE | |
EOF | |
fi | |
if [ ! -f "$SRC" ]; then fatal "$SRC: No such file or directory" | |
elif [ "$DST" = "$SRC" ]; then fatal "$DST: Missing output filename" | |
elif [ -d "$DST" ]; then fatal "$DST: is a directory" | |
elif [ ! -f "$LINKFILE" ]; then fatal "$LINKFILE: No such module" | |
elif [ ! -x "$NEWLISP" ]; then fatal "$NEWLISP: Cannot execute binary" | |
fi | |
$NEWLISP -n -e "(silent) | |
(load {$LINKFILE}) | |
(link {$NEWLISP} {$DST} {$SRC}) | |
" | |
if [ -f "$DST" ]; then | |
chmod u+x "$DST" | |
[ $DEBUG ] && echo "done" | |
fi | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment