File: configure.ac

package info (click to toggle)
r-cran-rpostgresql 0.7-7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 720 kB
  • sloc: sh: 3,070; ansic: 3,054; makefile: 7
file content (170 lines) | stat: -rw-r--r-- 4,410 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# Process this file with autoconf to produce a configure script.
#
# Configure.in for RPostgreSQL
# Copyright (C) 2008 Dirk Eddelbuettel and licensed under GNU GPL
#
# This file draws heavily on configure.in files from littler, RMySQL, and RdbiPgSQL

: ${R_HOME=`R RHOME`}
if test -z "${R_HOME}"; then
  echo "could not determine R_HOME"
  exit 1
fi
CC=`"${R_HOME}/bin/R" CMD config CC`
CFLAGS=`"${R_HOME}/bin/R" CMD config CFLAGS`
CPPFLAGS=`"${R_HOME}/bin/R" CMD config CPPFLAGS`

# Set the name and version -- the version set here will propagate to other files from here
AC_INIT([RPostgreSQL],[0.7])

AC_CONFIG_AUX_DIR(src)

AC_CANONICAL_HOST
AC_CANONICAL_TARGET
case "${host_os}" in
  darwin*)
    R_OS_TYPE="darwin"
    ;;
esac


# Check for non-standard programs: pg_config(1) to configure PostgreSQL builds
AC_PATH_PROG([PG_CONFIG], [pg_config])

# By default, we will not use the accompanied libpq 
ENABLE_LIBPQ=

# If pg_config was found, let's use it
if test "${PG_CONFIG}" != ""; then
    # for debug purpose, let pg_config print all the information
    ${PG_CONFIG} | sed -e 's/^/PG_CONFIG_/' -e '/C.*FLAGS/s/-W/cflwarn/g'
    # edit the output to avoid unnecessary warning

    # Use pg_config for header and linker arguments
    PG_INCDIR=`${PG_CONFIG} --includedir`
    PG_LIBDIR=`${PG_CONFIG} --libdir`

fi
# If pg_config wasn't found, or was found but references a directory that doesn't exist,
# Let's look elsewhere

if ! test -d "${PG_INCDIR}" || ! test -d "${PG_LIBDIR}" ; then
    unset PG_INCDIR
    unset PG_LIBDIR
fi

    # let's look around -- code copied from RdbuiPgSQL but modified to use test -f
    AC_MSG_NOTICE([checking for PostgreSQL header files])
    if ! test -d "$PG_INCDIR"
    then
	for dir in \
	/usr/include \
	/usr/include/postgresql \
	/usr/local/include \
	/usr/local/include/postgresql \
	/usr/local/pgsql/include \
	/usr/local/postgresql/include 
	do
        AC_MSG_NOTICE([Checking include ${dir}.])
	    if test -f ${dir}/libpq-fe.h
	    then
	    	PG_INCDIR=${dir}
		break
	    fi
	done
    fi
	
    # likewise, let's look around for libpq.so
    if ! test $PG_LIBDIR
    then
	for dir in \
	/usr/lib \
	/usr/lib/postgresql \
	/usr/local/lib \
	/usr/local/lib/postgresql \
	/usr/local/postgresql/lib 
	do
        AC_MSG_NOTICE([Checking lib ${dir}.])
	    if test -f ${dir}/libpq.so
	    then
	    	PG_LIBDIR=${dir}
		break
	    fi
	    if test -f ${dir}/libpq.dylib
	    then
	    	PG_LIBDIR=${dir}
		break
	    fi
	done
    fi
    if test $PG_LIBDIR && test $PG_INCDIR
    then
       echo $PG_LIBDIR
       echo $PG_INCDIR
    fi
    if test "$R_OS_TYPE" = "darwin" ; then
# in case we cannot find any libpq library we will use the accompanied libpq
# This content would be written into src/Makevars at the end of this script
            DARWIN_INTERNAL_LIBPQ='

PKG_CPPFLAGS=-Ilibpq
PKG_LIBS=libpq/libpq.a

.PHONY: all
all:  $(SHLIB)
$(SHLIB): libpq/libpq.5.dylib

libpq/libpq.5.dylib:
	(cd libpq; $(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" -f Makefile.darwin pg_config.h pg_config_os.h all)

clean:
	(cd libpq; $(MAKE) -f Makefile.darwin clean)
'
    fi 
# if darwin

# check if a program using libpq can be executed.
# int PQlibVersion(void);

## AC_CHECK_LIB(pq, PQlibVersion, ENABLE_LIBPQ="")

AC_LANG(C)
 echo '#include <libpq-fe.h>' > conftest.c
 echo 'int main(void);int main(void){printf("%i...",PQlibVersion());return 0;}' >> conftest.c
echo $CC $CFLAGS -I${PG_INCDIR} -L${PG_LIBDIR} conftest.c -lpq -o pqconftest
$CC $CFLAGS -I${PG_INCDIR} -L${PG_LIBDIR} conftest.c -lpq -o pqconftest
echo ./pqconftest
./pqconftest
status=$?
if test $status -eq 0 ; then
  echo "runs fine"
  ENABLE_LIBPQ="" 
else
  echo "system -lpq don't appear to work; use internal"
  ENABLE_LIBPQ=$DARWIN_INTERNAL_LIBPQ; 
fi
rm -f pqconftest conftest.c

# Expand into arguments

#  make sure we use the included libpq-fe.h if it was not previously found
if ! test "$ENABLE_LIBPQ" = '' ; then
	AC_MSG_NOTICE([Using internal package libpq-fe.h])
	PG_INCDIR="src/libpq"
fi

PKG_CPPFLAGS="-I${PG_INCDIR}"
PKG_LIBS="-L${PG_LIBDIR} -lpq"

# Test for sanity by looking for libpq-fe.h, no explicit action on found, error on failure
AC_CHECK_FILE(["${PG_INCDIR}/libpq-fe.h"],
	,
	AC_SUBST(R_OS_TYPE))

# Now substitute these two variable in src/Makevars.in to create src/Makevars
AC_SUBST(PKG_CPPFLAGS)
AC_SUBST(PKG_LIBS)

AC_SUBST(ENABLE_LIBPQ)
AC_CONFIG_FILES([src/Makevars])
AC_OUTPUT