283 lines
7.7 KiB
Bash
Executable File
283 lines
7.7 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
if [ ! "$COMPILE_R7RS_DEBUG" = "" ]; then set -x; fi
|
|
|
|
if [ "$CC" = "" ]
|
|
then
|
|
CC=gcc
|
|
fi
|
|
|
|
output="a.out"
|
|
libdirs=""
|
|
|
|
while getopts "I:A:o:" flag
|
|
do
|
|
case "$flag" in
|
|
o) output="$OPTARG";;
|
|
A) libdirs="$libdirs $OPTARG";;
|
|
I) libdirs="$OPTARG $libdirs";;
|
|
*) echo "Invalid flag: $flag" && exit 1
|
|
esac
|
|
done
|
|
|
|
for main; do true; done # Get the last argument
|
|
if [ ! "" = "$main" ]; then output="${main%.*}"; fi
|
|
|
|
#tmpdir="$HOME/.cache/compile-r7rs/$(md5sum $main)/"
|
|
tmpdir="$HOME/.cache/compile-r7rs/test"
|
|
|
|
if [ ! "$COMPILE_R7RS_DEBUG" = "" ]; then echo "SCMC: $SCMC"; fi
|
|
|
|
case "$SCMC" in
|
|
chibi-scheme)
|
|
paths="-I $tmpdir"
|
|
for dir in $libdirs
|
|
do
|
|
paths="$paths -I $tmpdir/${dir#./}"
|
|
done
|
|
scm_cmd="chibi-scheme $paths"
|
|
;;
|
|
csi)
|
|
paths="-I $tmpdir/*"
|
|
for dir in $libdirs
|
|
do
|
|
paths="$paths -I $tmpdir/${dir#./}/*"
|
|
done
|
|
scm_cmd="csi -b -R r7rs $paths -script"
|
|
;;
|
|
csc)
|
|
set -x
|
|
paths="-I $tmpdir"
|
|
objects=""
|
|
units="r7rs,scheme.base,scheme.case-lambda,scheme.char,scheme.complex,scheme.cxr,scheme.eval,scheme.file,scheme.inexact,scheme.lazy,scheme.load,scheme.process-context,scheme.read,scheme.repl,scheme.time,scheme.write,scheme.r5rs"
|
|
for dir in $libdirs
|
|
do
|
|
paths="$paths -I $tmpdir/${dir#./}"
|
|
findtmp="$(mktemp)"
|
|
find "$dir" -name '*.sld' > "$findtmp"
|
|
while IFS= read -r lib
|
|
do
|
|
unit0=$(cd "$dir" && find . -name "$(basename "$lib")")
|
|
unit1=$(echo "${unit0#\./}" | sed 's/\//\./g')
|
|
unit=${unit1%.sld}
|
|
echo "Compiling $lib as unit $unit"
|
|
# CSC_FLAGS need to expand with spaces
|
|
# shellcheck disable=SC2086
|
|
csc -X r7rs -R r7rs -cc "$CC" $CSC_FLAGS -c -J -unit "$unit" -uses "$units" "${lib}" -o "$unit.o"
|
|
units="$units,$unit"
|
|
objects="$objects ${lib%.sld}.o"
|
|
done < "$findtmp"
|
|
done
|
|
output="${main%.scm}"
|
|
# CSC_FLAGS need to expand with spaces
|
|
# shellcheck disable=SC2086
|
|
csc -X r7rs -R r7rs -cc "$CC" $CSC_FLAGS -static -o "$output" -uses "$units" "$main"
|
|
test -f "$output" && chmod +x "$output"
|
|
exit 0
|
|
;;
|
|
icyc)
|
|
paths="-I $tmpdir"
|
|
for dir in $libdirs
|
|
do
|
|
paths="$paths -I $tmpdir/${dir#./}"
|
|
done
|
|
scm_cmd="icyc $paths -s"
|
|
;;
|
|
gsi)
|
|
paths="${tmpdir%/}/" # / is needed
|
|
for dir in $libdirs
|
|
do
|
|
paths="$paths $tmpdir/${dir#./}/" # / is needed
|
|
done
|
|
scm_cmd="gsi -:s $paths"
|
|
;;
|
|
gosh)
|
|
paths="-I $tmpdir"
|
|
for dir in $libdirs
|
|
do
|
|
paths="$paths -I $tmpdir/${dir#./}"
|
|
done
|
|
scm_cmd="gosh -r7 $paths"
|
|
;;
|
|
gxi) # FIXME
|
|
paths=""
|
|
for dir in $libdirs
|
|
do
|
|
paths="$paths :module $tmpdir/${dir#./}"
|
|
done
|
|
scm_cmd="gxi --lang r7rs"
|
|
;;
|
|
gxc) # FIXME
|
|
echo "(prelude: :scheme/r7rs)" > gerbil.pkg
|
|
paths=""
|
|
libs=""
|
|
for dir in $libdirs
|
|
do
|
|
paths="$paths ${dir#./}"
|
|
findtmp="$(mktemp)"
|
|
find "$dir" -name '*.sld' > "$findtmp"
|
|
while IFS= read -r lib
|
|
do
|
|
libs="$libs $lib"
|
|
done < "$findtmp"
|
|
done
|
|
gxc -o "$output" -static "$libs" "$main"
|
|
rm -rf gerbil.pkg
|
|
exit
|
|
;;
|
|
guile)
|
|
paths="-L $tmpdir"
|
|
for dir in $libdirs
|
|
do
|
|
paths="$paths -L $tmpdir/${dir#./}"
|
|
done
|
|
scm_cmd="guile --r7rs $paths"
|
|
;;
|
|
kawa)
|
|
jar xf kawa.jar
|
|
paths=""
|
|
for dir in $libdirs
|
|
do
|
|
paths="$paths $dir"
|
|
findtmp="$(mktemp)"
|
|
find "$dir" -name '*.sld' > "$findtmp"
|
|
while IFS= read -r lib
|
|
do
|
|
kawa -C "$lib"
|
|
done < "$findtmp"
|
|
done
|
|
{
|
|
echo "Main-Class: main"
|
|
echo "Class-Path: . gnu kawa $paths"
|
|
} > /tmp/compile-r7rs-MANIFEST.mf
|
|
kawa --main -C "$main"
|
|
classfiles=$(find .- name "*.class")
|
|
jar cvfm "$output.jar" /tmp/compile-r7rs-MANIFEST.mf kawa gnu "$classfiles"
|
|
rm -rf gnu kawa
|
|
rm -rf META-INF
|
|
exit
|
|
;;
|
|
mosh)
|
|
paths="$tmpdir"
|
|
for dir in $libdirs
|
|
do
|
|
paths="$paths:$tmpdir/${dir#./}"
|
|
done
|
|
scm_cmd="mosh --loadpath=$paths"
|
|
;;
|
|
racket)
|
|
paths=""
|
|
for dir in $libdirs
|
|
do
|
|
paths="$PWD/${dir#./}:$paths"
|
|
findtmp="$(mktemp)"
|
|
find "$dir" -name '*.sld' > "$findtmp"
|
|
while IFS= read -r lib
|
|
do
|
|
{
|
|
echo "#lang r7rs"
|
|
echo "(import (scheme base))"
|
|
echo "(include \"$(basename "$lib")\")"
|
|
} > "${lib%.sld}.rkt"
|
|
done < "$findtmp"
|
|
done
|
|
|
|
{
|
|
echo "#lang r7rs"
|
|
cat "$main"
|
|
} > "${main%.scm}.rkt"
|
|
PLTCOLLECTS="$paths" raco exe --orig-exe -o "$output" ++lang r7rs "${main%.scm}.rkt"
|
|
exit
|
|
;;
|
|
racket.exe)
|
|
paths="$PWD"
|
|
for dir in $libdirs
|
|
do
|
|
paths="$paths;$(winepath "$PWD"/"${dir#./}")"
|
|
findtmp="$(mktemp)"
|
|
find "$dir" -name '*.sld' > "$findtmp"
|
|
while IFS= read -r lib
|
|
do
|
|
{
|
|
echo "#lang r7rs"
|
|
echo "(import (scheme base))"
|
|
echo "(include \"$(basename "$lib")\")"
|
|
} > "${lib%.sld}.rkt"
|
|
done < "$findtmp"
|
|
done
|
|
|
|
{
|
|
echo "#lang r7rs"
|
|
cat "$main"
|
|
} > "${main%.scm}.rkt"
|
|
set -x
|
|
WINEPATH="$HOME/.wine/drive_c/Program Files/Racket" \
|
|
PLTCOLLECTS="$paths" \
|
|
wine raco.exe exe --orig-exe --embed-dlls -o "$output.exe" ++lang r7rs "${main%.scm}.rkt"
|
|
exit
|
|
;;
|
|
sash)
|
|
paths="-L $tmpdir"
|
|
for dir in $libdirs
|
|
do
|
|
paths="$paths -L $tmpdir/${dir#./}"
|
|
done
|
|
scm_cmd="sash -r7 $paths"
|
|
;;
|
|
stklos)
|
|
paths="-I $tmpdir"
|
|
for dir in $libdirs
|
|
do
|
|
paths="$paths -I $tmpdir/${dir#./}"
|
|
done
|
|
scm_cmd="stklos $paths"
|
|
;;
|
|
skint)
|
|
paths="-I ${tmpdir%/}/"
|
|
for dir in $libdirs
|
|
do
|
|
dir1=${dir#./}
|
|
paths="$paths -I $tmpdir/${dir1%/}/" # / is needed
|
|
done
|
|
scm_cmd="skint $paths"
|
|
;;
|
|
tr7i)
|
|
paths="$tmpdir"
|
|
for dir in $libdirs
|
|
do
|
|
paths="$paths:$tmpdir/${dir%./}/" # / is needed
|
|
done
|
|
scm_cmd="TR7_LIB_PATH=\"$paths:$TR7_LIB_PATH\" tr7i"
|
|
;;
|
|
ypsilon)
|
|
paths="$tmpdir/"
|
|
for dir in $libdirs
|
|
do
|
|
paths="$paths:$tmpdir/${dir#./}"
|
|
done
|
|
scm_cmd="ypsilon --r7rs $paths --top-level-program"
|
|
;;
|
|
*)
|
|
echo "Unsupported SCMC (SCheMe Compiler) implementation or environment value not set."
|
|
exit 1
|
|
esac
|
|
|
|
command="$scm_cmd $tmpdir/$main"
|
|
rm -rf "$output"
|
|
{
|
|
echo "#!/bin/sh"
|
|
echo "mkdir -p $tmpdir"
|
|
echo "CURDIR=\$PWD"
|
|
echo "cd $tmpdir"
|
|
echo "{"
|
|
shar -M --quiet-unshar --no-check-existing --no-timestamp "$main" "$(find "$libdirs" -name "*.scm" -o -name "*.sld" -o -name "*.rkt")" | grep -v "exit 0"
|
|
echo "} > /dev/null"
|
|
echo "cd \$CURDIR"
|
|
echo "$command \"\$@\""
|
|
} > "$output"
|
|
|
|
chmod +x "$output"
|
|
echo "Command: $command"
|
|
|
|
|