| 1 |
#!/bin/sh |
| 2 |
# |
| 3 |
# Create a runnable file of auxiliary tools, such as gauche-install. |
| 4 |
# |
| 5 |
# Auxiliary scripts are written in Gauche, and on Unix systems it is |
| 6 |
# suffice to use shebang magic to execute them. However, on Windows, |
| 7 |
# shebang doesn't work, and we don't want to rely on .bat files |
| 8 |
# (its command-line processing is totaly broken). So we create |
| 9 |
# executables. Windows also requires resource info if the command |
| 10 |
# takes certain actions. |
| 11 |
|
| 12 |
usage() { |
| 13 |
echo "Usage: make-tool.sh <bindir> <target> <source> <aux-source> ..." |
| 14 |
exit 1 |
| 15 |
} |
| 16 |
|
| 17 |
do_posix() { |
| 18 |
bindir=$1 |
| 19 |
target=$2 |
| 20 |
source=$3 |
| 21 |
rm -f $target |
| 22 |
echo "#!${bindir}/gosh" > $target && cat $source >> $target |
| 23 |
chmod -w+x $target |
| 24 |
} |
| 25 |
|
| 26 |
scm2c() { |
| 27 |
source=$1 |
| 28 |
target=$2 |
| 29 |
|
| 30 |
rm -f $target |
| 31 |
cat > $target <<EOF |
| 32 |
#include "gauche.h" |
| 33 |
|
| 34 |
static const char* script = "\\n" |
| 35 |
EOF |
| 36 |
|
| 37 |
sed -e 's@\\@\\\\@g' -e 's@"@\\"@g' -e 's@^.*$@"&\\n"@g' $source > $target |
| 38 |
|
| 39 |
cat >> $target <<EOF |
| 40 |
; |
| 41 |
|
| 42 |
int main(int argc, const char **argv) |
| 43 |
{ |
| 44 |
Scm_Init(GAUCHE_SIGNATURE); |
| 45 |
Scm_SimpleMain(argc, argv, script, 0); |
| 46 |
return 0; |
| 47 |
} |
| 48 |
EOF |
| 49 |
} |
| 50 |
|
| 51 |
do_mingw() { |
| 52 |
# NB: Currently we still use ming-exify. Implement this using scm2c above |
| 53 |
# and replace mingw-exify with this script. |
| 54 |
echo "WRITEME!" |
| 55 |
} |
| 56 |
|
| 57 |
# |
| 58 |
# Main body |
| 59 |
# |
| 60 |
|
| 61 |
bindir=$1 |
| 62 |
target=$2 |
| 63 |
source=$3 |
| 64 |
rsrc=$4 |
| 65 |
|
| 66 |
if [ -z "$source" -o -z "$target" -o -z "$bindir" ]; then |
| 67 |
usage |
| 68 |
fi |
| 69 |
|
| 70 |
if uname -a | grep -i 'mingw'; then |
| 71 |
do_mingw "${bindir}" "${target}" "${source}" "${rsrc}" |
| 72 |
else |
| 73 |
do_posix "${bindir}" "${target}" "${source}" |
| 74 |
fi |