OpenZFS 4185 - add new cryptographic checksums to ZFS: SHA-512, Skein, Edon-R
[zfs.git] / config / zfs-meta.m4
blob3e1429d99d80c9a362125ebc6de01459d4a88e03
1 dnl #
2 dnl # DESCRIPTION:
3 dnl # Read meta data from the META file.  When building from a git repository
4 dnl # the ZFS_META_RELEASE field will be overwritten if there is an annotated
5 dnl # tag matching the form ZFS_META_NAME-ZFS_META_VERSION-*.  This allows
6 dnl # for working builds to be uniquely identified using the git commit hash.
7 dnl #
8 dnl #    The META file format is as follows:
9 dnl #      ^[ ]*KEY:[ \t]+VALUE$
10 dnl #
11 dnl #    In other words:
12 dnl #    - KEY is separated from VALUE by a colon and one or more spaces/tabs.
13 dnl #    - KEY and VALUE are case sensitive.
14 dnl #    - Leading spaces are ignored.
15 dnl #    - First match wins for duplicate keys.
16 dnl #
17 dnl #    A line can be commented out by preceding it with a '#' (or technically
18 dnl #    any non-space character since that will prevent the regex from
19 dnl #    matching).
20 dnl #
21 dnl # WARNING:
22 dnl #   Placing a colon followed by a space or tab (ie, ":[ \t]+") within the
23 dnl #   VALUE will prematurely terminate the string since that sequence is
24 dnl #   used as the awk field separator.
25 dnl #
26 dnl # KEYS:
27 dnl #   The following META keys are recognized:
28 dnl #     Name, Version, Release, Date, Author, LT_Current, LT_Revision, LT_Age
29 dnl #
30 dnl # Written by Chris Dunlap <cdunlap@llnl.gov>.
31 dnl # Modified by Brian Behlendorf <behlendorf1@llnl.gov>.
32 dnl #
33 AC_DEFUN([ZFS_AC_META], [
35         AH_BOTTOM([
36 #undef PACKAGE
37 #undef PACKAGE_BUGREPORT
38 #undef PACKAGE_NAME
39 #undef PACKAGE_STRING
40 #undef PACKAGE_TARNAME
41 #undef PACKAGE_VERSION
42 #undef STDC_HEADERS
43 #undef VERSION])
45         AC_PROG_AWK
46         AC_MSG_CHECKING([metadata])
48         META="$srcdir/META"
49         _zfs_ac_meta_type="none"
50         if test -f "$META"; then
51                 _zfs_ac_meta_type="META file"
53                 ZFS_META_NAME=_ZFS_AC_META_GETVAL([(Name|Project|Package)]);
54                 if test -n "$ZFS_META_NAME"; then
55                         AC_DEFINE_UNQUOTED([ZFS_META_NAME], ["$ZFS_META_NAME"],
56                                 [Define the project name.]
57                         )
58                         AC_SUBST([ZFS_META_NAME])
59                 fi
61                 ZFS_META_VERSION=_ZFS_AC_META_GETVAL([Version]);
62                 if test -n "$ZFS_META_VERSION"; then
63                         AC_DEFINE_UNQUOTED([ZFS_META_VERSION], ["$ZFS_META_VERSION"],
64                                 [Define the project version.]
65                         )
66                         AC_SUBST([ZFS_META_VERSION])
67                 fi
69                 ZFS_META_RELEASE=_ZFS_AC_META_GETVAL([Release]);
70                 if test ! -f ".nogitrelease" && git rev-parse --git-dir > /dev/null 2>&1; then
71                         _match="${ZFS_META_NAME}-${ZFS_META_VERSION}"
72                         _alias=$(git describe --match=${_match} 2>/dev/null)
73                         _release=$(echo ${_alias}|cut -f3- -d'-'|sed 's/-/_/g')
74                         if test -n "${_release}"; then
75                                 ZFS_META_RELEASE=${_release}
76                                 _zfs_ac_meta_type="git describe"
77                         else
78                                 _match="${ZFS_META_NAME}-${ZFS_META_VERSION}-${ZFS_META_RELEASE}"
79                                 _alias=$(git describe --match=${_match} 2>/dev/null)
80                                 _release=$(echo ${_alias}|cut -f3- -d'-'|sed 's/-/_/g')
81                                 if test -n "${_release}"; then
82                                         ZFS_META_RELEASE=${_release}
83                                         _zfs_ac_meta_type="git describe"
84                                 fi
85                         fi
86                 fi
88                 if test -n "$ZFS_META_RELEASE"; then
89                         AC_DEFINE_UNQUOTED([ZFS_META_RELEASE], ["$ZFS_META_RELEASE"],
90                                 [Define the project release.]
91                         )
92                         AC_SUBST([ZFS_META_RELEASE])
94                         RELEASE="$ZFS_META_RELEASE"
95                         AC_SUBST([RELEASE])
96                 fi
98                 ZFS_META_LICENSE=_ZFS_AC_META_GETVAL([License]);
99                 if test -n "$ZFS_META_LICENSE"; then
100                         AC_DEFINE_UNQUOTED([ZFS_META_LICENSE], ["$ZFS_META_LICENSE"],
101                                 [Define the project license.]
102                         )
103                         AC_SUBST([ZFS_META_LICENSE])
104                 fi
106                 if test -n "$ZFS_META_NAME" -a -n "$ZFS_META_VERSION"; then
107                                 ZFS_META_ALIAS="$ZFS_META_NAME-$ZFS_META_VERSION"
108                                 test -n "$ZFS_META_RELEASE" && 
109                                         ZFS_META_ALIAS="$ZFS_META_ALIAS-$ZFS_META_RELEASE"
110                                 AC_DEFINE_UNQUOTED([ZFS_META_ALIAS],
111                                         ["$ZFS_META_ALIAS"],
112                                         [Define the project alias string.] 
113                                 )
114                                 AC_SUBST([ZFS_META_ALIAS])
115                 fi
117                 ZFS_META_DATA=_ZFS_AC_META_GETVAL([Date]);
118                 if test -n "$ZFS_META_DATA"; then
119                         AC_DEFINE_UNQUOTED([ZFS_META_DATA], ["$ZFS_META_DATA"],
120                                 [Define the project release date.] 
121                         )
122                         AC_SUBST([ZFS_META_DATA])
123                 fi
125                 ZFS_META_AUTHOR=_ZFS_AC_META_GETVAL([Author]);
126                 if test -n "$ZFS_META_AUTHOR"; then
127                         AC_DEFINE_UNQUOTED([ZFS_META_AUTHOR], ["$ZFS_META_AUTHOR"],
128                                 [Define the project author.]
129                         )
130                         AC_SUBST([ZFS_META_AUTHOR])
131                 fi
133                 m4_pattern_allow([^LT_(CURRENT|REVISION|AGE)$])
134                 ZFS_META_LT_CURRENT=_ZFS_AC_META_GETVAL([LT_Current]);
135                 ZFS_META_LT_REVISION=_ZFS_AC_META_GETVAL([LT_Revision]);
136                 ZFS_META_LT_AGE=_ZFS_AC_META_GETVAL([LT_Age]);
137                 if test -n "$ZFS_META_LT_CURRENT" \
138                                  -o -n "$ZFS_META_LT_REVISION" \
139                                  -o -n "$ZFS_META_LT_AGE"; then
140                         test -n "$ZFS_META_LT_CURRENT" || ZFS_META_LT_CURRENT="0"
141                         test -n "$ZFS_META_LT_REVISION" || ZFS_META_LT_REVISION="0"
142                         test -n "$ZFS_META_LT_AGE" || ZFS_META_LT_AGE="0"
143                         AC_DEFINE_UNQUOTED([ZFS_META_LT_CURRENT],
144                                 ["$ZFS_META_LT_CURRENT"],
145                                 [Define the libtool library 'current'
146                                  version information.]
147                         )
148                         AC_DEFINE_UNQUOTED([ZFS_META_LT_REVISION],
149                                 ["$ZFS_META_LT_REVISION"],
150                                 [Define the libtool library 'revision'
151                                  version information.]
152                         )
153                         AC_DEFINE_UNQUOTED([ZFS_META_LT_AGE], ["$ZFS_META_LT_AGE"],
154                                 [Define the libtool library 'age' 
155                                  version information.]
156                         )
157                         AC_SUBST([ZFS_META_LT_CURRENT])
158                         AC_SUBST([ZFS_META_LT_REVISION])
159                         AC_SUBST([ZFS_META_LT_AGE])
160                 fi
161         fi
163         AC_MSG_RESULT([$_zfs_ac_meta_type])
164         ]
167 dnl # _ZFS_AC_META_GETVAL (KEY_NAME_OR_REGEX)
168 dnl #
169 dnl # Returns the META VALUE associated with the given KEY_NAME_OR_REGEX expr.
170 dnl #
171 dnl # Despite their resemblance to line noise,
172 dnl #   the "@<:@" and "@:>@" constructs are quadrigraphs for "[" and "]".
173 dnl #   <www.gnu.org/software/autoconf/manual/autoconf.html#Quadrigraphs>
174 dnl #
175 dnl # The "$[]1" and "$[]2" constructs prevent M4 parameter expansion
176 dnl #   so a literal $1 and $2 will be passed to the resulting awk script,
177 dnl #   whereas the "$1" will undergo M4 parameter expansion for the META key.
178 dnl #
179 AC_DEFUN([_ZFS_AC_META_GETVAL],
180         [`$AWK -F ':@<:@ \t@:>@+' '$[]1 ~ /^ *$1$/ { print $[]2; exit }' $META`]dnl