From e4a02d440d9d3d28d56bf9ba27a14eca238f341d Mon Sep 17 00:00:00 2001 From: "Peter W. Draper" <p.w.draper@durham.ac.uk> Date: Mon, 20 Apr 2015 17:10:19 +0100 Subject: [PATCH] Create an include file with more usual defines for the various versions. Tidy up autoconf to keep simple. Fix dependencies so that we do not keep rebuilding library and examples. Former-commit-id: ebff646b432b6982965d059c8e54a24969575fcd --- .gitignore | 2 ++ configure.ac | 18 ++--------- examples/test.c | 2 +- src/Makefile.am | 31 +++++++++--------- src/git_revision.c | 39 +++++++++++++++++++++++ src/{git_revision.h => git_revision.h.in} | 11 ++++--- 6 files changed, 66 insertions(+), 37 deletions(-) create mode 100644 src/git_revision.c rename src/{git_revision.h => git_revision.h.in} (77%) diff --git a/.gitignore b/.gitignore index cb8e018ccf..c1a56cc40c 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,8 @@ config.sub ltmain.sh libtool +src/git_revision.h +swift*.tar.gz doc/doxyfile.stamp doc/html/ doc/latex/ diff --git a/configure.ac b/configure.ac index 122d72c82b..0745d1f84b 100644 --- a/configure.ac +++ b/configure.ac @@ -238,21 +238,9 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM( [AC_DEFINE(HAVE__RTC,1,[Define if you have the UNICOS _rtc() intrinsic.])],[rtc_ok=no]) AC_MSG_RESULT($rtc_ok) -#Check for git -AC_PATH_PROG(gitrevisioncommand, git) - -# If the git command exists and we are in a directory generated by Git -AM_CONDITIONAL(HAVE_GIT_WC, test "X$gitrevisioncommand" != "X" && test `$gitrevisioncommand describe --abbrev=8 --always --tags --dirty 2>&1 | sed -n 1p | cut -f 1 -d " "` != "fatal:") - -# Generate the git revision command: either a call to git or a call to print the pre-generated file -if test "X$gitrevisioncommand" = "X" || test `$gitrevisioncommand describe --abbrev=8 --always --tags --dirty 2>&1 | sed -n 1p | cut -f 1 -d " "` = "fatal:"; then -my_git_revision="echo `cat src/git_revision` '\'" -else -my_git_revision="echo `git describe --abbrev=8 --always --tags --dirty` '\'" -fi -AC_SUBST(my_git_revision) - - +# Check for git, needed for revision stamps. +AC_PATH_PROG([GIT_CMD], [git]) +AC_SUBST([GIT_CMD]) # Make the documentation. DX_INIT_DOXYGEN(libswift,doc/Doxyfile,doc/) diff --git a/examples/test.c b/examples/test.c index 93b7703db0..a8268ab61e 100644 --- a/examples/test.c +++ b/examples/test.c @@ -573,7 +573,7 @@ int main ( int argc , char *argv[] ) { #endif /* Greeting message */ - message( "This is SWIFT version %s\n", git_revision()); + message( "This is %s\n", package_version() ); /* Init the space. */ bzero( &s , sizeof(struct space) ); diff --git a/src/Makefile.am b/src/Makefile.am index 783220aa28..d992294f4a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -22,6 +22,9 @@ AM_CFLAGS = -DTIMER -DCOUNTER -DCPU_TPS=2.30e9 # Assign a "safe" version number AM_LDFLAGS = $(LAPACK_LIBS) $(BLAS_LIBS) $(HDF5_LDFLAGS) -version-info 0:0:0 # -fsanitize=address +# The git command, if available. +GIT_CMD = @GIT_CMD@ + # Build the libswiftsim library lib_LTLIBRARIES = libswiftsim.la # Build a MPI-enabled version too? @@ -32,7 +35,7 @@ endif # List required headers include_HEADERS = space.h runner.h queue.h task.h lock.h cell.h part.h const.h \ engine.h swift.h serial_io.h timers.h debug.h scheduler.h proxy.h parallel_io.h \ - common_io.h multipole.h git_revision.h + common_io.h multipole.h # Common source files AM_SOURCES = space.c runner.c queue.c task.c cell.c engine.c \ @@ -53,20 +56,16 @@ libswiftsim_mpi_la_CFLAGS = $(AM_CFLAGS) -DWITH_MPI libswiftsim_mpi_la_SHORTNAME = mpi -# Git revision -# Generate a file with the Git revision chain using the pre-defined command -git_revision.c: GIT_REV_CHAIN - echo 'const char* git_revision(void) { const char* Git_Revision = "\' > git_revision.c - @my_git_revision@ >> git_revision.c - echo '"; return Git_Revision; }' >> git_revision.c - -# If we are in a git directory save the revision number -if HAVE_GIT_WC -git_revision: GIT_REV_CHAIN - @my_git_revision@ > git_revision -endif +# Git revision, if any sources change then update the git_revision.h file. +git_revision.h: git_revision.h.in $(AM_SOURCES) $(include_HEADERS) $(noinst_HEADERS) + if test "X$(GIT_CMD)" != "X"; then \ + GIT_REVISION=`git describe --abbrev=8 --always --tags --dirty`; \ + sed -e "s,@PACKAGE_VERSION\@,$(PACKAGE_VERSION)," \ + -e "s,@GIT_REVISION\@,$${GIT_REVISION}," git_revision.h.in > git_revision.h; \ + fi -GIT_REV_CHAIN: +# Make sure git_revision is built first. +BUILT_SOURCES = git_revision.h -BUILT_SOURCES=git_revision.c -EXTRA_DIST=git_revision +# And distribute the built file. +EXTRA_DIST = git_revision.h git_revision.h.in diff --git a/src/git_revision.c b/src/git_revision.c new file mode 100644 index 0000000000..958086bf5f --- /dev/null +++ b/src/git_revision.c @@ -0,0 +1,39 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Coypright (c) 2012 Matthieu Schaller (matthieu.schaller@durham.ac.uk). + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + ******************************************************************************/ + +#include <stdio.h> +#include "git_revision.h" + +const char* git_revision( void ) +{ + static const char *revision = GIT_REVISION; + return revision; +} + +const char* package_version( void ) +{ + static char buf[256]; + static int initialised = 0; + if ( ! initialised ) { + sprintf( buf, "SWIFT version: %s, at revision: %s", + PACKAGE_VERSION, GIT_REVISION ); + initialised = 1; + } + return buf; +} diff --git a/src/git_revision.h b/src/git_revision.h.in similarity index 77% rename from src/git_revision.h rename to src/git_revision.h.in index aa4b9df669..8861a225c0 100644 --- a/src/git_revision.h +++ b/src/git_revision.h.in @@ -1,6 +1,7 @@ /******************************************************************************* * This file is part of SWIFT. - * Coypright (c) 2012 Matthieu Schaller (matthieu.schaller@durham.ac.uk). + * Copyright (c) 2012 Matthieu Schaller (matthieu.schaller@durham.ac.uk). + * Copyright (c) 2015 Peter W. Draper (p.w.draper@durham.ac.uk). * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published @@ -21,13 +22,13 @@ /** * @file git_revision.h - * @brief Git revision hash key. + * @brief Package version and git revision sha. */ +#define PACKAGE_VERSION "@PACKAGE_VERSION@" +#define GIT_REVISION "@GIT_REVISION@" +const char* package_version(void); const char* git_revision(void); - - - #endif /* GIT_REVISION_H */ -- GitLab