Ticket #1728: 0001-Convert-build-script-to-Scheme-for-Windows-support.patch

File 0001-Convert-build-script-to-Scheme-for-Windows-support.patch, 5.2 KB (added by Vasilij Schneidermann, 6 months ago)
  • postgresql/4.1.3/build-postgresql

    From 457d3c717f496a6254d72d745f7e87cdb6299dae Mon Sep 17 00:00:00 2001
    From: Vasilij Schneidermann <mail@vasilij.de>
    Date: Sun, 16 May 2021 10:45:26 +0200
    Subject: [PATCH] Convert build script to Scheme for Windows support
    
    ---
     postgresql/4.1.3/build-postgresql     | 23 +------
     postgresql/4.1.3/build-postgresql.bat |  2 +
     postgresql/4.1.3/build-postgresql.scm | 88 +++++++++++++++++++++++++++
     3 files changed, 91 insertions(+), 22 deletions(-)
     mode change 100644 => 100755 postgresql/4.1.3/build-postgresql
     create mode 100644 postgresql/4.1.3/build-postgresql.bat
     create mode 100644 postgresql/4.1.3/build-postgresql.scm
    
    diff --git a/postgresql/4.1.3/build-postgresql b/postgresql/4.1.3/build-postgresql
    old mode 100644
    new mode 100755
    index ac1cf28..f6dd550
    a b  
    11#!/bin/sh
    2 
    3 # Determine if pkg-config exists and knows about libpq, otherwise
    4 # fall back on pg_config to determine compiler and linker flags.
    5 if pkg-config --exists libpq >/dev/null 2>/dev/null; then
    6    CFLAGS="`pkg-config --cflags libpq`"
    7    LDFLAGS="`pkg-config --libs libpq`"
    8 else
    9    CFLAGS="-I`pg_config --includedir`"
    10    LDFLAGS="-L`pg_config --libdir` -Wl,-rpath `pg_config --libdir` -lpq"
    11 fi
    12 
    13 known_features="escape-identifier connectdb-params diag-query-position diag-schema-info"
    14 
    15 feature_flags=""
    16 for feature in $known_features; do
    17     if "$CHICKEN_CSC" -C "$CFLAGS" -L "$LDFLAGS" "feature-tests/$feature.c" >/dev/null 2>/dev/null; then
    18         feature_flags="$feature_flags -Dhas-$feature"
    19     fi
    20     rm -f feature-tests/$feature.o feature-tests/$feature
    21 done
    22 
    23 "$CHICKEN_CSC" $feature_flags -C "$CFLAGS" -L "$LDFLAGS" "$@"
     2"$CHICKEN_CSI" -s build-postgresql.scm "$@"
  • new file postgresql/4.1.3/build-postgresql.bat

    diff --git a/postgresql/4.1.3/build-postgresql.bat b/postgresql/4.1.3/build-postgresql.bat
    new file mode 100644
    index 0000000..4f26db1
    - +  
     1@echo off
     2"%CHICKEN_CSI%" -s build-postgresql.scm %*
  • new file postgresql/4.1.3/build-postgresql.scm

    diff --git a/postgresql/4.1.3/build-postgresql.scm b/postgresql/4.1.3/build-postgresql.scm
    new file mode 100644
    index 0000000..dcc25cb
    - +  
     1(import scheme)
     2(import (chicken base))
     3(import (chicken file))
     4(import (chicken io))
     5(import (chicken format))
     6(import (chicken pathname))
     7(import (chicken platform))
     8(import (chicken process))
     9(import (chicken process-context))
     10(import (chicken string))
     11
     12(define blackhole-device
     13  (cond-expand
     14   ((or unix cygwin) ">/dev/null 2>/dev/null")
     15   (windows ">NUL 2>NUL")))
     16
     17(define object-extension
     18  (cond-expand
     19   (unix "o")
     20   (windows "obj")))
     21
     22(define executable-extension
     23  (cond-expand
     24   (unix "")
     25   (windows "exe")))
     26
     27;; adapted from egg-compile.scm
     28(define (system+ str)
     29  (system (if (and (eq? (software-type) 'windows)
     30                   (not (eq? (software-version) 'cygwin))
     31                   (positive? (string-length str))
     32                   (char=? #\" (string-ref str 0)))
     33              (string-append "\"" str "\"")
     34              str)))
     35
     36(define cflags #f)
     37(define ldflags #f)
     38
     39(define (capture command)
     40  (string-chomp
     41   (with-input-from-pipe command (cut read-string #f))))
     42
     43;; Determine if pkg-config exists and knows about libpq
     44(cond
     45 ((and (get-environment-variable "PG_CFLAGS")
     46       (get-environment-variable "PG_LDFLAGS"))
     47  (set! cflags (get-environment-variable "PG_CFLAGS"))
     48  (set! ldflags (get-environment-variable "PG_LDFLAGS")))
     49 ((zero? (system+ (format "pkg-config --exists libpq ~a" blackhole-device)))
     50  (set! cflags (capture "pkg-config --cflags libpq"))
     51  (set! ldflags (capture "pkg-config --libs libpq")))
     52 ((zero? (system+ (format "pg_config --version ~a" blackhole-device)))
     53  (set! cflags (format "-I~a" (capture "pg_config --includedir")))
     54  (set! ldflags (format "-L~a -Wl,-rpath ~a -lpq"
     55                        (capture "pg_config --libdir")
     56                        (capture "pg_config --libdir"))))
     57 (else
     58  (print "Please ensure that libpq and its headers are installed. "
     59         "Either install `pkg-config` or `pg_config` to auto-detect "
     60         "flags or set them manually in PG_CFLAGS and PG_LDFLAGS.")
     61  (exit 1)))
     62
     63(define csc (get-environment-variable "CHICKEN_CSC"))
     64(define known-features '("escape-identifier" "connectdb-params"
     65                         "diag-query-position" "diag-schema-info"))
     66(define feature-flags "")
     67
     68(for-each
     69 (lambda (feature)
     70   (when (zero? (system+ (format "~a -C ~a -L ~a ~a ~a"
     71                                 (qs csc) (qs cflags) (qs ldflags)
     72                                 (qs (make-pathname "feature-tests" feature "c"))
     73                                 blackhole-device)))
     74     (set! feature-flags (string-append feature-flags " -Dhas-" feature)))
     75   (delete-file*
     76    (make-pathname "feature-tests" feature object-extension))
     77   (delete-file*
     78    (make-pathname "feature-tests" feature executable-extension)))
     79 known-features)
     80
     81(define cmdline
     82  (format "~a ~a -C ~a -L ~a ~a"
     83          (qs csc) feature-flags (qs cflags) (qs ldflags)
     84          (string-intersperse (map qs (command-line-arguments)) " ")))
     85
     86(let ((status (system+ cmdline)))
     87  (when (not (zero? status))
     88    (error "shell invocation failed with non-zero return status" cmdline status)))