NAME

mfg - simple template-based makefile generator


SYNOPSIS

mfg
[-lnvhV] [-c config-file] [-f template] [-I directory] [-o output] [--help] [--version] target-file [source-file ...]


DESCRIPTION

mfg is a fairly simple (template-driven) makefile generator. It tries to `guess' (from its configuration file) all necessary steps to create the specified target-file from the given set of source-files. It will then create a makefile performing these steps using one of the provided template files. It can also be used on an already created makefile to update the file name lists or dependencies. Read the section Template Files below for a list of provided makefile templates and information on how to write your own.

mfg is not intended to be a replacement for automake (in fact, mfg is older than automake). automake is a rather complex tool for creating equally complex makefiles, while mfg is intended for small projects where the full functionality of automake is not required and `human readable' makefiles are more important.

Options

mfg currently supports the following options:

-c config-file
Read the configuration data from the given config-file. mfg will look for this file in the list of directories specified by the MFGPATH environment variable (see ENVIRONMENT below). In particular, it will not use a file from the current directory unless MFGPATH explicitly contains `.'. The name of the default configuration file is `config'.

-f template
Use the specified template when creating a new makefile. mfg will look for a template file with this name in the directories specified by the MFGPATH environment variable (see below). The default template is `prog', which can be used for building a C or C++ program.

Note that this template file will only be used if a makefile is created for the first time (i.e. the output file does not exist). If the output file already exists, it will be used as the template for the new makefile instead and this option has no effect.

-I directory
Add this directory to the front of the list of directories that are searched for included files when calculating dependencies. The initial value of the search path is determined by the environment variable MFG_INCLUDE_PATH (see below). If more than one -I option is present, the directories are scanned in left-to-right order.

-l
Leave long lines (i.e. longer than 80 characters) in the created makefile as is. By default, mfg will try to split long output lines and adds all necessary line continuation characters.

-n
Directly overwrite the output file without making an intermediate backup (while constructing the new makefile). Note that the backup file will be deleted automatically if the new makefile was created successfully. You need to specify this option if the output file is a link and you want to preserve the link.

-o output-file
Set the name of the output file that will be created. The default output file name is `Makefile', unless the file `makefile' in the current directory exists, in which case `makefile' is used in preference, as does make(1). If this file already exists, it will also be used as the template file, regardless of any -f option (`update mode').

-v
Print a lot of (really strange) debug output while the program is running. Giving this option multiple times increases the amount of debug output.

-h, --help
Print a short help text to the standard output and exit immediately. The help text contains a short description of all available options.

-V, --version
Print the version number of mfg, some compilation options and copyright information to the standard output and exit immediately.

Configuration Files

mfg has no built-in magic about the types of files referenced in the generated makefiles. All information about the list of known file types, and which files can be created by applying makefile rules, is defined in its configuration file (which is read automatically on program startup).

The format of such a configuration file is structurally similar to that of a makefile, the exact meaning of the contents is radically different, however. You may split a long line by inserting a backslash followed by a newline, as usual. A configuration file may contain three kinds of things:

A typical configuration file for mfg (for C, C++, Objective-C and Java source code) might look like this:

    HEADERS = %.h
    SOURCES = %.c %.cc %.m %.java
    CLASSES = %.class
    OBJECTS = %.o

    %.c:    %.o     ; "'_\__/**/
            "#include", "\"", "\""

    %.cc:   %.o     ; "'_\///**/
            "#include", "\"", "\""

    %.m:    %.o     ; "'_\///**/
            "#include", "\"", "\""
            "#import", "\"", "\""

    %.java: %.class

Template Files

For each different type of makefile that mfg can create for you, it needs to have a `template' file (basically a makefile fragment) that contains targets, implicit rules and variable definitions specific to this particular project type. A template for a `C library' makefile may define rules to compile C source code files, while a template for a `LaTeX document' makefile may instead provide rules to process LaTeX input into various output formats.

A template file for mfg is in fact nothing more that just a makefile fragment (inserted verbatim into the generated output), that may use all the variables defined in the configuration file as well as the two special variables `TARGET' and `CLEAN'. `TARGET' is the name of the target file given on the command line when mfg was run to create the makefile. `CLEAN' is the list of intermediate files that can be recreated by applying one or more makefile rules. Typical examples for this include linker object files or a DVI typesetting file.

A simple template for Java might look similar to this:

    CLASSPATH =     .
    JAVA =          java -classpath $(CLASSPATH)
    JAVAC =         javac -classpath $(CLASSPATH)
    JAVADOC =       javadoc -classpath $(CLASSPATH)
    JFLAGS =        -g# -O

    .SUFFIXES:      .java .class
    .java.class:
                    $(JAVAC) $(JFLAGS) $<

    $(TARGET):      $(CLASSES)

    clean:
                    $(RM) $(CLEAN)

Finally, here is a list of all template files currently included in the standard distribution of mfg:

aclib
C, C++ or Objective-C library (using autoconf)

aclibtool
C, C++ or Objective-C library (using autoconf and libtool)

acmany
set of C, C++ or Objective-C programs (using autoconf)

acprog
C, C++ or Objective-C program (using autoconf)

gslib
Objective-C library (using the GNUstep makefile package), this requires the `gsconfig' configuration file

gstool
Objective-C program (using the GNUstep makefile package), this requires the `gsconfig' configuration file

java
Java `program' (i.e. a set of class files)

latex
set of LaTeX documents (can produce DVI, PS or PDF)

lib
C, C++ or Objective-C library

libtool
C, C++ or Objective-C library (using libtool)

many
set of C, C++ or Objective-C programs

prog
C, C++ or Objective-C program (this is the default template)


EXAMPLES

mfg foobar *.[ch]

Creates a makefile to build the target foobar from all C source and header files in the current directory.


ENVIRONMENT

mfg recognizes these environment variables, if set:

MFGPATH
search path for configuration and template files (the default is typically `~/.mfg:/usr/share/mfg:.', but this can be changed at compilation time)

MFG_INCLUDE_PATH
search path for included files (when calculating dependencies using the internal algorithm), the default value is `.:include:../include'

HOME
to find the user's home directory


FILES

/usr/share/mfg
contains all the default configuration files and makefile templates


BUGS

The configuration file syntax for defining the rules used for automatic dependency calculation is currently very clumsy and should be changed. It is not much more than a quick hack to provide a built-in mechanism for dependency calculation that is platform independent (i.e. does not rely on external programs).


HISTORY

mfg version 1 was the result of my laziness in doing programming assignments during the summer of 1993. It has been completely rewritten for version 2 in 1995. The original design was inspired by the mmm(1) tool for creating makefiles in Ulm's Modula-2 System m2c.


SEE ALSO

make(1), autoconf(1), automake(1), libtool(1)


AUTHOR

Elmar Ludwig < elmar@informatik.uni-osnabrueck.de >