4.4. Dependencies

4.4.1. Automatic dependencies

By default, SCons assumes that a target file has automatic dependencies on the:

tool used to build the target file
contents of the input files
command line used to build the target file

If any of these changes, the target file will be rebuilt.

4.4.2. Implicit dependencies

Additionally, SCons can scan the contents of files for implicit dependencies on other files. For example, SCons will scan the contents of a .c file and determine that any object created from it is dependent on any .h files specified via #include. SCons, therefore, "does the right thing" without needing to have these dependencies listed explicitly:

	% cat Construct
	env = Environment()
	env.Program('hello', 'hello.c')
	% cat hello.c
	#include "hello_string.h"
	main()
	{
	        printf("%s\n", STRING);
	}
	% cat > hello_string.h
	#define STRING  "Hello, world!\n"
	% scons .
	gcc -c hello.c -o hello.o
	gcc -o hello hello.c
	% ./hello
	Hello, world!
	% cat > hello_string.h
	#define STRING  "Hello, world, hello!\n"
	% scons .
	gcc -c hello.c -o hello.o
	gcc -o hello hello.c
	% ./hello
	Hello, world, hello!
	%
	

4.4.3. Ignoring dependencies

Undesirable automatic dependencies or implicit dependencies may be ignored:

	env.Program(target = 'bar', source = 'bar.c')
	env.Ignore('bar', '/usr/bin/gcc', 'version.h')
	

In the above example, the bar program will not be rebuilt if the /usr/bin/gcc compiler or the version.h file change.

4.4.4. Explicit dependencies

Dependencies that are unknown to SCons may be specified explicitly in an SCons configuration file:

	env.Depends(target = 'output1', dependency = 'input_1 input_2')
	env.Depends(target = 'output2', dependency = ['input_1', 'input_2'])
	env.Depends(target = 'output3', dependency = ['white space input'])

	env.Depends(target = 'output_a output_b', dependency = 'input_3')
	env.Depends(target = ['output_c', 'output_d'], dependency = 'input_4')
	env.Depends(target = ['white space output'], dependency = 'input_5')
	

Just like the target keyword argument, the dependency keyword argument may be specified as a string of white-space separated file names, or as an array.

A dependency on an SCons configuration file itself may be specified explicitly to force a rebuild whenever the configuration file changes:

	env.Depends(target = 'archive.tar.gz', dependency = 'SConstruct')