Browse Source

package/ncmpc: Fix build error with gcc-14

The error appears on autobuilder with the build using GCC14:
FAILED: ncmpc.p/src_Styles.cxx.o
In file included from ../src/Styles.cxx:7:
/home/buildroot/instance-0/output-1/host/microblazeel-buildroot-linux-gnu/sysroot/usr/include/libintl.h:39:14: error: expected unqualified-id before 'const'
   39 | extern char *gettext (const char *__msgid)
      |              ^~~~~~~
/home/buildroot/instance-0/output-1/host/microblazeel-buildroot-linux-gnu/sysroot/usr/include/libintl.h:39:14: error: expected ')' before 'const'
../src/i18n.h:22:20: note: to match this '('
   22 | #define gettext(x) (x)
      |                    ^
[80/102] Compiling C++ object ncmpc.p/src_xterm_title.cxx.o
[81/102] Compiling C++ object ncmpc.p/src_db_completion.cxx.o
[82/102] Compiling C++ object ncmpc.p/src_signals.cxx.o
ninja: build stopped: subcommand failed.
make: *** [package/pkg-generic.mk:273: /home/buildroot/instance-0/output-1/build/ncmpc-0.49/.stamp_built] Error 1
make: Leaving directory '/home/buildroot/instance-0/buildroot'

Starting GCC14 the C++ standard library includes libintl.h that contains
a definition of gettext which caused a clash with the definition present
in ncmpc. This patch resolved this build error seen in [1] by
backporting an upstream commit [2] that renamed the internal gettext
implementation.

Applying the commits of [2], fixes the build error [1].

[1] https://autobuild.buildroot.org/results/cb2/cb292f2c99cdca742a8f52dbfc25f193fe513c6e/build-end.log
[2] https://github.com/MusicPlayerDaemon/ncmpc/commit/249b62fc9f5e3a653ebdd22da0d75fbe87069457

Fixes: https://autobuild.buildroot.org/results/cb2/cb292f2c99cdca742a8f52dbfc25f193fe513c6e/build-end.log
Signed-off-by: Tim Soubry <tim.soubry@mind.be>
[Julien:
 - mention gcc-14 in commit title
 - remove patch numbering to fix check-package error
]
Signed-off-by: Julien Olivain <ju.o@free.fr>
Tim Soubry 4 weeks ago
parent
commit
a52269e221

+ 199 - 0
package/ncmpc/0001-i18n-add-macro-my_gettext-do-not-define-gettext.patch

