]>
Commit | Line | Data |
---|---|---|
d32a59fe AS |
1 | #!/bin/sh |
2 | ||
3 | # | |
4 | # CDDL HEADER START | |
5 | # | |
6 | # This file and its contents are supplied under the terms of the | |
7 | # Common Development and Distribution License ("CDDL"), version 1.0. | |
8 | # You may only use this file in accordance with the terms of version | |
9 | # 1.0 of the CDDL. | |
10 | # | |
11 | # A full copy of the text of the CDDL should have accompanied this | |
12 | # source. A copy of the CDDL is also available via the Internet at | |
13 | # http://www.illumos.org/license/CDDL. | |
14 | # | |
15 | # CDDL HEADER END | |
16 | # | |
17 | ||
18 | # Copyright (c) 2018 by Delphix. All rights reserved. | |
19 | # Copyright (c) 2018 by Matthew Thode. All rights reserved. | |
20 | ||
21 | # | |
22 | # Generate zfs_gitrev.h. Note that we need to do this for every | |
23 | # invocation of `make`, including for incremental builds. Therefore we | |
24 | # can't use a zfs_gitrev.h.in file which would be processed only when | |
25 | # `configure` is run. | |
26 | # | |
27 | ||
28 | set -e -u | |
29 | ||
59415fc9 AS |
30 | dist=no |
31 | distdir=. | |
32 | while getopts D: flag | |
33 | do | |
34 | case $flag in | |
35 | \?) echo "Usage: $0 [-D distdir] [file]" >&2; exit 1;; | |
36 | D) dist=yes; distdir=${OPTARG};; | |
37 | esac | |
38 | done | |
39 | shift $((OPTIND - 1)) | |
40 | ||
d32a59fe AS |
41 | top_srcdir="$(dirname "$0")/.." |
42 | GITREV="${1:-include/zfs_gitrev.h}" | |
43 | ||
59415fc9 | 44 | # GITREV should be a relative path (relative to top_builddir or distdir) |
d32a59fe AS |
45 | case "${GITREV}" in |
46 | /*) echo "Error: ${GITREV} should be a relative path" >&2 | |
47 | exit 1;; | |
48 | esac | |
49 | ||
50 | ZFS_GITREV=$({ cd "${top_srcdir}" && | |
51 | git describe --always --long --dirty 2>/dev/null; } || :) | |
59415fc9 | 52 | |
88af959b | 53 | if [ -z "${ZFS_GITREV}" ] |
59415fc9 AS |
54 | then |
55 | # If the source directory is not a git repository, check if the file | |
56 | # already exists (in the source) | |
57 | if [ -f "${top_srcdir}/${GITREV}" ] | |
58 | then | |
f7d7ee05 | 59 | ZFS_GITREV=$(sed -n \ |
59415fc9 | 60 | '1s/^#define[[:blank:]]ZFS_META_GITREV "\([^"]*\)"$/\1/p' \ |
f7d7ee05 | 61 | "${top_srcdir}/${GITREV}") |
59415fc9 AS |
62 | fi |
63 | elif [ ${dist} = yes ] | |
64 | then | |
65 | # Append -dist when creating distributed sources from a git repository | |
66 | ZFS_GITREV="${ZFS_GITREV}-dist" | |
67 | fi | |
d32a59fe AS |
68 | ZFS_GITREV=${ZFS_GITREV:-unknown} |
69 | ||
70 | GITREVTMP="${GITREV}~" | |
71 | printf '#define\tZFS_META_GITREV "%s"\n' "${ZFS_GITREV}" >"${GITREVTMP}" | |
59415fc9 | 72 | GITREV="${distdir}/${GITREV}" |
d32a59fe AS |
73 | if cmp -s "${GITREV}" "${GITREVTMP}" |
74 | then | |
75 | rm -f "${GITREVTMP}" | |
76 | else | |
77 | mv -f "${GITREVTMP}" "${GITREV}" | |
78 | fi |