remake-gnulib-add-acsubst.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #! /bin/sh
  2. # Copyright (C) 2011-2017 Free Software Foundation, Inc.
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2, or (at your option)
  7. # any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. # Test remake rules when a new AC_SUBST'd variable is added, and C header
  17. # files are involved.
  18. # This test overlaps with others, and is not strictly necessary per se,
  19. # but it exercises a real use case (from gnulib, see:
  20. # <http://lists.gnu.org/archive/html/bug-gnulib/2011-04/msg00005.html>
  21. # for more info).
  22. required=cc
  23. . test-init.sh
  24. cat >> configure.ac <<'END'
  25. AC_PROG_CC
  26. MY_MACROS
  27. AC_OUTPUT
  28. END
  29. cat > Makefile.am <<'END'
  30. ACLOCAL_AMFLAGS = -I m4
  31. noinst_PROGRAMS = foo
  32. foo_SOURCES = foo.c
  33. BUILT_SOURCES = foo.h
  34. edit_h = sed -e 's|[@]foovar@|@foovar@|g'
  35. foo.h: foo.in.h
  36. $(edit_h) < $(srcdir)/foo.in.h > $@-t
  37. cat $@-t;: For debugging.
  38. mv -f $@-t $@
  39. EXTRA_DIST = foo.in.h
  40. MOSTLYCLEANFILES = foo.h foo.h-t
  41. END
  42. mkdir m4
  43. cat > m4/foo.m4 <<'END'
  44. AC_DEFUN([MY_MACROS], [
  45. FOO_MACRO
  46. dnl: ZAP_MACRO
  47. ])
  48. END
  49. cat > m4/bar.m4 <<'END'
  50. AC_DEFUN([FOO_MACRO], [
  51. foovar=42; AC_SUBST([foovar])
  52. dnl: barvar=47; AC_SUBST([barvar])
  53. ])
  54. END
  55. cat > foo.in.h <<'END'
  56. #define foo @foovar@
  57. END
  58. cat > foo.c <<'END'
  59. #include "foo.h"
  60. int main (void) { return 0; }
  61. typedef int checkfoo[1 - 2 * (foo != 42)];
  62. END
  63. $ACLOCAL -I m4
  64. $AUTOCONF
  65. $AUTOMAKE
  66. ./configure
  67. $MAKE
  68. : AC_SUBST @barvar@ and add it to foo.h.
  69. $sleep
  70. sed -e 's/^dnl:/ /' m4/bar.m4 > t
  71. mv -f t m4/bar.m4
  72. cat m4/bar.m4
  73. cat >> foo.in.h <<'END'
  74. #define bar @barvar@
  75. END
  76. cat >> foo.c <<'END'
  77. typedef int checkbar[1 - 2 * (bar != 47)];
  78. END
  79. cat >> Makefile.am <<'END'
  80. edit_h += -e 's|[@]barvar@|@barvar@|g'
  81. END
  82. using_gmake || $MAKE Makefile
  83. $MAKE
  84. : AC_SUBST @zapvar@ and add it to foo.h.
  85. # Do it in a slightly different way from how it was done for @barvar@.
  86. $sleep
  87. cat >> Makefile.am <<'END'
  88. edit_h += -e 's|[@]zapvar@|$(zapvar)|g'
  89. END
  90. cat >> foo.c <<'END'
  91. typedef int checkzap[1 - 2 * (zap != 163)];
  92. END
  93. sed -e 's/^dnl://' m4/foo.m4 > t
  94. mv -f t m4/foo.m4
  95. cat m4/foo.m4
  96. cat >> foo.in.h <<'END'
  97. #define zap @zapvar@
  98. END
  99. cat >> m4/bar.m4 <<'END'
  100. AC_DEFUN([ZAP_MACRO], [zapvar=163; AC_SUBST([zapvar])])
  101. END
  102. using_gmake || $MAKE Makefile
  103. $MAKE
  104. $MAKE distcheck
  105. :