You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
6.6 KiB

  1. dnl @synopsis AX_PREFIX_CONFIG_H [(OUTPUT-HEADER [,PREFIX [,ORIG-HEADER]])]
  2. dnl
  3. dnl This is a new variant from ac_prefix_config_ this one will use a
  4. dnl lowercase-prefix if the config-define was starting with a
  5. dnl lowercase-char, e.g. "#define const", "#define restrict", or
  6. dnl "#define off_t", (and this one can live in another directory, e.g.
  7. dnl testpkg/config.h therefore I decided to move the output-header to
  8. dnl be the first arg)
  9. dnl
  10. dnl takes the usual config.h generated header file; looks for each of
  11. dnl the generated "#define SOMEDEF" lines, and prefixes the defined name
  12. dnl (ie. makes it "#define PREFIX_SOMEDEF". The result is written to
  13. dnl the output config.header file. The PREFIX is converted to uppercase
  14. dnl for the conversions.
  15. dnl
  16. dnl Defaults:
  17. dnl
  18. dnl OUTPUT-HEADER = $PACKAGE-config.h
  19. dnl PREFIX = $PACKAGE
  20. dnl ORIG-HEADER, from AM_CONFIG_HEADER(config.h)
  21. dnl
  22. dnl Your configure.ac script should contain both macros in this order,
  23. dnl and unlike the earlier variations of this prefix-macro it is okay to
  24. dnl place the AX_PREFIX_CONFIG_H call before the AC_OUTPUT invokation.
  25. dnl
  26. dnl Example:
  27. dnl
  28. dnl AC_INIT(config.h.in) # config.h.in as created by "autoheader"
  29. dnl AM_INIT_AUTOMAKE(testpkg, 0.1.1) # makes #undef VERSION and PACKAGE
  30. dnl AM_CONFIG_HEADER(config.h) # prep config.h from config.h.in
  31. dnl AX_PREFIX_CONFIG_H(mylib/_config.h) # prep mylib/_config.h from it..
  32. dnl AC_MEMORY_H # makes "#undef NEED_MEMORY_H"
  33. dnl AC_C_CONST_H # makes "#undef const"
  34. dnl AC_OUTPUT(Makefile) # creates the "config.h" now
  35. dnl # and also mylib/_config.h
  36. dnl
  37. dnl if the argument to AX_PREFIX_CONFIG_H would have been omitted then the
  38. dnl default outputfile would have been called simply "testpkg-config.h", but
  39. dnl even under the name "mylib/_config.h" it contains prefix-defines like
  40. dnl
  41. dnl #ifndef TESTPKG_VERSION
  42. dnl #define TESTPKG_VERSION "0.1.1"
  43. dnl #endif
  44. dnl #ifndef TESTPKG_NEED_MEMORY_H
  45. dnl #define TESTPKG_NEED_MEMORY_H 1
  46. dnl #endif
  47. dnl #ifndef _testpkg_const
  48. dnl #define _testpkg_const _const
  49. dnl #endif
  50. dnl
  51. dnl and this "mylib/_config.h" can be installed along with other
  52. dnl header-files, which is most convenient when creating a shared
  53. dnl library (that has some headers) where some functionality is
  54. dnl dependent on the OS-features detected at compile-time. No
  55. dnl need to invent some "mylib-confdefs.h.in" manually. :-)
  56. dnl
  57. dnl Note that some AC_DEFINEs that end up in the config.h file are
  58. dnl actually self-referential - e.g. AC_C_INLINE, AC_C_CONST, and the
  59. dnl AC_TYPE_OFF_T say that they "will define inline|const|off_t if the
  60. dnl system does not do it by itself". You might want to clean up about
  61. dnl these - consider an extra mylib/conf.h that reads something like:
  62. dnl
  63. dnl #include <mylib/_config.h>
  64. dnl #ifndef _testpkg_const
  65. dnl #define _testpkg_const const
  66. dnl #endif
  67. dnl
  68. dnl and then start using _testpkg_const in the header files. That is
  69. dnl also a good thing to differentiate whether some library-user has
  70. dnl starting to take up with a different compiler, so perhaps it could
  71. dnl read something like this:
  72. dnl
  73. dnl #ifdef _MSC_VER
  74. dnl #include <mylib/_msvc.h>
  75. dnl #else
  76. dnl #include <mylib/_config.h>
  77. dnl #endif
  78. dnl #ifndef _testpkg_const
  79. dnl #define _testpkg_const const
  80. dnl #endif
  81. dnl
  82. dnl @version $Id$
  83. dnl @author Guiodo Draheim <guidod@gmx.de>
  84. dnl @License GPLV3
  85. AC_DEFUN([AX_PREFIX_CONFIG_H],[AC_REQUIRE([AC_CONFIG_HEADER])
  86. AC_CONFIG_COMMANDS([ifelse($1,,$PACKAGE-config.h,$1)],[dnl
  87. AS_VAR_PUSHDEF([_OUT],[ac_prefix_conf_OUT])dnl
  88. AS_VAR_PUSHDEF([_DEF],[ac_prefix_conf_DEF])dnl
  89. AS_VAR_PUSHDEF([_PKG],[ac_prefix_conf_PKG])dnl
  90. AS_VAR_PUSHDEF([_LOW],[ac_prefix_conf_LOW])dnl
  91. AS_VAR_PUSHDEF([_UPP],[ac_prefix_conf_UPP])dnl
  92. AS_VAR_PUSHDEF([_INP],[ac_prefix_conf_INP])dnl
  93. m4_pushdef([_script],[conftest.prefix])dnl
  94. m4_pushdef([_symbol],[m4_cr_Letters[]m4_cr_digits[]_])dnl
  95. _OUT=`echo ifelse($1, , $PACKAGE-config.h, $1)`
  96. _DEF=`echo _$_OUT | sed -e "y:m4_cr_letters:m4_cr_LETTERS[]:" -e "s/@<:@^m4_cr_Letters@:>@/_/g"`
  97. _PKG=`echo ifelse($2, , $PACKAGE, $2)`
  98. _LOW=`echo _$_PKG | sed -e "y:m4_cr_LETTERS-:m4_cr_letters[]_:"`
  99. _UPP=`echo $_PKG | sed -e "y:m4_cr_letters-:m4_cr_LETTERS[]_:" -e "/^@<:@m4_cr_digits@:>@/s/^/_/"`
  100. _INP=`echo "ifelse($3,,,$3)" | sed -e 's/ *//'`
  101. if test ".$_INP" = "."; then
  102. for ac_file in : $CONFIG_HEADERS; do test "_$ac_file" = _: && continue
  103. case "$ac_file" in
  104. *.h) _INP=$ac_file ;;
  105. *)
  106. esac
  107. test ".$_INP" != "." && break
  108. done
  109. fi
  110. if test ".$_INP" = "."; then
  111. case "$_OUT" in
  112. */*) _INP=`basename "$_OUT"`
  113. ;;
  114. *-*) _INP=`echo "$_OUT" | sed -e "s/@<:@_symbol@:>@*-//"`
  115. ;;
  116. *) _INP=config.h
  117. ;;
  118. esac
  119. fi
  120. if test -z "$_PKG" ; then
  121. AC_MSG_ERROR([no prefix for _PREFIX_PKG_CONFIG_H])
  122. else
  123. if test ! -f "$_INP" ; then if test -f "$srcdir/$_INP" ; then
  124. _INP="$srcdir/$_INP"
  125. fi fi
  126. AC_MSG_NOTICE(creating $_OUT - prefix $_UPP for $_INP defines)
  127. if test -f $_INP ; then
  128. echo "s/@%:@undef *\\(@<:@m4_cr_LETTERS[]_@:>@\\)/@%:@undef $_UPP""_\\1/" > _script
  129. echo "s/@%:@undef *\\(@<:@m4_cr_letters@:>@\\)/@%:@undef $_LOW""_\\1/" >> _script
  130. echo "s/@%:@def[]ine *\\(@<:@m4_cr_LETTERS[]_@:>@@<:@_symbol@:>@*\\)\\(.*\\)/@%:@ifndef $_UPP""_\\1 \\" >> _script
  131. echo "@%:@def[]ine $_UPP""_\\1 \\2 \\" >> _script
  132. echo "@%:@endif/" >>_script
  133. echo "s/@%:@def[]ine *\\(@<:@m4_cr_letters@:>@@<:@_symbol@:>@*\\)\\(.*\\)/@%:@ifndef $_LOW""_\\1 \\" >> _script
  134. echo "@%:@define $_LOW""_\\1 \\2 \\" >> _script
  135. echo "@%:@endif/" >> _script
  136. # now executing _script on _DEF input to create _OUT output file
  137. echo "@%:@ifndef $_DEF" >$tmp/pconfig.h
  138. echo "@%:@def[]ine $_DEF 1" >>$tmp/pconfig.h
  139. echo ' ' >>$tmp/pconfig.h
  140. echo /'*' $_OUT. Generated automatically at end of configure. '*'/ >>$tmp/pconfig.h
  141. sed -f _script $_INP >>$tmp/pconfig.h
  142. echo ' ' >>$tmp/pconfig.h
  143. echo '/* once:' $_DEF '*/' >>$tmp/pconfig.h
  144. echo "@%:@endif" >>$tmp/pconfig.h
  145. if cmp -s $_OUT $tmp/pconfig.h 2>/dev/null; then
  146. AC_MSG_NOTICE([$_OUT is unchanged])
  147. else
  148. ac_dir=`AS_DIRNAME(["$_OUT"])`
  149. AS_MKDIR_P(["$ac_dir"])
  150. rm -f "$_OUT"
  151. mv $tmp/pconfig.h "$_OUT"
  152. fi
  153. cp _script _configs.sed
  154. else
  155. AC_MSG_ERROR([input file $_INP does not exist - skip generating $_OUT])
  156. fi
  157. rm -f conftest.*
  158. fi
  159. m4_popdef([_symbol])dnl
  160. m4_popdef([_script])dnl
  161. AS_VAR_POPDEF([_INP])dnl
  162. AS_VAR_POPDEF([_UPP])dnl
  163. AS_VAR_POPDEF([_LOW])dnl
  164. AS_VAR_POPDEF([_PKG])dnl
  165. AS_VAR_POPDEF([_DEF])dnl
  166. AS_VAR_POPDEF([_OUT])dnl
  167. ],[PACKAGE="$PACKAGE"])])