Each build-script line is executed in a separate shell and each build-script line starts in omake's current directory. This causes special problems for some commands. For example, suppose you want to change directory to subdir and run omake recursively. If you use this line
recursion :
chdir subdir
omake $(MFLAGS)
omake $(MFLAGS) is executed from the current directory.
Similarly, setting environment variables does not work as expected because the environment variable is set in one shell, the shell exits back to omake, and the next command is executed in a new shell that doesn't have the variable set. For example, this line
setenv : |
|
set USER=dgk |
(for UNIX: setenv USER dgk) |
echo %USER% |
(for UNIX: echo $$USER) |
NOTE: In NMAKE emulation mode, omake handles internally any commands that start by setting an environment variable, rather than calling the shell.
Both of these problems can be avoided by using a multiple-command build-script line.
The syntax for executing more than one command in the same shell is
( command [ & command ] ... )
The build-script line is enclosed in parentheses, and the commands are separated by a semicolon (;). (Use \; to specify a literal semicolon). In terms of implementation, omake writes each command to a batch file and uses the shell program named by the .SHELL directive to execute the batch file.
The recursion examples now become
recursion :
( chdir subdir & omake $(MFLAGS) )
Simultaneous support of all operating systems is possible with a conditional macro definition such as this:
%if $(OS) == NT
; = & $; is "&"
%else
; = ; $; is ";"
%endif
The multiple-command build-script line is now written as
( chdir subdir $; omake $(MFLAGS) ) |
(for all OSes) |
After the macros are expanded, the build-script line becomes
( chdir subdir ; omake command_line_flags ) |
(if OS is not Windows NT) |
( chdir subdir & omake command_line_flags ) |
(for Windows NT) |
Rather than use a multiple-command build script to work around the change-directory problem, you can use a directive. The %chdir directory directive causes omake to change to directory, where it stays until the next %chdir directive or until omake exits. The recursion example becomes
recursion : |
|
%chdir subdir |
(change to the subdirectory) |
omake $(MFLAGS) |
(do the recursive Make) |
%chdir $(MAKEDIR) |
(change the directory back) |
Likewise, to work around the environment-variable problem you can use a directive. The %setenv name val directive sets environment variable NAME to the value val. Like %chdir, %setenv has effect until the next %setenv or until omake exits. The setenv example becomes
setenv : |
|
%setenv USER dgk |
|
echo %USER% |
(for unix: echo $$USER) |
For more information and recommendations on using the %setenv directive, see the %setenv entry in Table 14 here
Feedback on the documentation in this site? We welcome any comments!
Copyright © 2001 by Rational Software Corporation. All rights reserved. |