From 5643360306f6213dd5ecf9d306566b9d99e7e09c Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 5 Jan 2009 11:41:47 +0100 Subject: [PATCH] The configure script produces include/idzebra/version.h The configure script produces include/idzebra/version.h. The function zebra_get_version returns SHA1 ID as second argument. --- configure.ac | 21 ++++++++++-- include/idzebra/.gitignore | 1 + include/idzebra/Makefile.am | 1 + include/idzebra/version.h | 49 --------------------------- include/idzebra/version.h.in | 60 +++++++++++++++++++++++++++++++++ util/mk_version.tcl | 76 ++++++++++++++++++++++++++++++++++++++++++ util/version.c | 19 ++--------- 7 files changed, 160 insertions(+), 67 deletions(-) delete mode 100644 include/idzebra/version.h create mode 100644 include/idzebra/version.h.in create mode 100644 util/mk_version.tcl diff --git a/configure.ac b/configure.ac index f989b6a..f8709ed 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,5 @@ -dnl Zebra, Index Data ApS, 1995-2008 +dnl This file is part of the Zebra server. +dnl Copyright (C) 1994-2008 Index Data dnl AC_PREREQ(2.60) AC_INIT([idzebra],[2.0.34],[zebra-help@indexdata.dk]) @@ -287,13 +288,28 @@ ZEBRA_MODULE(safari,shared,[ --enable-mod-safari Safari filter (DBC)]) dnl ------ ANSI C Header files AC_STDC_HEADERS if test "$ac_cv_header_stdc" = "no"; then - AC_MSG_WARN(Your system doesn't seem to support ANSI C) + AC_MSG_WARN([Your system does not seem to support ANSI C]) fi AC_SUBST(IDZEBRA_SRC_ROOT) AC_SUBST(IDZEBRA_BUILD_ROOT) IDZEBRA_SRC_ROOT=`cd ${srcdir}; pwd` IDZEBRA_BUILD_ROOT=`pwd` +dnl +dnl ------ versioning +dnl +WIN_FILEVERSION=`echo $PACKAGE_VERSION | $AWK 'BEGIN { FS = "."; } { m = $4; printf("%d,%d,%d,%d", $1, $2, $3 == "" ? "0" : $3, $4 == "" ? "1" : $4);}'` +AC_SUBST([WIN_FILEVERSION]) +VERSION_HEX=`echo $PACKAGE_VERSION | $AWK 'BEGIN { FS = "."; } { printf("%x", ($1 * 256 + $2) * 256 + $3);}'` +AC_SUBST([VERSION_HEX]) +if test -d ${srcdir}/.git; then + VERSION_SHA1=`git show --pretty=format:%H|head -1` +else + VERSION_SHA1=`head -1 ${srcdir}/ChangeLog|awk '{print $2}'` +fi +AC_SUBST([VERSION_SHA1]) +dnl dnl ------ Create Makefiles +dnl AC_OUTPUT([ Makefile util/Makefile @@ -332,6 +348,7 @@ AC_OUTPUT([ idzebra.spec idzebra-config-2.0 Doxyfile + include/idzebra/version.h ],[sed s%echo_source=yes%echo_source=no%g < idzebra-config-2.0 > util/idzebra-config-2.0 && chmod +x idzebra-config-2.0 util/idzebra-config-2.0]) echo \ diff --git a/include/idzebra/.gitignore b/include/idzebra/.gitignore index 23c1897..32536ef 100644 --- a/include/idzebra/.gitignore +++ b/include/idzebra/.gitignore @@ -1,3 +1,4 @@ Makefile Makefile.in +version.h *~ diff --git a/include/idzebra/Makefile.am b/include/idzebra/Makefile.am index bb430b7..4ca72a5 100644 --- a/include/idzebra/Makefile.am +++ b/include/idzebra/Makefile.am @@ -5,3 +5,4 @@ zebrainclude_HEADERS=api.h version.h res.h recctrl.h data1.h recgrs.h \ bfile.h dict.h isam-codec.h isams.h isamc.h isamb.h util.h \ snippet.h flock.h +EXTRA_DIST = version.h.in \ No newline at end of file diff --git a/include/idzebra/version.h b/include/idzebra/version.h deleted file mode 100644 index 6be4a06..0000000 --- a/include/idzebra/version.h +++ /dev/null @@ -1,49 +0,0 @@ -/* This file is part of the Zebra server. - Copyright (C) 1995-2008 Index Data - -Zebra is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later -version. - -Zebra is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -#ifndef IDZEBRA_VERSION_H -#define IDZEBRA_VERSION_H - -#include - -YAZ_BEGIN_CDECL - -#define ZEBRAVER "2.0.34" - -#define ZEBRA_FILEVERSION 2,0,34,1 - -/** \brief Returns Zebra version and system info. - \param version_str buffer for version (at least 16 bytes) - \param sys_str buffer for system info (at least 80 bytes) - \returns version as integer -*/ -YAZ_EXPORT -void zebra_get_version(char *version_str, char *sys_str); - -YAZ_END_CDECL - -#endif -/* - * Local variables: - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - * vim: shiftwidth=4 tabstop=8 expandtab - */ - diff --git a/include/idzebra/version.h.in b/include/idzebra/version.h.in new file mode 100644 index 0000000..e6118dc --- /dev/null +++ b/include/idzebra/version.h.in @@ -0,0 +1,60 @@ +/* This file is part of the Zebra server. + Copyright (C) 1995-2008 Index Data + +Zebra is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#ifndef IDZEBRA_VERSION_H +#define IDZEBRA_VERSION_H + +#include + +YAZ_BEGIN_CDECL + +/** \brief Version as string */ +#define ZEBRAVER "@VERSION@" + +/** \brief Version as integer (for comparison purposes) */ +#define ZEBRA_VERSIONL 0x@VERSION_HEX@ + +/** \brief Version for Windows DLL/EXE */ +#define ZEBRA_FILEVERSION @WIN_FILEVERSION@ + +/** \brief SHA1 ID as generated by Git */ +#define ZEBRA_VERSION_SHA1 "@VERSION_SHA1@" + +/** \brief Returns Zebra version and SHA1 ID as generated by Git + \param version_str buffer for version (at least 16 bytes) + \param sha1_str SHA1 ID. Use NULL for not getting the ID + \returns version as integer + + The sha1_str if non-NULL must point to a buffer of at least + 65 bytes (64 ID + null char). +*/ +YAZ_EXPORT +void zebra_get_version(char *version_str, char *sha1_str); + +YAZ_END_CDECL + +#endif +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/util/mk_version.tcl b/util/mk_version.tcl new file mode 100644 index 0000000..160a918 --- /dev/null +++ b/util/mk_version.tcl @@ -0,0 +1,76 @@ +#!/usr/bin/tclsh + +proc usage {} { + puts {mk_version.tcl [-v] configure.ac infile ..} + exit 1 +} + +set verbose 0 +set l [llength $argv] +set i 0 +while {$i < $l} { + set arg [lindex $argv $i] + switch -glob -- $arg { + -v { + incr verbose + } + default { + if {![info exists conffile]} { + set conffile $arg + } else { + lappend infiles $arg + } + } + } + incr i +} +if {![info exists infiles]} { + puts "mk_version.tcl: missing input file(s)" + usage +} + +set f [open $conffile r] +while {1} { + set cnt [gets $f line] + if {$cnt < 0} { + break + } + regexp {AC_INIT\([^,]+,\[([0-9.]+)\]} $line s version +} +close $f + +set maps(VERSION) $version + +set c [split $version .] + +set versionl [expr ([lindex $c 0] * 256 + [lindex $c 1]) * 256 + [lindex $c 2]] +set maps(YAZ_VERSION_HEX) [format %x $versionl] + +if {[llength $c] == 3} { + lappend c 1 +} +set maps(WIN_FILEVERSION) [join $c ,] + +set maps(VERSION_SHA1) {} + +foreach x [array names maps] { + puts "$x=$maps($x)" +} + +foreach ifile $infiles { + set if [open "${ifile}.in" r] + set of [open "${ifile}" w] + + while {1} { + set cnt [gets $if line] + if {$cnt < 0} { + break + } + foreach x [array names maps] { + regsub -all "@$x@" $line $maps($x) line + } + puts $of $line + } + close $if + close $of +} diff --git a/util/version.c b/util/version.c index c6239e0..36cbfa2 100644 --- a/util/version.c +++ b/util/version.c @@ -30,25 +30,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include -void zebra_get_version(char *version_str, char *sys_str) +void zebra_get_version(char *version_str, char *sha1_str) { if (version_str) strcpy(version_str, ZEBRAVER); - if (sys_str) - { - strcpy(sys_str, "unknown"); - -#ifdef WIN32 - strcpy(sys_str, "win32"); -#ifdef _MSC_VER - yaz_snprintf(sys_str+strlen(sys_str), 25, "; mscver %lu", - (unsigned long) _MSC_VER); -#endif -#endif -#ifdef HOST_TRIPLET - strcpy(sys_str, HOST_TRIPLET); -#endif - } + if (sha1_str) + strcpy(sha1_str, ZEBRA_VERSION_SHA1); } /* -- 1.7.10.4