1# configure.ac for XS modules
2#
3# Copyright 2015-2020 Free Software Foundation, Inc.
4#
5# This file is free software; as a special exception the author gives
6# unlimited permission to copy and/or distribute it, with or without
7# modifications, as long as this notice is preserved.
8#
9# This program is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
11# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12#
13AC_INIT([texinfo], [0])
14AM_INIT_AUTOMAKE
15AC_CONFIG_MACRO_DIR([gnulib/m4])
16
17b='\'
18d='$'
19o='@<:@' dnl quadrigraph for [ - see autoconf documentatoin
20c='@:>@' dnl quadrigraph for ]
21
22# This turns a string like "cc='cc';" into a string like "cc".
23# Afterwards, convert \ into / in case \ is a path separator,
24# so it is not interpreted as a special character by the shell.
25
26sed_script="
27s/^$o^=$c*= *//
28s/^'//
29s/ *; *$//
30s/'$d//
31s/$b$b/$b//g"
32
33fetch_conf ()
34{
35          conf_value=`${PERL} -V:$1`
36          conf_value=`echo $conf_value | sed "$sed_script"`
37}
38
39AC_DEFUN([lookup_perl_conf],
40         [AC_MSG_CHECKING([Perl configuration value $1])
41          fetch_conf $1
42          AC_MSG_RESULT([$conf_value])
43          AC_SUBST([PERL_CONF_$1], [$conf_value])
44])
45
46AC_DEFUN([lookup_perl_conf_values],
47          [m4_foreach([var], [$1], [lookup_perl_conf(var)])
48])
49
50AC_ARG_ENABLE([perl-xs],
51    AS_HELP_STRING([--enable-perl-xs],
52              [build Perl XS modules for speed (default: yes)]),
53    [if test $enableval = 'no'; then
54       disable_xs=yes
55     else
56       disable_xs=no
57     fi],
58     [disable_xs=no])
59
60# PERL_EXT_var are user variables for a Perl XS extension, allowing
61# configuring at the top-level with e.g.
62#     "./configure CFLAGS='-g -O0' PERL_EXT_CFLAGS='-g'".
63# May be useful if the Perl interpreter was compiled with a
64# different compiler.  Also in top-level configure.ac.
65
66AC_ARG_VAR([PERL_EXT_CFLAGS], [Compiler flags for a Perl extension])
67AC_ARG_VAR([PERL_EXT_CPPFLAGS], [C preprocessor flags for a Perl extension])
68AC_ARG_VAR([PERL_EXT_LDFLAGS], [Linker flags for a Perl extension])
69AC_ARG_VAR([PERL_EXT_CC], [Compiler for a Perl extension])
70
71# See (automake)Conditional Subdirectories.  Even if --disable-perl-xs
72# is given, we still need to configure this directory minimally, so that
73# "make dist" will work.
74if test x$disable_xs != xyes; then
75  AC_PATH_PROG([PERL], [perl])
76
77  if test -n "$PERL_EXT_CC" ; then
78    CC=$PERL_EXT_CC
79  else
80    # It's essential that we use the same compiler that was used to build
81    # Perl.  Otherwise Perl's "config.h" will be incorrect.  This overrides
82    # the check in AC_PROG_CC below.
83    lookup_perl_conf([cc])
84    CC=$conf_value
85  fi
86
87  # Wipe cache values in case -C was given at the top level
88  ac_cv_prog_CC= ; unset ac_cv_prog_CC
89  ac_cv_prog_ac_ct_CC= ; unset ac_cv_prog_ac_ct_CC
90
91  lookup_perl_conf_values([[ccflags], [cccdlflags], [optimize]])
92
93  # flags for linking the extension, e.g. -rpath.
94  lookup_perl_conf([ccdlflags])
95
96  # Override these variables set by configure at the top level, because
97  # the compiler used in this subdirectory might be different.
98  # Change these now so they are used in the checks that follow.
99  CFLAGS="$PERL_EXT_CFLAGS $PERL_CONF_ccflags"
100  CPPFLAGS=$PERL_EXT_CPPFLAGS
101  LDFLAGS="$PERL_EXT_LDFLAGS $PERL_CONF_ccdlflags $PERL_CONF_cccdlflags"
102
103  lookup_perl_conf([libperl])
104  # Change libperl.so into -lperl to indicate a library dependency to
105  # libtool.
106  # Special case for Cygwin to change e.g. cygperl5_22.dll into -lperl
107  PERL_CONF_libperl=`echo $PERL_CONF_libperl \
108             | sed -e 's/^lib/-l/' \
109                   -e 's/\..*//' \
110                   -e 's/^cygperl.*/-lperl/' `
111
112  lookup_perl_conf_values([[archlibexp], [privlibexp]])
113
114  AC_CONFIG_HEADERS([config.h:config.in])
115fi # not disable_xs
116
117
118AC_PROG_CC
119
120gl_EARLY
121
122AM_GNU_GETTEXT([external])
123AM_MISSING_PROG([XSUBPP], [xsubpp])
124AM_MISSING_PROG([GAWK], [gawk])
125
126gl_INIT
127
128LT_INIT([disable-static])
129
130# Note that the above have to be outside the disable_xs block
131# otherwise it causes an error with configure.
132
133# Disable gnulib provision of "Microsoft deprecated alias" fdopen on
134# MS-Windows to prevent a clash with definitions in Perl header files
135GNULIB_MDA_FDOPEN=0
136
137
138host_needs_no_undefined=no
139case "$host" in *-mingw32 | *-mingw64 | *-msdosdjgpp | *-cygwin )
140  host_needs_no_undefined=yes ;;
141esac
142AM_CONDITIONAL([HOST_NEEDS_NO_UNDEFINED],
143               [test "x$host_needs_no_undefined" = "xyes"])
144
145AM_CONDITIONAL([HAVE_ICONV],
146               [test "x$am_func_iconv" = "xyes"])
147
148
149# Do not include Perl configuration values when outputting these variables
150CFLAGS=$PERL_EXT_CFLAGS
151CPPFLAGS=$PERL_EXT_CPPFLAGS
152LDFLAGS=$PERL_EXT_LDFLAGS
153
154AC_CONFIG_FILES([Makefile gnulib/lib/Makefile])
155AC_OUTPUT
156