Add version number defines for libtasn1.h

Signed-off-by: Tim Rühsen <tim.ruehsen@gmx.de>
diff --git a/.gitignore b/.gitignore
index b4ffef0..eefb7b5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -114,6 +114,7 @@
 lib/gstr.lo
 lib/gstr.o
 lib/.libs/
+lib/includes/libtasn1.h
 lib/libtasn1.la
 lib/libtasn1.pc
 lib/Makefile
diff --git a/NEWS b/NEWS
index 23e2549..c1cb081 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,9 @@
 GNU Libtasn1 NEWS                                     -*- outline -*-
 
 * Noteworthy changes in release 4.14 (unreleased) [stable]
+- New version number scheme: major.minor.patch
+- New #defines for version checking: ASN1_VERSION_MAJOR, ASN1_VERSION_MINOR,
+  ASN1_VERSION_PATCH, ASN1_VERSION_NUMBER
 - Simplify ordering of SET OF elements.
 - Marked explicitly const uses of asn1_node with the introduction
   of the (compatible) asn1_node_const type.
diff --git a/configure.ac b/configure.ac
index c23ad49..3065c86 100644
--- a/configure.ac
+++ b/configure.ac
@@ -32,6 +32,16 @@
 AC_SUBST(LT_REVISION, 6)
 AC_SUBST(LT_AGE, 5)
 
+# Generate version defines for include file
+AC_SUBST([ASN1_VERSION_MAJOR], [`echo $VERSION|cut -d'.' -f1`])
+AC_SUBST([ASN1_VERSION_MINOR], [`echo $VERSION|cut -d'.' -f2`])
+# Let's activate the following line as soon as we change to extended version numbering
+#AC_SUBST([ASN1_VERSION_PATCH], [`echo $VERSION|cut -d'.' -f3`])
+AC_SUBST([ASN1_VERSION_PATCH], [`echo 0`])
+AC_SUBST([ASN1_VERSION_NUMBER], [`printf '0x%02x%02x%02x' $ASN1_VERSION_MAJOR $ASN1_VERSION_MINOR $ASN1_VERSION_PATCH`])
+AC_CONFIG_FILES([lib/includes/libtasn1.h])
+
+
 AC_PROG_CC
 gl_EARLY
 AC_PROG_YACC
@@ -53,8 +63,6 @@
 AC_CHECK_SIZEOF(unsigned long int, 4)
 AC_CHECK_SIZEOF(unsigned int, 4)
 
-sj_UPDATE_HEADER_VERSION([$srcdir/lib/includes/libtasn1.h])
-
 # For gnulib compatibility modules.
 gl_INIT
 
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 9cc5d94..1ae8203 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -17,7 +17,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
-AM_CPPFLAGS = -I$(top_srcdir)/lib/includes
+AM_CPPFLAGS = -I$(top_builddir)/lib/includes -I$(top_srcdir)/lib/includes
 
 EXTRA_DIST = asn1Coding_test.asn asn1Coding_test.asg
 
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 2a6fb84..9f11955 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -19,7 +19,8 @@
 SUBDIRS = gl
 
 AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS) $(CFLAG_VISIBILITY) $(CODE_COVERAGE_CFLAGS)
-AM_CPPFLAGS = -I$(srcdir)/gl -I$(srcdir)/includes -DASN1_BUILDING $(CODE_COVERAGE_CPPFLAGS)
+AM_CPPFLAGS = -I$(builddir)/gl -I$(srcdir)/gl -I$(builddir)/includes -I$(srcdir)/includes\
+ -DASN1_BUILDING $(CODE_COVERAGE_CPPFLAGS)
 
 include_HEADERS = includes/libtasn1.h
 
diff --git a/lib/includes/libtasn1.h b/lib/includes/libtasn1.h.in
similarity index 95%
rename from lib/includes/libtasn1.h
rename to lib/includes/libtasn1.h.in
index aaca1f2..6fb11ca 100644
--- a/lib/includes/libtasn1.h
+++ b/lib/includes/libtasn1.h.in
@@ -62,11 +62,40 @@
 /**
  * ASN1_VERSION:
  *
- * Version of the library.
+ * Version of the library as a string.
  */
