summaryrefslogtreecommitdiff
path: root/dev-db/recutils/files/1.9/0003-Fix-bison-and-flex-build-rules.patch
blob: e28476423bdd46bf02fd941434649bcef80fe2c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
From c09d1b1fa83be41f6d0568c50cc287ae718de498 Mon Sep 17 00:00:00 2001
Message-ID: <c09d1b1fa83be41f6d0568c50cc287ae718de498.1760957586.git.sam@gentoo.org>
In-Reply-To: <9f08064fef75ce02df9b6133d240c0fa84df458e.1760957586.git.sam@gentoo.org>
References: <9f08064fef75ce02df9b6133d240c0fa84df458e.1760957586.git.sam@gentoo.org>
From: "Jose E. Marchesi" <jose.marchesi@oracle.com>
Date: Mon, 5 Jun 2023 23:44:03 +0200
Subject: [PATCH 03/10] Fix bison and flex build rules.

2023-06-05  Jose E. Marchesi  <jemarch@gnu.org>

	* configure.ac: Use gl_PROG_BISON instead of gl_BISON.
	* src/Makefile.am: Fix bison and flex rules.
	* src/rec-sex-ast.h: Include stddef.h for size_t.
	* src/rec-sex-lex.l: Use header-file option and fix includes.
---
 ChangeLog         |  8 +++++
 configure.ac      |  2 +-
 src/Makefile.am   | 90 +++++++++++++++++++++++++++++++++++++++++++++--
 src/rec-sex-ast.h |  1 +
 src/rec-sex-lex.l |  5 ++-
 6 files changed, 103 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5527ba2..d7cba1a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-06-05  Jose E. Marchesi  <jemarch@gnu.org>
+
+	* configure.ac: Use gl_PROG_BISON instead of gl_BISON.
+	* src/Makefile.am: Fix bison and flex rules.
+	* src/rec-sex-ast.h: Include stddef.h for size_t.
+	* src/rec-sex-lex.l: Use header-file option and fix includes.
+	* .gitignore: Ignore /src/rec-sex-lex.h.
+
 2022-04-25  Jose E. Marchesi  <jemarch@gnu.org>
 
 	* src/rec-db.c (rec_db_set): Avoid segfault with databases with no
diff --git a/configure.ac b/configure.ac
index 57dfb6a..24495b4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -46,7 +46,7 @@ AC_ARG_VAR([LEX], [The flex implementation to use.])
 AC_ARG_VAR([LEXLIB], [Options for linking with the flex runtime library.])
 AC_ARG_VAR([LEX_OUTPUT_ROOT], [Base of the file name that the lexer generates.])
 
-gl_BISON
+gl_PROG_BISON([RECUTILS_BISON],[3.6])
 
 dnl System
 AC_CANONICAL_HOST
diff --git a/src/Makefile.am b/src/Makefile.am
index cb7cf7a..f1e8fa7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -17,6 +17,11 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+BUILT_SOURCES=
+MOSTLYCLEANFILES=
+MAINTAINERCLEANFILES=
+EXTRA_DIST=
+
 lib_LTLIBRARIES = librec.la
 
 include_HEADERS = rec.h
@@ -52,9 +57,90 @@ else
    librec_la_SOURCES += rec-crypt-dummy.c
 endif
 
-BUILT_SOURCES = rec-sex-tab.h
-AM_YFLAGS = -d
 AM_LFLAGS = -d
