Shellcheckking added and problems fixed

This commit is contained in:
retropikzel 2025-02-01 09:36:07 +02:00
parent 9d43fbd9a8
commit f9b8d2dd88
3 changed files with 49 additions and 53 deletions

View File

@ -8,6 +8,9 @@ install:
mkdir -p ${PREFIX}/bin mkdir -p ${PREFIX}/bin
install compile-r7rs ${PREFIX}/bin/compile-r7rs install compile-r7rs ${PREFIX}/bin/compile-r7rs
shellcheck:
shellcheck compile-r7rs
test: test:
@cd test && ../compile-r7rs -I . -I ./libs -I ./libs2 main.scm @cd test && ../compile-r7rs -I . -I ./libs -I ./libs2 main.scm

View File

@ -17,18 +17,7 @@ For jar:
## Installing ## Installing
- Download the scman script make install
- Place it in ${HOME}/.local/bin
- Add ${HOME}/.local/bin to the PATH
- For example add to your .bashrc: export PATH="${HOME}/.local/bin:${PATH}"
- Make the script runnable
- chmod -x ${HOME}/.local/bin/scman
You can also run it in place with
./scman ...
but the ${HOME}/.local/bin needs to be in your path for you to be able to run the implementations.
## Usage ## Usage

View File

@ -1,11 +1,10 @@
#!/bin/sh #!/bin/sh
if [ ! "${COMPILE_R7RS_DEBUG}" = "" ]; then set -x; fi if [ ! "$COMPILE_R7RS_DEBUG" = "" ]; then set -x; fi
CC=gcc if [ "$CC" = "" ]
if [ "" = "${CC}" ]
then then
CC=${CC} CC=gcc
fi fi
output="a.out" output="a.out"
@ -13,22 +12,23 @@ libdirs=""
while getopts "I:A:o:" flag while getopts "I:A:o:" flag
do do
case $flag in case "$flag" in
o) output="${OPTARG}";; o) output="$OPTARG";;
A) libdirs="$libdirs ${OPTARG}";; A) libdirs="$libdirs $OPTARG";;
I) libdirs="${OPTARG} $libdirs";; I) libdirs="$OPTARG $libdirs";;
*) echo "Invalid flag: $flag" && exit 1
esac esac
done done
for main; do true; done # Get the last argument for main; do true; done # Get the last argument
if [ ! "" = "${main}" ]; then output="${main%.*}"; fi if [ ! "" = "$main" ]; then output="${main%.*}"; fi
#tmpdir="${HOME}/.cache/compile-r7rs/$(md5sum $main)/" #tmpdir="$HOME/.cache/compile-r7rs/$(md5sum $main)/"
tmpdir="${HOME}/.cache/compile-r7rs/test" tmpdir="$HOME/.cache/compile-r7rs/test"
if [ ! "${COMPILE_R7RS_DEBUG}" = "" ]; then echo "SCMC: ${SCMC}"; fi if [ ! "$COMPILE_R7RS_DEBUG" = "" ]; then echo "SCMC: $SCMC"; fi
case "${SCMC}" in case "$SCMC" in
chibi-scheme) chibi-scheme)
paths="-I $tmpdir" paths="-I $tmpdir"
for dir in $libdirs for dir in $libdirs
@ -53,20 +53,24 @@ case "${SCMC}" in
for dir in $libdirs for dir in $libdirs
do do
paths="$paths -I $tmpdir/${dir#./}" paths="$paths -I $tmpdir/${dir#./}"
for lib in $(find "${dir}" -name "*.sld") for lib in **/*.sld #$(find "${dir}" -name "*.sld")
do do
unit0=$(cd "${dir}" && find . -name $(basename "${lib}")) unit0=$(cd "$dir" && find . -name "$(basename "$lib")")
unit1=$(echo "${unit0#\./}" | sed 's/\//\./g') unit1=$(echo "${unit0#\./}" | sed 's/\//\./g')
unit=${unit1%.sld} unit=${unit1%.sld}
echo "Compiling $lib as unit ${unit}" echo "Compiling $lib as unit $unit"
csc -X r7rs -R r7rs -cc ${CC} ${CSCFLAGS} -c -J -unit ${unit} -uses "${units}" "$lib" -o "${unit}.o" # CSC_FLAGS need to expand with spaces
units="${units},${unit}" # 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" objects="$objects ${lib%.sld}.o"
done done
done done
output="${main%.scm}" output="${main%.scm}"
csc -X r7rs -R r7rs -cc ${CC} ${CSCFLAGS} -static -o "${output}" -uses ${units} ${main} # CSC_FLAGS need to expand with spaces
test -f "${output}" && chmod +x "${output}" # 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 exit 0
;; ;;
icyc) icyc)
@ -108,12 +112,12 @@ case "${SCMC}" in
for dir in $libdirs for dir in $libdirs
do do
paths="$paths ${dir#./}" paths="$paths ${dir#./}"
for lib in $(find "$dir" -name "*.sld") for lib in **/*.sld #$(find "${dir}" -name "*.sld")
do do
libs="$libs $lib" libs="$libs $lib"
done done
done done
gxc -o $output -static $libs $main gxc -o "$output" -static "$libs" "$main"
rm -rf gerbil.pkg rm -rf gerbil.pkg
exit exit
;; ;;
@ -131,18 +135,18 @@ case "${SCMC}" in
for dir in $libdirs for dir in $libdirs
do do
paths="$paths $dir" paths="$paths $dir"
for lib in $(find "$dir" -name "*.sld") for lib in **/*.sld #$(find "$dir" -name "*.sld")
do do
kawa -C $lib kawa -C "$lib"
done done
done done
{ {
echo "Main-Class: main" echo "Main-Class: main"
echo "Class-Path: . gnu kawa $paths" echo "Class-Path: . gnu kawa $paths"
} > /tmp/compile-r7rs-MANIFEST.mf } > /tmp/compile-r7rs-MANIFEST.mf
kawa --main -C $main kawa --main -C "$main"
classfiles=$(find .- name "*.class") classfiles=$(find .- name "*.class")
jar cvfm "${output}.jar" /tmp/compile-r7rs-MANIFEST.mf kawa gnu $classfiles jar cvfm "$output.jar" /tmp/compile-r7rs-MANIFEST.mf kawa gnu "$classfiles"
rm -rf gnu kawa rm -rf gnu kawa
rm -rf META-INF rm -rf META-INF
exit exit
@ -159,13 +163,13 @@ case "${SCMC}" in
paths="" paths=""
for dir in $libdirs for dir in $libdirs
do do
paths="${PWD}/${dir#./}:$paths" paths="$PWD/${dir#./}:$paths"
for lib in $(find "$dir" -name "*.sld") for lib in **/*.sld #$(find "$dir" -name "*.sld")
do do
{ {
echo "#lang r7rs" echo "#lang r7rs"
echo "(import (scheme base))" echo "(import (scheme base))"
echo "(include \"$(basename $lib)\")" echo "(include \"$(basename "$lib")\")"
} > "${lib%.sld}.rkt" } > "${lib%.sld}.rkt"
done done
done done
@ -174,20 +178,20 @@ case "${SCMC}" in
echo "#lang r7rs" echo "#lang r7rs"
cat "$main" cat "$main"
} > "${main%.scm}.rkt" } > "${main%.scm}.rkt"
PLTCOLLECTS="$paths" raco exe --orig-exe -o $output ++lang r7rs "${main%.scm}.rkt" PLTCOLLECTS="$paths" raco exe --orig-exe -o "$output" ++lang r7rs "${main%.scm}.rkt"
exit exit
;; ;;
racket.exe) racket.exe)
paths="${PWD}" paths="$PWD"
for dir in $libdirs for dir in $libdirs
do do
paths="$paths;$(winepath ${PWD}/${dir#./})" paths="$paths;$(winepath "$PWD"/"${dir#./}")"
for lib in $(find "$dir" -name "*.sld") for lib in **/*.sld #$(find "$dir" -name "*.sld")
do do
{ {
echo "#lang r7rs" echo "#lang r7rs"
echo "(import (scheme base))" echo "(import (scheme base))"
echo "(include \"$(basename $lib)\")" echo "(include \"$(basename "$lib")\")"
} > "${lib%.sld}.rkt" } > "${lib%.sld}.rkt"
done done
done done
@ -197,9 +201,9 @@ case "${SCMC}" in
cat "$main" cat "$main"
} > "${main%.scm}.rkt" } > "${main%.scm}.rkt"
set -x set -x
WINEPATH="${HOME}/.wine/drive_c/Program Files/Racket" \ WINEPATH="$HOME/.wine/drive_c/Program Files/Racket" \
PLTCOLLECTS="$paths" \ PLTCOLLECTS="$paths" \
wine raco.exe exe --orig-exe --embed-dlls -o "${output}.exe" ++lang r7rs "${main%.scm}.rkt" wine raco.exe exe --orig-exe --embed-dlls -o "$output.exe" ++lang r7rs "${main%.scm}.rkt"
exit exit
;; ;;
sash) sash)
@ -233,10 +237,10 @@ case "${SCMC}" in
do do
paths="$paths:$tmpdir/${dir%./}/" # / is needed paths="$paths:$tmpdir/${dir%./}/" # / is needed
done done
scm_cmd="TR7_LIB_PATH=\"$paths:${TR7_LIB_PATH}\" tr7i" scm_cmd="TR7_LIB_PATH=\"$paths:$TR7_LIB_PATH\" tr7i"
;; ;;
ypsilon) ypsilon)
paths="${tmpdir}/" paths="$tmpdir/"
for dir in $libdirs for dir in $libdirs
do do
paths="$paths:$tmpdir/${dir#./}" paths="$paths:$tmpdir/${dir#./}"
@ -253,12 +257,12 @@ rm -rf "$output"
{ {
echo "#!/bin/sh" echo "#!/bin/sh"
echo "mkdir -p $tmpdir" echo "mkdir -p $tmpdir"
echo 'CURDIR=${PWD}' echo "CURDIR=\$PWD"
echo "cd $tmpdir" echo "cd $tmpdir"
echo "{" 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" 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 "} > /dev/null"
echo 'cd ${CURDIR}' echo "cd \$CURDIR"
echo "$command \"\$@\"" echo "$command \"\$@\""
} > "$output" } > "$output"