preparation for the tag 0.80
[luatex.git] / source / m4 / kpse-common.m4
blob9c98f349e8cbdc6f3fac16d8bc5ee67974cee1bb
1 # Public macros for the TeX Live (TL) tree.
2 # Copyright (C) 1995-2009 Karl Berry <tex-live@tug.org>
3 # Copyright (C) 2009-2015 Peter Breitenlohner <tex-live@tug.org>
5 # This file is free software; the copyright holders
6 # give unlimited permission to copy and/or distribute it,
7 # with or without modifications, as long as this notice is preserved.
9 # KPSE_LIBS_PREPARE
10 # -----------------
11 # Enforce inclusion of this file.
12 AC_DEFUN([KPSE_LIBS_PREPARE], [])
14 # _KPSE_INIT()
15 # ------------
16 # Initialize infrastructure for libraries and programs in the TL tree.
17 # If in the TL tree, define kpse_TL as relative path to the TL root.
18 AC_DEFUN([_KPSE_INIT],
19 [## $0: Initialize TL infrastructure
20 m4_syscmd([test -f ../../texk/kpathsea/doc/kpathsea.texi])[]dnl
21 m4_if(m4_sysval, [0], [m4_define([kpse_TL], [../../])])[]dnl
22 m4_ifdef([kpse_TL],
23 [kpse_BLD=`(cd "./kpse_TL()." && pwd)`
24 kpse_SRC=`(cd "$srcdir/kpse_TL()." && pwd)`
25 ])[]dnl
26 ]) # _KPSE_INIT
28 # KPSE_INIT()
29 # -----------
30 # Initialize, if not automatically done so via KPSE_*_FLAGS
31 AC_DEFUN([KPSE_INIT],
32 [AC_REQUIRE([_KPSE_INIT])])
34 # _KPSE_USE_LIBTOOL()
35 # -------------------
36 AC_DEFUN([_KPSE_USE_LIBTOOL],
37 [## $0: Generate a libtool script for use in configure tests
38 AC_PROVIDE_IFELSE([LT_INIT], ,
39                   [m4_fatal([$0: requires libtool])])[]dnl
40 LT_OUTPUT
41 m4_append([AC_LANG(C)],
42 [ac_link="./libtool --mode=link --tag=CC $ac_link"
43 ])[]dnl
44 AC_PROVIDE_IFELSE([AC_PROG_CXX],
45 [m4_append([AC_LANG(C++)],
46 [ac_link="./libtool --mode=link --tag=CXX $ac_link"
47 ])])[]dnl
48 AC_LANG(_AC_LANG)[]dnl
49 ]) # _KPSE_USE_LIBTOOL
51 # _KPSE_LIB_FLAGS(LIBDIR, LIBNAME, OPTIONS,
52 #                 TL-INCLUDES, TL-LIBS, TL-EXTRA,
53 #                 [REBUILD-SRC-DEPENDENCIES],
54 #                 [REBUILD-BLD-DEPENDENCIES])
55 # -----------------------------------------------
56 # For generic libraries in libs/LIBDIR.
57 # Provide the configure options '--with-system-LIBDIR' (if in the TL tree)
58 # and, if applicable '--with-LIBDIR-includes' and '--with-LIBDIR-libdir'.
59 # Options:
60 #          lt - this is a Libtool library
61 #          tree - only use library from the TL tree
63 # Set the make variables LIBDIR_INCLUDES and LIBDIR_LIBS to the CPPFLAGS and
64 # LIBS required for the library in the directory libs/LIBDIR/ of the TL tree.
65 # The resulting values may be used by configure tests; thus they must not
66 # use, e.g., ${srcdir} or ${top_builddir}.
68 # If an installed (system) version of the library has been selected or is
69 # implied, then execute KPSE_LIBDIR_SYSTEM_FLAGS to set the two variables.
71 # Otherwise, set LIBDIR_INCLUDES based on the value of TL_INCLUDES and
72 # LIBDIR_LIBS based on the value of TL_LIBS; the optional shell code
73 # TL-EXTRA may modifiy these values.
74 # If OPTIONS specifies a Libtool library, then arrange that future configure
75 # test use Libtool. 
76 # Furthermore, set LIBDIR_DEPEND and LIBDIR_RULE to values suitable as
77 # dependency and (multiline) Make rule to rebuild the library (assuming that
78 # '${top_srcdir}/../../' and '${top_builddir}/../../' point to the root of
79 # the TL tree).
80 AC_DEFUN([_KPSE_LIB_FLAGS],
81 [AC_REQUIRE([_KPSE_INIT])[]dnl
82 ## $0: Setup $1 (-l$2) flags
83 m4_ifdef([kpse_TL],
84          [_KPSE_LIB_FLAGS_TL($@)],
85          [_KPSE_LIB_FLAGS_STANDALONE($@)])[]dnl
86 AC_SUBST(AS_TR_CPP($1)[_INCLUDES])[]dnl
87 AC_SUBST(AS_TR_CPP($1)[_LIBS])[]dnl
88 AC_SUBST(AS_TR_CPP($1)[_DEPEND])[]dnl
89 AC_SUBST(AS_TR_CPP($1)[_RULE])[]dnl
90 m4_provide_if([AM_INIT_AUTOMAKE], [_AM_SUBST_NOTMAKE(AS_TR_CPP($1)[_RULE])])[]dnl
91 ]) # _KPSE_LIB_FLAGS
93 # _KPSE_TEXLIB_FLAGS(LIBDIR, LIBNAME, OPTIONS,
94 #                    TL-INCLUDES, TL-LIBS, TL-EXTRA,
95 #                    [REBUILD-SRC-DEPENDENCIES],
96 #                    [REBUILD-BLD-DEPENDENCIES])
97 # -----------------------------------------------
98 # As above, but for TeX specific libraries in texk/LIBDIR.
99 AC_DEFUN([_KPSE_TEXLIB_FLAGS],
100 [m4_pushdef([Kpse_TeX_Lib], [])_KPSE_LIB_FLAGS($@)m4_popdef([Kpse_TeX_Lib])])
102 # _KPSE_LIB_FLAGS_TL(LIBDIR, LIBNAME, OPTIONS,
103 #                    TL-INCLUDES, TL-LIBS, TL-EXTRA,
104 #                    [REBUILD-SRC-DEPENDENCIES],
105 #                    [REBUILD-BLD-DEPENDENCIES])
106 # --------------------------------------------------
107 # Internal subroutine for use of _KPSE_LIB_FLAGS inside the TL tree.
108 m4_define([_KPSE_LIB_FLAGS_TL],
109 [m4_if(m4_index([ $3 ], [ lt ]), [-1], ,
110        [AC_REQUIRE([_KPSE_USE_LIBTOOL])])[]dnl m4_if
111 m4_if(m4_index([ $3 ], [ tree ]), [-1],
112 [KPSE_]AS_TR_CPP([$1])[_OPTIONS([with-system])[]dnl
113 if test "x$with_system_[]AS_TR_SH($1)" = xyes; then
114   ]AS_TR_CPP([kpse-$1-system-flags])[[]dnl
115 else
116 ])[]dnl m4_if
117   AS_TR_CPP($1)[_INCLUDES=]m4_bpatsubst(m4_bpatsubst(["$4"], [SRC], [$kpse_SRC]),
118                                                              [BLD], [$kpse_BLD])
119   AS_TR_CPP($1)[_LIBS=]m4_bpatsubst(["$5"], [BLD], [$kpse_BLD])m4_ifval([$6], [[
120   $6]])
121   AS_TR_CPP($1)[_DEPEND=]m4_ifdef([Kpse_TeX_Lib],
122                                   [m4_bpatsubst(['$5'], [BLD/texk],
123                                                 [${top_builddir}/..])m4_pushdef([Kpse_Lib_Bld],
124                                                                                 [..])],
125                                   [m4_bpatsubst(['$5'], [BLD],
126                                                 [${top_builddir}/../..])m4_pushdef([Kpse_Lib_Bld],
127                                                                                    [../../libs])])
128   AS_TR_CPP($1)[_RULE='# Rebuild lib$2
129 $(]AS_TR_CPP($1)[_DEPEND):]m4_ifval([$7],
130                                     [[ $7]])m4_ifval([$8], [[ $8
131         cd ${top_builddir}/]Kpse_Lib_Bld[/$1 && $(MAKE) $(AM_MAKEFLAGS) rebuild
132 $8:]])[
133         cd ${top_builddir}/]Kpse_Lib_Bld[/$1 && $(MAKE) $(AM_MAKEFLAGS) rebuild']m4_popdef([Kpse_Lib_Bld])
134 m4_if(m4_index([ $3 ], [ tree ]), [-1],
135       [fi
136 ])[]dnl m4_if
137 ]) # _KPSE_LIB_FLAGS_TL
139 # _KPSE_LIB_FLAGS_STANDALONE(LIBDIR, LIBNAME, OPTIONS)
140 # ----------------------------------------------------
141 # Internal subroutine for standalone use of _KPSE_LIB_FLAGS.
142 m4_define([_KPSE_LIB_FLAGS_STANDALONE],
143 [m4_if(m4_index([ $3 ], [ tree ]), [-1],
144 [KPSE_]AS_TR_CPP([$1])[_OPTIONS([])]dnl
145 [KPSE_]AS_TR_CPP([$1])[_SYSTEM_FLAGS],
146 [m4_fatal([$0: not in TL tree])])[]dnl m4_if
147 ]) # _KPSE_LIB_FLAGS_STANDALONE
149 # _KPSE_LIB_OPTIONS(LIBDIR, [WITH-SYSTEM], [CONFIG-PROG])
150 # -------------------------------------------------------
151 # Internal subroutine: default configure options for system library,
152 # including '--with-system-LIBDIR' if WITH-SYSTEM is nonempty.
153 m4_define([_KPSE_LIB_OPTIONS], [m4_ifval([$2], [dnl
154 AC_ARG_WITH([system-$1],
155             AS_HELP_STRING([--with-system-$1],
156                            [use installed $1 headers and library]m4_ifval([$3], [ (requires $3)])))[]dnl
157 m4_ifval([$3], [], [dnl
158 AC_ARG_WITH([$1-includes],
159             AS_HELP_STRING([--with-$1-includes=DIR],
160                            [$1 headers installed in DIR]))[]dnl
161 AC_ARG_WITH([$1-libdir],
162             AS_HELP_STRING([--with-$1-libdir=DIR],
163                            [$1 library installed in DIR]))[]dnl
164 ])])]) # _KPSE_LIB_OPTIONS
166 # _KPSE_LIB_FLAGS_SYSTEM(LIBDIR, LIBNAME)
167 # ---------------------------------------
168 # Internal subroutine: default flags for system library.
169 m4_define([_KPSE_LIB_FLAGS_SYSTEM],
170 [if test "x$with_[]AS_TR_SH($1)_includes" != x && test "x$with_[]AS_TR_SH($1)_includes" != xyes; then
171   AS_TR_CPP($1)_INCLUDES="-I$with_[]AS_TR_SH($1)_includes"
173 AS_TR_CPP($1)_LIBS="-l$2"
174 if test "x$with_[]AS_TR_SH($1)_libdir" != x && test "x$with_[]AS_TR_SH($1)_libdir" != xyes; then
175   AS_TR_CPP($1)_LIBS="-L$with_[]AS_TR_SH($1)_libdir $AS_TR_CPP($1)_LIBS"
177 ]) # _KPSE_LIB_FLAGS_SYSTEM
179 # KPSE_SAVE_FLAGS
180 # ---------------
181 # Save values of CPPFLAGS and LIBS.
182 AC_DEFUN([KPSE_SAVE_FLAGS],
183 [kpse_save_CPPFLAGS=$CPPFLAGS
184 kpse_save_LIBS=$LIBS
185 ]) # KPSE_SAVE_FLAGS
187 # KPSE_RESTORE_FLAGS
188 # ------------------
189 # Restore values of CPPFLAGS and LIBS.
190 AC_DEFUN([KPSE_RESTORE_FLAGS],
191 [AC_REQUIRE([KPSE_SAVE_FLAGS])[]dnl
192 CPPFLAGS=$kpse_save_CPPFLAGS
193 LIBS=$kpse_save_LIBS
194 ]) # KPSE_RESTORE_FLAGS
196 # KPSE_ADD_FLAGS(LIBDIR)
197 # ----------------------
198 # Add flags for LIBDIR to values of CPPFLAGS and LIBS.
199 AC_DEFUN([KPSE_ADD_FLAGS],
200 [AC_REQUIRE([KPSE_SAVE_FLAGS])[]dnl
201 eval CPPFLAGS=\"$[]AS_TR_CPP($1)_INCLUDES \$CPPFLAGS\"
202 eval LIBS=\"$[]AS_TR_CPP($1)_LIBS \$LIBS\"
203 ]) # KPSE_ADD_FLAGS
205 # KPSE_BASIC(PACKAGE-NAME, [MORE-AUTOMAKE-OPTIONS])
206 #--------------------------------------------------
207 # Common Autoconf code for all libraries and programs.
209 # Initialization of Automake, compiler warnings, etc.
210 AC_DEFUN([KPSE_BASIC], [dnl Remember PACKAGE-NAME as Kpse_Package (for future messages)
211 m4_define([Kpse_Package], [$1])
213 AM_INIT_AUTOMAKE([foreign silent-rules subdir-objects]m4_ifval([$2], [ $2]))
214 AM_MAINTAINER_MODE
216 dnl Check whether prototypes work.
217 AC_CACHE_CHECK([whether the compiler accepts prototypes],
218                [kb_cv_c_prototypes],
219                [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>]],
220                                                 [[extern void foo(int i,...);]])],
221                                [kb_cv_c_prototypes=yes],
222                                [kb_cv_c_prototypes=no])])
223 if test "x$kb_cv_c_prototypes" = xno; then
224   AC_MSG_ERROR([Sorry, your compiler does not understand prototypes.])
227 dnl Enable flags for compiler warnings
228 KPSE_COMPILER_WARNINGS
229 ]) # KPSE_BASIC
231 # KPSE_COMMON(PACKAGE-NAME, [MORE-AUTOMAKE-OPTIONS])
232 # --------------------------------------------------
233 # Common Autoconf code for all programs using libkpathsea.
234 # Originally written by Karl Berry as texk/kpathsea/common.ac.
236 AC_DEFUN([KPSE_COMMON], [dnl
237 KPSE_BASIC($@)
239 LT_PREREQ([2.2.6])
240 LT_INIT([win32-dll])
242 AC_SYS_LARGEFILE
243 AC_FUNC_FSEEKO
245 AC_HEADER_DIRENT
246 AC_HEADER_STDC
247 AC_FUNC_CLOSEDIR_VOID
248 AC_CHECK_HEADERS([assert.h float.h limits.h pwd.h stdlib.h sys/param.h])
250 dnl Replacement functions that may be required on ancient broken system.
251 AC_CHECK_FUNCS([putenv])
253 dnl More common functions
254 AC_CHECK_FUNCS([getcwd getwd memcmp memcpy mkstemp mktemp strchr strrchr])
256 AC_C_CONST
257 AC_C_INLINE
258 AC_TYPE_SIZE_T
259 AC_TYPE_INT64_T
260 AC_TYPE_UINT64_T
261 AS_CASE([:$ac_cv_c_int64_t:$ac_cv_c_int64_t:],
262         [*':no:'*], [AC_MSG_ERROR([Sorry, your compiler does not support 64-bit integer types.])])
264 dnl Check whether struct stat provides high-res time.
265 AC_CHECK_MEMBERS([struct stat.st_mtim])
266 ]) # KPSE_COMMON
268 # KPSE_MSG_WARN(PROBLEM)
269 # ----------------------
270 # Same as AC_MSG_WARN, but terminate if `--disable-missing' was given.
271 AC_DEFUN([KPSE_MSG_WARN],
272 [AC_REQUIRE([_KPSE_MSG_WARN_PREPARE])[]dnl
273 AC_MSG_WARN([$1])
274 AS_IF([test "x$enable_missing" = xno],
275       [AC_MSG_ERROR([terminating.])])
276 ]) # KPSE_MSG_WARN
278 # _KPSE_MSG_WARN_PREPARE
279 # ----------------------
280 # Internal subroutine.
281 AC_DEFUN([_KPSE_MSG_WARN_PREPARE],
282 [AC_ARG_ENABLE([missing],
283                AS_HELP_STRING([--disable-missing],
284                               [terminate if a requested program or feature must
285                                be disabled, e.g., due to missing libraries]))[]dnl
286 ]) # _KPSE_MSG_WARN_PREPARE
288 # _KPSE_CHECK_PKG_CONFIG
289 # ----------------------
290 # Check for pkg-config
291 AC_DEFUN([_KPSE_CHECK_PKG_CONFIG], [dnl
292 AC_REQUIRE([AC_CANONICAL_HOST])[]dnl
293 AC_CHECK_TOOL([PKG_CONFIG], [pkg-config], [false])[]dnl
294 ]) # _KPSE_CHECK_PKG_CONFIG
296 # _KPSE_PKG_CONFIG_FLAGS(PACKAGE-NAME, PKG_CONFIG_NAME, [AT_LEAST])
297 # -----------------------------------------------------------------
298 # Use pkg-config to determine INCLUDES and LIBS for a system library.
299 AC_DEFUN([_KPSE_PKG_CONFIG_FLAGS], [dnl
300 AC_REQUIRE([_KPSE_CHECK_PKG_CONFIG])[]dnl  
301 if $PKG_CONFIG $2[]m4_ifval([$3], [ --atleast-version=$3]); then
302   AS_TR_CPP($1)_INCLUDES=`$PKG_CONFIG $2 --cflags`
303   AS_TR_CPP($1)_LIBS=`$PKG_CONFIG $2 --libs`
304 elif test "x$need_[]AS_TR_SH($1):$with_system_[]AS_TR_SH($1)" = xyes:yes; then
305   AC_MSG_ERROR([did not find $2[]m4_ifval([$3], [ $3 or better])]) 
307 ]) # _KPSE_PKG_CONFIG_FLAGS
309 # KPSE_CANONICAL_HOST
310 # -------------------
311 # Require both --host and --build for cross compilations; set kpse_build_alias.
312 AC_DEFUN([KPSE_CANONICAL_HOST], [dnl
313 AC_REQUIRE([AC_CANONICAL_HOST])[]dnl
314 AS_IF([test "x$host_alias" != x && test "x$build_alias" = x],
315       [AC_MSG_ERROR([when cross-compiling you must specify both --host and --build.])])
316 eval kpse_build_alias=\${build_alias-$build}
317 ]) # KPSE_CANONICAL_HOST
319 # KPSE_NATIVE_SUBDIRS(DIR ...)
320 # ----------------------------
321 # Similar to AC_CONFIG_SUBDIRS for subdirectories configured for the build system.
322 # When cross compiling, the subdirectories need a different cache file.
323 AC_DEFUN([KPSE_NATIVE_SUBDIRS], [dnl
324 AC_REQUIRE([KPSE_CANONICAL_HOST])[]dnl
325 AC_CONFIG_SUBDIRS($@)
326 AC_CONFIG_COMMANDS_POST([dnl
327 AS_IF([test "x$cross_compiling" = xyes], [dnl
328 AS_IF([test "x$cache_file" != x/dev/null],
329       [cache_file=config.cache])
330 ac_configure_args="$ac_configure_args --host='$kpse_build_alias' \
331 CC='$BUILDCC' CFLAGS='$BUILDCFLAGS' \
332 CPPFLAGS='$BUILDCPPFLAGS' LDFLAGS='$BUILDLDFLAGS'"])])
333 ]) # KPSE_NATIVE_SUBDIRS