From 2203d6a335fe1883218a7a3037b2b01b44abfd5e Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Fri, 14 May 2021 22:49:17 +0100 Subject: [PATCH] Start using automatic git-based versioning --- .gitignore | 4 ++++ Makefile.am | 12 ++++++++++++ common.c | 20 +++++++++++++++++--- configure.ac | 7 +++++++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 5187a2b8..b78d32b7 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,7 @@ shairport-sync.core # macOS stuff .DS_Store shairport-sync.xcodeproj + +# version string generation +gitversion.h + diff --git a/Makefile.am b/Makefile.am index 16a0db74..d0a025e1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -32,6 +32,18 @@ else endif endif +# include information generated by 'git describe --dirty' if requested +if USE_GIT_VERSION +common.c: gitversion.h +gitversion.h: .git/index + echo "// Do not edit!" > gitversion.h + echo "// This file is automatically generated by 'git describe --dirty', if available." >> gitversion.h + echo -n " char git_version_string[] = \"" >> gitversion.h + git describe --dirty | tr -d '[[:space:]]' >> gitversion.h + echo "\";" >> gitversion.h +CLEANFILES += gitversion.h +endif + if USE_APPLE_ALAC shairport_sync_SOURCES += apple_alac.cpp endif diff --git a/common.c b/common.c index 69270cb9..ce43d004 100644 --- a/common.c +++ b/common.c @@ -2,7 +2,7 @@ * Utility routines. This file is part of Shairport. * Copyright (c) James Laird 2013 * The volume to attenuation function vol2attn copyright (c) Mike Brady 2014 - * Further changes and additions (c) Mike Brady 2014 -- 2019 + * Further changes and additions (c) Mike Brady 2014 -- 2021 * All rights reserved. * * Permission is hereby granted, free of charge, to any person @@ -27,6 +27,11 @@ */ #include "common.h" + +#ifdef CONFIG_USE_GIT_VERSION_STRING +#include "gitversion.h" +#endif + #include #include #include @@ -88,6 +93,8 @@ #include #endif + + #ifdef CONFIG_ALSA void set_alsa_out_dev(char *); #endif @@ -1602,9 +1609,16 @@ void pthread_cleanup_debug_mutex_unlock(void *arg) { pthread_mutex_unlock((pthre char *get_version_string() { char *version_string = malloc(1024); - if (version_string) { + if (version_string) { +#ifdef CONFIG_USE_GIT_VERSION_STRING + if (git_version_string[0] != '\0') + strcpy(version_string, git_version_string); + else +#endif strcpy(version_string, PACKAGE_VERSION); - +#ifdef CONFIG_AIRPLAY_2 + strcat(version_string, "-AirPlay2"); +#endif #ifdef CONFIG_APPLE_ALAC strcat(version_string, "-alac"); #endif diff --git a/configure.ac b/configure.ac index aa082dee..6b7c6d07 100644 --- a/configure.ac +++ b/configure.ac @@ -8,6 +8,13 @@ AC_CONFIG_SRCDIR([shairport.c]) AC_CONFIG_HEADERS([config.h]) AC_PROG_RANLIB +AC_CHECK_PROGS([GIT], [git]) +if test -n "$GIT"; then + AC_DEFINE([CONFIG_USE_GIT_VERSION_STRING], 1, [Use the version string produced by running 'git describe --dirty'.]) +fi +AM_CONDITIONAL([USE_GIT_VERSION], [test -n "$GIT"]) + + # Derived from the Avahi configure.ac file # Specifying the OS type, defaulting to linux. #