3 dnl this was once done by Katsumi Yamaoka <yamaoka@jpl.org>, but
4 dnl pretty much no original code remains.
6 dnl EMACS_LISP takes 5 arguments. $1 is the name of the shell
7 dnl variable to assign a value, $2 is a Lisp expression placed into
8 dnl shell double quotes (which has consequences for quoting and
9 dnl variable expansion). $3 is a list of Emacs options evaluated before
10 dnl the expression itself, $4 is a list of Elisp variables that is
11 dnl assigned from the command line arguments from $5.
13 AC_DEFUN(EMACS_LISP, [
16 echo "${EMACS}" -batch $3 -eval "(let* (patsubst([$4], [\w+], [(\&(pop command-line-args-left))])(x ${elisp})) (write-region (if (stringp x) x (prin1-to-string x)) nil \"${OUTPUT}\"))" $5 >& AC_FD_CC 2>&1
17 "${EMACS}" -batch $3 -eval "(let* (patsubst([$4], [\w+], [(\&(pop command-line-args-left))])(x ${elisp})) (write-region (if (stringp x) x (prin1-to-string x)) nil \"${OUTPUT}\"))" $5 >& AC_FD_CC 2>&1
19 echo "=> [$]{$1}" >& AC_FD_CC 2>&1
23 # This generates a prefix variables $1 from the executable in $2.
24 # The executable is searched in PATH, and a potential bin/ or
25 # bin/architecture/ component is stripped from it.
26 AC_DEFUN(EMACS_PATH_PREFIX,[
27 EMACS_LISP([$1],[[(condition-case nil (let*
28 ((prefix (directory-file-name (file-name-directory (executable-find cmd))))
29 (parent (directory-file-name (file-name-directory prefix))))
30 (if (string= (file-name-nondirectory prefix) \"bin\")
32 (if (string= (file-name-nondirectory parent) \"bin\")
33 (setq prefix (directory-file-name (file-name-directory parent)))))
34 prefix) (error "NONE"))]],[[-no-site-file]],[[cmd]],[$2])])
36 AC_DEFUN(EMACS_PROG_EMACS, [
37 # Check for (X)Emacs, report its path, flavor and prefix
39 # Apparently, if you run a shell window in Emacs, it sets the EMACS
40 # environment variable to 't'. Let's undo the damage.
41 if test "${EMACS}" = "t"; then
45 [ --with-emacs@<:@=PATH@:>@ Use Emacs to build (on PATH if given)],
46 [if test "${withval}" = "yes"; then EMACS=emacs
47 elif test "${withval}" = "no"; then EMACS=xemacs
48 else EMACS="${withval}"; fi])
51 [ --with-xemacs@<:@=PATH@:>@ Use XEmacs to build (on PATH if given)],
52 [if test "x${withval}" != xno
54 if test "x${with_emacs}" != xno -a "x${with_emacs}" != x
56 AC_MSG_ERROR([[cannot use both Emacs and XEmacs]])
58 if test "x${withval}" = "xyes"
64 elif test "x${with_emacs}" = xno
66 AC_MSG_ERROR([[need to use either Emacs or XEmacs]])
69 # "${prefix}/bin" is for Windows users
70 AC_PATH_PROGS(EMACS, ${EMACS} emacs xemacs, "", ${PATH} "${prefix}/bin" )
71 if test -z "${EMACS}"; then
72 AC_MSG_ERROR([(X)Emacs not found! Aborting!])
75 AC_MSG_CHECKING([if ${EMACS} is XEmacs])
77 [[(if (featurep (quote xemacs)) \"yes\" \"no\")]],[[-no-site-file]])
78 if test "${XEMACS}" = "yes"; then
81 elif test "${XEMACS}" = "no"; then
85 AC_MSG_ERROR([Unable to run ${EMACS}! Aborting!])
87 AC_MSG_RESULT(${XEMACS})
89 AC_SUBST(EMACS_FLAVOR)
90 AC_MSG_CHECKING([for ${EMACS_NAME} prefix])
91 EMACS_PATH_PREFIX([[emacsprefix]],[["${EMACS}"]])
92 AC_MSG_RESULT([["${emacsprefix}"]])
95 AC_DEFUN(AC_DATE_VERSION_FROM_CHANGELOG, [
96 AC_MSG_CHECKING([for date in ChangeLog])
97 $1=[`sed -n '1s/^\([-0-9][-0-9]*\).*/\1/p' ChangeLog`]
100 AC_MSG_ERROR([[not found]])
103 AC_MSG_CHECKING([for release in ChangeLog])
104 $2=[`sed -n '2,/^[0-9]/s/.*Version \(.*\) released\..*/\1/p' ChangeLog`]
108 AC_MSG_RESULT([not found, using ${$2} instead])
110 AC_MSG_RESULT([${$2}])
114 AC_DEFUN(EMACS_CHECK_VERSION, [
115 AC_MSG_CHECKING([if ${EMACS_NAME} is recent enough])
116 EMACS_LISP(result,[(cond ((< emacs-major-version $1) \"no\")
117 ((> emacs-major-version $1) \"yes\")
118 ((< emacs-minor-version 0$2) \"no\")
119 (t \"yes\"))],[[-no-site-file]])
120 AC_MSG_RESULT([${result}])
121 if test "${result}" != "yes"
123 AC_MSG_ERROR([This package requires at least ${EMACS_NAME} version $1.$2 Aborting!])
127 dnl Look for an installation directory under given prefixes.
128 dnl $1 is the variable name we are looking for.
129 dnl $2 is a list of prefixes to try as a list of shell words
130 dnl $3 is a Lisp expression giving a list of directory names
131 dnl those should be be either nil or a relative path like "tex/latex".
132 dnl Those names are tried in turn, and every one of them is matched
133 dnl against the tail of each location in $4. nil matches everything,
134 dnl it is a wildcard.
135 dnl $4 is Lisp expression giving a list of locations where to find names.
136 dnl A location is only considered if it is nonnil, an existing
137 dnl absolute directory,
138 dnl and is a subdirectory of one of the given prefixes.
139 dnl $5,$6,$7 are additional arguments for the elisp call
140 AC_DEFUN(EMACS_EXAMINE_INSTALLATION_DIR,
141 [ for currentprefix in $2
143 expprefix="${currentprefix}"
144 AC_FULL_EXPAND(expprefix)
147 (let (reldir (dirs $4))
148 (dolist (name $3 \"NONE\")
151 (setq dir (directory-file-name dir))
152 (file-name-absolute-p dir)
153 (file-directory-p dir)
154 (not (string-match \"\\\\\`\\\\.\\\\.\"
155 (setq reldir (file-relative-name dir expanded))))
156 (not (file-name-absolute-p reldir))
157 (let ((name name) (dir dir))
159 (string= (file-name-nondirectory dir)
160 (file-name-nondirectory name))
161 (setq dir (file-name-directory dir)
162 name (file-name-directory name))
164 (setq dir (directory-file-name dir)
165 name (directory-file-name name)))))
168 (if (string= reldir \".\") (directory-file-name prefix)
169 (concat (file-name-as-directory prefix)
170 reldir)))))))))],[$5],
171 [prefix expanded $6],["${currentprefix}" "${expprefix}" $7])
172 if test "[$]$1" != NONE; then break; fi; done])
174 AC_DEFUN(EMACS_PATH_PACKAGEDIR,
175 [AC_ARG_WITH(packagedir,
176 [ --with-packagedir=DIR package DIR for XEmacs],
177 [packagedir="`echo ${withval} | sed 's/^~\//${HOME}\//;s/[[\/\\]]$//'`"],
178 [if test ${EMACS_FLAVOR} = xemacs; then
179 AC_MSG_CHECKING([for XEmacs package directory])
180 EMACS_EXAMINE_INSTALLATION_DIR(packagedir,
181 [['${datadir}/xemacs/xemacs-packages' \
182 '${libdir}/xemacs/xemacs-packages' \
183 '${datadir}' '${libdir}' "${emacsprefix}"]],
184 [[(list \"xemacs/site-packages\" \"xemacs/xemacs-packages\"
185 \"site-packages\" \"xemacs-packages\")]],
186 [[(if (boundp 'late-packages)
187 (append late-packages last-packages early-packages)
188 (append late-package-hierarchies last-package-hierarchies
189 early-package-hierarchies))]])
190 if test "x${packagedir}" = xNONE -o -z "${packagedir}"; then
191 AC_MSG_ERROR([not found, exiting!])
193 AC_MSG_RESULT(${packagedir})
197 AC_SUBST(packagedir)])
199 AC_DEFUN(EMACS_PATH_LISPDIR, [
200 AC_MSG_CHECKING([where lisp files go])
202 [ --with-lispdir=DIR A place in load-path for Lisp files; most
203 files will be place in a subdirectory.],
204 [[lispdir="${withval}"]])
205 if test "X${lispdir}" = X; then
206 if test "X${packagedir}" = Xno; then
207 # Test paths relative to prefixes
208 EMACS_EXAMINE_INSTALLATION_DIR(lispdir,
209 [['${datadir}/'${EMACS_FLAVOR} '${libdir}/'${EMACS_FLAVOR} \
210 "${emacsprefix}/share/${EMACS_FLAVOR}" \
211 '${datadir}' '${libdir}' "${emacsprefix}"]],
212 [[(list \"${EMACS_FLAVOR}/site-lisp\" \"${EMACS_FLAVOR}/site-packages\"
213 \"site-lisp\" \"site-packages\")]], load-path)
214 if test "${lispdir}" = "NONE"; then
216 AC_MSG_ERROR([Cannot locate lisp directory,
217 use --with-lispdir, --datadir, or possibly --prefix to rectify this])
221 lispdir="${packagedir}/lisp"
224 AC_MSG_RESULT([[${lispdir}]])
229 AC_DEFUN(TEX_PATH_TEXMFDIR,
231 AC_ARG_WITH(texmf-dir,
232 [ --with-texmf-dir=DIR TEXMF tree to install into,
233 or --without-texmf-dir for runtime config],
234 [ texmfdir="${withval}" ;
235 if test "x${texmfdir}" = xno
237 previewtexmfdir="${packagedatadir}/latex"
238 previewdocdir="${packagedatadir}/doc"
240 AC_FULL_EXPAND(withval)
241 if test ! -d "${withval}" ; then
242 AC_MSG_ERROR([--with-texmf-dir="${texmfdir}": Directory does not exist])
244 previewtexmfdir="${texmfdir}/tex/latex/preview"
245 previewdocdir="${texmfdir}/doc/latex/styles"
250 [ --with-tex-dir=DIR Location to install preview TeX sources],
251 [ previewtexmfdir="${withval}" ;
252 AC_FULL_EXPAND(withval)
253 if test ! -d "${withval}" ; then
254 AC_MSG_ERROR([--with-tex-dir="${previewtexmfdir}": Directory does not exist])
259 [ --with-doc-dir=DIR Location to install preview.dvi],
260 [ previewdocdir="${withval}" ;
261 AC_FULL_EXPAND(withval)
262 if test ! -d "${withval}" ; then
263 AC_MSG_ERROR([--with-doc-dir="${previewdocdir}": Directory does not exist])
267 # First check for docstrip.cfg information -- removed. Too high
268 # likelihood to pick up a user preference instead of a system setting.
271 # kpsepath -n latex tex
272 # and then go for the following in its output:
273 # a) first path component in datadir/prefix ending in tex/latex// (strip trailing
274 # // and leading !!): "Searching for TDS-compliant directory." Install
275 # in preview subdirectory.
276 # b) first absolute path component ending in // "Searching for directory
277 # hierarchy" Install in preview subdirectory.
278 # c) anything absolute. Install both files directly there.
280 if test "x${texmfdir}" != xno ; then
281 if test "x${previewtexmfdir}" = x ; then
283 AC_MSG_CHECKING([for prefix from kpsepath])
285 EMACS_PATH_PREFIX(texprefix,kpsepath)
287 if test "x${texprefix}" != "xNONE"
290 AC_MSG_RESULT([["${texprefix}"]])
292 AC_MSG_CHECKING([for TDS-compliant directory])
294 pathoutput="`kpsepath -n latex tex`"
296 EMACS_EXAMINE_INSTALLATION_DIR(texmfdir,
297 [['${datadir}/texmf' "${texprefix}/share/texmf-local" "${texprefix}/share/texmf" "${texprefix}/texmf-local" "${texprefix}/texmf"]],
300 (and (string-match \"\\\\\`!*\\\\(.*\\\\)/tex/latex//+\\\\'\" x)
302 (append (split-string pathoutput \";\")
303 (split-string pathoutput \":\")))]],
305 [[pathoutput]],[["${pathoutput}"]])
307 if test -n "${texmfdir}" -a "${texmfdir}" != "NONE" ; then
308 previewdocdir="${texmfdir}/doc/latex/styles"
309 previewtexmfdir="${texmfdir}/tex/latex/preview"
312 if test -z "${previewtexmfdir}" -o "${previewtexmfdir}" = no ; then
315 AC_MSG_CHECKING([for TeX directory hierarchy])
317 EMACS_EXAMINE_INSTALLATION_DIR(texmfdir,
318 [['${datadir}/texmf' "${texprefix}/share/texmf-local" "${texprefix}/share/texmf" "${texprefix}/texmf-local" "${texprefix}/texmf" '${datadir}' "${texprefix}/share" "${texprefix}"]],
321 (and (string-match \"\\\\\`!*\\\\(.*[^/]\\\\)//+\\\\'\" x)
323 (append (split-string pathoutput \";\")
324 (split-string pathoutput \":\")))]],
326 [[pathoutput]],[["${pathoutput}"]])
328 if test -n "${texmfdir}" -a "${texmfdir}" != "NONE" ; then
329 previewtexmfdir="${texmfdir}/preview"
330 previewdocdir="${texmfdir}/preview"
334 if test -z "${previewtexmfdir}" -o "${previewtexmfdir}" = no ; then
337 AC_MSG_CHECKING([for TeX input directory])
339 EMACS_EXAMINE_INSTALLATION_DIR(texmfdir,
340 [['${datadir}' "${texprefix}/share" "${texprefix}"]],
343 (and (string-match \"\\\\\`!*\\\\(.*[^/]\\\\)/?\\\\'\" x)
345 (append (split-string pathoutput \";\")
346 (split-string pathoutput \":\")))]],
348 [[pathoutput]],[["${pathoutput}"]])
350 if test -n "${texmfdir}" -a "${texmfdir}" != "NONE" ; then
351 previewtexmfdir="${texmfdir}"
352 previewdocdir="${texmfdir}"
357 if test -z "${previewtexmfdir}" -o "${previewtexmfdir}" = no ; then
360 AC_MSG_ERROR([Cannot find the texmf directory!
361 Please use --with-texmf-dir=dir to specify where the preview tex files go])
364 AC_MSG_RESULT(${texmfdir})
368 echo Preview will be placed in ${previewtexmfdir}
369 echo Preview docs will be placed in ${previewdocdir}
371 AC_SUBST(previewtexmfdir)
372 AC_SUBST(previewdocdir)])
374 AC_DEFUN(AC_FULL_EXPAND,
375 [ __ac_tmp_oldprefix__="${prefix}"
376 __ac_tmp_oldexec_prefix__="$exec_prefix"
377 test "x${prefix}" = xNONE && prefix="${ac_default_prefix}"
378 test "x${exec_prefix}" = xNONE && exec_prefix='${prefix}'
379 while :;do case "[$]$1" in *\[$]*) __ac_tmp__='s/[[\`"-"]]/\\&/g'
380 eval "$1=`sed ${__ac_tmp__} <<EOF
383 `";; *) break ;; esac; done
384 prefix="${__ac_tmp_oldprefix__}"
385 exec_prefix="${__ac_tmp_oldexec_prefix__}" ])
387 AC_DEFUN(AC_CHECK_PROG_REQUIRED, [
388 AC_CHECK_PROG($1, $2, NONE)
389 if test "${$1}"x = NONEx ; then
394 AC_DEFUN(AC_CHECK_PROGS_REQUIRED, [
395 AC_CHECK_PROGS($1, $2, NONE)
396 if test "${$1}"x = NONEx ; then
402 AC_DEFUN(AC_PATH_PROG_REQUIRED, [
403 AC_PATH_PROG($1, $2, NONE)
404 if test "${$1}"x = NONEx ; then
409 AC_DEFUN(AC_PATH_PROGS_REQUIRED, [
410 AC_PATH_PROGS($1, $2, NONE)
411 if test "${$1}"x = NONEx ; then
418 dnl Check whether a function exists in a library
419 dnl All '_' characters in the first argument are converted to '-'
421 AC_DEFUN(EMACS_CHECK_LIB, [
422 if test -z "$3"; then
423 AC_MSG_CHECKING(for $2 in $1)
425 library=`echo $1 | tr _ -`
426 EMACS_LISP(EMACS_cv_SYS_$1,(progn (fmakunbound '$2) (condition-case nil (progn (require '${library}) (fboundp '$2)) (error (prog1 nil (message \"${library} not found\"))))))
427 if test "${EMACS_cv_SYS_$1}" = "nil"; then
430 if test "${EMACS_cv_SYS_$1}" = "t"; then
433 HAVE_$1=${EMACS_cv_SYS_$1}
435 if test -z "$3"; then
436 AC_MSG_RESULT(${HAVE_$1})
441 dnl Check whether a library is require'able
442 dnl All '_' characters in the first argument are converted to '-'
444 AC_DEFUN(EMACS_CHECK_REQUIRE, [
445 if test -z "$2"; then
446 AC_MSG_CHECKING(for $1)
448 library=`echo $1 | tr _ -`
450 [(condition-case nil (require '${library} ) \
451 (error (prog1 nil (message \"${library} not found\"))))])
452 if test "$$1" = "nil"; then
455 if test "$$1" = "${library}"; then
460 if test -z "$2"; then
461 AC_MSG_RESULT(${HAVE_$1})
466 dnl Perform sanity checking and try to locate the auctex package
468 AC_DEFUN(EMACS_CHECK_AUCTEX, [
469 AC_MSG_CHECKING(for the location of AUCTeX's tex-site.el)
470 AC_ARG_WITH(tex-site,[ --with-tex-site=DIR Location of AUCTeX's tex-site.el, if not standard],
471 [ auctexdir="${withval}" ;
472 AC_FULL_EXPAND(withval)
473 if test ! -d "${withval}" ; then
474 AC_MSG_ERROR([--with-tex-site=${auctexdir}: Directory does not exist])
477 if test -z "${auctexdir}" ; then
478 AC_CACHE_VAL(EMACS_cv_ACCEPTABLE_AUCTEX,[
479 EMACS_LISP(EMACS_cv_ACCEPTABLE_AUCTEX,
480 [[(condition-case nil
481 (directory-file-name (file-name-directory
482 (locate-library \"tex-site\")))
484 if test -z "${EMACS_cv_ACCEPTABLE_AUCTEX}" ; then
485 AC_MSG_ERROR([Can't find AUCTeX! Please install it!
486 Check the PROBLEMS file for details.])
489 auctexdir="${EMACS_cv_ACCEPTABLE_AUCTEX}"
491 AC_MSG_RESULT(${auctexdir})
496 dnl Check if (X)Emacs supports international characters,
497 dnl i.e. provides MULE libraries and runs in multibyte mode.
499 AC_DEFUN(EMACS_CHECK_MULE, [
500 AC_MSG_CHECKING(for MULE support)
501 EMACS_CHECK_REQUIRE(mule,silent)
502 if test "${HAVE_mule}" = "yes" && test "X${EMACS_UNIBYTE}" = X; then
508 if test "X${EMACS_UNIBYTE}" != X; then
509 AC_MSG_WARN([[EMACS_UNIBYTE environment variable set.
510 Disabling features requiring international character support.]])
518 dnl MAKEINFO_CHECK_MACRO( MACRO, [ACTION-IF-FOUND
519 dnl [, ACTION-IF-NOT-FOUND]])
521 AC_DEFUN(MAKEINFO_CHECK_MACRO,
522 [if test -n "${MAKEINFO}" -a "${makeinfo}" != ":"; then
523 AC_MSG_CHECKING([if ${MAKEINFO} understands @$1{}])
524 echo \\\\input texinfo > conftest.texi
525 echo @$1{test} >> conftest.texi
526 if ${MAKEINFO} conftest.texi > /dev/null 2> /dev/null; then
528 ifelse([$2], , :, [$2])
531 ifelse([$3], , :, [$3])
533 rm -f conftest.texi conftest.info
538 dnl MAKEINFO_CHECK_MACROS( MACRO ... [, ACTION-IF-FOUND
539 dnl [, ACTION-IF-NOT-FOUND]])
541 AC_DEFUN(MAKEINFO_CHECK_MACROS,
542 [for ac_macro in $1; do
543 MAKEINFO_CHECK_MACRO(${ac_macro}, $2,
544 [MAKEINFO_MACROS="-D no-${ac_macro} ${MAKEINFO_MACROS}"
547 AC_SUBST(MAKEINFO_MACROS)
550 AC_DEFUN(AC_SHELL_QUOTIFY,
551 [$1=["`sed 's/[^-0-9a-zA-Z_./:$]/\\\\&/g;s/[$]\\\\[{(]\\([^)}]*\\)\\\\[})]/${\\1}/g' <<EOF]
557 dnl Check if build directory is valid.
558 dnl The directory should not be part of `load-path'
560 AC_DEFUN(VALID_BUILD_DIR, [
561 AC_MSG_CHECKING([if build directory is valid])
562 EMACS_LISP(valid_build_dir,
563 [[(if (or (member (directory-file-name default-directory) load-path)\
564 (member (file-name-as-directory default-directory) load-path))\
566 if test "${valid_build_dir}" = "no"; then
567 AC_MSG_ERROR([Build directory inside load-path! Aborting!])
575 # Set the directory containing AUCTeX automatically generated global style
577 AC_DEFUN(AUCTEX_AUTO_DIR,
578 [AC_MSG_CHECKING([where automatically generated global style hooks go])
579 AC_ARG_WITH(auto-dir,
580 [ --with-auto-dir=DIR directory containing AUCTeX automatically generated
582 [autodir="${withval}"],
583 [autodir='${localstatedir}/auctex'])
584 AC_MSG_RESULT([${autodir}])
589 # First argument is a variable name where a lisp expression is to be
590 # substituted with AC_SUBST and "lisp" prepended.
591 # lispdir is used for two purposes: any relative names are resolved
592 # relative to lispdir, and the lispification uses relative file names
593 # in relation to the second argument if the target dir is in the
595 # Second argument is a path to be resolved relatively to the filename
596 # in the third argument.
597 # If a third argument is given, it specifies a path specification
598 # to be expanded relative to the resulting directory.
599 AC_DEFUN(AC_LISPIFY_DIR,[
601 AC_FULL_EXPAND(tmpdir)
602 explispdir="[$]{lispdir}"
603 AC_FULL_EXPAND(explispdir)
605 AC_FULL_EXPAND(expstartup)
606 EMACS_LISP([lisp$1],[[(progn (setq path (directory-file-name path))
608 (not (string= (car load-path) (directory-file-name (car load-path)))))
609 (setq path (file-name-as-directory path)))
610 (setq path (expand-file-name path lispdir))
611 (setq startupdir (file-name-directory (expand-file-name startup lispdir)))
613 (if (or (string-match \"\\\\\`\\\\.\\\\.\"
614 (setq relname (file-relative-name startupdir lispdir)))
615 (file-name-absolute-p relname)
616 (string-match \"\\\\\`\\\\.\\\\.\"
617 (setq relname (file-relative-name path lispdir)))
618 (file-name-absolute-p relname))
622 ,(file-relative-name (concat path target) startupdir)
623 (file-name-directory load-file-name)))
624 ((string= path startupdir)
625 '(file-name-directory load-file-name))
626 ((string= path (directory-file-name startupdir))
627 '(directory-file-name (file-name-directory load-file-name)))
630 ,(file-relative-name path startupdir)
631 (file-name-directory load-file-name)))))))]],
632 -no-site-file,[[path lispdir startup target]],
633 [["${tmpdir}" "${explispdir}" "${expstartup}" $3]])