| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: parse.c,v 1.230 2018/12/17 02:06:00 christos Exp $ */ | | 1 | /* $NetBSD: parse.c,v 1.231 2018/12/22 00:36:32 sjg Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1988, 1989, 1990, 1993 | | 4 | * Copyright (c) 1988, 1989, 1990, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to Berkeley by | | 7 | * This code is derived from software contributed to Berkeley by |
8 | * Adam de Boor. | | 8 | * Adam de Boor. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -59,34 +59,34 @@ | | | @@ -59,34 +59,34 @@ |
59 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 59 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
60 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 60 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
61 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 61 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
62 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 62 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
63 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 63 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
64 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 64 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
65 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 65 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
66 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 66 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
67 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 67 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
68 | * SUCH DAMAGE. | | 68 | * SUCH DAMAGE. |
69 | */ | | 69 | */ |
70 | | | 70 | |
71 | #ifndef MAKE_NATIVE | | 71 | #ifndef MAKE_NATIVE |
72 | static char rcsid[] = "$NetBSD: parse.c,v 1.230 2018/12/17 02:06:00 christos Exp $"; | | 72 | static char rcsid[] = "$NetBSD: parse.c,v 1.231 2018/12/22 00:36:32 sjg Exp $"; |
73 | #else | | 73 | #else |
74 | #include <sys/cdefs.h> | | 74 | #include <sys/cdefs.h> |
75 | #ifndef lint | | 75 | #ifndef lint |
76 | #if 0 | | 76 | #if 0 |
77 | static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94"; | | 77 | static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94"; |
78 | #else | | 78 | #else |
79 | __RCSID("$NetBSD: parse.c,v 1.230 2018/12/17 02:06:00 christos Exp $"); | | 79 | __RCSID("$NetBSD: parse.c,v 1.231 2018/12/22 00:36:32 sjg Exp $"); |
80 | #endif | | 80 | #endif |
81 | #endif /* not lint */ | | 81 | #endif /* not lint */ |
82 | #endif | | 82 | #endif |
83 | | | 83 | |
84 | /*- | | 84 | /*- |
85 | * parse.c -- | | 85 | * parse.c -- |
86 | * Functions to parse a makefile. | | 86 | * Functions to parse a makefile. |
87 | * | | 87 | * |
88 | * One function, Parse_Init, must be called before any functions | | 88 | * One function, Parse_Init, must be called before any functions |
89 | * in this module are used. After that, the function Parse_File is the | | 89 | * in this module are used. After that, the function Parse_File is the |
90 | * main entry point and controls most of the other functions in this | | 90 | * main entry point and controls most of the other functions in this |
91 | * module. | | 91 | * module. |
92 | * | | 92 | * |
| @@ -666,41 +666,52 @@ ParseFindKeyword(const char *str) | | | @@ -666,41 +666,52 @@ ParseFindKeyword(const char *str) |
666 | */ | | 666 | */ |
667 | /* VARARGS */ | | 667 | /* VARARGS */ |
668 | static void | | 668 | static void |
669 | ParseVErrorInternal(FILE *f, const char *cfname, size_t clineno, int type, | | 669 | ParseVErrorInternal(FILE *f, const char *cfname, size_t clineno, int type, |
670 | const char *fmt, va_list ap) | | 670 | const char *fmt, va_list ap) |
671 | { | | 671 | { |
672 | static Boolean fatal_warning_error_printed = FALSE; | | 672 | static Boolean fatal_warning_error_printed = FALSE; |
673 | | | 673 | |
674 | (void)fprintf(f, "%s: ", progname); | | 674 | (void)fprintf(f, "%s: ", progname); |
675 | | | 675 | |
676 | if (cfname != NULL) { | | 676 | if (cfname != NULL) { |
677 | (void)fprintf(f, "\""); | | 677 | (void)fprintf(f, "\""); |
678 | if (*cfname != '/' && strcmp(cfname, "(stdin)") != 0) { | | 678 | if (*cfname != '/' && strcmp(cfname, "(stdin)") != 0) { |
679 | char *cp; | | 679 | char *cp, *cp2; |
680 | const char *dir; | | 680 | const char *dir, *fname; |
681 | | | 681 | |
682 | /* | | 682 | /* |
683 | * Nothing is more annoying than not knowing | | 683 | * Nothing is more annoying than not knowing |
684 | * which Makefile is the culprit; we try ${.PARSEDIR} | | 684 | * which Makefile is the culprit; we try ${.PARSEDIR} |
685 | * first and if that's not absolute, we try ${.CURDIR} | | 685 | * and apply realpath(3) if not absolute. |
686 | */ | | 686 | */ |
687 | dir = Var_Value(".PARSEDIR", VAR_GLOBAL, &cp); | | 687 | dir = Var_Value(".PARSEDIR", VAR_GLOBAL, &cp); |
688 | if (dir == NULL || *dir == '\0' || *dir != '/') | | | |
689 | dir = Var_Value(".CURDIR", VAR_GLOBAL, &cp); | | | |
690 | if (dir == NULL) | | 688 | if (dir == NULL) |
691 | dir = "."; | | 689 | dir = "."; |
692 | | | 690 | if (*dir != '/') { |
693 | (void)fprintf(f, "%s/%s", dir, cfname); | | 691 | dir = cp2 = realpath(dir, NULL); |
| | | 692 | free(cp); |
| | | 693 | cp = cp2; /* cp2 set to NULL by Var_Value */ |
| | | 694 | } |
| | | 695 | fname = Var_Value(".PARSEFILE", VAR_GLOBAL, &cp2); |
| | | 696 | if (fname == NULL) { |
| | | 697 | if ((fname = strrchr(cfname, '/'))) |
| | | 698 | fname++; |
| | | 699 | else |
| | | 700 | fname = cfname; |
| | | 701 | } |
| | | 702 | (void)fprintf(f, "%s/%s", dir, fname); |
| | | 703 | free(cp2); |
| | | 704 | free(cp); |
694 | } else | | 705 | } else |
695 | (void)fprintf(f, "%s", cfname); | | 706 | (void)fprintf(f, "%s", cfname); |
696 | | | 707 | |
697 | (void)fprintf(f, "\" line %d: ", (int)clineno); | | 708 | (void)fprintf(f, "\" line %d: ", (int)clineno); |
698 | } | | 709 | } |
699 | if (type == PARSE_WARNING) | | 710 | if (type == PARSE_WARNING) |
700 | (void)fprintf(f, "warning: "); | | 711 | (void)fprintf(f, "warning: "); |
701 | (void)vfprintf(f, fmt, ap); | | 712 | (void)vfprintf(f, fmt, ap); |
702 | (void)fprintf(f, "\n"); | | 713 | (void)fprintf(f, "\n"); |
703 | (void)fflush(f); | | 714 | (void)fflush(f); |
704 | if (type == PARSE_INFO) | | 715 | if (type == PARSE_INFO) |
705 | return; | | 716 | return; |
706 | if (type == PARSE_FATAL || parseWarnFatal) | | 717 | if (type == PARSE_FATAL || parseWarnFatal) |