# This will work.
%.h: %.my-hdr
$(preprocess-header) $< >$@
- foo_SOURCES = foo.c
+ foo_SOURCES = foo.c foo.h
EXTRA_DIST = foo.my-hdr
BUILT_SOURCES = foo.h
* The Automake-generated clean targets do not exit successfully anymore if
an error occurs while removing a file or directory.
+* The semantic of $(BUILT_SOURCES) support has been slightly altered; now,
+ the files listed in $(BUILT_SOURCES) will be built not only before the
+ "all", "check" or "install" targets, but before *any* target.
+
-----
Copyright (C) 2012 Free Software Foundation, Inc.
.PHONY: all-recursive
endif
-all-am: all-local %ALL-DEPS%
-
-# We need to make sure config.h is built before we recurse.
-# We also want to make sure that built sources are built
-# before any ordinary 'all' targets are run.
-ifeq ($(strip %LOCAL-HEADERS% $(BUILT_SOURCES)),)
-all: $(if $(SUBDIRS),all-recursive,all-am)
+# We need to make sure $(BUILT_SOURCES) files are built before
+# any "ordinary" target (all, check, install, ...) is run.
+# Ditto for config.h (or files specified in AC_CONFIG_HEADERS).
+# But of course, we shouldn't attempt to build any of them when
+# running in dry mode.
+am.built-early = %LOCAL-HEADERS% $(BUILT_SOURCES)
+ifeq ($(am__make_dryrun),true)
+# A trick to make the "make -n" output more useful, albeit not
+# completely accurate.
+all check install: | $(am.built-early)
else
-all: %LOCAL-HEADERS% $(BUILT_SOURCES)
- $(MAKE) $(if $(SUBDIRS),all-recursive,all-am)
+$(foreach x,$(am.built-early),$(eval -include .am/built-sources/$(x)))
+.am/built-sources/%: | %
+ @$(am__ensure_target_dir_exists)
+ @touch $@
endif
+
+all-am: all-local %ALL-DEPS%
+all: $(if $(SUBDIRS),all-recursive,all-am)
$(if %CHECK-DEPS%,$(MAKE) %CHECK-DEPS%,@:)
$(MAKE) %CHECK-TESTS% check-local
-# Handle recursion. We have to honor BUILT_SOURCES like for 'all:'.
-ifdef BUILT_SOURCES
-check: $(BUILT_SOURCES)
- $(MAKE) $(if $(SUBDIRS),check-recursive,check-am)
-else
check: $(if $(SUBDIRS),check-recursive,check-am)
-endif
uninstall: uninstall-am
endif
-ifdef BUILT_SOURCES
-install: $(BUILT_SOURCES)
- $(MAKE) $(if $(SUBDIRS),install-recursive,install-am)
-else
install: $(if $(SUBDIRS),install-recursive,install-am)
-endif
.PHONY: install-am
install-am: all-am
BUILT_SOURCES = foo.h
foo.h:
echo \#define FOO_DEFINE 1 >$@
+CLEANFILES = $(BUILT_SOURCES)
END
cat > lib/foo.c << 'END'
#include <foo.h>
-int foo () { return !FOO_DEFINE; }
+int foo (void) { return !FOO_DEFINE; }
END
./configure
$MAKE
+$MAKE distcheck
:
stdio.h: stdio.in.h $(top_builddir)/config.status
cp $(srcdir)/stdio.in.h $@
else
-stdio.h: $(top_builddir)/config.status
+.PHONY: stdio.h
+stdio.h:
rm -f $@
endif
MOSTLYCLEANFILES = stdio.h
cat > Makefile.am << 'END'
noinst_PROGRAMS = zardoz
-nodist_zardoz_SOURCES = foo.c
+nodist_zardoz_SOURCES = foo.c bar.h
EXTRA_DIST = bar.my-h foo.my-c
BUILT_SOURCES = bar.h
%.c: %.my-c
headers='parse1.h p2-parse2.h parse3.h parse4.h'
-# Check that we remake only the necessary headers.
-
-rm -f $headers
-$MAKE parse1.h
-test -f parse1.h
-test ! -e p2-parse2.h
-test ! -e parse3.h
-test ! -e parse4.h
-
-rm -f $headers
-$MAKE p2-parse2.h
-test ! -e parse1.h
-test -f p2-parse2.h
-test ! -e parse3.h
-test ! -e parse4.h
-
-rm -f $headers
-$MAKE parse3.h
-test ! -e parse1.h
-test ! -e p2-parse2.h
-test -f parse3.h
-test ! -e parse4.h
-# Since we declared parse3.h into $(p3_SOURCES), make should be
-# able to rebuild it automatically before remaking 'p3'.
-rm -f $headers
-$MAKE clean-p3
-test ! -e parse3.h # Sanity check.
-$MAKE build-p3
-test -f parse3.h
-
-$MAKE
-
-rm -f $headers
-$MAKE parse4.h
-test ! -e parse1.h
-test ! -e p2-parse2.h
-test ! -e parse3.h
-test -f parse4.h
-
-# Now remake all the headers together.
-
rm -f $headers
$MAKE $headers
-test -f parse1.h
-test -f p2-parse2.h
-test -f parse3.h
-test -f parse4.h
+for h in $headers; do test -f $h; done
# Most headers should be remade by "make all".
test -f parse1.h
test -f p2-parse2.h
test -f parse3.h
-# parse4.h is not declared in any *_SOURCES variable, nor #included
-# by any C source file, so it shouldn't be rebuilt by "make all".
+# parse4.h is not declared in any *_SOURCES variable, nor in
+# BUILT_SOURCES, nor #included by any C source file, so it
+# shouldn't be rebuilt by "make all".
test ! -e parse4.h
:
# Minimal checks about recovering from header removal.
rm -f p.h parse.hh parse3.hxx
- $run_make p.h parse.hh
+ $run_make
$debug_info
test -f p.h
test -f parse.hh
- test ! -e parse3.hxx
- $run_make
- $debug_info
test -f parse3.hxx
cd $srcdir