From 4c82f7a8d5d65571b0b827b9b9f2b05ae864cd89 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Wed, 1 Jan 2025 00:48:26 +0100 Subject: [PATCH] build: Merge version.{c,h} into string.{c,h}. This is a preparatory patch for the upcoming revamp of the git version script. The revamped script generates version.c, a file which is currently tracked by git. We can easily get rid of it (and of version.h) since all paraslash executables link in both string.o and version.o. So let's move the three small functions of version.c to string.c and their declarations from version.h to string.h. --- Makefile.real | 23 ++++++++-------- afh.c | 1 - audioc.c | 1 - audiod.c | 1 - audiod_command.c | 1 - client.c | 1 - client_common.c | 1 - command.c | 1 - filter.c | 1 - gui.c | 1 - mixer.c | 1 - play.c | 1 - recv.c | 1 - server.c | 1 - string.c | 63 +++++++++++++++++++++++++++++++++++++++++++ string.h | 3 +++ upgrade_db.c | 1 - version.c | 69 ------------------------------------------------ version.h | 5 ---- write.c | 1 - 20 files changed, 77 insertions(+), 101 deletions(-) delete mode 100644 version.c delete mode 100644 version.h diff --git a/Makefile.real b/Makefile.real index a5492d66..33b9ba46 100644 --- a/Makefile.real +++ b/Makefile.real @@ -47,7 +47,7 @@ ifneq ($(CRYPTOLIB),) crypt_common base64 ipc dccp_send fd user_list \ chunk_queue afs aft mood mp score attribute blob \ playlist sched acl send_common udp_send color fec \ - wma_afh wma_common sideband version lsu \ + wma_afh wma_common sideband lsu \ ) ifeq ($(CRYPTOLIB),openssl) server_objs += openssl.o @@ -73,14 +73,14 @@ ifneq ($(CRYPTOLIB),) server_objs += aac_afh.o mp4.o endif upgrade_db_objs := $(addsuffix .o, crypt_common exec fd string \ - upgrade_db version base64) + upgrade_db base64) endif endif ifneq ($(CRYPTOLIB),) executables += client audiod client_objs := $(addsuffix .o, \ client net string fd lsu sched stdin stdout time sideband client_common \ - buffer_tree crypt_common base64 version $(CRYPTOLIB) \ + buffer_tree crypt_common base64 $(CRYPTOLIB) \ ) ifeq ($(HAVE_READLINE),yes) client_objs += interactive.o @@ -90,7 +90,7 @@ ifneq ($(CRYPTOLIB),) time grab_client filter_common wav_filter compress_filter amp_filter \ http_recv dccp_recv recv_common fd sched write_common file_write \ audiod_command fecdec_filter client_common udp_recv color fec \ - prebuffer_filter version bitstream imdct wma_common wmadec_filter \ + prebuffer_filter bitstream imdct wma_common wmadec_filter \ buffer_tree sync_filter lsu $(CRYPTOLIB) \ ) audiod_audio_formats := "wma" @@ -133,7 +133,7 @@ ifneq ($(CRYPTOLIB),) endif ifneq ($(HAVE_OSS)-$(HAVE_ALSA),no-no) executables += mixer - mixer_objs := $(addsuffix .o, mixer exec string fd time lsu version) + mixer_objs := $(addsuffix .o, mixer exec string fd time lsu) ifeq ($(HAVE_OSS),yes) mixer_objs += oss_mix.o endif @@ -144,11 +144,11 @@ endif ifeq ($(HAVE_CURSES),yes) executables += gui gui_objs := $(addsuffix .o, exec signal string stat ringbuffer fd \ - gui gui_theme lsu time sched version) + gui gui_theme lsu time sched) endif filter_objs := $(addsuffix .o, \ filter_common wav_filter compress_filter filter string stdin stdout \ - sched fd amp_filter fecdec_filter fec lsu version prebuffer_filter \ + sched fd amp_filter fecdec_filter fec lsu prebuffer_filter \ time bitstream imdct wma_common wmadec_filter buffer_tree net \ sync_filter \ ) @@ -177,7 +177,6 @@ endif recv_objs := $(addsuffix .o, \ http_recv recv_common recv time string net dccp_recv fd sched stdout \ udp_recv buffer_tree afh_recv afh_common wma_afh wma_common mp3_afh \ - version \ ) ifeq ($(NEED_OGG_OBJECTS),yes) recv_objs += ogg_afh_common.o @@ -200,7 +199,7 @@ endif audio_format_handlers := mp3 wma afh_objs := $(addsuffix .o, afh string fd mp3_afh afh_common time wma_afh \ - wma_common version) + wma_common) ifeq ($(NEED_OGG_OBJECTS),yes) afh_objs += ogg_afh_common.o endif @@ -232,7 +231,7 @@ ifeq ($(HAVE_READLINE),yes) wma_afh wma_common mp3_afh recv_common udp_recv http_recv dccp_recv \ filter_common fec bitstream imdct wav_filter compress_filter \ amp_filter prebuffer_filter fecdec_filter wmadec_filter write_common \ - file_write version sync_filter lsu interactive \ + file_write sync_filter lsu interactive \ ) ifeq ($(NEED_OGG_OBJECTS),yes) play_objs += ogg_afh_common.o @@ -270,7 +269,7 @@ ifeq ($(HAVE_READLINE),yes) endif write_objs := $(addsuffix .o, write write_common file_write time fd \ - string sched stdin buffer_tree check_wav version) + string sched stdin buffer_tree check_wav) ifeq ($(NEED_AO_OBJECTS),yes) write_objs += ao_write.o endif @@ -281,7 +280,7 @@ ifeq ($(HAVE_ALSA),yes) write_objs += alsa_write.o endif -audioc_objs := $(addsuffix .o, audioc string lsu net fd time version) +audioc_objs := $(addsuffix .o, audioc string lsu net fd time) ifeq ($(HAVE_READLINE),yes) audioc_objs += buffer_tree.o interactive.o sched.o endif diff --git a/afh.c b/afh.c index e419d270..92ce54a5 100644 --- a/afh.c +++ b/afh.c @@ -11,7 +11,6 @@ #include "fd.h" #include "afh.h" #include "error.h" -#include "version.h" /** Array of error strings. */ DEFINE_PARA_ERRLIST; diff --git a/audioc.c b/audioc.c index f2e4cb91..be9cc858 100644 --- a/audioc.c +++ b/audioc.c @@ -21,7 +21,6 @@ #include "net.h" #include "string.h" #include "fd.h" -#include "version.h" /** Array of error strings. */ DEFINE_PARA_ERRLIST; diff --git a/audiod.c b/audiod.c index 3e86af53..53112d59 100644 --- a/audiod.c +++ b/audiod.c @@ -33,7 +33,6 @@ #include "fd.h" #include "write.h" #include "signal.h" -#include "version.h" /** Array of error strings. */ DEFINE_PARA_ERRLIST; diff --git a/audiod_command.c b/audiod_command.c index 5f0b35a5..699cf97b 100644 --- a/audiod_command.c +++ b/audiod_command.c @@ -27,7 +27,6 @@ #include "string.h" #include "write.h" #include "fd.h" -#include "version.h" extern struct sched sched; extern char *stat_item_values[NUM_STAT_ITEMS]; diff --git a/client.c b/client.c index d2d11fd3..eb1e275f 100644 --- a/client.c +++ b/client.c @@ -17,7 +17,6 @@ #include "client.h" #include "buffer_tree.h" #include "error.h" -#include "version.h" /** Array of error strings. */ DEFINE_PARA_ERRLIST; diff --git a/client_common.c b/client_common.c index 396fd88c..5d60e7fb 100644 --- a/client_common.c +++ b/client_common.c @@ -24,7 +24,6 @@ #include "string.h" #include "client.h" #include "buffer_tree.h" -#include "version.h" /** The size of the receiving buffer. */ #define CLIENT_BUFSIZE 4000 diff --git a/command.c b/command.c index 78c9106c..7bf8cbe4 100644 --- a/command.c +++ b/command.c @@ -30,7 +30,6 @@ #include "server_cmd.lsg.h" #include "user_list.h" #include "signal.h" -#include "version.h" /** \cond server_cmd_aux_info */ #define SERVER_CMD_AUX_INFO(_arg) _arg, diff --git a/filter.c b/filter.c index 50447ec0..63e5c7b8 100644 --- a/filter.c +++ b/filter.c @@ -18,7 +18,6 @@ #include "stdout.h" #include "error.h" #include "fd.h" -#include "version.h" /** Array of error strings. */ DEFINE_PARA_ERRLIST; diff --git a/gui.c b/gui.c index feb65c0f..6133b6ca 100644 --- a/gui.c +++ b/gui.c @@ -21,7 +21,6 @@ #include "list.h" #include "sched.h" #include "signal.h" -#include "version.h" /** Array of error strings. */ DEFINE_PARA_ERRLIST; diff --git a/mixer.c b/mixer.c index 787a7257..dc6af767 100644 --- a/mixer.c +++ b/mixer.c @@ -13,7 +13,6 @@ #include "string.h" #include "mix.h" #include "error.h" -#include "version.h" /** Array of error strings. */ DEFINE_PARA_ERRLIST; diff --git a/play.c b/play.c index 596b4b6d..6dd89696 100644 --- a/play.c +++ b/play.c @@ -16,7 +16,6 @@ #include "list.h" #include "error.h" #include "buffer_tree.h" -#include "version.h" #include "string.h" #include "sched.h" #include "filter.h" diff --git a/recv.c b/recv.c index 68417187..f914821e 100644 --- a/recv.c +++ b/recv.c @@ -17,7 +17,6 @@ #include "string.h" #include "error.h" #include "stdout.h" -#include "version.h" /** Array of error strings. */ DEFINE_PARA_ERRLIST; diff --git a/server.c b/server.c index ea9cc9c0..991301ba 100644 --- a/server.c +++ b/server.c @@ -35,7 +35,6 @@ #include "signal.h" #include "user_list.h" #include "color.h" -#include "version.h" /** Array of error strings. */ DEFINE_PARA_ERRLIST; diff --git a/string.c b/string.c index d8bd027b..5e8d72bc 100644 --- a/string.c +++ b/string.c @@ -13,6 +13,7 @@ #include "string.h" #include "error.h" +#include "git-version.h" /** * Reallocate an array, abort on failure or bugs. @@ -1093,3 +1094,65 @@ __must_check int sanitize_str(const char *src, size_t max_width, free(wcs); return 1; } + +/** + * Get the version string for an executable. + * + * \param pfx The program name (without the leading "para_"). + * + * \return A statically allocated string which contains the program name and + * the git version. It must not be freed by the caller. + */ +const char *version_single_line(const char *pfx) +{ + static char buf[100]; + snprintf(buf, sizeof(buf) - 1, + "para_%s " GIT_VERSION, pfx); + return buf; +} + +/** + * Get the full version text. + * + * \param pfx See \ref version_single_line(). + * + * \return A string containing the same text as returned by \ref + * version_single_line(), augmented by additional build information, a + * copyright text and the email address of the author. + * + * Like \ref version_single_line(), this string is stored in a statically + * allocated buffer and must not be freed. + */ +const char *version_text(const char *pfx) +{ + static char buf[512]; + + snprintf(buf, sizeof(buf) - 1, "%s\n" + "Copyright (C) " COPYRIGHT_YEAR " Andre Noll\n" + "This is free software with ABSOLUTELY NO WARRANTY." + " See COPYING for details.\n" + "Report bugs to .\n" + "build date: " BUILD_DATE ",\n" + "build system: " UNAME_RS ",\n" + "compiler: " CC_VERSION ".\n", + version_single_line(pfx) + ); + return buf; +} + +/** + * Print the version text and exit successfully. + * + * \param pfx See \ref version_single_line(). + * \param flag Whether --version was given. + * + * If \a flag is false, this function does nothing. Otherwise it prints the + * full version text as returned by \ref version_text() and exits successfully. + */ +void version_handle_flag(const char *pfx, bool flag) +{ + if (!flag) + return; + printf("%s", version_text(pfx)); + exit(EXIT_SUCCESS); +} diff --git a/string.h b/string.h index d773600f..fe1f49cb 100644 --- a/string.h +++ b/string.h @@ -98,3 +98,6 @@ int skip_cells(const char *s, size_t cells_to_skip, size_t *result); __must_check int strwidth(const char *s, size_t *result); __must_check int sanitize_str(const char *src, size_t max_width, char **result, size_t *width); +const char *version_single_line(const char *pfx); +const char *version_text(const char *pfx); +void version_handle_flag(const char *pfx, bool flag); diff --git a/upgrade_db.c b/upgrade_db.c index 487d46c0..faadc922 100644 --- a/upgrade_db.c +++ b/upgrade_db.c @@ -12,7 +12,6 @@ #include "string.h" #include "fd.h" #include "crypt.h" -#include "version.h" #define CMD_PTR (lls_cmd(0, upgrade_db_suite)) #define OPT_RESULT(_name, _lpr) \ diff --git a/version.c b/version.c deleted file mode 100644 index d057f9c3..00000000 --- a/version.c +++ /dev/null @@ -1,69 +0,0 @@ -/* Copyright (C) 2013 Andre Noll , see file COPYING. */ - -/** \file version.c Some helpers for printing version and copyright strings. */ - -#include "para.h" -#include "version.h" -#include "git-version.h" - -/** - * Get the version string for an executable. - * - * \param pfx The program name (without the leading "para_"). - * - * \return A statically allocated string which contains the program name and - * the git version. It must not be freed by the caller. - */ -const char *version_single_line(const char *pfx) -{ - static char buf[100]; - snprintf(buf, sizeof(buf) - 1, - "para_%s " GIT_VERSION, pfx); - return buf; -} - -/** - * Get the full version text. - * - * \param pfx See \ref version_single_line(). - * - * \return A string containing the same text as returned by \ref - * version_single_line(), augmented by additional build information, a - * copyright text and the email address of the author. - * - * Like \ref version_single_line(), this string is stored in a statically - * allocated buffer and must not be freed. - */ -const char *version_text(const char *pfx) -{ - static char buf[512]; - - snprintf(buf, sizeof(buf) - 1, "%s\n" - "Copyright (C) " COPYRIGHT_YEAR " Andre Noll\n" - "This is free software with ABSOLUTELY NO WARRANTY." - " See COPYING for details.\n" - "Report bugs to .\n" - "build date: " BUILD_DATE ",\n" - "build system: " UNAME_RS ",\n" - "compiler: " CC_VERSION ".\n", - version_single_line(pfx) - ); - return buf; -} - -/** - * Print the version text and exit successfully. - * - * \param pfx See \ref version_single_line(). - * \param flag Whether --version was given. - * - * If \a flag is false, this function does nothing. Otherwise it prints the - * full version text as returned by \ref version_text() and exits successfully. - */ -void version_handle_flag(const char *pfx, bool flag) -{ - if (!flag) - return; - printf("%s", version_text(pfx)); - exit(EXIT_SUCCESS); -} diff --git a/version.h b/version.h deleted file mode 100644 index f5282854..00000000 --- a/version.h +++ /dev/null @@ -1,5 +0,0 @@ -/** \file version.h Functions for printing the version string. */ - -const char *version_single_line(const char *pfx); -const char *version_text(const char *pfx); -void version_handle_flag(const char *pfx, bool flag); diff --git a/write.c b/write.c index cb32d391..9fb98192 100644 --- a/write.c +++ b/write.c @@ -17,7 +17,6 @@ #include "write.h" #include "fd.h" #include "error.h" -#include "version.h" #include "check_wav.h" /** Array of error strings. */ -- 2.39.5