sh conditionals do not work inside make files (with fix)

Joe Kelsey joe at fluke.UUCP
Tue Sep 25 07:57:42 AEST 1984


Subject: shell error handling -e flag breaks conditionals in make.
Index:	bin/sh/xec.c 4.2BSD

Description:
	sh conditionals do not work inside make files.
Repeat-By:
	Place an if statement with both branches in a make file such that
	the condition is false to try to force execution of the else
	clause.  For example:

	all:
		if false ; then echo "true" ; else "false" ; fi

	Make will report an error and exit immediately after printing
	the command line.
Fix:
	The -e flag is supposed to cause the shell to exit as soon as it
	encounters a command which returns non-zero exit status.  Make
	obviously uses this flag so that it can pass complex shell commands
	without parsing them into individual lines.  Unfortunately, the
	shell will exit if the command on a conditional test internal
	statement returns non-zero status.  Shell should treat commands
	run for the if, while, and until commands differently than others
	when the -e flag is set.  The solution is to turn off the -e
	flag while running the commands associated with these flow control
	statements, then turn it back on immediately after.  Here are diff
	-e for the module xec.c (sorry -this is proprietary, so I can't
	post contextual diffs - I am also indenting them so that the
	naked '.'s don't offend anyones software):

> 379,380c
> 			THEN	flags |= saveflg;
> 				execute(t->thtre,execflg);
> 			ELSE	flags |= saveflg;
> 				execute(t->eltre,execflg);
> .
> 377a
> 			saveflg = flags&errflg;
> 			flags &= ~errflg;
> .
> 371a
> 			   flags |= saveflg;
> .
> 369c
> 			   DO flags |= saveflg;
> 			      i=execute(t->dotre,0);
> 			      flags &= ~errflg;
> .
> 366a
> 			   saveflg = flags&errflg;
> 			   flags &= ~errflg;
> .
> 32a
> 	INT		saveflg;
> .

/Joe



More information about the Comp.unix.wizards mailing list