1# Autoconf's _AC_SRCDIRS (from status.m4; historically _AC_SRCPATHS)
2# doesn't quite suit the C++ Toolkit's conventions; tweak it accordingly.
3m4_copy([_AC_SRCDIRS], [NCBI_ORIG__AC_SRCDIRS])
4m4_define([_AC_SRCDIRS],
5[# Base source directories on path to *input* file.
6if test -n "$ac_f"; then
7   ac_f_rel=`echo "$ac_f" | sed -e 's,^/.*/\./,,'`
8   ac_dir_in=`AS_DIRNAME(["$ac_f_rel"])`
9else
10   ac_dir_in=$1
11fi
12
13NCBI_ORIG__AC_SRCDIRS(["$ac_dir_in"])
14
15AS_SET_CATFILE([ac_abs_top_srcdir], [$ac_dir_in], [$real_srcdir])
16ac_builddir=$builddir
17])
18
19
20dnl _AS_DETECT_BETTER_SHELL(from m4sh.m4; historically part of
21dnl _AS_LINENO_PREPARE) also needs tweaking, to make bash a last resort
22dnl due to issues with sourcing .bashrc.
23m4_copy([_AS_DETECT_BETTER_SHELL], [NCBI_ORIG__AS_DETECT_BETTER_SHELL])
24
25m4_define([_AS_DETECT_BETTER_SHELL],
26  [patsubst(m4_defn([NCBI_ORIG__AS_DETECT_BETTER_SHELL]),
27     [sh bash ksh sh5], [sh ksh sh5 bash])])
28
29
30# One more hack: suppress PACKAGE_*, as we don't use them and some
31# third-party libraries expose their corresponding settings, leading
32# to preprocessor warnings.
33m4_copy([AC_DEFINE_UNQUOTED], [NCBI_ORIG_AC_DEFINE_UNQUOTED])
34m4_ifdef([_AC_DEFINE_UNQUOTED],
35   [m4_copy([_AC_DEFINE_UNQUOTED], [_NCBI_ORIG_AC_DEFINE_UNQUOTED])])
36m4_define([AC_DEFINE_UNQUOTED],
37   [ifelse(m4_substr([$1], 0, 8), [PACKAGE_], [],
38       [NCBI_ORIG_AC_DEFINE_UNQUOTED($@)])])
39
40
41AC_DEFUN(NCBI_FIX_DIR,
42[ncbi_fix_dir_tmp=`if cd $[$1]; then AS_UNSET(PWD); /bin/pwd; fi`
43 case "$ncbi_fix_dir_tmp" in
44    /.*) ncbi_fix_dir_tmp2=`cd $[$1] && $smart_pwd 2>/dev/null`
45         if test -n "$ncbi_fix_dir_tmp2" -a -d "$ncbi_fix_dir_tmp2"; then
46            $1=$ncbi_fix_dir_tmp2
47         else
48            case "$[$1]" in
49               /*) ;;
50               * ) $1=$ncbi_fix_dir_tmp ;;
51            esac
52         fi
53         ;;
54    /*) $1=$ncbi_fix_dir_tmp ;;
55 esac])
56
57
58# Keep track of (un)available features, packages, and projects.
59AC_DEFUN(NCBI_FEAT_EX,
60         [m4_append_uniq([NCBI_ALL_]$1, $2, [ ])dnl
61          With$1="[$]With$1[$]{With$1Sep}$2"; With$1Sep=" "])
62AC_DEFUN(NCBI_FEATURE, [NCBI_FEAT_EX(Features, $1)])
63AC_DEFUN(NCBI_PACKAGE, [NCBI_FEAT_EX(Packages, $1)])
64AC_DEFUN(NCBI_PROJECT, [NCBI_FEAT_EX(Projects, $1)])
65
66
67# Argument: question to ask user.
68AC_DEFUN(NCBI_CAUTION,
69[case "$with_caution" in
70    yes )
71       AC_MSG_ERROR([Configuration has been canceled per --with-caution.]) ;;
72    no )
73       AC_MSG_WARN([Proceeding without questions per --without-caution]) ;;
74    * )
75       echo "$1 [[y/N]]"
76       read answer <& AS_ORIGINAL_STDIN_FD
77       case "$answer" in
78         [[Yy]]* )  AC_MSG_WARN([Proceeding at your own risk...]) ;;
79         *       )  AC_MSG_ERROR([Configuration has been canceled by user.]) ;;
80       esac
81       ;;
82 esac])
83
84
85# Arguments:
86# 1. library name (turned into environment/make variable)
87# 2. values to check
88# 3. function name
89AC_DEFUN(NCBI_CHECK_LIBS,
90[saved_LIBS=$LIBS
91 AC_SEARCH_LIBS($3, ["[$]$1_LIBS" $2],
92  [AC_DEFINE(HAVE_LIB$1, 1,
93   [Define to 1 if $1 is available, either in its own library or as part
94    of the standard libraries.])
95   test "x$ac_cv_search_$3" = "xnone required" || $1_LIBS=$ac_cv_search_$3],
96   [])
97 LIBS=$saved_LIBS
98])
99
100
101# Arguments:
102# 1. variable name
103# 2. path(s)
104# 3. suffix (optional)
105dnl
106dnl Naive implementation
107dnl
108dnl AC_DEFUN(NCBI_RPATHIFY,
109dnl [$1="-L$2 ${CONF_f_runpath}$2$3"])
110dnl
111dnl AC_DEFUN(NCBI_RPATHIFY_COND,
112dnl [: ${$1="-L$2 ${CONF_f_runpath}$2$3"}])
113
114AC_DEFUN(NCBI_RPATHIFY,
115[ncbi_rp_L_flags=
116 ncbi_rp_L_sep=$CONF_f_libpath
117 if test "x${CONF_f_runpath}" = "x${CONF_f_libpath}"; then
118    for x in $2; do
119       case "$x" in
120          /lib | /usr/lib | /usr/lib32 | /usr/lib64 | /usr/lib/$multiarch )
121             continue
122             ;;
123       esac
124       ncbi_rp_L_flags="${ncbi_rp_L_flags}${ncbi_rp_L_sep}$x"
125       ncbi_rp_L_sep=" $CONF_f_libpath"
126    done
127    $1="${ncbi_rp_L_flags}$3"
128 else
129    ncbi_rp_R_flags=
130    ncbi_rp_R_sep=" $CONF_f_runpath"
131    for x in $2; do
132       case "$x" in
133          /lib | /usr/lib | /usr/lib32 | /usr/lib64 | /usr/lib/$multiarch )
134             continue
135             ;;
136       esac
137       ncbi_rp_L_flags="${ncbi_rp_L_flags}${ncbi_rp_L_sep}$x"
138       ncbi_rp_L_sep=" $CONF_f_libpath"
139       x=`echo $x | sed -e "$ncbi_rpath_sed"`
140       ncbi_rp_R_flags="${ncbi_rp_R_flags}${ncbi_rp_R_sep}$x"
141       ncbi_rp_R_sep=:
142    done
143    $1="${ncbi_rp_L_flags}${ncbi_rp_R_flags}$3"
144 fi])
145
146AC_DEFUN(NCBI_RPATHIFY_COND,
147[if test -z "${$1+set}"; then
148    NCBI_RPATHIFY(m4_translit($1, :), [$2], [$3])
149 fi])
150
151# Arguments:
152# 1. variable name
153# 2. command
154# 3. extra sed code (optional)
155dnl
156dnl AC_DEFUN(NCBI_RPATHIFY_OUTPUT,
157dnl [$1=`$2 | sed -e "$3s/-L\\([[^ ]]*\\)/-L\\1 ${CONF_f_runpath}\\1/"`])
158dnl
159dnl AC_DEFUN(NCBI_RPATHIFY_OUTPUT_COND,
160dnl [: ${$1=`$2 | sed -e "$3s/-L\\([[^ ]]*\\)/-L\\1 ${CONF_f_runpath}\\1/"`}])
161
162AC_DEFUN(NCBI_RPATHIFY_OUTPUT,
163[if test "x${CONF_f_runpath}" = "x${CONF_f_libpath}"; then
164    $1=`$2 | sed -e "$3"`
165 else
166    $1=
167    ncbi_rp_L_sep=
168    ncbi_rp_R_flags=
169    ncbi_rp_R_sep=" $CONF_f_runpath"
170    for x in `$2 | sed -e "$3"`; do
171       case "$x" in
172          -L/lib | -L/usr/lib | -L/usr/lib32 | -L/usr/lib64 \
173          | -L/usr/lib/$multiarch )
174             continue
175             ;;
176          -L*)
177             $1="[$]$1${ncbi_rp_L_sep}$x"
178             x=`echo $x | sed -e "s/^-L//; $ncbi_rpath_sed"`
179             ncbi_rp_R_flags="${ncbi_rp_R_flags}${ncbi_rp_R_sep}$x"
180             ncbi_rp_R_sep=:
181             ;;
182          *)
183             $1="[$]$1${ncbi_rp_R_flags}${ncbi_rp_L_sep}$x"
184             ncbi_rp_R_flags=
185             ncbi_rp_R_sep=" $CONF_f_runpath"
186             ;;
187       esac
188       ncbi_rp_L_sep=" "
189    done
190    $1="[$]$1${ncbi_rp_R_flags}"
191 fi])
192
193AC_DEFUN(NCBI_RPATHIFY_OUTPUT_COND,
194[if test -z "${$1+set}"; then
195    NCBI_RPATHIFY_OUTPUT(m4_translit($1, :), [$2], [$3])
196 fi])
197
198# Arguments:
199# 1. (3.) Properly-cased library name
200# 2. (4.) Test code.
201# 3. (5.) Extra libraries to put in $2_LIBS.
202# 4. (6.) Extra libraries to require users to put in LIBS.
203# 5. (7.) Extra include paths that should go into $2_INCLUDE.
204
205AC_DEFUN(NCBI_CHECK_THIRD_PARTY_LIB,
206[NCBI_CHECK_THIRD_PARTY_LIB_EX(m4_tolower($1), m4_toupper($1), $@)])
207
208AC_DEFUN(NCBI_CHECK_THIRD_PARTY_LIB_EX,
209[if test "$with_$1" != "no"; then
210    case "[$]$2_PATH:$with_$1" in
211       *:yes | *: | $with_$1* ) ;;
212       * ) $2_PATH=$with_$1 ;;
213    esac
214    if test "[$]$2_PATH" != /usr -a -d "[$]$2_PATH"; then
215       in_path=" in [$]$2_PATH"
216       if test -z "[$]$2_INCLUDE" -a -d "[$]$2_PATH/include"; then
217          $2_INCLUDE="-I[$]$2_PATH/include"
218       fi
219       if test -n "[$]$2_LIBPATH"; then
220          :
221       elif test -d "[$]$2_PATH/lib${bit64_sfx}"; then
222          NCBI_RPATHIFY($2_LIBPATH, [$]$2_PATH/lib${bit64_sfx}, [])
223       elif test -d "[$]$2_PATH/lib"; then
224          NCBI_RPATHIFY($2_LIBPATH, [$]$2_PATH/lib, [])
225       fi
226       $2_LIBS="[$]$2_LIBPATH -l$3 $5"
227    else
228       $2_INCLUDE=""
229       $2_LIBS="-l$3 $5"
230       in_path=
231    fi
232    AC_CACHE_CHECK([for lib$3$in_path], ncbi_cv_lib_$1,
233       CPPFLAGS="$7 [$]$2_INCLUDE $orig_CPPFLAGS"
234       LIBS="[$]$2_LIBS $6 $orig_LIBS"
235       [AC_LINK_IFELSE([$4], [ncbi_cv_lib_$1=yes], [ncbi_cv_lib_$1=no])])
236    if test "$ncbi_cv_lib_$1" = "no"; then
237       NCBI_MISSING_PACKAGE($1)
238    fi
239 fi
240 if test "$with_$1" = "no"; then
241    $2_PATH="No_$2"
242    $2_INCLUDE=
243    $2_LIBS=
244 else
245    NCBI_PACKAGE($2)
246    $2_INCLUDE="$7 [$]$2_INCLUDE"
247    AC_DEFINE([HAVE_LIB]patsubst($2, [^LIB], []), 1,
248              [Define to 1 if lib$3 is available.])
249 fi
250 AC_SUBST($2_INCLUDE)
251 AC_SUBST($2_LIBS)
252])
253
254AC_DEFUN(NCBI_MISSING_PACKAGE,
255   [if test "${[with_]m4_translit($1, [-], [_]):=no}" != no; then
256       AC_MSG_ERROR([--with-$1 explicitly specified, but no usable version found.])
257    fi])
258
259AC_DEFUN(NCBI_CHECK_PYTHON,
260[_NCBI_CHECK_PYTHON([PYTHON]patsubst($1, [\.], []), $@)])
261
262AC_DEFUN(_NCBI_CHECK_PYTHON,
263[AC_PATH_PROG($1, python$2, [],
264    [${PYTHON_PATH+$PYTHON_PATH/bin:}$PATH:/usr/local/python-$2/bin])
265 if test -x "[$]$1"; then
266    pyconf="$real_srcdir/scripts/common/impl/python-config.py"
267    $1_VERSION=`DYLD_BIND_AT_LAUNCH=1 "[$]$1" "$pyconf" --version 2>&AS_MESSAGE_LOG_FD`
268 else
269    $1_VERSION=
270    [ncbi_cv_lib_]m4_tolower($1)=no
271 fi
272 if test -n "[$]$1_VERSION"; then
273    $1_INCLUDE=`"[$]$1" "$pyconf" --include`
274    $1_LIBPATH=`"[$]$1" "$pyconf" --libpath`
275    NCBI_RPATHIFY($1_LIBS, [$]$1_LIBPATH, [ ]`"[$]$1" "$pyconf" --libs`)
276    CPPFLAGS="[$]$1_INCLUDE $orig_CPPFLAGS"
277    LIBS="[$]$1_LIBS $orig_LIBS"
278    AC_CACHE_CHECK([for usable Python [$]$1_VERSION libraries],
279       [ncbi_cv_lib_]m4_tolower($1),
280       [AC_LINK_IFELSE([AC_LANG_PROGRAM(
281           [[
282#ifdef HAVE_INTTYPES_H
283#include <inttypes.h>
284#endif
285#ifdef HAVE_STDINT_H
286#include <stdint.h>
287#endif
288#include <Python.h>]],
289           [[Py_Initialize(); Py_Finalize();]])],
290           [[ncbi_cv_lib_]m4_tolower($1)=yes],
291           [[ncbi_cv_lib_]m4_tolower($1)=no])])
292 else
293    $1=
294    [ncbi_cv_lib_]m4_tolower($1)=no
295 fi
296 if test "[$ncbi_cv_lib_]m4_tolower($1)" = "no"; then
297    $1_INCLUDE=
298    $1_LIBS=
299 else
300    NCBI_PACKAGE($1)
301    AC_DEFINE(HAVE_$1, 1, [Define to 1 if Python $2 libraries are available.])
302 fi
303 AC_SUBST($1_INCLUDE)
304 AC_SUBST($1_LIBS)
305])
306
307AC_DEFUN(NCBI_LOCAL_FTDS,
308[d="dbapi/driver/ftds$1/freetds"
309      if test $try_local = yes -a -f "${real_srcdir}/src/$d/Makefile.in" ; then
310         test "$ftds_ver" = $1  &&  FTDS_PATH="<$d>"
311         FTDS$1[_CTLIB_LIB]="ct_ftds$1${STATIC} tds_ftds$1${STATIC}"
312         FTDS$1[_CTLIB_LIBS]='$(ICONV_LIBS) $(KRB5_LIBS) $(NETWORK_LIBS)'
313         FTDS$1[_CTLIB_INCLUDE]="-I\$(includedir)/$d -I\$(includedir0)/$d"
314         freetds=freetds
315      elif test -d "$FTDS_PATH" ; then
316         FTDS$1[_CTLIB_LIB]=
317         FTDS$1[_CTLIB_LIBS]=$FTDS_CTLIBS
318         FTDS$1[_CTLIB_INCLUDE]=$FTDS_INCLUDE
319      fi
320      FTDS$1[_LIB]='$(FTDS$1[_CTLIB_LIB])'
321      FTDS$1[_LIBS]='$(FTDS$1[_CTLIB_LIBS])'
322      FTDS$1[_INCLUDE]='$(FTDS$1[_CTLIB_INCLUDE])'
323])
324
325AC_DEFUN(NCBI_CHECK_SUBTREE,
326[if test "$with_$1" = "no" ; then
327   NoConfProjects="$NoConfProjects $1"
328fi
329
330if test ! -f ${real_srcdir}/src/$1/Makefile.in  -o  \
331        ! -d ${real_srcdir}/include/$1 ; then
332   if test "${with_$1-no}" != "no" ; then
333      AC_MSG_ERROR([--with-]$1[:  ]m4_toupper($1)[ sources are missing])
334   fi
335   with_$1="no"
336fi
337])
338
339# AS_VAR_IF(VARIABLE, VALUE, IF-TRUE, IF-FALSE)
340# ---------------------------------------------
341# Implement a shell `if test $VARIABLE = VALUE; then-else'.
342# Polymorphic, and avoids sh expansion error upon interrupt or term signal.
343# (Taken from Autoconf 2.64, for the sake of ax_check_gnu_make.m4.)
344m4_define([AS_VAR_IF],
345[AS_LITERAL_IF([$1],
346  [AS_IF([test "x$$1" = x""$2], [$3], [$4])],
347  [AS_VAR_COPY([as_val], [$1])
348   AS_IF([test "x$as_val" = x""$2], [$3], [$4])])])
349
350m4_include([m4/ax_check_gnu_make.m4])
351m4_include([m4/ax_jni_include_dir.m4])
352m4_include([m4/ax_prog_cc_for_build.m4])
353