Next: , Previous: , Up: Tutorial   [Contents][Index]

4.2 Adding source files to a project

Suppose we want to add extra source files to the C program used in the last section. The source files could now be the following:

hello.c:

#include "message.h"

int
main (void)
{
  message ();
}

message.c:

#include <stdio.h>

void
message (void)
{
  printf ("hello, world\n");
}

message.h:

void message (void);

To add these files so the build system knows about them, edit Makefile.am to look like the following:

AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=hello
hello_SOURCES=hello.c message.c message.h

As long as you have already run the configure script, ‘make’ will rebuild Makefile.in and Makefile from the new contents of Makefile.am, and rebuild hello using the new source files. make does this because the source files are newer than the hello executable file that depends upon them.