;; -*- Scheme -*- (use files) (define libcrypt-presence-checker #< int main (void) { return crypt("foo", "bar") != NULL; } EOF ) (delete-file* "crypt-features") (define known-hash-types '(blowfish sha512 sha256 md5 des-extended des)) (define *compile-features* '()) ;; OpenBSD and Android are odd: they don't have libcrypt, crypt is part of libc (define uses-libcrypt (cond ((get-environment-variable "FORCE_CRYPT_USE_LIBCRYPT") => (lambda (f) (or (string-ci=? f "true") (string-ci=? f "1") (string-ci=? f "yes")))) (else (cond-expand ((or openbsd android) #f) (else #t))))) (define libcrypt-flags (if uses-libcrypt '(-L -lcrypt) '())) (cond ((get-environment-variable "FORCE_CRYPT_HASHTYPES") => (lambda (f) (let* ((forced-types (with-input-from-string f read-file)) (supported-features (filter (lambda (x) (member x known-hash-types)) forced-types)) (features (map (lambda (h) (string->symbol (conc 'crypt-native- h))) supported-features))) (print "\n==============================================================") (print "Using forced native hash types:") (print features) (print "==============================================================\n") (set! *compile-features* features)))) ((feature? 'cross-chicken) (print "\n================================================================") (print "Looks like you're cross-compiling and didn't force any hash types.") (print "All hashing implementations will be provided by the egg.") (print "This is okay, but if you want full control you can abort the") (print "installation, and run chicken-install again with the ") (print "FORCE_CRYPT_HASHTYPES environment variable set to the natively") (print "supported hash types on the target system. You can choose from:\n") (pp known-hash-types) (print "================================================================\n")) ((try-compile libcrypt-presence-checker cflags: "-D_XOPEN_SOURCE" ldflags: (if uses-libcrypt "-lcrypt" "")) (compile -C -D_XOPEN_SOURCE ,@libcrypt-flags detect-native-crypt-features.scm) (run (./detect-native-crypt-features)) (let ((features (with-input-from-file "crypt-features" read))) ;; Useful for debugging (print "\n================================================================") (print "Detected support for the following hash types in system crypt():") (print features) (print "================================================================\n") (set! *compile-features* features))) (else (print "\n===============================================================") (print "NOTE: Your system appears not to have a native crypt() at all!") (print "All hashing implementations will be provided by the egg.") (newline) (print "HINT: Linker flag (-lcrypt) may be wrong, please check this.") (print "To force -lcrypt (or its omission) you may try setting the") (print "FORCE_CRYPT_USE_LIBCRYPT environment variable to TRUE or FALSE.") (print "If flag detection is wrong, please consider filing a bugreport.") (print "===============================================================\n"))) (let* ((feature-flags (intersperse *compile-features* '-feature)) (flags (if (null? feature-flags) '() `(-feature has-native-crypt -feature ,@feature-flags)))) (compile -s -O2 crypt.scm ,@libcrypt-flags -C -D_XOPEN_SOURCE ,@flags -j crypt)) (compile -s -O2 crypt.import.scm) (install-extension 'crypt '("crypt.so" "crypt.import.so") `((version 0.4.3)))