2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk#!/bin/sh
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk
2152111779d69aefaf7cfe474d80356a5d059d54Pascal VolkSRCDIR="${1:-`pwd`}"
2152111779d69aefaf7cfe474d80356a5d059d54Pascal VolkBUILDDIR="${2:-`pwd`}"
2152111779d69aefaf7cfe474d80356a5d059d54Pascal VolkVERSION_H="dovecot-version.h"
2152111779d69aefaf7cfe474d80356a5d059d54Pascal VolkVERSION_HT="dovecot-version.h.tmp"
17aeaeec37ef11d4f9fbb80aa2583f574b4ac3bfTimo SirainenDOVECOT_BUILD_INFO=${DOVECOT_BUILD_INFO:-DOVECOT_VERSION_FULL}
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volkabspath()
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk{ #$1 the path
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk #$2 1 -> SRCDIR || 2 -> BUILDDIR
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk old=`pwd`
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk cd "${1}"
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk if [ ${2} -eq 1 ]; then
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk SRCDIR=`pwd`
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk else
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk BUILDDIR=`pwd`
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk fi
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk cd "$old"
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk}
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volkabspath "${SRCDIR}" 1
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volkabspath "${BUILDDIR}" 2
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk
8232ca302ed650200ea91cb6d5438379d187753eTimo Sirainen# when using a different BUILDDIR just copy from SRCDIR, if there is no .git
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volkif [ "${BUILDDIR}" != "${SRCDIR}" ]; then
8232ca302ed650200ea91cb6d5438379d187753eTimo Sirainen if [ ! -d "${SRCDIR}/.git" ] && [ -f "${SRCDIR}/${VERSION_H}" ]; then
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk cmp -s "${SRCDIR}/${VERSION_H}" "${BUILDDIR}/${VERSION_H}"
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk if [ $? -ne 0 ]; then
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk cp "${SRCDIR}/${VERSION_H}" "${BUILDDIR}/${VERSION_H}"
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk exit 0
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk fi
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk fi
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volkfi
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk
8232ca302ed650200ea91cb6d5438379d187753eTimo Sirainen# Don't generate dovecot-version.h if the source tree has no .git dir but
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk# a dovecot-version.h. This may be the result of a release/nightly tarball.
8232ca302ed650200ea91cb6d5438379d187753eTimo Sirainen[ ! -d "${SRCDIR}/.git" ] && [ -f "${BUILDDIR}/${VERSION_H}" ] && exit 0
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk# Lets generate the dovecot-version.h
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk[ -f "${BUILDDIR}/${VERSION_HT}" ] && rm -f "${BUILDDIR}/${VERSION_HT}"
8232ca302ed650200ea91cb6d5438379d187753eTimo Sirainenif true; then
bdf3c77e7299a2d036cc1016c77a5aa76f230fb9Timo Sirainen GITID=`git --git-dir ${SRCDIR}/.git rev-parse --short HEAD`
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk cat > "${BUILDDIR}/${VERSION_HT}" <<EOF
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk#ifndef DOVECOT_VERSION_H
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk#define DOVECOT_VERSION_H
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk
8232ca302ed650200ea91cb6d5438379d187753eTimo Sirainen#define DOVECOT_VERSION_FULL VERSION" (${GITID})"
17aeaeec37ef11d4f9fbb80aa2583f574b4ac3bfTimo Sirainen#define DOVECOT_BUILD_INFO ${DOVECOT_BUILD_INFO}
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk#endif /* DOVECOT_VERSION_H */
2152111779d69aefaf7cfe474d80356a5d059d54Pascal VolkEOF
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volkelse
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk cat > "${BUILDDIR}/${VERSION_HT}" <<EOF
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk#ifndef DOVECOT_VERSION_H
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk#define DOVECOT_VERSION_H
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk#define DOVECOT_VERSION_FULL VERSION
17aeaeec37ef11d4f9fbb80aa2583f574b4ac3bfTimo Sirainen#define DOVECOT_BUILD_INFO ${DOVECOT_BUILD_INFO}
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk#endif /* DOVECOT_VERSION_H */
2152111779d69aefaf7cfe474d80356a5d059d54Pascal VolkEOF
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volkfi
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volkcmp -s "${BUILDDIR}/${VERSION_H}" "${BUILDDIR}/${VERSION_HT}" && \
2152111779d69aefaf7cfe474d80356a5d059d54Pascal Volk rm -f "${BUILDDIR}/${VERSION_HT}" || \
0b27cde4733690450b0e8f754806b3f6ff4af722Timo Sirainen mv -f "${BUILDDIR}/${VERSION_HT}" "${BUILDDIR}/${VERSION_H}"