openh264/codec/common/generate_version.sh
Martin Storsjö 078d96bef7 Don't overwrite the git-tracked version.h
When generating a new version of the header, that includes the
actual git hash, don't overwrite the file that is tracked by git.
Instead create a new file, and include this only if the build system
indicates that it exists (by setting a define). This allows the
untouched source tree to be built from within an IDE even if make
has not been run.

This reduces the hassle with a file that needs to be ignored in the
git configuration.

The downside is that the generated file isn't used if building
from within an IDE, if the header has been updated by calling make
before (since the IDE configuration doesn't know whether the user
actually has run make). Since users of the IDE might not build via
make in the command line at all (in the same source checkout at least),
this should not be an issue in practice. The previous way things worked,
the version hash (generated by make) when used in an IDE could actually
be outdated and misleading.
2015-01-30 10:55:16 +02:00

27 lines
903 B
Bash
Executable File

#!/bin/bash
git rev-list HEAD | sort > config.git-hash
LOCALVER=`wc -l config.git-hash | awk '{print $1}'`
if [ $LOCALVER \> 1 ] ; then
VER="$(git rev-list HEAD -n 1 | cut -c 1-7)"
if git status | grep -q "modified:" ; then
VER="${VER}+M"
fi
GIT_VERSION=$VER
else
GIT_VERSION=
VER="x"
fi
GIT_VERSION='"'$GIT_VERSION'"'
rm -f config.git-hash
cat codec/common/inc/version_gen.h.template | sed "s/\$FULL_VERSION/$GIT_VERSION/g" > codec/common/inc/version_gen.h.new
if cmp codec/common/inc/version_gen.h.new codec/common/inc/version_gen.h > /dev/null 2>&1; then
# Identical to old version, don't touch it (to avoid unnecessary rebuilds)
rm codec/common/inc/version_gen.h.new
echo "Keeping existing codec/common/inc/version_gen.h"
exit 0
fi
mv codec/common/inc/version_gen.h.new codec/common/inc/version_gen.h
echo "Generated codec/common/inc/version_gen.h"