Merge branch 'minor'
[automake.git] / t / built-sources-fork-bomb.sh
blob59ded693144ec31bf452831ada73908805bfa8f6
1 #! /bin/sh
2 # Copyright (C) 2012-2017 Free Software Foundation, Inc.
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.
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.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
17 # Due to how the handling of $(BUILT_SOURCES) is implemented in Automake-NG,
18 # a recursive make call in the recipe of any $(BUILT_SOURCES) (or of any of
19 # its prerequisites) might cause an infinite recursion (complete with fork
20 # bomb, yuck) if not handled correctly. Verify that this doesn't happen.
21 # For more background, see:
22 # <https://lists.gnu.org/archive/html/help-smalltalk/2012-08/msg00027.html>
23 # <https://lists.gnu.org/archive/html/automake-patches/2012-08/msg00052.html>
24 # Backported to improve coverage of mainline Automake.
26 required=GNUmake
27 . test-init.sh
29 echo AC_OUTPUT >> configure.ac
31 cat > Makefile.am << 'END'
32 BUILT_SOURCES = foo
33 .PHONY: build-foo
34 build-foo:
35 echo OK > foo
36 foo:
37 $(MAKE) build-foo
39 # If the bug is still present, we want this test to fail, not to actually
40 # go fork bomb and potentially crash the user machine. Take care of that.
42 is_too_deep := $(shell test $(MAKELEVEL) -lt 10 && echo no)
44 ## Extra indentation here required to avoid confusing Automake.
45 ifeq ($(is_too_deep),no)
46 # All is ok.
47 else
48 $(error ::OOPS:: Recursion too deep, $(MAKELEVEL) levels)
49 endif
50 END
52 $ACLOCAL
53 $AUTOMAKE -Wno-portability
54 $AUTOCONF
56 ./configure
58 run_make -M -- -n foo
59 test ! -f foo
60 # Guard against possible infinite recursion.
61 $FGREP '::OOPS::' output && exit 1
63 run_make -M -- foo
64 # Guard against possible infinite recursion.
65 $FGREP '::OOPS::' output && exit 1