Debian Codegraph @

m4/kpse-common.m4

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