Path: blob/main/sys/contrib/openzfs/scripts/make_gitrev.sh
48266 views
#!/bin/sh1# SPDX-License-Identifier: CDDL-1.023#4# CDDL HEADER START5#6# This file and its contents are supplied under the terms of the7# Common Development and Distribution License ("CDDL"), version 1.0.8# You may only use this file in accordance with the terms of version9# 1.0 of the CDDL.10#11# A full copy of the text of the CDDL should have accompanied this12# source. A copy of the CDDL is also available via the Internet at13# http://www.illumos.org/license/CDDL.14#15# CDDL HEADER END16#1718# Copyright (c) 2018 by Delphix. All rights reserved.19# Copyright (c) 2018 by Matthew Thode. All rights reserved.2021#22# Generate zfs_gitrev.h. Note that we need to do this for every23# invocation of `make`, including for incremental builds. Therefore we24# can't use a zfs_gitrev.h.in file which would be processed only when25# `configure` is run.26#2728set -eu2930dist=no31distdir=.32while getopts D: flag33do34case $flag in35\?) echo "Usage: $0 [-D distdir] [file]" >&2; exit 1;;36D) dist=yes; distdir=${OPTARG};;37*) ;;38esac39done40shift $((OPTIND - 1))4142top_srcdir="$(dirname "$0")/.."43GITREV="${1:-include/zfs_gitrev.h}"4445# GITREV should be a relative path (relative to top_builddir or distdir)46case "${GITREV}" in47/*) echo "Error: ${GITREV} should be a relative path" >&248exit 1;;49*) ;;50esac5152ZFS_GITREV=$({ cd "${top_srcdir}" &&53git describe --always --long --dirty 2>/dev/null; } || :)5455if [ -z "${ZFS_GITREV}" ]56then57# If the source directory is not a git repository, check if the file58# already exists (in the source)59if [ -f "${top_srcdir}/${GITREV}" ]60then61ZFS_GITREV=$(sed -n \62'1s/^#define[[:blank:]]ZFS_META_GITREV "\([^"]*\)"$/\1/p' \63"${top_srcdir}/${GITREV}")64fi65elif [ "${dist}" = yes ]66then67# Append -dist when creating distributed sources from a git repository68ZFS_GITREV="${ZFS_GITREV}-dist"69fi70ZFS_GITREV=${ZFS_GITREV:-unknown}7172GITREVTMP="${GITREV}~"73printf '#define\tZFS_META_GITREV "%s"\n' "${ZFS_GITREV}" >"${GITREVTMP}"74GITREV="${distdir}/${GITREV}"75if cmp -s "${GITREV}" "${GITREVTMP}"76then77rm -f "${GITREVTMP}"78else79mv -f "${GITREVTMP}" "${GITREV}"80fi818283