commit 0fbf04cb8882e3cb4b29e297d4c323c091c55426 Author: retropikzel Date: Mon Dec 23 22:01:08 2024 +0200 Made this diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..131e88c --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.swp +*.c +*.o +*.so +META-INF diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3b8f447 --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +PREFIX=/usr/local +build: + @echo "No need to build, just run make install" + +install: + mkdir -p ${PREFIX}/bin + install compile-r7rs ${PREFIX}/bin/compile-r7rs + +run-test: + @cd test && ../compile-r7rs -D ./libs -D ./libs2 main.scm + +clean: + find . -name "*.c*" -delete + find . -name "*.o*" -delete + find . -name "*.so*" -delete + find . -name "*.import.scm" -delete + find . -name "*.link" -delete + find . -name "*.class" -delete + find . -name "META-INF" -exec rm -rf {} \; + find . -not -name "kawa.jar" -name "*.jar" -delete + rm -rf test/main diff --git a/README.md b/README.md new file mode 100644 index 0000000..e89e5db --- /dev/null +++ b/README.md @@ -0,0 +1,70 @@ +Non implementation specific implementation of [SRFI-138](https://srfi.schemers.org/srfi-138/srfi-138.html). + +## Dependencies + +For scripts: + + apt install sharutils + +For binaries: + + apt install build-essential + +For jar: + + apt install default-jdk + +## Installing + +- Download the scman script +- 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 + +## Usage + +The environment variable SCC 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. + +## Outputs + +### Self contained, self extracting and runnable shell script + +Requires the Scheme implementation to be installed to run. + +- chibi-scheme +- csi (Chicken) +- icyc (Cyclone) +- gsi (Gambit) +- gosh (Gauche) +- guile +- mosh +- sash +- stklos +- skint +- tr7i (tr7) +- ypsilon + +### Static binary executable + +Requires nothing to be installed to run. + +- csc (Chicken) +- racket (Racket) + + +### Java ARchive (JAR) + +Only requires Java to be installed to run. + +- kawa + - The build folder needs to contain kawa.jar + +## How it works + +The scripts searches for .sld files in given paths, compiles them if needed and combines them with +the main script to form something that can be run on it's own. Meaning that the only thing the +person running the things needs, might be, the Scheme implementation. diff --git a/compile-r7rs b/compile-r7rs new file mode 100755 index 0000000..6c91575 --- /dev/null +++ b/compile-r7rs @@ -0,0 +1,209 @@ +#!/bin/sh + +CC=gcc +if [ "" = "${CC}" ] +then + CC=${CC} +fi + +output="a.out" +libdirs="" + +while getopts "D:o:" flag +do + case $flag in + o) output="${OPTARG}";; + D) libdirs="$libdirs ${OPTARG}";; + 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" + +case ${SCC} 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) + paths="-I $tmpdir" + objects="" + for dir in $libdirs + do + paths="$paths -I $tmpdir/${dir#./}" + for lib in $(find "$dir" -name "*.sld") + do + echo "Compiling $lib" + csc -X r7rs -R r7rs -c -J -unit ${lib%.sld} "$lib" + objects="$objects ${lib%.sld}.o" + done + done + csc -X r7rs -R r7rs -static $objects -o $output $main + 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#./}" + for lib in $(find "$dir" -name "*.sld") + do + libs="$libs $lib" + done + 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 -s" + ;; + kawa) + jar xf kawa.jar + paths="" + for dir in $libdirs + do + paths="$paths $dir" + for lib in $(find "$dir" -name "*.sld") + do + kawa -C $lib + done + 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" + ;; + 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 SCC (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 $libdirs | grep -v "exit 0" + echo "} > /dev/null" + echo 'cd ${CURDIR}' + echo "$command" +} > "$output" + +chmod +x "$output" +echo "Command: $command" + + diff --git a/configure b/configure new file mode 100644 index 0000000..aeafbb2 --- /dev/null +++ b/configure @@ -0,0 +1 @@ +echo "No need to configure, just run make" diff --git a/test/kawa.jar b/test/kawa.jar new file mode 100644 index 0000000..31e7afc Binary files /dev/null and b/test/kawa.jar differ diff --git a/test/libs/hello.scm b/test/libs/hello.scm new file mode 100644 index 0000000..ed11862 --- /dev/null +++ b/test/libs/hello.scm @@ -0,0 +1 @@ +(define hello "Hello") diff --git a/test/libs/hello.sld b/test/libs/hello.sld new file mode 100644 index 0000000..320e49d --- /dev/null +++ b/test/libs/hello.sld @@ -0,0 +1,6 @@ +(define-library + (libs hello) + (import (scheme base) + (scheme write)) + (export hello) + (include "hello.scm")) diff --git a/test/libs2/world.scm b/test/libs2/world.scm new file mode 100644 index 0000000..07b2e31 --- /dev/null +++ b/test/libs2/world.scm @@ -0,0 +1 @@ +(define world "world.") diff --git a/test/libs2/world.sld b/test/libs2/world.sld new file mode 100644 index 0000000..6a6e218 --- /dev/null +++ b/test/libs2/world.sld @@ -0,0 +1,6 @@ +(define-library + (libs2 world) + (import (scheme base) + (scheme write)) + (export world) + (include "world.scm")) diff --git a/test/main.scm b/test/main.scm new file mode 100644 index 0000000..475928d --- /dev/null +++ b/test/main.scm @@ -0,0 +1,12 @@ +(import (scheme base) + (scheme write) + (libs hello) + (libs2 world)) + + +(display hello) +(display " ") +(display world) +(newline) + +(exit 0)