Andrew Geissler | 615f2f1 | 2022-07-15 14:00:58 -0500 | [diff] [blame^] | 1 | From 1862c6e57a308a05889c80c048dbc58bdc378dcb Mon Sep 17 00:00:00 2001 |
| 2 | From: Bruno Haible <bruno@clisp.org> |
| 3 | Date: Tue, 5 Jul 2022 07:51:46 +0200 |
| 4 | Subject: [PATCH] Add support for reproducible builds. |
| 5 | |
| 6 | Suggested by Richard Purdie <richard.purdie@linuxfoundation.org> in |
| 7 | <https://lists.gnu.org/archive/html/bug-gperf/2022-07/msg00000.html>. |
| 8 | |
| 9 | * autogen.sh: Import also lib/filename.h. |
| 10 | * Makefile.in (IMPORTED_FILES): Add lib/filename.h. |
| 11 | * src/options.cc: Include filename.h. |
| 12 | (Options::print_options): Print only the base name of the program name. |
| 13 | * tests/*.exp: Update. |
| 14 | |
| 15 | Upstream-Status: Backport |
| 16 | |
| 17 | Index: gperf-3.1/ChangeLog |
| 18 | =================================================================== |
| 19 | --- gperf-3.1.orig/ChangeLog |
| 20 | +++ gperf-3.1/ChangeLog |
| 21 | @@ -1,3 +1,14 @@ |
| 22 | +2022-07-05 Bruno Haible <bruno@clisp.org> |
| 23 | + |
| 24 | + Add support for reproducible builds. |
| 25 | + Suggested by Richard Purdie <richard.purdie@linuxfoundation.org> in |
| 26 | + <https://lists.gnu.org/archive/html/bug-gperf/2022-07/msg00000.html>. |
| 27 | + * autogen.sh: Import also lib/filename.h. |
| 28 | + * Makefile.in (IMPORTED_FILES): Add lib/filename.h. |
| 29 | + * src/options.cc: Include filename.h. |
| 30 | + (Options::print_options): Print only the base name of the program name. |
| 31 | + * tests/*.exp: Update. |
| 32 | + |
| 33 | 2017-01-02 Marcel Schaible <marcel.schaible@studium.fernuni-hagen.de> |
| 34 | |
| 35 | * gperf-3.1 released. |
| 36 | Index: gperf-3.1/src/options.cc |
| 37 | =================================================================== |
| 38 | --- gperf-3.1.orig/src/options.cc |
| 39 | +++ gperf-3.1/src/options.cc |
| 40 | @@ -26,6 +26,7 @@ |
| 41 | #include <string.h> /* declares strcmp() */ |
| 42 | #include <ctype.h> /* declares isdigit() */ |
| 43 | #include <limits.h> /* defines CHAR_MAX */ |
| 44 | +#include "filename.h" |
| 45 | #include "getopt.h" |
| 46 | #include "version.h" |
| 47 | |
| 48 | @@ -280,6 +281,16 @@ Options::print_options () const |
| 49 | { |
| 50 | const char *arg = _argument_vector[i]; |
| 51 | |
| 52 | + if (i == 0) |
| 53 | + { |
| 54 | + /* _argument_vector[0] is the program name. Print only its base name. |
| 55 | + This is useful for reproducible builds. */ |
| 56 | + const char *p = arg + strlen (arg); |
| 57 | + while (p > arg && ! ISSLASH (p[-1])) |
| 58 | + p--; |
| 59 | + arg = p; |
| 60 | + } |
| 61 | + |
| 62 | /* Escape arg if it contains shell metacharacters. */ |
| 63 | if (*arg == '-') |
| 64 | { |
| 65 | Index: gperf-3.1/lib/filename.h |
| 66 | =================================================================== |
| 67 | --- /dev/null |
| 68 | +++ gperf-3.1/lib/filename.h |
| 69 | @@ -0,0 +1,112 @@ |
| 70 | +/* Basic filename support macros. |
| 71 | + Copyright (C) 2001-2022 Free Software Foundation, Inc. |
| 72 | + This file is part of the GNU C Library. |
| 73 | + |
| 74 | + The GNU C Library is free software; you can redistribute it and/or |
| 75 | + modify it under the terms of the GNU Lesser General Public |
| 76 | + License as published by the Free Software Foundation; either |
| 77 | + version 2.1 of the License, or (at your option) any later version. |
| 78 | + |
| 79 | + The GNU C Library is distributed in the hope that it will be useful, |
| 80 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 81 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 82 | + Lesser General Public License for more details. |
| 83 | + |
| 84 | + You should have received a copy of the GNU Lesser General Public |
| 85 | + License along with the GNU C Library; if not, see |
| 86 | + <https://www.gnu.org/licenses/>. */ |
| 87 | + |
| 88 | +/* From Paul Eggert and Jim Meyering. */ |
| 89 | + |
| 90 | +#ifndef _FILENAME_H |
| 91 | +#define _FILENAME_H |
| 92 | + |
| 93 | +#include <string.h> |
| 94 | + |
| 95 | +#ifdef __cplusplus |
| 96 | +extern "C" { |
| 97 | +#endif |
| 98 | + |
| 99 | + |
| 100 | +/* Filename support. |
| 101 | + ISSLASH(C) tests whether C is a directory separator |
| 102 | + character. |
| 103 | + HAS_DEVICE(Filename) tests whether Filename contains a device |
| 104 | + specification. |
| 105 | + FILE_SYSTEM_PREFIX_LEN(Filename) length of the device specification |
| 106 | + at the beginning of Filename, |
| 107 | + index of the part consisting of |
| 108 | + alternating components and slashes. |
| 109 | + FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE |
| 110 | + 1 when a non-empty device specification |
| 111 | + can be followed by an empty or relative |
| 112 | + part, |
| 113 | + 0 when a non-empty device specification |
| 114 | + must be followed by a slash, |
| 115 | + 0 when device specification don't exist. |
| 116 | + IS_ABSOLUTE_FILE_NAME(Filename) |
| 117 | + tests whether Filename is independent of |
| 118 | + any notion of "current directory". |
| 119 | + IS_RELATIVE_FILE_NAME(Filename) |
| 120 | + tests whether Filename may be concatenated |
| 121 | + to a directory filename. |
| 122 | + Note: On native Windows, OS/2, DOS, "c:" is neither an absolute nor a |
| 123 | + relative file name! |
| 124 | + IS_FILE_NAME_WITH_DIR(Filename) tests whether Filename contains a device |
| 125 | + or directory specification. |
| 126 | + */ |
| 127 | +#if defined _WIN32 || defined __CYGWIN__ \ |
| 128 | + || defined __EMX__ || defined __MSDOS__ || defined __DJGPP__ |
| 129 | + /* Native Windows, Cygwin, OS/2, DOS */ |
| 130 | +# define ISSLASH(C) ((C) == '/' || (C) == '\\') |
| 131 | + /* Internal macro: Tests whether a character is a drive letter. */ |
| 132 | +# define _IS_DRIVE_LETTER(C) \ |
| 133 | + (((C) >= 'A' && (C) <= 'Z') || ((C) >= 'a' && (C) <= 'z')) |
| 134 | + /* Help the compiler optimizing it. This assumes ASCII. */ |
| 135 | +# undef _IS_DRIVE_LETTER |
| 136 | +# define _IS_DRIVE_LETTER(C) \ |
| 137 | + (((unsigned int) (C) | ('a' - 'A')) - 'a' <= 'z' - 'a') |
| 138 | +# define HAS_DEVICE(Filename) \ |
| 139 | + (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':') |
| 140 | +# define FILE_SYSTEM_PREFIX_LEN(Filename) (HAS_DEVICE (Filename) ? 2 : 0) |
| 141 | +# ifdef __CYGWIN__ |
| 142 | +# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0 |
| 143 | +# else |
| 144 | + /* On native Windows, OS/2, DOS, the system has the notion of a |
| 145 | + "current directory" on each drive. */ |
| 146 | +# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 1 |
| 147 | +# endif |
| 148 | +# if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE |
| 149 | +# define IS_ABSOLUTE_FILE_NAME(Filename) \ |
| 150 | + ISSLASH ((Filename)[FILE_SYSTEM_PREFIX_LEN (Filename)]) |
| 151 | +# else |
| 152 | +# define IS_ABSOLUTE_FILE_NAME(Filename) \ |
| 153 | + (ISSLASH ((Filename)[0]) || HAS_DEVICE (Filename)) |
| 154 | +# endif |
| 155 | +# define IS_RELATIVE_FILE_NAME(Filename) \ |
| 156 | + (! (ISSLASH ((Filename)[0]) || HAS_DEVICE (Filename))) |
| 157 | +# define IS_FILE_NAME_WITH_DIR(Filename) \ |
| 158 | + (strchr ((Filename), '/') != NULL || strchr ((Filename), '\\') != NULL \ |
| 159 | + || HAS_DEVICE (Filename)) |
| 160 | +#else |
| 161 | + /* Unix */ |
| 162 | +# define ISSLASH(C) ((C) == '/') |
| 163 | +# define HAS_DEVICE(Filename) ((void) (Filename), 0) |
| 164 | +# define FILE_SYSTEM_PREFIX_LEN(Filename) ((void) (Filename), 0) |
| 165 | +# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0 |
| 166 | +# define IS_ABSOLUTE_FILE_NAME(Filename) ISSLASH ((Filename)[0]) |
| 167 | +# define IS_RELATIVE_FILE_NAME(Filename) (! ISSLASH ((Filename)[0])) |
| 168 | +# define IS_FILE_NAME_WITH_DIR(Filename) (strchr ((Filename), '/') != NULL) |
| 169 | +#endif |
| 170 | + |
| 171 | +/* Deprecated macros. For backward compatibility with old users of the |
| 172 | + 'filename' module. */ |
| 173 | +#define IS_ABSOLUTE_PATH IS_ABSOLUTE_FILE_NAME |
| 174 | +#define IS_PATH_WITH_DIR IS_FILE_NAME_WITH_DIR |
| 175 | + |
| 176 | + |
| 177 | +#ifdef __cplusplus |
| 178 | +} |
| 179 | +#endif |
| 180 | + |
| 181 | +#endif /* _FILENAME_H */ |