common: support custom, extra information for build's version
[babeltrace.git] / src / common / Makefile.am
CommitLineData
056632bf 1AM_CPPFLAGS += -DBABELTRACE_PLUGINS_DIR=\"$(BABELTRACE_PLUGINS_DIR)\"
578e048b
MJ
2
3noinst_LTLIBRARIES = libbabeltrace2-common.la
4
5libbabeltrace2_common_la_SOURCES = \
578e048b 6 assert.c \
6162e6b7 7 assert.h \
578e048b 8 common.c \
6162e6b7
MJ
9 common.h \
10 uuid.c \
11 uuid.h
578e048b
MJ
12
13noinst_HEADERS = \
14 align.h \
578e048b 15 list.h \
91d81473 16 macros.h \
578e048b 17 mmap-align.h \
89e18e1e
PP
18 safe.h
19
20# The following section is based on a similar feature in LTTng-tools.
578e048b
MJ
21
22##
23## This target generates an include file that contains the git version
24## string of the current branch, it must be continuously updated when
25## we build in the git repo and shipped in dist tarballs to reflect the
26## status of the tree when it was generated. If the tree is clean and
27## the current commit is tag a starting with "v", consider this a
28## release version and set an empty git version.
29##
30## Here is what the inline script does:
31##
32## First, delete any stale "version.i.tmp" file.
33##
34## If "bootstrap" and ".git" exists in the top source directory and the git
35## executable is available, get the current git version string in the form:
36##
37## "latest_tag"(-"number_of_commits_on_top")(-g"latest_commit_hash")(-dirty)
38##
39## And store it in "version.i.tmp", if the current commit is tagged, the tag
40## starts with "v" and the tree is clean, consider this a release version and
41## overwrite the git version with an empty string in "version.i.tmp".
42##
43## If we don't have a "version.i.tmp" nor a "version.i", generate an empty
89e18e1e
PP
44## string as a failover. If a "version.i" is present, for example when building
45## from a distribution tarball, get the git_version using grep.
578e048b 46##
89e18e1e
PP
47## Fetch the BT_VERSION_EXTRA_NAME define from "version/extra_version_name" and output it
48## to "version.i.tmp".
49##
50## Fetch the BT_VERSION_EXTRA_DESCRIPTION define from "version/extra_version_description",
51## sanitize and format it with a sed script to replace all non-alpha-numeric values
52## with "-" and join all lines by replacing "\n" with litteral string c-style "\n" and
53## output it to "version.i.tmp".
54##
55## Repeat the same logic for the "version/extra_patches" directory.
56## Data fetched from "version/extra_patches" must be sanitized and
57## formatted.
58## The data is fetched using "ls" with an ignore pattern for the README.adoc file.
59## The sanitize step uses sed with a script to replace all
60## non-alpha-numeric values, except " " (space), to "-".
61## The formatting step uses sed with a script to join all lines
62## by replacing "\n" with litteral string c-style "\n".
63##
64## If we don't have a "version.i" or we have both files (version.i, version.i.tmp)
65## and they are different, copy "version.i.tmp" over "version.i".
66## This way the dependent targets are only rebuilt when the git version
67## string or either one of extra version string change.
578e048b 68##
578e048b
MJ
69version_verbose = $(version_verbose_@AM_V@)
70version_verbose_ = $(version_verbose_@AM_DEFAULT_V@)
89e18e1e 71version_verbose_0 = @echo " GEN " $@;
578e048b
MJ
72
73version.i:
74 $(version_verbose)rm -f version.i.tmp; \
89e18e1e
PP
75 if (test ! -f version.i && test -f "$(top_srcdir)/include/version.i"); then \
76 cp "$(top_srcdir)/include/version.i" version.i; \
77 fi; \
578e048b
MJ
78 if (test -r "$(top_srcdir)/bootstrap" && test -r "$(top_srcdir)/.git") && \
79 test -x "`which git 2>&1;true`"; then \
80 GIT_VERSION_STR="`cd "$(top_srcdir)" && git describe --tags --dirty`"; \
81 GIT_CURRENT_TAG="`cd "$(top_srcdir)" && git describe --tags --exact-match --match="v[0-9]*" HEAD 2> /dev/null`"; \
89e18e1e 82 echo "#define BT_VERSION_GIT \"$$GIT_VERSION_STR\"" > version.i.tmp; \
578e048b
MJ
83 if ! $(GREP) -- "-dirty" version.i.tmp > /dev/null && \
84 test "x$$GIT_CURRENT_TAG" != "x"; then \
89e18e1e 85 echo "#define BT_VERSION_GIT \"\"" > version.i.tmp; \
578e048b
MJ
86 fi; \
87 fi; \
88 if test ! -f version.i.tmp; then \
89e18e1e
PP
89 if test -f version.i; then \
90 $(GREP) "^#define \bBT_VERSION_GIT\b.*" version.i > version.i.tmp; \
91 else \
92 echo '#define BT_VERSION_GIT ""' > version.i.tmp; \
578e048b 93 fi; \
89e18e1e
PP
94 fi; \
95 echo "#define BT_VERSION_EXTRA_NAME \"`$(SED) -n '1p' "$(top_srcdir)/version/extra_version_name" 2> /dev/null`\"" >> version.i.tmp; \
96 echo "#define BT_VERSION_EXTRA_DESCRIPTION \"`$(SED) -E ':a ; N ; $$!ba ; s/[^a-zA-Z0-9 \n\t\.,]/-/g ; s/\r{0,1}\n/\\\n/g' "$(top_srcdir)/version/extra_version_description" 2> /dev/null`\"" >> version.i.tmp; \
97 echo "#define BT_VERSION_EXTRA_PATCHES \"`ls --ignore='README.adoc' -1 "$(top_srcdir)/version/extra_patches" | $(SED) -E ':a ; N ; $$!ba ; s/[^a-zA-Z0-9 \n\t\.]/-/g ; s/\r{0,1}\n/\\\n/g' 2> /dev/null`\"" >> version.i.tmp; \
98 if test ! -f version.i || \
578e048b
MJ
99 test x"`cat version.i.tmp`" != x"`cat version.i`"; then \
100 mv version.i.tmp version.i; \
101 fi; \
102 rm -f version.i.tmp; \
103 true
104
105##
106## version.i is defined as a .PHONY target even if it's a real file,
107## we want the target to be re-run on every make.
108##
109.PHONY: version.i
110
111CLEANFILES = version.i.tmp
112
113##
114## Only clean "version.i" on dist-clean, we need to keep it on regular
115## clean when it's part of a dist tarball.
116##
117DISTCLEANFILES = version.i
89e18e1e
PP
118
119noinst_HEADERS += version.h version.i
This page took 0.05433 seconds and 4 git commands to generate.