diff --git a/.github/workflows/haskell-ci.yml b/.github/workflows/haskell-ci.yml new file mode 100644 index 0000000..705288a --- /dev/null +++ b/.github/workflows/haskell-ci.yml @@ -0,0 +1,277 @@ +# This GitHub workflow config has been generated by a script via +# +# haskell-ci 'github' 'cabal.project' +# +# To regenerate the script (for example after adjusting tested-with) run +# +# haskell-ci regenerate +# +# For more information, see https://github.com/haskell-CI/haskell-ci +# +# version: 0.19.20250605 +# +# REGENDATA ("0.19.20250605",["github","cabal.project"]) +# +name: Haskell-CI +on: + push: + branches: + - master + pull_request: + branches: + - master +jobs: + linux: + name: Haskell-CI - Linux - ${{ matrix.compiler }} + runs-on: ubuntu-24.04 + timeout-minutes: + 60 + container: + image: buildpack-deps:jammy + services: + postgres: + image: postgres:14 + env: + POSTGRES_PASSWORD: postgres + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + continue-on-error: ${{ matrix.allow-failure }} + strategy: + matrix: + include: + - compiler: ghc-9.12.1 + compilerKind: ghc + compilerVersion: 9.12.1 + setup-method: ghcup + allow-failure: false + - compiler: ghc-9.10.1 + compilerKind: ghc + compilerVersion: 9.10.1 + setup-method: ghcup + allow-failure: false + - compiler: ghc-9.8.4 + compilerKind: ghc + compilerVersion: 9.8.4 + setup-method: ghcup + allow-failure: false + - compiler: ghc-9.6.6 + compilerKind: ghc + compilerVersion: 9.6.6 + setup-method: ghcup + allow-failure: false + - compiler: ghc-9.4.8 + compilerKind: ghc + compilerVersion: 9.4.8 + setup-method: ghcup + allow-failure: false + - compiler: ghc-9.2.8 + compilerKind: ghc + compilerVersion: 9.2.8 + setup-method: ghcup + allow-failure: false + - compiler: ghc-9.0.2 + compilerKind: ghc + compilerVersion: 9.0.2 + setup-method: ghcup + allow-failure: false + - compiler: ghc-8.10.7 + compilerKind: ghc + compilerVersion: 8.10.7 + setup-method: ghcup + allow-failure: false + - compiler: ghc-8.8.4 + compilerKind: ghc + compilerVersion: 8.8.4 + setup-method: ghcup + allow-failure: false + - compiler: ghc-8.6.5 + compilerKind: ghc + compilerVersion: 8.6.5 + setup-method: ghcup + allow-failure: false + fail-fast: false + steps: + - name: apt-get install + run: | + apt-get update + apt-get install -y --no-install-recommends gnupg ca-certificates dirmngr curl git software-properties-common libtinfo5 + apt-get install -y libpq-dev + - name: Install GHCup + run: | + mkdir -p "$HOME/.ghcup/bin" + curl -sL https://downloads.haskell.org/ghcup/0.1.50.1/x86_64-linux-ghcup-0.1.50.1 > "$HOME/.ghcup/bin/ghcup" + chmod a+x "$HOME/.ghcup/bin/ghcup" + - name: Install cabal-install + run: | + "$HOME/.ghcup/bin/ghcup" install cabal 3.14.2.0 || (cat "$HOME"/.ghcup/logs/*.* && false) + echo "CABAL=$HOME/.ghcup/bin/cabal-3.14.2.0 -vnormal+nowrap" >> "$GITHUB_ENV" + - name: Install GHC (GHCup) + if: matrix.setup-method == 'ghcup' + run: | + "$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false) + HC=$("$HOME/.ghcup/bin/ghcup" whereis ghc "$HCVER") + HCPKG=$(echo "$HC" | sed 's#ghc$#ghc-pkg#') + HADDOCK=$(echo "$HC" | sed 's#ghc$#haddock#') + echo "HC=$HC" >> "$GITHUB_ENV" + echo "HCPKG=$HCPKG" >> "$GITHUB_ENV" + echo "HADDOCK=$HADDOCK" >> "$GITHUB_ENV" + env: + HCKIND: ${{ matrix.compilerKind }} + HCNAME: ${{ matrix.compiler }} + HCVER: ${{ matrix.compilerVersion }} + - name: Set PATH and environment variables + run: | + echo "$HOME/.cabal/bin" >> $GITHUB_PATH + echo "LANG=C.UTF-8" >> "$GITHUB_ENV" + echo "CABAL_DIR=$HOME/.cabal" >> "$GITHUB_ENV" + echo "CABAL_CONFIG=$HOME/.cabal/config" >> "$GITHUB_ENV" + HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\d+)\.(\d+)\.(\d+)(\.(\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))') + echo "HCNUMVER=$HCNUMVER" >> "$GITHUB_ENV" + echo "ARG_TESTS=--enable-tests" >> "$GITHUB_ENV" + echo "ARG_BENCH=--enable-benchmarks" >> "$GITHUB_ENV" + echo "HEADHACKAGE=false" >> "$GITHUB_ENV" + echo "ARG_COMPILER=--$HCKIND --with-compiler=$HC" >> "$GITHUB_ENV" + env: + HCKIND: ${{ matrix.compilerKind }} + HCNAME: ${{ matrix.compiler }} + HCVER: ${{ matrix.compilerVersion }} + - name: env + run: | + env + - name: write cabal config + run: | + mkdir -p $CABAL_DIR + cat >> $CABAL_CONFIG <> $CABAL_CONFIG < cabal-plan.xz + echo 'f62ccb2971567a5f638f2005ad3173dba14693a45154c1508645c52289714cb2 cabal-plan.xz' | sha256sum -c - + xz -d < cabal-plan.xz > $HOME/.cabal/bin/cabal-plan + rm -f cabal-plan.xz + chmod a+x $HOME/.cabal/bin/cabal-plan + cabal-plan --version + - name: checkout + uses: actions/checkout@v4 + with: + path: source + - name: initial cabal.project for sdist + run: | + touch cabal.project + echo "packages: $GITHUB_WORKSPACE/source/." >> cabal.project + echo "packages: $GITHUB_WORKSPACE/source/postgresql-libpq-pkgconfig" >> cabal.project + echo "packages: $GITHUB_WORKSPACE/source/postgresql-libpq-configure" >> cabal.project + cat cabal.project + - name: sdist + run: | + mkdir -p sdist + $CABAL sdist all --output-dir $GITHUB_WORKSPACE/sdist + - name: unpack + run: | + mkdir -p unpacked + find sdist -maxdepth 1 -type f -name '*.tar.gz' -exec tar -C $GITHUB_WORKSPACE/unpacked -xzvf {} \; + - name: generate cabal.project + run: | + PKGDIR_postgresql_libpq="$(find "$GITHUB_WORKSPACE/unpacked" -maxdepth 1 -type d -regex '.*/postgresql-libpq-[0-9.]*')" + echo "PKGDIR_postgresql_libpq=${PKGDIR_postgresql_libpq}" >> "$GITHUB_ENV" + PKGDIR_postgresql_libpq_pkgconfig="$(find "$GITHUB_WORKSPACE/unpacked" -maxdepth 1 -type d -regex '.*/postgresql-libpq-pkgconfig-[0-9.]*')" + echo "PKGDIR_postgresql_libpq_pkgconfig=${PKGDIR_postgresql_libpq_pkgconfig}" >> "$GITHUB_ENV" + PKGDIR_postgresql_libpq_configure="$(find "$GITHUB_WORKSPACE/unpacked" -maxdepth 1 -type d -regex '.*/postgresql-libpq-configure-[0-9.]*')" + echo "PKGDIR_postgresql_libpq_configure=${PKGDIR_postgresql_libpq_configure}" >> "$GITHUB_ENV" + rm -f cabal.project cabal.project.local + touch cabal.project + touch cabal.project.local + echo "packages: ${PKGDIR_postgresql_libpq}" >> cabal.project + echo "packages: ${PKGDIR_postgresql_libpq_pkgconfig}" >> cabal.project + echo "packages: ${PKGDIR_postgresql_libpq_configure}" >> cabal.project + echo "package postgresql-libpq" >> cabal.project + echo " ghc-options: -Werror=missing-methods" >> cabal.project + echo "package postgresql-libpq-pkgconfig" >> cabal.project + echo " ghc-options: -Werror=missing-methods" >> cabal.project + echo "package postgresql-libpq-configure" >> cabal.project + echo " ghc-options: -Werror=missing-methods" >> cabal.project + cat >> cabal.project <> cabal.project.local + cat cabal.project + cat cabal.project.local + - name: dump install plan + run: | + $CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH --dry-run all + cabal-plan + - name: restore cache + uses: actions/cache/restore@v4 + with: + key: ${{ runner.os }}-${{ matrix.compiler }}-${{ github.sha }} + path: ~/.cabal/store + restore-keys: ${{ runner.os }}-${{ matrix.compiler }}- + - name: install dependencies + run: | + $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --dependencies-only -j2 all + $CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH --dependencies-only -j2 all + - name: build w/o tests + run: | + $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks all + - name: build + run: | + $CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH all --write-ghc-environment-files=always + - name: tests + run: | + $CABAL v2-test $ARG_COMPILER $ARG_TESTS $ARG_BENCH all --test-show-details=direct + - name: cabal check + run: | + cd ${PKGDIR_postgresql_libpq} || false + ${CABAL} -vnormal check + cd ${PKGDIR_postgresql_libpq_pkgconfig} || false + ${CABAL} -vnormal check + cd ${PKGDIR_postgresql_libpq_configure} || false + ${CABAL} -vnormal check + - name: haddock + run: | + $CABAL v2-haddock --disable-documentation --haddock-all $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all + - name: unconstrained build + run: | + rm -f cabal.project.local + $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks all + - name: prepare for constraint sets + run: | + rm -f cabal.project.local + - name: constraint set pkg-config + run: | + $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --constraint='postgresql-libpq +use-pkg-config' all --dry-run + cabal-plan topo | sort + $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --constraint='postgresql-libpq +use-pkg-config' --dependencies-only -j2 all + $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --constraint='postgresql-libpq +use-pkg-config' all + - name: save cache + if: always() + uses: actions/cache/save@v4 + with: + key: ${{ runner.os }}-${{ matrix.compiler }}-${{ github.sha }} + path: ~/.cabal/store diff --git a/.github/workflows/simple.yml b/.github/workflows/simple.yml new file mode 100644 index 0000000..99a2438 --- /dev/null +++ b/.github/workflows/simple.yml @@ -0,0 +1,74 @@ +name: Simple +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + native: + name: "Simple: GHC ${{ matrix.ghc }} on ${{ matrix.os }}" + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-latest, windows-latest] + # Older GHCs need LLVM on macos-latest (ARM) + ghc: ['9.2','9.4.8','9.6.6','9.8.2','9.10.1'] + fail-fast: false + timeout-minutes: + 60 + steps: + - name: Set git to use LF + run: | + git config --global core.autocrlf false + git config --global core.eol lf + + - name: Set up Haskell + id: setup-haskell + uses: haskell-actions/setup@v2 + with: + ghc-version: ${{ matrix.ghc }} + cabal-version: '3.10.2.0' + + - name: Set up PostgreSQL + uses: ikalnytskyi/action-setup-postgres@v6 + id: postgres + with: + username: ci + password: sw0rdfish + database: test + postgres-version: "14" + + - name: Checkout + uses: actions/checkout@v4 + + - name: Cache + uses: actions/cache@v4 + with: + path: ${{ steps.setup-haskell.outputs.cabal-store }} + key: ${{ runner.os }}-${{ matrix.ghc }}-${{ github.sha }} + restore-keys: ${{ runner.os }}-${{ matrix.ghc }}- + + - name: cabal.project (win) + if: matrix.os == 'windows-latest' + run: cp cabal.project.win cabal.project + + - name: cabal.project (macos) + if: matrix.os == 'macos-latest' + run: cp cabal.project.macos cabal.project + + - name: ghc-pkg dump + run: ghc-pkg list + + - name: Dependencies + run: cabal build all --enable-tests --only-dependencies + + - name: Build + run: cabal build all --enable-tests + + - name: Test + run: cabal test all --enable-tests --test-show-details=direct + env: + DATABASE_CONNSTRING: ${{ steps.postgres.outputs.connection-uri }} diff --git a/.gitignore b/.gitignore index 1bd7da3..f485534 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ Database/PQ.hs dist .cabal-sandbox/ cabal.sandbox.config +dist-newstyle/ +.ghc.environment.* diff --git a/.stylish-haskell.yaml b/.stylish-haskell.yaml new file mode 100644 index 0000000..c3abe21 --- /dev/null +++ b/.stylish-haskell.yaml @@ -0,0 +1,18 @@ +steps: + - imports: + align: group + list_align: after_alias + long_list_align: new_line + empty_list_align: right_after + list_padding: module_name + - language_pragmas: + style: vertical + remove_redundant: true + - trailing_whitespace: {} +columns: 160 +language_extensions: + - DataKinds + - EmptyCase + - ExplicitForAll + - FlexibleContexts + - MultiParamTypeClasses diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..6f27f1e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,55 @@ +0.11 +---- + +- Add pipeline mode API + https://www.postgresql.org/docs/current/libpq-pipeline-mode.html + + There are new values in `ExecStatus`, therefore the major version release. + + +0.10.2.0 +-------- + +- Split the c library dependency into separate packages. + Now the dependencies are either all `build-type: Simple` (`-f +use-pkg-config`) + or `build-type: Configure` (`-f -use-pkg-config`). + +0.10.1.0 +-------- + +- Fix issue with empty binary values (https://github.com/haskellari/postgresql-libpq/issues/54) + +0.10.0.0 +-------- + +There are technicallly two breaking changes in this release, +but they shouldn't affect anyone not doing anything weird. + +- Binary parameters are passed without copying. +- FFI functions are imported without `unsafe`. Most uses were incorrect. + We make all calls "safe", as checking whether libpq functions do IO + or may call a notifier (potentially calling back into Haskell), + is virtually impossible for all versions of libpq. + (The above properties are not specified in the documentation). + +0.9.5.0 +------- + +- Drop support for GHCs prior 8.6 +- Require libpq >=10.22 (when using pkgconfig). +- Use CApiFFI for some parts of the API + (we cannot use for all due https://gitlab.haskell.org/ghc/ghc/-/issues/22043) + +0.9.4.3 +------- + +- Support `bytestring-0.11` +- Allow `Win32-2.10.0.0` +- Make `PQconsumeInput` FFI call `safe` + +0.9.4.2 +------- + +- Support GHC-8.6.1 +- Add simple smoke test + diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..e4ac86c --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,13 @@ +Patches welcome! + +- If you are only going to bump bounds: + - If it's really **only bounds**, please simply open an issue (so you'll have a URL to refer to). I have a semi-automated process to make revisions, pull requests only disturb it. + - If patch includes **source code change** (i.e. I'll need to make a release), and it's a patch to support **newer base/GHC version**: + - Amend `tested-with` to include that GHC + - Regenerate `.github/workflows/haskell-ci.yml` with `haskell-ci regenerate` (get the latest from [GitHub haskell-ci/haskell-ci](https://github.com/haskell-ci/haskell-ci)) + +- Don't edit `CHANGELOG.md`, rather include a copyable entry in your pull request description. I often process pull requests in bulk, and everyone editing the `CHANGELOG.md` causes unnecessary conflicts. +- For the same reason, do not edit `version` or `x-revision` + +- I use [`stylish-haskell`](https://github.com/jaspervdj/stylish-haskell) to format imports. I encourage you to use it too, when contributing. +- General code style is 4 spaces, just look around how it looks, it's not so strict. diff --git a/README.md b/README.md index 7b7f04f..4e806ee 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,4 @@ Haskell libpq binding This is a Haskell binding to libpq: the C application programmer's interface to PostgreSQL. libpq is a set of library functions that allow client programs to pass queries to the PostgreSQL backend server -and to receive the results of these queries. \ No newline at end of file +and to receive the results of these queries. diff --git a/Setup.hs b/Setup.hs deleted file mode 100755 index 5f21407..0000000 --- a/Setup.hs +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env runhaskell - -import Distribution.Simple -import Distribution.PackageDescription -import Distribution.Version - -import Distribution.Simple.LocalBuildInfo -import Distribution.Simple.Program -import Distribution.Verbosity - -import Data.Char (isSpace) -import Data.List (dropWhile,reverse) - -main = defaultMainWithHooks simpleUserHooks { - confHook = \pkg flags -> do - lbi <- confHook simpleUserHooks pkg flags - bi <- psqlBuildInfo lbi - - return lbi { - localPkgDescr = updatePackageDescription - (Just bi, [("runtests", bi)]) (localPkgDescr lbi) - } -} - -psqlBuildInfo :: LocalBuildInfo -> IO BuildInfo -psqlBuildInfo lbi = do - (pgconfigProg, _) <- requireProgram verbosity - (simpleProgram "pg_config") (withPrograms lbi) - let pgconfig = rawSystemProgramStdout verbosity pgconfigProg - - incDir <- pgconfig ["--includedir"] - libDir <- pgconfig ["--libdir"] - - return emptyBuildInfo { - extraLibDirs = [strip libDir], - includeDirs = [strip incDir] - } - where - verbosity = normal -- honestly, this is a hack - strip x = dropWhile isSpace $ reverse $ dropWhile isSpace $ reverse x diff --git a/cabal.haskell-ci b/cabal.haskell-ci new file mode 100644 index 0000000..b0abf40 --- /dev/null +++ b/cabal.haskell-ci @@ -0,0 +1,6 @@ +branches: master +postgresql: True +apt: libpq-dev + +constraint-set pkg-config + constraints: postgresql-libpq +use-pkg-config diff --git a/cabal.project b/cabal.project new file mode 100644 index 0000000..1831c58 --- /dev/null +++ b/cabal.project @@ -0,0 +1,3 @@ +packages: . +packages: postgresql-libpq-pkgconfig +packages: postgresql-libpq-configure diff --git a/cabal.project.macos b/cabal.project.macos new file mode 100644 index 0000000..d541351 --- /dev/null +++ b/cabal.project.macos @@ -0,0 +1,7 @@ +packages: . +packages: postgresql-libpq-configure + +constraints: unix installed + +package postgresql-libpq + flags: -use-pkg-config diff --git a/cabal.project.win b/cabal.project.win new file mode 100644 index 0000000..de781d3 --- /dev/null +++ b/cabal.project.win @@ -0,0 +1,7 @@ +packages: . +packages: postgresql-libpq-configure + +constraints: Win32 installed + +package postgresql-libpq + flags: -use-pkg-config diff --git a/cbits/hs-libpq.h b/cbits/hs-libpq.h new file mode 100644 index 0000000..115e112 --- /dev/null +++ b/cbits/hs-libpq.h @@ -0,0 +1,26 @@ +#ifndef HS_POSTGRESQL_LIBPQ +#define HS_POSTGRESQL_LIBPQ + +#include +#include +#include +#include + +typedef struct PGnotice{ + struct PGnotice * next; + size_t len; + char str[]; +} PGnotice; + +typedef struct { + PGnotice * first; + PGnotice * last; +} NoticeBuffer; + +void hs_postgresql_libpq_discard_notices(NoticeBuffer* arg, const PGresult* res); +void hs_postgresql_libpq_store_notices(NoticeBuffer* arg, const PGresult* res); +PGnotice * hs_postgresql_libpq_get_notice(NoticeBuffer* arg); +NoticeBuffer * hs_postgresql_libpq_malloc_noticebuffer (void); +void hs_postgresql_libpq_free_noticebuffer (NoticeBuffer * arg); + +#endif diff --git a/cbits/noticehandlers.c b/cbits/noticehandlers.c index c1d370a..3d81dec 100644 --- a/cbits/noticehandlers.c +++ b/cbits/noticehandlers.c @@ -1,6 +1,4 @@ -#include "noticehandlers.h" -#include -#include +#include "hs-libpq.h" void hs_postgresql_libpq_discard_notices(NoticeBuffer* arg, const PGresult* res) { @@ -56,4 +54,5 @@ hs_postgresql_libpq_free_noticebuffer (NoticeBuffer * arg) { free(x); x = nx; } + free(arg); } diff --git a/cbits/noticehandlers.h b/cbits/noticehandlers.h deleted file mode 100644 index fa616f1..0000000 --- a/cbits/noticehandlers.h +++ /dev/null @@ -1,12 +0,0 @@ -#include - -typedef struct PGnotice{ - struct PGnotice * next; - size_t len; - char str[]; -} PGnotice; - -typedef struct { - PGnotice * first; - PGnotice * last; -} NoticeBuffer; diff --git a/postgresql-libpq-configure/.gitignore b/postgresql-libpq-configure/.gitignore new file mode 100644 index 0000000..39729ac --- /dev/null +++ b/postgresql-libpq-configure/.gitignore @@ -0,0 +1,5 @@ +postgresql-libpq-configure.buildinfo +config.log +config.status +aclocal.m4 +autom4te.cache/ diff --git a/postgresql-libpq-configure/CHANGELOG.md b/postgresql-libpq-configure/CHANGELOG.md new file mode 100644 index 0000000..f186426 --- /dev/null +++ b/postgresql-libpq-configure/CHANGELOG.md @@ -0,0 +1,14 @@ +0.11 +---- + +* Require libpq >=14.12 + +0.10.0.1 +-------- + +* Fix issues in `configure` script + +0.10 +---- + +* Initial release diff --git a/postgresql-libpq-configure/LICENSE b/postgresql-libpq-configure/LICENSE new file mode 100644 index 0000000..a92de38 --- /dev/null +++ b/postgresql-libpq-configure/LICENSE @@ -0,0 +1,31 @@ +Copyright (c) 2010, Grant Monroe +Copyright (c) 2011, Leon P Smith + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of the authors nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/postgresql-libpq-configure/Setup.hs b/postgresql-libpq-configure/Setup.hs new file mode 100644 index 0000000..2806fef --- /dev/null +++ b/postgresql-libpq-configure/Setup.hs @@ -0,0 +1,6 @@ +module Main (main) where + +import Distribution.Simple (defaultMainWithHooks, autoconfUserHooks) + +main :: IO () +main = defaultMainWithHooks autoconfUserHooks diff --git a/postgresql-libpq-configure/configure b/postgresql-libpq-configure/configure new file mode 100755 index 0000000..fe392c1 --- /dev/null +++ b/postgresql-libpq-configure/configure @@ -0,0 +1,5262 @@ +#! /bin/sh +# Guess values for system-dependent variables and create Makefiles. +# Generated by GNU Autoconf 2.71 for Haskell PostgreSQL bindings 0.10. +# +# Report bugs to . +# +# +# Copyright (C) 1992-1996, 1998-2017, 2020-2021 Free Software Foundation, +# Inc. +# +# +# This configure script is free software; the Free Software Foundation +# gives unlimited permission to copy, distribute and modify it. +## -------------------- ## +## M4sh Initialization. ## +## -------------------- ## + +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +as_nop=: +if test ${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1 +then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else $as_nop + case `(set -o) 2>/dev/null` in #( + *posix*) : + set -o posix ;; #( + *) : + ;; +esac +fi + + + +# Reset variables that may have inherited troublesome values from +# the environment. + +# IFS needs to be set, to space, tab, and newline, in precisely that order. +# (If _AS_PATH_WALK were called with IFS unset, it would have the +# side effect of setting IFS to empty, thus disabling word splitting.) +# Quoting is to prevent editors from complaining about space-tab. +as_nl=' +' +export as_nl +IFS=" "" $as_nl" + +PS1='$ ' +PS2='> ' +PS4='+ ' + +# Ensure predictable behavior from utilities with locale-dependent output. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# We cannot yet rely on "unset" to work, but we need these variables +# to be unset--not just set to an empty or harmless value--now, to +# avoid bugs in old shells (e.g. pre-3.0 UWIN ksh). This construct +# also avoids known problems related to "unset" and subshell syntax +# in other old shells (e.g. bash 2.01 and pdksh 5.2.14). +for as_var in BASH_ENV ENV MAIL MAILPATH CDPATH +do eval test \${$as_var+y} \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done + +# Ensure that fds 0, 1, and 2 are open. +if (exec 3>&0) 2>/dev/null; then :; else exec 0&1) 2>/dev/null; then :; else exec 1>/dev/null; fi +if (exec 3>&2) ; then :; else exec 2>/dev/null; fi + +# The user is always right. +if ${PATH_SEPARATOR+false} :; then + PATH_SEPARATOR=: + (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { + (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || + PATH_SEPARATOR=';' + } +fi + + +# Find who we are. Look in the path if we contain no directory separator. +as_myself= +case $0 in #(( + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + test -r "$as_dir$0" && as_myself=$as_dir$0 && break + done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + printf "%s\n" "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + exit 1 +fi + + +# Use a proper internal environment variable to ensure we don't fall + # into an infinite loop, continuously re-executing ourselves. + if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then + _as_can_reexec=no; export _as_can_reexec; + # We cannot yet assume a decent shell, so we have to provide a +# neutralization value for shells without unset; and this also +# works around shells that cannot unset nonexistent variables. +# Preserve -v and -x to the replacement shell. +BASH_ENV=/dev/null +ENV=/dev/null +(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV +case $- in # (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; +esac +exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} +# Admittedly, this is quite paranoid, since all the known shells bail +# out after a failed `exec'. +printf "%s\n" "$0: could not re-execute with $CONFIG_SHELL" >&2 +exit 255 + fi + # We don't want this to propagate to other subprocesses. + { _as_can_reexec=; unset _as_can_reexec;} +if test "x$CONFIG_SHELL" = x; then + as_bourne_compatible="as_nop=: +if test \${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1 +then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which + # is contrary to our usage. Disable this feature. + alias -g '\${1+\"\$@\"}'='\"\$@\"' + setopt NO_GLOB_SUBST +else \$as_nop + case \`(set -o) 2>/dev/null\` in #( + *posix*) : + set -o posix ;; #( + *) : + ;; +esac +fi +" + as_required="as_fn_return () { (exit \$1); } +as_fn_success () { as_fn_return 0; } +as_fn_failure () { as_fn_return 1; } +as_fn_ret_success () { return 0; } +as_fn_ret_failure () { return 1; } + +exitcode=0 +as_fn_success || { exitcode=1; echo as_fn_success failed.; } +as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } +as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } +as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } +if ( set x; as_fn_ret_success y && test x = \"\$1\" ) +then : + +else \$as_nop + exitcode=1; echo positional parameters were not saved. +fi +test x\$exitcode = x0 || exit 1 +blah=\$(echo \$(echo blah)) +test x\"\$blah\" = xblah || exit 1 +test -x / || exit 1" + as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO + as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO + eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && + test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1 +test \$(( 1 + 1 )) = 2 || exit 1" + if (eval "$as_required") 2>/dev/null +then : + as_have_required=yes +else $as_nop + as_have_required=no +fi + if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null +then : + +else $as_nop + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +as_found=false +for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + as_found=: + case $as_dir in #( + /*) + for as_base in sh bash ksh sh5; do + # Try only shells that exist, to save several forks. + as_shell=$as_dir$as_base + if { test -f "$as_shell" || test -f "$as_shell.exe"; } && + as_run=a "$as_shell" -c "$as_bourne_compatible""$as_required" 2>/dev/null +then : + CONFIG_SHELL=$as_shell as_have_required=yes + if as_run=a "$as_shell" -c "$as_bourne_compatible""$as_suggested" 2>/dev/null +then : + break 2 +fi +fi + done;; + esac + as_found=false +done +IFS=$as_save_IFS +if $as_found +then : + +else $as_nop + if { test -f "$SHELL" || test -f "$SHELL.exe"; } && + as_run=a "$SHELL" -c "$as_bourne_compatible""$as_required" 2>/dev/null +then : + CONFIG_SHELL=$SHELL as_have_required=yes +fi +fi + + + if test "x$CONFIG_SHELL" != x +then : + export CONFIG_SHELL + # We cannot yet assume a decent shell, so we have to provide a +# neutralization value for shells without unset; and this also +# works around shells that cannot unset nonexistent variables. +# Preserve -v and -x to the replacement shell. +BASH_ENV=/dev/null +ENV=/dev/null +(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV +case $- in # (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; +esac +exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} +# Admittedly, this is quite paranoid, since all the known shells bail +# out after a failed `exec'. +printf "%s\n" "$0: could not re-execute with $CONFIG_SHELL" >&2 +exit 255 +fi + + if test x$as_have_required = xno +then : + printf "%s\n" "$0: This script requires a shell more modern than all" + printf "%s\n" "$0: the shells that I found on your system." + if test ${ZSH_VERSION+y} ; then + printf "%s\n" "$0: In particular, zsh $ZSH_VERSION has bugs and should" + printf "%s\n" "$0: be upgraded to zsh 4.3.4 or later." + else + printf "%s\n" "$0: Please tell bug-autoconf@gnu.org and +$0: oleg.grenrus@iki.fi about your system, including any +$0: error possibly output before this message. Then install +$0: a modern shell, or manually run the script under such a +$0: shell if you do have one." + fi + exit 1 +fi +fi +fi +SHELL=${CONFIG_SHELL-/bin/sh} +export SHELL +# Unset more variables known to interfere with behavior of common tools. +CLICOLOR_FORCE= GREP_OPTIONS= +unset CLICOLOR_FORCE GREP_OPTIONS + +## --------------------- ## +## M4sh Shell Functions. ## +## --------------------- ## +# as_fn_unset VAR +# --------------- +# Portably unset VAR. +as_fn_unset () +{ + { eval $1=; unset $1;} +} +as_unset=as_fn_unset + + +# as_fn_set_status STATUS +# ----------------------- +# Set $? to STATUS, without forking. +as_fn_set_status () +{ + return $1 +} # as_fn_set_status + +# as_fn_exit STATUS +# ----------------- +# Exit the shell with STATUS, even in a "trap 0" or "set -e" context. +as_fn_exit () +{ + set +e + as_fn_set_status $1 + exit $1 +} # as_fn_exit +# as_fn_nop +# --------- +# Do nothing but, unlike ":", preserve the value of $?. +as_fn_nop () +{ + return $? +} +as_nop=as_fn_nop + +# as_fn_mkdir_p +# ------------- +# Create "$as_dir" as a directory, including parents if necessary. +as_fn_mkdir_p () +{ + + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || eval $as_mkdir_p || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`printf "%s\n" "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +printf "%s\n" X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" + + +} # as_fn_mkdir_p + +# as_fn_executable_p FILE +# ----------------------- +# Test if FILE is an executable regular file. +as_fn_executable_p () +{ + test -f "$1" && test -x "$1" +} # as_fn_executable_p +# as_fn_append VAR VALUE +# ---------------------- +# Append the text in VALUE to the end of the definition contained in VAR. Take +# advantage of any shell optimizations that allow amortized linear growth over +# repeated appends, instead of the typical quadratic growth present in naive +# implementations. +if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null +then : + eval 'as_fn_append () + { + eval $1+=\$2 + }' +else $as_nop + as_fn_append () + { + eval $1=\$$1\$2 + } +fi # as_fn_append + +# as_fn_arith ARG... +# ------------------ +# Perform arithmetic evaluation on the ARGs, and store the result in the +# global $as_val. Take advantage of shells that can avoid forks. The arguments +# must be portable across $(()) and expr. +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null +then : + eval 'as_fn_arith () + { + as_val=$(( $* )) + }' +else $as_nop + as_fn_arith () + { + as_val=`expr "$@" || test $? -eq 1` + } +fi # as_fn_arith + +# as_fn_nop +# --------- +# Do nothing but, unlike ":", preserve the value of $?. +as_fn_nop () +{ + return $? +} +as_nop=as_fn_nop + +# as_fn_error STATUS ERROR [LINENO LOG_FD] +# ---------------------------------------- +# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are +# provided, also output the error to LOG_FD, referencing LINENO. Then exit the +# script with STATUS, using 1 if that was 0. +as_fn_error () +{ + as_status=$1; test $as_status -eq 0 && as_status=1 + if test "$4"; then + as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 + fi + printf "%s\n" "$as_me: error: $2" >&2 + as_fn_exit $as_status +} # as_fn_error + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +printf "%s\n" X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + + + as_lineno_1=$LINENO as_lineno_1a=$LINENO + as_lineno_2=$LINENO as_lineno_2a=$LINENO + eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && + test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { + # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-) + sed -n ' + p + /[$]LINENO/= + ' <$as_myself | + sed ' + s/[$]LINENO.*/&-/ + t lineno + b + :lineno + N + :loop + s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ + t loop + s/-\n.*// + ' >$as_me.lineno && + chmod +x "$as_me.lineno" || + { printf "%s\n" "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } + + # If we had to re-execute with $CONFIG_SHELL, we're ensured to have + # already done that, so ensure we don't try to do so again and fall + # in an infinite loop. This has already happened in practice. + _as_can_reexec=no; export _as_can_reexec + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensitive to this). + . "./$as_me.lineno" + # Exit status is that of the last command. + exit +} + + +# Determine whether it's possible to make 'echo' print without a newline. +# These variables are no longer used directly by Autoconf, but are AC_SUBSTed +# for compatibility with existing Makefiles. +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in #((((( +-n*) + case `echo 'xy\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + xy) ECHO_C='\c';; + *) echo `echo ksh88 bug on AIX 6.1` > /dev/null + ECHO_T=' ';; + esac;; +*) + ECHO_N='-n';; +esac + +# For backward compatibility with old third-party macros, we provide +# the shell variables $as_echo and $as_echo_n. New code should use +# AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively. +as_echo='printf %s\n' +as_echo_n='printf %s' + + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir 2>/dev/null +fi +if (echo >conf$$.file) 2>/dev/null; then + if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -pR'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -pR' + elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln + else + as_ln_s='cp -pR' + fi +else + as_ln_s='cp -pR' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + +if mkdir -p . 2>/dev/null; then + as_mkdir_p='mkdir -p "$as_dir"' +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +as_test_x='test -x' +as_executable_p=as_fn_executable_p + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + +test -n "$DJDIR" || exec 7<&0 &1 + +# Name of the host. +# hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status, +# so uname gets run too. +ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` + +# +# Initializations. +# +ac_default_prefix=/usr/local +ac_clean_files= +ac_config_libobj_dir=. +LIBOBJS= +cross_compiling=no +subdirs= +MFLAGS= +MAKEFLAGS= + +# Identity of this package. +PACKAGE_NAME='Haskell PostgreSQL bindings' +PACKAGE_TARNAME='the-url' +PACKAGE_VERSION='0.10' +PACKAGE_STRING='Haskell PostgreSQL bindings 0.10' +PACKAGE_BUGREPORT='oleg.grenrus@iki.fi' +PACKAGE_URL='' + +# Factoring default headers for most tests. +ac_includes_default="\ +#include +#ifdef HAVE_STDIO_H +# include +#endif +#ifdef HAVE_STDLIB_H +# include +#endif +#ifdef HAVE_STRING_H +# include +#endif +#ifdef HAVE_INTTYPES_H +# include +#endif +#ifdef HAVE_STDINT_H +# include +#endif +#ifdef HAVE_STRINGS_H +# include +#endif +#ifdef HAVE_SYS_TYPES_H +# include +#endif +#ifdef HAVE_SYS_STAT_H +# include +#endif +#ifdef HAVE_UNISTD_H +# include +#endif" + +ac_header_c_list= +ac_subst_vars='LTLIBOBJS +LIBOBJS +POSTGRESQL_INCLUDEDIR +POSTGRESQL_LIBDIR +POSTGRESQL_EXTRA_LIBS +POSTGRESQL_LIBS +POSTGRESQL_VERSION +AWK +PKG_CONFIG_LIBDIR +PKG_CONFIG_PATH +PKG_CONFIG +POSTGRESQL_LDFLAGS +POSTGRESQL_LIBFLAGS +POSTGRESQL_CPPFLAGS +SED +OBJEXT +EXEEXT +ac_ct_CC +CPPFLAGS +LDFLAGS +CFLAGS +CC +target_alias +host_alias +build_alias +LIBS +ECHO_T +ECHO_N +ECHO_C +DEFS +mandir +localedir +libdir +psdir +pdfdir +dvidir +htmldir +infodir +docdir +oldincludedir +includedir +runstatedir +localstatedir +sharedstatedir +sysconfdir +datadir +datarootdir +libexecdir +sbindir +bindir +program_transform_name +prefix +exec_prefix +PACKAGE_URL +PACKAGE_BUGREPORT +PACKAGE_STRING +PACKAGE_VERSION +PACKAGE_TARNAME +PACKAGE_NAME +PATH_SEPARATOR +SHELL' +ac_subst_files='' +ac_user_opts=' +enable_option_checking +with_postgresql +' + ac_precious_vars='build_alias +host_alias +target_alias +CC +CFLAGS +LDFLAGS +LIBS +CPPFLAGS +POSTGRESQL_CPPFLAGS +POSTGRESQL_LIBFLAGS +POSTGRESQL_LDFLAGS +PKG_CONFIG +PKG_CONFIG_PATH +PKG_CONFIG_LIBDIR' + + +# Initialize some variables set by options. +ac_init_help= +ac_init_version=false +ac_unrecognized_opts= +ac_unrecognized_sep= +# The variables have the same names as the options, with +# dashes changed to underlines. +cache_file=/dev/null +exec_prefix=NONE +no_create= +no_recursion= +prefix=NONE +program_prefix=NONE +program_suffix=NONE +program_transform_name=s,x,x, +silent= +site= +srcdir= +verbose= +x_includes=NONE +x_libraries=NONE + +# Installation directory options. +# These are left unexpanded so users can "make install exec_prefix=/foo" +# and all the variables that are supposed to be based on exec_prefix +# by default will actually change. +# Use braces instead of parens because sh, perl, etc. also accept them. +# (The list follows the same order as the GNU Coding Standards.) +bindir='${exec_prefix}/bin' +sbindir='${exec_prefix}/sbin' +libexecdir='${exec_prefix}/libexec' +datarootdir='${prefix}/share' +datadir='${datarootdir}' +sysconfdir='${prefix}/etc' +sharedstatedir='${prefix}/com' +localstatedir='${prefix}/var' +runstatedir='${localstatedir}/run' +includedir='${prefix}/include' +oldincludedir='/usr/include' +docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' +infodir='${datarootdir}/info' +htmldir='${docdir}' +dvidir='${docdir}' +pdfdir='${docdir}' +psdir='${docdir}' +libdir='${exec_prefix}/lib' +localedir='${datarootdir}/locale' +mandir='${datarootdir}/man' + +ac_prev= +ac_dashdash= +for ac_option +do + # If the previous option needs an argument, assign it. + if test -n "$ac_prev"; then + eval $ac_prev=\$ac_option + ac_prev= + continue + fi + + case $ac_option in + *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; + *=) ac_optarg= ;; + *) ac_optarg=yes ;; + esac + + case $ac_dashdash$ac_option in + --) + ac_dashdash=yes ;; + + -bindir | --bindir | --bindi | --bind | --bin | --bi) + ac_prev=bindir ;; + -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) + bindir=$ac_optarg ;; + + -build | --build | --buil | --bui | --bu) + ac_prev=build_alias ;; + -build=* | --build=* | --buil=* | --bui=* | --bu=*) + build_alias=$ac_optarg ;; + + -cache-file | --cache-file | --cache-fil | --cache-fi \ + | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) + ac_prev=cache_file ;; + -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ + | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) + cache_file=$ac_optarg ;; + + --config-cache | -C) + cache_file=config.cache ;; + + -datadir | --datadir | --datadi | --datad) + ac_prev=datadir ;; + -datadir=* | --datadir=* | --datadi=* | --datad=*) + datadir=$ac_optarg ;; + + -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ + | --dataroo | --dataro | --datar) + ac_prev=datarootdir ;; + -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ + | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) + datarootdir=$ac_optarg ;; + + -disable-* | --disable-*) + ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid feature name: \`$ac_useropt'" + ac_useropt_orig=$ac_useropt + ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"enable_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval enable_$ac_useropt=no ;; + + -docdir | --docdir | --docdi | --doc | --do) + ac_prev=docdir ;; + -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) + docdir=$ac_optarg ;; + + -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) + ac_prev=dvidir ;; + -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) + dvidir=$ac_optarg ;; + + -enable-* | --enable-*) + ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid feature name: \`$ac_useropt'" + ac_useropt_orig=$ac_useropt + ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"enable_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval enable_$ac_useropt=\$ac_optarg ;; + + -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ + | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ + | --exec | --exe | --ex) + ac_prev=exec_prefix ;; + -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ + | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ + | --exec=* | --exe=* | --ex=*) + exec_prefix=$ac_optarg ;; + + -gas | --gas | --ga | --g) + # Obsolete; use --with-gas. + with_gas=yes ;; + + -help | --help | --hel | --he | -h) + ac_init_help=long ;; + -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) + ac_init_help=recursive ;; + -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) + ac_init_help=short ;; + + -host | --host | --hos | --ho) + ac_prev=host_alias ;; + -host=* | --host=* | --hos=* | --ho=*) + host_alias=$ac_optarg ;; + + -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) + ac_prev=htmldir ;; + -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ + | --ht=*) + htmldir=$ac_optarg ;; + + -includedir | --includedir | --includedi | --included | --include \ + | --includ | --inclu | --incl | --inc) + ac_prev=includedir ;; + -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ + | --includ=* | --inclu=* | --incl=* | --inc=*) + includedir=$ac_optarg ;; + + -infodir | --infodir | --infodi | --infod | --info | --inf) + ac_prev=infodir ;; + -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) + infodir=$ac_optarg ;; + + -libdir | --libdir | --libdi | --libd) + ac_prev=libdir ;; + -libdir=* | --libdir=* | --libdi=* | --libd=*) + libdir=$ac_optarg ;; + + -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ + | --libexe | --libex | --libe) + ac_prev=libexecdir ;; + -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ + | --libexe=* | --libex=* | --libe=*) + libexecdir=$ac_optarg ;; + + -localedir | --localedir | --localedi | --localed | --locale) + ac_prev=localedir ;; + -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) + localedir=$ac_optarg ;; + + -localstatedir | --localstatedir | --localstatedi | --localstated \ + | --localstate | --localstat | --localsta | --localst | --locals) + ac_prev=localstatedir ;; + -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ + | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) + localstatedir=$ac_optarg ;; + + -mandir | --mandir | --mandi | --mand | --man | --ma | --m) + ac_prev=mandir ;; + -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) + mandir=$ac_optarg ;; + + -nfp | --nfp | --nf) + # Obsolete; use --without-fp. + with_fp=no ;; + + -no-create | --no-create | --no-creat | --no-crea | --no-cre \ + | --no-cr | --no-c | -n) + no_create=yes ;; + + -no-recursion | --no-recursion | --no-recursio | --no-recursi \ + | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) + no_recursion=yes ;; + + -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ + | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ + | --oldin | --oldi | --old | --ol | --o) + ac_prev=oldincludedir ;; + -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ + | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ + | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) + oldincludedir=$ac_optarg ;; + + -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) + ac_prev=prefix ;; + -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) + prefix=$ac_optarg ;; + + -program-prefix | --program-prefix | --program-prefi | --program-pref \ + | --program-pre | --program-pr | --program-p) + ac_prev=program_prefix ;; + -program-prefix=* | --program-prefix=* | --program-prefi=* \ + | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) + program_prefix=$ac_optarg ;; + + -program-suffix | --program-suffix | --program-suffi | --program-suff \ + | --program-suf | --program-su | --program-s) + ac_prev=program_suffix ;; + -program-suffix=* | --program-suffix=* | --program-suffi=* \ + | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) + program_suffix=$ac_optarg ;; + + -program-transform-name | --program-transform-name \ + | --program-transform-nam | --program-transform-na \ + | --program-transform-n | --program-transform- \ + | --program-transform | --program-transfor \ + | --program-transfo | --program-transf \ + | --program-trans | --program-tran \ + | --progr-tra | --program-tr | --program-t) + ac_prev=program_transform_name ;; + -program-transform-name=* | --program-transform-name=* \ + | --program-transform-nam=* | --program-transform-na=* \ + | --program-transform-n=* | --program-transform-=* \ + | --program-transform=* | --program-transfor=* \ + | --program-transfo=* | --program-transf=* \ + | --program-trans=* | --program-tran=* \ + | --progr-tra=* | --program-tr=* | --program-t=*) + program_transform_name=$ac_optarg ;; + + -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) + ac_prev=pdfdir ;; + -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) + pdfdir=$ac_optarg ;; + + -psdir | --psdir | --psdi | --psd | --ps) + ac_prev=psdir ;; + -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) + psdir=$ac_optarg ;; + + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + silent=yes ;; + + -runstatedir | --runstatedir | --runstatedi | --runstated \ + | --runstate | --runstat | --runsta | --runst | --runs \ + | --run | --ru | --r) + ac_prev=runstatedir ;; + -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ + | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ + | --run=* | --ru=* | --r=*) + runstatedir=$ac_optarg ;; + + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) + ac_prev=sbindir ;; + -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ + | --sbi=* | --sb=*) + sbindir=$ac_optarg ;; + + -sharedstatedir | --sharedstatedir | --sharedstatedi \ + | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ + | --sharedst | --shareds | --shared | --share | --shar \ + | --sha | --sh) + ac_prev=sharedstatedir ;; + -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ + | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ + | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ + | --sha=* | --sh=*) + sharedstatedir=$ac_optarg ;; + + -site | --site | --sit) + ac_prev=site ;; + -site=* | --site=* | --sit=*) + site=$ac_optarg ;; + + -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) + ac_prev=srcdir ;; + -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) + srcdir=$ac_optarg ;; + + -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ + | --syscon | --sysco | --sysc | --sys | --sy) + ac_prev=sysconfdir ;; + -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ + | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) + sysconfdir=$ac_optarg ;; + + -target | --target | --targe | --targ | --tar | --ta | --t) + ac_prev=target_alias ;; + -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) + target_alias=$ac_optarg ;; + + -v | -verbose | --verbose | --verbos | --verbo | --verb) + verbose=yes ;; + + -version | --version | --versio | --versi | --vers | -V) + ac_init_version=: ;; + + -with-* | --with-*) + ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid package name: \`$ac_useropt'" + ac_useropt_orig=$ac_useropt + ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"with_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval with_$ac_useropt=\$ac_optarg ;; + + -without-* | --without-*) + ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid package name: \`$ac_useropt'" + ac_useropt_orig=$ac_useropt + ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"with_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval with_$ac_useropt=no ;; + + --x) + # Obsolete; use --with-x. + with_x=yes ;; + + -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ + | --x-incl | --x-inc | --x-in | --x-i) + ac_prev=x_includes ;; + -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ + | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) + x_includes=$ac_optarg ;; + + -x-libraries | --x-libraries | --x-librarie | --x-librari \ + | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) + ac_prev=x_libraries ;; + -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ + | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) + x_libraries=$ac_optarg ;; + + -*) as_fn_error $? "unrecognized option: \`$ac_option' +Try \`$0 --help' for more information" + ;; + + *=*) + ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` + # Reject names that are not valid shell variable names. + case $ac_envvar in #( + '' | [0-9]* | *[!_$as_cr_alnum]* ) + as_fn_error $? "invalid variable name: \`$ac_envvar'" ;; + esac + eval $ac_envvar=\$ac_optarg + export $ac_envvar ;; + + *) + # FIXME: should be removed in autoconf 3.0. + printf "%s\n" "$as_me: WARNING: you should use --build, --host, --target" >&2 + expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && + printf "%s\n" "$as_me: WARNING: invalid host type: $ac_option" >&2 + : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" + ;; + + esac +done + +if test -n "$ac_prev"; then + ac_option=--`echo $ac_prev | sed 's/_/-/g'` + as_fn_error $? "missing argument to $ac_option" +fi + +if test -n "$ac_unrecognized_opts"; then + case $enable_option_checking in + no) ;; + fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; + *) printf "%s\n" "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; + esac +fi + +# Check all directory arguments for consistency. +for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ + datadir sysconfdir sharedstatedir localstatedir includedir \ + oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ + libdir localedir mandir runstatedir +do + eval ac_val=\$$ac_var + # Remove trailing slashes. + case $ac_val in + */ ) + ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` + eval $ac_var=\$ac_val;; + esac + # Be sure to have absolute directory names. + case $ac_val in + [\\/$]* | ?:[\\/]* ) continue;; + NONE | '' ) case $ac_var in *prefix ) continue;; esac;; + esac + as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" +done + +# There might be people who depend on the old broken behavior: `$host' +# used to hold the argument of --host etc. +# FIXME: To remove some day. +build=$build_alias +host=$host_alias +target=$target_alias + +# FIXME: To remove some day. +if test "x$host_alias" != x; then + if test "x$build_alias" = x; then + cross_compiling=maybe + elif test "x$build_alias" != "x$host_alias"; then + cross_compiling=yes + fi +fi + +ac_tool_prefix= +test -n "$host_alias" && ac_tool_prefix=$host_alias- + +test "$silent" = yes && exec 6>/dev/null + + +ac_pwd=`pwd` && test -n "$ac_pwd" && +ac_ls_di=`ls -di .` && +ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || + as_fn_error $? "working directory cannot be determined" +test "X$ac_ls_di" = "X$ac_pwd_ls_di" || + as_fn_error $? "pwd does not report name of working directory" + + +# Find the source files, if location was not specified. +if test -z "$srcdir"; then + ac_srcdir_defaulted=yes + # Try the directory containing this script, then the parent directory. + ac_confdir=`$as_dirname -- "$as_myself" || +$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_myself" : 'X\(//\)[^/]' \| \ + X"$as_myself" : 'X\(//\)$' \| \ + X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || +printf "%s\n" X"$as_myself" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + srcdir=$ac_confdir + if test ! -r "$srcdir/$ac_unique_file"; then + srcdir=.. + fi +else + ac_srcdir_defaulted=no +fi +if test ! -r "$srcdir/$ac_unique_file"; then + test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." + as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" +fi +ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" +ac_abs_confdir=`( + cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" + pwd)` +# When building in place, set srcdir=. +if test "$ac_abs_confdir" = "$ac_pwd"; then + srcdir=. +fi +# Remove unnecessary trailing slashes from srcdir. +# Double slashes in file names in object file debugging info +# mess up M-x gdb in Emacs. +case $srcdir in +*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; +esac +for ac_var in $ac_precious_vars; do + eval ac_env_${ac_var}_set=\${${ac_var}+set} + eval ac_env_${ac_var}_value=\$${ac_var} + eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} + eval ac_cv_env_${ac_var}_value=\$${ac_var} +done + +# +# Report the --help message. +# +if test "$ac_init_help" = "long"; then + # Omit some internal or obsolete options to make the list less imposing. + # This message is too long to be a string in the A/UX 3.1 sh. + cat <<_ACEOF +\`configure' configures Haskell PostgreSQL bindings 0.10 to adapt to many kinds of systems. + +Usage: $0 [OPTION]... [VAR=VALUE]... + +To assign environment variables (e.g., CC, CFLAGS...), specify them as +VAR=VALUE. See below for descriptions of some of the useful variables. + +Defaults for the options are specified in brackets. + +Configuration: + -h, --help display this help and exit + --help=short display options specific to this package + --help=recursive display the short help of all the included packages + -V, --version display version information and exit + -q, --quiet, --silent do not print \`checking ...' messages + --cache-file=FILE cache test results in FILE [disabled] + -C, --config-cache alias for \`--cache-file=config.cache' + -n, --no-create do not create output files + --srcdir=DIR find the sources in DIR [configure dir or \`..'] + +Installation directories: + --prefix=PREFIX install architecture-independent files in PREFIX + [$ac_default_prefix] + --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX + [PREFIX] + +By default, \`make install' will install all the files in +\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify +an installation prefix other than \`$ac_default_prefix' using \`--prefix', +for instance \`--prefix=\$HOME'. + +For better control, use the options below. + +Fine tuning of the installation directories: + --bindir=DIR user executables [EPREFIX/bin] + --sbindir=DIR system admin executables [EPREFIX/sbin] + --libexecdir=DIR program executables [EPREFIX/libexec] + --sysconfdir=DIR read-only single-machine data [PREFIX/etc] + --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] + --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] + --libdir=DIR object code libraries [EPREFIX/lib] + --includedir=DIR C header files [PREFIX/include] + --oldincludedir=DIR C header files for non-gcc [/usr/include] + --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] + --datadir=DIR read-only architecture-independent data [DATAROOTDIR] + --infodir=DIR info documentation [DATAROOTDIR/info] + --localedir=DIR locale-dependent data [DATAROOTDIR/locale] + --mandir=DIR man documentation [DATAROOTDIR/man] + --docdir=DIR documentation root [DATAROOTDIR/doc/the-url] + --htmldir=DIR html documentation [DOCDIR] + --dvidir=DIR dvi documentation [DOCDIR] + --pdfdir=DIR pdf documentation [DOCDIR] + --psdir=DIR ps documentation [DOCDIR] +_ACEOF + + cat <<\_ACEOF +_ACEOF +fi + +if test -n "$ac_init_help"; then + case $ac_init_help in + short | recursive ) echo "Configuration of Haskell PostgreSQL bindings 0.10:";; + esac + cat <<\_ACEOF + +Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] + --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) + --with-postgresql=[ARG] use PostgreSQL library [default=yes], optionally + specify path to pg_config + +Some influential environment variables: + CC C compiler command + CFLAGS C compiler flags + LDFLAGS linker flags, e.g. -L if you have libraries in a + nonstandard directory + LIBS libraries to pass to the linker, e.g. -l + CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if + you have headers in a nonstandard directory + POSTGRESQL_CPPFLAGS + cpp flags for PostgreSQL overriding detected flags + POSTGRESQL_LIBFLAGS + libs for PostgreSQL overriding detected flags + POSTGRESQL_LDFLAGS + linker flags for PostgreSQL overriding detected flags + PKG_CONFIG path to pkg-config utility + PKG_CONFIG_PATH + directories to add to pkg-config's search path + PKG_CONFIG_LIBDIR + path overriding pkg-config's built-in search path + +Use these variables to override the choices made by `configure' or to help +it to find libraries and programs with nonstandard names/locations. + +Report bugs to . +_ACEOF +ac_status=$? +fi + +if test "$ac_init_help" = "recursive"; then + # If there are subdirs, report their specific --help. + for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue + test -d "$ac_dir" || + { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || + continue + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`printf "%s\n" "$ac_dir" | sed 's|^\.[\\/]||'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`printf "%s\n" "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + cd "$ac_dir" || { ac_status=$?; continue; } + # Check for configure.gnu first; this name is used for a wrapper for + # Metaconfig's "Configure" on case-insensitive file systems. + if test -f "$ac_srcdir/configure.gnu"; then + echo && + $SHELL "$ac_srcdir/configure.gnu" --help=recursive + elif test -f "$ac_srcdir/configure"; then + echo && + $SHELL "$ac_srcdir/configure" --help=recursive + else + printf "%s\n" "$as_me: WARNING: no configuration information is in $ac_dir" >&2 + fi || ac_status=$? + cd "$ac_pwd" || { ac_status=$?; break; } + done +fi + +test -n "$ac_init_help" && exit $ac_status +if $ac_init_version; then + cat <<\_ACEOF +Haskell PostgreSQL bindings configure 0.10 +generated by GNU Autoconf 2.71 + +Copyright (C) 2021 Free Software Foundation, Inc. +This configure script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it. +_ACEOF + exit +fi + +## ------------------------ ## +## Autoconf initialization. ## +## ------------------------ ## + +# ac_fn_c_try_compile LINENO +# -------------------------- +# Try to compile conftest.$ac_ext, and return whether this succeeded. +ac_fn_c_try_compile () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext conftest.beam + if { { ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +printf "%s\n" "$ac_try_echo"; } >&5 + (eval "$ac_compile") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext +then : + ac_retval=0 +else $as_nop + printf "%s\n" "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_c_try_compile + +# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES +# ------------------------------------------------------- +# Tests whether HEADER exists and can be compiled using the include files in +# INCLUDES, setting the cache variable VAR accordingly. +ac_fn_c_check_header_compile () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +printf %s "checking for $2... " >&6; } +if eval test \${$3+y} +then : + printf %s "(cached) " >&6 +else $as_nop + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +#include <$2> +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + eval "$3=yes" +else $as_nop + eval "$3=no" +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +fi +eval ac_res=\$$3 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} # ac_fn_c_check_header_compile + +# ac_fn_c_try_link LINENO +# ----------------------- +# Try to link conftest.$ac_ext, and return whether this succeeded. +ac_fn_c_try_link () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext conftest.beam conftest$ac_exeext + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +printf "%s\n" "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && { + test "$cross_compiling" = yes || + test -x conftest$ac_exeext + } +then : + ac_retval=0 +else $as_nop + printf "%s\n" "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information + # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would + # interfere with the next link command; also delete a directory that is + # left behind by Apple's compiler. We do this before executing the actions. + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_c_try_link +ac_configure_args_raw= +for ac_arg +do + case $ac_arg in + *\'*) + ac_arg=`printf "%s\n" "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + as_fn_append ac_configure_args_raw " '$ac_arg'" +done + +case $ac_configure_args_raw in + *$as_nl*) + ac_safe_unquote= ;; + *) + ac_unsafe_z='|&;<>()$`\\"*?[ '' ' # This string ends in space, tab. + ac_unsafe_a="$ac_unsafe_z#~" + ac_safe_unquote="s/ '\\([^$ac_unsafe_a][^$ac_unsafe_z]*\\)'/ \\1/g" + ac_configure_args_raw=` printf "%s\n" "$ac_configure_args_raw" | sed "$ac_safe_unquote"`;; +esac + +cat >config.log <<_ACEOF +This file contains any messages produced by compilers while +running configure, to aid debugging if configure makes a mistake. + +It was created by Haskell PostgreSQL bindings $as_me 0.10, which was +generated by GNU Autoconf 2.71. Invocation command line was + + $ $0$ac_configure_args_raw + +_ACEOF +exec 5>>config.log +{ +cat <<_ASUNAME +## --------- ## +## Platform. ## +## --------- ## + +hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` + +/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` +/usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` +/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` +/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` + +_ASUNAME + +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + printf "%s\n" "PATH: $as_dir" + done +IFS=$as_save_IFS + +} >&5 + +cat >&5 <<_ACEOF + + +## ----------- ## +## Core tests. ## +## ----------- ## + +_ACEOF + + +# Keep a trace of the command line. +# Strip out --no-create and --no-recursion so they do not pile up. +# Strip out --silent because we don't want to record it for future runs. +# Also quote any args containing shell meta-characters. +# Make two passes to allow for proper duplicate-argument suppression. +ac_configure_args= +ac_configure_args0= +ac_configure_args1= +ac_must_keep_next=false +for ac_pass in 1 2 +do + for ac_arg + do + case $ac_arg in + -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + continue ;; + *\'*) + ac_arg=`printf "%s\n" "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + case $ac_pass in + 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; + 2) + as_fn_append ac_configure_args1 " '$ac_arg'" + if test $ac_must_keep_next = true; then + ac_must_keep_next=false # Got value, back to normal. + else + case $ac_arg in + *=* | --config-cache | -C | -disable-* | --disable-* \ + | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ + | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ + | -with-* | --with-* | -without-* | --without-* | --x) + case "$ac_configure_args0 " in + "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; + esac + ;; + -* ) ac_must_keep_next=true ;; + esac + fi + as_fn_append ac_configure_args " '$ac_arg'" + ;; + esac + done +done +{ ac_configure_args0=; unset ac_configure_args0;} +{ ac_configure_args1=; unset ac_configure_args1;} + +# When interrupted or exit'd, cleanup temporary files, and complete +# config.log. We remove comments because anyway the quotes in there +# would cause problems or look ugly. +# WARNING: Use '\'' to represent an apostrophe within the trap. +# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. +trap 'exit_status=$? + # Sanitize IFS. + IFS=" "" $as_nl" + # Save into config.log some information that might help in debugging. + { + echo + + printf "%s\n" "## ---------------- ## +## Cache variables. ## +## ---------------- ##" + echo + # The following way of writing the cache mishandles newlines in values, +( + for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( + *) { eval $ac_var=; unset $ac_var;} ;; + esac ;; + esac + done + (set) 2>&1 | + case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + sed -n \ + "s/'\''/'\''\\\\'\'''\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" + ;; #( + *) + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) + echo + + printf "%s\n" "## ----------------- ## +## Output variables. ## +## ----------------- ##" + echo + for ac_var in $ac_subst_vars + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`printf "%s\n" "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + printf "%s\n" "$ac_var='\''$ac_val'\''" + done | sort + echo + + if test -n "$ac_subst_files"; then + printf "%s\n" "## ------------------- ## +## File substitutions. ## +## ------------------- ##" + echo + for ac_var in $ac_subst_files + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`printf "%s\n" "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + printf "%s\n" "$ac_var='\''$ac_val'\''" + done | sort + echo + fi + + if test -s confdefs.h; then + printf "%s\n" "## ----------- ## +## confdefs.h. ## +## ----------- ##" + echo + cat confdefs.h + echo + fi + test "$ac_signal" != 0 && + printf "%s\n" "$as_me: caught signal $ac_signal" + printf "%s\n" "$as_me: exit $exit_status" + } >&5 + rm -f core *.core core.conftest.* && + rm -f -r conftest* confdefs* conf$$* $ac_clean_files && + exit $exit_status +' 0 +for ac_signal in 1 2 13 15; do + trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal +done +ac_signal=0 + +# confdefs.h avoids OS command line length limits that DEFS can exceed. +rm -f -r conftest* confdefs.h + +printf "%s\n" "/* confdefs.h */" > confdefs.h + +# Predefined preprocessor variables. + +printf "%s\n" "#define PACKAGE_NAME \"$PACKAGE_NAME\"" >>confdefs.h + +printf "%s\n" "#define PACKAGE_TARNAME \"$PACKAGE_TARNAME\"" >>confdefs.h + +printf "%s\n" "#define PACKAGE_VERSION \"$PACKAGE_VERSION\"" >>confdefs.h + +printf "%s\n" "#define PACKAGE_STRING \"$PACKAGE_STRING\"" >>confdefs.h + +printf "%s\n" "#define PACKAGE_BUGREPORT \"$PACKAGE_BUGREPORT\"" >>confdefs.h + +printf "%s\n" "#define PACKAGE_URL \"$PACKAGE_URL\"" >>confdefs.h + + +# Let the site file select an alternate cache file if it wants to. +# Prefer an explicitly selected file to automatically selected ones. +if test -n "$CONFIG_SITE"; then + ac_site_files="$CONFIG_SITE" +elif test "x$prefix" != xNONE; then + ac_site_files="$prefix/share/config.site $prefix/etc/config.site" +else + ac_site_files="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" +fi + +for ac_site_file in $ac_site_files +do + case $ac_site_file in #( + */*) : + ;; #( + *) : + ac_site_file=./$ac_site_file ;; +esac + if test -f "$ac_site_file" && test -r "$ac_site_file"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 +printf "%s\n" "$as_me: loading site script $ac_site_file" >&6;} + sed 's/^/| /' "$ac_site_file" >&5 + . "$ac_site_file" \ + || { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "failed to load site script $ac_site_file +See \`config.log' for more details" "$LINENO" 5; } + fi +done + +if test -r "$cache_file"; then + # Some versions of bash will fail to source /dev/null (special files + # actually), so we avoid doing that. DJGPP emulates it as a regular file. + if test /dev/null != "$cache_file" && test -f "$cache_file"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 +printf "%s\n" "$as_me: loading cache $cache_file" >&6;} + case $cache_file in + [\\/]* | ?:[\\/]* ) . "$cache_file";; + *) . "./$cache_file";; + esac + fi +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 +printf "%s\n" "$as_me: creating cache $cache_file" >&6;} + >$cache_file +fi + +# Test code for whether the C compiler supports C89 (global declarations) +ac_c_conftest_c89_globals=' +/* Does the compiler advertise C89 conformance? + Do not test the value of __STDC__, because some compilers set it to 0 + while being otherwise adequately conformant. */ +#if !defined __STDC__ +# error "Compiler does not advertise C89 conformance" +#endif + +#include +#include +struct stat; +/* Most of the following tests are stolen from RCS 5.7 src/conf.sh. */ +struct buf { int x; }; +struct buf * (*rcsopen) (struct buf *, struct stat *, int); +static char *e (p, i) + char **p; + int i; +{ + return p[i]; +} +static char *f (char * (*g) (char **, int), char **p, ...) +{ + char *s; + va_list v; + va_start (v,p); + s = g (p, va_arg (v,int)); + va_end (v); + return s; +} + +/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has + function prototypes and stuff, but not \xHH hex character constants. + These do not provoke an error unfortunately, instead are silently treated + as an "x". The following induces an error, until -std is added to get + proper ANSI mode. Curiously \x00 != x always comes out true, for an + array size at least. It is necessary to write \x00 == 0 to get something + that is true only with -std. */ +int osf4_cc_array ['\''\x00'\'' == 0 ? 1 : -1]; + +/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters + inside strings and character constants. */ +#define FOO(x) '\''x'\'' +int xlc6_cc_array[FOO(a) == '\''x'\'' ? 1 : -1]; + +int test (int i, double x); +struct s1 {int (*f) (int a);}; +struct s2 {int (*f) (double a);}; +int pairnames (int, char **, int *(*)(struct buf *, struct stat *, int), + int, int);' + +# Test code for whether the C compiler supports C89 (body of main). +ac_c_conftest_c89_main=' +ok |= (argc == 0 || f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]); +' + +# Test code for whether the C compiler supports C99 (global declarations) +ac_c_conftest_c99_globals=' +// Does the compiler advertise C99 conformance? +#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L +# error "Compiler does not advertise C99 conformance" +#endif + +#include +extern int puts (const char *); +extern int printf (const char *, ...); +extern int dprintf (int, const char *, ...); +extern void *malloc (size_t); + +// Check varargs macros. These examples are taken from C99 6.10.3.5. +// dprintf is used instead of fprintf to avoid needing to declare +// FILE and stderr. +#define debug(...) dprintf (2, __VA_ARGS__) +#define showlist(...) puts (#__VA_ARGS__) +#define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__)) +static void +test_varargs_macros (void) +{ + int x = 1234; + int y = 5678; + debug ("Flag"); + debug ("X = %d\n", x); + showlist (The first, second, and third items.); + report (x>y, "x is %d but y is %d", x, y); +} + +// Check long long types. +#define BIG64 18446744073709551615ull +#define BIG32 4294967295ul +#define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0) +#if !BIG_OK + #error "your preprocessor is broken" +#endif +#if BIG_OK +#else + #error "your preprocessor is broken" +#endif +static long long int bignum = -9223372036854775807LL; +static unsigned long long int ubignum = BIG64; + +struct incomplete_array +{ + int datasize; + double data[]; +}; + +struct named_init { + int number; + const wchar_t *name; + double average; +}; + +typedef const char *ccp; + +static inline int +test_restrict (ccp restrict text) +{ + // See if C++-style comments work. + // Iterate through items via the restricted pointer. + // Also check for declarations in for loops. + for (unsigned int i = 0; *(text+i) != '\''\0'\''; ++i) + continue; + return 0; +} + +// Check varargs and va_copy. +static bool +test_varargs (const char *format, ...) +{ + va_list args; + va_start (args, format); + va_list args_copy; + va_copy (args_copy, args); + + const char *str = ""; + int number = 0; + float fnumber = 0; + + while (*format) + { + switch (*format++) + { + case '\''s'\'': // string + str = va_arg (args_copy, const char *); + break; + case '\''d'\'': // int + number = va_arg (args_copy, int); + break; + case '\''f'\'': // float + fnumber = va_arg (args_copy, double); + break; + default: + break; + } + } + va_end (args_copy); + va_end (args); + + return *str && number && fnumber; +} +' + +# Test code for whether the C compiler supports C99 (body of main). +ac_c_conftest_c99_main=' + // Check bool. + _Bool success = false; + success |= (argc != 0); + + // Check restrict. + if (test_restrict ("String literal") == 0) + success = true; + char *restrict newvar = "Another string"; + + // Check varargs. + success &= test_varargs ("s, d'\'' f .", "string", 65, 34.234); + test_varargs_macros (); + + // Check flexible array members. + struct incomplete_array *ia = + malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10)); + ia->datasize = 10; + for (int i = 0; i < ia->datasize; ++i) + ia->data[i] = i * 1.234; + + // Check named initializers. + struct named_init ni = { + .number = 34, + .name = L"Test wide string", + .average = 543.34343, + }; + + ni.number = 58; + + int dynamic_array[ni.number]; + dynamic_array[0] = argv[0][0]; + dynamic_array[ni.number - 1] = 543; + + // work around unused variable warnings + ok |= (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == '\''x'\'' + || dynamic_array[ni.number - 1] != 543); +' + +# Test code for whether the C compiler supports C11 (global declarations) +ac_c_conftest_c11_globals=' +// Does the compiler advertise C11 conformance? +#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L +# error "Compiler does not advertise C11 conformance" +#endif + +// Check _Alignas. +char _Alignas (double) aligned_as_double; +char _Alignas (0) no_special_alignment; +extern char aligned_as_int; +char _Alignas (0) _Alignas (int) aligned_as_int; + +// Check _Alignof. +enum +{ + int_alignment = _Alignof (int), + int_array_alignment = _Alignof (int[100]), + char_alignment = _Alignof (char) +}; +_Static_assert (0 < -_Alignof (int), "_Alignof is signed"); + +// Check _Noreturn. +int _Noreturn does_not_return (void) { for (;;) continue; } + +// Check _Static_assert. +struct test_static_assert +{ + int x; + _Static_assert (sizeof (int) <= sizeof (long int), + "_Static_assert does not work in struct"); + long int y; +}; + +// Check UTF-8 literals. +#define u8 syntax error! +char const utf8_literal[] = u8"happens to be ASCII" "another string"; + +// Check duplicate typedefs. +typedef long *long_ptr; +typedef long int *long_ptr; +typedef long_ptr long_ptr; + +// Anonymous structures and unions -- taken from C11 6.7.2.1 Example 1. +struct anonymous +{ + union { + struct { int i; int j; }; + struct { int k; long int l; } w; + }; + int m; +} v1; +' + +# Test code for whether the C compiler supports C11 (body of main). +ac_c_conftest_c11_main=' + _Static_assert ((offsetof (struct anonymous, i) + == offsetof (struct anonymous, w.k)), + "Anonymous union alignment botch"); + v1.i = 2; + v1.w.k = 5; + ok |= v1.i != 5; +' + +# Test code for whether the C compiler supports C11 (complete). +ac_c_conftest_c11_program="${ac_c_conftest_c89_globals} +${ac_c_conftest_c99_globals} +${ac_c_conftest_c11_globals} + +int +main (int argc, char **argv) +{ + int ok = 0; + ${ac_c_conftest_c89_main} + ${ac_c_conftest_c99_main} + ${ac_c_conftest_c11_main} + return ok; +} +" + +# Test code for whether the C compiler supports C99 (complete). +ac_c_conftest_c99_program="${ac_c_conftest_c89_globals} +${ac_c_conftest_c99_globals} + +int +main (int argc, char **argv) +{ + int ok = 0; + ${ac_c_conftest_c89_main} + ${ac_c_conftest_c99_main} + return ok; +} +" + +# Test code for whether the C compiler supports C89 (complete). +ac_c_conftest_c89_program="${ac_c_conftest_c89_globals} + +int +main (int argc, char **argv) +{ + int ok = 0; + ${ac_c_conftest_c89_main} + return ok; +} +" + +as_fn_append ac_header_c_list " stdio.h stdio_h HAVE_STDIO_H" +as_fn_append ac_header_c_list " stdlib.h stdlib_h HAVE_STDLIB_H" +as_fn_append ac_header_c_list " string.h string_h HAVE_STRING_H" +as_fn_append ac_header_c_list " inttypes.h inttypes_h HAVE_INTTYPES_H" +as_fn_append ac_header_c_list " stdint.h stdint_h HAVE_STDINT_H" +as_fn_append ac_header_c_list " strings.h strings_h HAVE_STRINGS_H" +as_fn_append ac_header_c_list " sys/stat.h sys_stat_h HAVE_SYS_STAT_H" +as_fn_append ac_header_c_list " sys/types.h sys_types_h HAVE_SYS_TYPES_H" +as_fn_append ac_header_c_list " unistd.h unistd_h HAVE_UNISTD_H" +# Check that the precious variables saved in the cache have kept the same +# value. +ac_cache_corrupted=false +for ac_var in $ac_precious_vars; do + eval ac_old_set=\$ac_cv_env_${ac_var}_set + eval ac_new_set=\$ac_env_${ac_var}_set + eval ac_old_val=\$ac_cv_env_${ac_var}_value + eval ac_new_val=\$ac_env_${ac_var}_value + case $ac_old_set,$ac_new_set in + set,) + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 +printf "%s\n" "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,set) + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 +printf "%s\n" "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,);; + *) + if test "x$ac_old_val" != "x$ac_new_val"; then + # differences in whitespace do not lead to failure. + ac_old_val_w=`echo x $ac_old_val` + ac_new_val_w=`echo x $ac_new_val` + if test "$ac_old_val_w" != "$ac_new_val_w"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 +printf "%s\n" "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} + ac_cache_corrupted=: + else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 +printf "%s\n" "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} + eval $ac_var=\$ac_old_val + fi + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 +printf "%s\n" "$as_me: former value: \`$ac_old_val'" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 +printf "%s\n" "$as_me: current value: \`$ac_new_val'" >&2;} + fi;; + esac + # Pass precious variables to config.status. + if test "$ac_new_set" = set; then + case $ac_new_val in + *\'*) ac_arg=$ac_var=`printf "%s\n" "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; + *) ac_arg=$ac_var=$ac_new_val ;; + esac + case " $ac_configure_args " in + *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. + *) as_fn_append ac_configure_args " '$ac_arg'" ;; + esac + fi +done +if $ac_cache_corrupted; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 +printf "%s\n" "$as_me: error: changes in the environment can compromise the build" >&2;} + as_fn_error $? "run \`${MAKE-make} distclean' and/or \`rm $cache_file' + and start over" "$LINENO" 5 +fi +## -------------------- ## +## Main body of script. ## +## -------------------- ## + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + + + + + + + + + + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. +set dummy ${ac_tool_prefix}gcc; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}gcc" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "gcc", so it can be a program name with args. +set dummy gcc; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="gcc" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +printf "%s\n" "$ac_ct_CC" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +else + CC="$ac_cv_prog_CC" +fi + +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. +set dummy ${ac_tool_prefix}cc; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}cc" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi + + + fi +fi +if test -z "$CC"; then + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + ac_prog_rejected=no +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if test "$as_dir$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then + ac_prog_rejected=yes + continue + fi + ac_cv_prog_CC="cc" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +if test $ac_prog_rejected = yes; then + # We found a bogon in the path, so make sure we never use it. + set dummy $ac_cv_prog_CC + shift + if test $# != 0; then + # We chose a different compiler from the bogus one. + # However, it has the same basename, so the bogon will be chosen + # first if we set CC to just the basename; use the full file name. + shift + ac_cv_prog_CC="$as_dir$ac_word${1+' '}$@" + fi +fi +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi + + +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + for ac_prog in cl.exe + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="$ac_tool_prefix$ac_prog" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi + + + test -n "$CC" && break + done +fi +if test -z "$CC"; then + ac_ct_CC=$CC + for ac_prog in cl.exe +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="$ac_prog" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +printf "%s\n" "$ac_ct_CC" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi + + + test -n "$ac_ct_CC" && break +done + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +fi + +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}clang", so it can be a program name with args. +set dummy ${ac_tool_prefix}clang; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}clang" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "clang", so it can be a program name with args. +set dummy clang; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="clang" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +printf "%s\n" "$ac_ct_CC" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +else + CC="$ac_cv_prog_CC" +fi + +fi + + +test -z "$CC" && { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "no acceptable C compiler found in \$PATH +See \`config.log' for more details" "$LINENO" 5; } + +# Provide some information about the compiler. +printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 +set X $ac_compile +ac_compiler=$2 +for ac_option in --version -v -V -qversion -version; do + { { ac_try="$ac_compiler $ac_option >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +printf "%s\n" "$ac_try_echo"; } >&5 + (eval "$ac_compiler $ac_option >&5") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + sed '10a\ +... rest of stderr output deleted ... + 10q' conftest.err >conftest.er1 + cat conftest.er1 >&5 + fi + rm -f conftest.er1 conftest.err + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +done + +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main (void) +{ + + ; + return 0; +} +_ACEOF +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" +# Try to create an executable without -o first, disregard a.out. +# It will help us diagnose broken compilers, and finding out an intuition +# of exeext. +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 +printf %s "checking whether the C compiler works... " >&6; } +ac_link_default=`printf "%s\n" "$ac_link" | sed 's/ -o *conftest[^ ]*//'` + +# The possible output files: +ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" + +ac_rmfiles= +for ac_file in $ac_files +do + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; + * ) ac_rmfiles="$ac_rmfiles $ac_file";; + esac +done +rm -f $ac_rmfiles + +if { { ac_try="$ac_link_default" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +printf "%s\n" "$ac_try_echo"; } >&5 + (eval "$ac_link_default") 2>&5 + ac_status=$? + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +then : + # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. +# So ignore a value of `no', otherwise this would lead to `EXEEXT = no' +# in a Makefile. We should not override ac_cv_exeext if it was cached, +# so that the user can short-circuit this test for compilers unknown to +# Autoconf. +for ac_file in $ac_files '' +do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) + ;; + [ab].out ) + # We found the default executable, but exeext='' is most + # certainly right. + break;; + *.* ) + if test ${ac_cv_exeext+y} && test "$ac_cv_exeext" != no; + then :; else + ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + fi + # We set ac_cv_exeext here because the later test for it is not + # safe: cross compilers may not add the suffix if given an `-o' + # argument, so we may need to know it at that point already. + # Even if this section looks crufty: it has the advantage of + # actually working. + break;; + * ) + break;; + esac +done +test "$ac_cv_exeext" = no && ac_cv_exeext= + +else $as_nop + ac_file='' +fi +if test -z "$ac_file" +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +printf "%s\n" "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error 77 "C compiler cannot create executables +See \`config.log' for more details" "$LINENO" 5; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 +printf %s "checking for C compiler default output file name... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 +printf "%s\n" "$ac_file" >&6; } +ac_exeext=$ac_cv_exeext + +rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out +ac_clean_files=$ac_clean_files_save +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 +printf %s "checking for suffix of executables... " >&6; } +if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +printf "%s\n" "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +then : + # If both `conftest.exe' and `conftest' are `present' (well, observable) +# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will +# work properly (i.e., refer to `conftest.exe'), while it won't with +# `rm'. +for ac_file in conftest.exe conftest conftest.*; do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; + *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + break;; + * ) break;; + esac +done +else $as_nop + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot compute suffix of executables: cannot compile and link +See \`config.log' for more details" "$LINENO" 5; } +fi +rm -f conftest conftest$ac_cv_exeext +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 +printf "%s\n" "$ac_cv_exeext" >&6; } + +rm -f conftest.$ac_ext +EXEEXT=$ac_cv_exeext +ac_exeext=$EXEEXT +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main (void) +{ +FILE *f = fopen ("conftest.out", "w"); + return ferror (f) || fclose (f) != 0; + + ; + return 0; +} +_ACEOF +ac_clean_files="$ac_clean_files conftest.out" +# Check that the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 +printf %s "checking whether we are cross compiling... " >&6; } +if test "$cross_compiling" != yes; then + { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +printf "%s\n" "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + if { ac_try='./conftest$ac_cv_exeext' + { { case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +printf "%s\n" "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then + cross_compiling=no + else + if test "$cross_compiling" = maybe; then + cross_compiling=yes + else + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error 77 "cannot run C compiled programs. +If you meant to cross compile, use \`--host'. +See \`config.log' for more details" "$LINENO" 5; } + fi + fi +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 +printf "%s\n" "$cross_compiling" >&6; } + +rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out +ac_clean_files=$ac_clean_files_save +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 +printf %s "checking for suffix of object files... " >&6; } +if test ${ac_cv_objext+y} +then : + printf %s "(cached) " >&6 +else $as_nop + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main (void) +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.o conftest.obj +if { { ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +printf "%s\n" "$ac_try_echo"; } >&5 + (eval "$ac_compile") 2>&5 + ac_status=$? + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +then : + for ac_file in conftest.o conftest.obj conftest.*; do + test -f "$ac_file" || continue; + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;; + *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` + break;; + esac +done +else $as_nop + printf "%s\n" "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot compute suffix of object files: cannot compile +See \`config.log' for more details" "$LINENO" 5; } +fi +rm -f conftest.$ac_cv_objext conftest.$ac_ext +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 +printf "%s\n" "$ac_cv_objext" >&6; } +OBJEXT=$ac_cv_objext +ac_objext=$OBJEXT +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports GNU C" >&5 +printf %s "checking whether the compiler supports GNU C... " >&6; } +if test ${ac_cv_c_compiler_gnu+y} +then : + printf %s "(cached) " >&6 +else $as_nop + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main (void) +{ +#ifndef __GNUC__ + choke me +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + ac_compiler_gnu=yes +else $as_nop + ac_compiler_gnu=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +ac_cv_c_compiler_gnu=$ac_compiler_gnu + +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 +printf "%s\n" "$ac_cv_c_compiler_gnu" >&6; } +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +if test $ac_compiler_gnu = yes; then + GCC=yes +else + GCC= +fi +ac_test_CFLAGS=${CFLAGS+y} +ac_save_CFLAGS=$CFLAGS +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 +printf %s "checking whether $CC accepts -g... " >&6; } +if test ${ac_cv_prog_cc_g+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_save_c_werror_flag=$ac_c_werror_flag + ac_c_werror_flag=yes + ac_cv_prog_cc_g=no + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main (void) +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + ac_cv_prog_cc_g=yes +else $as_nop + CFLAGS="" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main (void) +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + +else $as_nop + ac_c_werror_flag=$ac_save_c_werror_flag + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main (void) +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + ac_cv_prog_cc_g=yes +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + ac_c_werror_flag=$ac_save_c_werror_flag +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 +printf "%s\n" "$ac_cv_prog_cc_g" >&6; } +if test $ac_test_CFLAGS; then + CFLAGS=$ac_save_CFLAGS +elif test $ac_cv_prog_cc_g = yes; then + if test "$GCC" = yes; then + CFLAGS="-g -O2" + else + CFLAGS="-g" + fi +else + if test "$GCC" = yes; then + CFLAGS="-O2" + else + CFLAGS= + fi +fi +ac_prog_cc_stdc=no +if test x$ac_prog_cc_stdc = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C11 features" >&5 +printf %s "checking for $CC option to enable C11 features... " >&6; } +if test ${ac_cv_prog_cc_c11+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_cv_prog_cc_c11=no +ac_save_CC=$CC +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$ac_c_conftest_c11_program +_ACEOF +for ac_arg in '' -std=gnu11 +do + CC="$ac_save_CC $ac_arg" + if ac_fn_c_try_compile "$LINENO" +then : + ac_cv_prog_cc_c11=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam + test "x$ac_cv_prog_cc_c11" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC +fi + +if test "x$ac_cv_prog_cc_c11" = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +printf "%s\n" "unsupported" >&6; } +else $as_nop + if test "x$ac_cv_prog_cc_c11" = x +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +printf "%s\n" "none needed" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c11" >&5 +printf "%s\n" "$ac_cv_prog_cc_c11" >&6; } + CC="$CC $ac_cv_prog_cc_c11" +fi + ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c11 + ac_prog_cc_stdc=c11 +fi +fi +if test x$ac_prog_cc_stdc = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C99 features" >&5 +printf %s "checking for $CC option to enable C99 features... " >&6; } +if test ${ac_cv_prog_cc_c99+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_cv_prog_cc_c99=no +ac_save_CC=$CC +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$ac_c_conftest_c99_program +_ACEOF +for ac_arg in '' -std=gnu99 -std=c99 -c99 -qlanglvl=extc1x -qlanglvl=extc99 -AC99 -D_STDC_C99= +do + CC="$ac_save_CC $ac_arg" + if ac_fn_c_try_compile "$LINENO" +then : + ac_cv_prog_cc_c99=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam + test "x$ac_cv_prog_cc_c99" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC +fi + +if test "x$ac_cv_prog_cc_c99" = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +printf "%s\n" "unsupported" >&6; } +else $as_nop + if test "x$ac_cv_prog_cc_c99" = x +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +printf "%s\n" "none needed" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c99" >&5 +printf "%s\n" "$ac_cv_prog_cc_c99" >&6; } + CC="$CC $ac_cv_prog_cc_c99" +fi + ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99 + ac_prog_cc_stdc=c99 +fi +fi +if test x$ac_prog_cc_stdc = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C89 features" >&5 +printf %s "checking for $CC option to enable C89 features... " >&6; } +if test ${ac_cv_prog_cc_c89+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_cv_prog_cc_c89=no +ac_save_CC=$CC +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$ac_c_conftest_c89_program +_ACEOF +for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +do + CC="$ac_save_CC $ac_arg" + if ac_fn_c_try_compile "$LINENO" +then : + ac_cv_prog_cc_c89=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam + test "x$ac_cv_prog_cc_c89" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC +fi + +if test "x$ac_cv_prog_cc_c89" = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +printf "%s\n" "unsupported" >&6; } +else $as_nop + if test "x$ac_cv_prog_cc_c89" = x +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +printf "%s\n" "none needed" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 +printf "%s\n" "$ac_cv_prog_cc_c89" >&6; } + CC="$CC $ac_cv_prog_cc_c89" +fi + ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89 + ac_prog_cc_stdc=c89 +fi +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5 +printf %s "checking for a sed that does not truncate output... " >&6; } +if test ${ac_cv_path_SED+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ + for ac_i in 1 2 3 4 5 6 7; do + ac_script="$ac_script$as_nl$ac_script" + done + echo "$ac_script" 2>/dev/null | sed 99q >conftest.sed + { ac_script=; unset ac_script;} + if test -z "$SED"; then + ac_path_SED_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_prog in sed gsed + do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_SED="$as_dir$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_SED" || continue +# Check for GNU ac_path_SED and select it if it is found. + # Check for GNU $ac_path_SED +case `"$ac_path_SED" --version 2>&1` in +*GNU*) + ac_cv_path_SED="$ac_path_SED" ac_path_SED_found=:;; +*) + ac_count=0 + printf %s 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + printf "%s\n" '' >> "conftest.nl" + "$ac_path_SED" -f conftest.sed < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_SED_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_SED="$ac_path_SED" + ac_path_SED_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_SED_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_SED"; then + as_fn_error $? "no acceptable sed could be found in \$PATH" "$LINENO" 5 + fi +else + ac_cv_path_SED=$SED +fi + +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5 +printf "%s\n" "$ac_cv_path_SED" >&6; } + SED="$ac_cv_path_SED" + rm -f conftest.sed + + + + + + + + + +if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}pkg-config", so it can be a program name with args. +set dummy ${ac_tool_prefix}pkg-config; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_path_PKG_CONFIG+y} +then : + printf %s "(cached) " >&6 +else $as_nop + case $PKG_CONFIG in + [\\/]* | ?:[\\/]*) + ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_path_PKG_CONFIG="$as_dir$ac_word$ac_exec_ext" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +PKG_CONFIG=$ac_cv_path_PKG_CONFIG +if test -n "$PKG_CONFIG"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $PKG_CONFIG" >&5 +printf "%s\n" "$PKG_CONFIG" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_PKG_CONFIG"; then + ac_pt_PKG_CONFIG=$PKG_CONFIG + # Extract the first word of "pkg-config", so it can be a program name with args. +set dummy pkg-config; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_path_ac_pt_PKG_CONFIG+y} +then : + printf %s "(cached) " >&6 +else $as_nop + case $ac_pt_PKG_CONFIG in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_PKG_CONFIG="$ac_pt_PKG_CONFIG" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_PKG_CONFIG="$as_dir$ac_word$ac_exec_ext" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_PKG_CONFIG=$ac_cv_path_ac_pt_PKG_CONFIG +if test -n "$ac_pt_PKG_CONFIG"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_pt_PKG_CONFIG" >&5 +printf "%s\n" "$ac_pt_PKG_CONFIG" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi + + if test "x$ac_pt_PKG_CONFIG" = x; then + PKG_CONFIG="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + PKG_CONFIG=$ac_pt_PKG_CONFIG + fi +else + PKG_CONFIG="$ac_cv_path_PKG_CONFIG" +fi + +fi +if test -n "$PKG_CONFIG"; then + _pkg_min_version=0.9.0 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking pkg-config is at least version $_pkg_min_version" >&5 +printf %s "checking pkg-config is at least version $_pkg_min_version... " >&6; } + if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } + else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } + PKG_CONFIG="" + fi +fi +for ac_prog in gawk mawk nawk awk +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_AWK+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if test -n "$AWK"; then + ac_cv_prog_AWK="$AWK" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_prog_AWK="$ac_prog" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +AWK=$ac_cv_prog_AWK +if test -n "$AWK"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5 +printf "%s\n" "$AWK" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi + + + test -n "$AWK" && break +done + + +ac_header= ac_cache= +for ac_item in $ac_header_c_list +do + if test $ac_cache; then + ac_fn_c_check_header_compile "$LINENO" $ac_header ac_cv_header_$ac_cache "$ac_includes_default" + if eval test \"x\$ac_cv_header_$ac_cache\" = xyes; then + printf "%s\n" "#define $ac_item 1" >> confdefs.h + fi + ac_header= ac_cache= + elif test $ac_header; then + ac_cache=$ac_item + else + ac_header=$ac_item + fi +done + + + + + + + + +if test $ac_cv_header_stdlib_h = yes && test $ac_cv_header_string_h = yes +then : + +printf "%s\n" "#define STDC_HEADERS 1" >>confdefs.h + +fi + + +# Check whether --with-postgresql was given. +if test ${with_postgresql+y} +then : + withval=$with_postgresql; + case $withval in #( + [nN][oO]) : + want_postgresql="no" ;; #( + [yY][eE][sS]) : + want_postgresql="yes" ;; #( + *) : + + want_postgresql="yes" + PG_CONFIG="$withval" + ;; +esac + +else $as_nop + want_postgresql="yes" + +fi + + + + + + + # populate cache + if test "X$POSTGRESQL_CPPFLAGS" != X +then : + ac_cv_POSTGRESQL_CPPFLAGS="$POSTGRESQL_CPPFLAGS" +fi + if test "X$POSTGRESQL_LDFLAGS" != X +then : + ac_cv_POSTGRESQL_LDFLAGS="$POSTGRESQL_LDFLAGS" +fi + if test "X$POSTGRESQL_LIBS" != X +then : + ac_cv_POSTGRESQL_LIBS="$POSTGRESQL_LIBS" +fi + + postgresql_version_req=14.12 + found_postgresql="no" + + POSTGRESQL_VERSION="" + + if test X"$want_postgresql" = "Xyes" +then : + + + + found_postgresql=no + + while true; do + + + + + + + +if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}pkg-config", so it can be a program name with args. +set dummy ${ac_tool_prefix}pkg-config; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_path_PKG_CONFIG+y} +then : + printf %s "(cached) " >&6 +else $as_nop + case $PKG_CONFIG in + [\\/]* | ?:[\\/]*) + ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_path_PKG_CONFIG="$as_dir$ac_word$ac_exec_ext" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +PKG_CONFIG=$ac_cv_path_PKG_CONFIG +if test -n "$PKG_CONFIG"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $PKG_CONFIG" >&5 +printf "%s\n" "$PKG_CONFIG" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_PKG_CONFIG"; then + ac_pt_PKG_CONFIG=$PKG_CONFIG + # Extract the first word of "pkg-config", so it can be a program name with args. +set dummy pkg-config; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_path_ac_pt_PKG_CONFIG+y} +then : + printf %s "(cached) " >&6 +else $as_nop + case $ac_pt_PKG_CONFIG in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_PKG_CONFIG="$ac_pt_PKG_CONFIG" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_PKG_CONFIG="$as_dir$ac_word$ac_exec_ext" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_PKG_CONFIG=$ac_cv_path_ac_pt_PKG_CONFIG +if test -n "$ac_pt_PKG_CONFIG"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_pt_PKG_CONFIG" >&5 +printf "%s\n" "$ac_pt_PKG_CONFIG" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi + + if test "x$ac_pt_PKG_CONFIG" = x; then + PKG_CONFIG="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + PKG_CONFIG=$ac_pt_PKG_CONFIG + fi +else + PKG_CONFIG="$ac_cv_path_PKG_CONFIG" +fi + +fi +if test -n "$PKG_CONFIG"; then + _pkg_min_version=0.9.0 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking pkg-config is at least version $_pkg_min_version" >&5 +printf %s "checking pkg-config is at least version $_pkg_min_version... " >&6; } + if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } + else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } + PKG_CONFIG="" + fi +fi + if test X$PKG_CONFIG = X +then : + break +fi + + _AX_LIB_POSTGRESQL_PKG_CONFIG_fail=no; + if test "X$postgresql_version_req" = "X" +then : + if test -n "$PKG_CONFIG" && \ + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libpq\""; } >&5 + ($PKG_CONFIG --exists --print-errors "libpq") 2>&5 + ac_status=$? + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + found_postgresql_pkg_config=yes +else + found_postgresql=no +fi +else $as_nop + if test -n "$PKG_CONFIG" && \ + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libpq >= \"\$postgresql_version_req\"\""; } >&5 + ($PKG_CONFIG --exists --print-errors "libpq >= "$postgresql_version_req"") 2>&5 + ac_status=$? + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + found_postgresql=yes +else + found_postgresql=no +fi +fi + if test "X$found_postgresql" = "Xno" +then : + break +fi + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for the PostgreSQL libraries CPPFLAGS" >&5 +printf %s "checking for the PostgreSQL libraries CPPFLAGS... " >&6; } +if test ${ac_cv_POSTGRESQL_CPPFLAGS+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_cv_POSTGRESQL_CPPFLAGS="`$PKG_CONFIG libpq --cflags-only-I`" || _AX_LIB_POSTGRESQL_PKG_CONFIG_fail=yes +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_POSTGRESQL_CPPFLAGS" >&5 +printf "%s\n" "$ac_cv_POSTGRESQL_CPPFLAGS" >&6; } + if test "X$_AX_LIB_POSTGRESQL_PKG_CONFIG_fail" = "Xyes" +then : + break +fi + POSTGRESQL_CPPFLAGS="$ac_cv_POSTGRESQL_CPPFLAGS" + + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for the PostgreSQL libraries LDFLAGS" >&5 +printf %s "checking for the PostgreSQL libraries LDFLAGS... " >&6; } +if test ${ac_cv_POSTGRESQL_LDFLAGS+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_cv_POSTGRESQL_LDFLAGS="`$PKG_CONFIG libpq --libs-only-L --libs-only-other`" || _AX_LIB_POSTGRESQL_PKG_CONFIG_fail=yes +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_POSTGRESQL_LDFLAGS" >&5 +printf "%s\n" "$ac_cv_POSTGRESQL_LDFLAGS" >&6; } + if test "X$_AX_LIB_POSTGRESQL_PKG_CONFIG_fail" = "Xyes" +then : + break +fi + POSTGRESQL_LDFLAGS="$ac_cv_POSTGRESQL_LDFLAGS" + + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for the PostgreSQL libraries LIBS" >&5 +printf %s "checking for the PostgreSQL libraries LIBS... " >&6; } +if test ${ac_cv_POSTGRESQL_LIBS+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_cv_POSTGRESQL_LIBS="`$PKG_CONFIG libpq --libs-only-l`" || _AX_LIB_POSTGRESQL_PKG_CONFIG_fail=ye +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_POSTGRESQL_LIBS" >&5 +printf "%s\n" "$ac_cv_POSTGRESQL_LIBS" >&6; } + if test "X$_AX_LIB_POSTGRESQL_PKG_CONFIG_fail" = "Xyes" +then : + break +fi + POSTGRESQL_LIBS="$ac_cv_POSTGRESQL_LIBS" + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for the PostgreSQL version" >&5 +printf %s "checking for the PostgreSQL version... " >&6; } +if test ${ac_cv_POSTGRESQL_VERSION+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_cv_POSTGRESQL_VERSION="`$PKG_CONFIG libpq --modversion`" || _AX_LIB_POSTGRESQL_PKG_CONFIG_fail=yes +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_POSTGRESQL_VERSION" >&5 +printf "%s\n" "$ac_cv_POSTGRESQL_VERSION" >&6; } + if test "X$_AX_LIB_POSTGRESQL_PKG_CONFIG_fail" = "Xyes" +then : + break +fi + POSTGRESQL_VERSION="$ac_cv_POSTGRESQL_VERSION" + + found_postgresql=yes + break; + done + + + + + if test X"$found_postgresql" = "Xno" +then : + + found_postgresql="no" + _AX_LIB_POSTGRESQL_OLD_fail="no" + while true; do + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for the pg_config program" >&5 +printf %s "checking for the pg_config program... " >&6; } +if test ${ac_cv_path_PG_CONFIG+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if test -z "$PG_CONFIG"; then + ac_path_PG_CONFIG_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_prog in pg_config + do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_PG_CONFIG="$as_dir$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_PG_CONFIG" || continue +ac_cv_path_PG_CONFIG="";"$ac_path_PG_CONFIG" --includedir > /dev/null \ + && ac_cv_path_PG_CONFIG="$ac_path_PG_CONFIG" ac_path_PG_CONFIG_found=: + $ac_path_PG_CONFIG_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_PG_CONFIG"; then + ac_cv_path_PG_CONFIG="" + fi +else + ac_cv_path_PG_CONFIG=$PG_CONFIG +fi + +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_PG_CONFIG" >&5 +printf "%s\n" "$ac_cv_path_PG_CONFIG" >&6; } + PG_CONFIG="$ac_cv_path_PG_CONFIG" + if test "X$PG_CONFIG" = "X" +then : + break +fi + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for the PostgreSQL libraries CPPFLAGS" >&5 +printf %s "checking for the PostgreSQL libraries CPPFLAGS... " >&6; } +if test ${ac_cv_POSTGRESQL_CPPFLAGS+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_cv_POSTGRESQL_CPPFLAGS="-I`"$PG_CONFIG" --includedir`" || _AX_LIB_POSTGRESQL_OLD_fail=yes +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_POSTGRESQL_CPPFLAGS" >&5 +printf "%s\n" "$ac_cv_POSTGRESQL_CPPFLAGS" >&6; } + if test "X$_AX_LIB_POSTGRESQL_OLD_fail" = "Xyes" +then : + break +fi + POSTGRESQL_CPPFLAGS="$ac_cv_POSTGRESQL_CPPFLAGS" + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for the PostgreSQL libraries LDFLAGS" >&5 +printf %s "checking for the PostgreSQL libraries LDFLAGS... " >&6; } +if test ${ac_cv_POSTGRESQL_LDFLAGS+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_cv_POSTGRESQL_LDFLAGS="-L`"$PG_CONFIG" --libdir`" || _AX_LIB_POSTGRESQL_OLD_fail=yes +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_POSTGRESQL_LDFLAGS" >&5 +printf "%s\n" "$ac_cv_POSTGRESQL_LDFLAGS" >&6; } + if test "X$_AX_LIB_POSTGRESQL_OLD_fail" = "Xyes" +then : + break +fi + POSTGRESQL_LDFLAGS="$ac_cv_POSTGRESQL_LDFLAGS" + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for the PostgreSQL libraries LIBS" >&5 +printf %s "checking for the PostgreSQL libraries LIBS... " >&6; } +if test ${ac_cv_POSTGRESQL_LIBS+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_cv_POSTGRESQL_LIBS="-lpq" +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_POSTGRESQL_LIBS" >&5 +printf "%s\n" "$ac_cv_POSTGRESQL_LIBS" >&6; } + POSTGRESQL_LIBS="$ac_cv_POSTGRESQL_LIBS" + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for the PostgreSQL version" >&5 +printf %s "checking for the PostgreSQL version... " >&6; } +if test ${ac_cv_POSTGRESQL_VERSION+y} +then : + printf %s "(cached) " >&6 +else $as_nop + + ac_cv_POSTGRESQL_VERSION=`"$PG_CONFIG" --version | sed "s/^PostgreSQL[[:space:]][[:space:]]*\([0-9.][0-9.]*\).*/\1/"` \ + || _AX_LIB_POSTGRESQL_OLD_fail=yes + +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_POSTGRESQL_VERSION" >&5 +printf "%s\n" "$ac_cv_POSTGRESQL_VERSION" >&6; } + if test "X$_AX_LIB_POSTGRESQL_OLD_fail" = "Xyes" +then : + break +fi + POSTGRESQL_VERSION="$ac_cv_POSTGRESQL_VERSION" + + + if test X"$postgresql_version_req" != "X" +then : + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if PostgreSQL version $POSTGRESQL_VERSION is >= $postgresql_version_req" >&5 +printf %s "checking if PostgreSQL version $POSTGRESQL_VERSION is >= $postgresql_version_req... " >&6; } + + + + # Used to indicate true or false condition + ax_compare_version=false + + # Convert the two version strings to be compared into a format that + # allows a simple string comparison. The end result is that a version + # string of the form 1.12.5-r617 will be converted to the form + # 0001001200050617. In other words, each number is zero padded to four + # digits, and non digits are removed. + + ax_compare_version_A=`echo "$POSTGRESQL_VERSION" | sed -e 's/\([0-9]*\)/Z\1Z/g' \ + -e 's/Z\([0-9]\)Z/Z0\1Z/g' \ + -e 's/Z\([0-9][0-9]\)Z/Z0\1Z/g' \ + -e 's/Z\([0-9][0-9][0-9]\)Z/Z0\1Z/g' \ + -e 's/[^0-9]//g'` + + + ax_compare_version_B=`echo "$postgresql_version_req" | sed -e 's/\([0-9]*\)/Z\1Z/g' \ + -e 's/Z\([0-9]\)Z/Z0\1Z/g' \ + -e 's/Z\([0-9][0-9]\)Z/Z0\1Z/g' \ + -e 's/Z\([0-9][0-9][0-9]\)Z/Z0\1Z/g' \ + -e 's/[^0-9]//g'` + + + ax_compare_version=`echo "x$ax_compare_version_A +x$ax_compare_version_B" | sed 's/^ *//' | sort -r | sed "s/x${ax_compare_version_A}/true/;s/x${ax_compare_version_B}/false/;1q"` + + + + if test "$ax_compare_version" = "true" ; then + found_postgresql_req_version=yes + else found_postgresql_req_version=no + fi + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $found_postgresql_req_version" >&5 +printf "%s\n" "$found_postgresql_req_version" >&6; } + +fi + if test "X$found_postgresql_req_version" = "Xno" +then : + break +fi + + found_postgresql="yes" + break + done + +fi + + if test X"$found_postgresql" = Xyes +then : + + _AX_LIB_POSTGRESQL_OLD_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $POSTGRESQL_CPPFLAGS" + _AX_LIB_POSTGRESQL_OLD_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS $POSTGRESQL_LDFLAGS" + _AX_LIB_POSTGRESQL_OLD_LIBS="$LIBS" + LIBS="$LIBS $POSTGRESQL_LIBS" + while true; do + ac_fn_c_check_header_compile "$LINENO" "libpq-fe.h" "ac_cv_header_libpq_fe_h" "$ac_includes_default" +if test "x$ac_cv_header_libpq_fe_h" = xyes +then : + +else $as_nop + found_postgresql=no +fi + + if test "X$found_postgresql" = "Xno" +then : + break +fi + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for the PostgreSQL library linking is working" >&5 +printf %s "checking for the PostgreSQL library linking is working... " >&6; } +if test ${ac_cv_postgresql_found+y} +then : + printf %s "(cached) " >&6 +else $as_nop + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + + #include + +int +main (void) +{ + + char conninfo[]="dbname = postgres"; + PGconn *conn; + conn = PQconnectdb(conninfo); + + + ; + return 0; +} + +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + ac_cv_postgresql_found=yes +else $as_nop + ac_cv_postgresql_found=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext + +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_postgresql_found" >&5 +printf "%s\n" "$ac_cv_postgresql_found" >&6; } + found_postgresql="$ac_cv_postgresql_found" + if test "X$found_postgresql" = "Xno" +then : + break +fi + break + done + CPPFLAGS="$_AX_LIB_POSTGRESQL_OLD_CPPFLAGS" + LDFLAGS="$_AX_LIB_POSTGRESQL_OLD_LDFLAGS" + LIBS="$_AX_LIB_POSTGRESQL_OLD_LIBS" + +fi + + + if test "x$found_postgresql" = "xyes" +then : + + +printf "%s\n" "#define HAVE_POSTGRESQL 1" >>confdefs.h + +fi + +fi + + + + + + + if test "x$found_postgresql" = "xyes" +then : + : +else $as_nop + if test X"$want_postgresql" = "Xyes" +then : + as_fn_error $? "Library requirements (PostgreSQL) not met." "$LINENO" 5 +else $as_nop + : +fi +fi + + + +POSTGRESQL_EXTRA_LIBS="pq" +POSTGRESQL_LIBDIR=$(echo "$POSTGRESQL_LDFLAGS"|$SED 's/-L//') +POSTGRESQL_INCLUDEDIR=$(echo "$POSTGRESQL_CPPFLAGS"|$SED 's/-I//') + + + + + +ac_config_files="$ac_config_files postgresql-libpq-configure.buildinfo" + + +cat >confcache <<\_ACEOF +# This file is a shell script that caches the results of configure +# tests run on this system so they can be shared between configure +# scripts and configure runs, see configure's option --config-cache. +# It is not useful on other systems. If it contains results you don't +# want to keep, you may remove or edit it. +# +# config.status only pays attention to the cache file if you give it +# the --recheck option to rerun configure. +# +# `ac_cv_env_foo' variables (set or unset) will be overridden when +# loading this file, other *unset* `ac_cv_foo' will be assigned the +# following values. + +_ACEOF + +# The following way of writing the cache mishandles newlines in values, +# but we know of no workaround that is simple, portable, and efficient. +# So, we kill variables containing newlines. +# Ultrix sh set writes to stderr and can't be redirected directly, +# and sets the high bit in the cache file unless we assign to the vars. +( + for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( + *) { eval $ac_var=; unset $ac_var;} ;; + esac ;; + esac + done + + (set) 2>&1 | + case $as_nl`(ac_space=' '; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + # `set' does not quote correctly, so add quotes: double-quote + # substitution turns \\\\ into \\, and sed turns \\ into \. + sed -n \ + "s/'/'\\\\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" + ;; #( + *) + # `set' quotes correctly as required by POSIX, so do not add quotes. + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) | + sed ' + /^ac_cv_env_/b end + t clear + :clear + s/^\([^=]*\)=\(.*[{}].*\)$/test ${\1+y} || &/ + t end + s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ + :end' >>confcache +if diff "$cache_file" confcache >/dev/null 2>&1; then :; else + if test -w "$cache_file"; then + if test "x$cache_file" != "x/dev/null"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 +printf "%s\n" "$as_me: updating cache $cache_file" >&6;} + if test ! -f "$cache_file" || test -h "$cache_file"; then + cat confcache >"$cache_file" + else + case $cache_file in #( + */* | ?:*) + mv -f confcache "$cache_file"$$ && + mv -f "$cache_file"$$ "$cache_file" ;; #( + *) + mv -f confcache "$cache_file" ;; + esac + fi + fi + else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 +printf "%s\n" "$as_me: not updating unwritable cache $cache_file" >&6;} + fi +fi +rm -f confcache + +test "x$prefix" = xNONE && prefix=$ac_default_prefix +# Let make expand exec_prefix. +test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' + +# Transform confdefs.h into DEFS. +# Protect against shell expansion while executing Makefile rules. +# Protect against Makefile macro expansion. +# +# If the first sed substitution is executed (which looks for macros that +# take arguments), then branch to the quote section. Otherwise, +# look for a macro that doesn't take arguments. +ac_script=' +:mline +/\\$/{ + N + s,\\\n,, + b mline +} +t clear +:clear +s/^[ ]*#[ ]*define[ ][ ]*\([^ (][^ (]*([^)]*)\)[ ]*\(.*\)/-D\1=\2/g +t quote +s/^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\)/-D\1=\2/g +t quote +b any +:quote +s/[ `~#$^&*(){}\\|;'\''"<>?]/\\&/g +s/\[/\\&/g +s/\]/\\&/g +s/\$/$$/g +H +:any +${ + g + s/^\n// + s/\n/ /g + p +} +' +DEFS=`sed -n "$ac_script" confdefs.h` + + +ac_libobjs= +ac_ltlibobjs= +U= +for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue + # 1. Remove the extension, and $U if already installed. + ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' + ac_i=`printf "%s\n" "$ac_i" | sed "$ac_script"` + # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR + # will be set to the directory where LIBOBJS objects are built. + as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext" + as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo' +done +LIBOBJS=$ac_libobjs + +LTLIBOBJS=$ac_ltlibobjs + + + +: "${CONFIG_STATUS=./config.status}" +ac_write_fail=0 +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files $CONFIG_STATUS" +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 +printf "%s\n" "$as_me: creating $CONFIG_STATUS" >&6;} +as_write_fail=0 +cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 +#! $SHELL +# Generated by $as_me. +# Run this file to recreate the current configuration. +# Compiler output produced by configure, useful for debugging +# configure, is in config.log if it exists. + +debug=false +ac_cs_recheck=false +ac_cs_silent=false + +SHELL=\${CONFIG_SHELL-$SHELL} +export SHELL +_ASEOF +cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 +## -------------------- ## +## M4sh Initialization. ## +## -------------------- ## + +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +as_nop=: +if test ${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1 +then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else $as_nop + case `(set -o) 2>/dev/null` in #( + *posix*) : + set -o posix ;; #( + *) : + ;; +esac +fi + + + +# Reset variables that may have inherited troublesome values from +# the environment. + +# IFS needs to be set, to space, tab, and newline, in precisely that order. +# (If _AS_PATH_WALK were called with IFS unset, it would have the +# side effect of setting IFS to empty, thus disabling word splitting.) +# Quoting is to prevent editors from complaining about space-tab. +as_nl=' +' +export as_nl +IFS=" "" $as_nl" + +PS1='$ ' +PS2='> ' +PS4='+ ' + +# Ensure predictable behavior from utilities with locale-dependent output. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# We cannot yet rely on "unset" to work, but we need these variables +# to be unset--not just set to an empty or harmless value--now, to +# avoid bugs in old shells (e.g. pre-3.0 UWIN ksh). This construct +# also avoids known problems related to "unset" and subshell syntax +# in other old shells (e.g. bash 2.01 and pdksh 5.2.14). +for as_var in BASH_ENV ENV MAIL MAILPATH CDPATH +do eval test \${$as_var+y} \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done + +# Ensure that fds 0, 1, and 2 are open. +if (exec 3>&0) 2>/dev/null; then :; else exec 0&1) 2>/dev/null; then :; else exec 1>/dev/null; fi +if (exec 3>&2) ; then :; else exec 2>/dev/null; fi + +# The user is always right. +if ${PATH_SEPARATOR+false} :; then + PATH_SEPARATOR=: + (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { + (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || + PATH_SEPARATOR=';' + } +fi + + +# Find who we are. Look in the path if we contain no directory separator. +as_myself= +case $0 in #(( + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + test -r "$as_dir$0" && as_myself=$as_dir$0 && break + done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + printf "%s\n" "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + exit 1 +fi + + + +# as_fn_error STATUS ERROR [LINENO LOG_FD] +# ---------------------------------------- +# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are +# provided, also output the error to LOG_FD, referencing LINENO. Then exit the +# script with STATUS, using 1 if that was 0. +as_fn_error () +{ + as_status=$1; test $as_status -eq 0 && as_status=1 + if test "$4"; then + as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 + fi + printf "%s\n" "$as_me: error: $2" >&2 + as_fn_exit $as_status +} # as_fn_error + + + +# as_fn_set_status STATUS +# ----------------------- +# Set $? to STATUS, without forking. +as_fn_set_status () +{ + return $1 +} # as_fn_set_status + +# as_fn_exit STATUS +# ----------------- +# Exit the shell with STATUS, even in a "trap 0" or "set -e" context. +as_fn_exit () +{ + set +e + as_fn_set_status $1 + exit $1 +} # as_fn_exit + +# as_fn_unset VAR +# --------------- +# Portably unset VAR. +as_fn_unset () +{ + { eval $1=; unset $1;} +} +as_unset=as_fn_unset + +# as_fn_append VAR VALUE +# ---------------------- +# Append the text in VALUE to the end of the definition contained in VAR. Take +# advantage of any shell optimizations that allow amortized linear growth over +# repeated appends, instead of the typical quadratic growth present in naive +# implementations. +if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null +then : + eval 'as_fn_append () + { + eval $1+=\$2 + }' +else $as_nop + as_fn_append () + { + eval $1=\$$1\$2 + } +fi # as_fn_append + +# as_fn_arith ARG... +# ------------------ +# Perform arithmetic evaluation on the ARGs, and store the result in the +# global $as_val. Take advantage of shells that can avoid forks. The arguments +# must be portable across $(()) and expr. +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null +then : + eval 'as_fn_arith () + { + as_val=$(( $* )) + }' +else $as_nop + as_fn_arith () + { + as_val=`expr "$@" || test $? -eq 1` + } +fi # as_fn_arith + + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +printf "%s\n" X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + + +# Determine whether it's possible to make 'echo' print without a newline. +# These variables are no longer used directly by Autoconf, but are AC_SUBSTed +# for compatibility with existing Makefiles. +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in #((((( +-n*) + case `echo 'xy\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + xy) ECHO_C='\c';; + *) echo `echo ksh88 bug on AIX 6.1` > /dev/null + ECHO_T=' ';; + esac;; +*) + ECHO_N='-n';; +esac + +# For backward compatibility with old third-party macros, we provide +# the shell variables $as_echo and $as_echo_n. New code should use +# AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively. +as_echo='printf %s\n' +as_echo_n='printf %s' + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir 2>/dev/null +fi +if (echo >conf$$.file) 2>/dev/null; then + if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -pR'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -pR' + elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln + else + as_ln_s='cp -pR' + fi +else + as_ln_s='cp -pR' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + + +# as_fn_mkdir_p +# ------------- +# Create "$as_dir" as a directory, including parents if necessary. +as_fn_mkdir_p () +{ + + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || eval $as_mkdir_p || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`printf "%s\n" "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +printf "%s\n" X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" + + +} # as_fn_mkdir_p +if mkdir -p . 2>/dev/null; then + as_mkdir_p='mkdir -p "$as_dir"' +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + + +# as_fn_executable_p FILE +# ----------------------- +# Test if FILE is an executable regular file. +as_fn_executable_p () +{ + test -f "$1" && test -x "$1" +} # as_fn_executable_p +as_test_x='test -x' +as_executable_p=as_fn_executable_p + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + +exec 6>&1 +## ----------------------------------- ## +## Main body of $CONFIG_STATUS script. ## +## ----------------------------------- ## +_ASEOF +test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# Save the log message, to keep $0 and so on meaningful, and to +# report actual input values of CONFIG_FILES etc. instead of their +# values after options handling. +ac_log=" +This file was extended by Haskell PostgreSQL bindings $as_me 0.10, which was +generated by GNU Autoconf 2.71. Invocation command line was + + CONFIG_FILES = $CONFIG_FILES + CONFIG_HEADERS = $CONFIG_HEADERS + CONFIG_LINKS = $CONFIG_LINKS + CONFIG_COMMANDS = $CONFIG_COMMANDS + $ $0 $@ + +on `(hostname || uname -n) 2>/dev/null | sed 1q` +" + +_ACEOF + +case $ac_config_files in *" +"*) set x $ac_config_files; shift; ac_config_files=$*;; +esac + + + +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +# Files that config.status was made for. +config_files="$ac_config_files" + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +ac_cs_usage="\ +\`$as_me' instantiates files and other configuration actions +from templates according to the current configuration. Unless the files +and actions are specified as TAGs, all are instantiated by default. + +Usage: $0 [OPTION]... [TAG]... + + -h, --help print this help, then exit + -V, --version print version number and configuration settings, then exit + --config print configuration, then exit + -q, --quiet, --silent + do not print progress messages + -d, --debug don't remove temporary files + --recheck update $as_me by reconfiguring in the same conditions + --file=FILE[:TEMPLATE] + instantiate the configuration file FILE + +Configuration files: +$config_files + +Report bugs to ." + +_ACEOF +ac_cs_config=`printf "%s\n" "$ac_configure_args" | sed "$ac_safe_unquote"` +ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\''/g"` +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +ac_cs_config='$ac_cs_config_escaped' +ac_cs_version="\\ +Haskell PostgreSQL bindings config.status 0.10 +configured by $0, generated by GNU Autoconf 2.71, + with options \\"\$ac_cs_config\\" + +Copyright (C) 2021 Free Software Foundation, Inc. +This config.status script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it." + +ac_pwd='$ac_pwd' +srcdir='$srcdir' +AWK='$AWK' +test -n "\$AWK" || AWK=awk +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# The default lists apply if the user does not specify any file. +ac_need_defaults=: +while test $# != 0 +do + case $1 in + --*=?*) + ac_option=`expr "X$1" : 'X\([^=]*\)='` + ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` + ac_shift=: + ;; + --*=) + ac_option=`expr "X$1" : 'X\([^=]*\)='` + ac_optarg= + ac_shift=: + ;; + *) + ac_option=$1 + ac_optarg=$2 + ac_shift=shift + ;; + esac + + case $ac_option in + # Handling of the options. + -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) + ac_cs_recheck=: ;; + --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) + printf "%s\n" "$ac_cs_version"; exit ;; + --config | --confi | --conf | --con | --co | --c ) + printf "%s\n" "$ac_cs_config"; exit ;; + --debug | --debu | --deb | --de | --d | -d ) + debug=: ;; + --file | --fil | --fi | --f ) + $ac_shift + case $ac_optarg in + *\'*) ac_optarg=`printf "%s\n" "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; + '') as_fn_error $? "missing file argument" ;; + esac + as_fn_append CONFIG_FILES " '$ac_optarg'" + ac_need_defaults=false;; + --he | --h | --help | --hel | -h ) + printf "%s\n" "$ac_cs_usage"; exit ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil | --si | --s) + ac_cs_silent=: ;; + + # This is an error. + -*) as_fn_error $? "unrecognized option: \`$1' +Try \`$0 --help' for more information." ;; + + *) as_fn_append ac_config_targets " $1" + ac_need_defaults=false ;; + + esac + shift +done + +ac_configure_extra_args= + +if $ac_cs_silent; then + exec 6>/dev/null + ac_configure_extra_args="$ac_configure_extra_args --silent" +fi + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +if \$ac_cs_recheck; then + set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion + shift + \printf "%s\n" "running CONFIG_SHELL=$SHELL \$*" >&6 + CONFIG_SHELL='$SHELL' + export CONFIG_SHELL + exec "\$@" +fi + +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +exec 5>>config.log +{ + echo + sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX +## Running $as_me. ## +_ASBOX + printf "%s\n" "$ac_log" +} >&5 + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 + +# Handling of arguments. +for ac_config_target in $ac_config_targets +do + case $ac_config_target in + "postgresql-libpq-configure.buildinfo") CONFIG_FILES="$CONFIG_FILES postgresql-libpq-configure.buildinfo" ;; + + *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; + esac +done + + +# If the user did not use the arguments to specify the items to instantiate, +# then the envvar interface is used. Set only those that are not. +# We use the long form for the default assignment because of an extremely +# bizarre bug on SunOS 4.1.3. +if $ac_need_defaults; then + test ${CONFIG_FILES+y} || CONFIG_FILES=$config_files +fi + +# Have a temporary directory for convenience. Make it in the build tree +# simply because there is no reason against having it here, and in addition, +# creating and moving files from /tmp can sometimes cause problems. +# Hook for its removal unless debugging. +# Note that there is a small window in which the directory will not be cleaned: +# after its creation but before its name has been assigned to `$tmp'. +$debug || +{ + tmp= ac_tmp= + trap 'exit_status=$? + : "${ac_tmp:=$tmp}" + { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status +' 0 + trap 'as_fn_exit 1' 1 2 13 15 +} +# Create a (secure) tmp directory for tmp files. + +{ + tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && + test -d "$tmp" +} || +{ + tmp=./conf$$-$RANDOM + (umask 077 && mkdir "$tmp") +} || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5 +ac_tmp=$tmp + +# Set up the scripts for CONFIG_FILES section. +# No need to generate them if there are no CONFIG_FILES. +# This happens for instance with `./config.status config.h'. +if test -n "$CONFIG_FILES"; then + + +ac_cr=`echo X | tr X '\015'` +# On cygwin, bash can eat \r inside `` if the user requested igncr. +# But we know of no other shell where ac_cr would be empty at this +# point, so we can use a bashism as a fallback. +if test "x$ac_cr" = x; then + eval ac_cr=\$\'\\r\' +fi +ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null` +if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then + ac_cs_awk_cr='\\r' +else + ac_cs_awk_cr=$ac_cr +fi + +echo 'BEGIN {' >"$ac_tmp/subs1.awk" && +_ACEOF + + +{ + echo "cat >conf$$subs.awk <<_ACEOF" && + echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' && + echo "_ACEOF" +} >conf$$subs.sh || + as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 +ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'` +ac_delim='%!_!# ' +for ac_last_try in false false false false false :; do + . ./conf$$subs.sh || + as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 + + ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X` + if test $ac_delim_n = $ac_delim_num; then + break + elif $ac_last_try; then + as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 + else + ac_delim="$ac_delim!$ac_delim _$ac_delim!! " + fi +done +rm -f conf$$subs.sh + +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK && +_ACEOF +sed -n ' +h +s/^/S["/; s/!.*/"]=/ +p +g +s/^[^!]*!// +:repl +t repl +s/'"$ac_delim"'$// +t delim +:nl +h +s/\(.\{148\}\)..*/\1/ +t more1 +s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/ +p +n +b repl +:more1 +s/["\\]/\\&/g; s/^/"/; s/$/"\\/ +p +g +s/.\{148\}// +t nl +:delim +h +s/\(.\{148\}\)..*/\1/ +t more2 +s/["\\]/\\&/g; s/^/"/; s/$/"/ +p +b +:more2 +s/["\\]/\\&/g; s/^/"/; s/$/"\\/ +p +g +s/.\{148\}// +t delim +' >$CONFIG_STATUS || ac_write_fail=1 +rm -f conf$$subs.awk +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +_ACAWK +cat >>"\$ac_tmp/subs1.awk" <<_ACAWK && + for (key in S) S_is_set[key] = 1 + FS = "" + +} +{ + line = $ 0 + nfields = split(line, field, "@") + substed = 0 + len = length(field[1]) + for (i = 2; i < nfields; i++) { + key = field[i] + keylen = length(key) + if (S_is_set[key]) { + value = S[key] + line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3) + len += length(value) + length(field[++i]) + substed = 1 + } else + len += 1 + keylen + } + + print line +} + +_ACAWK +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then + sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g" +else + cat +fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \ + || as_fn_error $? "could not setup config files machinery" "$LINENO" 5 +_ACEOF + +# VPATH may cause trouble with some makes, so we remove sole $(srcdir), +# ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and +# trailing colons and then remove the whole line if VPATH becomes empty +# (actually we leave an empty line to preserve line numbers). +if test "x$srcdir" = x.; then + ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{ +h +s/// +s/^/:/ +s/[ ]*$/:/ +s/:\$(srcdir):/:/g +s/:\${srcdir}:/:/g +s/:@srcdir@:/:/g +s/^:*// +s/:*$// +x +s/\(=[ ]*\).*/\1/ +G +s/\n// +s/^[^=]*=[ ]*$// +}' +fi + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +fi # test -n "$CONFIG_FILES" + + +eval set X " :F $CONFIG_FILES " +shift +for ac_tag +do + case $ac_tag in + :[FHLC]) ac_mode=$ac_tag; continue;; + esac + case $ac_mode$ac_tag in + :[FHL]*:*);; + :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;; + :[FH]-) ac_tag=-:-;; + :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; + esac + ac_save_IFS=$IFS + IFS=: + set x $ac_tag + IFS=$ac_save_IFS + shift + ac_file=$1 + shift + + case $ac_mode in + :L) ac_source=$1;; + :[FH]) + ac_file_inputs= + for ac_f + do + case $ac_f in + -) ac_f="$ac_tmp/stdin";; + *) # Look for the file first in the build tree, then in the source tree + # (if the path is not absolute). The absolute path cannot be DOS-style, + # because $ac_f cannot contain `:'. + test -f "$ac_f" || + case $ac_f in + [\\/$]*) false;; + *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; + esac || + as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;; + esac + case $ac_f in *\'*) ac_f=`printf "%s\n" "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac + as_fn_append ac_file_inputs " '$ac_f'" + done + + # Let's still pretend it is `configure' which instantiates (i.e., don't + # use $as_me), people would be surprised to read: + # /* config.h. Generated by config.status. */ + configure_input='Generated from '` + printf "%s\n" "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' + `' by configure.' + if test x"$ac_file" != x-; then + configure_input="$ac_file. $configure_input" + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 +printf "%s\n" "$as_me: creating $ac_file" >&6;} + fi + # Neutralize special characters interpreted by sed in replacement strings. + case $configure_input in #( + *\&* | *\|* | *\\* ) + ac_sed_conf_input=`printf "%s\n" "$configure_input" | + sed 's/[\\\\&|]/\\\\&/g'`;; #( + *) ac_sed_conf_input=$configure_input;; + esac + + case $ac_tag in + *:-:* | *:-) cat >"$ac_tmp/stdin" \ + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; + esac + ;; + esac + + ac_dir=`$as_dirname -- "$ac_file" || +$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$ac_file" : 'X\(//\)[^/]' \| \ + X"$ac_file" : 'X\(//\)$' \| \ + X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || +printf "%s\n" X"$ac_file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + as_dir="$ac_dir"; as_fn_mkdir_p + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`printf "%s\n" "$ac_dir" | sed 's|^\.[\\/]||'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`printf "%s\n" "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + + case $ac_mode in + :F) + # + # CONFIG_FILE + # + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# If the template does not know about datarootdir, expand it. +# FIXME: This hack should be removed a few years after 2.60. +ac_datarootdir_hack=; ac_datarootdir_seen= +ac_sed_dataroot=' +/datarootdir/ { + p + q +} +/@datadir@/p +/@docdir@/p +/@infodir@/p +/@localedir@/p +/@mandir@/p' +case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in +*datarootdir*) ac_datarootdir_seen=yes;; +*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 +printf "%s\n" "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 + ac_datarootdir_hack=' + s&@datadir@&$datadir&g + s&@docdir@&$docdir&g + s&@infodir@&$infodir&g + s&@localedir@&$localedir&g + s&@mandir@&$mandir&g + s&\\\${datarootdir}&$datarootdir&g' ;; +esac +_ACEOF + +# Neutralize VPATH when `$srcdir' = `.'. +# Shell code in configure.ac might set extrasub. +# FIXME: do we really want to maintain this feature? +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +ac_sed_extra="$ac_vpsub +$extrasub +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +:t +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b +s|@configure_input@|$ac_sed_conf_input|;t t +s&@top_builddir@&$ac_top_builddir_sub&;t t +s&@top_build_prefix@&$ac_top_build_prefix&;t t +s&@srcdir@&$ac_srcdir&;t t +s&@abs_srcdir@&$ac_abs_srcdir&;t t +s&@top_srcdir@&$ac_top_srcdir&;t t +s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t +s&@builddir@&$ac_builddir&;t t +s&@abs_builddir@&$ac_abs_builddir&;t t +s&@abs_top_builddir@&$ac_abs_top_builddir&;t t +$ac_datarootdir_hack +" +eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \ + >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5 + +test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && + { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } && + { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \ + "$ac_tmp/out"`; test -z "$ac_out"; } && + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined" >&5 +printf "%s\n" "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined" >&2;} + + rm -f "$ac_tmp/stdin" + case $ac_file in + -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";; + *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";; + esac \ + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 + ;; + + + + esac + +done # for ac_tag + + +as_fn_exit 0 +_ACEOF +ac_clean_files=$ac_clean_files_save + +test $ac_write_fail = 0 || + as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5 + + +# configure is writing to config.log, and then calls config.status. +# config.status does its own redirection, appending to config.log. +# Unfortunately, on DOS this fails, as config.log is still kept open +# by configure, so config.status won't be able to write to it; its +# output is simply discarded. So we exec the FD to /dev/null, +# effectively closing config.log, so it can be properly (re)opened and +# appended to by config.status. When coming back to configure, we +# need to make the FD available again. +if test "$no_create" != yes; then + ac_cs_success=: + ac_config_status_args= + test "$silent" = yes && + ac_config_status_args="$ac_config_status_args --quiet" + exec 5>/dev/null + $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false + exec 5>>config.log + # Use ||, not &&, to avoid exiting from the if with $? = 1, which + # would make configure fail if this is the last instruction. + $ac_cs_success || as_fn_exit 1 +fi +if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 +printf "%s\n" "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} +fi + + diff --git a/postgresql-libpq-configure/configure.ac b/postgresql-libpq-configure/configure.ac new file mode 100644 index 0000000..56352e8 --- /dev/null +++ b/postgresql-libpq-configure/configure.ac @@ -0,0 +1,20 @@ +AC_PREREQ([2.69]) +AC_INIT([Haskell PostgreSQL bindings],[0.10],[oleg.grenrus@iki.fi],[the-url]) +AC_CONFIG_MACRO_DIRS([m4]) + +AC_PROG_CC +AC_PROG_SED + +AX_LIB_POSTGRESQL([14.12]) + +POSTGRESQL_EXTRA_LIBS="pq" +POSTGRESQL_LIBDIR=$(echo "$POSTGRESQL_LDFLAGS"|$SED 's/-L//') +POSTGRESQL_INCLUDEDIR=$(echo "$POSTGRESQL_CPPFLAGS"|$SED 's/-I//') + +AC_SUBST([POSTGRESQL_EXTRA_LIBS]) +AC_SUBST([POSTGRESQL_LIBDIR]) +AC_SUBST([POSTGRESQL_INCLUDEDIR]) + +AC_CONFIG_FILES([postgresql-libpq-configure.buildinfo]) + +AC_OUTPUT diff --git a/postgresql-libpq-configure/m4/ax_compare_version.m4 b/postgresql-libpq-configure/m4/ax_compare_version.m4 new file mode 100644 index 0000000..ffb4997 --- /dev/null +++ b/postgresql-libpq-configure/m4/ax_compare_version.m4 @@ -0,0 +1,177 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_compare_version.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_COMPARE_VERSION(VERSION_A, OP, VERSION_B, [ACTION-IF-TRUE], [ACTION-IF-FALSE]) +# +# DESCRIPTION +# +# This macro compares two version strings. Due to the various number of +# minor-version numbers that can exist, and the fact that string +# comparisons are not compatible with numeric comparisons, this is not +# necessarily trivial to do in a autoconf script. This macro makes doing +# these comparisons easy. +# +# The six basic comparisons are available, as well as checking equality +# limited to a certain number of minor-version levels. +# +# The operator OP determines what type of comparison to do, and can be one +# of: +# +# eq - equal (test A == B) +# ne - not equal (test A != B) +# le - less than or equal (test A <= B) +# ge - greater than or equal (test A >= B) +# lt - less than (test A < B) +# gt - greater than (test A > B) +# +# Additionally, the eq and ne operator can have a number after it to limit +# the test to that number of minor versions. +# +# eq0 - equal up to the length of the shorter version +# ne0 - not equal up to the length of the shorter version +# eqN - equal up to N sub-version levels +# neN - not equal up to N sub-version levels +# +# When the condition is true, shell commands ACTION-IF-TRUE are run, +# otherwise shell commands ACTION-IF-FALSE are run. The environment +# variable 'ax_compare_version' is always set to either 'true' or 'false' +# as well. +# +# Examples: +# +# AX_COMPARE_VERSION([3.15.7],[lt],[3.15.8]) +# AX_COMPARE_VERSION([3.15],[lt],[3.15.8]) +# +# would both be true. +# +# AX_COMPARE_VERSION([3.15.7],[eq],[3.15.8]) +# AX_COMPARE_VERSION([3.15],[gt],[3.15.8]) +# +# would both be false. +# +# AX_COMPARE_VERSION([3.15.7],[eq2],[3.15.8]) +# +# would be true because it is only comparing two minor versions. +# +# AX_COMPARE_VERSION([3.15.7],[eq0],[3.15]) +# +# would be true because it is only comparing the lesser number of minor +# versions of the two values. +# +# Note: The characters that separate the version numbers do not matter. An +# empty string is the same as version 0. OP is evaluated by autoconf, not +# configure, so must be a string, not a variable. +# +# The author would like to acknowledge Guido Draheim whose advice about +# the m4_case and m4_ifvaln functions make this macro only include the +# portions necessary to perform the specific comparison specified by the +# OP argument in the final configure script. +# +# LICENSE +# +# Copyright (c) 2008 Tim Toolan +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 13 + +dnl ######################################################################### +AC_DEFUN([AX_COMPARE_VERSION], [ + AC_REQUIRE([AC_PROG_AWK]) + + # Used to indicate true or false condition + ax_compare_version=false + + # Convert the two version strings to be compared into a format that + # allows a simple string comparison. The end result is that a version + # string of the form 1.12.5-r617 will be converted to the form + # 0001001200050617. In other words, each number is zero padded to four + # digits, and non digits are removed. + AS_VAR_PUSHDEF([A],[ax_compare_version_A]) + A=`echo "$1" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \ + -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \ + -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \ + -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \ + -e 's/[[^0-9]]//g'` + + AS_VAR_PUSHDEF([B],[ax_compare_version_B]) + B=`echo "$3" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \ + -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \ + -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \ + -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \ + -e 's/[[^0-9]]//g'` + + dnl # In the case of le, ge, lt, and gt, the strings are sorted as necessary + dnl # then the first line is used to determine if the condition is true. + dnl # The sed right after the echo is to remove any indented white space. + m4_case(m4_tolower($2), + [lt],[ + ax_compare_version=`echo "x$A +x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/false/;s/x${B}/true/;1q"` + ], + [gt],[ + ax_compare_version=`echo "x$A +x$B" | sed 's/^ *//' | sort | sed "s/x${A}/false/;s/x${B}/true/;1q"` + ], + [le],[ + ax_compare_version=`echo "x$A +x$B" | sed 's/^ *//' | sort | sed "s/x${A}/true/;s/x${B}/false/;1q"` + ], + [ge],[ + ax_compare_version=`echo "x$A +x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/true/;s/x${B}/false/;1q"` + ],[ + dnl Split the operator from the subversion count if present. + m4_bmatch(m4_substr($2,2), + [0],[ + # A count of zero means use the length of the shorter version. + # Determine the number of characters in A and B. + ax_compare_version_len_A=`echo "$A" | $AWK '{print(length)}'` + ax_compare_version_len_B=`echo "$B" | $AWK '{print(length)}'` + + # Set A to no more than B's length and B to no more than A's length. + A=`echo "$A" | sed "s/\(.\{$ax_compare_version_len_B\}\).*/\1/"` + B=`echo "$B" | sed "s/\(.\{$ax_compare_version_len_A\}\).*/\1/"` + ], + [[0-9]+],[ + # A count greater than zero means use only that many subversions + A=`echo "$A" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"` + B=`echo "$B" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"` + ], + [.+],[ + AC_WARNING( + [invalid OP numeric parameter: $2]) + ],[]) + + # Pad zeros at end of numbers to make same length. + ax_compare_version_tmp_A="$A`echo $B | sed 's/./0/g'`" + B="$B`echo $A | sed 's/./0/g'`" + A="$ax_compare_version_tmp_A" + + # Check for equality or inequality as necessary. + m4_case(m4_tolower(m4_substr($2,0,2)), + [eq],[ + test "x$A" = "x$B" && ax_compare_version=true + ], + [ne],[ + test "x$A" != "x$B" && ax_compare_version=true + ],[ + AC_WARNING([invalid OP parameter: $2]) + ]) + ]) + + AS_VAR_POPDEF([A])dnl + AS_VAR_POPDEF([B])dnl + + dnl # Execute ACTION-IF-TRUE / ACTION-IF-FALSE. + if test "$ax_compare_version" = "true" ; then + m4_ifvaln([$4],[$4],[:])dnl + m4_ifvaln([$5],[else $5])dnl + fi +]) dnl AX_COMPARE_VERSION diff --git a/postgresql-libpq-configure/m4/ax_lib_postgresql.m4 b/postgresql-libpq-configure/m4/ax_lib_postgresql.m4 new file mode 100644 index 0000000..fea8da1 --- /dev/null +++ b/postgresql-libpq-configure/m4/ax_lib_postgresql.m4 @@ -0,0 +1,247 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_lib_postgresql.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_LIB_POSTGRESQL([MINIMUM-VERSION],[ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) +# +# DESCRIPTION +# +# This macro provides tests of availability of PostgreSQL 'libpq' library +# of particular version or newer. +# +# AX_LIB_POSTGRESQL macro takes only one argument which is optional. If +# there is no required version passed, then macro does not run version +# test. +# +# The --with-postgresql option takes one of three possible values: +# +# no - do not check for PostgreSQL client library +# +# yes - do check for PostgreSQL library in standard locations (pg_config +# should be in the PATH) +# +# path - complete path to pg_config utility, use this option if pg_config +# can't be found in the PATH (You could set also PG_CONFIG variable) +# +# This macro calls: +# +# AC_SUBST(POSTGRESQL_CPPFLAGS) +# AC_SUBST(POSTGRESQL_LDFLAGS) +# AC_SUBST(POSTGRESQL_LIBS) +# AC_SUBST(POSTGRESQL_VERSION) +# +# And sets: +# +# HAVE_POSTGRESQL +# +# It execute if found ACTION-IF-FOUND (empty by default) and +# ACTION-IF-NOT-FOUND (AC_MSG_FAILURE by default) if not found. +# +# LICENSE +# +# Copyright (c) 2008 Mateusz Loskot +# Copyright (c) 2014 Sree Harsha Totakura +# Copyright (c) 2018 Bastien Roucaries +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 22 + +AC_DEFUN([_AX_LIB_POSTGRESQL_OLD],[ + found_postgresql="no" + _AX_LIB_POSTGRESQL_OLD_fail="no" + while true; do + AC_CACHE_CHECK([for the pg_config program], [ac_cv_path_PG_CONFIG], + [AC_PATH_PROGS_FEATURE_CHECK([PG_CONFIG], [pg_config], + [[ac_cv_path_PG_CONFIG="";"$ac_path_PG_CONFIG" --includedir > /dev/null \ + && ac_cv_path_PG_CONFIG="$ac_path_PG_CONFIG" ac_path_PG_CONFIG_found=:]], + [ac_cv_path_PG_CONFIG=""])]) + PG_CONFIG="$ac_cv_path_PG_CONFIG" + AS_IF([test "X$PG_CONFIG" = "X"],[break]) + + AC_CACHE_CHECK([for the PostgreSQL libraries CPPFLAGS],[ac_cv_POSTGRESQL_CPPFLAGS], + [ac_cv_POSTGRESQL_CPPFLAGS="-I`"$PG_CONFIG" --includedir`" || _AX_LIB_POSTGRESQL_OLD_fail=yes]) + AS_IF([test "X$_AX_LIB_POSTGRESQL_OLD_fail" = "Xyes"],[break]) + POSTGRESQL_CPPFLAGS="$ac_cv_POSTGRESQL_CPPFLAGS" + + AC_CACHE_CHECK([for the PostgreSQL libraries LDFLAGS],[ac_cv_POSTGRESQL_LDFLAGS], + [ac_cv_POSTGRESQL_LDFLAGS="-L`"$PG_CONFIG" --libdir`" || _AX_LIB_POSTGRESQL_OLD_fail=yes]) + AS_IF([test "X$_AX_LIB_POSTGRESQL_OLD_fail" = "Xyes"],[break]) + POSTGRESQL_LDFLAGS="$ac_cv_POSTGRESQL_LDFLAGS" + + AC_CACHE_CHECK([for the PostgreSQL libraries LIBS],[ac_cv_POSTGRESQL_LIBS], + [ac_cv_POSTGRESQL_LIBS="-lpq"]) + POSTGRESQL_LIBS="$ac_cv_POSTGRESQL_LIBS" + + AC_CACHE_CHECK([for the PostgreSQL version],[ac_cv_POSTGRESQL_VERSION], + [ + ac_cv_POSTGRESQL_VERSION=`"$PG_CONFIG" --version | sed "s/^PostgreSQL[[[:space:]]][[[:space:]]]*\([[0-9.]][[0-9.]]*\).*/\1/"` \ + || _AX_LIB_POSTGRESQL_OLD_fail=yes + ]) + AS_IF([test "X$_AX_LIB_POSTGRESQL_OLD_fail" = "Xyes"],[break]) + POSTGRESQL_VERSION="$ac_cv_POSTGRESQL_VERSION" + + + dnl + dnl Check if required version of PostgreSQL is available + dnl + AS_IF([test X"$postgresql_version_req" != "X"],[ + AC_MSG_CHECKING([if PostgreSQL version $POSTGRESQL_VERSION is >= $postgresql_version_req]) + AX_COMPARE_VERSION([$POSTGRESQL_VERSION],[ge],[$postgresql_version_req], + [found_postgresql_req_version=yes],[found_postgresql_req_version=no]) + AC_MSG_RESULT([$found_postgresql_req_version]) + ]) + AS_IF([test "X$found_postgresql_req_version" = "Xno"],[break]) + + found_postgresql="yes" + break + done +]) + +AC_DEFUN([_AX_LIB_POSTGRESQL_PKG_CONFIG], +[ + AC_REQUIRE([PKG_PROG_PKG_CONFIG]) + found_postgresql=no + + while true; do + PKG_PROG_PKG_CONFIG + AS_IF([test X$PKG_CONFIG = X],[break]) + + _AX_LIB_POSTGRESQL_PKG_CONFIG_fail=no; + AS_IF([test "X$postgresql_version_req" = "X"], + [PKG_CHECK_EXISTS([libpq],[found_postgresql_pkg_config=yes],[found_postgresql=no])], + [PKG_CHECK_EXISTS([libpq >= "$postgresql_version_req"], + [found_postgresql=yes],[found_postgresql=no])]) + AS_IF([test "X$found_postgresql" = "Xno"],[break]) + + AC_CACHE_CHECK([for the PostgreSQL libraries CPPFLAGS],[ac_cv_POSTGRESQL_CPPFLAGS], + [ac_cv_POSTGRESQL_CPPFLAGS="`$PKG_CONFIG libpq --cflags-only-I`" || _AX_LIB_POSTGRESQL_PKG_CONFIG_fail=yes]) + AS_IF([test "X$_AX_LIB_POSTGRESQL_PKG_CONFIG_fail" = "Xyes"],[break]) + POSTGRESQL_CPPFLAGS="$ac_cv_POSTGRESQL_CPPFLAGS" + + + AC_CACHE_CHECK([for the PostgreSQL libraries LDFLAGS],[ac_cv_POSTGRESQL_LDFLAGS], + [ac_cv_POSTGRESQL_LDFLAGS="`$PKG_CONFIG libpq --libs-only-L --libs-only-other`" || _AX_LIB_POSTGRESQL_PKG_CONFIG_fail=yes]) + AS_IF([test "X$_AX_LIB_POSTGRESQL_PKG_CONFIG_fail" = "Xyes"],[break]) + POSTGRESQL_LDFLAGS="$ac_cv_POSTGRESQL_LDFLAGS" + + + AC_CACHE_CHECK([for the PostgreSQL libraries LIBS],[ac_cv_POSTGRESQL_LIBS], + [ac_cv_POSTGRESQL_LIBS="`$PKG_CONFIG libpq --libs-only-l`" || _AX_LIB_POSTGRESQL_PKG_CONFIG_fail=ye]) + AS_IF([test "X$_AX_LIB_POSTGRESQL_PKG_CONFIG_fail" = "Xyes"],[break]) + POSTGRESQL_LIBS="$ac_cv_POSTGRESQL_LIBS" + + dnl already checked by exist but need to be recovered + AC_CACHE_CHECK([for the PostgreSQL version],[ac_cv_POSTGRESQL_VERSION], + [ac_cv_POSTGRESQL_VERSION="`$PKG_CONFIG libpq --modversion`" || _AX_LIB_POSTGRESQL_PKG_CONFIG_fail=yes]) + AS_IF([test "X$_AX_LIB_POSTGRESQL_PKG_CONFIG_fail" = "Xyes"],[break]) + POSTGRESQL_VERSION="$ac_cv_POSTGRESQL_VERSION" + + found_postgresql=yes + break; + done + +]) + + + +AC_DEFUN([AX_LIB_POSTGRESQL], +[ + AC_ARG_WITH([postgresql], + AS_HELP_STRING([--with-postgresql=@<:@ARG@:>@], + [use PostgreSQL library @<:@default=yes@:>@, optionally specify path to pg_config] + ), + [ + AS_CASE([$withval], + [[[nN]][[oO]]],[want_postgresql="no"], + [[[yY]][[eE]][[sS]]],[want_postgresql="yes"], + [ + want_postgresql="yes" + PG_CONFIG="$withval" + ]) + ], + [want_postgresql="yes"] + ) + + AC_ARG_VAR([POSTGRESQL_CPPFLAGS],[cpp flags for PostgreSQL overriding detected flags]) + AC_ARG_VAR([POSTGRESQL_LIBFLAGS],[libs for PostgreSQL overriding detected flags]) + AC_ARG_VAR([POSTGRESQL_LDFLAGS],[linker flags for PostgreSQL overriding detected flags]) + + # populate cache + AS_IF([test "X$POSTGRESQL_CPPFLAGS" != X],[ac_cv_POSTGRESQL_CPPFLAGS="$POSTGRESQL_CPPFLAGS"]) + AS_IF([test "X$POSTGRESQL_LDFLAGS" != X],[ac_cv_POSTGRESQL_LDFLAGS="$POSTGRESQL_LDFLAGS"]) + AS_IF([test "X$POSTGRESQL_LIBS" != X],[ac_cv_POSTGRESQL_LIBS="$POSTGRESQL_LIBS"]) + + postgresql_version_req=ifelse([$1], [], [], [$1]) + found_postgresql="no" + + POSTGRESQL_VERSION="" + + dnl + dnl Check PostgreSQL libraries (libpq) + dnl + AS_IF([test X"$want_postgresql" = "Xyes"],[ + _AX_LIB_POSTGRESQL_PKG_CONFIG + + + AS_IF([test X"$found_postgresql" = "Xno"], + [_AX_LIB_POSTGRESQL_OLD]) + + AS_IF([test X"$found_postgresql" = Xyes],[ + _AX_LIB_POSTGRESQL_OLD_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $POSTGRESQL_CPPFLAGS" + _AX_LIB_POSTGRESQL_OLD_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS $POSTGRESQL_LDFLAGS" + _AX_LIB_POSTGRESQL_OLD_LIBS="$LIBS" + LIBS="$LIBS $POSTGRESQL_LIBS" + while true; do + dnl try to compile + AC_CHECK_HEADER([libpq-fe.h],[],[found_postgresql=no]) + AS_IF([test "X$found_postgresql" = "Xno"],[break]) + dnl try now to link + AC_CACHE_CHECK([for the PostgreSQL library linking is working],[ac_cv_postgresql_found], + [ + AC_LINK_IFELSE([ + AC_LANG_PROGRAM( + [ + #include + ], + [[ + char conninfo[]="dbname = postgres"; + PGconn *conn; + conn = PQconnectdb(conninfo); + ]] + ) + ],[ac_cv_postgresql_found=yes], + [ac_cv_postgresql_found=no]) + ]) + found_postgresql="$ac_cv_postgresql_found" + AS_IF([test "X$found_postgresql" = "Xno"],[break]) + break + done + CPPFLAGS="$_AX_LIB_POSTGRESQL_OLD_CPPFLAGS" + LDFLAGS="$_AX_LIB_POSTGRESQL_OLD_LDFLAGS" + LIBS="$_AX_LIB_POSTGRESQL_OLD_LIBS" + ]) + + + AS_IF([test "x$found_postgresql" = "xyes"],[ + AC_DEFINE([HAVE_POSTGRESQL], [1], + [Define to 1 if PostgreSQL libraries are available])]) + ]) + + AC_SUBST([POSTGRESQL_VERSION]) + AC_SUBST([POSTGRESQL_CPPFLAGS]) + AC_SUBST([POSTGRESQL_LDFLAGS]) + AC_SUBST([POSTGRESQL_LIBS]) + + AS_IF([test "x$found_postgresql" = "xyes"], + [ifelse([$2], , :, [$2])], + [ifelse([$3], , AS_IF([test X"$want_postgresql" = "Xyes"],[AC_MSG_ERROR([Library requirements (PostgreSQL) not met.])],[:]), [$3])]) + +]) diff --git a/postgresql-libpq-configure/postgresql-libpq-configure.buildinfo.in b/postgresql-libpq-configure/postgresql-libpq-configure.buildinfo.in new file mode 100644 index 0000000..9ad4ca8 --- /dev/null +++ b/postgresql-libpq-configure/postgresql-libpq-configure.buildinfo.in @@ -0,0 +1,3 @@ +extra-libraries: @POSTGRESQL_EXTRA_LIBS@ +include-dirs: @POSTGRESQL_INCLUDEDIR@ +extra-lib-dirs: @POSTGRESQL_LIBDIR@ diff --git a/postgresql-libpq-configure/postgresql-libpq-configure.cabal b/postgresql-libpq-configure/postgresql-libpq-configure.cabal new file mode 100644 index 0000000..109f95e --- /dev/null +++ b/postgresql-libpq-configure/postgresql-libpq-configure.cabal @@ -0,0 +1,46 @@ +cabal-version: 2.4 +name: postgresql-libpq-configure +version: 0.11 +synopsis: low-level binding to libpq: configure based provider +description: + This is a binding to libpq: the C application + programmer's interface to PostgreSQL. libpq is a + set of library functions that allow client + programs to pass queries to the PostgreSQL + backend server and to receive the results of + these queries. + +homepage: https://github.com/haskellari/postgresql-libpq +bug-reports: https://github.com/haskellari/postgresql-libpq/issues +license: BSD-3-Clause +license-file: LICENSE +author: Grant Monroe, Leon P Smith, Joey Adams +maintainer: Oleg Grenrus +copyright: (c) 2024 Oleg Grenrus +category: Database +extra-doc-files: CHANGELOG.md +tested-with: + GHC ==8.6.5 + || ==8.8.4 + || ==8.10.7 + || ==9.0.2 + || ==9.2.8 + || ==9.4.8 + || ==9.6.6 + || ==9.8.4 + || ==9.10.1 + || ==9.12.1 + +build-type: Configure +extra-source-files: + configure + postgresql-libpq-configure.buildinfo.in + +library + default-language: Haskell2010 + build-depends: base <5 + +source-repository head + type: git + location: https://github.com/haskellari/postgresql-libpq + subdir: postgresql-libpq-configure diff --git a/postgresql-libpq-pkgconfig/CHANGELOG.md b/postgresql-libpq-pkgconfig/CHANGELOG.md new file mode 100644 index 0000000..96afbc3 --- /dev/null +++ b/postgresql-libpq-pkgconfig/CHANGELOG.md @@ -0,0 +1,9 @@ +0.11 +---- + +* Require libpq >=14.12 + +0.10 +---- + +* Initial release diff --git a/postgresql-libpq-pkgconfig/LICENSE b/postgresql-libpq-pkgconfig/LICENSE new file mode 100644 index 0000000..a92de38 --- /dev/null +++ b/postgresql-libpq-pkgconfig/LICENSE @@ -0,0 +1,31 @@ +Copyright (c) 2010, Grant Monroe +Copyright (c) 2011, Leon P Smith + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of the authors nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/postgresql-libpq-pkgconfig/postgresql-libpq-pkgconfig.cabal b/postgresql-libpq-pkgconfig/postgresql-libpq-pkgconfig.cabal new file mode 100644 index 0000000..b8f4f89 --- /dev/null +++ b/postgresql-libpq-pkgconfig/postgresql-libpq-pkgconfig.cabal @@ -0,0 +1,44 @@ +cabal-version: 2.4 +name: postgresql-libpq-pkgconfig +version: 0.11 +synopsis: low-level binding to libpq: pkg-config based provider +description: + This is a binding to libpq: the C application + programmer's interface to PostgreSQL. libpq is a + set of library functions that allow client + programs to pass queries to the PostgreSQL + backend server and to receive the results of + these queries. + +homepage: https://github.com/haskellari/postgresql-libpq +bug-reports: https://github.com/haskellari/postgresql-libpq/issues +license: BSD-3-Clause +license-file: LICENSE +author: Grant Monroe, Leon P Smith, Joey Adams +maintainer: Oleg Grenrus +copyright: (c) 2024 Oleg Grenrus +category: Database +build-type: Simple +tested-with: + GHC ==8.6.5 + || ==8.8.4 + || ==8.10.7 + || ==9.0.2 + || ==9.2.8 + || ==9.4.8 + || ==9.6.6 + || ==9.8.4 + || ==9.10.1 + || ==9.12.1 + +extra-source-files: CHANGELOG.md + +library + default-language: Haskell2010 + build-depends: base <5 + pkgconfig-depends: libpq >=14.12 + +source-repository head + type: git + location: https://github.com/haskellari/postgresql-libpq + subdir: postgresql-libpq-pkgconfig diff --git a/postgresql-libpq.cabal b/postgresql-libpq.cabal index 582c7e9..d0c2c85 100644 --- a/postgresql-libpq.cabal +++ b/postgresql-libpq.cabal @@ -1,47 +1,107 @@ -Name: postgresql-libpq -Version: 0.9.1.0 -Synopsis: low-level binding to libpq - -Description: This is a binding to libpq: the C application - programmer's interface to PostgreSQL. libpq is a - set of library functions that allow client - programs to pass queries to the PostgreSQL - backend server and to receive the results of - these queries. - -Homepage: http://github.com/lpsmith/postgresql-libpq -License: BSD3 -License-file: LICENSE -Author: Grant Monroe, Leon P Smith, Joey Adams -Maintainer: Leon P Smith -Copyright: (c) 2010 Grant Monroe - (c) 2011 Leon P Smith -Category: Database -Build-type: Custom --- Extra-source-files: -Cabal-version: >=1.8 -Library - hs-source-dirs: src - c-sources: cbits/noticehandlers.c - include-dirs: cbits - Exposed-modules: Database.PostgreSQL.LibPQ - - Build-depends: base >= 4 && < 5 - , bytestring - - GHC-Options: -Wall - Extra-Libraries: pq - if os(openbsd) - Extra-Libraries: crypto ssl - - -- Other-modules: - Build-tools: hsc2hs +cabal-version: 2.4 +name: postgresql-libpq +version: 0.11.0.0 +x-revision: 1 +synopsis: low-level binding to libpq +description: + This is a binding to libpq: the C application + programmer's interface to PostgreSQL. libpq is a + set of library functions that allow client + programs to pass queries to the PostgreSQL + backend server and to receive the results of + these queries. -source-repository head - type: git - location: http://github.com/lpsmith/postgresql-libpq +homepage: https://github.com/haskellari/postgresql-libpq +bug-reports: https://github.com/haskellari/postgresql-libpq/issues +license: BSD-3-Clause +license-file: LICENSE +author: Grant Monroe, Leon P Smith, Joey Adams +maintainer: Oleg Grenrus +copyright: + (c) 2010 Grant Monroe + (c) 2011 Leon P Smith + +category: Database +build-type: Simple +extra-source-files: cbits/hs-libpq.h +tested-with: + GHC ==8.6.5 + || ==8.8.4 + || ==8.10.7 + || ==9.0.2 + || ==9.2.8 + || ==9.4.8 + || ==9.6.6 + || ==9.8.4 + || ==9.10.1 + || ==9.12.1 + +extra-source-files: CHANGELOG.md + +-- If true, use pkg-config, otherwise use the pg_config based build +-- configuration +flag use-pkg-config + default: False + manual: True + +library + default-language: Haskell2010 + hs-source-dirs: src + c-sources: cbits/noticehandlers.c + include-dirs: cbits + ghc-options: -Wall + other-extensions: + BangPatterns + CApiFFI + DerivingStrategies + EmptyDataDecls + GeneralizedNewtypeDeriving + OverloadedStrings + ScopedTypeVariables + + exposed-modules: + Database.PostgreSQL.LibPQ + Database.PostgreSQL.LibPQ.Internal + + other-modules: + Database.PostgreSQL.LibPQ.Compat + Database.PostgreSQL.LibPQ.Enums + Database.PostgreSQL.LibPQ.FFI + Database.PostgreSQL.LibPQ.Marshal + Database.PostgreSQL.LibPQ.Notify + Database.PostgreSQL.LibPQ.Oid + Database.PostgreSQL.LibPQ.Ptr -source-repository this + build-depends: + , base >=4.12.0.0 && <4.22 + , bytestring >=0.10.8.2 && <0.13 + + if !os(windows) + build-depends: unix >=2.7.2.2 && <2.9 + + if os(windows) + build-depends: Win32 >=2.2.0.2 && <2.15 + + if flag(use-pkg-config) + build-depends: postgresql-libpq-pkgconfig ^>=0.11 + + else + build-depends: postgresql-libpq-configure ^>=0.11 + + build-tool-depends: hsc2hs:hsc2hs >=0.68.5 + +test-suite smoke + default-language: Haskell2010 + type: exitcode-stdio-1.0 + main-is: Smoke.hs + hs-source-dirs: test + build-depends: + , base + , bytestring + , postgresql-libpq + , tasty ^>=1.5 + , tasty-hunit ^>=0.10.1 + +source-repository head type: git - location: http://github.com/lpsmith/postgresql-libpq - tag: v0.9.1.0 + location: https://github.com/haskellari/postgresql-libpq diff --git a/src/Database/PostgreSQL/LibPQ.hsc b/src/Database/PostgreSQL/LibPQ.hs similarity index 68% rename from src/Database/PostgreSQL/LibPQ.hsc rename to src/Database/PostgreSQL/LibPQ.hs index 8c36657..5b0c625 100644 --- a/src/Database/PostgreSQL/LibPQ.hsc +++ b/src/Database/PostgreSQL/LibPQ.hs @@ -37,12 +37,14 @@ -- ----------------------------------------------------------------------------- -{-# LANGUAGE ForeignFunctionInterface #-} -{-# LANGUAGE EmptyDataDecls #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE BangPatterns #-} +{-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE ScopedTypeVariables #-} + +-- The FFI imports are in .FFI module +{-# LANGUAGE NoForeignFunctionInterface #-} module Database.PostgreSQL.LibPQ ( @@ -77,6 +79,7 @@ module Database.PostgreSQL.LibPQ , parameterStatus , protocolVersion , serverVersion + , libpqVersion , errorMessage , socket , backendPID @@ -164,9 +167,19 @@ module Database.PostgreSQL.LibPQ , isBusy , setnonblocking , isnonblocking + , setSingleRowMode , FlushStatus(..) , flush + -- * Pipeline Mode + -- $pipelinemode + , PipelineStatus(..) + , pipelineStatus + , enterPipelineMode + , exitPipelineMode + , pipelineSync + , sendFlushRequest + -- * Cancelling Queries in Progress -- $cancel , Cancel @@ -209,50 +222,32 @@ module Database.PostgreSQL.LibPQ ) where -#include -#include -#include "noticehandlers.h" - -import Prelude hiding ( print ) -import Foreign -import Foreign.C.Types -import Foreign.C.String -#if __GLASGOW_HASKELL__ >= 702 +import Control.Concurrent.MVar (MVar, newMVar, swapMVar, tryTakeMVar, withMVar) +import Control.Exception (mask_) +import Foreign.C.String (CString, CStringLen, withCString) +import Foreign.C.Types (CInt (..)) +import Foreign.ForeignPtr (ForeignPtr, finalizeForeignPtr, newForeignPtr, newForeignPtr_, touchForeignPtr, withForeignPtr) +import Foreign.Marshal (alloca, allocaBytes, finalizerFree, free, mallocBytes, maybeWith, reallocBytes, withArrayLen, withMany) +import Foreign.Ptr (Ptr, castPtr, nullPtr) +import Foreign.Storable (Storable (peek)) +import GHC.Conc (closeFdWith) +import System.IO (IOMode (..), SeekMode (..)) +import System.Posix.Types (CPid, Fd (..)) + +import qualified Data.ByteString as B +import qualified Data.ByteString.Internal as B (c_strlen, createAndTrim, fromForeignPtr) +import qualified Data.ByteString.Unsafe as B +import qualified Foreign.Concurrent as FC import qualified Foreign.ForeignPtr.Unsafe as Unsafe -#endif -import qualified Foreign.Concurrent as FC -import Control.Monad(when) -import System.Posix.Types ( Fd(..) ) -import Data.List ( foldl' ) -import System.IO ( IOMode(..), SeekMode(..) ) - -#if __GLASGOW_HASKELL__ >= 700 -import GHC.Conc ( closeFdWith ) -- Won't work with GHC 7.0.1 -#endif -import System.Posix.Types ( CPid ) - -import Data.ByteString.Char8 () -import qualified Data.ByteString.Unsafe as B -import qualified Data.ByteString.Internal as B ( fromForeignPtr - , c_strlen - , createAndTrim - , ByteString(..) - ) -import qualified Data.ByteString as B - -#if 0 -#if __GLASGOW_HASKELL__ < 706 -import Control.Concurrent (newEmptyMVar, takeMVar) -#endif -#endif -import Control.Concurrent.MVar - -#if __GLASGOW_HASKELL__ >= 700 -import Control.Exception (mask_) -#else -import qualified Control.Exception -mask_ = Control.Exception.block -#endif + +import Database.PostgreSQL.LibPQ.Compat +import Database.PostgreSQL.LibPQ.Enums +import Database.PostgreSQL.LibPQ.FFI +import Database.PostgreSQL.LibPQ.Internal +import Database.PostgreSQL.LibPQ.Marshal +import Database.PostgreSQL.LibPQ.Notify +import Database.PostgreSQL.LibPQ.Oid +import Database.PostgreSQL.LibPQ.Ptr -- $dbconn -- The following functions deal with making a connection to a @@ -264,16 +259,6 @@ mask_ = Control.Exception.block -- whether a connection was successfully made before queries are sent -- via the connection object. --- | 'Connection' encapsulates a connection to the backend. -data Connection = Conn {-# UNPACK #-} !(ForeignPtr PGconn) - {-# UNPACK #-} !(MVar NoticeBuffer) - -instance Eq Connection where - (Conn c _) == (Conn d _) = c == d - (Conn c _) /= (Conn d _) = c /= d - -data PGconn - -- | Makes a new connection to the database server. -- -- This function opens a new database connection using the parameters @@ -290,37 +275,30 @@ data PGconn connectdb :: B.ByteString -- ^ Connection Info -> IO Connection connectdb conninfo = - do connPtr <- B.useAsCString conninfo c_PQconnectdb + mask_ $ do + connPtr <- B.useAsCString conninfo c_PQconnectdb if connPtr == nullPtr then fail "libpq failed to allocate a PGconn structure" else do noticeBuffer <- newMVar nullPtr -#if __GLASGOW_HASKELL__ >= 706 - connection <- FC.newForeignPtr connPtr (pqfinish connPtr noticeBuffer) -#else connection <- newForeignPtrOnce connPtr (pqfinish connPtr noticeBuffer) -#endif return $! Conn connection noticeBuffer -- | Make a connection to the database server in a nonblocking manner. connectStart :: B.ByteString -- ^ Connection Info -> IO Connection connectStart connStr = - do connPtr <- B.useAsCString connStr c_PQconnectStart + mask_ $ do + connPtr <- B.useAsCString connStr c_PQconnectStart if connPtr == nullPtr then fail "libpq failed to allocate a PGconn structure" else do noticeBuffer <- newMVar nullPtr -#if __GLASGOW_HASKELL__ >= 706 - connection <- FC.newForeignPtr connPtr (pqfinish connPtr noticeBuffer) -#else connection <- newForeignPtrOnce connPtr (pqfinish connPtr noticeBuffer) -#endif return $! Conn connection noticeBuffer pqfinish :: Ptr PGconn -> MVar NoticeBuffer -> IO () pqfinish conn noticeBuffer = do -#if __GLASGOW_HASKELL__ >= 700 -- This covers the case when a connection is closed while other Haskell -- threads are using GHC's IO manager to wait on the descriptor. This is -- commonly the case with asynchronous notifications, for example. Since @@ -333,13 +311,10 @@ pqfinish conn noticeBuffer = do -- This case may be worth investigating further c_PQfinish conn fd -> closeFdWith (\_ -> c_PQfinish conn) (Fd fd) -#else - c_PQfinish conn -#endif + nb <- swapMVar noticeBuffer nullPtr - when (nb /= nullPtr) (free nb) + c_free_noticebuffer nb -#if __GLASGOW_HASKELL__ < 706 -- | Workaround for bug in 'FC.newForeignPtr' before base 4.6. Ensure the -- finalizer is only run once, to prevent a segfault. See GHC ticket #7170 -- @@ -349,7 +324,6 @@ newForeignPtrOnce :: Ptr a -> IO () -> IO (ForeignPtr a) newForeignPtrOnce ptr fin = do mv <- newMVar fin FC.newForeignPtr ptr $ tryTakeMVar mv >>= maybe (return ()) id -#endif -- | Allocate a Null Connection, which all libpq functions -- should safely fail on. @@ -361,11 +335,7 @@ newNullConnection = do -- | Test if a connection is the Null Connection. isNullConnection :: Connection -> Bool -#if __GLASGOW_HASKELL__ >= 702 isNullConnection (Conn x _) = Unsafe.unsafeForeignPtrToPtr x == nullPtr -#else -isNullConnection (Conn x _) = unsafeForeignPtrToPtr x == nullPtr -#endif {-# INLINE isNullConnection #-} -- | If 'connectStart' succeeds, the next stage is to poll libpq so @@ -440,7 +410,6 @@ resetStart :: Connection resetStart connection = enumFromConn connection c_PQresetStart - -- | To initiate a connection reset, call 'resetStart'. If it returns -- 'False', the reset has failed. If it returns 'True', poll the reset -- using 'resetPoll' in exactly the same way as you would create the @@ -449,24 +418,15 @@ resetPoll :: Connection -> IO PollingStatus resetPoll = pollHelper c_PQresetPoll -data PollingStatus - = PollingFailed - | PollingReading - | PollingWriting - | PollingOk deriving (Eq, Show) - pollHelper :: (Ptr PGconn -> IO CInt) -> Connection -> IO PollingStatus pollHelper poller connection = do code <- withConn connection poller - case code of - (#const PGRES_POLLING_READING) -> return PollingReading - (#const PGRES_POLLING_OK) -> return PollingOk - (#const PGRES_POLLING_WRITING) -> return PollingWriting - (#const PGRES_POLLING_FAILED) -> return PollingFailed - _ -> fail $ "unexpected polling status " ++ show code - + maybe + (fail $ "unexpected polling status " ++ show code) + return + (fromCInt code) -- | Closes the connection to the server. -- @@ -532,20 +492,6 @@ statusString f connection = else Just `fmap` B.packCString cstr -data ConnStatus - = ConnectionOk -- ^ The 'Connection' is ready. - | ConnectionBad -- ^ The connection procedure has failed. - | ConnectionStarted -- ^ Waiting for connection to be made. - | ConnectionMade -- ^ Connection OK; waiting to send. - | ConnectionAwaitingResponse -- ^ Waiting for a response from the server. - | ConnectionAuthOk -- ^ Received authentication; - -- waiting for backend start-up to - -- finish. - | ConnectionSetEnv -- ^ Negotiating environment-driven - -- parameter settings. - | ConnectionSSLStartup -- ^ Negotiating SSL encryption. - deriving (Eq, Show) - -- | Returns the status of the connection. -- @@ -564,25 +510,11 @@ status :: Connection -> IO ConnStatus status connection = do stat <- withConn connection c_PQstatus - case stat of - (#const CONNECTION_OK) -> return ConnectionOk - (#const CONNECTION_BAD) -> return ConnectionBad - (#const CONNECTION_STARTED) -> return ConnectionStarted - (#const CONNECTION_MADE) -> return ConnectionMade - (#const CONNECTION_AWAITING_RESPONSE)-> return ConnectionAwaitingResponse - (#const CONNECTION_AUTH_OK) -> return ConnectionAuthOk - (#const CONNECTION_SETENV) -> return ConnectionSetEnv - (#const CONNECTION_SSL_STARTUP) -> return ConnectionSSLStartup - --(#const CONNECTION_NEEDED) -> ConnectionNeeded - c -> fail $ "Unknown connection status " ++ show c - - -data TransactionStatus = TransIdle -- ^ currently idle - | TransActive -- ^ a command is in progress - | TransInTrans -- ^ idle, in a valid transaction block - | TransInError -- ^ idle, in a failed transaction block - | TransUnknown -- ^ the connection is bad - deriving (Eq, Show) + maybe + (fail $ "Unknown connection status " ++ show stat) + return + (fromCInt stat) + -- | Returns the current in-transaction status of the server. -- @@ -591,14 +523,11 @@ data TransactionStatus = TransIdle -- ^ currently idle transactionStatus :: Connection -> IO TransactionStatus transactionStatus connection = do - stat <- withConn connection c_PQtransactionStatus - case stat of - (#const PQTRANS_IDLE) -> return TransIdle - (#const PQTRANS_ACTIVE) -> return TransActive - (#const PQTRANS_INTRANS) -> return TransInTrans - (#const PQTRANS_INERROR) -> return TransInError - (#const PQTRANS_UNKNOWN) -> return TransUnknown - c -> fail $ "Unknown transaction status " ++ show c + stat <- withConn connection c_PQtransactionStatus + maybe + (fail $ "Unknown transaction status " ++ show stat) + return + (fromCInt stat) -- | Looks up a current parameter setting of the server. @@ -650,6 +579,16 @@ serverVersion :: Connection serverVersion connection = fmap fromIntegral $ withConn connection c_PQserverVersion +-- | Return the version of libpq that is being used. +-- +-- The result of this function can be used to determine, at +-- run time, if specific functionality is available in the currently +-- loaded version of libpq. The function can be used, for example, +-- to determine which connection options are available for +-- PQconnectdb or if the hex bytea output added in PostgreSQL 9.0 is supported. +-- +libpqVersion :: IO Int +libpqVersion = fmap fromIntegral c_PQlibVersion -- | Returns the error message most recently generated by an operation -- on the connection. @@ -724,14 +663,77 @@ connectionUsedPassword connection = -- contain multiple commands and thus return multiple instances of -- 'Result'. newtype Result = Result (ForeignPtr PGresult) deriving (Eq, Show) -data PGresult - -data Format = Text | Binary deriving (Eq, Ord, Show, Enum) -newtype Oid = Oid CUInt deriving (Eq, Ord, Read, Show, Storable) - -invalidOid :: Oid -invalidOid = Oid (#const InvalidOid) +-- | Prepare the given parameter bytestring for passing on to libpq, +-- without copying for binary parameters. +-- +-- This is safe to use to pass parameters to libpq considering: +-- * libpq treats the parameter data as read-only +-- * 'ByteString' uses pinned memory +-- * the reference to the 'CString' doesn't escape +unsafeUseParamAsCString :: (B.ByteString, Format) -> (CString -> IO a) -> IO a +unsafeUseParamAsCString (bs, format) kont = + case format of + Binary -> B.unsafeUseAsCStringLen bs kont' + Text -> B.useAsCString bs kont + where + kont' (ptr, 0) = if ptr == nullPtr then kont emptyPtr else kont ptr + kont' (ptr, _) = kont ptr + +-- | Convert a list of parameters to the format expected by libpq FFI calls. +withParams :: [Maybe (Oid, B.ByteString, Format)] + -> (CInt -> Ptr Oid -> Ptr CString -> Ptr CInt -> Ptr CInt -> IO a) + -> IO a +withParams params action = + unsafeWithArray n oids $ \ts -> + withMany (maybeWith unsafeUseParamAsCString) values $ \c_values -> + unsafeWithArray n c_values $ \vs -> + unsafeWithArray n c_lengths $ \ls -> + unsafeWithArray n formats $ \fs -> + action (intToCInt n) ts vs ls fs + where + AccumParams n oids values c_lengths formats = + foldr accum (AccumParams 0 [] [] [] []) params + + accum :: Maybe (Oid, B.ByteString, Format) -> AccumParams -> AccumParams + accum Nothing ~(AccumParams i a b c d) = + AccumParams (i + 1) (invalidOid : a) (Nothing : b) (0 : c) (0 : d) + + accum (Just (t,v,f)) ~(AccumParams i xs ys zs ws) = + let !z = intToCInt (B.length v) + !w = toCInt f + in AccumParams (i + 1) (t : xs) (Just (v, f) : ys) (z : zs) (w : ws) + +intToCInt :: Int -> CInt +intToCInt = toEnum + +data AccumParams = AccumParams !Int ![Oid] ![Maybe (B.ByteString, Format)] ![CInt] ![CInt] + +-- | Convert a list of parameters to the format expected by libpq FFI calls, +-- prepared statement variant. +withParamsPrepared :: [Maybe (B.ByteString, Format)] + -> (CInt -> Ptr CString -> Ptr CInt -> Ptr CInt -> IO a) + -> IO a +withParamsPrepared params action = + withMany (maybeWith unsafeUseParamAsCString) values $ \c_values -> + unsafeWithArray n c_values $ \vs -> + unsafeWithArray n c_lengths $ \ls -> + unsafeWithArray n formats $ \fs -> + action (intToCInt n) vs ls fs + where + AccumPrepParams n values c_lengths formats = + foldr accum (AccumPrepParams 0 [] [] []) params + + accum :: Maybe (B.ByteString, Format) -> AccumPrepParams -> AccumPrepParams + accum Nothing ~(AccumPrepParams i a b c) = + AccumPrepParams (i + 1) (Nothing : a) (0 : b) (0 : c) + + accum (Just (v, f)) ~(AccumPrepParams i xs ys zs) = + let !y = intToCInt (B.length v) + !z = toCInt f + in AccumPrepParams (i + 1) (Just (v, f) : xs) (y : ys) (z : zs) + +data AccumPrepParams = AccumPrepParams !Int ![Maybe (B.ByteString, Format)] ![CInt] ![CInt] -- | Submits a command to the server and waits for the result. -- @@ -799,31 +801,12 @@ execParams :: Connection -- ^ connection -> Format -- ^ result format -> IO (Maybe Result) -- ^ result execParams connection statement params rFmt = - do let (oids, values, lengths, formats) = - foldl' accum ([],[],[],[]) $ reverse params - !c_lengths = map toEnum lengths :: [CInt] - !n = toEnum $ length params - !f = toEnum $ fromEnum rFmt - resultFromConn connection $ \c -> - B.useAsCString statement $ \s -> - withArray oids $ \ts -> - withMany (maybeWith B.useAsCString) values $ \c_values -> - withArray c_values $ \vs -> - withArray c_lengths $ \ls -> - withArray formats $ \fs -> - c_PQexecParams c s n ts vs ls fs f - - where - accum (!a,!b,!c,!d) Nothing = ( invalidOid:a - , Nothing:b - , 0:c - , 0:d - ) - accum (!a,!b,!c,!d) (Just (t,v,f)) = ( t:a - , (Just v):b - , (B.length v):c - , (toEnum $ fromEnum f):d - ) + resultFromConn connection $ \c -> + B.useAsCString statement $ \s -> + withParams params $ \n ts vs ls fs -> + c_PQexecParams c s n ts vs ls fs f + where + !f = toCInt rFmt -- | Submits a request to create a prepared statement with the given @@ -871,9 +854,8 @@ prepare connection stmtName query mParamTypes = resultFromConn connection $ \c -> B.useAsCString stmtName $ \s -> B.useAsCString query $ \q -> - maybeWith withArray mParamTypes $ \o -> - let l = maybe 0 (toEnum . length) mParamTypes - in c_PQprepare c s q l o + maybeWithInt withArrayLen mParamTypes $ \l o -> + c_PQprepare c s q (intToCInt l) o -- | Sends a request to execute a prepared statement with given @@ -898,28 +880,13 @@ execPrepared :: Connection -- ^ connection -> [Maybe (B.ByteString, Format)] -- ^ parameters -> Format -- ^ result format -> IO (Maybe Result) -- ^ result -execPrepared connection stmtName mPairs rFmt = - do let (values, lengths, formats) = foldl' accum ([],[],[]) $ reverse mPairs - !c_lengths = map toEnum lengths :: [CInt] - !n = toEnum $ length mPairs - !f = toEnum $ fromEnum rFmt - resultFromConn connection $ \c -> - B.useAsCString stmtName $ \s -> - withMany (maybeWith B.useAsCString) values $ \c_values -> - withArray c_values $ \vs -> - withArray c_lengths $ \ls -> - withArray formats $ \fs -> - c_PQexecPrepared c s n vs ls fs f - +execPrepared connection stmtName params rFmt = + resultFromConn connection $ \c -> + B.useAsCString stmtName $ \s -> + withParamsPrepared params $ \n vs ls fs -> + c_PQexecPrepared c s n vs ls fs f where - accum (!a,!b,!c) Nothing = ( Nothing:a - , 0:b - , 0:c - ) - accum (!a,!b,!c) (Just (v, f)) = ( (Just v):a - , (B.length v):b - , (toEnum $ fromEnum f):c - ) + !f = toCInt rFmt -- | Submits a request to obtain information about the specified @@ -968,43 +935,6 @@ describePortal connection portalName = B.useAsCString portalName $ \p -> c_PQdescribePortal c p - -data ExecStatus = EmptyQuery -- ^ The string sent to the server was empty. - | CommandOk -- ^ Successful completion of a - -- command returning no data. - | TuplesOk -- ^ Successful completion of a - -- command returning data (such as a - -- SELECT or SHOW). - | CopyOut -- ^ Copy Out (from server) data - -- transfer started. - | CopyIn -- ^ Copy In (to server) data transfer - -- started. - | BadResponse -- ^ The server's response was not understood. - | NonfatalError -- ^ A nonfatal error (a notice or - -- warning) occurred. - | FatalError -- ^ A fatal error occurred. - deriving (Eq, Show) - -instance Enum ExecStatus where - toEnum (#const PGRES_EMPTY_QUERY) = EmptyQuery - toEnum (#const PGRES_COMMAND_OK) = CommandOk - toEnum (#const PGRES_TUPLES_OK) = TuplesOk - toEnum (#const PGRES_COPY_OUT) = CopyOut - toEnum (#const PGRES_COPY_IN) = CopyIn - toEnum (#const PGRES_BAD_RESPONSE) = BadResponse - toEnum (#const PGRES_NONFATAL_ERROR) = NonfatalError - toEnum (#const PGRES_FATAL_ERROR) = FatalError - toEnum _ = error "Database.PQ.Enum.ExecStatus.toEnum: bad argument" - - fromEnum EmptyQuery = (#const PGRES_EMPTY_QUERY) - fromEnum CommandOk = (#const PGRES_COMMAND_OK) - fromEnum TuplesOk = (#const PGRES_TUPLES_OK) - fromEnum CopyOut = (#const PGRES_COPY_OUT) - fromEnum CopyIn = (#const PGRES_COPY_IN) - fromEnum BadResponse = (#const PGRES_BAD_RESPONSE) - fromEnum NonfatalError = (#const PGRES_NONFATAL_ERROR) - fromEnum FatalError = (#const PGRES_FATAL_ERROR) - -- | Returns the result status of the command. resultStatus :: Result -> IO ExecStatus @@ -1017,14 +947,14 @@ resultStatus result = enumFromResult result c_PQresultStatus resStatus :: ExecStatus -> IO B.ByteString resStatus es = - do cstr <- c_PQresStatus $ fromIntegral $ fromEnum es + do cstr <- c_PQresStatus $ toCInt es len <- B.c_strlen cstr fp <- newForeignPtr_ $ castPtr cstr return $ B.fromForeignPtr fp 0 $ fromIntegral len --- | Returns the error message most recently generated by an operation --- on the connection. +-- | Returns the error message associated with the command, or an +-- empty string if there was no error. resultErrorMessage :: Result -> IO (Maybe B.ByteString) resultErrorMessage = flip maybeBsFromResult c_PQresultErrorMessage @@ -1041,109 +971,6 @@ resultErrorMessage = flip maybeBsFromResult c_PQresultErrorMessage unsafeFreeResult :: Result -> IO () unsafeFreeResult (Result x) = finalizeForeignPtr x - -data FieldCode = DiagSeverity - -- ^ The severity; the field contents are ERROR, FATAL, - -- or PANIC (in an error message), or WARNING, NOTICE, - -- DEBUG, INFO, or LOG (in a notice message), or a - -- localized translation of one of these. Always - -- present. - - | DiagSqlstate - -- ^ The SQLSTATE code for the error. The SQLSTATE code - -- identifies the type of error that has occurred; it - -- can be used by front-end applications to perform - -- specific operations (such as error handling) in - -- response to a particular database error. For a list - -- of the possible SQLSTATE codes, see Appendix A. This - -- field is not localizable, and is always present. - - | DiagMessagePrimary - -- ^ The primary human-readable error message - -- (typically one line). Always present. - - | DiagMessageDetail - -- ^ Detail: an optional secondary error message - -- carrying more detail about the problem. Might run to - -- multiple lines. - - | DiagMessageHint - -- ^ Hint: an optional suggestion what to do about the - -- problem. This is intended to differ from detail in - -- that it offers advice (potentially inappropriate) - -- rather than hard facts. Might run to multiple lines. - - | DiagStatementPosition - -- ^ A string containing a decimal integer indicating - -- an error cursor position as an index into the - -- original statement string. The first character has - -- index 1, and positions are measured in characters - -- not bytes. - - | DiagInternalPosition - -- ^ This is defined the same as the - -- 'DiagStatementPosition' field, but it is used when - -- the cursor position refers to an internally - -- generated command rather than the one submitted by - -- the client. The 'DiagInternalQuery' field will - -- always appear when this field appears. - - | DiagInternalQuery - -- ^ The text of a failed internally-generated - -- command. This could be, for example, a SQL query - -- issued by a PL/pgSQL function. - - | DiagContext - -- ^ An indication of the context in which the error - -- occurred. Presently this includes a call stack - -- traceback of active procedural language functions - -- and internally-generated queries. The trace is one - -- entry per line, most recent first. - - | DiagSourceFile - -- ^ The file name of the source-code location where - -- the error was reported. - - | DiagSourceLine - -- ^ The line number of the source-code location where - -- the error was reported. - - | DiagSourceFunction - -- ^ The name of the source-code function reporting the - -- error. - - deriving (Eq, Show) - - -instance Enum FieldCode where - toEnum (#const PG_DIAG_SEVERITY) = DiagSeverity - toEnum (#const PG_DIAG_SQLSTATE) = DiagSqlstate - toEnum (#const PG_DIAG_MESSAGE_PRIMARY) = DiagMessagePrimary - toEnum (#const PG_DIAG_MESSAGE_DETAIL) = DiagMessageDetail - toEnum (#const PG_DIAG_MESSAGE_HINT) = DiagMessageHint - toEnum (#const PG_DIAG_STATEMENT_POSITION) = DiagStatementPosition - toEnum (#const PG_DIAG_INTERNAL_POSITION) = DiagInternalPosition - toEnum (#const PG_DIAG_INTERNAL_QUERY) = DiagInternalQuery - toEnum (#const PG_DIAG_CONTEXT) = DiagContext - toEnum (#const PG_DIAG_SOURCE_FILE) = DiagSourceFile - toEnum (#const PG_DIAG_SOURCE_LINE) = DiagSourceLine - toEnum (#const PG_DIAG_SOURCE_FUNCTION) = DiagSourceFunction - toEnum _ = error "Database.PQ.Enum.FieldCode.toEnum: bad argument" - - fromEnum DiagSeverity = (#const PG_DIAG_SEVERITY) - fromEnum DiagSqlstate = (#const PG_DIAG_SQLSTATE) - fromEnum DiagMessagePrimary = (#const PG_DIAG_MESSAGE_PRIMARY) - fromEnum DiagMessageDetail = (#const PG_DIAG_MESSAGE_DETAIL) - fromEnum DiagMessageHint = (#const PG_DIAG_MESSAGE_HINT) - fromEnum DiagStatementPosition = (#const PG_DIAG_STATEMENT_POSITION) - fromEnum DiagInternalPosition = (#const PG_DIAG_INTERNAL_POSITION) - fromEnum DiagInternalQuery = (#const PG_DIAG_INTERNAL_QUERY) - fromEnum DiagContext = (#const PG_DIAG_CONTEXT) - fromEnum DiagSourceFile = (#const PG_DIAG_SOURCE_FILE) - fromEnum DiagSourceLine = (#const PG_DIAG_SOURCE_LINE) - fromEnum DiagSourceFunction = (#const PG_DIAG_SOURCE_FUNCTION) - - -- | Returns an individual field of an error report. -- -- fieldcode is an error field identifier; see the symbols listed @@ -1168,7 +995,7 @@ resultErrorField :: Result -> IO (Maybe B.ByteString) resultErrorField (Result fp) fieldcode = maybeBsFromForeignPtr fp $ \res -> - c_PQresultErrorField res $ fromIntegral $ fromEnum fieldcode + c_PQresultErrorField res $ toCInt fieldcode -- $queryresultinfo @@ -1181,9 +1008,9 @@ resultErrorField (Result fp) fieldcode = -- values, these functions will act as though the result has zero rows -- and zero columns. --- | Returns the number of rows (tuples) in the query result. Because --- it returns an integer result, large result sets might overflow the --- return value on 32-bit operating systems. +-- | Returns the number of rows (tuples) in the query result. (Note +-- that PGresult objects are limited to no more than INT_MAX rows, so +-- an int result is sufficient.) ntuples :: Result -> IO Row ntuples res = withResult res (return . toRow . c_PQntuples) @@ -1196,8 +1023,12 @@ nfields :: Result nfields res = withResult res (return . toColumn . c_PQnfields) -newtype Column = Col CInt deriving (Eq, Ord, Show, Enum, Num) -newtype Row = Row CInt deriving (Eq, Ord, Show, Enum, Num) +newtype Column = Col CInt + deriving stock (Eq, Ord, Show) + deriving newtype (Enum, Num) +newtype Row = Row CInt + deriving stock (Eq, Ord, Show) + deriving newtype (Enum, Num) toColumn :: (Integral a) => a -> Column toColumn = Col . fromIntegral @@ -1313,13 +1144,14 @@ getvalue :: Result getvalue (Result fp) (Row rowNum) (Col colNum) = withForeignPtr fp $ \ptr -> do isnull <- c_PQgetisnull ptr rowNum colNum - if toEnum $ fromIntegral isnull - then return $ Nothing - - else do cstr <- c_PQgetvalue ptr rowNum colNum - l <- c_PQgetlength ptr rowNum colNum - fp' <- FC.newForeignPtr (castPtr cstr) finalizer - return $! Just $! B.fromForeignPtr fp' 0 $ fromIntegral l + case fromCInt isnull of + Just True -> return Nothing + Just False -> do + cstr <- c_PQgetvalue ptr rowNum colNum + l <- c_PQgetlength ptr rowNum colNum + fp' <- FC.newForeignPtr (castPtr cstr) finalizer + return $! Just $! B.fromForeignPtr fp' 0 $ fromIntegral l + Nothing -> fail $ "fromCInt @Bool " ++ show isnull where finalizer = touchForeignPtr fp @@ -1337,12 +1169,13 @@ getvalue' :: Result getvalue' res (Row rowNum) (Col colNum) = withResult res $ \ptr -> do isnull <- c_PQgetisnull ptr rowNum colNum - if toEnum $ fromIntegral isnull - then return $ Nothing - - else do cstr <- c_PQgetvalue ptr rowNum colNum - l <- fromIntegral `fmap` c_PQgetlength ptr rowNum colNum - Just `fmap` B.packCStringLen (cstr, l) + case fromCInt isnull of + Just True -> return Nothing + Just False -> do + cstr <- c_PQgetvalue ptr rowNum colNum + l <- fromIntegral `fmap` c_PQgetlength ptr rowNum colNum + Just `fmap` B.packCStringLen (cstr, l) + Nothing -> fail $ "fromCInt @Bool " ++ show isnull -- | Tests a field for a null value. Row and column numbers start at @@ -1594,7 +1427,7 @@ data CopyOutResult -- while waiting for data. getCopyData :: Connection -> Bool -> IO CopyOutResult getCopyData conn async = alloca $ \strp -> withConn conn $ \c -> do - len <- c_PQgetCopyData c strp $! (fromIntegral (fromEnum async)) + len <- c_PQgetCopyData c strp $! toCInt async if len <= 0 then case compare len (-1) of LT -> return CopyOutError @@ -1654,31 +1487,13 @@ sendQueryParams :: Connection -> Format -> IO Bool sendQueryParams connection statement params rFmt = - do let (oids, values, lengths, formats) = - foldl' accum ([],[],[],[]) $ reverse params - !c_lengths = map toEnum lengths :: [CInt] - !n = toEnum $ length params - !f = toEnum $ fromEnum rFmt - enumFromConn connection $ \c -> - B.useAsCString statement $ \s -> - withArray oids $ \ts -> - withMany (maybeWith B.useAsCString) values $ \c_values -> - withArray c_values $ \vs -> - withArray c_lengths $ \ls -> - withArray formats $ \fs -> - c_PQsendQueryParams c s n ts vs ls fs f + enumFromConn connection $ \c -> + B.useAsCString statement $ \s -> + withParams params $ \n ts vs ls fs -> + c_PQsendQueryParams c s n ts vs ls fs f where - accum (!a,!b,!c,!d) Nothing = ( invalidOid:a - , Nothing:b - , 0:c - , 0:d - ) - accum (!a,!b,!c,!d) (Just (t,v,f)) = ( t:a - , (Just v):b - , (B.length v):c - , (toEnum $ fromEnum f):d - ) + !f = toCInt rFmt -- | Sends a request to create a prepared statement with the given @@ -1692,9 +1507,8 @@ sendPrepare connection stmtName query mParamTypes = enumFromConn connection $ \c -> B.useAsCString stmtName $ \s -> B.useAsCString query $ \q -> - maybeWith withArray mParamTypes $ \o -> - let l = maybe 0 (toEnum . length) mParamTypes - in c_PQsendPrepare c s q l o + maybeWithInt withArrayLen mParamTypes $ \l o -> + c_PQsendPrepare c s q (intToCInt l) o -- | Sends a request to execute a prepared statement with given @@ -1704,28 +1518,14 @@ sendQueryPrepared :: Connection -> [Maybe (B.ByteString, Format)] -> Format -> IO Bool -sendQueryPrepared connection stmtName mPairs rFmt = - do let (values, lengths, formats) = foldl' accum ([],[],[]) $ reverse mPairs - !c_lengths = map toEnum lengths :: [CInt] - !n = toEnum $ length mPairs - !f = toEnum $ fromEnum rFmt - enumFromConn connection $ \c -> - B.useAsCString stmtName $ \s -> - withMany (maybeWith B.useAsCString) values $ \c_values -> - withArray c_values $ \vs -> - withArray c_lengths $ \ls -> - withArray formats $ \fs -> - c_PQsendQueryPrepared c s n vs ls fs f +sendQueryPrepared connection stmtName params rFmt = + enumFromConn connection $ \c -> + B.useAsCString stmtName $ \s -> + withParamsPrepared params $ \n vs ls fs -> + c_PQsendQueryPrepared c s n vs ls fs f where - accum (!a,!b,!c) Nothing = ( Nothing:a - , 0:b - , 0:c - ) - accum (!a,!b,!c) (Just (v, f)) = ( (Just v):a - , (B.length v):b - , (toEnum $ fromEnum f):c - ) + !f = toCInt rFmt -- | Submits a request to obtain information about the specified @@ -1806,9 +1606,8 @@ isBusy connection = enumFromConn connection c_PQisBusy setnonblocking :: Connection -> Bool -> IO Bool -setnonblocking connection blocking = - do let arg = fromIntegral $ fromEnum blocking - stat <- withConn connection $ \ptr -> c_PQsetnonblocking ptr arg +setnonblocking connection blocking = do + stat <- withConn connection $ \ptr -> c_PQsetnonblocking ptr (toCInt blocking) return $! stat == 0 @@ -1818,6 +1617,19 @@ isnonblocking :: Connection isnonblocking connection = enumFromConn connection c_PQisnonblocking +-- | Select single-row mode for the currently-executing query. +-- +-- This function can only be called immediately after PQsendQuery or one of its +-- sibling functions, before any other operation on the connection such as +-- PQconsumeInput or PQgetResult. If called at the correct time, the function +-- activates single-row mode for the current query and returns 1. Otherwise the +-- mode stays unchanged and the function returns 0. In any case, the mode +-- reverts to normal after completion of the current query. +setSingleRowMode :: Connection + -> IO Bool +setSingleRowMode connection = enumFromConn connection c_PQsetSingleRowMode + + data FlushStatus = FlushOk | FlushFailed | FlushWriting @@ -1837,6 +1649,60 @@ flush connection = 1 -> return FlushWriting _ -> return FlushFailed +-- $pipelinemode +-- These functions control behaviour in pipeline mode. +-- +-- Pipeline mode allows applications to send a query +-- without having to read the result of the previously +-- sent query. Taking advantage of the pipeline mode, +-- a client will wait less for the server, since multiple +-- queries/results can be sent/received in +-- a single network transaction. + +-- | Returns the current pipeline mode status of the libpq connection. +-- +-- @since 0.11.0.0 +pipelineStatus :: Connection + -> IO PipelineStatus +pipelineStatus connection = do + stat <- withConn connection c_PQpipelineStatus + maybe + (fail $ "Unknown pipeline status " ++ show stat) + return + (fromCInt stat) + +-- | Causes a connection to enter pipeline mode if it is currently idle or already in pipeline mode. +-- +-- @since 0.11.0.0 +enterPipelineMode :: Connection + -> IO Bool +enterPipelineMode connection = + enumFromConn connection c_PQenterPipelineMode + +-- | Causes a connection to exit pipeline mode if it is currently in pipeline mode with an empty queue and no pending results. +-- +-- @since 0.11.0.0 +exitPipelineMode :: Connection + -> IO Bool +exitPipelineMode connection = + enumFromConn connection c_PQexitPipelineMode + +-- | Marks a synchronization point in a pipeline by sending a sync message and flushing the send buffer. This serves as the delimiter of an implicit transaction and an error recovery point> +-- +-- @since 0.11.0.0 +pipelineSync :: Connection + -> IO Bool +pipelineSync connection = + enumFromConn connection c_PQpipelineSync + +-- | Sends a request for the server to flush its output buffer. +-- +-- @since 0.11.0.0 +sendFlushRequest :: Connection + -> IO Bool +sendFlushRequest connection = + enumFromConn connection c_PQsendFlushRequest + -- $cancel -- A client application can request cancellation of a command that is @@ -1846,7 +1712,6 @@ flush connection = -- | Contains the information needed to cancel a command issued -- through a particular database connection. newtype Cancel = Cancel (ForeignPtr PGcancel) deriving (Eq, Show) -data PGcancel -- | Creates a data structure containing the information needed to @@ -1858,7 +1723,7 @@ data PGcancel getCancel :: Connection -> IO (Maybe Cancel) getCancel connection = - withConn connection $ \conn -> + mask_ $ withConn connection $ \conn -> do ptr <- c_PQgetCancel conn if ptr == nullPtr then return Nothing @@ -1906,33 +1771,7 @@ cancel (Cancel fp) = -- ordinary SQL commands. The arrival of NOTIFY messages can -- subsequently be detected by calling 'notifies'. -data Notify = Notify { - notifyRelname :: {-# UNPACK #-} !B.ByteString -- ^ notification channel name - , notifyBePid :: {-# UNPACK #-} !CPid -- ^ process ID of notifying server process - , notifyExtra :: {-# UNPACK #-} !B.ByteString -- ^ notification payload string - } deriving Show - -#let alignment t = "%lu", (unsigned long)offsetof(struct {char x__; t (y__); }, y__) -instance Storable Notify where - sizeOf _ = #{size PGnotify} - alignment _ = #{alignment PGnotify} - - peek ptr = do - relname <- B.packCString =<< #{peek PGnotify, relname} ptr - extra <- B.packCString =<< #{peek PGnotify, extra} ptr - be_pid <- fmap f $ #{peek PGnotify, be_pid} ptr - return $! Notify relname be_pid extra - where - f :: CInt -> CPid - f = fromIntegral - - poke ptr (Notify a b c) = - B.useAsCString a $ \a' -> - B.useAsCString c $ \c' -> - do #{poke PGnotify, relname} ptr a' - #{poke PGnotify, be_pid} ptr (fromIntegral b :: CInt) - #{poke PGnotify, extra} ptr c' -- | Returns the next notification from a list of unhandled @@ -1978,21 +1817,6 @@ setClientEncoding connection enc = return $! stat == 0 -data Verbosity = ErrorsTerse - | ErrorsDefault - | ErrorsVerbose deriving (Eq, Show) - -instance Enum Verbosity where - toEnum (#const PQERRORS_TERSE) = ErrorsTerse - toEnum (#const PQERRORS_DEFAULT) = ErrorsDefault - toEnum (#const PQERRORS_VERBOSE) = ErrorsVerbose - toEnum _ = error "Database.PQ.Enum.Verbosity.toEnum: bad argument" - - fromEnum ErrorsTerse = (#const PQERRORS_TERSE) - fromEnum ErrorsDefault = (#const PQERRORS_DEFAULT) - fromEnum ErrorsVerbose = (#const PQERRORS_VERBOSE) - - -- | Determines the verbosity of messages returned by 'errorMessage' -- and 'resultErrorMessage'. -- @@ -2010,25 +1834,21 @@ setErrorVerbosity :: Connection -> IO Verbosity setErrorVerbosity connection verbosity = enumFromConn connection $ \p -> - c_PQsetErrorVerbosity p $ fromIntegral $ fromEnum verbosity - -withConn :: Connection - -> (Ptr PGconn -> IO b) - -> IO b -withConn (Conn !fp _) f = withForeignPtr fp f - + c_PQsetErrorVerbosity p $ toCInt verbosity -enumFromConn :: (Integral a, Enum b) => Connection - -> (Ptr PGconn -> IO a) +enumFromConn :: FromCInt b + => Connection + -> (Ptr PGconn -> IO CInt) -> IO b -enumFromConn connection f = fmap (toEnum . fromIntegral) $ withConn connection f +enumFromConn connection f = withConn connection f >>= maybe (fail "enumFromConn") return . fromCInt resultFromConn :: Connection -> (Ptr PGconn -> IO (Ptr PGresult)) -> IO (Maybe Result) resultFromConn connection f = - do resPtr <- withConn connection f + mask_ $ do + resPtr <- withConn connection f if resPtr == nullPtr then return Nothing else (Just . Result) `fmap` newForeignPtr p_PQclear resPtr @@ -2046,10 +1866,11 @@ numFromResult :: (Integral a, Num b) => Result numFromResult result f = fmap fromIntegral $ withResult result f -enumFromResult :: (Integral a, Enum b) => Result - -> (Ptr PGresult -> IO a) +enumFromResult :: FromCInt b + => Result + -> (Ptr PGresult -> IO CInt) -> IO b -enumFromResult result f = fmap (toEnum . fromIntegral) $ withResult result f +enumFromResult result f = withResult result f >>= maybe (fail "enumFromResult") return . fromCInt -- | Returns a ByteString with a finalizer that touches the ForeignPtr @@ -2096,27 +1917,36 @@ maybeBsFromForeignPtr fp f = -- where -- finalizer = touchForeignPtr fp -data CNoticeBuffer -type NoticeBuffer = Ptr CNoticeBuffer - -type NoticeReceiver = NoticeBuffer -> Ptr PGresult -> IO () - -data PGnotice +-- | Upon connection initialization, any notices received from the server are +-- normally written to the console. Notices are akin to warnings, and +-- are distinct from notifications. This function suppresses notices. +-- You may later call 'enableNoticeReporting' after calling this function. disableNoticeReporting :: Connection -> IO () disableNoticeReporting conn@(Conn _ nbRef) = do _ <- withConn conn $ \c -> c_PQsetNoticeReceiver c p_discard_notices nullPtr nb <- swapMVar nbRef nullPtr c_free_noticebuffer nb - +-- | Upon connection initialization, any notices received from the server are +-- normally written to the console. Notices are akin to warnings, and +-- are distinct from notifications. This function enables notices to be +-- programmatically retreived using the 'getNotice' function. You may +-- later call 'disableNoticeReporting' after calling this function. enableNoticeReporting :: Connection -> IO () enableNoticeReporting conn@(Conn _ nbRef) = do - nb' <- c_malloc_noticebuffer - _ <- withConn conn $ \c -> c_PQsetNoticeReceiver c p_store_notices nb' - nb <- swapMVar nbRef nb' - c_free_noticebuffer nb - + if isNullConnection conn + then return () + else do + nb' <- c_malloc_noticebuffer + _ <- withConn conn $ \c -> c_PQsetNoticeReceiver c p_store_notices nb' + nb <- swapMVar nbRef nb' + c_free_noticebuffer nb + +-- | This function retrieves any notices received from the backend. +-- Because multiple notices can be received at a time, you will +-- typically want to call this function in a loop until you get +-- back a 'Nothing'. getNotice :: Connection -> IO (Maybe B.ByteString) getNotice (Conn _ nbRef) = withMVar nbRef $ \nb -> do @@ -2125,8 +1955,8 @@ getNotice (Conn _ nbRef) = then return Nothing else do fp <- newForeignPtr finalizerFree (castPtr np) - len <- #{peek PGnotice, len} np - return $! Just $! B.PS fp (#offset PGnotice, str) len + len <- pgNoticePeekLen np + return $! Just $! mkPS fp pgNoticeOffsetStr (fromIntegral len) -- $largeobjects @@ -2136,11 +1966,7 @@ getNotice (Conn _ nbRef) = newtype LoFd = LoFd CInt deriving (Eq, Ord, Show) loMode :: IOMode -> CInt -loMode mode = case mode of - ReadMode -> (#const INV_READ) - WriteMode -> (#const INV_WRITE) - ReadWriteMode -> (#const INV_READ) .|. (#const INV_WRITE) - AppendMode -> (#const INV_WRITE) +loMode = toCInt toMaybeOid :: Oid -> IO (Maybe Oid) toMaybeOid oid | oid == invalidOid = return Nothing @@ -2238,7 +2064,7 @@ loOpen connection oid mode -- handling is likely to be slightly wrong. Start by -- reading the source of lo_open, lo_lseek, and -- lo_close. - err <- c_lo_lseek c fd 0 (#const SEEK_END) + err <- c_lo_lseek c fd 0 (toCInt SeekFromEnd) case err of -1 -> do -- the lo_lseek failed, so we try to close the fd @@ -2286,10 +2112,7 @@ loSeek :: Connection -> LoFd -> SeekMode -> Int -> IO (Maybe Int) loSeek connection (LoFd fd) seekmode delta = withConn connection $ \c -> do let d = fromIntegral delta - pos <- c_lo_lseek c fd d $ case seekmode of - AbsoluteSeek -> #const SEEK_SET - RelativeSeek -> #const SEEK_CUR - SeekFromEnd -> #const SEEK_END + pos <- c_lo_lseek c fd d $ toCInt seekmode nonnegInt pos -- | Obtains the current read or write location of a large object descriptor. @@ -2327,333 +2150,3 @@ loUnlink :: Connection -> Oid -> IO (Maybe ()) loUnlink connection oid = withConn connection $ \c -> do negError =<< c_lo_unlink c oid - - - -foreign import ccall "libpq-fe.h PQconnectdb" - c_PQconnectdb :: CString ->IO (Ptr PGconn) - -foreign import ccall "libpq-fe.h PQconnectStart" - c_PQconnectStart :: CString ->IO (Ptr PGconn) - -foreign import ccall "libpq-fe.h PQconnectPoll" - c_PQconnectPoll :: Ptr PGconn ->IO CInt - -foreign import ccall unsafe "libpq-fe.h PQdb" - c_PQdb :: Ptr PGconn -> IO CString - -foreign import ccall unsafe "libpq-fe.h PQuser" - c_PQuser :: Ptr PGconn -> IO CString - -foreign import ccall unsafe "libpq-fe.h PQpass" - c_PQpass :: Ptr PGconn -> IO CString - -foreign import ccall unsafe "libpq-fe.h PQhost" - c_PQhost :: Ptr PGconn -> IO CString - -foreign import ccall unsafe "libpq-fe.h PQport" - c_PQport :: Ptr PGconn -> IO CString - -foreign import ccall unsafe "libpq-fe.h PQoptions" - c_PQoptions :: Ptr PGconn -> IO CString - -foreign import ccall unsafe "libpq-fe.h PQbackendPID" - c_PQbackendPID :: Ptr PGconn -> IO CInt - -foreign import ccall unsafe "libpq-fe.h PQconnectionNeedsPassword" - c_PQconnectionNeedsPassword :: Ptr PGconn -> IO CInt - -foreign import ccall unsafe "libpq-fe.h PQconnectionUsedPassword" - c_PQconnectionUsedPassword :: Ptr PGconn -> IO CInt - -foreign import ccall unsafe "libpq-fe.h PQstatus" - c_PQstatus :: Ptr PGconn -> IO CInt - -foreign import ccall unsafe "libpq-fe.h PQtransactionStatus" - c_PQtransactionStatus :: Ptr PGconn -> IO CInt - -foreign import ccall "libpq-fe.h PQparameterStatus" - c_PQparameterStatus :: Ptr PGconn -> CString -> IO CString - -foreign import ccall unsafe "libpq-fe.h PQprotocolVersion" - c_PQprotocolVersion :: Ptr PGconn -> IO CInt - -foreign import ccall unsafe "libpq-fe.h PQserverVersion" - c_PQserverVersion :: Ptr PGconn -> IO CInt - -foreign import ccall unsafe "libpq-fe.h PQsocket" - c_PQsocket :: Ptr PGconn -> IO CInt - -foreign import ccall "libpq-fe.h PQerrorMessage" - c_PQerrorMessage :: Ptr PGconn -> IO CString - -#if __GLASGOW_HASKELL__ >= 700 -foreign import ccall "libpq-fe.h PQfinish" - c_PQfinish :: Ptr PGconn -> IO () -#else -foreign import ccall "libpq-fe.h &PQfinish" - p_PQfinish :: FunPtr (Ptr PGconn -> IO ()) -#endif - -foreign import ccall "libpq-fe.h PQreset" - c_PQreset :: Ptr PGconn -> IO () - -foreign import ccall "libpq-fe.h PQresetStart" - c_PQresetStart :: Ptr PGconn ->IO CInt - -foreign import ccall "libpq-fe.h PQresetPoll" - c_PQresetPoll :: Ptr PGconn ->IO CInt - -foreign import ccall unsafe "libpq-fe.h PQclientEncoding" - c_PQclientEncoding :: Ptr PGconn -> IO CInt - -foreign import ccall "libpq-fe.h pg_encoding_to_char" - c_pg_encoding_to_char :: CInt -> IO CString - -foreign import ccall "libpq-fe.h PQsetClientEncoding" - c_PQsetClientEncoding :: Ptr PGconn -> CString -> IO CInt - -type PGVerbosity = CInt -foreign import ccall unsafe "libpq-fe.h PQsetErrorVerbosity" - c_PQsetErrorVerbosity :: Ptr PGconn -> PGVerbosity -> IO PGVerbosity - -foreign import ccall "libpq-fe.h PQputCopyData" - c_PQputCopyData :: Ptr PGconn -> Ptr CChar -> CInt -> IO CInt - -foreign import ccall "libpq-fe.h PQputCopyEnd" - c_PQputCopyEnd :: Ptr PGconn -> CString -> IO CInt - -foreign import ccall "libpq-fe.h PQgetCopyData" - c_PQgetCopyData :: Ptr PGconn -> Ptr (Ptr Word8) -> CInt -> IO CInt - -foreign import ccall "libpq-fe.h PQsendQuery" - c_PQsendQuery :: Ptr PGconn -> CString ->IO CInt - -foreign import ccall "libpq-fe.h PQsendQueryParams" - c_PQsendQueryParams :: Ptr PGconn -> CString -> CInt -> Ptr Oid - -> Ptr CString -> Ptr CInt -> Ptr CInt -> CInt - -> IO CInt - -foreign import ccall "libpq-fe.h PQsendPrepare" - c_PQsendPrepare :: Ptr PGconn -> CString -> CString -> CInt -> Ptr Oid - -> IO CInt - -foreign import ccall "libpq-fe.h PQsendQueryPrepared" - c_PQsendQueryPrepared :: Ptr PGconn -> CString -> CInt -> Ptr CString - -> Ptr CInt -> Ptr CInt -> CInt -> IO CInt - -foreign import ccall "libpq-fe.h PQsendDescribePrepared" - c_PQsendDescribePrepared :: Ptr PGconn -> CString -> IO CInt - -foreign import ccall "libpq-fe.h PQsendDescribePortal" - c_PQsendDescribePortal :: Ptr PGconn -> CString -> IO CInt - -foreign import ccall "libpq-fe.h PQflush" - c_PQflush :: Ptr PGconn -> IO CInt - -foreign import ccall "libpq-fe.h PQgetCancel" - c_PQgetCancel :: Ptr PGconn -> IO (Ptr PGcancel) - -foreign import ccall "libpq-fe.h &PQfreeCancel" - p_PQfreeCancel :: FunPtr (Ptr PGcancel -> IO ()) - -foreign import ccall "libpq-fe.h PQcancel" - c_PQcancel :: Ptr PGcancel -> CString -> CInt -> IO CInt - -foreign import ccall unsafe "libpq-fe.h PQnotifies" - c_PQnotifies :: Ptr PGconn -> IO (Ptr Notify) - -foreign import ccall unsafe "libpq-fe.h PQconsumeInput" - c_PQconsumeInput :: Ptr PGconn -> IO CInt - -foreign import ccall unsafe "libpq-fe.h PQisBusy" - c_PQisBusy :: Ptr PGconn -> IO CInt - -foreign import ccall "libpq-fe.h PQsetnonblocking" - c_PQsetnonblocking :: Ptr PGconn -> CInt -> IO CInt - -foreign import ccall unsafe "libpq-fe.h PQisnonblocking" - c_PQisnonblocking :: Ptr PGconn -> IO CInt - -foreign import ccall "libpq-fe.h PQgetResult" - c_PQgetResult :: Ptr PGconn -> IO (Ptr PGresult) - -foreign import ccall "libpq-fe.h PQexec" - c_PQexec :: Ptr PGconn -> CString -> IO (Ptr PGresult) - -foreign import ccall "libpq-fe.h PQexecParams" - c_PQexecParams :: Ptr PGconn -> CString -> CInt -> Ptr Oid - -> Ptr CString -> Ptr CInt -> Ptr CInt -> CInt - -> IO (Ptr PGresult) - -foreign import ccall "libpq-fe.h PQprepare" - c_PQprepare :: Ptr PGconn -> CString -> CString -> CInt -> Ptr Oid - -> IO (Ptr PGresult) - -foreign import ccall "libpq-fe.h PQexecPrepared" - c_PQexecPrepared :: Ptr PGconn -> CString -> CInt -> Ptr CString - -> Ptr CInt -> Ptr CInt -> CInt -> IO (Ptr PGresult) - -foreign import ccall "libpq-fe.h PQdescribePrepared" - c_PQdescribePrepared :: Ptr PGconn -> CString -> IO (Ptr PGresult) - -foreign import ccall "libpq-fe.h PQdescribePortal" - c_PQdescribePortal :: Ptr PGconn -> CString -> IO (Ptr PGresult) - -foreign import ccall "libpq-fe.h &PQclear" - p_PQclear :: FunPtr (Ptr PGresult ->IO ()) - -foreign import ccall unsafe "libpq-fe.h PQresultStatus" - c_PQresultStatus :: Ptr PGresult -> IO CInt - -foreign import ccall unsafe "libpq-fe.h PQresStatus" - c_PQresStatus :: CInt -> IO CString - -foreign import ccall unsafe "libpq-fe.h PQresultErrorMessage" - c_PQresultErrorMessage :: Ptr PGresult -> IO CString - -foreign import ccall "libpq-fe.h PQresultErrorField" - c_PQresultErrorField :: Ptr PGresult -> CInt -> IO CString - -foreign import ccall unsafe "libpq-fe.h PQntuples" - c_PQntuples :: Ptr PGresult -> CInt - -foreign import ccall unsafe "libpq-fe.h PQnfields" - c_PQnfields :: Ptr PGresult -> CInt - -foreign import ccall unsafe "libpq-fe.h PQfname" - c_PQfname :: Ptr PGresult -> CInt -> IO CString - -foreign import ccall unsafe "libpq-fe.h PQfnumber" - c_PQfnumber :: Ptr PGresult -> CString -> IO CInt - -foreign import ccall unsafe "libpq-fe.h PQftable" - c_PQftable :: Ptr PGresult -> CInt -> IO Oid - -foreign import ccall unsafe "libpq-fe.h PQftablecol" - c_PQftablecol :: Ptr PGresult -> CInt -> IO CInt - -foreign import ccall unsafe "libpq-fe.h PQfformat" - c_PQfformat :: Ptr PGresult -> CInt -> IO CInt - -foreign import ccall unsafe "libpq-fe.h PQftype" - c_PQftype :: Ptr PGresult -> CInt -> IO Oid - -foreign import ccall unsafe "libpq-fe.h PQfmod" - c_PQfmod :: Ptr PGresult -> CInt -> IO CInt - -foreign import ccall unsafe "libpq-fe.h PQfsize" - c_PQfsize :: Ptr PGresult -> CInt -> IO CInt - -foreign import ccall unsafe "libpq-fe.h PQgetvalue" - c_PQgetvalue :: Ptr PGresult -> CInt -> CInt -> IO CString - -foreign import ccall unsafe "libpq-fe.h PQgetisnull" - c_PQgetisnull :: Ptr PGresult -> CInt -> CInt -> IO CInt - -foreign import ccall unsafe "libpq-fe.h PQgetlength" - c_PQgetlength :: Ptr PGresult -> CInt -> CInt -> IO CInt - -foreign import ccall unsafe "libpq-fe.h PQnparams" - c_PQnparams :: Ptr PGresult -> IO CInt - -foreign import ccall unsafe "libpq-fe.h PQparamtype" - c_PQparamtype :: Ptr PGresult -> CInt -> IO Oid - -foreign import ccall unsafe "libpq-fe.h PQcmdStatus" - c_PQcmdStatus :: Ptr PGresult -> IO CString - -foreign import ccall unsafe "libpq-fe.h PQcmdTuples" - c_PQcmdTuples :: Ptr PGresult -> IO CString - -foreign import ccall "libpq-fe.h PQescapeStringConn" - c_PQescapeStringConn :: Ptr PGconn - -> Ptr Word8 -- Actually (CString) - -> CString - -> CSize - -> Ptr CInt - -> IO CSize - -foreign import ccall "libpq-fe.h PQescapeByteaConn" - c_PQescapeByteaConn :: Ptr PGconn - -> CString -- Actually (Ptr CUChar) - -> CSize - -> Ptr CSize - -> IO (Ptr Word8) -- Actually (IO (Ptr CUChar)) - -foreign import ccall "libpq-fe.h PQunescapeBytea" - c_PQunescapeBytea :: CString -- Actually (Ptr CUChar) - -> Ptr CSize - -> IO (Ptr Word8) -- Actually (IO (Ptr CUChar)) - -foreign import ccall unsafe "libpq-fe.h PQescapeIdentifier" - c_PQescapeIdentifier :: Ptr PGconn - -> CString - -> CSize - -> IO CString - -foreign import ccall unsafe "libpq-fe.h &PQfreemem" - p_PQfreemem :: FunPtr (Ptr a -> IO ()) - -foreign import ccall unsafe "libpq-fe.h PQfreemem" - c_PQfreemem :: Ptr a -> IO () - -foreign import ccall unsafe "noticehandlers.h hs_postgresql_libpq_malloc_noticebuffer" - c_malloc_noticebuffer :: IO (Ptr CNoticeBuffer) - -foreign import ccall unsafe "noticehandlers.h hs_postgresql_libpq_free_noticebuffer" - c_free_noticebuffer :: Ptr CNoticeBuffer -> IO () - -foreign import ccall unsafe "noticehandlers.h hs_postgresql_libpq_get_notice" - c_get_notice :: Ptr CNoticeBuffer -> IO (Ptr PGnotice) - -foreign import ccall unsafe "noticehandlers.h &hs_postgresql_libpq_discard_notices" - p_discard_notices :: FunPtr NoticeReceiver - -foreign import ccall unsafe "noticehandlers.h &hs_postgresql_libpq_store_notices" - p_store_notices :: FunPtr NoticeReceiver - -foreign import ccall unsafe "libpq-fe.h PQsetNoticeReceiver" - c_PQsetNoticeReceiver :: Ptr PGconn -> FunPtr NoticeReceiver -> Ptr CNoticeBuffer -> IO (FunPtr NoticeReceiver) - - -type CFd = CInt - -foreign import ccall "libpq-fs.h lo_creat" - c_lo_creat :: Ptr PGconn -> CInt -> IO Oid - -foreign import ccall "libpq-fs.h lo_create" - c_lo_create :: Ptr PGconn -> Oid -> IO Oid - -foreign import ccall "libpq-fs.h lo_import" - c_lo_import :: Ptr PGconn -> CString -> IO Oid - -foreign import ccall "libpq-fs.h lo_import_with_oid" - c_lo_import_with_oid :: Ptr PGconn -> CString -> Oid -> IO Oid - -foreign import ccall "libpq-fs.h lo_export" - c_lo_export :: Ptr PGconn -> Oid -> CString -> IO CInt - -foreign import ccall "libpq-fs.h lo_open" - c_lo_open :: Ptr PGconn -> Oid -> CInt -> IO CFd - -foreign import ccall "libpq-fs.h lo_write" - c_lo_write :: Ptr PGconn -> CFd -> CString -> CSize -> IO CInt - -foreign import ccall "libpq-fs.h lo_read" - c_lo_read :: Ptr PGconn -> CFd -> Ptr Word8 -> CSize -> IO CInt - -foreign import ccall "libpq-fs.h lo_lseek" - c_lo_lseek :: Ptr PGconn -> CFd -> CInt -> CInt -> IO CInt - -foreign import ccall "libpq-fs.h lo_tell" - c_lo_tell :: Ptr PGconn -> CFd -> IO CInt - -foreign import ccall "libpq-fs.h lo_truncate" - c_lo_truncate :: Ptr PGconn -> CFd -> CSize -> IO CInt - -foreign import ccall "libpq-fs.h lo_close" - c_lo_close :: Ptr PGconn -> CFd -> IO CInt - -foreign import ccall "libpq-fs.h lo_unlink" - c_lo_unlink :: Ptr PGconn -> Oid -> IO CInt diff --git a/src/Database/PostgreSQL/LibPQ/Compat.hs b/src/Database/PostgreSQL/LibPQ/Compat.hs new file mode 100644 index 0000000..4bdd48a --- /dev/null +++ b/src/Database/PostgreSQL/LibPQ/Compat.hs @@ -0,0 +1,27 @@ +{-# LANGUAGE CPP #-} +{-# LANGUAGE MagicHash #-} +module Database.PostgreSQL.LibPQ.Compat where + +import Data.ByteString.Internal (ByteString (..)) +import Data.Word (Word8) +import Foreign.ForeignPtr (ForeignPtr) + +#if MIN_VERSION_bytestring(0,11,0) +import Data.ByteString.Internal (plusForeignPtr) +#endif + +withPS :: ByteString -> (ForeignPtr Word8 -> Int -> Int -> r) -> r +#if MIN_VERSION_bytestring(0,11,0) +withPS (BS fp len) kont = kont fp 0 len +#else +withPS (PS fp off len) kont = kont fp off len +#endif +{-# INLINE withPS #-} + +mkPS :: ForeignPtr Word8 -> Int -> Int -> ByteString +#if MIN_VERSION_bytestring(0,11,0) +mkPS fp off len = BS (plusForeignPtr fp off) len +#else +mkPS fp off len = PS fp off len +#endif +{-# INLINE mkPS #-} diff --git a/src/Database/PostgreSQL/LibPQ/Enums.hsc b/src/Database/PostgreSQL/LibPQ/Enums.hsc new file mode 100644 index 0000000..52001a1 --- /dev/null +++ b/src/Database/PostgreSQL/LibPQ/Enums.hsc @@ -0,0 +1,348 @@ +module Database.PostgreSQL.LibPQ.Enums where + +#include "hs-libpq.h" + +import Data.Bits ((.|.)) +import Data.Maybe (fromMaybe) +import Foreign.C.Types (CInt (..)) +import System.IO (IOMode(..), SeekMode(..)) + +------------------------------------------------------------------------------- +-- Type classes +------------------------------------------------------------------------------- + +class ToCInt a where + toCInt :: a -> CInt + +class FromCInt a where + fromCInt :: CInt -> Maybe a + +------------------------------------------------------------------------------- +-- Enumerations +------------------------------------------------------------------------------- + +data ExecStatus + = EmptyQuery -- ^ The string sent to the server was empty. + | CommandOk -- ^ Successful completion of a + -- command returning no data. + | TuplesOk -- ^ Successful completion of a + -- command returning data (such as a + -- SELECT or SHOW). + | CopyOut -- ^ Copy Out (from server) data + -- transfer started. + | CopyIn -- ^ Copy In (to server) data transfer + -- started. + | CopyBoth -- ^ Copy In/Out data transfer started. + | BadResponse -- ^ The server's response was not understood. + | NonfatalError -- ^ A nonfatal error (a notice or + -- warning) occurred. + | FatalError -- ^ A fatal error occurred. + | SingleTuple -- ^ The 'Result' contains a single result tuple + -- from the current command. This status occurs + -- only when single-row mode has been selected + -- for the query. + + | PipelineSync -- ^ The 'Result' represents a synchronization + -- point in pipeline mode, requested by + -- 'pipelineSync'. This status occurs only + -- when pipeline mode has been selected. + -- + -- @since 0.11.0.0 + + | PipelineAbort -- ^ The 'Result' represents a pipeline that + -- has received an error from the server. + -- 'getResult' must be called repeatedly, + -- and each time it will return this status + -- code until the end of the current pipeline, + -- at which point it will return 'PipelineSync' + -- and normal processing can resume. + -- + -- @since 0.11.0.0 + deriving (Eq, Show) + +instance FromCInt ExecStatus where + fromCInt (#const PGRES_EMPTY_QUERY) = Just EmptyQuery + fromCInt (#const PGRES_COMMAND_OK) = Just CommandOk + fromCInt (#const PGRES_TUPLES_OK) = Just TuplesOk + fromCInt (#const PGRES_COPY_OUT) = Just CopyOut + fromCInt (#const PGRES_COPY_IN) = Just CopyIn + fromCInt (#const PGRES_COPY_BOTH) = Just CopyBoth + fromCInt (#const PGRES_BAD_RESPONSE) = Just BadResponse + fromCInt (#const PGRES_NONFATAL_ERROR) = Just NonfatalError + fromCInt (#const PGRES_FATAL_ERROR) = Just FatalError + fromCInt (#const PGRES_SINGLE_TUPLE) = Just SingleTuple + fromCInt (#const PGRES_PIPELINE_SYNC) = Just PipelineSync + fromCInt (#const PGRES_PIPELINE_ABORTED) = Just PipelineAbort + fromCInt _ = Nothing + +instance ToCInt ExecStatus where + toCInt EmptyQuery = (#const PGRES_EMPTY_QUERY) + toCInt CommandOk = (#const PGRES_COMMAND_OK) + toCInt TuplesOk = (#const PGRES_TUPLES_OK) + toCInt CopyOut = (#const PGRES_COPY_OUT) + toCInt CopyIn = (#const PGRES_COPY_IN) + toCInt CopyBoth = (#const PGRES_COPY_BOTH) + toCInt BadResponse = (#const PGRES_BAD_RESPONSE) + toCInt NonfatalError = (#const PGRES_NONFATAL_ERROR) + toCInt FatalError = (#const PGRES_FATAL_ERROR) + toCInt SingleTuple = (#const PGRES_SINGLE_TUPLE) + toCInt PipelineSync = (#const PGRES_PIPELINE_SYNC) + toCInt PipelineAbort = (#const PGRES_PIPELINE_ABORTED) + + +data FieldCode + = DiagSeverity + -- ^ The severity; the field contents are ERROR, FATAL, + -- or PANIC (in an error message), or WARNING, NOTICE, + -- DEBUG, INFO, or LOG (in a notice message), or a + -- localized translation of one of these. Always + -- present. + + | DiagSqlstate + -- ^ The SQLSTATE code for the error. The SQLSTATE code + -- identifies the type of error that has occurred; it + -- can be used by front-end applications to perform + -- specific operations (such as error handling) in + -- response to a particular database error. For a list + -- of the possible SQLSTATE codes, see Appendix A. This + -- field is not localizable, and is always present. + + | DiagMessagePrimary + -- ^ The primary human-readable error message + -- (typically one line). Always present. + + | DiagMessageDetail + -- ^ Detail: an optional secondary error message + -- carrying more detail about the problem. Might run to + -- multiple lines. + + | DiagMessageHint + -- ^ Hint: an optional suggestion what to do about the + -- problem. This is intended to differ from detail in + -- that it offers advice (potentially inappropriate) + -- rather than hard facts. Might run to multiple lines. + + | DiagStatementPosition + -- ^ A string containing a decimal integer indicating + -- an error cursor position as an index into the + -- original statement string. The first character has + -- index 1, and positions are measured in characters + -- not bytes. + + | DiagInternalPosition + -- ^ This is defined the same as the + -- 'DiagStatementPosition' field, but it is used when + -- the cursor position refers to an internally + -- generated command rather than the one submitted by + -- the client. The 'DiagInternalQuery' field will + -- always appear when this field appears. + + | DiagInternalQuery + -- ^ The text of a failed internally-generated + -- command. This could be, for example, a SQL query + -- issued by a PL/pgSQL function. + + | DiagContext + -- ^ An indication of the context in which the error + -- occurred. Presently this includes a call stack + -- traceback of active procedural language functions + -- and internally-generated queries. The trace is one + -- entry per line, most recent first. + + | DiagSourceFile + -- ^ The file name of the source-code location where + -- the error was reported. + + | DiagSourceLine + -- ^ The line number of the source-code location where + -- the error was reported. + + | DiagSourceFunction + -- ^ The name of the source-code function reporting the + -- error. + + deriving (Eq, Show) + +instance FromCInt FieldCode where + fromCInt (#const PG_DIAG_SEVERITY) = Just DiagSeverity + fromCInt (#const PG_DIAG_SQLSTATE) = Just DiagSqlstate + fromCInt (#const PG_DIAG_MESSAGE_PRIMARY) = Just DiagMessagePrimary + fromCInt (#const PG_DIAG_MESSAGE_DETAIL) = Just DiagMessageDetail + fromCInt (#const PG_DIAG_MESSAGE_HINT) = Just DiagMessageHint + fromCInt (#const PG_DIAG_STATEMENT_POSITION) = Just DiagStatementPosition + fromCInt (#const PG_DIAG_INTERNAL_POSITION) = Just DiagInternalPosition + fromCInt (#const PG_DIAG_INTERNAL_QUERY) = Just DiagInternalQuery + fromCInt (#const PG_DIAG_CONTEXT) = Just DiagContext + fromCInt (#const PG_DIAG_SOURCE_FILE) = Just DiagSourceFile + fromCInt (#const PG_DIAG_SOURCE_LINE) = Just DiagSourceLine + fromCInt (#const PG_DIAG_SOURCE_FUNCTION) = Just DiagSourceFunction + fromCInt _ = Nothing + +instance ToCInt FieldCode where + toCInt DiagSeverity = (#const PG_DIAG_SEVERITY) + toCInt DiagSqlstate = (#const PG_DIAG_SQLSTATE) + toCInt DiagMessagePrimary = (#const PG_DIAG_MESSAGE_PRIMARY) + toCInt DiagMessageDetail = (#const PG_DIAG_MESSAGE_DETAIL) + toCInt DiagMessageHint = (#const PG_DIAG_MESSAGE_HINT) + toCInt DiagStatementPosition = (#const PG_DIAG_STATEMENT_POSITION) + toCInt DiagInternalPosition = (#const PG_DIAG_INTERNAL_POSITION) + toCInt DiagInternalQuery = (#const PG_DIAG_INTERNAL_QUERY) + toCInt DiagContext = (#const PG_DIAG_CONTEXT) + toCInt DiagSourceFile = (#const PG_DIAG_SOURCE_FILE) + toCInt DiagSourceLine = (#const PG_DIAG_SOURCE_LINE) + toCInt DiagSourceFunction = (#const PG_DIAG_SOURCE_FUNCTION) + + +data Verbosity + = ErrorsTerse + | ErrorsDefault + | ErrorsVerbose + deriving (Eq, Show) + +instance FromCInt Verbosity where + fromCInt (#const PQERRORS_TERSE) = Just ErrorsTerse + fromCInt (#const PQERRORS_DEFAULT) = Just ErrorsDefault + fromCInt (#const PQERRORS_VERBOSE) = Just ErrorsVerbose + fromCInt _ = Nothing + +instance ToCInt Verbosity where + toCInt ErrorsTerse = (#const PQERRORS_TERSE) + toCInt ErrorsDefault = (#const PQERRORS_DEFAULT) + toCInt ErrorsVerbose = (#const PQERRORS_VERBOSE) + + +data PollingStatus + = PollingFailed + | PollingReading + | PollingWriting + | PollingOk + deriving (Eq, Show) + +instance FromCInt PollingStatus where + fromCInt (#const PGRES_POLLING_READING) = return PollingReading + fromCInt (#const PGRES_POLLING_OK) = return PollingOk + fromCInt (#const PGRES_POLLING_WRITING) = return PollingWriting + fromCInt (#const PGRES_POLLING_FAILED) = return PollingFailed + fromCInt _ = Nothing + + +data ConnStatus + = ConnectionOk -- ^ The 'Connection' is ready. + | ConnectionBad -- ^ The connection procedure has failed. + | ConnectionStarted -- ^ Waiting for connection to be made. + | ConnectionMade -- ^ Connection OK; waiting to send. + | ConnectionAwaitingResponse -- ^ Waiting for a response from the server. + | ConnectionAuthOk -- ^ Received authentication; + -- waiting for backend start-up to + -- finish. + | ConnectionSetEnv -- ^ Negotiating environment-driven + -- parameter settings. + | ConnectionSSLStartup -- ^ Negotiating SSL encryption. + deriving (Eq, Show) + +instance FromCInt ConnStatus where + fromCInt (#const CONNECTION_OK) = return ConnectionOk + fromCInt (#const CONNECTION_BAD) = return ConnectionBad + fromCInt (#const CONNECTION_STARTED) = return ConnectionStarted + fromCInt (#const CONNECTION_MADE) = return ConnectionMade + fromCInt (#const CONNECTION_AWAITING_RESPONSE) = return ConnectionAwaitingResponse + fromCInt (#const CONNECTION_AUTH_OK) = return ConnectionAuthOk + fromCInt (#const CONNECTION_SETENV) = return ConnectionSetEnv + fromCInt (#const CONNECTION_SSL_STARTUP) = return ConnectionSSLStartup + -- fromCInt (#const CONNECTION_NEEDED) = return ConnectionNeeded + fromCInt _ = Nothing + + +data TransactionStatus + = TransIdle -- ^ currently idle + | TransActive -- ^ a command is in progress + | TransInTrans -- ^ idle, in a valid transaction block + | TransInError -- ^ idle, in a failed transaction block + | TransUnknown -- ^ the connection is bad + deriving (Eq, Show) + +instance FromCInt TransactionStatus where + fromCInt (#const PQTRANS_IDLE) = return TransIdle + fromCInt (#const PQTRANS_ACTIVE) = return TransActive + fromCInt (#const PQTRANS_INTRANS) = return TransInTrans + fromCInt (#const PQTRANS_INERROR) = return TransInError + fromCInt (#const PQTRANS_UNKNOWN) = return TransUnknown + fromCInt _ = Nothing + + +data Format + = Text + | Binary + deriving (Eq, Ord, Show, Enum) + +instance ToCInt Format where + toCInt Text = 0 + toCInt Binary = 1 + +instance FromCInt Format where + fromCInt 0 = Just Text + fromCInt 1 = Just Binary + fromCInt _ = Nothing + + +-- | +-- +-- @since 0.11.0.0 +data PipelineStatus + = PipelineOn -- ^ The 'Connection' is in pipeline mode. + | PipelineOff -- ^ The 'Connection' is /not/ in pipeline mode. + | PipelineAborted -- ^ The 'Connection' is in pipeline mode and an error + -- occurred while processing the current pipeline. The + -- aborted flag is cleared when 'getResult' returns a + -- result with status 'PipelineSync'. + deriving (Eq, Show) + +instance FromCInt PipelineStatus where + fromCInt (#const PQ_PIPELINE_ON) = return PipelineOn + fromCInt (#const PQ_PIPELINE_OFF) = return PipelineOff + fromCInt (#const PQ_PIPELINE_ABORTED) = return PipelineAborted + fromCInt _ = Nothing + +------------------------------------------------------------------------------- +-- System.IO enumerations +------------------------------------------------------------------------------- + +instance ToCInt IOMode where + toCInt ReadMode = (#const INV_READ) + toCInt WriteMode = (#const INV_WRITE) + toCInt ReadWriteMode = (#const INV_READ) .|. (#const INV_WRITE) + toCInt AppendMode = (#const INV_WRITE) + +instance ToCInt SeekMode where + toCInt AbsoluteSeek = #const SEEK_SET + toCInt RelativeSeek = #const SEEK_CUR + toCInt SeekFromEnd = #const SEEK_END + +------------------------------------------------------------------------------- +-- Prelude +------------------------------------------------------------------------------- + +instance ToCInt Bool where + toCInt False = 0 + toCInt True = 1 + +instance FromCInt Bool where + fromCInt 0 = Just False + fromCInt 1 = Just True + fromCInt _ = Nothing + +------------------------------------------------------------------------------- +-- Enum instances (for backwards compatibility) +------------------------------------------------------------------------------- + +instance Enum ExecStatus where + toEnum = fromMaybe (error "toEnum @Database.PostgreSQL.LibPQ.ExecStatus") . fromCInt . toEnum + fromEnum = fromEnum . toCInt + +instance Enum FieldCode where + toEnum = fromMaybe (error "toEnum @Database.PostgreSQL.LibPQ.FieldCode") . fromCInt . toEnum + fromEnum = fromEnum . toCInt + +instance Enum Verbosity where + toEnum = fromMaybe (error "toEnum @Database.PostgreSQL.LibPQ.Verbosity") . fromCInt . toEnum + fromEnum = fromEnum . toCInt diff --git a/src/Database/PostgreSQL/LibPQ/FFI.hs b/src/Database/PostgreSQL/LibPQ/FFI.hs new file mode 100644 index 0000000..5bc11ac --- /dev/null +++ b/src/Database/PostgreSQL/LibPQ/FFI.hs @@ -0,0 +1,383 @@ +{-# LANGUAGE CApiFFI #-} +{-# LANGUAGE EmptyDataDecls #-} +module Database.PostgreSQL.LibPQ.FFI where + +import Data.Word (Word8) +import Foreign.C.String (CString) +import Foreign.C.Types (CChar, CInt (..), CSize (..), CUInt (..)) +import Foreign.Ptr (FunPtr, Ptr) + +import Database.PostgreSQL.LibPQ.Internal (CNoticeBuffer, NoticeBuffer, PGconn) +import Database.PostgreSQL.LibPQ.Notify (Notify, PGnotice) +import Database.PostgreSQL.LibPQ.Oid (Oid (..)) + +------------------------------------------------------------------------------- +-- Types / Ptr tags +------------------------------------------------------------------------------- + +data PGresult +data PGcancel + +type CFd = CInt + +type NoticeReceiver = NoticeBuffer -> Ptr PGresult -> IO () + +------------------------------------------------------------------------------- +-- FFI imports +------------------------------------------------------------------------------- + +foreign import capi "hs-libpq.h PQconnectdb" + c_PQconnectdb :: CString -> IO (Ptr PGconn) + +foreign import capi "hs-libpq.h PQconnectStart" + c_PQconnectStart :: CString -> IO (Ptr PGconn) + +foreign import capi "hs-libpq.h PQconnectPoll" + c_PQconnectPoll :: Ptr PGconn -> IO CInt + +foreign import capi "hs-libpq.h PQdb" + c_PQdb :: Ptr PGconn -> IO CString + +foreign import capi "hs-libpq.h PQuser" + c_PQuser :: Ptr PGconn -> IO CString + +foreign import capi "hs-libpq.h PQpass" + c_PQpass :: Ptr PGconn -> IO CString + +foreign import capi "hs-libpq.h PQhost" + c_PQhost :: Ptr PGconn -> IO CString + +foreign import capi "hs-libpq.h PQport" + c_PQport :: Ptr PGconn -> IO CString + +foreign import capi "hs-libpq.h PQoptions" + c_PQoptions :: Ptr PGconn -> IO CString + +foreign import capi "hs-libpq.h PQbackendPID" + c_PQbackendPID :: Ptr PGconn -> IO CInt + +foreign import capi "hs-libpq.h PQconnectionNeedsPassword" + c_PQconnectionNeedsPassword :: Ptr PGconn -> IO CInt + +foreign import capi "hs-libpq.h PQconnectionUsedPassword" + c_PQconnectionUsedPassword :: Ptr PGconn -> IO CInt + +foreign import capi "hs-libpq.h PQstatus" + c_PQstatus :: Ptr PGconn -> IO CInt + +foreign import capi "hs-libpq.h PQtransactionStatus" + c_PQtransactionStatus :: Ptr PGconn -> IO CInt + +-- TODO: GHC #22043 +foreign import ccall "hs-libpq.h PQparameterStatus" + c_PQparameterStatus :: Ptr PGconn -> CString -> IO CString + +foreign import capi "hs-libpq.h PQprotocolVersion" + c_PQprotocolVersion :: Ptr PGconn -> IO CInt + +foreign import capi "hs-libpq.h PQserverVersion" + c_PQserverVersion :: Ptr PGconn -> IO CInt + +foreign import capi "hs-libpq.h PQlibVersion" + c_PQlibVersion :: IO CInt + +foreign import capi "hs-libpq.h PQsocket" + c_PQsocket :: Ptr PGconn -> IO CInt + +foreign import capi "hs-libpq.h PQerrorMessage" + c_PQerrorMessage :: Ptr PGconn -> IO CString + +foreign import capi "hs-libpq.h PQfinish" + c_PQfinish :: Ptr PGconn -> IO () + +foreign import capi "hs-libpq.h PQreset" + c_PQreset :: Ptr PGconn -> IO () + +foreign import capi "hs-libpq.h PQresetStart" + c_PQresetStart :: Ptr PGconn -> IO CInt + +foreign import capi "hs-libpq.h PQresetPoll" + c_PQresetPoll :: Ptr PGconn -> IO CInt + +foreign import capi "hs-libpq.h PQclientEncoding" + c_PQclientEncoding :: Ptr PGconn -> IO CInt + +-- TODO: GHC #22043 +foreign import ccall "hs-libpq.h pg_encoding_to_char" + c_pg_encoding_to_char :: CInt -> IO CString + +foreign import capi "hs-libpq.h PQsetClientEncoding" + c_PQsetClientEncoding :: Ptr PGconn -> CString -> IO CInt + +type PGVerbosity = CInt +foreign import capi "hs-libpq.h PQsetErrorVerbosity" + c_PQsetErrorVerbosity :: Ptr PGconn -> PGVerbosity -> IO PGVerbosity + +foreign import capi "hs-libpq.h PQputCopyData" + c_PQputCopyData :: Ptr PGconn -> Ptr CChar -> CInt -> IO CInt + +foreign import capi "hs-libpq.h PQputCopyEnd" + c_PQputCopyEnd :: Ptr PGconn -> CString -> IO CInt + +-- TODO: GHC #22043 +foreign import ccall "hs-libpq.h PQgetCopyData" + c_PQgetCopyData :: Ptr PGconn -> Ptr (Ptr Word8) -> CInt -> IO CInt + +foreign import capi "hs-libpq.h PQsendQuery" + c_PQsendQuery :: Ptr PGconn -> CString -> IO CInt + +-- TODO: GHC #22043 +foreign import ccall "hs-libpq.h PQsendQueryParams" + c_PQsendQueryParams :: Ptr PGconn -> CString -> CInt -> Ptr Oid + -> Ptr CString -> Ptr CInt -> Ptr CInt -> CInt + -> IO CInt + +foreign import capi "hs-libpq.h PQsendPrepare" + c_PQsendPrepare :: Ptr PGconn -> CString -> CString -> CInt -> Ptr Oid + -> IO CInt + +-- TODO: GHC #22043 +foreign import ccall "hs-libpq.h PQsendQueryPrepared" + c_PQsendQueryPrepared :: Ptr PGconn -> CString -> CInt -> Ptr CString + -> Ptr CInt -> Ptr CInt -> CInt -> IO CInt + +foreign import capi "hs-libpq.h PQsendDescribePrepared" + c_PQsendDescribePrepared :: Ptr PGconn -> CString -> IO CInt + +foreign import capi "hs-libpq.h PQsendDescribePortal" + c_PQsendDescribePortal :: Ptr PGconn -> CString -> IO CInt + +foreign import capi "hs-libpq.h PQflush" + c_PQflush :: Ptr PGconn -> IO CInt + +foreign import capi "hs-libpq.h PQgetCancel" + c_PQgetCancel :: Ptr PGconn -> IO (Ptr PGcancel) + +foreign import capi "hs-libpq.h &PQfreeCancel" + p_PQfreeCancel :: FunPtr (Ptr PGcancel -> IO ()) + +foreign import capi "hs-libpq.h PQcancel" + c_PQcancel :: Ptr PGcancel -> CString -> CInt -> IO CInt + +foreign import capi "hs-libpq.h PQnotifies" + c_PQnotifies :: Ptr PGconn -> IO (Ptr Notify) + +foreign import capi "hs-libpq.h PQconsumeInput" + c_PQconsumeInput :: Ptr PGconn -> IO CInt + +foreign import capi "hs-libpq.h PQisBusy" + c_PQisBusy :: Ptr PGconn -> IO CInt + +foreign import capi "hs-libpq.h PQsetnonblocking" + c_PQsetnonblocking :: Ptr PGconn -> CInt -> IO CInt + +foreign import capi "hs-libpq.h PQisnonblocking" + c_PQisnonblocking :: Ptr PGconn -> IO CInt + +foreign import capi "hs-libpq.h PQsetSingleRowMode" + c_PQsetSingleRowMode :: Ptr PGconn -> IO CInt + +foreign import capi "hs-libpq.h PQgetResult" + c_PQgetResult :: Ptr PGconn -> IO (Ptr PGresult) + +foreign import capi "hs-libpq.h PQexec" + c_PQexec :: Ptr PGconn -> CString -> IO (Ptr PGresult) + +-- TODO: GHC #22043 +foreign import ccall "hs-libpq.h PQexecParams" + c_PQexecParams :: Ptr PGconn -> CString -> CInt -> Ptr Oid + -> Ptr CString -> Ptr CInt -> Ptr CInt -> CInt + -> IO (Ptr PGresult) + +foreign import capi "hs-libpq.h PQprepare" + c_PQprepare :: Ptr PGconn -> CString -> CString -> CInt -> Ptr Oid + -> IO (Ptr PGresult) + +-- TODO: GHC #22043 +foreign import ccall "hs-libpq.h PQexecPrepared" + c_PQexecPrepared :: Ptr PGconn -> CString -> CInt -> Ptr CString + -> Ptr CInt -> Ptr CInt -> CInt -> IO (Ptr PGresult) + +foreign import capi "hs-libpq.h PQdescribePrepared" + c_PQdescribePrepared :: Ptr PGconn -> CString -> IO (Ptr PGresult) + +foreign import capi "hs-libpq.h PQdescribePortal" + c_PQdescribePortal :: Ptr PGconn -> CString -> IO (Ptr PGresult) + +foreign import capi "hs-libpq.h &PQclear" + p_PQclear :: FunPtr (Ptr PGresult -> IO ()) + +foreign import capi "hs-libpq.h PQresultStatus" + c_PQresultStatus :: Ptr PGresult -> IO CInt + +foreign import capi "hs-libpq.h PQresStatus" + c_PQresStatus :: CInt -> IO CString + +foreign import capi "hs-libpq.h PQresultErrorMessage" + c_PQresultErrorMessage :: Ptr PGresult -> IO CString + +foreign import capi "hs-libpq.h PQresultErrorField" + c_PQresultErrorField :: Ptr PGresult -> CInt -> IO CString + +foreign import capi "hs-libpq.h PQntuples" + c_PQntuples :: Ptr PGresult -> CInt + +foreign import capi "hs-libpq.h PQnfields" + c_PQnfields :: Ptr PGresult -> CInt + +foreign import capi "hs-libpq.h PQfname" + c_PQfname :: Ptr PGresult -> CInt -> IO CString + +foreign import capi "hs-libpq.h PQfnumber" + c_PQfnumber :: Ptr PGresult -> CString -> IO CInt + +foreign import capi "hs-libpq.h PQftable" + c_PQftable :: Ptr PGresult -> CInt -> IO Oid + +foreign import capi "hs-libpq.h PQftablecol" + c_PQftablecol :: Ptr PGresult -> CInt -> IO CInt + +foreign import capi "hs-libpq.h PQfformat" + c_PQfformat :: Ptr PGresult -> CInt -> IO CInt + +foreign import capi "hs-libpq.h PQftype" + c_PQftype :: Ptr PGresult -> CInt -> IO Oid + +foreign import capi "hs-libpq.h PQfmod" + c_PQfmod :: Ptr PGresult -> CInt -> IO CInt + +foreign import capi "hs-libpq.h PQfsize" + c_PQfsize :: Ptr PGresult -> CInt -> IO CInt + +foreign import capi "hs-libpq.h PQgetvalue" + c_PQgetvalue :: Ptr PGresult -> CInt -> CInt -> IO CString + +foreign import capi "hs-libpq.h PQgetisnull" + c_PQgetisnull :: Ptr PGresult -> CInt -> CInt -> IO CInt + +foreign import capi "hs-libpq.h PQgetlength" + c_PQgetlength :: Ptr PGresult -> CInt -> CInt -> IO CInt + +foreign import capi "hs-libpq.h PQnparams" + c_PQnparams :: Ptr PGresult -> IO CInt + +foreign import capi "hs-libpq.h PQparamtype" + c_PQparamtype :: Ptr PGresult -> CInt -> IO Oid + +foreign import capi "hs-libpq.h PQcmdStatus" + c_PQcmdStatus :: Ptr PGresult -> IO CString + +foreign import capi "hs-libpq.h PQcmdTuples" + c_PQcmdTuples :: Ptr PGresult -> IO CString + +foreign import capi "hs-libpq.h PQescapeStringConn" + c_PQescapeStringConn :: Ptr PGconn + -> Ptr Word8 -- Actually (CString) + -> CString + -> CSize + -> Ptr CInt + -> IO CSize + +foreign import capi "hs-libpq.h PQescapeByteaConn" + c_PQescapeByteaConn :: Ptr PGconn + -> CString -- Actually (Ptr CUChar) + -> CSize + -> Ptr CSize + -> IO (Ptr Word8) -- Actually (IO (Ptr CUChar)) + +foreign import capi "hs-libpq.h PQunescapeBytea" + c_PQunescapeBytea :: CString -- Actually (Ptr CUChar) + -> Ptr CSize + -> IO (Ptr Word8) -- Actually (IO (Ptr CUChar)) + +foreign import capi "hs-libpq.h PQescapeIdentifier" + c_PQescapeIdentifier :: Ptr PGconn + -> CString + -> CSize + -> IO CString + +foreign import capi "hs-libpq.h &PQfreemem" + p_PQfreemem :: FunPtr (Ptr a -> IO ()) + +foreign import capi "hs-libpq.h PQfreemem" + c_PQfreemem :: Ptr a -> IO () + +foreign import capi "hs-libpq.h PQpipelineStatus" + c_PQpipelineStatus :: Ptr PGconn -> IO CInt + +foreign import capi "hs-libpq.h PQenterPipelineMode" + c_PQenterPipelineMode :: Ptr PGconn -> IO CInt + +foreign import capi "hs-libpq.h PQexitPipelineMode" + c_PQexitPipelineMode :: Ptr PGconn -> IO CInt + +foreign import capi "hs-libpq.h PQpipelineSync" + c_PQpipelineSync :: Ptr PGconn -> IO CInt + +foreign import capi "hs-libpq.h PQsendFlushRequest" + c_PQsendFlushRequest :: Ptr PGconn -> IO CInt + +------------------------------------------------------------------------------- +-- FFI imports: noticebuffers +------------------------------------------------------------------------------- + +foreign import capi "hs-libpq.h hs_postgresql_libpq_malloc_noticebuffer" + c_malloc_noticebuffer :: IO (Ptr CNoticeBuffer) + +foreign import capi "hs-libpq.h hs_postgresql_libpq_free_noticebuffer" + c_free_noticebuffer :: Ptr CNoticeBuffer -> IO () + +foreign import capi "hs-libpq.h hs_postgresql_libpq_get_notice" + c_get_notice :: Ptr CNoticeBuffer -> IO (Ptr PGnotice) + +foreign import capi "hs-libpq.h &hs_postgresql_libpq_discard_notices" + p_discard_notices :: FunPtr NoticeReceiver + +foreign import capi "hs-libpq.h &hs_postgresql_libpq_store_notices" + p_store_notices :: FunPtr NoticeReceiver + +foreign import capi "hs-libpq.h PQsetNoticeReceiver" + c_PQsetNoticeReceiver :: Ptr PGconn -> FunPtr NoticeReceiver -> Ptr CNoticeBuffer -> IO (FunPtr NoticeReceiver) + +------------------------------------------------------------------------------- +-- FFI imports: Large Objects +------------------------------------------------------------------------------- + +foreign import capi "hs-libpq.h lo_creat" + c_lo_creat :: Ptr PGconn -> CInt -> IO Oid + +foreign import capi "hs-libpq.h lo_create" + c_lo_create :: Ptr PGconn -> Oid -> IO Oid + +foreign import capi "hs-libpq.h lo_import" + c_lo_import :: Ptr PGconn -> CString -> IO Oid + +foreign import capi "hs-libpq.h lo_import_with_oid" + c_lo_import_with_oid :: Ptr PGconn -> CString -> Oid -> IO Oid + +foreign import capi "hs-libpq.h lo_export" + c_lo_export :: Ptr PGconn -> Oid -> CString -> IO CInt + +foreign import capi "hs-libpq.h lo_open" + c_lo_open :: Ptr PGconn -> Oid -> CInt -> IO CFd + +foreign import capi "hs-libpq.h lo_write" + c_lo_write :: Ptr PGconn -> CFd -> CString -> CSize -> IO CInt + +foreign import capi "hs-libpq.h lo_read" + c_lo_read :: Ptr PGconn -> CFd -> Ptr Word8 -> CSize -> IO CInt + +foreign import capi "hs-libpq.h lo_lseek" + c_lo_lseek :: Ptr PGconn -> CFd -> CInt -> CInt -> IO CInt + +foreign import capi "hs-libpq.h lo_tell" + c_lo_tell :: Ptr PGconn -> CFd -> IO CInt + +foreign import capi "hs-libpq.h lo_truncate" + c_lo_truncate :: Ptr PGconn -> CFd -> CSize -> IO CInt + +foreign import capi "hs-libpq.h lo_close" + c_lo_close :: Ptr PGconn -> CFd -> IO CInt + +foreign import capi "hs-libpq.h lo_unlink" + c_lo_unlink :: Ptr PGconn -> Oid -> IO CInt diff --git a/src/Database/PostgreSQL/LibPQ/Internal.hs b/src/Database/PostgreSQL/LibPQ/Internal.hs new file mode 100644 index 0000000..e56fa7d --- /dev/null +++ b/src/Database/PostgreSQL/LibPQ/Internal.hs @@ -0,0 +1,45 @@ +----------------------------------------------------------------------------- +-- | +-- Module : Database.PostgreSQL.LibPQ.Internal +-- Copyright : (c) 2010 Grant Monroe, +-- (c) 2011 Leon P Smith +-- License : BSD3 +-- +-- This module exports the data constructor for the database connection +-- object so that people may create their own foreign bindings to libpq +-- functions that may not exist yet in vanilla postgresql-libpq. +-- +----------------------------------------------------------------------------- + +{-# LANGUAGE BangPatterns #-} +{-# LANGUAGE EmptyDataDecls #-} + +module Database.PostgreSQL.LibPQ.Internal ( + Connection (..), + withConn, + PGconn, + CNoticeBuffer, + NoticeBuffer, +) where + +import Control.Concurrent.MVar (MVar) +import Foreign (ForeignPtr, Ptr, withForeignPtr) + +-- | 'Connection' encapsulates a connection to the backend. +data Connection = Conn {-# UNPACK #-} !(ForeignPtr PGconn) + {-# UNPACK #-} !(MVar NoticeBuffer) + +instance Eq Connection where + (Conn c _) == (Conn d _) = c == d + (Conn c _) /= (Conn d _) = c /= d + +withConn :: Connection + -> (Ptr PGconn -> IO b) + -> IO b +withConn (Conn !fp _) f = withForeignPtr fp f +{-# INLINE withConn #-} + +data PGconn + +data CNoticeBuffer +type NoticeBuffer = Ptr CNoticeBuffer diff --git a/src/Database/PostgreSQL/LibPQ/Marshal.hs b/src/Database/PostgreSQL/LibPQ/Marshal.hs new file mode 100644 index 0000000..8945812 --- /dev/null +++ b/src/Database/PostgreSQL/LibPQ/Marshal.hs @@ -0,0 +1,19 @@ +{-# LANGUAGE CPP #-} +module Database.PostgreSQL.LibPQ.Marshal where + +import Foreign (Ptr, Storable, allocaArray, nullPtr, pokeArray) + +unsafeWithArray :: Storable a => Int -> [a] -> (Ptr a -> IO b) -> IO b +unsafeWithArray len vals f = +#if 0 + if len /= length vals then error "unsafeWithArray: len mismatch" else +#endif + allocaArray len $ \ptr -> do + pokeArray ptr vals + f ptr + +-- | Like maybe with but takes an int. Usable with 'withArrayLen'. +-- In 'Nothing' case uses 0 and 'nullPtr'. +maybeWithInt :: ( a -> (Int -> Ptr b -> IO c) -> IO c) + -> (Maybe a -> (Int -> Ptr b -> IO c) -> IO c) +maybeWithInt = maybe (\f -> f 0 nullPtr) diff --git a/src/Database/PostgreSQL/LibPQ/Notify.hsc b/src/Database/PostgreSQL/LibPQ/Notify.hsc new file mode 100644 index 0000000..30f9878 --- /dev/null +++ b/src/Database/PostgreSQL/LibPQ/Notify.hsc @@ -0,0 +1,52 @@ +module Database.PostgreSQL.LibPQ.Notify where + +#include "hs-libpq.h" + +import Foreign (Ptr, Storable (..)) +import Foreign.C.Types (CInt, CSize) +import System.Posix.Types (CPid) + +import qualified Data.ByteString as B + +------------------------------------------------------------------------------- +-- Notify +------------------------------------------------------------------------------- + +data Notify = Notify { + notifyRelname :: {-# UNPACK #-} !B.ByteString -- ^ notification channel name + , notifyBePid :: {-# UNPACK #-} !CPid -- ^ process ID of notifying server process + , notifyExtra :: {-# UNPACK #-} !B.ByteString -- ^ notification payload string + } deriving Show + +instance Storable Notify where + sizeOf _ = #{size PGnotify} + + alignment _ = #{alignment PGnotify} + + peek ptr = do + relname <- B.packCString =<< #{peek PGnotify, relname} ptr + extra <- B.packCString =<< #{peek PGnotify, extra} ptr + be_pid <- fmap f $ #{peek PGnotify, be_pid} ptr + return $! Notify relname be_pid extra + where + f :: CInt -> CPid + f = fromIntegral + + poke ptr (Notify a b c) = + B.useAsCString a $ \a' -> + B.useAsCString c $ \c' -> + do #{poke PGnotify, relname} ptr a' + #{poke PGnotify, be_pid} ptr (fromIntegral b :: CInt) + #{poke PGnotify, extra} ptr c' + +------------------------------------------------------------------------------- +-- Notice +------------------------------------------------------------------------------- + +data PGnotice + +pgNoticePeekLen :: Ptr PGnotice -> IO CSize +pgNoticePeekLen = #{peek PGnotice, len} + +pgNoticeOffsetStr :: Int +pgNoticeOffsetStr = #{offset PGnotice, str} diff --git a/src/Database/PostgreSQL/LibPQ/Oid.hsc b/src/Database/PostgreSQL/LibPQ/Oid.hsc new file mode 100644 index 0000000..f8ca906 --- /dev/null +++ b/src/Database/PostgreSQL/LibPQ/Oid.hsc @@ -0,0 +1,15 @@ +{-# LANGUAGE DerivingStrategies #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-} +module Database.PostgreSQL.LibPQ.Oid where + +#include + +import Foreign.C.Types (CUInt) +import Foreign.Storable (Storable) + +newtype Oid = Oid CUInt + deriving stock (Eq, Ord, Read, Show) + deriving newtype (Storable) + +invalidOid :: Oid +invalidOid = Oid (#const InvalidOid) diff --git a/src/Database/PostgreSQL/LibPQ/Ptr.hs b/src/Database/PostgreSQL/LibPQ/Ptr.hs new file mode 100644 index 0000000..c4162d8 --- /dev/null +++ b/src/Database/PostgreSQL/LibPQ/Ptr.hs @@ -0,0 +1,7 @@ +{-# LANGUAGE MagicHash #-} +module Database.PostgreSQL.LibPQ.Ptr (emptyPtr) where + +import GHC.Ptr (Ptr (..)) + +emptyPtr :: Ptr a +emptyPtr = Ptr ""# diff --git a/test/Smoke.hs b/test/Smoke.hs new file mode 100644 index 0000000..d21894b --- /dev/null +++ b/test/Smoke.hs @@ -0,0 +1,121 @@ +{-# LANGUAGE OverloadedStrings #-} +module Main (main) where + +import Control.Monad (unless) +import Data.Foldable (toList) +import Database.PostgreSQL.LibPQ +import System.Environment (getEnvironment) +import Test.Tasty (defaultMain, testGroup) +import Test.Tasty.HUnit (assertEqual, testCaseSteps) + +import qualified Data.ByteString as BS +import qualified Data.ByteString.Char8 as BS8 + +main :: IO () +main = do + libpqVersion >>= print + withConnstring $ \connString -> defaultMain $ testGroup "postgresql-libpq" + [ testCaseSteps "smoke" $ smoke connString + , testCaseSteps "issue54" $ issue54 connString + , testCaseSteps "pipeline" $ testPipeline connString + ] + +withConnstring :: (BS8.ByteString -> IO ()) -> IO () +withConnstring kont = do + env <- getEnvironment + case lookup "DATABASE_CONNSTRING" env of + Just s -> kont (BS8.pack (special s)) + Nothing -> case lookup "GITHUB_ACTIONS" env of + Just "true" -> kont (BS8.pack gha) + _ -> putStrLn "Set DATABASE_CONNSTRING environment variable" + where + -- https://www.appveyor.com/docs/services-databases/ + special "appveyor" = "dbname='TestDb' user='postgres' password='Password12!'" + special "travis" = "" + special s = s + + gha = unwords + [ "dbname='postgres'" + , "user='postgres'" + , "password='postgres'" + , "host='postgres'" + , "port=5432" + ] + +smoke :: BS8.ByteString -> (String -> IO ()) -> IO () +smoke connstring info = do + let infoShow x = info (show x) + + conn <- connectdb connstring + + -- status functions + db conn >>= infoShow + user conn >>= infoShow + host conn >>= infoShow + port conn >>= infoShow + status conn >>= infoShow + transactionStatus conn >>= infoShow + protocolVersion conn >>= infoShow + serverVersion conn >>= infoShow + pipelineStatus conn >>= infoShow + + s <- status conn + assertEqual "connection not ok" ConnectionOk s + + finish conn + +issue54 :: BS8.ByteString -> (String -> IO ()) -> IO () +issue54 connString info = do + conn <- connectdb connString + + Just result <- execParams conn + "SELECT ($1 :: bytea), ($2 :: bytea)" + [Just (Oid 17,"",Binary), Just (Oid 17,BS.empty,Binary)] + Binary + s <- resultStatus result + assertEqual "result status" TuplesOk s + + -- ntuples result >>= info . show + -- nfields result >>= info . show + + null1 <- getisnull result 0 0 + null2 <- getisnull result 0 1 + assertEqual "fst not null" False null1 + assertEqual "snd not null" False null2 + + Just val1 <- getvalue result 0 0 + Just val2 <- getvalue result 0 1 + + assertEqual "fst not null" BS.empty val1 + assertEqual "snd not null" BS.empty val2 + +testPipeline :: BS8.ByteString -> (String -> IO ()) -> IO () +testPipeline connstring info = do + conn <- connectdb connstring + + setnonblocking conn True `shouldReturn` True + enterPipelineMode conn `shouldReturn` True + pipelineStatus conn `shouldReturn` PipelineOn + sendQueryParams conn (BS8.pack "select 1") [] Text `shouldReturn` True + sendQueryParams conn (BS8.pack "select 2") [] Text `shouldReturn` True + pipelineSync conn `shouldReturn` True + + Just r1 <- getResult conn + resultStatus r1 `shouldReturn` TuplesOk + getvalue r1 0 0 `shouldReturn` Just (BS8.pack "1") + Nothing <- getResult conn + + Just r2 <- getResult conn + getvalue r2 0 0 `shouldReturn` Just (BS8.pack "2") + Nothing <- getResult conn + + Just r3 <- getResult conn + resultStatus r3 `shouldReturn` PipelineSync + + finish conn + where + shouldBe r value = assertEqual "shouldBe" r value + + shouldReturn action value = do + r <- action + r `shouldBe` value