From be9f7c9b442f7b723427a79f85774d5fa7718425 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Tue, 22 Feb 2011 13:02:17 +0100 Subject: [PATCH 1/1] Fix git-version file creation. ATM, this does not work well, since only the executables depend on GIT-VERSION-FILE, but relinking these does not take into account the new contents of GIT-VERSION-FILE. Hence a "make clean" is necessary to produce executables that reports the correct version number. This patch changes GIT-VERSION-GEN so that it generates a preprocessor define instead of setting a Makefile variable. This value is written to stdout in any case and also to the file named "$1" if an argument was given and the current git version differs from the contents of this file (or if the file does not exist). In order to not have to recompile everything on version changes, the macros related to versioning are moved from para.h into the new version.h file which is included only where necessary. Makefile.in no longer uses phony targets to include the GIT_VERSION variable. Instead we simply execute $(shell ./GIT_VERSION_FILE version.h) at the top of the Makefile. --- .gitignore | 2 +- GIT-VERSION-GEN | 31 ++++++++++++------------------- Makefile.in | 13 ++++--------- afh.c | 1 + audioc.c | 1 + audiod.c | 1 + client_common.c | 1 + command.c | 1 + fade.c | 1 + filter.c | 1 + gui.c | 1 + para.h | 16 ---------------- recv.c | 1 + server.c | 1 + version.h | 17 +++++++++++++++++ write.c | 1 + 16 files changed, 45 insertions(+), 45 deletions(-) create mode 100644 version.h diff --git a/.gitignore b/.gitignore index d3a1fc5e..91c6f858 100644 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,4 @@ web_sync confdefs.h conftest conftest.c -GIT-VERSION-FILE +git-version.h diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN index a64d7961..15c38794 100755 --- a/GIT-VERSION-GEN +++ b/GIT-VERSION-GEN @@ -1,22 +1,17 @@ -#!/bin/sh - -if test $# -ne 1; then - echo >&2 "usage: $0 " - exit 1 -fi +#!/usr/bin/env bash +(($# > 1)) && { echo >&2 "usage: $0 []"; exit 1; } GVF="$1" -DEF_VER="unnamed_version" +DEF_VER="unnamed_version" LF=' ' # First see if there is a version file (included in release tarballs), # then try git-describe, then default. -if test -f VERSION -then +if [[ -f VERSION ]]; then VN=$(cat VERSION) || VN="$DEF_VER" -elif test -d .git -o -f .git && +elif [[ -d .git || -f .git ]] && VN=$(git describe --abbrev=4 HEAD 2>/dev/null) && case "$VN" in *$LF*) (exit 1) ;; @@ -32,14 +27,12 @@ else fi VN=$(expr "$VN" : v*'\(.*\)') +echo "$VN" -if test -r $GVF -then - VC=$(sed -e 's/^GIT_VERSION = //' <$GVF) -else - VC=unset +[[ -z "$GVF" ]] && exit 0 +if [[ -r "$GVF" ]]; then + VC=$(sed -e 's/^#define GIT_VERSION "//; s/"$//' < "$GVF") + [[ "$VN" == "$VC" ]] && exit 0 fi -test "$VN" = "$VC" || { - echo >&2 "GIT_VERSION = $VN" - echo "GIT_VERSION = $VN" >$GVF -} +echo >&2 "new git version: $VN" +echo "#define GIT_VERSION \"$VN\"" >$GVF diff --git a/Makefile.in b/Makefile.in index c64b5ae7..06c86eb6 100644 --- a/Makefile.in +++ b/Makefile.in @@ -16,6 +16,8 @@ uname_rs := $(shell uname -rs) cc_version := $(shell $(CC) --version | head -n 1) codename := deterministic entropy +GIT_VERSION := $(shell ./GIT-VERSION-GEN git-version.h) + DEBUG_CPPFLAGS += -Wno-sign-compare -g -Wunused -Wundef -W DEBUG_CPPFLAGS += -Wredundant-decls # produces false positives @@ -59,7 +61,6 @@ CPPFLAGS += @arch_cppflags@ CPPFLAGS += -I/usr/local/include CPPFLAGS += -I$(cmdline_dir) CPPFLAGS += @osl_cppflags@ -CPPFLAGS += -DGIT_VERSION='"$(GIT_VERSION)"' man_pages := $(patsubst %, man/man1/%.1, @executables@) man_pages_in := $(patsubst %, web/%.man.in.html, @executables@) @@ -99,18 +100,12 @@ else Q = @ endif -.PHONY: dep all clean distclean maintainer-clean install man tarball\ - .FORCE-GIT-VERSION-FILE +.PHONY: dep all clean distclean maintainer-clean install man tarball all: dep @executables@ $(man_pages) dep: $(deps) man: $(man_pages) tarball: $(tarball) -GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE - @./GIT-VERSION-GEN GIT-VERSION-FILE --include GIT-VERSION-FILE -@executables@: GIT-VERSION-FILE - -include $(ggo_dir)/makefile %_command_list.c: %.cmd @@ -303,7 +298,7 @@ $(tarball): $(cmdline_generated) git archive --format=tar --prefix=$(tarball_pfx)/ HEAD \ | tar --delete $(tarball_delete) > $(tarball_pfx).tar mkdir -p $(tarball_pfx)/$(cmdline_dir) - echo $(GIT_VERSION) > $(tarball_pfx)/VERSION + ./GIT-VERSION-GEN > $(tarball_pfx)/VERSION cp -r $(autocrap) $(tarball_pfx) cp -r $(cmdline_generated) $(tarball_pfx)/$(cmdline_dir) tar rf $(tarball_pfx).tar $(tarball_pfx)/* diff --git a/afh.c b/afh.c index c5d7aec2..37d71224 100644 --- a/afh.c +++ b/afh.c @@ -16,6 +16,7 @@ #include "fd.h" #include "afh.h" #include "error.h" +#include "version.h" static struct afh_args_info conf; /** The list of all status items */ diff --git a/audioc.c b/audioc.c index 74fb824c..adcae715 100644 --- a/audioc.c +++ b/audioc.c @@ -16,6 +16,7 @@ #include "net.h" #include "string.h" #include "fd.h" +#include "version.h" INIT_AUDIOC_ERRLISTS; diff --git a/audiod.c b/audiod.c index 8b17d95f..8dd69c60 100644 --- a/audiod.c +++ b/audiod.c @@ -33,6 +33,7 @@ #include "write.h" #include "write_common.h" #include "signal.h" +#include "version.h" /** define the array of error lists needed by para_audiod */ INIT_AUDIOD_ERRLISTS; diff --git a/client_common.c b/client_common.c index a7115fd7..54bb9433 100644 --- a/client_common.c +++ b/client_common.c @@ -25,6 +25,7 @@ #include "client.h" #include "hash.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 f9ef6cd7..029e2890 100644 --- a/command.c +++ b/command.c @@ -37,6 +37,7 @@ #include "afs_command_list.h" #include "sched.h" #include "signal.h" +#include "version.h" /** Commands including options must be shorter than this. */ #define MAX_COMMAND_LEN 32768 diff --git a/fade.c b/fade.c index 8eeb79e7..8affd69d 100644 --- a/fade.c +++ b/fade.c @@ -23,6 +23,7 @@ #include "fd.h" #include "string.h" #include "error.h" +#include "version.h" INIT_FADE_ERRLISTS; static struct fade_args_info conf; diff --git a/filter.c b/filter.c index 1d938c45..0dfc94b1 100644 --- a/filter.c +++ b/filter.c @@ -20,6 +20,7 @@ #include "stdin.h" #include "stdout.h" #include "error.h" +#include "version.h" /** The list of all status items used by para_{server,audiod,gui}. */ const char *status_item_list[] = {STATUS_ITEM_ARRAY}; diff --git a/gui.c b/gui.c index 38addd98..4be81f74 100644 --- a/gui.c +++ b/gui.c @@ -22,6 +22,7 @@ #include "list.h" #include "sched.h" #include "signal.h" +#include "version.h" /** define the array of error lists needed by para_gui */ INIT_GUI_ERRLISTS; diff --git a/para.h b/para.h index 29c5c2b8..3121850f 100644 --- a/para.h +++ b/para.h @@ -67,22 +67,6 @@ va_end(argp); \ } -/** Version text used by various commands if -V switch was given. */ -#define VERSION_TEXT(prefix) "para_" prefix " " PACKAGE_VERSION \ - " (" GIT_VERSION ": " CODENAME ")" "\n" \ - "Copyright (C) 2011 Andre Noll\n" \ - "This is free software with ABSOLUTELY NO WARRANTY." \ - " See COPYING for details.\n" \ - "Written by Andre Noll.\n" \ - "Report bugs to .\n" - -/** Print out \p VERSION_TEXT and exit if version flag was given. */ -#define HANDLE_VERSION_FLAG(_prefix, _args_info_struct) \ - if (_args_info_struct.version_given) { \ - printf("%s", VERSION_TEXT(_prefix)); \ - exit(EXIT_SUCCESS); \ - } - /** Sent by para_client to initiate the authentication procedure. */ #define AUTH_REQUEST_MSG "auth rsa " /** Sent by para_server for commands that expect a data file. */ diff --git a/recv.c b/recv.c index a737e4cb..ae8a1f66 100644 --- a/recv.c +++ b/recv.c @@ -22,6 +22,7 @@ #include "error.h" #include "stdout.h" #include "buffer_tree.h" +#include "version.h" /** The gengetopt args info struct. */ static struct recv_args_info conf; diff --git a/server.c b/server.c index 35d6f191..4d54f74b 100644 --- a/server.c +++ b/server.c @@ -91,6 +91,7 @@ #include "signal.h" #include "user_list.h" #include "color.h" +#include "version.h" /** Define the array of error lists needed by para_server. */ INIT_SERVER_ERRLISTS; diff --git a/version.h b/version.h new file mode 100644 index 00000000..3b839669 --- /dev/null +++ b/version.h @@ -0,0 +1,17 @@ +#include "git-version.h" +/** Version text used by various commands if -V switch was given. */ +#define VERSION_TEXT(prefix) "para_" prefix " " PACKAGE_VERSION \ + " (" GIT_VERSION ": " CODENAME ")" "\n" \ + "Copyright (C) 2011 Andre Noll\n" \ + "This is free software with ABSOLUTELY NO WARRANTY." \ + " See COPYING for details.\n" \ + "Written by Andre Noll.\n" \ + "Report bugs to .\n" + +/** Print out \p VERSION_TEXT and exit if version flag was given. */ +#define HANDLE_VERSION_FLAG(_prefix, _args_info_struct) \ + if (_args_info_struct.version_given) { \ + printf("%s", VERSION_TEXT(_prefix)); \ + exit(EXIT_SUCCESS); \ + } + diff --git a/write.c b/write.c index 2ea9d213..cf48922a 100644 --- a/write.c +++ b/write.c @@ -23,6 +23,7 @@ #include "write_common.h" #include "fd.h" #include "error.h" +#include "version.h" INIT_WRITE_ERRLISTS; -- 2.30.2