]> git.itanic.dy.fi Git - rrdd/commitdiff
Add automatic versioning and compiler checks
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Tue, 20 Nov 2012 16:32:28 +0000 (18:32 +0200)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Tue, 20 Nov 2012 16:32:28 +0000 (18:32 +0200)
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 <timo.t.kokkonen@iki.fi>
Makefile
main.c
mkcompile_h [new file with mode: 0755]

index 0f3d347531f2af895f60b81fa4866fb4c606b02c..36e60d5d93b50536cefc604d699ea5402d89acf5 100644 (file)
--- 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 a1d74cacd69449bf28cdeb0fa065b0e4849a186d..75eddf397076e82b0441961866f0242b3842b81b 100644 (file)
--- a/main.c
+++ b/main.c
@@ -3,6 +3,7 @@
 #include <getopt.h>
 #include <time.h>
 
+#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 (executable)
index 0000000..c142459
--- /dev/null
@@ -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
+