Subject: make(1) patches to support `.-include' -- optional include files
To: None <current-users@NetBSD.ORG>
From: Roland McGrath <roland@frob.com>
List: current-users
Date: 05/13/1995 02:35:32
The following patches add the directive:

.-include <file>

or 

.-include "file"

to makefiles.  This is just like ".include", but there is no error
if the file is not found.

With this patch to make (I even changed the man page), I humbly
submit this patch to sys.mk, which I have been adding by hand every
time I reinstall.

*** /usr/src/share/mk/sys.mk.~1~        Mon Nov 21 16:53:16 1994
--- /usr/src/share/mk/sys.mk    Sat May 13 02:28:45 1995
***************
*** 181,183 ****
--- 181,186 ----
  .sh:
        rm -f ${.TARGET}
        cp ${.IMPSRC} ${.TARGET}
+ 
+ # Include site-specific configuration makefile, but no error if absent.
+ .-include <site.mk>

Diff exited abnormally with code 1 at Sat May 13 02:34:17


Thanks,
Roland



*** parse.c.~1~ Wed Feb  8 06:16:33 1995
--- parse.c     Sat May 13 02:29:21 1995
***************
*** 233,239 ****
  static int ParseReadc __P((void));
  static void ParseUnreadc __P((int));
  static void ParseHasCommands __P((ClientData));
! static void ParseDoInclude __P((char *));
  #ifdef SYSVINCLUDE
  static void ParseTraditionalInclude __P((char *));
  #endif
--- 233,239 ----
  static int ParseReadc __P((void));
  static void ParseUnreadc __P((int));
  static void ParseHasCommands __P((ClientData));
! static void ParseDoInclude __P((char *, int));
  #ifdef SYSVINCLUDE
  static void ParseTraditionalInclude __P((char *));
  #endif
***************
*** 1570,1577 ****
   *---------------------------------------------------------------------
   */
  static void
! ParseDoInclude (file)
      char          *file;      /* file specification */
  {
      char          *fullname;  /* full pathname of file */
      IFile         *oldFile;   /* state associated with current file */
--- 1570,1578 ----
   *---------------------------------------------------------------------
   */
  static void
! ParseDoInclude (file, optional)
      char          *file;      /* file specification */
+     int                 optional;     /* if nonzero, no error for missing file */
  {
      char          *fullname;  /* full pathname of file */
      IFile         *oldFile;   /* state associated with current file */
***************
*** 1686,1692 ****
  
      if (fullname == (char *) NULL) {
        *cp = endc;
!       Parse_Error (PARSE_FATAL, "Could not find %s", file);
        return;
      }
  
--- 1687,1694 ----
  
      if (fullname == (char *) NULL) {
        *cp = endc;
!       if (! optional)
!               Parse_Error (PARSE_FATAL, "Could not find %s", file);
        return;
      }
  
***************
*** 2385,2391 ****
                    continue;
                }
                if (strncmp (cp, "include", 7) == 0) {
!                   ParseDoInclude (cp + 7);
                    goto nextLine;
                } else if (strncmp(cp, "undef", 5) == 0) {
                    char *cp2;
--- 2387,2396 ----
                    continue;
                }
                if (strncmp (cp, "include", 7) == 0) {
!                   ParseDoInclude (cp + 7, 0);
!                   goto nextLine;
!               } else if (strncmp (cp, "-include", 8) == 0) {
!                   ParseDoInclude (cp + 8, 1);
                    goto nextLine;
                } else if (strncmp(cp, "undef", 5) == 0) {
                    char *cp2;
[Exit 1]

*** make.1.~1~  Sat Apr 29 23:52:38 1995
--- make.1      Sat May 13 02:30:34 1995
***************
*** 524,529 ****
--- 524,534 ----
  .Fl I
  option are searched before the system
  makefile directory.
+ The variant
+ .Ql .-include <file>
+ or
+ .Ql .-include \*qfile\*q .
+ does the same, but does not diagnose an error if the file is not found.
  .Pp
  Conditional expressions are also preceded by a single dot as the first
  character of a line.
[Exit 1]