cristy | 430a731 | 2010-01-21 20:44:04 +0000 | [diff] [blame] | 1 | # =========================================================================== |
cristy | 964cb7f | 2010-04-25 23:18:00 +0000 | [diff] [blame] | 2 | # http://www.gnu.org/software/autoconf-archive/ax_prefix_config_h.html |
cristy | 430a731 | 2010-01-21 20:44:04 +0000 | [diff] [blame] | 3 | # =========================================================================== |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4 | # |
| 5 | # SYNOPSIS |
| 6 | # |
| 7 | # AX_PREFIX_CONFIG_H [(OUTPUT-HEADER [,PREFIX [,ORIG-HEADER]])] |
| 8 | # |
| 9 | # DESCRIPTION |
| 10 | # |
| 11 | # This is a new variant from ac_prefix_config_ this one will use a |
| 12 | # lowercase-prefix if the config-define was starting with a |
cristy | 430a731 | 2010-01-21 20:44:04 +0000 | [diff] [blame] | 13 | # lowercase-char, e.g. "#define const", "#define restrict", or "#define |
| 14 | # off_t", (and this one can live in another directory, e.g. |
| 15 | # testpkg/config.h therefore I decided to move the output-header to be the |
| 16 | # first arg) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 17 | # |
cristy | 430a731 | 2010-01-21 20:44:04 +0000 | [diff] [blame] | 18 | # takes the usual config.h generated header file; looks for each of the |
| 19 | # generated "#define SOMEDEF" lines, and prefixes the defined name (ie. |
| 20 | # makes it "#define PREFIX_SOMEDEF". The result is written to the output |
| 21 | # config.header file. The PREFIX is converted to uppercase for the |
| 22 | # conversions. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 23 | # |
| 24 | # Defaults: |
| 25 | # |
| 26 | # OUTPUT-HEADER = $PACKAGE-config.h |
| 27 | # PREFIX = $PACKAGE |
| 28 | # ORIG-HEADER, from AM_CONFIG_HEADER(config.h) |
| 29 | # |
cristy | 430a731 | 2010-01-21 20:44:04 +0000 | [diff] [blame] | 30 | # Your configure.ac script should contain both macros in this order, and |
| 31 | # unlike the earlier variations of this prefix-macro it is okay to place |
| 32 | # the AX_PREFIX_CONFIG_H call before the AC_OUTPUT invokation. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 33 | # |
| 34 | # Example: |
| 35 | # |
| 36 | # AC_INIT(config.h.in) # config.h.in as created by "autoheader" |
| 37 | # AM_INIT_AUTOMAKE(testpkg, 0.1.1) # makes #undef VERSION and PACKAGE |
| 38 | # AM_CONFIG_HEADER(config.h) # prep config.h from config.h.in |
| 39 | # AX_PREFIX_CONFIG_H(mylib/_config.h) # prep mylib/_config.h from it.. |
| 40 | # AC_MEMORY_H # makes "#undef NEED_MEMORY_H" |
| 41 | # AC_C_CONST_H # makes "#undef const" |
| 42 | # AC_OUTPUT(Makefile) # creates the "config.h" now |
| 43 | # # and also mylib/_config.h |
| 44 | # |
cristy | 430a731 | 2010-01-21 20:44:04 +0000 | [diff] [blame] | 45 | # if the argument to AX_PREFIX_CONFIG_H would have been omitted then the |
| 46 | # default outputfile would have been called simply "testpkg-config.h", but |
| 47 | # even under the name "mylib/_config.h" it contains prefix-defines like |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 48 | # |
| 49 | # #ifndef TESTPKG_VERSION |
| 50 | # #define TESTPKG_VERSION "0.1.1" |
| 51 | # #endif |
| 52 | # #ifndef TESTPKG_NEED_MEMORY_H |
| 53 | # #define TESTPKG_NEED_MEMORY_H 1 |
| 54 | # #endif |
| 55 | # #ifndef _testpkg_const |
| 56 | # #define _testpkg_const _const |
| 57 | # #endif |
| 58 | # |
| 59 | # and this "mylib/_config.h" can be installed along with other |
cristy | 430a731 | 2010-01-21 20:44:04 +0000 | [diff] [blame] | 60 | # header-files, which is most convenient when creating a shared library |
| 61 | # (that has some headers) where some functionality is dependent on the |
| 62 | # OS-features detected at compile-time. No need to invent some |
| 63 | # "mylib-confdefs.h.in" manually. :-) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 64 | # |
cristy | 430a731 | 2010-01-21 20:44:04 +0000 | [diff] [blame] | 65 | # Note that some AC_DEFINEs that end up in the config.h file are actually |
| 66 | # self-referential - e.g. AC_C_INLINE, AC_C_CONST, and the AC_TYPE_OFF_T |
| 67 | # say that they "will define inline|const|off_t if the system does not do |
| 68 | # it by itself". You might want to clean up about these - consider an |
| 69 | # extra mylib/conf.h that reads something like: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 70 | # |
cristy | 964cb7f | 2010-04-25 23:18:00 +0000 | [diff] [blame] | 71 | # #include <mylib/_config.h> |
| 72 | # #ifndef _testpkg_const |
| 73 | # #define _testpkg_const const |
| 74 | # #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 75 | # |
cristy | 430a731 | 2010-01-21 20:44:04 +0000 | [diff] [blame] | 76 | # and then start using _testpkg_const in the header files. That is also a |
| 77 | # good thing to differentiate whether some library-user has starting to |
| 78 | # take up with a different compiler, so perhaps it could read something |
| 79 | # like this: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 80 | # |
| 81 | # #ifdef _MSC_VER |
| 82 | # #include <mylib/_msvc.h> |
| 83 | # #else |
| 84 | # #include <mylib/_config.h> |
| 85 | # #endif |
| 86 | # #ifndef _testpkg_const |
| 87 | # #define _testpkg_const const |
| 88 | # #endif |
| 89 | # |
cristy | 430a731 | 2010-01-21 20:44:04 +0000 | [diff] [blame] | 90 | # LICENSE |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 91 | # |
cristy | 430a731 | 2010-01-21 20:44:04 +0000 | [diff] [blame] | 92 | # Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de> |
| 93 | # Copyright (c) 2008 Marten Svantesson |
| 94 | # Copyright (c) 2008 Gerald Point <Gerald.Point@labri.fr> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 95 | # |
cristy | 430a731 | 2010-01-21 20:44:04 +0000 | [diff] [blame] | 96 | # This program is free software; you can redistribute it and/or modify it |
| 97 | # under the terms of the GNU General Public License as published by the |
| 98 | # Free Software Foundation; either version 2 of the License, or (at your |
| 99 | # option) any later version. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 100 | # |
| 101 | # This program is distributed in the hope that it will be useful, but |
| 102 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
cristy | 430a731 | 2010-01-21 20:44:04 +0000 | [diff] [blame] | 103 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
| 104 | # Public License for more details. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 105 | # |
cristy | 430a731 | 2010-01-21 20:44:04 +0000 | [diff] [blame] | 106 | # You should have received a copy of the GNU General Public License along |
| 107 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 108 | # |
cristy | 430a731 | 2010-01-21 20:44:04 +0000 | [diff] [blame] | 109 | # As a special exception, the respective Autoconf Macro's copyright owner |
| 110 | # gives unlimited permission to copy, distribute and modify the configure |
| 111 | # scripts that are the output of Autoconf when processing the Macro. You |
| 112 | # need not follow the terms of the GNU General Public License when using |
| 113 | # or distributing such scripts, even though portions of the text of the |
| 114 | # Macro appear in them. The GNU General Public License (GPL) does govern |
| 115 | # all other use of the material that constitutes the Autoconf Macro. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 116 | # |
cristy | 430a731 | 2010-01-21 20:44:04 +0000 | [diff] [blame] | 117 | # This special exception to the GPL applies to versions of the Autoconf |
| 118 | # Macro released by the Autoconf Archive. When you make and distribute a |
| 119 | # modified version of the Autoconf Macro, you may extend this special |
| 120 | # exception to the GPL to apply to your modified version as well. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 121 | |
cristy | 964cb7f | 2010-04-25 23:18:00 +0000 | [diff] [blame] | 122 | #serial 9 |
| 123 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 124 | AC_DEFUN([AX_PREFIX_CONFIG_H],[dnl |
| 125 | AC_BEFORE([AC_CONFIG_HEADERS],[$0])dnl |
| 126 | AC_CONFIG_COMMANDS([ifelse($1,,$PACKAGE-config.h,$1)],[dnl |
| 127 | AS_VAR_PUSHDEF([_OUT],[ac_prefix_conf_OUT])dnl |
| 128 | AS_VAR_PUSHDEF([_DEF],[ac_prefix_conf_DEF])dnl |
| 129 | AS_VAR_PUSHDEF([_PKG],[ac_prefix_conf_PKG])dnl |
| 130 | AS_VAR_PUSHDEF([_LOW],[ac_prefix_conf_LOW])dnl |
| 131 | AS_VAR_PUSHDEF([_UPP],[ac_prefix_conf_UPP])dnl |
| 132 | AS_VAR_PUSHDEF([_INP],[ac_prefix_conf_INP])dnl |
| 133 | m4_pushdef([_script],[conftest.prefix])dnl |
| 134 | m4_pushdef([_symbol],[m4_cr_Letters[]m4_cr_digits[]_])dnl |
| 135 | _OUT=`echo ifelse($1, , $PACKAGE-config.h, $1)` |
| 136 | _DEF=`echo _$_OUT | sed -e "y:m4_cr_letters:m4_cr_LETTERS[]:" -e "s/@<:@^m4_cr_Letters@:>@/_/g"` |
| 137 | _PKG=`echo ifelse($2, , $PACKAGE, $2)` |
| 138 | _LOW=`echo _$_PKG | sed -e "y:m4_cr_LETTERS-:m4_cr_letters[]_:"` |
| 139 | _UPP=`echo $_PKG | sed -e "y:m4_cr_letters-:m4_cr_LETTERS[]_:" -e "/^@<:@m4_cr_digits@:>@/s/^/_/"` |
| 140 | _INP=`echo "ifelse($3,,,$3)" | sed -e 's/ *//'` |
| 141 | if test ".$_INP" = "."; then |
| 142 | for ac_file in : $CONFIG_HEADERS; do test "_$ac_file" = _: && continue |
| 143 | case "$ac_file" in |
| 144 | *.h) _INP=$ac_file ;; |
| 145 | *) |
| 146 | esac |
| 147 | test ".$_INP" != "." && break |
| 148 | done |
| 149 | fi |
| 150 | if test ".$_INP" = "."; then |
| 151 | case "$_OUT" in |
| 152 | */*) _INP=`basename "$_OUT"` |
| 153 | ;; |
| 154 | *-*) _INP=`echo "$_OUT" | sed -e "s/@<:@_symbol@:>@*-//"` |
| 155 | ;; |
| 156 | *) _INP=config.h |
| 157 | ;; |
| 158 | esac |
| 159 | fi |
| 160 | if test -z "$_PKG" ; then |
| 161 | AC_MSG_ERROR([no prefix for _PREFIX_PKG_CONFIG_H]) |
| 162 | else |
| 163 | if test ! -f "$_INP" ; then if test -f "$srcdir/$_INP" ; then |
| 164 | _INP="$srcdir/$_INP" |
| 165 | fi fi |
| 166 | AC_MSG_NOTICE(creating $_OUT - prefix $_UPP for $_INP defines) |
| 167 | if test -f $_INP ; then |
| 168 | echo "s/^@%:@undef *\\(@<:@m4_cr_LETTERS[]_@:>@\\)/@%:@undef $_UPP""_\\1/" > _script |
| 169 | echo "s/^@%:@undef *\\(@<:@m4_cr_letters@:>@\\)/@%:@undef $_LOW""_\\1/" >> _script |
cristy | 964cb7f | 2010-04-25 23:18:00 +0000 | [diff] [blame] | 170 | echo "s/^@%:@def[]ine *\\(@<:@m4_cr_LETTERS[]_@:>@@<:@_symbol@:>@*\\)\\(.*\\)/@%:@ifndef $_UPP""_\\1\\" >> _script |
| 171 | echo "@%:@def[]ine $_UPP""_\\1\\2\\" >> _script |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 172 | echo "@%:@endif/" >>_script |
cristy | 964cb7f | 2010-04-25 23:18:00 +0000 | [diff] [blame] | 173 | echo "s/^@%:@def[]ine *\\(@<:@m4_cr_letters@:>@@<:@_symbol@:>@*\\)\\(.*\\)/@%:@ifndef $_LOW""_\\1\\" >> _script |
| 174 | echo "@%:@define $_LOW""_\\1\\2\\" >> _script |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 175 | echo "@%:@endif/" >> _script |
| 176 | # now executing _script on _DEF input to create _OUT output file |
| 177 | echo "@%:@ifndef $_DEF" >$tmp/pconfig.h |
| 178 | echo "@%:@def[]ine $_DEF 1" >>$tmp/pconfig.h |
| 179 | echo ' ' >>$tmp/pconfig.h |
| 180 | echo /'*' $_OUT. Generated automatically at end of configure. '*'/ >>$tmp/pconfig.h |
| 181 | |
| 182 | sed -f _script $_INP >>$tmp/pconfig.h |
| 183 | echo ' ' >>$tmp/pconfig.h |
| 184 | echo '/* once:' $_DEF '*/' >>$tmp/pconfig.h |
| 185 | echo "@%:@endif" >>$tmp/pconfig.h |
| 186 | if cmp -s $_OUT $tmp/pconfig.h 2>/dev/null; then |
| 187 | AC_MSG_NOTICE([$_OUT is unchanged]) |
| 188 | else |
| 189 | ac_dir=`AS_DIRNAME(["$_OUT"])` |
| 190 | AS_MKDIR_P(["$ac_dir"]) |
| 191 | rm -f "$_OUT" |
| 192 | mv $tmp/pconfig.h "$_OUT" |
| 193 | fi |
| 194 | cp _script _configs.sed |
| 195 | else |
| 196 | AC_MSG_ERROR([input file $_INP does not exist - skip generating $_OUT]) |
| 197 | fi |
| 198 | rm -f conftest.* |
| 199 | fi |
| 200 | m4_popdef([_symbol])dnl |
| 201 | m4_popdef([_script])dnl |
| 202 | AS_VAR_POPDEF([_INP])dnl |
| 203 | AS_VAR_POPDEF([_UPP])dnl |
| 204 | AS_VAR_POPDEF([_LOW])dnl |
| 205 | AS_VAR_POPDEF([_PKG])dnl |
| 206 | AS_VAR_POPDEF([_DEF])dnl |
| 207 | AS_VAR_POPDEF([_OUT])dnl |
| 208 | ],[PACKAGE="$PACKAGE"])]) |
| 209 | |
| 210 | dnl implementation note: a bug report (31.5.2005) from Marten Svantesson points |
| 211 | dnl out a problem where `echo "\1"` results in a Control-A. The unix standard |
| 212 | dnl http://www.opengroup.org/onlinepubs/000095399/utilities/echo.html |
| 213 | dnl defines all backslash-sequences to be inherently non-portable asking |
| 214 | dnl for replacement mit printf. Some old systems had problems with that |
| 215 | dnl one either. However, the latest libtool (!) release does export an $ECHO |
| 216 | dnl (and $echo) that does the right thing - just one question is left: what |
| 217 | dnl was the first version to have it? Is it greater 2.58 ? |