diff --git a/Makefile.in b/Makefile.in index ee4df722..b6616a6b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -27,16 +27,18 @@ INSTALL := @INSTALL@ INSTALL_PROGRAM := @INSTALL_PROGRAM@ INSTALL_SCRIPT := @INSTALL_SCRIPT@ INSTALL_DATA := @INSTALL_DATA@ +GIT := @GIT@ +SED := @SED@ LIB_SRCS := ZNCString.cpp Csocket.cpp znc.cpp IRCNetwork.cpp User.cpp IRCSock.cpp \ Client.cpp Chan.cpp Nick.cpp Server.cpp Modules.cpp MD5.cpp Buffer.cpp Utils.cpp \ FileUtils.cpp HTTPSock.cpp Template.cpp ClientCommand.cpp Socket.cpp SHA256.cpp \ - WebModules.cpp Listener.cpp Config.cpp ZNCDebug.cpp + WebModules.cpp Listener.cpp Config.cpp ZNCDebug.cpp version.cpp LIB_SRCS := $(addprefix src/,$(LIB_SRCS)) BIN_SRCS := src/main.cpp LIB_OBJS := $(patsubst %cpp,%o,$(LIB_SRCS)) BIN_OBJS := $(patsubst %cpp,%o,$(BIN_SRCS)) -CLEAN := znc src/*.o core core.* +CLEAN := znc src/*.o core core.* .version_extra DISTCLEAN := Makefile config.log config.status znc-buildmod .depend \ modules/.depend modules/Makefile man/Makefile znc.pc znc-uninstalled.pc @@ -55,7 +57,7 @@ E=@\# C= endif -.PHONY: all man modules clean distclean install +.PHONY: all man modules clean distclean install version_extra_recompile .SECONDARY: all: znc man modules $(LIBZNC) @@ -98,6 +100,16 @@ 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`$(GIT) --git-dir=$(srcdir)/.git describe 2> /dev/null` ]; then echo version_extra_recompile; fi) + @mkdir -p .depend src + $(E) Building core object version... + $(Q)$(CXX) $(shell $(GIT) --git-dir=$(srcdir)/.git describe 2> /dev/null | $(SED) 's/.*-\([0123456789][0123456789]*\)-g\(.*\)/-DVERSION_EXTRA="\\"-git-\1-\2\\""/') $(CXXFLAGS) -c -o $@ $< -MD -MF .depend/version.dep -MT $@ + -$(Q)$(GIT) --git-dir=$(srcdir)/.git describe > .version_extra 2> /dev/null +endif + install: znc $(LIBZNC) test -d $(DESTDIR)$(bindir) || $(INSTALL) -d $(DESTDIR)$(bindir) test -d $(DESTDIR)$(includedir)/znc || $(INSTALL) -d $(DESTDIR)$(includedir)/znc diff --git a/configure.ac b/configure.ac index 53e6c626..2ab56b9c 100644 --- a/configure.ac +++ b/configure.ac @@ -35,6 +35,7 @@ AC_PROG_SED AC_CANONICAL_HOST AC_SYS_LARGEFILE ZNC_VISIBILITY +AC_PATH_PROG([GIT], [git]) appendLib () { if test "$LIBS" != ""; then diff --git a/include/znc/main.h b/include/znc/main.h index b80b6034..bade558e 100644 --- a/include/znc/main.h +++ b/include/znc/main.h @@ -10,17 +10,7 @@ #define _MAIN_H #include - -// The following defines are for #if comparison (preprocessor only likes ints) -#define VERSION_MAJOR 0 -#define VERSION_MINOR 207 -// This one is for display purpose -#define VERSION (VERSION_MAJOR + VERSION_MINOR / 1000.0) - -// You can add -DVERSION_EXTRA="stuff" to your CXXFLAGS! -#ifndef VERSION_EXTRA -#define VERSION_EXTRA "" -#endif +#include #define NOTHING (void)0 diff --git a/include/znc/version.h b/include/znc/version.h new file mode 100644 index 00000000..d1cbd758 --- /dev/null +++ b/include/znc/version.h @@ -0,0 +1,13 @@ +#ifndef _VERSION_H +#define _VERSION_H + +// The following defines are for #if comparison (preprocessor only likes ints) +#define VERSION_MAJOR 0 +#define VERSION_MINOR 207 +// This one is for display purpose +#define VERSION (VERSION_MAJOR + VERSION_MINOR / 1000.0) + +// You can add -DVERSION_EXTRA="stuff" to your CXXFLAGS! +extern const char* ZNC_VERSION_EXTRA; + +#endif diff --git a/modules/modperl/module.h b/modules/modperl/module.h index d2cecc36..bcfa49b7 100644 --- a/modules/modperl/module.h +++ b/modules/modperl/module.h @@ -175,7 +175,7 @@ inline double GetVersion() { } inline CString GetVersionExtra() { - return VERSION_EXTRA; + return ZNC_VERSION_EXTRA; } #if HAVE_VISIBILITY #pragma GCC visibility pop diff --git a/modules/modpython/module.h b/modules/modpython/module.h index bd3d5db5..8d9ae951 100644 --- a/modules/modpython/module.h +++ b/modules/modpython/module.h @@ -215,7 +215,7 @@ inline double GetVersion() { } inline CString GetVersionExtra() { - return VERSION_EXTRA; + return ZNC_VERSION_EXTRA; } class MCString_iter { diff --git a/src/version.cpp b/src/version.cpp new file mode 100644 index 00000000..aa398c7f --- /dev/null +++ b/src/version.cpp @@ -0,0 +1,8 @@ +#include + +#ifdef VERSION_EXTRA +const char* ZNC_VERSION_EXTRA = VERSION_EXTRA; +#else +const char* ZNC_VERSION_EXTRA = ""; +#endif + diff --git a/src/znc.cpp b/src/znc.cpp index 5805f24c..bd781909 100644 --- a/src/znc.cpp +++ b/src/znc.cpp @@ -72,7 +72,7 @@ CZNC::~CZNC() { CString CZNC::GetVersion() { char szBuf[128]; - snprintf(szBuf, sizeof(szBuf), "%1.3f"VERSION_EXTRA, VERSION); + snprintf(szBuf, sizeof(szBuf), "%1.3f%s", VERSION, ZNC_VERSION_EXTRA); // If snprintf overflows (which I doubt), we want to be on the safe side szBuf[sizeof(szBuf) - 1] = '\0'; @@ -87,7 +87,7 @@ CString CZNC::GetTag(bool bIncludeVersion, bool bHTML) { } char szBuf[128]; - snprintf(szBuf, sizeof(szBuf), "ZNC %1.3f"VERSION_EXTRA" - ", VERSION); + snprintf(szBuf, sizeof(szBuf), "ZNC %1.3f%s - ", VERSION, ZNC_VERSION_EXTRA); // If snprintf overflows (which I doubt), we want to be on the safe side szBuf[sizeof(szBuf) - 1] = '\0';