In a directory containing source that gets built into a program (as
opposed to a library or a script), the PROGRAMS
primary is used.
Programs can be installed in bindir
, sbindir
,
libexecdir
, pkglibdir
, or not at all (noinst
).
They can also be built only for make check
, in which case the
prefix is check
.
For instance:
bin_PROGRAMS = hello
In this simple case, the resulting Makefile.in
will contain code
to generate a program named hello
.
Associated with each program are several assisting variables which are named after the program. These variables are all optional, and have reasonable defaults. Each variable, its use, and default is spelled out below; we use the "hello" example throughout.
The variable hello_SOURCES
is used to specify which source files
get built into an executable:
hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
This causes each mentioned .c
file to be compiled into the
corresponding .o
. Then all are linked to produce hello
.
If hello_SOURCES
is not specified, then it defaults to the single
file hello.c
; that is, the default is to compile a single C file
whose base name is the name of the program itself. (This is a terrible
default but we are stuck with it for historical reasons.)
Multiple programs can be built in a single directory. Multiple programs
can share a single source file, which must be listed in each
_SOURCES
definition.
Header files listed in a _SOURCES
definition will be included in
the distribution but otherwise ignored. In case it isn't obvious, you
should not include the header file generated by configure
in a
_SOURCES
variable; this file should not be distributed. Lex
(.l
) and Yacc (.y
) files can also be listed; see Yacc and Lex.