build: provide git-head revision via githead.h
We need the git-revision for module-version checks so provide the infrastructure now and print it in log_init(). Note that the git-describe string is distributed with the tarballs so end-users will not have to generate it themself. But when building from git, the revision will be automatically updated whenever something changes. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
parent
7a9b85c306
commit
ca446c691f
1
.gitignore
vendored
1
.gitignore
vendored
@ -30,6 +30,7 @@ genshader
|
|||||||
genunifont
|
genunifont
|
||||||
src/static_shaders.c
|
src/static_shaders.c
|
||||||
src/genshader.c
|
src/genshader.c
|
||||||
|
src/githead.h
|
||||||
src/text_font_unifont_data.c
|
src/text_font_unifont_data.c
|
||||||
docs/reference/*.txt
|
docs/reference/*.txt
|
||||||
docs/reference/*.bak
|
docs/reference/*.bak
|
||||||
|
37
Makefile.am
37
Makefile.am
@ -92,6 +92,42 @@ SHL_REGISTER = \
|
|||||||
src/shl_register.h \
|
src/shl_register.h \
|
||||||
$(SHL_DLIST)
|
$(SHL_DLIST)
|
||||||
|
|
||||||
|
#
|
||||||
|
# GIT-HEAD helper
|
||||||
|
# The file ./src/githead.h contains a constant BUILD_GIT_HEAD which is defined
|
||||||
|
# to the string returned by "git describe". We need to adjust this string for
|
||||||
|
# every build and correctly rebuild any sources that depend on it. Therefore,
|
||||||
|
# you should use this file rarely as it causes rebuilds on every git-commit.
|
||||||
|
#
|
||||||
|
# We have a helper-script ./src/genversion.sh that takes as argument the header
|
||||||
|
# file and creates it if necessary. It updates it only if the new git-describe
|
||||||
|
# string is different to the old one. So the file is only modified on changes.
|
||||||
|
# Hence, we can use it as normal dependency in this Makefile.
|
||||||
|
# However, we need to run this script on _every_ "make" invocation before any
|
||||||
|
# recipy is executed. To achieve this, we use $(shell ...) and assign it to a
|
||||||
|
# "simply expanded" variable (:=) so the shell command is executed on
|
||||||
|
# variable-declaration and not during expansion.
|
||||||
|
#
|
||||||
|
# Note that we must not clean ./src/githead.h ever! If we would, a distribution
|
||||||
|
# tarball might delete that file and have no way to recreate it.
|
||||||
|
# We could delete it on something like "make maintainerclean", but then again,
|
||||||
|
# it seems unnecessary so lets simply not clean it at all.
|
||||||
|
#
|
||||||
|
# If the helper-script is executed in a directory that is not a git-repository
|
||||||
|
# (like a distribution tarball) and githead.h exists, then it does nothing as it
|
||||||
|
# expects githead.h to be correctly written by "make dist".
|
||||||
|
# However, if githead.h does not exist, it will print a warning and write
|
||||||
|
# "<unknown>" as git-revision.
|
||||||
|
# This guarantees, that githead.h is always present and has the most correct
|
||||||
|
# value that we can get under any conditions.
|
||||||
|
#
|
||||||
|
# The $(emptyvariable) expansion below is used for broken $(shell ...)
|
||||||
|
# syntax-highlighting algorithms in many existing editors.
|
||||||
|
#
|
||||||
|
|
||||||
|
EXTRA_DIST += src/genversion.sh
|
||||||
|
GITHEAD:=$(shell $(emptyvariable)"$(srcdir)/src/genversion.sh" "$(srcdir)/src/githead.h")
|
||||||
|
|
||||||
#
|
#
|
||||||
# libeloop
|
# libeloop
|
||||||
# This library contains the whole event-loop implementation of kmscon. It is
|
# This library contains the whole event-loop implementation of kmscon. It is
|
||||||
@ -372,6 +408,7 @@ kmscon_SOURCES = \
|
|||||||
$(SHL_TIMER) \
|
$(SHL_TIMER) \
|
||||||
$(SHL_HOOK) \
|
$(SHL_HOOK) \
|
||||||
$(SHL_REGISTER) \
|
$(SHL_REGISTER) \
|
||||||
|
src/githead.h \
|
||||||
src/conf.h \
|
src/conf.h \
|
||||||
src/conf.c \
|
src/conf.c \
|
||||||
src/log.h \
|
src/log.h \
|
||||||
|
62
src/genversion.sh
Executable file
62
src/genversion.sh
Executable file
@ -0,0 +1,62 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Generate $1 with:
|
||||||
|
# #define BUILD_GIT_HEAD "<git-head-revision>"
|
||||||
|
# But do not touch $1 if the git-revision is already up-to-date.
|
||||||
|
#
|
||||||
|
|
||||||
|
if test "x$1" = "x" ; then
|
||||||
|
echo "usage: ./genversion <file>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
#
|
||||||
|
# Check whether this is a valid git repository.
|
||||||
|
# Set ISGIT to 1=true or 0=false.
|
||||||
|
#
|
||||||
|
|
||||||
|
ISGIT=0
|
||||||
|
REV=`git rev-parse --git-dir 2>/dev/null`
|
||||||
|
if test "x$?" = "x0" ; then
|
||||||
|
ISGIT=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
#
|
||||||
|
# Check the old revision from $1.
|
||||||
|
#
|
||||||
|
|
||||||
|
if test -f "$1" ; then
|
||||||
|
OLDREV=`cat "$1"`
|
||||||
|
else
|
||||||
|
if test $ISGIT = 0 ; then
|
||||||
|
echo "WARNING: version file $1 is missing"
|
||||||
|
echo "#define BUILD_GIT_HEAD \"unknown-revision\""
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
OLDREV=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
#
|
||||||
|
# Check new revision from "git describe". However, if this is no valid
|
||||||
|
# git-repository, return success and do nothing.
|
||||||
|
#
|
||||||
|
|
||||||
|
if test $ISGIT = 0 ; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
NEWREV=`git describe`
|
||||||
|
NEWREV="#define BUILD_GIT_HEAD \"$NEWREV\""
|
||||||
|
|
||||||
|
#
|
||||||
|
# Exit if the file is already up to date.
|
||||||
|
# Otherwise, write the new revision into the file.
|
||||||
|
#
|
||||||
|
|
||||||
|
if test "x$OLDREV" = "x$NEWREV" ; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$NEWREV" >"$1"
|
18
src/log.c
18
src/log.c
@ -17,6 +17,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "githead.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -67,19 +68,6 @@ static void log__time(long long *sec, long long *usec)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Build-Count
|
|
||||||
* This is incremented for every build. ISO-C does not provide a method to do
|
|
||||||
* this so we default to 1 if no external build-number is specified.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* TODO: define LOG_BUILD as incremental build number */
|
|
||||||
#ifdef LOG_BUILD
|
|
||||||
static unsigned long log_build = LOG_BUILD;
|
|
||||||
#else
|
|
||||||
static unsigned long log_build = 1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Default Values
|
* Default Values
|
||||||
* Several logging-parameters may be omitted by applications. To provide sane
|
* Several logging-parameters may be omitted by applications. To provide sane
|
||||||
@ -512,6 +500,6 @@ void log_print_init(const char *appname)
|
|||||||
if (!appname)
|
if (!appname)
|
||||||
appname = "<unknown>";
|
appname = "<unknown>";
|
||||||
log_format(LOG_DEFAULT_CONF, NULL, LOG_NOTICE,
|
log_format(LOG_DEFAULT_CONF, NULL, LOG_NOTICE,
|
||||||
"%s Build #%lu %s %s", appname,
|
"%s Revision %s %s %s", appname,
|
||||||
log_build, __DATE__, __TIME__);
|
BUILD_GIT_HEAD, __DATE__, __TIME__);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user