'\"macro stdmacro
.if n .pH g8.mk @(#)mk	40.5
.\" Copyright 1989 AT&T
.nr X
.if \nX=0 .ds x} mk 8 "" "\&"
.if \nX=1 .ds x} mk 8 ""
.if \nX=2 .ds x} mk 8 "" "\&"
.if \nX=3 .ds x} mk "" "" "\&"
.TH \*(x}
.SH NAME
\f4mk\f1 \- remake the binary system and commands from source code
.SH DESCRIPTION
All source code for the
.SM UNIX
system is distributed in the
directory \f4/usr/src\f1.
The directory tree rooted at \f4/usr/src\f1 includes source code
for the operating system, libraries,
commands, miscellaneous data files necessary for the system
and procedures to transform this source code into an executable system.
.PP
Within the \f4/usr/src\f1 directory are the
\f4cmd\f1, \f4lib\f1, \f4uts\f1, \f4head\f1,
and \f4stand\f1 directories, as well as commands to remake
the parts of the system found under each of these sub-directories.
These commands are named \f4:mk\f1
and \f4:mk\f2dir\f1 where \f2dir\f1 is the
name of the directory to be recreated.
Each of these \f4:mk\f2dir\f1 commands rebuilds all or part of the directory
it is responsible for.
The \f4:mk\f1 command runs each of the other commands in order and
thus recreates the whole system.
The \f4:mk\f1 command is distributed only to source code licensees.
.PP
Each command, with its associated directory, is described below.
.TP 12 
\f4:mklib\fP
The \f4lib\f1 directory contains the source code for the system libraries.
The most important of these is the C library.
Each library is in its own sub-directory.
If any arguments are specified on the \f4:mklib\f1 command line
then only the given libraries are rebuilt.
The argument \f4\\*\fP causes it to rebuild all libraries found under the \f4lib\f1 directory.
.TP
\f4:mkhead\fP
The \f4head\f1 directory contains the source code versions of the header files
found in the \f4/usr/include\f1 directory.
The \f4:mkhead\f1 command installs the header files given as arguments.
The argument \f4\\*\fP causes it to install all header files.
.TP
\f4:mkuts\fP
The \f4uts\f1 directory contains the source code for the
.SM UNIX
Operating System.
The \f4:mkuts\f1 command takes no arguments and invokes a series of makefiles
that recreates the operating system.
.IP
Associated with the operating system is a set of header files that
describe the user interface to the operating system.
The source for these header files is found in a sub-directory
within the \f4uts\f1 directory tree.
The user-accessible versions of these header files
are found in the \f4/usr/include/sys\f1 directory.
The \f4:mksyshead\f1 command installs these header files
into the \f4/usr/include/sys\f1 directory.
.TP
\f4:mkstand\fP
The \f4stand\f1 directory contains stand-alone commands and boot programs.
The \f4:mkstand\f1 command rebuilds and installs these programs.
Note that these stand-alone programs are only applicable to the
.SM DEC
processors and are not built for any other machine.
.TP
\f4:mkcmd\fP
The \f4cmd\f1 directory contains the source code for
all the commands available on the system.
There are two types of entries within the \f4cmd\f1 directory:
commands whose source code consists of only one file
with one of the following suffixes: \f4.l\f1, \f4.y\f1, \f4.c\f1, \f4.s\f1, \f4.sh\f1,
or a sub-directory that contains the multiple source files that
comprise a particular command or subsystem.
Each sub-directory is assumed to have a makefile [see \f4make\fP(1)]
with the name \f2command\f4.mk\f1 that
takes care of creating everything associated with that
directory and its sub-directories.
.IP
The \f4:mkcmd\f1 command transforms source code into an executable command
based on a set of predefined rules.
If the \f4:mkcmd\f1 command encounters a sub-directory within the \f4cmd\f1
directory then it runs the makefile found in that sub-directory.
If no makefile is found then an error is reported.
For single-file commands, the predefined rules are dependent
on the file's suffix.
C programs (\f4.c\f1) are compiled by the C compiler
and loaded stripped with shared text.
Assembly language programs (\f4.s\f1) are assembled
and loaded stripped.
Yacc programs (\f4.y\f1) and lex programs (\f4.l\f1) are processed by
\f4yacc\fP(1) and \f4lex\fP(1) respectively, before
C compilation.
Shell programs (\f4.sh\f1) are copied to create the command.
Each of these operations leaves a command in the \f4./cmd\f1 directory which is
then installed into a user-accessible directory by using \f4/usr/sbin/install\f1.
.IP
The arguments to \f4:mkcmd\f1 are either command names
or subsystem names.
Some subsystems distributed with the
.SM UNIX
system are:
\f4acct\f1, \f4graf\f1, \f4sgs\f1, \f4sccs\f1, and \f4text\f1.
Prefacing the \f4:mkcmd\f1 command with an assignment
to the shell variable \f4$ARGS\f1 causes the indicated
components of the subsystem to be rebuilt.
.P
For example,
the entire \f4sccs\f1 subsystem can be rebuilt by:
.P
.RS
.ft 4
.nf
/usr/src/:mkcmd sccs
.fi
.ft 1
.RE
.P
while the \f4delta\fP component of \f4sccs\f1 can be rebuilt by:
.P
.RS
.ft 4
.nf
ARGS="delta" /usr/src/:mkcmd sccs
.fi
.ft 1
.RE
.P
The \f4log\fP command, which is a part of the \f4stat\f1 package,
which is itself a part of the \f4graf\f1 package, can be rebuilt by:
.P
.RS
.ft 4
.nf
ARGS="stat log" /usr/src/:mkcmd graf
.fi
.ft 1
.RE
.P
The argument \f4\\*\fP causes all commands and subsystems to be rebuilt.
.PP
Makefiles throughout the system, and particularly in the \f4cmd\f1
directory, have a standard format.
In particular, \f4:mkcmd\f1 depends on each makefile having target entries for
\f4install\fP and \f4clobber\f1.
The \f4install\fP target should cause everything over which
the makefile has jurisdiction to be built
and installed by \f4/usr/sbin/install\f1.
The \f4clobber\f1 target should cause a complete cleanup of
all unnecessary files resulting from the previous invocation.
The commands that use the \f4CLOBBER\f1 environment variable are
\f4:mkcmd\f1, \f4:mklib\f1, and \f4:mkuts\f1.  These commands
all check the \f4CLOBBER\f1 variable before executing \f4make clobber\f1.
If this variable is set to \f4OFF\f1, then \f4make clobber\f1 is
\f2not\f1 performed.  If the variable is \f2not\f1 set or is set
to anything other than \f4OFF\f1, the \f4make clobber\f1 \f2is\f1
performed.
.PP
An effort has been made to separate the creation of
a command from source and its installation on the running system.
The command \f4/usr/sbin/install\f1 is used by \f4:mkcmd\f1 and most
makefiles to install commands in standard directories on the system.
The use of \f4install\fP allows maximum flexibility in the
administration of the system.
The \f4install\fP command makes very few assumptions about where a
command is located, who owns it, and what modes are in effect.
All assumptions may be overridden on invocation of the command,
or more permanently by redefining a few variables in \f4install\fP.
The purpose of \f4install\fP is to install a new version of a command
in the same place, with the same attributes as the prior version.
.PP
In addition, the use of a separate command to perform
installation allows for the creation of test
systems in other than standard places, easy movement
of commands to balance load, and independent maintenance of
makefiles.
.SH SEE ALSO
\f4install\fP(1M)
.P
\f4lex\fP(1), \f4make\fP(1), \f4yacc\fP(1) in the \f2Programmer's Reference Manual\f1
.Ee
