1 dnl aclocal.m4 -*-shell-script-*-
2 dnl StepMake subroutines for configure.ac
4 # This file is part of LilyPond, the GNU music typesetter.
6 # Copyright (C) 1998--2023 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 # Jan Nieuwenhuizen <janneke@gnu.org>
9 # LilyPond is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # LilyPond is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
23 ### mostly internal macros
25 # Get full path of executable ($1)
26 AC_DEFUN(STEPMAKE_GET_EXECUTABLE, [
27 ## which doesn't work in ash, if /usr/bin/which isn't installed
28 ## type -p doesn't work in ash
29 ## command -v doesn't work in zsh
30 ## command -v "$1" 2>&1
31 ## this test should work in ash, bash, pdksh (ksh), zsh
32 type -p $1 2>/dev/null | tail -n 1 | awk '{print $NF}'
36 # Get version string from executable ($1)
37 AC_DEFUN(STEPMAKE_GET_VERSION, [
38 ## "$1" --version 2>&1 | grep -v '^$' | head -n 1 | awk '{print $NF}'
41 ## Workaround for broken Debian gcc version string:
42 ## gcc (GCC) 3.1.1 20020606 (Debian prerelease)
44 ## -V: Workaround for python
46 changequote(<<, >>)#dnl
48 ## Assume and hunt for dotted version multiplet.
49 ## use eval trickery, because we cannot use multi-level $() instead of ``
50 ## for compatibility reasons.
52 ## grab the first version number in --version output.
53 eval _ver=\"\`("$1" --version || "$1" -V) 2>&1 |
54 grep -E '(^| )[0-9][0-9]*\.[0-9]' |
57 sed 's/\([0-9][0-9]*\.[0-9][0-9.]*\).*/\1/g' |
58 grep -E '(^| )[0-9][0-9]*\.[0-9]' |
61 if test -z "$_ver"; then
62 ## If empty, try date [fontforge]
63 eval _ver=\"\`("$1" --version || "$1" -V) 2>&1 \
64 | grep '\(^\|[^0-9a-f]\)[0-9]\{6,8\}\([^0-9a-f]\|$\)' \
66 | sed -e 's/^[^.0-9]*//' -e 's/[^.0-9]*$//'\`\"
72 # Calculate simplistic numeric version from version string ($1)
73 # As yet, we have no need for something more elaborate.
74 AC_DEFUN(STEPMAKE_NUMERIC_VERSION, [
82 # for version dates like '20230124', avoiding numeric overflow
88 {printf "%.0f\n", one*1000000 + two*1000 + three}'
92 # Add item ($2) to list ($1, one of 'OPTIONAL', 'REQUIRED')
93 AC_DEFUN(STEPMAKE_ADD_ENTRY, [
94 eval "$1"=\"`eval echo \"'$'$1\" \"$2\"`\"
97 # Check if tested program ($2) was found ($1).
98 # If not, add entry to missing-list ($3, one of 'OPTIONAL',
99 # 'REQUIRED') and assign "false" to ($1). "false" can be tested
100 # clearly in makefiles and will surely fail if run unintentionally.
101 AC_DEFUN(STEPMAKE_OPTIONAL_REQUIRED, [
102 STEPMAKE_CHECK_SEARCH_RESULT($1)
103 if test $? -ne 0; then
104 STEPMAKE_ADD_ENTRY($3, $2)
113 # Return if tested proram ($1) was found (true) or not (false).
114 AC_DEFUN(STEPMAKE_CHECK_SEARCH_RESULT, [
115 r="`eval echo '$'"$1"`"
117 && test "$r" != "error" \
118 && test "$r" != "no" \
119 && expr '`eval echo '$'"$1"`' : '.*\(echo\)' > /dev/null; then
126 # Check version of program ($1)
127 # If version is smaller than requested ($3) or larger than requested
128 # ($4, optional), add entry to missing-list ($2, one of 'OPTIONAL',
130 AC_DEFUN(STEPMAKE_CHECK_VERSION, [
131 r="`eval echo '$'"$1"`"
132 AC_MSG_CHECKING([$r version])
133 exe=`STEPMAKE_GET_EXECUTABLE($r)`
134 ver=`STEPMAKE_GET_VERSION($exe)`
135 num=`STEPMAKE_NUMERIC_VERSION($ver)`
136 min=`STEPMAKE_NUMERIC_VERSION($3)`
137 AC_MSG_RESULT([$ver])
138 if test "$num" -lt "$min"; then
139 STEPMAKE_ADD_ENTRY($2, ["$r >= $3 (installed: $ver)"])
141 if test -n "$4"; then
142 max=`STEPMAKE_NUMERIC_VERSION($4)`
143 if test "$num" -gt "$max"; then
144 STEPMAKE_ADD_ENTRY($2, ["$r <= $4 (installed: $ver)"])
147 vervar="`echo $1 | tr '[a-z]' '[A-Z]'`_VERSION"
148 eval `echo $vervar=$num`
149 ## AC_SUBST(`eval echo $vervar`)
153 ### Macros to build configure.ac
156 AC_DEFUN(STEPMAKE_BISON, [
157 STEPMAKE_PROGS(BISON, bison, $1)
159 # urg. should test functionality rather than version.
160 if test "$BISON" = "bison" && test -n "$2"; then
161 STEPMAKE_CHECK_VERSION(BISON, $1, $2)
166 AC_DEFUN(STEPMAKE_COMPILE_BEFORE, [
167 # -O is necessary to get inlining
169 CXXFLAGS=${CXXFLAGS-$CFLAGS}
170 LDFLAGS=${LDFLAGS-""}
176 AC_ARG_ENABLE(debugging,
178 [--enable-debugging],
179 [compile with debugging info. Default: on])],
180 [debug_b=$enableval])
182 AC_ARG_ENABLE(optimising,
184 [--enable-optimising],
185 [compile with optimising. Default: on])],
186 [optimise_b=$enableval])
188 AC_ARG_ENABLE(profiling,
190 [--enable-profiling],
191 [compile with gprof support. Default: off])],
192 [profile_b=$enableval])
197 [compile with -pipe. Default: on])],
200 if test "$optimise_b" = yes; then
201 OPTIMIZE=" -O2 -finline-functions"
204 if test $profile_b = yes; then
206 OPTIMIZE="$OPTIMIZE -pg"
209 if test $debug_b = yes; then
210 OPTIMIZE="$OPTIMIZE -g"
215 AC_DEFUN(STEPMAKE_COMPILE, [
216 AC_REQUIRE([STEPMAKE_COMPILE_BEFORE])
217 AC_REQUIRE([AC_PROG_CC])
218 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
220 STEPMAKE_OPTIONAL_REQUIRED(CC, cc, $1)
222 # If -pipe requested, test if it works and add to CFLAGS.
223 if test "$pipe_b" = yes; then
224 save_cflags="$CFLAGS"
225 CFLAGS=" -pipe $CFLAGS";
226 AC_CACHE_CHECK([whether compiler understands -pipe],
227 [stepmake_cv_cflags_pipe],
228 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[/* -pipe test */]])],
229 [stepmake_cv_cflags_pipe=yes],
230 [stepmake_cv_cflags_pipe=no]))
232 if test $stepmake_cv_cflags_pipe = yes; then
233 OPTIMIZE="$OPTIMIZE -pipe"
237 CFLAGS="$CFLAGS $OPTIMIZE"
238 CPPFLAGS=${CPPFLAGS-""}
240 AC_SUBST(cross_compiling)
249 AC_DEFUN(STEPMAKE_CXX, [
251 STEPMAKE_OPTIONAL_REQUIRED(CXX, c++, $1)
253 CXXFLAGS="$CXXFLAGS $OPTIMIZE"
260 AC_DEFUN(STEPMAKE_DATADIR, [
262 if test "$prefix" = "NONE"; then
263 presome=${ac_default_prefix}
266 build_package_datadir=$ac_pwd/out/share/$package
268 DATADIR=`echo ${datadir} | sed "s!\\\${datarootdir}!${presome}/share!"`
269 DATADIR=`echo ${DATADIR} | sed "s!\\\${prefix}!$presome!"`
270 BUILD_PACKAGE_DATADIR=`echo ${build_package_datadir} | sed "s!\\\${prefix}!$presome!"`
273 AC_SUBST(datarootdir)
274 AC_SUBST(build_package_datadir)
275 AC_DEFINE_UNQUOTED(CONFIG_DATADIR, ["${DATADIR}"])
276 AC_DEFINE_UNQUOTED(BUILD_PACKAGE_DATADIR, ["${BUILD_PACKAGE_DATADIR}"])
280 ## ugh: cut & paste programming from datadir.
281 AC_DEFUN(STEPMAKE_LIBDIR, [
282 presome=${exec_prefix}
283 if test "$presome" = "NONE"; then
286 if test "$presome" = "NONE"; then
287 presome=${ac_default_prefix}
290 build_package_libdir=$ac_pwd/out/lib/$package
292 LIBDIR=`echo ${libdir} | sed "s!\\\${exec_prefix}!$presome!"`
293 BUILD_PACKAGE_LIBDIR=`echo ${build_package_libdir} | sed "s!\\\${exec_prefix}!$presome!"`
296 AC_SUBST(build_package_libdir)
297 AC_DEFINE_UNQUOTED(CONFIG_LIBDIR, ["${LIBDIR}"])
298 AC_DEFINE_UNQUOTED(BUILD_PACKAGE_LIBDIR, ["${BUILD_PACKAGE_LIBDIR}"])
302 AC_DEFUN(STEPMAKE_PREFIX_EXPAND_FIXUP, [
303 # undo expanding of explicit --infodir=/usr/share
304 # to ease install-time override with prefix=...
305 strip=`echo $includedir | eval sed s@^$prefix@@`
306 if test "$includedir" = "`eval echo $prefix$strip`"; then
307 includedir='${prefix}'$strip''
309 strip=`echo $libdir | eval sed s@^$exec_prefix@@`
310 if test "$libdir" = "`eval echo $exec_prefix$strip`"; then
311 libdir='${exec_prefix}'$strip''
313 strip=`echo $infodir | eval sed s@^$datarootdir@@`
314 if test "$infodir" = "`eval echo $datarootdir$strip`"; then
315 infodir='${datarootdir}'$strip''
317 strip=`echo $mandir | eval sed s@^$datarootdir@@`
318 if test "$mandir" = "`eval echo $datarootdir$strip`"; then
319 mandir='${datarootdir}'$strip''
324 AC_DEFUN(STEPMAKE_END, [
325 STEPMAKE_PREFIX_EXPAND_FIXUP
330 AC_CONFIG_FILES([config.make:config.make.in])
333 if test -n "$OPTIONAL"; then
335 echo "WARNING: Please consider installing optional programs or files: $OPTIONAL"
338 if test -n "$REQUIRED"; then
340 echo "ERROR: Please install required programs: $REQUIRED"
343 if test -n "$UNSUPPORTED"; then
345 echo "ERROR: Please use older version of programs: $UNSUPPORTED"
348 if test -n "$OPTIONAL$REQUIRED$UNSUPPORTED"; then
350 echo "See INSTALL.txt for more information on how to build $PACKAGE_NAME"
351 if test -f config.cache ; then
352 echo "Remove config.cache before rerunning ./configure"
356 if test -n "$REQUIRED$UNSUPPORTED"; then
357 rm -f $srcdir/GNUmakefile
361 # regular in-place build
362 # test for srcdir_build = yes ?
363 if test "$srcdir_build" != "yes"; then
364 if test -f $srcdir/GNUmakefile; then
366 Source directory already configured. Please clean the source directory
368 make -C $srcdir distclean
376 for d in 2 3 4 5 ; do
378 for mf in `cd $srcdir; \
379 find . -maxdepth $d -mindepth $d -name GNUmakefile`; do
382 # source is below build directory, always copy
385 case "$abssrcdir/${mf#./}" in
387 # find descended into build directory, don't copy
395 include \$(depth)/config.make
396 include \$(configure-srcdir)/$mf
400 for mf in `cd $srcdir; \
401 find . -maxdepth $d -mindepth $d -name '*.make' \
402 | grep -v config.make `; do
405 # source is below build directory, always copy
408 case "$abssrcdir/${mf#./}" in
410 # find descended into build directory, don't copy
417 include \$(depth)/config.make
418 include \$(configure-srcdir)/$mf
424 cat <<EOF > GNUmakefile
427 include \$(configure-srcdir)/GNUmakefile.in
429 chmod 444 GNUmakefile
434 AC_DEFUN(STEPMAKE_FLEX, [
436 ac_cv_prog_lex_root=lex.yy
437 STEPMAKE_PROGS(FLEX, flex, $1)
441 AC_DEFUN(STEPMAKE_FLEXLEXER, [
442 save_CPPFLAGS="$CPPFLAGS"
443 if test -n "$FLEXLEXER_DIR"; then
444 FLEXLEXER_CPPFLAGS="-I$FLEXLEXER_DIR"
445 AC_SUBST(FLEXLEXER_CPPFLAGS)
446 CPPFLAGS="$FLEXLEXER_CPPFLAGS $CPPFLAGS"
448 AC_CHECK_HEADERS([FlexLexer.h],[true],[false])
449 if test $? -ne 0; then
450 warn='FlexLexer.h (flex package)'
451 STEPMAKE_ADD_ENTRY($1, $warn)
453 # check for yyFlexLexer.yypop_buffer_state () since flex 2.5.29
454 AC_CACHE_CHECK([for yyFlexLexer.yypop_buffer_state ()],
455 [stepmake_cv_flexlexer_yypop_buffer_state],
458 #include <FlexLexer.h>
459 class yy_flex_lexer: public yyFlexLexer
464 yypop_buffer_state ();
469 [stepmake_cv_flexlexer_yypop_buffer_state=yes],
470 [stepmake_cv_flexlexer_yypop_buffer_state=no]))
472 if test $stepmake_cv_flexlexer_yypop_buffer_state = no; then
473 warn='FlexLexer.h with yypop_buffer_state (flex >= 2.5.29)'
474 STEPMAKE_ADD_ENTRY($1, $warn)
476 CPPFLAGS=$save_CPPFLAGS
480 AC_DEFUN(STEPMAKE_GETTEXT, [
482 if test "$prefix" = "NONE"; then
483 presome=${ac_default_prefix}
485 LOCALEDIR=`echo ${localedir} | sed "s!\\\${prefix}!$presome!"`
488 AC_DEFINE_UNQUOTED(LOCALEDIR, ["${LOCALEDIR}"])
489 AC_CHECK_LIB(intl, gettext)
490 AC_CHECK_FUNCS(gettext)
494 AC_DEFUN(STEPMAKE_GUILE_DEVEL, [
495 AC_ARG_VAR(GUILE_FLAVOR,
496 AS_HELP_STRING([], [pkgconfig name for Guile, like guile-3.0.
497 If the respective .pc file
498 cannot be found by pkgconfig,
499 add its path to PKG_CONFIG_PATH]))dnl
501 if test -n "$GUILE_FLAVOR"; then
502 PKG_CHECK_MODULES([GUILE], [$GUILE_FLAVOR],
503 [true], [GUILE_FLAVOR="missing"])
505 PKG_CHECK_MODULES([GUILE], [guile-3.0 >= 3.0.7],
506 [GUILE_FLAVOR="guile-3.0"], [
507 GUILE_FLAVOR="missing"
511 if test "$GUILE_FLAVOR" = "missing"; then
512 STEPMAKE_ADD_ENTRY(REQUIRED, ["guile-devel >= 3.0.7"])
517 AC_DEFUN(STEPMAKE_INIT, [
519 FULL_VERSION=$MAJOR_VERSION.$MINOR_VERSION.$PATCH_LEVEL
520 TOPLEVEL_VERSION=$FULL_VERSION
521 if test x$MY_PATCH_LEVEL != x; then
522 FULL_VERSION=$FULL_VERSION.$MY_PATCH_LEVEL
524 VERSION=$FULL_VERSION
525 export MAJOR_VERSION MINOR_VERSION PATCH_LEVEL
527 # urg, how is this supposed to work?
528 if test "$program_prefix" = "NONE"; then
531 if test "$program_suffix" = "NONE"; then
535 # From configure: "When building in place, set srcdir=."
536 if test "$srcdir" = "."; then
541 abssrcdir="`cd $srcdir; pwd`"
546 AC_SUBST(MAJOR_VERSION)
547 AC_SUBST(MINOR_VERSION)
549 # stepmake nonstandard names
550 AC_SUBST(PATCH_LEVEL)
551 AC_SUBST(TOPLEVEL_VERSION)
553 AUTOGENERATE="This file was automatically generated by configure"
554 AC_SUBST(AUTOGENERATE)
557 STEPMAKE_PROGS(MAKE, gmake make, REQUIRED)
558 STEPMAKE_CHECK_VERSION(MAKE, REQUIRED, 4.2)
559 STEPMAKE_PROGS(FIND, find, REQUIRED)
561 STEPMAKE_PROGS(TAR, tar, REQUIRED)
563 if expr "$MAKE" : '.*\(echo\)' >/dev/null; then
564 $MAKE -v 2> /dev/null | grep GNU > /dev/null
565 if test "$?" = 1; then
566 warn='make (Please install *GNU* make)'
567 STEPMAKE_ADD_ENTRY(REQUIRED, $warn)
574 AC_SUBST(program_prefix)
575 AC_SUBST(program_suffix)
577 AC_DEFINE_UNQUOTED(PATHSEP, ['${PATHSEP}'])
585 AC_DEFUN(STEPMAKE_LIB, [
586 STEPMAKE_PROGS(AR, ar, $1)
588 STEPMAKE_OPTIONAL_REQUIRED(RANLIB, ranlib, $1)
592 AC_DEFUN(STEPMAKE_LOCALE, [
594 AC_ARG_WITH(localedir,
596 [--with-localedir=DIR],
597 [location of locales. Default: PREFIX/share/locale])],
598 localedir=$with_localedir,
599 localedir='${prefix}/share/locale')
603 AC_DEFUN(STEPMAKE_MSGFMT, [
604 STEPMAKE_PROGS(MSGFMT, msgfmt, $1)
608 # Check for program ($2). If found, assign full path result to ($1).
609 # If missing, add entry to missing-list ($3, one of 'OPTIONAL', 'REQUIRED')
610 # and assign "false" to ($1).
611 AC_DEFUN(STEPMAKE_PATH_PROG, [
612 AC_CHECK_PROGS($1, $2, no)
613 STEPMAKE_OPTIONAL_REQUIRED($1, $2, $3)
614 if test $? -eq 0; then
615 AC_PATH_PROGS($1, $2)
616 if test -n "$4"; then
617 STEPMAKE_CHECK_VERSION($1, $3, $4)
623 # Check for program in a set of names ($2). If found, assign result to ($1).
624 # If missing, add entry to missing-list ($3, one of 'OPTIONAL', 'REQUIRED')
625 # and assign "false" to ($1).
626 # Otherwise, compare version to minimum version ($4, optional) and/or maximum
627 # version ($5, optional).
628 AC_DEFUN(STEPMAKE_PROGS, [
629 AC_CHECK_PROGS($1, $2, no)
630 STEPMAKE_OPTIONAL_REQUIRED($1, $2, $3)
631 if test $? -eq 0; then
632 if test -n "$4" || test -n "$5"; then
633 STEPMAKE_CHECK_VERSION($1, $3, $4, $5)
639 AC_DEFUN(STEPMAKE_PERL, [
640 STEPMAKE_PATH_PROG(PERL, perl, $1)
644 # Check for python, between minimum ($2) and maximum version ($3).
645 # If missing, add entry to missing-list ($1, one of 'OPTIONAL', 'REQUIRED')
646 AC_DEFUN(STEPMAKE_PYTHON, [
647 AC_MSG_CHECKING([for python])
650 for r in $PYTHON python python3; do
651 exe=`STEPMAKE_GET_EXECUTABLE($r)`
652 if ! $exe -V > /dev/null 2>&1 ; then
655 ver=`STEPMAKE_GET_VERSION($exe)`
656 num=`STEPMAKE_NUMERIC_VERSION($ver)`
657 req=`STEPMAKE_NUMERIC_VERSION($2)`
658 sup=`STEPMAKE_NUMERIC_VERSION($3)`
659 if test -n "$2" && test "$num" -lt "$req"; then
660 python=["$r >= $2 (installed: $ver)"]
663 if test -n "$3" && test "$num" -ge "$sup"; then
664 python=["$r < $3 (installed: $ver)"]
673 AC_MSG_RESULT([$found])
674 if test "$found" != "no"; then
675 AC_MSG_CHECKING([$python version])
676 AC_MSG_RESULT([$ver])
679 STEPMAKE_ADD_ENTRY($1, $python)
681 AC_PATH_PROG(PYTHON, $PYTHON)
686 AC_DEFUN(STEPMAKE_FONTFORGE, [
687 STEPMAKE_PATH_PROG(FONTFORGE, fontforge, $1, 20110222)
688 if test $? -eq 0; then
689 min_quiet=`STEPMAKE_NUMERIC_VERSION(20220308)`
690 # `num` comes from `STEPMAKE_PATH_PROG`; we compare it with the
691 # first version that gives the `-quiet` option the expected
692 # functionality, that is, suppressing version and copyright
693 # information sent to stderr.
694 if test "$num" -ge "$min_quiet"; then
695 FONTFORGE_QUIET_OPTION=-quiet
696 AC_SUBST(FONTFORGE_QUIET_OPTION)
702 AC_DEFUN(STEPMAKE_TEXMF_DIRS, [
703 STEPMAKE_PROGS(KPSEWHICH, kpsewhich, $1)
705 AC_MSG_CHECKING(for metapost required files)
706 if test "$MFPLAIN_MP" = ""; then
707 MFPLAIN_MP=`kpsewhich -format=mp mfplain`
709 if test "$MFPLAIN_MP" = ""; then
711 STEPMAKE_ADD_ENTRY($1,
712 ['metapost CTAN package (texlive-metapost)'])
719 AC_DEFUN(STEPMAKE_TEXMF, [
720 STEPMAKE_PROGS(METAFONT, mf-nowin mf mfw mfont, $1)
721 STEPMAKE_PROGS(METAPOST, mpost, $1)
722 if test "$METAPOST" != ""; then
723 ver=`STEPMAKE_GET_VERSION($METAPOST)`
724 num=`STEPMAKE_NUMERIC_VERSION($ver)`
725 # Avoid buggy metapost versions: 1.600 <= x < 1.803
726 if test "$num" -ge "1600000" \
727 && test "$num" -lt "1803000"; then
728 STEPMAKE_ADD_ENTRY($1,
729 ["mpost (due to a bug in metapost, versions 1.600 <= x < 1.803 are not supported; installed: $ver)"])
735 AC_DEFUN(STEPMAKE_WINDOWS, [
736 AC_MSG_CHECKING([for some flavor of Windows])
753 AC_MSG_RESULT([$PLATFORM_WINDOWS])
756 AC_DEFINE_UNQUOTED(PATHSEP, ['${PATHSEP}'])
758 AC_SUBST(program_suffix)
760 AC_SUBST(PLATFORM_WINDOWS)
761 STEPMAKE_PROGS(WINDRES, $host-windres windres, x)
765 m4_include([m4/pkg.m4])