(use files srfi-1 make shell) (define cross-compiling (feature? 'cross-chicken)) (define build-for-host (or (not cross-compiling) (host-extension))) (define (require-envvar var) (let ((val (get-environment-variable var))) (or val (with-output-to-port (current-error-port) (lambda () (printf "\n\n=== Please, set the ~a environment variable. ===\n\n" var))) (exit 1)))) (define java-path (require-envvar "JAVA_HOME")) (define (choose-libjvm-path . jvm-paths) (let ((candidates (map (lambda (jvm-path) (make-pathname java-path jvm-path)) jvm-paths))) (or (find file-exists? candidates) (error 'jni "could not find libjvm" candidates)))) (define libjvm-path (if (or (and (feature? 'cross-chicken) (host-extension)) (not (host-extension))) (cond-expand (x86-64 (choose-libjvm-path "/jre/lib/amd64/server/" "/jre/lib/x64/server/" "/jre/lib/amd64/client/" "/jre/lib/x64/client/")) (x86 (choose-libjvm-path "/jre/lib/i386/server/" "/jre/lib/i386/client/"))))) (define-syntax compile/for-host (ir-macro-transformer (lambda (x i c) `(compile ,',(string-append "-L" libjvm-path) -ljvm ,',(string-append "-I" (make-pathname java-path "/include")) ,',(string-append "-I" (make-pathname java-path "/include/linux")) . ,(cdr x))))) (make (("jni-utils.jar" ("java/misc-utils/build.xml" "java/misc-utils/src/com/chicken_mobile/jni/ExceptionHelper.java" "java/misc-utils/src/com/chicken_mobile/jni/ReflectionHelper.java") (run (ant -f "java/misc-utils/build.xml" clean)) (run (ant -f "java/misc-utils/build.xml")) (file-copy "java/misc-utils/misc-utils.jar" "jni-utils.jar" #t))) '("jni-utils.jar")) ;;;XXX temporary fix for stale binaries in target variant when doing cross-build (when (feature? 'cross-chicken) (for-each delete-file (glob "*.so"))) (let-syntax ((compile* (syntax-rules () ((_ args ...) (if build-for-host (compile/for-host -s args ...) (compile -s -Dandroid args ...)))))) (make (("jni-lolevel.so" ("jni-lolevel.scm" "jvalue-tools.c" "jni-utils.jar" "jni-primitives.scm" "jni-jlambda.scm" "jni-reflection.scm") (compile* jni-lolevel.scm -J) (compile* jni-lolevel.import.scm)) ("jni.so" ("jni.scm" "jni-lolevel.so") (compile* jni.scm -J) (compile* jni.import.scm))) '("jni-lolevel.so" "jni.so"))) (install-extension 'jni '("jni-lolevel.so" "jni-lolevel.import.so" "jni.import.so" "jni.so" "jni-utils.jar") '((version "0.1")))