MKMF(1)

NAME
mkmf - make a makefile

SYNOPSIS
mkmf [-acdeilLS] [-f makefile] [-F template] [-M language] [macroname=value ...]

DESCRIPTION
mkmf creates a makefile that informs the make(1) command how to construct and maintain programs and libraries. After gathering up all source code file names in the current working directory and inserting them into the makefile, mkmf scans source code files for included files and generates dependency information that is appended to the makefile. Source code files are identified by their file name suffixes. mkmf recognizes the following suffixes:

    .c  C
    .C  C++
    .f  Fortran
    .h  Include files
    .i  Pascal include files
    .l  Lex or Lisp
    .o  Object files
    .p  Pascal
    .r  Ratfor
    .s  Assembler
    .y  Yacc

mkmf checks for an existing makefile before creating one. If no -f option is present, mkmf tries the makefiles makefile and Makefile, respectively.

After the makefile has been created, arbitrary changes can be made using a text editor. mkmf can also be used to re-edit the macro definitions in the makefile, regardless of changes that may have been made since it was created.

By default, mkmf creates a program makefile. To create a makefile that handles libraries, either the -l or -L options must be used.

  Make Requests
Given a makefile created by mkmf, make recognizes the following requests:

    all Compile and load a program or library.

    clean
        Remove all object and core files.

    clobber
        Remove all files that can be regenerated.

    depend
        Update included file dependencies in a makefile.

    echo
        List the names of the source code files on standard output.

    extract
        Extract all object files from the library and place them in the same directory as the source code files. The library is not altered.

    index
        Print an index of functions on standard output.

    install
        Compile and load the program or library and move it to its destination directory.

    print
        Print source code files on standard output.

    tags
        Create a tags file for the ex(1) editor, for C, Pascal, and Fortran source code files.

Several requests can be given simultaneously. For example, to (1) compile and link a program, (2) move the program to its destination directory, and (3) remove any unnecessary object files, use:

    make install clean

  Macro Definitions
mkmf understands the following macro definitions:

CFLAGS
    C compiler flags. After searching for included files in the directory currently being processed, mkmf searches in directories named in -I compiler options and then in the /usr/include directory.

COMPILESYSTYPE
    Location of /usr/include. If the COMPILESYSTYPE macro or environment variable is defined, mkmf searches for included files in /$COMPILESYSTYPE/usr/include instead of /usr/include.

CXXFLAGS
    C++ compiler flags. After searching for included files in the directory currently being processed, mkmf searches in directories named in -I compiler options and then in the /usr/include/CC directory, followed by the /usr/include directory.

C++FLAGS
    C++ compiler flags. After searching for included files in the directory currently being processed, mkmf searches in directories named in -I compiler options and then in the /usr/include/CC directory, followed by the /usr/include directory.

CCFLAGS
    C++ compiler flags. After searching for included files in the directory currently being processed, mkmf searches in directories named in -I compiler options and then in the /usr/include/CC directory, followed by the /usr/include directory.

DEST
    Directory where the program or library is to be installed.

EXTHDRS
    List of included files external to the current directory. mkmf automatically updates this macro definition in the makefile if dependency information is being generated.

FFLAGS
    Fortran compiler flags. After searching for included files in the directory currently being processed, mkmf searches in directories named in -I compiler options, then in the /usr/include directory.

HDRS
    List of included files in the current directory. mkmf automatically updates this macro definition in the makefile.

INSTALL
    Installation program name.

LD  Link editor name.

LDFLAGS
    Link editor flags. Before searching for libraries in the /lib and /usr/lib directories, mkmf searches for libraries in directories named by -L link editor options.

LIBRARY
    Library name. This macro also implies the -l option.

LIBS
    List of libraries needed by the link editor to resolve external references. Since executable files depend on libraries, mkmf expands each library -lx option to /lib/libx.a or /usr/lib/libx.a. If the LPATH environment variable is defined, it should contain a colon-separated list of directories to search instead of the default library directories.

MAKEFILE
    Makefile name.

OBJS
    List of object files. mkmf automatically updates this macro definition in the makefile.

PROGRAM
    Program name.

SRCS
    List of source code files. mkmf automatically updates this macro definition in the makefile.

SUFFIX
    List of additional file name suffixes for mkmf to know about.

SYSHDRS
    List of included files found in the /usr/include directory hierarchy. mkmf automatically updates this macro definition in the makefile if dependency information is being generated. If SYSHDRS is omitted from the makefile, mkmf does not generate /usr/include dependencies.

VPATH
    List of source code directories separated by colons or spaces. mkmf will search for files in the current directory, and then in each of the directories defined by VPATH.

Both these and any other macro definitions already within the makefile can be replaced by definitions on the command line in the form macroname=value. For example, to change the C compiler flags and the program name, type the following line:

    mkmf "CFLAGS=-I../include -O" PROGRAM=mkmf

