;;;; -*- Scheme -*- (define version "0.2.0") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; The logic for determining compiler flags is pretty messy, to make ;;; the install process painless for most users. (define (print-help-and-exit!) (print " Error: could not automatically determine SDL2 flags. Try setting the SDL2_CFLAGS, SDL2_LDFLAGS, SDL2_TTF_CFAGS, and/or SDL2_TTF_LDFLAGS environment variables to specify what compiler and linker flags to use. Example: export SDL2_CFLAGS=\"-I/usr/local/include/SDL2\" export SDL2_LDFLAGS=\"-L/usr/local/lib -lSDL2\" export SDL2_TTF_LDFLAGS=\"-lSDL2_ttf\" chicken-install sdl2-ttf") (exit 1)) (define (try-command command) (receive (out in pid err) (process* command) (receive (_ normal-exit? status) (process-wait pid) (and normal-exit? (zero? status) (string-trim (string-join (with-input-from-port out read-lines) " ")))))) (define (has-mac-framework? name) (any (lambda (dir) (file-exists? (sprintf "~A/~A.framework" dir name))) '("/Library/Frameworks" "/System/Library/Frameworks"))) (define (token-prefixer prefix) (lambda (str) (map (cut string-append prefix <>) (string-split str)))) (define (get-flags #!key prefixer env-var command mac-framework default) (prefixer (or ;; If the env var is set, it takes highest precedence. (get-environment-variable env-var) ;; Othewise, try running the command. (and command (try-command command)) ;; If that didn't work, see if the Mac framework is available. (cond ((not (eq? 'macosx (software-version))) #f) ((or (not mac-framework) (string-null? mac-framework)) "") ((has-mac-framework? mac-framework) (string-append "-framework " mac-framework)) (else #f)) ;; Otherwise use the default, if there is one. default ;; Otherwise, abort. (print-help-and-exit!)))) (define sdl2-flags-list (append (get-flags prefixer: (token-prefixer "-C ") env-var: "SDL2_CFLAGS" command: "sdl2-config --cflags") (get-flags prefixer: (token-prefixer "-L ") env-var: "SDL2_LDFLAGS" command: "sdl2-config --libs" mac-framework: "SDL2") (get-flags prefixer: (token-prefixer "-C ") env-var: "SDL2_TTF_CFLAGS" default: "") (get-flags prefixer: (token-prefixer "-L ") env-var: "SDL2_TTF_LDFLAGS" mac-framework: "SDL2_ttf" default: "-lSDL2_ttf"))) ;;; If compiling with a Mac framework, register this feature during ;;; compilation so that the correct "#include" statement will be used. (when (and (eq? 'macosx (software-version)) (any (cut irregex-search "-framework\\b" <>) sdl2-flags-list)) (set! sdl2-flags-list (cons "-feature sdl2-ttf-use-mac-framework" sdl2-flags-list))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (compile -J -s -O3 -d1 ,@sdl2-flags-list -emit-type-file "sdl2-ttf.types" "sdl2-ttf.scm") (compile -v -s -O3 -d0 "sdl2-ttf.import.scm") (install-extension 'sdl2-ttf '("sdl2-ttf.so" "sdl2-ttf.import.so" "sdl2-ttf.types") `((version ,version)))