;;; postgresql.setup -*- Scheme -*- (use files) (define libpq-flags `(-C -I -C "\"`pg_config --includedir`\"" -L -L -L "\"`pg_config --libdir`\"" -rpath "\"`pg_config --libdir`\"" -lpq)) (define PQescapeIdentifier-presence-checker #< int main(void) { PGconn *conn = NULL; /* Bork */ return PQescapeIdentifier(conn, "test", 4) != NULL; } EOF ) (define PQconnectdbParams-presence-checker #< int main(void) { const char *kw[] = {"a", NULL}; const char *val[] = {"b", NULL}; return PQconnectdbParams(kw, val, 0) != NULL; } EOF ) (define feature-checks `((has-PQescapeIdentifier . ,PQescapeIdentifier-presence-checker) (has-PQconnectdbParams . ,PQconnectdbParams-presence-checker))) (define-syntax try-compile-pgsql-prog (syntax-rules () ((_ str) (begin (with-output-to-file "attempt.c" (lambda () (display str) (newline))) (let ((result (handle-exceptions ex #f (compile "attempt.c" ,@libpq-flags)))) (delete-file* "attempt.c") (delete-file* "attempt.o") (delete-file* "attempt") result))))) (define (check-features) (fold (lambda (feature/test features) (if (try-compile-pgsql-prog (cdr feature/test)) (append! `(-feature ,(car feature/test)) features) features)) '() feature-checks)) (compile -s -O2 -d0 postgresql.scm -j postgresql ,@(check-features) ,@libpq-flags) (compile postgresql.import.scm -s -O2 -d0) (install-extension 'postgresql '("postgresql.so" "postgresql.import.so") '((version "3.7") (documentation "postgresql.html")))