Note that macro definitions such as CFLAGS with blanks in them must be enclosed in double quote (") marks.

  Environment
The environment is read by mkmf. All variables are assumed to be macro definitions with the exception of HDRS, EXTHDRS, SRCS, and OBJS. Environment variables are processed after command line macro definitions and the macro definitions in a makefile. The -e option forces the environment to override the macro definitions in a makefile.

  File Name Suffixes
mkmf can recognize additional file name suffixes or ignore ones that it already recognizes by specifying suffix descriptions in the SUFFIX macro definition. Each suffix description takes the form .suffix:tI where t is a character indicating the contents of the file (s = source file, o = object file, h = header file, x = executable file) and I is an optional character indicating the include syntax for header files (C = C syntax, C++ = C syntax plus the addition of /usr/include/CC as a standard search directory, F = Fortran and Ratfor syntax, P = Pascal syntax). The following list shows the default configuration for mkmf:

    .c:sC
        C
    .C:sC++
        C++
    .f:sF
        Fortran
    .h:h
        Include files
    .i:h
        Pascal include files
    .l:sC
        Lex or Lisp
    .o:o
        Object files
    .p:sP
        Pascal
    .r:sF
        Ratfor
    .s:s
        Assembler
    .y:sC
        Yacc

For example, to change the object file suffix to .obj, undefine the Pascal include file suffix, and prevent Fortran files from being scanned for included files, the SUFFIX macro definition could be:

    SUFFIX = .obj:o .i: .f:s

  Include Statement Syntax
The syntax of include statements for C, C++, Fortran, and Pascal source code are of the form:

C/C++:
    #include "filename"
    #include <filename>
    where # must be the first non-white space character in the line.

Fortran:
    #include "filename"
    #include <filename>
    $include 'filename'$
    $INCLUDE 'filename'$
    where $ must be the first non-white space character in the line. Alternatively, the $ can be omitted if the include statement starts in column 7. In either case the trailing $ can be omitted.

Pascal:
    #include "filename"
    #include <filename>
    $include 'filename'$
    $INCLUDE 'filename'$
    where $ must be the first non-white space character in the line and the trailing $ is optional.

  User-Defined Templates

If mkmf cannot find a makefile within the current directory, it normally uses one of the standard makefile templates, C.p, C.l, or C.L, in /usr/local/lib/mkmf unless the user has alternative C.p, C.l, or C.L template files in a directory $PROJECT/lib/mkmf where $PROJECT is the absolute path name of the directory assigned to the PROJECT environment variable.

  Options
mkmf recognizes the following options:

-a  Include source files beginning with a . in the makefile.

-c  Suppress `creating makefile from ...' message.

-d  Turn off scanning of source code for include files. Old dependency information is left untouched in the makefile.

-e  Environment variables override macro definitions within makefiles.

-fmakefile
    Specify an alternative makefile file name. The default file name is Makefile.

-i  Prompt the user for the name of the program or library and the directory where it is to be installed. If a carriage-return is typed in response to each of these queries, mkmf assumes that the default program name is a.out or the default library name is lib.a, and the destination directory is the current directory.

-l  Force the makefile to be a library makefile.

-L  Force the makefile to be a library makefile containing object file names defined as library members.

-Ftemplate
    Specify an alternative makefile template path name. The path name can be relative or absolute.

-Mlanguage
    Specify an alternative language-specific makefile template. The default language is C and the corresponding program and library makefile templates are C.p, and C.l or C.L, respectively. mkmf looks for these templates in /usr/local/lib/mkmf or $PROJECT/lib/mkmf.

-S  Symbolically link source code files found in directories listed in the VPATH macro into the current directory. Additionally, if the -S option is repeated, remove any symbolic links to files in directories not listed in the VPATH macro.

DIAGNOSTICS
Exit status 0 is normal. Exit status 1 indicates an error.

WARNINGS
The name of the makefile is included as a macro definition within the makefile and must be changed if the makefile is renamed.

Generated dependency information appears after a line in the makefile beginning with ###. This line must not be removed, nor must any other information be inserted in the makefile below this line.

The name of a program or library must not conflict with any predefined target names in a makefile.

AUTHOR
Peter J. Nicklin

FILES

/usr/local/lib/mkmf/C.p
    Standard program template
/usr/local/lib/mkmf/C.l
    Standard library template
/usr/local/lib/mkmf/C.L
    Alternative library template
$PROJECT/lib/mkmf/C.p
    User-defined program template
$PROJECT/lib/mkmf/C.l
    User-defined library template
$PROJECT/lib/mkmf/C.L
    Alternative user-defined library template

SEE ALSO
ar(1), ctags(1), ld(1), make(1).

"Make - A Program for Maintaining Computer Programs", Software-Practice and Experience, Feldman, S.I., vol. 9, no. 4, pp. 255-265, April 1979.

"Automatic Generation of Make Dependencies", Software-Practice and Experience, Walden, K., vol. 14, no. 6, pp. 575-585, June 1984.