From 1b230d059b14362e69537868196f778088b5bd15 Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Tue, 20 Nov 2012 18:32:28 +0200 Subject: [PATCH] Add automatic versioning and compiler checks Generate a version string from the git HEAD commit. This makes it possible to distinguish different versions of rrdd from each others. Also add compiler string check. If compiler changes, rebuild everything. Signed-off-by: Timo Kokkonen --- Makefile | 10 ++++++++-- main.c | 3 +++ mkcompile_h | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100755 mkcompile_h diff --git a/Makefile b/Makefile index 0f3d347..36e60d5 100644 --- a/Makefile +++ b/Makefile @@ -29,15 +29,21 @@ onewire_parser.so: $(ONEWIRE_PARSER_OBJS) $(QUIET_LINK)$(CC) $(CFLAGS) -lownet -shared -fPIC $< -o $@ clean: - rm -vf rrdd *~ *.o .*.d *.so + rm -vf rrdd *~ *.o .*.d *.so .version version.h .compiler_check* -.c.o: +%.o: %.c .compiler_check $(QUIET_CC)$(CC) -MMD -MF .$@.d $(CFLAGS) -c $< -o $@ $(Q)cp .$@.d .$@.P; \ sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ -e '/^$$/ d' -e 's/$$/ :/' < .$@.d >> .$@.P; \ mv .$@.P .$@.d +version.h .compiler_check: FORCE + $(Q)./mkcompile_h "$(CC) $(CFLAGS)" + +FORCE: + + TAGS: @echo -e "\tTAGS\t" @etags *.[ch] diff --git a/main.c b/main.c index a1d74ca..75eddf3 100644 --- a/main.c +++ b/main.c @@ -3,6 +3,7 @@ #include #include +#include "version.h" #include "process.h" #include "rrdtool.h" #include "parser.h" @@ -64,6 +65,8 @@ int main(int argc, char *argv[]) int sleeptime; int ret = 0; + pr_info("%s Version %s starting\n", argv[0], RRDD_VERSION); + bzero(&opts, sizeof(opts)); if (read_args(argc, argv, &opts) < 0) diff --git a/mkcompile_h b/mkcompile_h new file mode 100755 index 0000000..c142459 --- /dev/null +++ b/mkcompile_h @@ -0,0 +1,36 @@ +#!/bin/sh + +VERSION_TMP=.version +VERSION_TARGET=version.h + +VERSION_STR=$(git show | grep ^commit | sed -e s.commit\ .. | cut -b -10) + +COMPILER_STR="$1" +COMPILER_STR_TARGET=.compiler_check +COMPILER_STR_TMP=$COMPILER_CHECK.tmp + +echo > $VERSION_TMP +echo "#ifndef _VERSION_H_" >> $VERSION_TMP +echo "#define _VERSION_H_" >> $VERSION_TMP +echo >> $VERSION_TMP +echo "/* Autogenerated version.h file */" >> $VERSION_TMP +echo >> $VERSION_TMP +echo "#define RRDD_VERSION \"$VERSION_STR\"" >> $VERSION_TMP +echo >> $VERSION_TMP +echo "#endif" >> $VERSION_TMP + +if [ -f $VERSION_TARGET ] ; then + cmp -s $VERSION_TMP $VERSION_TARGET || cp $VERSION_TMP $VERSION_TARGET +else + cp $VERSION_TMP $VERSION_TARGET +fi + +echo $COMPILER_STR > $COMPILER_STR_TMP + +if [ -f $COMPILER_STR_TARGET ] ; then + cmp -s $COMPILER_STR_TMP $COMPILER_STR_TARGET || \ + cp $COMPILER_STR_TMP $COMPILER_STR_TARGET +else + cp $COMPILER_STR_TMP $COMPILER_STR_TARGET +fi + -- 2.44.0