From 21aa069f78879d5d671968a916f067cff5b845f1 Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Thu, 21 Dec 2023 08:08:25 +0100 Subject: [PATCH] sed the generated enum yytokentype to avoid LTO -Wodr warnings. yacc doesnt support this yet --- CMakeLists.txt | 2 ++ src/CMakeLists.txt | 13 +++++++++---- src/ansi-c/Makefile | 3 +++ src/common | 10 ++++++++++ src/statement-list/Makefile | 3 +++ 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c34eec783d39..474400f166dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -242,6 +242,8 @@ else() message(STATUS "IPO / LTO not supported: <${error}>") endif() +find_program(SED sed gsed) + add_subdirectory(src) add_subdirectory(regression) add_subdirectory(unit) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ede10e72e3b0..9529b881f69c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -41,10 +41,15 @@ macro(generic_bison name) COMPILE_FLAGS "${bison_warnings_as_errors} -pyy${name}" ) set(renamed_parser_header "${CMAKE_CURRENT_BINARY_DIR}/${bison_header}") - add_custom_command(OUTPUT "${renamed_parser_header}" - COMMAND "${CMAKE_COMMAND}" -E copy "${BISON_parser_OUTPUT_HEADER}" "${renamed_parser_header}" - MAIN_DEPENDENCY "${BISON_parser_OUTPUT_HEADER}" - ) + if(${SED} STREQUAL "SED-NOTFOUND") + add_custom_command(OUTPUT "${renamed_parser_header}" + COMMAND "${CMAKE_COMMAND}" -E copy "${BISON_parser_OUTPUT_HEADER}" "${renamed_parser_header}" + MAIN_DEPENDENCY "${BISON_parser_OUTPUT_HEADER}") + else() + add_custom_command(OUTPUT "${renamed_parser_header}" + COMMAND ${SED} -e "s,enum yytokentype,enum yytokentype_${name}," <${BISON_parser_OUTPUT_HEADER} >${renamed_parser_header} + MAIN_DEPENDENCY "${BISON_parser_OUTPUT_HEADER}") + endif() list(REMOVE_ITEM BISON_parser_OUTPUTS "${BISON_parser_OUTPUT_HEADER}") list(APPEND BISON_parser_OUTPUTS "${renamed_parser_header}") endmacro(generic_bison) diff --git a/src/ansi-c/Makefile b/src/ansi-c/Makefile index 64ffa4970723..4f5d28867769 100644 --- a/src/ansi-c/Makefile +++ b/src/ansi-c/Makefile @@ -86,6 +86,9 @@ all: ansi-c$(LIBEXT) ansi_c_y.tab.cpp: parser.y $(YACC) $(YFLAGS) -pyyansi_c parser.y --defines=ansi_c_y.tab.h -o $@ + $(SED) -e's,enum yytokentype,enum yytokentype_ansi,' \ + ansi_c_y.tab.h.tmp && \ + mv ansi_c_y.tab.h.tmp ansi_c_y.tab.h ansi_c_y.tab.h: ansi_c_y.tab.cpp diff --git a/src/common b/src/common index bf4190c5bd5f..71ac0a56caa8 100644 --- a/src/common +++ b/src/common @@ -98,6 +98,9 @@ endif ifeq ($(origin LEX),default) LEX = flex endif +ifeq ($(origin SED),default) + SED = sed +endif else ifeq ($(BUILD_ENV_),Cygwin) # use these for Cygwin: @@ -130,6 +133,9 @@ endif ifeq ($(origin LEX),default) LEX = flex endif +ifeq ($(origin SED),default) + SED = sed +endif else ifeq ($(BUILD_ENV_),MSVC) @@ -158,6 +164,10 @@ endif ifeq ($(origin LEX),default) LEX = win_flex endif +ifeq ($(origin SED),default) + # on MSVC there is no lto + SED = rem +endif else diff --git a/src/statement-list/Makefile b/src/statement-list/Makefile index b23de3460640..54ec5aa771f0 100644 --- a/src/statement-list/Makefile +++ b/src/statement-list/Makefile @@ -31,6 +31,9 @@ all: statement-list$(LIBEXT) statement_list_y.tab.cpp: parser.y $(YACC) $(YFLAGS) -pyystatement_list parser.y --defines=statement_list_y.tab.h -o $@ + $(SED) -e's,enum yytokentype,enum yytokentype_stmt,' \ + statement_list_y.tab.h.tmp && \ + mv statement_list_y.tab.h.tmp statement_list_y.tab.h statement_list_y.tab.h: statement_list_y.tab.cpp