remake-gnulib-remove-header.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 C header "guarded" by AC_SUBST'd variables
  17. # is not needed anymore, or when it's needed again.
  18. # This test requires some user-level machinery, overlaps with other tests,
  19. # and is not strictly necessary per se, but it exercises a real, important
  20. # use case (from gnulib, see:
  21. # <http://lists.gnu.org/archive/html/bug-gnulib/2011-04/msg00005.html>
  22. # for more info).
  23. required=cc
  24. . test-init.sh
  25. cat >> configure.ac <<'END'
  26. AC_CONFIG_HEADERS([config.h])
  27. AC_PROG_CC
  28. MY_MACROS
  29. AC_OUTPUT
  30. END
  31. cat > Makefile.am <<'END'
  32. ACLOCAL_AMFLAGS = -I .
  33. noinst_PROGRAMS = foo
  34. foo_SOURCES = foo.c
  35. BUILT_SOURCES = $(STDIO_H)
  36. if REPLACE_STDIO_H
  37. stdio.h: stdio.in.h $(top_builddir)/config.status
  38. cp $(srcdir)/stdio.in.h $@
  39. else
  40. stdio.h: $(top_builddir)/config.status
  41. rm -f $@
  42. endif
  43. MOSTLYCLEANFILES = stdio.h
  44. END
  45. cat > macros.m4 <<'END'
  46. AC_DEFUN([MY_MACROS], [
  47. override_stdio=:
  48. if $override_stdio; then
  49. STDIO_H=stdio.h
  50. use_dummies=1
  51. else
  52. STDIO_H=
  53. use_dummies=0
  54. fi
  55. AC_SUBST([STDIO_H])
  56. AC_DEFINE_UNQUOTED([USE_DUMMIES], [$use_dummies],
  57. [Whether to use dummy types.])
  58. AM_CONDITIONAL([REPLACE_STDIO_H], [test -n "$STDIO_H"])
  59. ])
  60. END
  61. cat > stdio.in.h <<'END'
  62. typedef struct dummyfile { void *p; } DUMMYFILE;
  63. END
  64. cat > foo.c <<'END'
  65. #include <config.h>
  66. #include <stdio.h>
  67. #if USE_DUMMIES
  68. DUMMYFILE *f;
  69. #else
  70. FILE *f;
  71. #endif
  72. int main () { return 0; }
  73. END
  74. $ACLOCAL -I .
  75. $AUTOHEADER
  76. $AUTOMAKE
  77. $AUTOCONF
  78. for vpath in : false; do
  79. if $vpath; then
  80. mkdir build
  81. cd build
  82. srcdir=..
  83. else
  84. srcdir=.
  85. fi
  86. # Do not reject slow dependency extractors: we need dependency tracking.
  87. $srcdir/configure --enable-dependency-tracking
  88. if $FGREP 'depmode=none' Makefile; then
  89. skip_ "automatic dependency tracking couldn't be activated"
  90. fi
  91. $MAKE
  92. ls -l
  93. test -f stdio.h
  94. # Simulate that we don't need our custom stdio.h anymore.
  95. $sleep
  96. sed -e 's/^\( *override_stdio\)=.*$/\1=false/' $srcdir/macros.m4 > t
  97. diff $srcdir/macros.m4 t && fatal_ "failed to edit macros.m4"
  98. mv -f t $srcdir/macros.m4
  99. using_gmake || $MAKE Makefile
  100. $MAKE
  101. ls -l
  102. test ! -e stdio.h
  103. # And now simulate that we want our custom stdio.h back.
  104. $sleep
  105. sed -e 's/^\( *override_stdio\)=.*$/\1=:/' $srcdir/macros.m4 > t
  106. diff $srcdir/macros.m4 t && fatal_ "failed to edit macros.m4"
  107. mv -f t $srcdir/macros.m4
  108. using_gmake || $MAKE Makefile
  109. $MAKE
  110. ls -l
  111. test -f stdio.h
  112. $MAKE distclean
  113. cd $srcdir
  114. done
  115. :