1dnl Copyright (c) 2011 the LinBox group
2dnl This file is part of LinBox
3
4 dnl ========LICENCE========
5 dnl This file is part of the library LinBox.
6 dnl
7 dnl LinBox is free software: you can redistribute it and/or modify
8 dnl it under the terms of the  GNU Lesser General Public
9 dnl License as published by the Free Software Foundation; either
10 dnl version 2.1 of the License, or (at your option) any later version.
11 dnl
12 dnl This library is distributed in the hope that it will be useful,
13 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
14 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 dnl Lesser General Public License for more details.
16 dnl
17 dnl You should have received a copy of the GNU Lesser General Public
18 dnl License along with this library; if not, write to the Free Software
19 dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20 dnl ========LICENCE========
21 dnl
22
23
24
25AC_DEFUN([AX_PREFIX_CONFIG_H],[AC_REQUIRE([AC_CONFIG_HEADERS])
26AC_CONFIG_COMMANDS([ifelse($1,,$PACKAGE-config.h,$1)],[dnl
27AS_VAR_PUSHDEF([_OUT],[ac_prefix_conf_OUT])dnl
28AS_VAR_PUSHDEF([_DEF],[ac_prefix_conf_DEF])dnl
29AS_VAR_PUSHDEF([_PKG],[ac_prefix_conf_PKG])dnl
30AS_VAR_PUSHDEF([_LOW],[ac_prefix_conf_LOW])dnl
31AS_VAR_PUSHDEF([_UPP],[ac_prefix_conf_UPP])dnl
32AS_VAR_PUSHDEF([_INP],[ac_prefix_conf_INP])dnl
33m4_pushdef([_script],[conftest.prefix])dnl
34m4_pushdef([_symbol],[m4_cr_Letters[]m4_cr_digits[]_])dnl
35_OUT=`echo ifelse($1, , $PACKAGE-config.h, $1)`
36_DEF=`echo _$_OUT | sed -e "y:m4_cr_letters:m4_cr_LETTERS[]:" -e "s/@<:@^m4_cr_Letters@:>@/_/g"`
37_PKG=`echo ifelse($2, , $PACKAGE, $2)`
38_LOW=`echo _$_PKG | sed -e "y:m4_cr_LETTERS-:m4_cr_letters[]_:"`
39_UPP=`echo $_PKG | sed -e "y:m4_cr_letters-:m4_cr_LETTERS[]_:"  -e "/^@<:@m4_cr_digits@:>@/s/^/_/"`
40_INP=`echo "ifelse($3,,,$3)" | sed -e 's/ *//'`
41if test ".$_INP" = "."; then
42   for ac_file in : $CONFIG_HEADERS; do test "_$ac_file" = _: && continue
43     case "$ac_file" in
44        *.h) _INP=$ac_file ;;
45        *)
46     esac
47     test ".$_INP" != "." && break
48   done
49fi
50if test ".$_INP" = "."; then
51   case "$_OUT" in
52      */*) _INP=`basename "$_OUT"`
53      ;;
54      *-*) _INP=`echo "$_OUT" | sed -e "s/@<:@_symbol@:>@*-//"`
55      ;;
56      *) _INP=config.h
57      ;;
58   esac
59fi
60if test -z "$_PKG" ; then
61   AC_MSG_ERROR([no prefix for _PREFIX_PKG_CONFIG_H])
62else
63  if test ! -f "$_INP" ; then if test -f "$srcdir/$_INP" ; then
64     _INP="$srcdir/$_INP"
65  fi fi
66  AC_MSG_NOTICE(creating $_OUT - prefix $_UPP for $_INP defines)
67  if test -f $_INP ; then
68    AS_ECHO("s/@%:@undef  *\\(@<:@m4_cr_LETTERS[]_@:>@\\)/@%:@undef $_UPP""_\\1/") > _script
69    AS_ECHO("s/@%:@undef  *\\(@<:@m4_cr_letters@:>@\\)/@%:@undef $_LOW""_\\1/") >> _script
70    AS_ECHO("s/@%:@def[]ine  *\\(@<:@m4_cr_LETTERS[]_@:>@@<:@_symbol@:>@*\\)\\(.*\\)/@%:@ifndef $_UPP""_\\1 \\") >> _script
71    AS_ECHO("@%:@def[]ine $_UPP""_\\1 \\2 \\") >> _script
72    AS_ECHO("@%:@endif/") >>_script
73    AS_ECHO("s/@%:@def[]ine  *\\(@<:@m4_cr_letters@:>@@<:@_symbol@:>@*\\)\\(.*\\)/@%:@ifndef $_LOW""_\\1 \\") >> _script
74    AS_ECHO("@%:@define $_LOW""_\\1 \\2 \\") >> _script
75    AS_ECHO("@%:@endif/") >> _script
76    # now executing _script on _DEF input to create _OUT output file
77    AS_ECHO("@%:@ifndef $_DEF")      >$tmp/pconfig.h
78    AS_ECHO("@%:@def[]ine $_DEF 1") >>$tmp/pconfig.h
79    AS_ECHO(" ") >>$tmp/pconfig.h
80    AS_ECHO("/* $_OUT. Generated automatically at end of configure. */") >>$tmp/pconfig.h
81
82    sed -f _script $_INP >>$tmp/pconfig.h
83    AS_ECHO(" ") >>$tmp/pconfig.h
84    AS_ECHO("/* once: $_DEF */") >>$tmp/pconfig.h
85    AS_ECHO("@%:@endif") >>$tmp/pconfig.h
86    if cmp -s $_OUT $tmp/pconfig.h 2>/dev/null; then
87      AC_MSG_NOTICE([$_OUT is unchanged])
88    else
89      ac_dir=`AS_DIRNAME(["$_OUT"])`
90      AS_MKDIR_P(["$ac_dir"])
91      rm -f "$_OUT"
92      mv $tmp/pconfig.h "$_OUT"
93    fi
94    cp _script _configs.sed
95  else
96    AC_MSG_ERROR([input file $_INP does not exist - skip generating $_OUT])
97  fi
98  rm -f conftest.*
99fi
100m4_popdef([_symbol])dnl
101m4_popdef([_script])dnl
102AS_VAR_POPDEF([_INP])dnl
103AS_VAR_POPDEF([_UPP])dnl
104AS_VAR_POPDEF([_LOW])dnl
105AS_VAR_POPDEF([_PKG])dnl
106AS_VAR_POPDEF([_DEF])dnl
107AS_VAR_POPDEF([_OUT])dnl
108],[PACKAGE="$PACKAGE"])])
109
110
111