Chapter 3. Less Simple Things to Do With Builds
Prev |  | Next

## Chapter 3. Less Simple Things to Do With Builds

Of course, most builds are more complicated than in the previous chapter. In this chapter, you will learn about builds that incorporate multiple source files, and then about building multiple targets that share some source files.

## 3.1. Specifying the Name of the Target (Output) File

You've seen that when you call the `Program` builder method, it builds the resulting program with the same base name as the source file. That is, the following call to build an executable program from the `hello.c` source file will build an executable program named `hello` on POSIX systems, and an executable program named `hello.exe` on Windows systems:

    Program('hello.c')

If you want to build a program with a different base name than the base of the source file name (or even the same name), you simply put the target file name to the left of the source file name:

    Program('new_hello', 'hello.c')

SCons requires the target file name first, followed by the source file name, so that the order mimics that of an assignment statement in most programming languages, including Python: `"target = source files"`. For an alternative way to supply this information, see Section 3.6, “Keyword Arguments”.

Now SCons will build an executable program named `new_hello` when run on a POSIX system:

    % scons -Q
    cc -o hello.o -c hello.c
    cc -o new_hello hello.o

And SCons will build an executable program named `new_hello.exe` when run on a Windows system:

    C:\>scons -Q
    cl /Fohello.obj /c hello.c /nologo
    link /nologo /OUT:new_hello.exe hello.obj
    embedManifestExeCheck(target, source, env)

Prev |  | Next
2.6. Making the SCons Output Less Verbose | Home | 3.2. Compiling Multiple Source Files