Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 22 May 1998 08:36:04 -0400 (EDT)
From:      njs3@doc.ic.ac.uk
To:        FreeBSD-gnats-submit@FreeBSD.ORG
Subject:   bin/6720: [PATCH] make(1) cannot terminate gracefully under user request
Message-ID:  <199805221236.IAA09770@www.in-design.com>

next in thread | raw e-mail | index | archive | help

>Number:         6720
>Category:       bin
>Synopsis:       [PATCH] make(1) cannot terminate gracefully under user request
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:
>Keywords:
>Date-Required:
>Class:          doc-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri May 22 05:40:01 PDT 1998
>Last-Modified:
>Originator:     Niall Smart, njs3@doc.ic.ac.uk
>Organization:
>Release:        FreeBSD 2.2.5-RELEASE i386
>Environment:

>Description:

Complex makefiles may wish to report an error to the user under
certain circumstances, e.g. if the user has not specified a variable
on the command line, this cannot currently be achieved elegantly.
The supplied patch adds an ".error" directive which immediately
terminates processing of the makefile and prints a supplied error message

>How-To-Repeat:

>Fix:


*** parse.c~	Fri May 22 12:35:07 1998
--- parse.c	Tue May 19 12:24:45 1998
***************
*** 251,256 ****
--- 249,255 ----
  static void ParseUnreadc __P((int));
  static void ParseHasCommands __P((ClientData));
  static void ParseDoInclude __P((char *));
+ static void ParseDoError __P((char *));
  #ifdef SYSVINCLUDE
  static void ParseTraditionalInclude __P((char *));
  #endif
***************
*** 1552,1557 ****
--- 1551,1585 ----
      Dir_AddDir (parseIncPath, dir);
  }
  
+ /*---------------------------------------------------------------------
+  * ParseDoError  --
+  *	Handle error directive
+  *
+  *	The input is the line minus the ".error".  We substitute variables,
+  *	print the message and exit(1) or just print a warning if the ".error"
+  *	directive is malformed.
+  *
+  *---------------------------------------------------------------------
+  */
+ static void
+ ParseDoError(errmsg)
+     char          *errmsg;	/* error message */
+ {
+ 	if (!isspace(*errmsg)) {
+ 		Parse_Error(PARSE_WARNING, "invalid syntax: .error%s", errmsg);
+ 		return;
+ 	}
+ 	
+ 	while (isspace(*errmsg))
+ 		errmsg++;
+ 	
+ 	errmsg = Var_Subst(NULL, errmsg, VAR_GLOBAL, FALSE);
+ 
+ 	/* use fprintf/exit instead of Parse_Error to terminate immediately */
+ 	fprintf(stderr, "\"%s\", line %d: %s\n", fname, lineno, errmsg);
+ 	exit(1);
+ }
+ 
  /*-
   *---------------------------------------------------------------------
   * ParseDoInclude  --
***************
*** 1734,1739 ****
--- 1762,1768 ----
  }
  
  
+ 
  /*-
   *---------------------------------------------------------------------
   * Parse_FromString  --
***************
*** 2385,2390 ****
--- 2414,2422 ----
  		if (strncmp (cp, "include", 7) == 0) {
  		    ParseDoInclude (cp + 7);
  		    goto nextLine;
+ 		} else if (strncmp (cp, "error", 5) == 0) {
+ 		    ParseDoError(cp + 5);
+ 	            goto nextLine;	    
  		} else if (strncmp(cp, "undef", 5) == 0) {
  		    char *cp2;
  		    for (cp += 5; isspace((unsigned char) *cp); cp++) {
*** make.1~	Fri May 22 12:35:10 1998
--- make.1	Tue May 19 13:08:18 1998
***************
*** 551,585 ****
  to be replaced in
  .Ar new_string
  .El
! .Sh INCLUDE STATEMENTS, CONDITIONALS AND FOR LOOPS
! Makefile inclusion, conditional structures and for loops  reminiscent
  of the C programming language are provided in
  .Nm make .
  All such structures are identified by a line beginning with a single
  dot
  .Pq Ql \&.
! character.
! Files are included with either
! .Ql .include <file>
! or
! .Ql .include \*qfile\*q .
! Variables between the angle brackets or double quotes are expanded
! to form the file name.
! If angle brackets are used, the included makefile is expected to be in
! the system makefile directory.
! If double quotes are used, the including makefile's directory and any
! directories specified using the
  .Fl I
  option are searched before the system
  makefile directory.
! .Pp
! Conditional expressions are also preceded by a single dot as the first
! character of a line.
! The possible conditionals are as follows:
! .Bl -tag -width Ds
! .It Ic .undef Ar variable
  Un-define the specified global variable.
  Only global variables may be un-defined.
  .It Xo
  .Ic \&.if
  .Oo \&! Oc Ns Ar expression
--- 551,590 ----
  to be replaced in
  .Ar new_string
  .El
! .Sh DIRECTIVES, CONDITIONALS AND FOR LOOPS
! Directives, conditionals and for loops reminiscent
  of the C programming language are provided in
  .Nm make .
  All such structures are identified by a line beginning with a single
  dot
  .Pq Ql \&.
! character.  The following directives are supported:
! .Bl -tag -width Ds
! .It Ic \&.include Ar <file>
! .It Ic \&.include Ar \*qfile\*q
! Include the specified makefile.  Variables between the angle brackets
! or double quotes are expanded to form the file name.  If angle brackets
! are used, the included makefile is expected to be in the system
! makefile directory.  If double quotes are used, the including
! makefile's directory and any directories specified using the
  .Fl I
  option are searched before the system
  makefile directory.
! .It Ic \&.undef Ar variable
  Un-define the specified global variable.
  Only global variables may be un-defined.
+ .It Ic \&.error Ar message
+ Terminate processing of the makefile immediately. The filename of the
+ makefile, the line on which the error was encountered and the specified
+ message are printed to standard output and
+ .Nm make
+ terminates with exit code 1.  Variables in the message are expanded.
+ .El
+ .Pp
+ Conditionals are used to determine which parts of the Makefile
+ to process.  They are used similarly to the conditionals supported
+ by the C pre-processor.  The following conditionals are supported:
+ .Bl -tag -width Ds
  .It Xo
  .Ic \&.if
  .Oo \&! Oc Ns Ar expression
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199805221236.IAA09770>