2
0

remake-gnulib-add-header.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 C header "guarded" by AC_SUBST'd
  17. # variables is added.
  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_CONFIG_HEADERS([config.h])
  26. AC_PROG_CC
  27. MY_MACROS
  28. AC_OUTPUT
  29. END
  30. cat > Makefile.am <<'END'
  31. ACLOCAL_AMFLAGS = -I .
  32. noinst_PROGRAMS = foo
  33. foo_SOURCES = foo.c
  34. BUILT_SOURCES = $(STDIO_H)
  35. stdio.h: stdio.in.h
  36. cp $(srcdir)/stdio.in.h $@
  37. MOSTLYCLEANFILES = stdio.h
  38. EXTRA_DIST = stdio.in.h
  39. check-local:
  40. ls -l . $(srcdir)
  41. if test -n '$(STDIO_H)'; then \
  42. test -f stdio.h || exit 1; \
  43. else \
  44. test ! -f stdio.h || exit 1; \
  45. fi
  46. END
  47. cat > macros.m4 <<'END'
  48. AC_DEFUN([MY_MACROS], [
  49. override_stdio=false
  50. if $override_stdio; then
  51. STDIO_H=stdio.h
  52. use_dummies=1
  53. else
  54. STDIO_H=
  55. use_dummies=0
  56. fi
  57. AC_SUBST([STDIO_H])
  58. AC_DEFINE_UNQUOTED([USE_DUMMIES], [$use_dummies],
  59. [Whether to use dummy types.])
  60. ])
  61. END
  62. cat > stdio.in.h <<'END'
  63. typedef struct dummyfile { void *p; } DUMMYFILE;
  64. END
  65. cat > foo.c <<'END'
  66. #include <config.h>
  67. #include <stdio.h>
  68. #if USE_DUMMIES
  69. DUMMYFILE *f;
  70. #else
  71. FILE *f;
  72. #endif
  73. int main () { return 0; }
  74. END
  75. $ACLOCAL -I .
  76. $AUTOHEADER
  77. $AUTOMAKE
  78. $AUTOCONF
  79. ./configure
  80. $MAKE
  81. ls -l
  82. test ! -e stdio.h
  83. # Also try our build rules in a VPATH build.
  84. $MAKE distcheck
  85. # No need to sleep here: "./configure" and "make distcheck" above
  86. # have already slept enough.
  87. sed -e 's/^\( *override_stdio\)=.*$/\1=:/' macros.m4 > t
  88. mv -f t macros.m4
  89. using_gmake || $MAKE Makefile
  90. $MAKE
  91. ls -l
  92. test -f stdio.h
  93. # Also try our build rules in a VPATH build.
  94. $MAKE distcheck
  95. :