digitalmars.com                        
Last update Sun Aug 19 03:11:23 2018

MAKE: Orchestrate build

Documentation for make.exe for Win32

Command line syntax

make {target} {macro=text} {switch}
Make Arguments
Argument Description
target What targets to make
macro=text Define macro to be text
-d Output debugging info
-ffile Use file instead of makefile
-f file Use file instead of makefile
-f- Read makefile from stdin
-h Print help message
-i Ignore errors from executing make rules
-l Show macro expansions in makefile
-man Open browser on this page
-n Make rules are not executed, just written to stdout
-q Return with errorlevel 1 if rules would be executed
-s Do not echo make rules
-t Just touch files

Environment Variables

make looks for the environment variable MAKEFLAGS upon startup. The string for MAKEFLAGS, if any, is parsed as if it was typed on the command line for the actual command line is parsed. For example:

SET MAKEFLAGS=CFLAGS=-D
make target

is equivalent to:

make CFLAGS=-D target

The Makefile

A makefile is a text file containing a sequence of:

If the last character on a line is a \, then the line is concatenated with the next line in the file. The \ and all immediately following spaces and tabs are removed and replaced with a single space.

Comment lines

Comment lines are lines in which the first non-blank character is a #. Comment lines are ignored. Comment lines are removed before \ line splicing is done.

Blank lines

Blank lines contain zero or more tabs or spaces. Blank lines are ignored.

Macro definition lines

Macros are defined with lines of the form:
MACRO = text
Spaces and tabs around the = are stripped. They are used:
$(MACRO)

Single character macro names do not need () when expanded. Definitions for macros are searched for in the following order:

  1. Definitions from the command line.
  2. Definitions in the makefile.
  3. Definitions from the environment.
  4. The macro is expanded to nothing.

Explicit Definition lines

target [target ...] : [dependency ...] [; rule] [# ... ]

Implicit Definition lines

.targ_ext.dep_ext : [; rule] [# ... ]

Rule lines

tab [rule flag] rule [# ...]

Predefined macros

Predefined Macros
Macro Description
$? List of dependencies that are newer than target
$** Full list of dependencies
$* Name of current target without extension
$< From name of current target, if made using a implicit rule
$@ Full target name
$$ Expand to $

Rule flags

Rules can be preceeded by one of the following characters:

Rule Flags
Flag Description
+ Force use of COMMAND.COM or CMD.EXE to execute the rule. This is useful for .BAT files
- Ignore exit status from this rule
@ Do not echo this rule when it's executed
* Use _CMDLINE environment variable to pass long command lines
~ Use _CMDLINE environment variable to pass command line

Win32 internal commands

The following commands are internal to Win32, that is, when make executes one it does so by executing CMD.EXE and passing the line to be executed to it. The internal commands are:

break,cd,chdir,cls,copy,ctty,
date,del,dir,echo,erase,exit,
if,md,mkdir,pause,
rd,rem,rmdir,ren,rename,
time,type,ver,verify,vol

Long command lines

Windows and DOS have limits on the length of a command line. Under DOS, this limit is 127. Under Win32, it varies from version to version and can depend on end user configuration. make assumes a command line limit of 996. If this limit is exceeded, and the rule is known to or flagged as accepting long command lines via the environment, the long command line is passed via the environment variable _CMDLINE. The actual command line the rule sees is @_CMDLINE. If writing programs to make use of this, use the response_expand() function in the program. To flag a rule as accepting this form, use the * rule flag. If running under a version of Windows that cannot handle 996 character command lines, use the ~ rule flag to tell make to pass the command line via _CMDLINE.

Special targets

Special Targets
Target Description
.SILENT Same as if -s was specified on command line. Do not put a : after this
.IGNORE Same as if -i was specified on command line. Do not put a : after this.
.DEFAULT Rules following this target are executed for targets that have no rules specified for them. Any dependencies listed for the .DEFAULT target are ignored

Default makefile

The default makefile (if the -f flag is not given) is "makefile".

Logging

For long and verbose makes, the output of make along with all messages can be redirected to a log file for later perusal.

make >log

Note that only stdout output of programs run by make are redirected. dmc.exe, etc. all redirect fine. masm 4.0 and earlier versions won't.

Error messages

undefined switch 'xxxx'

bad macro definition 'xxxx'

can't read makefile 'xxxx'

target must appear before commands
Can't specify rules before any targets.

unrecognized target 'xxxx'
Target was not one of .SILENT or .IGNORE.

command line too long
Rules to be executed by CMD.EXE cannot exceed 124 bytes in length.

expanded line is too long
Argument to a command exceeds 127 bytes in length.

')' expected

expecting target : dependencies
Could not decipher target line.

ambiguous implicit rule
Two implicit rules were found for the same from and to extensions.

bad syntax for implicit rule
Implicit rule syntax is of the form:
.from.to :
No dependencies are allowed for a implicit rule.

undefined macro 'xxxx'

don't know how to make 'xxxx'
The file xxxx does not exist and no rules were specified for making it.

'xxxx' not found
Could not find the command xxxx along the search path.

out of memory

Other

When a rule is executed and it returns a non-zero exit status, the message:

--- errorlevel exitstatus

is printed and make terminates (unless make was instructed to ignore the exit status).

A # indicates a comment. The rest of the line is ignored.

Home | Runtime Library | IDDE Reference | STL | Search | Download | Forums