Building a Binary with Chicken Scheme

So that was fucking fun. Seems Chicken's docs aren't correct on how to build with modules, because those were added after the dark-ages R5RS it was modelled on. Finally got this working:

src/somelib.scm:

(declare (unit somelib))
(module somelib
    (hello)

(import chicken scheme)

(define (hello) (display "Hello!\n"))
)

src/somemain.scm:

(import chicken scheme)

(cond-expand
    (compiling (declare (uses somelib)))
    (else (load "somelib.scm")))
(import somelib)

(hello)

Don't you just love that muffin-man-muffin-man repetitious bullshit? declare is for the compiler, load is for the interpreter, then import for both. You import builtins like chicken, but use libraries (aforementioned sdl) without an import. Bizarre and contradictory.

build.zsh:

#!/bin/zsh
EXE=something
# LIBS is space-delimited, must not include main script
LIBS="somelib.scm"
MAIN=somemain.scm

cd src
for SF in ${=LIBS}; do
    SNAME=`basename $SF .scm`
    if [[ "$SNAME" == "main" ]]; then
        continue
    fi
    csc -c -j $SNAME $SF -o $SNAME.o || exit 1
done
csc -c $MAIN -o `basename $MAIN .scm`.o || exit 1
csc *.o -o ../$EXE || exit 1
rm *.o *.import.scm
cd ..

echo "Built $EXE"
% ./build.zsh
Built something
% ./something
Hello!

Hello, working native binary! There's a bunch more stuff about making a deployable app, but I'll take this for now. My actual program can show a blank green graphics window!