@@ -0,0 +1,199 @@
+From d90e80cf0b3525d780b57d016afaa879e16b0fe4 Mon Sep 17 00:00:00 2001
+From: Max Kellermann <max@musicpd.org>
+Date: Tue, 23 Jul 2024 14:15:16 +0200
+Subject: [PATCH] i18n: add macro my_gettext(), do not define "gettext"
+
+Defining the macro "gettext" can cause breakages if the C++ standard
+library happens to include libintl.h (which GCC 14 does).
+
+Signed-off-by: Tim Soubry <tim.soubry@mind.be>
+Upstream: https://github.com/MusicPlayerDaemon/ncmpc/commit/249b62fc9f5e3a653ebdd22da0d75fbe87069457
+---
+ src/Command.cxx    | 2 +-
+ src/HelpPage.cxx   | 6 +++---
+ src/KeyDefPage.cxx | 2 +-
+ src/SearchPage.cxx | 6 +++---
+ src/SongPage.cxx   | 8 ++++----
+ src/TabBar.cxx     | 2 +-
+ src/i18n.h         | 8 +++-----
+ 7 files changed, 16 insertions(+), 18 deletions(-)
+
+diff --git a/src/Command.cxx b/src/Command.cxx
+index 1caac250..b12a4a35 100644
+--- a/src/Command.cxx
++++ b/src/Command.cxx
+@@ -238,7 +238,7 @@ get_cmds_max_name_width()
+ const char *
+ get_key_description(Command command)
+ {
+-	return gettext(cmds[size_t(command)].description);
++	return my_gettext(cmds[size_t(command)].description);
+ }
+ 
+ const char *
+diff --git a/src/HelpPage.cxx b/src/HelpPage.cxx
+index fad0f8c0..c07a20c4 100644
+--- a/src/HelpPage.cxx
++++ b/src/HelpPage.cxx
+@@ -242,7 +242,7 @@ HelpPage::GetListItemText(char *, size_t, unsigned i) const noexcept
+ 	assert(i < std::size(help_text));
+ 
+ 	if (row->text != nullptr)
+-		return gettext(row->text);
++		return my_gettext(row->text);
+ 
+ 	if (row->command != Command::NONE)
+ 		return get_key_description(row->command);
+@@ -272,7 +272,7 @@ HelpPage::PaintListItem(WINDOW *w, unsigned i,
+ 
+ 	if (row->command == Command::NONE) {
+ 		if (row->text != nullptr)
+-			mvwaddstr(w, y, 6, gettext(row->text));
++			mvwaddstr(w, y, 6, my_gettext(row->text));
+ 		else if (row->highlight == 2)
+ 			mvwhline(w, y, 3, ACS_HLINE, width - 6);
+ 	} else {
+@@ -285,7 +285,7 @@ HelpPage::PaintListItem(WINDOW *w, unsigned i,
+ 		mvwaddch(w, y, 21, ':');
+ 		mvwaddstr(w, y, 23,
+ 			  row->text != nullptr
+-			  ? gettext(row->text)
++			  ? my_gettext(row->text)
+ 			  : get_key_description(row->command));
+ 	}
+ }
+diff --git a/src/KeyDefPage.cxx b/src/KeyDefPage.cxx
+index be638940..dd301d39 100644
+--- a/src/KeyDefPage.cxx
++++ b/src/KeyDefPage.cxx
+@@ -434,7 +434,7 @@ CommandListPage::GetListItemText(char *buffer, size_t size,
+ 
+ 	snprintf(buffer + get_cmds_max_name_width(),
+ 		 size - get_cmds_max_name_width(),
+-		 " - %s", gettext(get_command_definitions()[idx].description));
++		 " - %s", my_gettext(get_command_definitions()[idx].description));
+ 
+ 	return buffer;
+ }
+diff --git a/src/SearchPage.cxx b/src/SearchPage.cxx
+index 4f2e3228..9ae8436b 100644
+--- a/src/SearchPage.cxx
++++ b/src/SearchPage.cxx
+@@ -142,7 +142,7 @@ public:
+ 				 " %s : %s [%s]",
+ 				 GetGlobalKeyBindings().GetKeyNames(Command::SEARCH_MODE).c_str(),
+ 				 get_key_description(Command::SEARCH_MODE),
+-				 gettext(mode[options.search_mode].label));
++				 my_gettext(mode[options.search_mode].label));
+ 			return buffer;
+ 		}
+ 
+@@ -453,7 +453,7 @@ SearchPage::GetTitle(char *str, size_t size) const noexcept
+ 			 "%s '%s' [%s]",
+ 			 _("Search"),
+ 			 pattern.c_str(),
+-			 gettext(mode[options.search_mode].label));
++			 my_gettext(mode[options.search_mode].label));
+ 	else
+ 		return _("Search");
+ 
+@@ -478,7 +478,7 @@ SearchPage::OnCommand(struct mpdclient &c, Command cmd)
+ 		if (mode[options.search_mode].label == nullptr)
+ 			options.search_mode = 0;
+ 		screen_status_printf(_("Search mode: %s"),
+-				     gettext(mode[options.search_mode].label));
++				     my_gettext(mode[options.search_mode].label));
+ 
+ 		if (pattern.empty())
+ 			/* show the new mode in the help text */
+diff --git a/src/SongPage.cxx b/src/SongPage.cxx
+index c0830a9e..6d166b13 100644
+--- a/src/SongPage.cxx
++++ b/src/SongPage.cxx
+@@ -174,14 +174,14 @@ static std::unique_ptr<Page>
+ screen_song_init(ScreenManager &_screen, WINDOW *w, Size size) noexcept
+ {
+ 	for (unsigned i = 0; tag_labels[i].label != nullptr; ++i) {
+-		unsigned width = StringWidthMB(gettext(tag_labels[i].label));
++		unsigned width = StringWidthMB(my_gettext(tag_labels[i].label));
+ 		if (width > max_tag_label_width)
+ 			max_tag_label_width = width;
+ 	}
+ 
+ 	for (unsigned i = 0; i < std::size(stats_labels); ++i) {
+ 		if (stats_labels[i] != nullptr) {
+-			unsigned width = StringWidthMB(gettext(stats_labels[i]));
++			unsigned width = StringWidthMB(my_gettext(stats_labels[i]));
+ 
+ 			if (width > max_stats_label_width)
+ 				max_stats_label_width = width;
+@@ -267,7 +267,7 @@ get_tag_label(unsigned tag) noexcept
+ {
+ 	for (unsigned i = 0; tag_labels[i].label != nullptr; ++i)
+ 		if (tag_labels[i].tag_type == tag)
+-			return gettext(tag_labels[i].label);
++			return my_gettext(tag_labels[i].label);
+ 
+ 	assert(tag < MPD_TAG_COUNT);
+ 	return mpd_tag_name((enum mpd_tag_type)tag);
+@@ -351,7 +351,7 @@ SongPage::AddSong(const struct mpd_song *song) noexcept
+ void
+ SongPage::AppendStatsLine(enum stats_label label, const char *value) noexcept
+ {
+-	AppendLine(gettext(stats_labels[label]), value, max_stats_label_width);
++	AppendLine(my_gettext(stats_labels[label]), value, max_stats_label_width);
+ }
+ 
+ bool
+diff --git a/src/TabBar.cxx b/src/TabBar.cxx
+index 426bce12..0518801f 100644
+--- a/src/TabBar.cxx
++++ b/src/TabBar.cxx
+@@ -48,7 +48,7 @@ PaintTabBar(WINDOW *w, const PageMeta &current_page_meta,
+ 			title = current_page_title;
+ 
+ 		if (title == nullptr)
+-			title = gettext(page->title);
++			title = my_gettext(page->title);
+ 
+ 		PaintPageTab(w, page->command, title,
+ 			     page == &current_page_meta);
+diff --git a/src/i18n.h b/src/i18n.h
+index 8bda456e..7e98c1b0 100644
+--- a/src/i18n.h
++++ b/src/i18n.h
+@@ -1,8 +1,7 @@
+ // SPDX-License-Identifier: GPL-2.0-or-later
+ // Copyright The Music Player Daemon Project
+ 
+-#ifndef I18N_H
+-#define I18N_H
++#pragma once
+ 
+ #include "config.h"
+ 
+@@ -10,6 +9,7 @@
+ 
+ #include <libintl.h> // IWYU pragma: export
+ 
++#define my_gettext(x) gettext(x)
+ #define _(x) gettext(x)
+ 
+ #ifdef gettext_noop
+@@ -19,12 +19,10 @@
+ #endif
+ 
+ #else
+-#define gettext(x) (x)
++#define my_gettext(x) (x)
+ #define  _(x) x
+ #define N_(x) x
+ #endif
+ 
+ #define YES_TRANSLATION _("y")
+ #define NO_TRANSLATION _("n")
+-
+-#endif
+-- 
+2.39.5
+