digitalmars.com                        
Last update Mon Mar 8 17:52:42 2010
Compiler & Tools Guide

Tools
BCC
CHMOD
CL
COFF2OMF
COFFIMPLIB
DMC
DIFF
DIFFDIR
DUMP
DUMPOBJ
DUMPEXE
EXE2BIN
FLPYIMG
GREP
HC
IMPLIB
LIB
LIBUNRES
MAKE
MAKEDEP
ME
OBJ2ASM
PATCHOBJ
RC
RCC
SC
SHELL
SMAKE
TOUCH
UNMANGLE
WHEREIS


Compiling
Compiling Code
C Implementation
C++ Implementation
Language Extensions
Mixing Languages
Assembly Language
Inline Assembler
Optimizing Code
Numerics Programming
Regular Expressions
Acrtused
Pragmas
Precompiled Headers
Predefined Macros
Warning Messages
Error Messages
Runtime Messages


Linking
Optlink
Switches
Module Definition Files
Operation and Design
Error Messages


Win32 Programming
Win32 Programming


DOS and Win16
Programming

Memory Models
16 Bit Pointer Types
and Type Modifiers

Handle Pointers
DOS
DOS 32 (DOSX)
Win16
Win16 DLLs
Win16 Prolog/Epilog
Virtual Memory
For 640Kb DOS



C/C++ Extensions
Contract Programming
__debug statement
__debug declaration
Dynamic Profiling
Embedding C in HTML


Porting to DMC++
Switching to DMC++
from Microsoft
from Borland
Porting Guide



MAKE: Orchestrate build

Documentation for make.exe for Win32

Command line syntax

	make {target} {macro=text} {switch}
target
What targets to make
macro=text
Define macro to be text
switch
-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.
-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:
  • Comment lines
  • Blank lines
  • Macro definition lines
  • Explicit definition lines
  • Implicit definition lines
  • Rule lines
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

$? 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:
+ 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

.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. sc.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.