(import scheme) (import (chicken base)) (import (chicken file)) (import (chicken format)) (import (chicken io)) (import (chicken process)) (import (chicken process-context)) (import (chicken string)) (define (library-flags var command) (or (get-environment-variable var) (let ((exit (system (string-append command " > /dev/null")))) (if (zero? exit) (let ((output (with-input-from-pipe command (cut read-string #f)))) (when (eof-object? output) (error (format "Command didn't produce any output: ~a" command))) (string-chomp output)) (error (format "Command failed with exit code ~s, set $~a" exit var)))))) (define csc (get-environment-variable "CHICKEN_CSC")) (define stfl-cflags (library-flags "STFL_CFLAGS" "(pkg-config --cflags stfl || echo '')")) (define stfl-ldlibs (library-flags "STFL_LDLIBS" "(pkg-config --libs stfl || echo '-lstfl')")) (define args (list csc stfl-cflags stfl-ldlibs)) (define cmdline (string-append (apply format "~a -C ~a -L ~a " (map qs args)) (string-intersperse (map qs (command-line-arguments)) " "))) (print cmdline) (system* cmdline)