+# The Automake generated .l.c rule is broken: When executed in a VPATH build,
+#   - The .c file gets generated in the build directory. But since it requires
+#     special tools to rebuild it, we need to distribute it in the tarballs,
+#     and by the GNU Coding Standards
+#     <https://www.gnu.org/prep/standards/html_node/Makefile-Basics.html>
+#     the file should be generated in the source directory.
+#   - The #line directives in the .c file refer to a nonexistent file once it
+#     has been moved from the build directory to the source directory. This
+#     leads to error if 'lcov' is used later.
+# Additionally, here we assume Flex and therefore don't need the ylwrap script.
+# Therefore we override this rule.
+# Since this is a rule that produces multiple files, we apply the idiom from
+# <https://lists.gnu.org/archive/html/bug-make/2020-09/msg00008.html>, so that
+# it works also in parallel 'make'.
+generate-rec-sex-lex:
+	$(AM_V_LEX)$(LEX) $(LFLAGS) $(AM_LFLAGS) -t $(srcdir)/rec-sex-lex.l > rec-sex-lex.c \
+	&& test ':' = '$(LEX)' || { \
+	  sed -e 's|".*/rec-sex-lex\.l"|"rec-sex-lex.l"|' \
+	      -e 's|"lex\.yy\.c"|"rec-sex-lex.c"|' \
+	      < rec-sex-lex.c > rec-sex-lex.c-tmp \
+	  && sed -e 's|".*/rec-sex-lex\.l"|"rec-sex-lex.l"|' \
+	         < rec-sex-lex.h > rec-sex-lex.h-tmp \
+	  && rm -f rec-sex-lex.c rec-sex-lex.h \
+	  && mv rec-sex-lex.c-tmp $(srcdir)/rec-sex-lex.c \
+	  && mv rec-sex-lex.h-tmp $(srcdir)/rec-sex-lex.h; \
+	}
+.PHONY: generate-rec-sex-lex
+# The above rule will generate files with time-stamp order
+# rec-sex-lex.l <= rec-sex-lex.c <= rec-sex-lex.h.
+rec-sex-lex.c: rec-sex-lex.l
+	@{ test -f $(srcdir)/rec-sex-lex.c && test ! $(srcdir)/rec-sex-lex.c -ot $(srcdir)/rec-sex-lex.l; } || $(MAKE) generate-rec-sex-lex
+rec-sex-lex.h: rec-sex-lex.c
+	@{ test -f $(srcdir)/rec-sex-lex.h && test ! $(srcdir)/rec-sex-lex.h -ot $(srcdir)/rec-sex-lex.c; } || $(MAKE) generate-rec-sex-lex
+BUILT_SOURCES += rec-sex-lex.c rec-sex-lex.h
+MOSTLYCLEANFILES += rec-sex-lex.c-tmp rec-sex-lex.h-tmp
+MAINTAINERCLEANFILES += $(srcdir)/rec-sex-lex.c $(srcdir)/rec-sex-lex.h
+EXTRA_DIST += rec-sex-lex.l rec-sex-lex.c rec-sex-lex.h
+
+AM_YFLAGS = -t --report=state
+# The Automake generated .y.c rule is broken: When executed in a VPATH build,
+#   - The .c file gets generated in the build directory. But since it requires
+#     special tools to rebuild it, we need to distribute it in the tarballs,
+#     and by the GNU Coding Standards
+#     <https://www.gnu.org/prep/standards/html_node/Makefile-Basics.html>
+#     the file should be generated in the source directory.
+#   - The #line directives in the .c file refer to a nonexistent file once it
+#     has been moved from the build directory to the source directory. This
+#     leads to error if 'lcov' is used later.
+# Additionally, here we assume GNU Bison and therefore don't need the ylwrap
+# script.
+# Therefore we override this rule.
+# Since this is a rule that produces multiple files, we apply the idiom from
+# <https://lists.gnu.org/archive/html/bug-make/2020-09/msg00008.html>, so that
+# it works also in parallel 'make'.
+generate-rec-sex-tab:
+	$(AM_V_YACC)$(RECUTILS_BISON) -d $(YFLAGS) $(AM_YFLAGS) $(srcdir)/rec-sex-tab.y \
+	&& test ':' = '$(POKE_BISON)' || { \
+	  sed -e 's|".*/rec-sex-tab\.y"|"rec-sex-tab.y"|' \
+	      -e 's|"rec-sex-tab\.tab\.c"|"rec-sex-tab.c"|' \
+	      -e 's|"rec-sex-tab\.tab\.h"|"rec-sex-tab.h"|' \
+	      < rec-sex-tab.tab.c > rec-sex-tab.c-tmp \
+	  && sed -e 's|".*/rec-sex-tab\.y"|"rec-sex-tab.y"|' \
+	         -e 's|"rec-sex-tab\.tab\.h"|"rec-sex-tab.h"|' \
+	         < rec-sex-tab.tab.h > rec-sex-tab.h-tmp \
+	  && rm -f rec-sex-tab.tab.c rec-sex-tab.tab.h \
+	  && mv rec-sex-tab.c-tmp $(srcdir)/rec-sex-tab.c \
+	  && mv rec-sex-tab.h-tmp $(srcdir)/rec-sex-tab.h; \
+	}
+.PHONY: generate-rec-sex-tab
+# The above rule will generate files with time-stamp order
+# rec-sex-tab.y <= rec-sex-tab.c <= rec-sex-tab.h.
+rec-sex-tab.c: rec-sex-tab.y
+	@{ test -f $(srcdir)/rec-sex-tab.c && test ! $(srcdir)/rec-sex-tab.c -ot $(srcdir)/rec-sex-tab.y; } || $(MAKE) generate-rec-sex-tab
+rec-sex-tab.h: rec-sex-tab.c
+	@{ test -f $(srcdir)/rec-sex-tab.h && test ! $(srcdir)/rec-sex-tab.h -ot $(srcdir)/rec-sex-tab.c; } || $(MAKE) generate-rec-sex-tab
+BUILT_SOURCES += rec-sex-tab.c rec-sex-tab.h
+MOSTLYCLEANFILES += \
+  rec-sex-tab.tab.c rec-sex-tab.tab.h \
+  rec-sex-tab.c-tmp rec-sex-tab.h-tmp \
+  rec-sex-tab.output
+MAINTAINERCLEANFILES += $(srcdir)/rec-sex-tab.c $(srcdir)/rec-sex-tab.h
+EXTRA_DIST += rec-sex-tab.y rec-sex-tab.c rec-sex-tab.h
+
 AM_CFLAGS = 
 if USE_COVERAGE
   AM_CFLAGS += -fprofile-arcs -ftest-coverage
diff --git a/src/rec-sex-ast.h b/src/rec-sex-ast.h
index e2ef0dc..b5c6a79 100644
--- a/src/rec-sex-ast.h
+++ b/src/rec-sex-ast.h
@@ -22,6 +22,7 @@
 
 #include <config.h>
 
+#include <stddef.h> /* For size_t */
 #include <stdbool.h>
 
 enum rec_sex_ast_node_type_e
diff --git a/src/rec-sex-lex.l b/src/rec-sex-lex.l
index 2d4a891..8eee8dd 100644
--- a/src/rec-sex-lex.l
+++ b/src/rec-sex-lex.l
@@ -25,13 +25,16 @@
 %option reentrant
 %option bison-bridge
 %option extra-type="void *"
+%option header-file="rec-sex-lex.h"
 
 %option nounput
 %option noinput
 %top {
    /* This code goes at the "top" of the generated file.  */
    #include <config.h>
-   #include "rec-sex-lex.h"
+   #include <rec-sex-ast.h>
+   #include <rec-sex-parser.h>
+   #include "rec-sex-tab.h"
 }
 
 %{
-- 
2.51.1