From 9c2375b6d4e725f0757d7df83473177234425dc4 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Mon, 4 Mar 2013 15:05:17 +0100 Subject: [PATCH] shl: move githead into a source file This moves githead.h to shl_githead.c so we can skip recompilations on GIT-HEAD changes. We only need to relink now (which we cannot skip). This speeds up build-processes considerably on slower machines. Signed-off-by: David Herrmann --- .gitignore | 2 +- Makefile.am | 37 +++++++++++++++-------------------- src/genversion.sh | 6 +++--- src/kmscon_module.c | 6 +++--- src/kmscon_module_interface.h | 4 ++-- src/shl_githead.h | 31 +++++++++++++++++++++++++++++ src/shl_log.c | 4 ++-- 7 files changed, 58 insertions(+), 32 deletions(-) create mode 100644 src/shl_githead.h diff --git a/.gitignore b/.gitignore index 7143f58..e407031 100644 --- a/.gitignore +++ b/.gitignore @@ -32,7 +32,7 @@ genshader genunifont src/static_shaders.c src/genshader.c -src/githead.h +src/shl_githead.c src/font_unifont_data.bin docs/reference/*.txt docs/reference/*.bak diff --git a/Makefile.am b/Makefile.am index bce78ed..382da61 100644 --- a/Makefile.am +++ b/Makefile.am @@ -112,12 +112,13 @@ endif # # 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. +# The file ./src/shl_githead.c contains a constant "shl_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 +# We have a helper-script ./src/genversion.sh that takes as argument the source # 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. @@ -126,17 +127,17 @@ endif # "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. +# Note that we must not clean ./src/shl_githead.c 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 -# "" as git-revision. -# This guarantees, that githead.h is always present and has the most correct +# (like a distribution tarball) and shl_githead.c exists, then it does nothing +# as it expects shl_githead.c to be correctly written by "make dist". +# However, if shl_githead.c does not exist, it will print a warning and write +# an unknown random git-revision. +# This guarantees, that shl_githead.c 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 ...) @@ -144,7 +145,7 @@ endif # EXTRA_DIST += src/genversion.sh -GITHEAD:=$(shell $(emptyvariable)"$(srcdir)/src/genversion.sh" "$(srcdir)/src/githead.h") +GITHEAD:=$(shell $(emptyvariable)"$(srcdir)/src/genversion.sh" "$(srcdir)/src/shl_githead.c") # # SHL - Static Helper Library @@ -155,6 +156,8 @@ GITHEAD:=$(shell $(emptyvariable)"$(srcdir)/src/genversion.sh" "$(srcdir)/src/gi noinst_LTLIBRARIES += libshl.la libshl_la_SOURCES = \ + src/shl_githead.h \ + src/shl_githead.c \ src/shl_dlist.h \ src/shl_array.h \ src/shl_hashtable.h \ @@ -445,7 +448,6 @@ endif mod_unifont_la_SOURCES = \ src/kmscon_module_interface.h \ - src/githead.h \ src/font_unifont.c \ src/kmscon_mod_unifont.c EXTRA_mod_unifont_la_DEPENDENCIES = $(UNIFONT_BIN) @@ -463,7 +465,6 @@ endif mod_freetype2_la_SOURCES = \ src/kmscon_module_interface.h \ - src/githead.h \ src/font_freetype2.c \ src/kmscon_mod_freetype2.c mod_freetype2_la_CPPFLAGS = \ @@ -485,7 +486,6 @@ endif mod_pango_la_SOURCES = \ src/kmscon_module_interface.h \ - src/githead.h \ src/font_pango.c \ src/kmscon_mod_pango.c mod_pango_la_CPPFLAGS = \ @@ -507,7 +507,6 @@ endif mod_bbulk_la_SOURCES = \ src/kmscon_module_interface.h \ - src/githead.h \ src/text_bbulk.c \ src/kmscon_mod_bbulk.c mod_bbulk_la_LIBADD = libshl.la @@ -523,7 +522,6 @@ endif mod_gltex_la_SOURCES = \ src/kmscon_module_interface.h \ - src/githead.h \ src/text_gltex.c \ src/static_gl.h \ src/static_gl_math.c \ @@ -548,7 +546,6 @@ endif mod_cairo_la_SOURCES = \ src/kmscon_module_interface.h \ - src/githead.h \ src/text_cairo.c \ src/kmscon_mod_cairo.c mod_cairo_la_CPPFLAGS = \ @@ -568,7 +565,6 @@ endif mod_pixman_la_SOURCES = \ src/kmscon_module_interface.h \ - src/githead.h \ src/text_pixman.c \ src/kmscon_mod_pixman.c mod_pixman_la_CPPFLAGS = \ @@ -600,7 +596,6 @@ MANPAGES += docs/man/kmscon.1 endif kmscon_SOURCES = \ - src/githead.h \ src/conf.h \ src/conf.c \ src/pty.h \ diff --git a/src/genversion.sh b/src/genversion.sh index 4d49fa1..0d392e4 100755 --- a/src/genversion.sh +++ b/src/genversion.sh @@ -2,7 +2,7 @@ # # Generate $1 with: -# #define BUILD_GIT_HEAD "" +# const char shl_git_head[] = ""; # But do not touch $1 if the git-revision is already up-to-date. # @@ -31,7 +31,7 @@ if test -f "$1" ; then else if test $ISGIT = 0 ; then echo "WARNING: version file $1 is missing" - echo "#define BUILD_GIT_HEAD \"unknown-revision\"" + echo "const char shl_git_head[] = \"UnknownRevision\";" >"$1" exit 0 fi @@ -48,7 +48,7 @@ if test $ISGIT = 0 ; then fi NEWREV=`git describe` -NEWREV="#define BUILD_GIT_HEAD \"$NEWREV\"" +NEWREV="const char shl_git_head[] = \"$NEWREV\";" # # Exit if the file is already up to date. diff --git a/src/kmscon_module.c b/src/kmscon_module.c index 471f5af..2bf0576 100644 --- a/src/kmscon_module.c +++ b/src/kmscon_module.c @@ -30,10 +30,10 @@ #include #include #include -#include "githead.h" #include "kmscon_module.h" #include "kmscon_module_interface.h" #include "shl_dlist.h" +#include "shl_githead.h" #include "shl_log.h" #include "shl_misc.h" @@ -66,9 +66,9 @@ int kmscon_module_open(struct kmscon_module **out, const char *file) goto err_unload; } - if (strcmp(module->info.githead, BUILD_GIT_HEAD)) { + if (strcmp(module->info.githead, shl_git_head)) { log_error("incompatible module %s (%s != %s)", - file, module->info.githead, BUILD_GIT_HEAD); + file, module->info.githead, shl_git_head); ret = -EFAULT; goto err_unload; } diff --git a/src/kmscon_module_interface.h b/src/kmscon_module_interface.h index 8203a34..f13f724 100644 --- a/src/kmscon_module_interface.h +++ b/src/kmscon_module_interface.h @@ -32,9 +32,9 @@ #include #include -#include "githead.h" #include "kmscon_module.h" #include "shl_dlist.h" +#include "shl_githead.h" #include "shl_misc.h" struct kmscon_module_info { @@ -59,7 +59,7 @@ struct kmscon_module { #define KMSCON_MODULE(_init, _load, _unload, _exit) \ struct kmscon_module module = { \ .info = { \ - .githead = BUILD_GIT_HEAD, \ + .githead = shl_git_head, \ .date = __DATE__, \ .time = __TIME__, \ .init = _init, \ diff --git a/src/shl_githead.h b/src/shl_githead.h new file mode 100644 index 0000000..a368cba --- /dev/null +++ b/src/shl_githead.h @@ -0,0 +1,31 @@ +/* + * shl - GIT-HEAD + * + * Copyright (c) 2011-2013 David Herrmann + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef SHL_GITHEAD_H +#define SHL_GITHEAD_H + +extern const char shl_git_head[]; + +#endif /* SHL_GITHEAD_H */ diff --git a/src/shl_log.c b/src/shl_log.c index d35a31f..5b726a4 100644 --- a/src/shl_log.c +++ b/src/shl_log.c @@ -19,7 +19,7 @@ #include #include #include -#include "githead.h" +#include "shl_githead.h" #include "shl_log.h" #include "shl_misc.h" @@ -505,5 +505,5 @@ void log_print_init(const char *appname) appname = ""; log_format(LOG_DEFAULT_CONF, NULL, LOG_NOTICE, "%s Revision %s %s %s", appname, - BUILD_GIT_HEAD, __DATE__, __TIME__); + shl_git_head, __DATE__, __TIME__); }