The program determines what type of file it should create, by matching patterns against the name of the file you wish to create. The default patterns recognised and the file types they correspond to are given below.
-------------------------------------------------- Filename Pattern File Type -------------------------------------------------- *.h *.hh *.hxx *.hpp *.H Header file *.c *.cc *.cxx *.cpp *.C Source file makeit.mk Makeit.mk makefile Makefile Makefile --------------------------------------------------To obtain a full list of the patterns which the mksrc program understands, execute mksrc with the `-dump' option. For example:
mksrc -dumpTo create files, list the names of the files on the command line when executing mksrc. For example:
mksrc foo.hh foo.cc bar.hhThe output of the mksrc program for certain file types can be customised by providing additional options to mksrc. Options for customising the output, will always be of the form `-DVARIABLE' or `-DVARIABLE=VALUE'. For example, to create a C++ source file which includes a main() routine, you would run:
mksrc -DMAIN foo.ccA list of the variables which can be set for a particular file type, can be found by listing the `-help' option on the command line when running mksrc. For example:
mksrc -help foo.ccThis will not result in the file being created, but will display the help file associated with that type of file.
If you need to always define certain flags, you can list those options in the environment variable MKSRC_FLAGS. For example:
MKSRC_FLAGS="-DORGANISATION=\"ACME Software Corporation\""
*.h mkheader mkheader.hlpEach line in the configuration file has three fields. The first field is a wildcard pattern, that is matched against the name of the file you wish to create, to work out which program should be run to create the file. The second field is the name of the program to run, to create a file matching the pattern listed in the first field. If the name of the program is not defined using an absolute pathname, it is expected that the program resides in the same directory as the configuration file. The third field is the name of a help file, for the program listed in the second field. The help file will be displayed when the `-help' option is used, together with the name of the file you want to create. The help file will describe the various symbols which can be defined, to customise what the program listed in the second field generates. The listing of a help file in the third column is optional. Any text appearing after the character `#', is regarded as a comment, and is discarded before interpreting the line.
*.hh mkheader mkheader.hlp
*.hxx mkheader mkheader.hlp
*.hpp mkheader mkheader.hlp
*.H mkheader mkheader.hlp
*.c mksource mksource.hlp
*.cc mksource mksource.hlp
*.cxx mksource mksource.hlp
*.cpp mksource mksource.hlp
*.C mksource mksource.hlp
makeit.mk mkmakefile mkmakefile.hlp
Makeit.mk mkmakefile mkmakefile.hlp
makefile mkmakefile mkmakefile.hlp
Makefile mkmakefile mkmakefile.hlp
If you asked mksrc to create a file called `obj1.cc', it will apply the patterns listed in the first field of each line in order, until it finds one which matches. In this case, the pattern `*.cc' will match. Once mksrc has found a pattern which matches the name of the file you want to create, it will run the program listed in the second column, in this case the program called mksource. The name of the file you wish to create, along with any symbol definitions, will be passed as command line arguments to the program, when it is run by mksrc. If you asked mksrc to create more than one file, the program to create the file will be run more than once, each time being supplied a different file name.
For example, if you had originally run \code{mksrc} with the options:
mksrc -DLIBNAME=MYLIB -DDIRNAME=part1 h1.hh o1.cc o2.ccthe following commands would in turn be run by mksrc.
mkheader -DLIBNAME=MYLIB -DDIRNAME=part1 h1.cc
mksource -DLIBNAME=MYLIB -DDIRNAME=part1 o1.cc
mksource -DLIBNAME=MYLIB -DDIRNAME=part1 o2.cc
*.y mkyaccSo that mksrc can find your configuration file and the associated programs, you must set the environment variable MKSRC_PATH to the name of the directory containing your configuration file. If you need to specify more than one directory, each directory should be separated by a `:'. For example:
*.l mklex
MKSRC_PATH="$HOME/lib:/home/projects/simulator/mksrc"You do not need to define the location of the default configuration file; it will be searched automatically, after all the other configuration files have been read. If there is a file called `mksrc.cf' in the directory in which you run mksrc, it will be read before all other files, even if that directory isn't listed in the MKSRC_PATH variable.
When mksrc is run, it will try matching the patterns in each of the configuration files against the name of the file you wish to create. Once a pattern matching the name of the file has been found, the search will stop and the program for that pattern will be used to generate the file. If you have defined a pattern, which is the same as one which appears in a later file, your pattern will override the other pattern. Therefore, you could provide your own program for creating header files. For example:
*.h mymkheader
ose/*.h mkheader mkheader.hlpThe tag in this case is `ose'. It is placed before the pattern, and separated from it by a `/' character. The tag has the effect of grouping the patterns into a scope. The patterns will only be matched against the name of the file you want to create, when you tell mksrc to search the scope defined by that tag. For example, if you had overridden the pattern `*.h', you can still access the pattern provided in the default configuration by running mksrc as follows:
ose/*.hh mkheader mkheader.hlp
ose/*.hxx mkheader mkheader.hlp
ose/*.hpp mkheader mkheader.hlp
ose/*.H mkheader mkheader.hlp
ose/*.c mksource mksource.hlp
ose/*.cc mksource mksource.hlp
ose/*.cxx mksource mksource.hlp
ose/*.cpp mksource mksource.hlp
ose/*.C mksource mksource.hlp
ose/makeit.mk mkmakefile mkmakefile.hlp
ose/Makeit.mk mkmakefile mkmakefile.hlp
ose/makefile mkmakefile mkmakefile.hlp
ose/Makefile mkmakefile mkmakefile.hlp
mksrc -group ose header.hWhen you define your own patterns, which override the defaults, you should add additional definitions which add them to a specific group. This way, if your definitions are later overridden, you can still access them. For example:
*.h mymkheaderGrouping patterns using a tag, is also useful if you need to use a different format for a file at different times. For example, if you use a number of different graphics libraries, where the structure of the main() program loop for each is different, you could include the following in your configuration file.
mystuff/*.h mymkheader
xmain/*.c mkxmainprogram # creates Xt main loop
ivmain/*.c mkivmainprogram # creates InterViews main loop
#! /bin/sh
# Set some defaults.
AUTHOR=${MKSRC_AUTHOR-"???"}
ORGANISATION=${ORGANISATION-"WIZZ BANG SOFTWARE"}
YEAR=${YEAR-19`date +%y`}
FILENAME=""
# Usage message.
USAGE()
{
P=`basename $0`
echo "Usage: $P [ -DNAME -DNAME=VALUE ] filename" 1>&2
exit 1
}
# Parse the command line.
while test "$#" != 0
do
case "$1" in
-D*=*)
EVAL="`echo $1 | sed -e `s/^-D//' \
-e `s/=/=\"/' -e `s/$/\"/'`"
eval ${EVAL}
;;
-D*)
EVAL="`echo $1 | sed -e `s/^-D//'`"
eval ${EVAL}=1
;;
-*)
USAGE
;;
*)
if test "${FILENAME}" != ""
then
USAGE
fi
FILENAME=$1
;;
esac
shift
done
# Check that a filename has been given and that the file
# doesn't exist.
if test "${FILENAME}" = ""
then
USAGE
fi
if test -f "${FILENAME}"
then
echo "`basename $0`: ${FILENAME} already exists" 1>&2
exit 1
fi
# Do it.
echo "`basename $0`: ${FILENAME}"
cat >> ${FILENAME} << EOT
# Copyright ${YEAR} ${ORGANISATION}
# Makeit Initialisation.
MODULES := c cc ose
include makeit/init.mk
# Module Initialisation/Definitions.
SUBDIRS :=
PROGRAMS :=
EXCLUDE :=
NONLIBSRC :=
CPPFLAGS :=
CFLAGS :=
C++FLAGS :=
LDFLAGS :=
LDLIBS :=
include makeit/modules.mk
# Additional Dependencies/Rules.
EOT