diff -u -b -B --minimal make-3.80/dep.h make-3.80-new/dep.h --- make-3.80/dep.h Mon Jul 8 08:05:02 2002 +++ make-3.80-new/dep.h Fri May 23 09:44:32 2003 @@ -25,6 +25,7 @@ #define RM_INCLUDED (1 << 1) /* Search makefile search path. */ #define RM_DONTCARE (1 << 2) /* No error if it doesn't exist. */ #define RM_NO_TILDE (1 << 3) /* Don't expand ~ in file name. */ +#define RM_CINCLUDED (1 << 4) /* Search in parent makefile directory. */ #define RM_NOFLAG 0 /* Structure representing one dependency of a file. diff -u -b -B --minimal make-3.80/expand.c make-3.80-new/expand.c --- make-3.80/expand.c Thu Jul 11 01:38:57 2002 +++ make-3.80-new/expand.c Tue May 27 18:08:09 2003 @@ -458,6 +458,9 @@ save = current_variable_set_list; current_variable_set_list = file->variables; + + /* Note that reading_file_path is not changed since it's not relevant. */ + if (file->cmds && file->cmds->fileinfo.filenm) reading_file = &file->cmds->fileinfo; else diff -u -b -B --minimal make-3.80/main.c make-3.80-new/main.c --- make-3.80/main.c Fri Aug 9 20:27:17 2002 +++ make-3.80-new/main.c Fri May 23 10:48:00 2003 @@ -856,6 +856,7 @@ default_goal_file = 0; reading_file = 0; + reading_file_path = 0; #if defined (__MSDOS__) && !defined (_POSIX_SOURCE) /* Request the most powerful version of `system', to diff -u -b -B --minimal make-3.80/make.h make-3.80-new/make.h --- make-3.80/make.h Wed Sep 11 11:55:44 2002 +++ make-3.80-new/make.h Fri May 23 10:39:21 2003 @@ -483,6 +483,7 @@ #endif extern const struct floc *reading_file; +extern const char *reading_file_path; extern char **environ; diff -u -b -B --minimal make-3.80/read.c make-3.80-new/read.c --- make-3.80/read.c Thu Oct 3 21:13:42 2002 +++ make-3.80-new/read.c Tue May 27 18:00:51 2003 @@ -118,6 +118,7 @@ makefile currently being read in. */ const struct floc *reading_file = 0; +const char *reading_file_path = 0; /* The chain of makefiles read by read_makefile. */ @@ -280,6 +281,7 @@ struct dep *deps; struct ebuffer ebuf; const struct floc *curfile; + const char *curfile_path; int makefile_errno; int r; @@ -293,6 +295,8 @@ printf (_(" (no default goal)")); if (flags & RM_INCLUDED) printf (_(" (search path)")); + if (flags & RM_CINCLUDED) + printf (_(" (search in parent makefile dir)")); if (flags & RM_DONTCARE) printf (_(" (don't care)")); if (flags & RM_NO_TILDE) @@ -311,7 +315,31 @@ filename = expanded; } + /* Try to open in parent makefile directory if cinclud'ed and in + current directory otherwise. */ + if ((flags & RM_CINCLUDED) && *filename != '/') + { + char* dir = xstrdup (reading_file_path); + char* p = strrchr (dir, '/'); + + if (p == 0) ebuf.fp = fopen (filename, "r"); + else + { + *p = '\0'; + char* path = concat (dir, "/", filename); + + ebuf.fp = fopen (path, "r"); + if (ebuf.fp == 0) + free (path); + else + filename = path; + } + free (dir); + } + else + ebuf.fp = fopen (filename, "r"); + /* Save the error code so we print the right message later. */ makefile_errno = errno; @@ -374,11 +403,15 @@ ebuf.buffer = ebuf.bufnext = ebuf.bufstart = xmalloc (ebuf.size); curfile = reading_file; + curfile_path = reading_file_path; + reading_file = &ebuf.floc; + reading_file_path = filename; r = eval (&ebuf, !(flags & RM_NO_DEFAULT_GOAL)); reading_file = curfile; + reading_file_path = curfile_path; fclose (ebuf.fp); @@ -392,6 +425,7 @@ { struct ebuffer ebuf; const struct floc *curfile; + int r; /* Evaluate the buffer */ @@ -402,6 +436,9 @@ ebuf.floc = *reading_file; + /* Note: there is no need to perform analogous manipulations with + reading_file_path since it doesn't change. */ + curfile = reading_file; reading_file = &ebuf.floc; @@ -758,22 +795,27 @@ goto rule_complete; } - if (word1eq ("include") || word1eq ("-include") || word1eq ("sinclude")) + if (word1eq ("include") + || word1eq ("-include") + || word1eq ("sinclude") + || word1eq ("cinclude")) { /* We have found an `include' line specifying a nested makefile to be read at this point. */ struct conditionals *save; struct conditionals new_conditionals; struct nameseq *files; - /* "-include" (vs "include") says no error if the file does not - exist. "sinclude" is an alias for this from SGI. */ - int noerror = (p[0] != 'i'); + /* "-include" (vs "include", "cinclude") says no error if the file + does not exist. "sinclude" is an alias for this from SGI. */ + int noerror = ((p[0] == '-') || (p[0] == 's')); + int cinclude = (p[0] == 'c'); p = allocated_variable_expand (p2); if (*p == '\0') { error (fstart, - _("no file name for `include'"), noerror ? "-" : ""); + _("no file name for `include'"), + cinclude ? "c" : (noerror ? "-" : "")); continue; } @@ -806,11 +848,18 @@ files = next; r = eval_makefile (name, (RM_INCLUDED | RM_NO_TILDE - | (noerror ? RM_DONTCARE : 0))); + | (noerror ? RM_DONTCARE : 0) + | (cinclude ? RM_CINCLUDED : 0))); if (!r) { if (!noerror) + { + if (cinclude) + fatal (fstart, ": ", name, strerror (errno)); + else error (fstart, ": ", name, strerror (errno)); + } + free (name); } }