-#define ASN1_VERSION "4.14"
+#define ASN1_VERSION "@VERSION@"
 
-#if defined(__GNUC__) && !defined(ASN1_INTERNAL_BUILD)
+/**
+ * ASN1_VERSION_MAJOR:
+ *
+ * Major version number of the library.
+ */
+#define ASN1_VERSION_MAJOR @ASN1_VERSION_MAJOR@
+
+/**
+ * ASN1_VERSION_MINOR:
+ *
+ * Minor version number of the library.
+ */
+#define ASN1_VERSION_MINOR @ASN1_VERSION_MINOR@
+
+/**
+ * ASN1_VERSION_PATCH:
+ *
+ * Patch version number of the library.
+ */
+#define ASN1_VERSION_PATCH @ASN1_VERSION_PATCH@
+
+/**
+ * ASN1_VERSION_NUMBER:
+ *
+ * Version number of the library as a number.
+ */
+#define ASN1_VERSION_NUMBER @ASN1_VERSION_NUMBER@
+
+
+#if defined __GNUC__ && !defined ASN1_INTERNAL_BUILD
 # define _ASN1_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
 # if _ASN1_GCC_VERSION >= 30100
 #  define _ASN1_GCC_ATTR_DEPRECATED __attribute__ ((__deprecated__))
diff --git a/m4/update-header-version.m4 b/m4/update-header-version.m4
deleted file mode 100644
index 73575a2..0000000
--- a/m4/update-header-version.m4
+++ /dev/null
@@ -1,24 +0,0 @@
-# update-header-version.m4 serial 1
-dnl Copyright (C) 2008-2014 Free Software Foundation, Inc.
-dnl This file is free software; the Free Software Foundation
-dnl gives unlimited permission to copy and/or distribute it,
-dnl with or without modifications, as long as this notice is preserved.
-
-dnl From Simon Josefsson
-
-# sj_UPDATE_HEADER_VERSION(HEADER-FILE)
-# -------------
-# Update version number in HEADER-FILE.  It searches for '_VERSION ".*"'
-# and replaces the .* part with the $PACKAGE_VERSION.
-AC_DEFUN([sj_UPDATE_HEADER_VERSION],
-[
-  # Update version number in lib/libtasn1.h.
-  if ! sed 's/_VERSION ".*"/_VERSION "'$PACKAGE_VERSION'"/' $1 > fixhdr.tmp; then
-    AC_MSG_ERROR([[*** Failed to update version number in $1...]])
-  fi
-  if cmp -s $1 fixhdr.tmp 2>/dev/null; then
-    rm -f fixhdr.tmp
-  elif ! mv fixhdr.tmp $1; then
-    AC_MSG_ERROR([[*** Failed to move fixhdr.tmp to $1...]])
-  fi
-])
diff --git a/src/Makefile.am b/src/Makefile.am
index 8db7aa4..fca9877 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -17,7 +17,8 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
-AM_CPPFLAGS = -I$(top_srcdir)/lib/includes -I$(top_builddir)/lib/gl
+AM_CPPFLAGS = -I$(top_builddir)/lib/includes -I$(top_srcdir)/lib/includes\
+ -I$(top_builddir)/lib/gl -I$(top_srcdir)/lib/gl
 
 LDADD = ../lib/libtasn1.la
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b0fe211..26d1a38 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -17,7 +17,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS) $(CFLAG_VISIBILITY)
-AM_CPPFLAGS = -I$(top_srcdir)/lib/includes
+AM_CPPFLAGS = -I$(top_builddir)/lib/includes -I$(top_srcdir)/lib/includes
 
 AM_LDFLAGS = -no-install
 LDADD = ../lib/libtasn1.la