From 3f976de9a30ba93c417bd43b4dc81c3ad3ee133b Mon Sep 17 00:00:00 2001 From: retropikzel Date: Tue, 21 Jan 2025 18:32:35 +0200 Subject: [PATCH] Made improvements to csc compiling --- Makefile | 2 +- README.md | 7 ++++++- compile-r7rs | 32 +++++++++++++++++++++----------- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index e32cfde..f15c239 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ install: install compile-r7rs ${PREFIX}/bin/compile-r7rs test: - @cd test && ../compile-r7rs -D . -D ./libs -D ./libs2 main.scm + @cd test && ../compile-r7rs -I . -I ./libs -I ./libs2 main.scm clean: find . -name "*.c*" -delete diff --git a/README.md b/README.md index 25e1ac1..286cd7a 100644 --- a/README.md +++ b/README.md @@ -32,12 +32,17 @@ but the ${HOME}/.local/bin needs to be in your path for you to be able to run th ## Usage -The environment variable SCC must be set to the same value as the implementations command. +The environment variable SCMC must be set to the same value as the implementations command. The command is the first word on the list. So for example guile for Guile, csi for Chicken interpreter, csc for Chicken compiler. If the command has .exe at it's end cross compilation from Linux to .exe with Wine is assumed. + +Run + + SCMC= compile-r7rs -I + ## Outputs ### Self contained, self extracting and runnable shell script diff --git a/compile-r7rs b/compile-r7rs index a968eee..9c6842a 100755 --- a/compile-r7rs +++ b/compile-r7rs @@ -1,5 +1,7 @@ #!/bin/sh +if [ ! "${COMPILE_R7RS_DEBUG}" = "" ]; then set -x; fi + CC=gcc if [ "" = "${CC}" ] then @@ -9,11 +11,12 @@ fi output="a.out" libdirs="" -while getopts "D:o:" flag +while getopts "I:A:o:" flag do case $flag in o) output="${OPTARG}";; - D) libdirs="$libdirs ${OPTARG}";; + A) libdirs="$libdirs ${OPTARG}";; + I) libdirs="${OPTARG} $libdirs";; esac done @@ -23,7 +26,9 @@ if [ ! "" = "${main}" ]; then output="${main%.*}"; fi #tmpdir="${HOME}/.cache/compile-r7rs/$(md5sum $main)/" tmpdir="${HOME}/.cache/compile-r7rs/test" -case ${SCC} in +if [ ! "${COMPILE_R7RS_DEBUG}" = "" ]; then echo "SCMC: ${SCMC}"; fi + +case "${SCMC}" in chibi-scheme) paths="-I $tmpdir" for dir in $libdirs @@ -43,17 +48,22 @@ case ${SCC} in csc) 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#./}" - for lib in $(find "$dir" -name "*.sld") + for lib in $(find "${dir}" -name "*.sld") do - echo "Compiling $lib" - csc -X r7rs -R r7rs -c -J -unit ${lib%.sld} "$lib" + unit0=$(cd "${dir}" && find . -name $(basename "${lib}")) + unit1=$(echo "${unit0#\./}" | sed 's/\//\./g') + unit=${unit1%.sld} + echo "Compiling $lib as unit ${unit}" + csc -X r7rs -R r7rs -cc ${CC} ${CSCFLAGS} -c -J -unit ${unit} -uses "${units}" "$lib" -o "${unit}.o" + units="${units},${unit}" objects="$objects ${lib%.sld}.o" done done - csc -X r7rs -R r7rs -static $objects -o $output $main + csc -X r7rs -R r7rs -cc ${CC} ${CSCFLAGS} -o $output -static -uses ${units} $main chmod +x "$output" exit 0 ;; @@ -111,7 +121,7 @@ case ${SCC} in do paths="$paths -L $tmpdir/${dir#./}" done - scm_cmd="guile --r7rs $paths -s" + scm_cmd="guile --r7rs $paths" ;; kawa) jar xf kawa.jar @@ -232,7 +242,7 @@ case ${SCC} in scm_cmd="ypsilon --r7rs $paths --top-level-program" ;; *) - echo "Unsupported SCC (SCheme Compiler) implementation or environment value not set." + echo "Unsupported SCMC (SCheMe Compiler) implementation or environment value not set." exit 1 esac @@ -244,10 +254,10 @@ rm -rf "$output" echo 'CURDIR=${PWD}' echo "cd $tmpdir" echo "{" - shar -M --quiet-unshar --no-check-existing --no-timestamp $main $libdirs | 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 'cd ${CURDIR}' - echo "$command" + echo "$command \"\$@\"" } > "$output" chmod +x "$output"