2 ## The version.h file must be verified and generated or updated if the
3 ## git commit id (called git version here) changed since the last build
8 ## We first create variables for the current git version and
9 ## the locations of the version.h and version.h.tmpl files
11 @echo -n "Generating version.h ... "
12 @(version_h_tmpl="$(top_srcdir)/include/version.h.tmpl"; \
13 if [ -f "$${version_h_tmpl}" ]; then \
14 version_h="$(top_builddir)/include/version.h"; \
16 ## We check the git version format we will use depending on
17 ## whether or not we are in the master branch or on a tag
19 git_branch="$$(git describe --all 2>/dev/null)"; \
20 if [ -z "$${git_branch}" ]; then \
23 git_describe="$$(git describe)"; \
24 if [ "$${git_branch}" == "$${git_describe}" ] || \
25 [ "$${git_branch}" == "heads/master" ]; then \
26 git_version="$${git_describe}"; \
28 git_version="$$(git describe --long --all)"; \
32 ## If the version.h file doesn't exist or is not up to date,
33 ## We replace it by the version.h.tmpl file
35 if [ ! -e "$${version_h}" ] || \
36 [ "$${version_h_tmpl}" -nt "$${version_h}" ]; then \
37 cp "$${version_h_tmpl}" "$${version_h}"; \
39 if [ -n "$${git_version}" ]; then \
41 ## We remove the leading "v" for the version number
43 git_version="$$(echo "$${git_version}" | sed -r "s/^v([0-9])/\1/")"; \
45 ## If we have a git version, we verify that it isn't the same
46 ## as the one currently in the file (if there is one), as we
47 ## don't want to update the file if it is already up to date
49 if [ $$(grep -cE "^#define GIT_VERSION \"?$${git_version}\"?$$" "$${version_h}") -eq 0 ]; then \
50 if [ $$(grep -c "^#define GIT_VERSION" "$${version_h}") -gt 0 ]; then \
52 ## If there is already a GIT_VERSION defined,
53 ## we just replace it by the new version
55 sed -i "s'^#define GIT_VERSION.*$$'#define GIT_VERSION \"$${git_version}\"'" "$${version_h}"; \
58 ## Else, we add a GIT_VERSION define
59 ## containing our new version.
61 sed -i "s'^\(#define VERSION_H.*\)$$'\1\n\n#define GIT_VERSION \"$${git_version}\"'" "$${version_h}"; \
69 ## version.h is defined as a .PHONY file even if it's a real file as
70 ## we want our routine to be runned for each build.
74 lttnginclude_HEADERS = \
90 lttng/snapshot-internal.h \
91 lttng/health-internal.h \
92 lttng/save-internal.h \