diff --git a/Makefile.in b/Makefile.in index def8565b..7dd0fd19 100644 --- a/Makefile.in +++ b/Makefile.in @@ -101,15 +101,12 @@ src/%.o: src/%.cpp Makefile $(E) Building core object $*... $(Q)$(CXX) $(CXXFLAGS) -c -o $@ $< -MD -MF .depend/$*.dep -MT $@ -ifneq "$(GIT)" "" # If git-describe differs from .version_extra, add a phony target to dependencies, forcing version.o to be recompiled # znc-0.200-430-g80acaa7 -> -DVERSION_EXTRA="\"-git-430-80acaa7\"" -src/version.o: src/version.cpp Makefile $(shell if [ x`cat .version_extra 2> /dev/null` != x`$(srcdir)/version.sh $(GIT) 2> /dev/null` ]; then echo version_extra_recompile; fi) +src/version.cpp: Makefile version.sh $(shell if [ x`cat .version_extra 2> /dev/null` != x`$(srcdir)/version.sh '' $(GIT) 2> /dev/null` ]; then echo version_extra_recompile; fi) @mkdir -p .depend src - $(E) Building core object version... - $(Q)$(CXX) "$(shell $(srcdir)/version.sh $(GIT))" $(CXXFLAGS) -c -o $@ $< -MD -MF .depend/version.dep -MT $@ - -$(Q)$(srcdir)/version.sh $(GIT) > .version_extra 2> /dev/null -endif + $(E) Building source file version.cpp... + $(Q)$(srcdir)/version.sh "$@" "$(GIT)" > .version_extra 2> /dev/null install: znc $(LIBZNC) test -d $(DESTDIR)$(bindir) || $(INSTALL) -d $(DESTDIR)$(bindir) diff --git a/src/version.cpp b/src/version.cpp deleted file mode 100644 index a616aed3..00000000 --- a/src/version.cpp +++ /dev/null @@ -1,7 +0,0 @@ - -#ifdef VERSION_EXTRA -const char* ZNC_VERSION_EXTRA = VERSION_EXTRA; -#else -const char* ZNC_VERSION_EXTRA = ""; -#endif - diff --git a/version.sh b/version.sh index 913e85fd..3a5e4e16 100755 --- a/version.sh +++ b/version.sh @@ -1,25 +1,39 @@ #!/bin/sh -# Change into the source directory -cd `dirname $0` +# Get the path to the source directory +GIT_DIR=`dirname $0` -# Our first argument should be the path to git -GIT="$1" +# Our first argument should be the file that we write to +OUTPUT="$1" + +# Our second argument should be the path to git +GIT="$2" if [ "x$GIT" = "x" ] then - # Let's hope the best - GIT=git + EXTRA="" +else + GIT="${GIT} --git-dir=${GIT_DIR}/.git" + + # Figure out the information we need + LATEST_TAG=`${GIT} describe --abbrev=0 HEAD` + COMMITS_SINCE=`${GIT} log --format=oneline ${LATEST_TAG}..HEAD | wc -l` + SHORT_ID=`${GIT} rev-parse --short HEAD` + + # If this commit is tagged, don't print anything + # (the assumption here is: this is a release) + if [ "x$COMMITS_SINCE" = "x0" ] + then + EXTRA="" + else + EXTRA="-git-${COMMITS_SINCE}-${SHORT_ID}" + fi fi -# Figure out the information we need -LATEST_TAG=`${GIT} describe --abbrev=0 HEAD` -COMMITS_SINCE=`${GIT} log --format=oneline ${LATEST_TAG}..HEAD | wc -l` -SHORT_ID=`${GIT} rev-parse --short HEAD` - -# If this commit is tagged, don't print anything -# (the assumption here is: this is a release) -if [ "x$COMMITS_SINCE" = "x0" ] +# Generate output file, if any +if [ "x$OUTPUT" != "x" ] then - exit 0 + echo '#include ' > $OUTPUT + echo "const char* ZNC_VERSION_EXTRA = \"$EXTRA\";" >> $OUTPUT fi -echo "-DVERSION_EXTRA=\\\"-git-${COMMITS_SINCE}-${SHORT_ID}\\\"" + +echo "$EXTRA"