--- a/Makefile.am
+++ b/Makefile.am
@@ -1,10 +1,12 @@
 ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
 
+SUBDIRS = . docs
+
 # Installation directories.
 pkgconfigdir     = $(libdir)/pkgconfig
 GEXIV2_publicdir = $(includedir)/gexiv2
 girdir           = $(datadir)/gir-1.0
-typelibdir       = $(datadir)/gir-1.0
+typelibdir       = $(libdir)/girepository-1.0
 py2gidir         = $(PYTHON2_GIDIR)
 py3gidir         = $(PYTHON3_GIDIR)
 vapidir          = $(datadir)/vala/vapi
@@ -45,20 +47,21 @@ endif
 vapi: gexiv2.vapi
 
 if ENABLE_VAPIGEN
-gexiv2.vapi: gexiv2_vapi.stamp
-	@true
-
 gexiv2_vapi.stamp: $(top_builddir)/GExiv2-0.10.gir $(abs_top_srcdir)/vapi/GExiv2-0.10.metadata $(abs_top_srcdir)/vapi/gexiv2-custom.vala
 	rm -f $(@F)
 	$(AM_V_GEN)$(VAPIGEN) --metadatadir=$(abs_top_srcdir)/vapi \
 			      --library=gexiv2 \
 			      $(top_builddir)/GExiv2-0.10.gir $(abs_top_srcdir)/vapi/gexiv2-custom.vala
 	echo timestmap > $(@F)
+endif
+
+gexiv2.vapi: gexiv2_vapi.stamp
+	@true
+
+CLEANFILES = gexiv2.vapi gexiv2_vapi.stamp
 
 dist_vapi_DATA = gexiv2.vapi
 EXTRA_DIST += $(top_srcdir)/vapi/GExiv2-0.10.metadata gexiv2.vapi gexiv2_vapi.stamp $(top_srcdir)/vapi/gexiv2-custom.vala
-DISTCLEANFILES = gexiv2.vapi gexiv2_vapi.stamp
-endif
 
 GEXIV2_GIRHEADERS = \
 	$(srcdir)/gexiv2/gexiv2.h \
@@ -97,18 +100,7 @@ if PLATFORM_WIN32
 no_undefined = -no-undefined
 endif
 
-# REQUIRED_CFLAGS absolutely get appended to CFLAGS, whatever the
-# the value of CFLAGS in the environment.
-REQUIRED_CXXFLAGS=
-
-# Because -fPIC can interfere with compilation on 32-bit platforms but
-# is absolutely necessary for AMD64, we check what the target machine's
-# word size is, and set our required flags based upon that.
-if WORD_64
-REQUIRED_CXXFLAGS += -fPIC -DPIC
-endif
-
-AM_CXXFLAGS = $(REQUIRED_CXXFLAGS) -I$(top_builddir)/gexiv2 $(WARN_CXXFLAGS)
+AM_CXXFLAGS = -I$(top_builddir)/gexiv2 $(WARN_CXXFLAGS)
 
 $(GEXIV2_sources): gexiv2/gexiv2-version.h
 
@@ -130,22 +122,9 @@ clean-local:
 	rm -rf test/python/gi test/python/__pycache__
 
 # Tests and utilities #
+#
 
-if ENABLE_TESTS
-
-tests: test/gexiv2-dump test/python2 test/python3
-
-test/gexiv2-dump: test/gexiv2-dump.vala
-	valac -g --enable-checking --vapidir=. --pkg gexiv2 $< -o $@
-
-test/python/gi/overrides/GExiv2.py:
-	[ -d $(dir $@) ] || mkdir -p $(dir $@)
-	ln -sf ../../../../GExiv2.py $@
-
-test/python%: $(TYPELIB_FILES) test/python/gi/overrides/GExiv2.py
-	LD_LIBRARY_PATH=.libs GI_TYPELIB_PATH=. PYTHONPATH=test/python python$* -m unittest gexiv2
-
-endif
+include check.am
 
 # Optional Introspection #
 
@@ -168,5 +147,5 @@ GExiv2_@GIR_VERSION_U@_gir_NAMESPACE = G
 GExiv2_@GIR_VERSION_U@_gir_VERSION = $(GIR_VERSION)
 INTROSPECTION_GIRS += GExiv2-$(GIR_VERSION).gir
 
-CLEANFILES = $(gir_DATA) $(typelib_DATA)
+CLEANFILES += $(gir_DATA) $(typelib_DATA)
 endif
--- /dev/null
+++ b/check.am
@@ -0,0 +1,42 @@
+TESTS_ENVIRONMENT = \
+	G_SLICE=always-malloc \
+	LD_LIBRARY_PATH=$(top_builddir)/.libs:$(LD_LIBRARY_PATH) \
+	GI_TYPELIB_PATH=$(top_builddir) \
+	PYTHONPATH=$(top_srcdir)/test/python \
+	MALLOC_CHECK_=2 \
+	MALLOC_PERTURB_=$$((RANDOM % 255))
+
+tests: check
+
+TESTS = test/gexiv2-regression
+
+check_PROGRAMS = test/gexiv2-regression
+
+test_gexiv2_regression_SOURCES = test/gexiv2-regression.c
+
+if PYTHON2_PATH
+TESTS += test/python2-test
+endif
+
+if PYTHON3_PATH
+TESTS += test/python3-test
+endif
+
+if HAVE_VALAC
+check_PROGRAMS += test/gexiv2-dump
+test_gexiv2_dump_SOURCES = test/gexiv2-dump.vala
+endif
+
+AM_VALAFLAGS = --pkg gexiv2 --pkg glib-2.0 --vapidir=$(top_srcdir)
+
+LDADD = \
+	$(top_builddir)/libgexiv2.la \
+	$(GLIB_LIBS) $(EXIV2_LIBS)
+AM_CFLAGS = \
+	$(GLIB_CFLAGS) $(EXIV2_CFLAGS) \
+	-I $(top_srcdir) -DSAMPLE_PATH="\"$(abs_top_srcdir)/test\""
+
+EXTRA_DIST += \
+	test/sample-author-badencoding.jpg \
+	test/CaorVN.jpeg
+
--- a/configure.ac
+++ b/configure.ac
@@ -1,15 +1,26 @@
-AC_INIT([gexiv2], [0.10.4], [gexiv2-list@gnome.org], [gexiv2], [https://wiki.gnome.org/Projects/gexiv2])
-AC_PREREQ(2.54)
+AC_INIT([gexiv2],
+        [0.10.4],
+        [https://bugzilla.gnome.org/enter_bug.cgi?product=gexiv2],
+        [gexiv2],
+        [https://wiki.gnome.org/Projects/gexiv2])
+AC_PREREQ([2.69])
 
 AC_CONFIG_MACRO_DIR([m4])
 
 # Will install auxiliary build tools (depcomp, install-sh, missing...) under build-aux/
 AC_CONFIG_AUX_DIR([build-aux])
-AM_INIT_AUTOMAKE([1.11 -Wall no-define foreign dist-xz no-dist-gzip tar-ustar subdir-objects])
+AM_INIT_AUTOMAKE([1.11 -Wall no-define foreign dist-xz no-dist-gzip tar-ustar
+                  subdir-objects -Wno-portability])
 
 AM_MAINTAINER_MODE([enable])
 AM_SILENT_RULES([yes])
 
+##############
+# Debug Mode #
+##############
+
+AX_CHECK_ENABLE_DEBUG([no])
+
 AM_PROG_AR
 LT_PREREQ([2.2])
 LT_INIT([disable-static win32-dll])
@@ -89,37 +100,20 @@ PKG_CHECK_MODULES(EXIV2,
                   ,
                   AC_MSG_ERROR([exiv2 is required. Please install it.]))
 
-##############
-# Debug Mode #
-##############
-
-AC_MSG_CHECKING([debugging mode])
-AC_ARG_ENABLE(debug,
-              [  --enable-debug          enable debug mode [[default=no]]],
-              if eval "test x$enable_debug = xyes"; then
-              DEBUG_CFLAGS="-O0"
-              fi)
-
-if test -n "$DEBUG_CFLAGS"; then
-    AC_MSG_RESULT([yes])
-    if test -z "$CXXFLAGS"; then
-        CXXFLAGS="-O0 -g -pipe -nostdlib -shared"
-    else
-        CXXFLAGS="$DEBUG_CFLAGS $CXXFLAGS"
-    fi
-else
-    AC_MSG_RESULT([no])
-    if test -z "$CXXFLAGS"; then
-        CXXFLAGS="-O2 -g -pipe -nostdlib -shared"
-    fi
-fi
-
 #################
 # Introspection #
 #################
 
 GOBJECT_INTROSPECTION_CHECK([0.6.4])
 
+AC_PATH_PROGS([PYTHON2_PATH],[python2],[:])
+AC_SUBST(PYTHON2_PATH)
+AM_CONDITIONAL([PYTHON2_PATH], [test "x$PYTHON2_PATH" != "x:"])
+
+AC_PATH_PROGS([PYTHON3_PATH],[python3],[:])
+AC_SUBST(PYTHON3_PATH)
+AM_CONDITIONAL([PYTHON3_PATH], [test "x$PYTHON3_PATH" != "x:"])
+
 AC_ARG_WITH([python2-girdir],
             AS_HELP_STRING([--with-python2-girdir],
                              [Set the GI override file install dir]),
@@ -134,22 +128,28 @@ AC_ARG_WITH([python3-girdir],
 
 enable_python2="no (introspection disabled)"
 enable_python3="no (introspection disabled)"
-if test "x$found_introspection" = "xyes"; then
+PYTHON_CODE="import gi; print(gi._overridesdir)"
+AS_IF([test "x$found_introspection" = "xyes"],
+      [
     # Used to determine where Python wants the .gi file to be installed ...
     # if Python is not installed, PYTHON2 and PYTHON3 will be empty
-    PYTHON="import gi; print(gi._overridesdir)"
     AS_IF([test "x$ac_py2girdir" = "x"],
     [
-        PYTHON2_GIDIR=$(python2 -c "$PYTHON")
+        AS_IF([test "x$PYTHON2_PATH" != "x:"],
+              [PYTHON2_GIDIR=$($PYTHON2_PATH -c "$PYTHON_CODE")],
+              [PYTHON2_GIDIR=""])
     ],
     [
         PYTHON2_GIDIR=$ac_py2girdir
     ])
     AC_MSG_RESULT([Python2 GObject Introspection directory: $PYTHON2_GIDIR])
 
+
     AS_IF([test "x$ac_py3girdir" = "x"],
     [
-        PYTHON3_GIDIR=$(python3 -c "$PYTHON")
+        AS_IF([test "x$PYTHON3_PATH" != "x:"],
+              [PYTHON3_GIDIR=$($PYTHON3_PATH -c "$PYTHON_CODE")],
+              [PYTHON3_GIDIR=""])
     ],
     [
         PYTHON3_GIDIR=$ac_py3girdir
@@ -163,7 +163,7 @@ if test "x$found_introspection" = "xyes"
 
     AC_SUBST(PYTHON2_GIDIR)
     AC_SUBST(PYTHON3_GIDIR)
-fi
+    ])
 AM_CONDITIONAL(HAS_PYTHON2, test "x$PYTHON2_GIDIR" != "x")
 AM_CONDITIONAL(HAS_PYTHON3, test "x$PYTHON3_GIDIR" != "x")
 
@@ -171,32 +171,8 @@ AM_CONDITIONAL(HAS_PYTHON3, test "x$PYTH
 # Tests and utilities #
 #######################
 
-AC_ARG_ENABLE(tests, [  --enable-tests          enable tests and utilities (requires Vala) [[default=no]]],
-              if eval "test x$enable_tests = xno"; then
-              enable_tests=no
-              else
-              enable_tests=yes
-              fi,
-              enable_tests=no)
-
-if test "x$enable_tests" != "xno"; then
-    AC_CHECK_TOOL([VALAC], [valac], [:])
-    if test "x$VALAC" = "x:"; then
-        enable_tests="no (missing valac)"
-    fi
-fi
-AM_CONDITIONAL(ENABLE_TESTS, test "x$enable_tests" = "xyes")
-
-AC_MSG_CHECKING([enable tests])
-AC_MSG_RESULT([$enable_tests])
-
-###################
-# Check Word Size #
-###################
-
-AC_CHECK_SIZEOF([int *])
-AC_SUBST(SIZEOF_INT_P)
-AM_CONDITIONAL(WORD_64, test "x$SIZEOF_INT_P" = "x8" )
+AC_CHECK_TOOL([VALAC], [valac], [:])
+AM_CONDITIONAL([HAVE_VALAC], [test "x$VALAC" != "x:"])
 
 ###########################
 # Check target architecture
@@ -211,29 +187,6 @@ case x"$target" in
 esac
 AC_MSG_RESULT([$target_or_host])
 
-case "$target_or_host" in
-    i*86-*-*)
-        have_x86=yes
-        AC_DEFINE(ARCH_X86, 1, [Define to 1 if you are compiling for ix86.])
-    ;;
-    x86_64-*-*)
-        have_x86=yes
-        AC_DEFINE(ARCH_X86, 1, [Define to 1 if you are compiling for ix86.])
-        AC_DEFINE(ARCH_X86_64, 1, [Define to 1 if you are compiling for amd64.])
-    ;;
-    ppc-*-* | powerpc-*)
-        have_ppc=yes
-        AC_DEFINE(ARCH_PPC, 1, [Define to 1 if you are compiling for PowerPC.])
-    ;;
-    ppc64-*-* | powerpc64-*)
-        have_ppc=yes
-        AC_DEFINE(ARCH_PPC, 1, [Define to 1 if you are compiling for PowerPC.])
-        AC_DEFINE(ARCH_PPC64, 1, [Define to 1 if you are compiling for PowerPC64.])
-    ;;
-    *)
-    ;;
-esac
-
 #################
 # Check for Win32
 #################
@@ -256,6 +209,11 @@ AM_CONDITIONAL(PLATFORM_WIN32, test "$pl
 
 VAPIGEN_CHECK
 
+###########
+# gtk-doc #
+###########
+GTK_DOC_CHECK([1.14],[--flavour no-tmpl])
+
 ##############
 # Generation #
 ##############
@@ -263,7 +221,11 @@ VAPIGEN_CHECK
 AC_CONFIG_FILES([
 Makefile
 gexiv2.pc:gexiv2.pc.in
+docs/Makefile
+docs/reference/Makefile
 ])
+AC_CONFIG_FILES([test/python2-test], [chmod +x test/python2-test])
+AC_CONFIG_FILES([test/python3-test], [chmod +x test/python3-test])
 
 AC_OUTPUT
 
@@ -274,7 +236,6 @@ Options:
     Introspection:      $found_introspection
     Python2 binding:    $enable_python2
     Python3 binding:    $enable_python3
-    Tests and utils:    $enable_tests
 ])
 
 if test "x$enable_tests" = "xyes"; then
--- a/gexiv2.vapi
+++ /dev/null
@@ -1,164 +0,0 @@
-/* gexiv2.vapi generated by vapigen-0.32, do not modify. */
-
-[CCode (cprefix = "GExiv2", gir_namespace = "GExiv2", gir_version = "0.10", lower_case_cprefix = "gexiv2_")]
-namespace GExiv2 {
-	[CCode (cheader_filename = "gexiv2/gexiv2.h")]
-	public class Metadata : GLib.Object {
-		[CCode (has_construct_function = false)]
-		public Metadata ();
-		public void clear ();
-		public void clear_comment ();
-		public void clear_exif ();
-		public void clear_iptc ();
-		public bool clear_tag (string tag);
-		public void clear_xmp ();
-		public void delete_gps_info ();
-		public void erase_exif_thumbnail ();
-		public bool from_app1_segment ([CCode (array_length = false)] uchar[] data, long n_data) throws GLib.Error;
-		public string? generate_xmp_packet (GExiv2.XmpFormatFlags xmp_format_flags, uint32 padding);
-		public string? get_comment ();
-		public bool get_exif_tag_rational (string tag, out int nom, out int den);
-		[CCode (array_length = false, array_null_terminated = true)]
-		public string[] get_exif_tags ();
-		public bool get_exif_thumbnail ([CCode (array_length_cname = "size", array_length_pos = 1.1)] out uint8[] buffer);
-		public bool get_exposure_time (out int nom, out int den);
-		public double get_fnumber ();
-		public double get_focal_length ();
-		public bool get_gps_altitude (out double altitude);
-		public bool get_gps_info (out double longitude, out double latitude, out double altitude);
-		public bool get_gps_latitude (out double latitude);
-		public bool get_gps_longitude (out double longitude);
-		[CCode (array_length = false, array_null_terminated = true)]
-		public string[] get_iptc_tags ();
-		public int get_iso_speed ();
-		public int get_metadata_pixel_height ();
-		public int get_metadata_pixel_width ();
-		public unowned string get_mime_type ();
-		public GExiv2.Orientation get_orientation ();
-		public int get_pixel_height ();
-		public int get_pixel_width ();
-		public GExiv2.PreviewImage get_preview_image (GExiv2.PreviewProperties props);
-		[CCode (array_length = false, array_null_terminated = true)]
-		public unowned GExiv2.PreviewProperties[]? get_preview_properties ();
-		public bool get_supports_exif ();
-		public bool get_supports_iptc ();
-		public bool get_supports_xmp ();
-		public static unowned string? get_tag_description (string tag);
-		public string? get_tag_interpreted_string (string tag);
-		public static unowned string? get_tag_label (string tag);
-		public long get_tag_long (string tag);
-		[CCode (array_length = false, array_null_terminated = true)]
-		public string[]? get_tag_multiple (string tag);
-		public GLib.Bytes? get_tag_raw (string tag);
-		public string? get_tag_string (string tag);
-		public static unowned string? get_tag_type (string tag);
-		public string? get_xmp_packet ();
-		[CCode (array_length = false, array_null_terminated = true)]
-		public string[] get_xmp_tags ();
-		public bool has_exif ();
-		public bool has_iptc ();
-		public bool has_tag (string tag);
-		public bool has_xmp ();
-		public static bool is_exif_tag (string tag);
-		public static bool is_iptc_tag (string tag);
-		public static bool is_xmp_tag (string tag);
-		public bool open_buf ([CCode (array_length = false)] uchar[] data, long n_data) throws GLib.Error;
-		public bool open_path (string path) throws GLib.Error;
-		public static bool register_xmp_namespace (string name, string prefix);
-		public bool save_file (string path) throws GLib.Error;
-		public void set_comment (string comment);
-		public bool set_exif_tag_rational (string tag, int nom, int den);
-		public void set_exif_thumbnail_from_buffer ([CCode (array_length_cname = "size", array_length_pos = 1.1)] uint8[] buffer);
-		public bool set_exif_thumbnail_from_file (string path) throws GLib.Error;
-		public bool set_gps_info (double longitude, double latitude, double altitude);
-		public void set_metadata_pixel_height (int height);
-		public void set_metadata_pixel_width (int width);
-		public void set_orientation (GExiv2.Orientation orientation);
-		public bool set_tag_long (string tag, long value);
-		public bool set_tag_multiple (string tag, [CCode (array_length = false, array_null_terminated = true)] string[] values);
-		public bool set_tag_string (string tag, string value);
-		public bool set_xmp_tag_struct (string tag, GExiv2.StructureType type);
-		public static void unregister_all_xmp_namespaces ();
-		public static bool unregister_xmp_namespace (string name);
-	}
-	[CCode (cheader_filename = "gexiv2/gexiv2.h", type_id = "gexiv2_preview_image_get_type ()")]
-	public class PreviewImage : GLib.Object {
-		[CCode (has_construct_function = false)]
-		protected PreviewImage ();
-		[CCode (array_length_pos = 0.1, array_length_type = "guint32")]
-		public unowned uint8[] get_data ();
-		public unowned string get_extension ();
-		public uint32 get_height ();
-		public unowned string get_mime_type ();
-		public uint32 get_width ();
-		public long write_file (string path);
-	}
-	[CCode (cheader_filename = "gexiv2/gexiv2.h", type_id = "gexiv2_preview_properties_get_type ()")]
-	public class PreviewProperties : GLib.Object {
-		[CCode (has_construct_function = false)]
-		protected PreviewProperties ();
-		public unowned string get_extension ();
-		public uint32 get_height ();
-		public unowned string get_mime_type ();
-		public uint32 get_size ();
-		public uint32 get_width ();
-	}
-	[CCode (cheader_filename = "gexiv2/gexiv2.h", cprefix = "GEXIV2_LOG_LEVEL_", has_type_id = false)]
-	public enum LogLevel {
-		DEBUG,
-		INFO,
-		WARN,
-		ERROR,
-		MUTE
-	}
-	[CCode (cheader_filename = "gexiv2/gexiv2.h", cprefix = "GEXIV2_ORIENTATION_", has_type_id = false)]
-	public enum Orientation {
-		MIN,
-		UNSPECIFIED,
-		NORMAL,
-		HFLIP,
-		ROT_180,
-		VFLIP,
-		ROT_90_HFLIP,
-		ROT_90,
-		ROT_90_VFLIP,
-		ROT_270,
-		MAX
-	}
-	[CCode (cheader_filename = "gexiv2/gexiv2.h", cprefix = "GEXIV2_STRUCTURE_XA_", has_type_id = false)]
-	public enum StructureType {
-		NONE,
-		ALT,
-		BAG,
-		SEQ,
-		LANG
-	}
-	[CCode (cheader_filename = "gexiv2/gexiv2.h", cprefix = "GEXIV2_", has_type_id = false)]
-	public enum XmpFormatFlags {
-		OMIT_PACKET_WRAPPER,
-		READ_ONLY_PACKET,
-		USE_COMPACT_FORMAT,
-		INCLUDE_THUMBNAIL_PAD,
-		EXACT_PACKET_LENGTH,
-		WRITE_ALIAS_COMMENTS,
-		OMIT_ALL_FORMATTING
-	}
-	[CCode (cheader_filename = "gexiv2/gexiv2.h", has_target = false)]
-	public delegate void LogHandler (GExiv2.LogLevel level, string msg);
-	[CCode (cheader_filename = "gexiv2/gexiv2.h", cname = "GEXIV2_MAJOR_VERSION")]
-	public const int MAJOR_VERSION;
-	[CCode (cheader_filename = "gexiv2/gexiv2.h", cname = "GEXIV2_MICRO_VERSION")]
-	public const int MICRO_VERSION;
-	[CCode (cheader_filename = "gexiv2/gexiv2.h", cname = "GEXIV2_MINOR_VERSION")]
-	public const int MINOR_VERSION;
-	[CCode (cheader_filename = "gexiv2/gexiv2.h")]
-	public static int get_version ();
-	[CCode (cheader_filename = "gexiv2/gexiv2.h")]
-	public static bool initialize ();
-	[CCode (cheader_filename = "gexiv2/gexiv2.h")]
-	public static GExiv2.LogLevel log_get_level ();
-	[CCode (cheader_filename = "gexiv2/gexiv2.h")]
-	public static void log_set_level (GExiv2.LogLevel level);
-	[CCode (cheader_filename = "gexiv2/gexiv2.h")]
-	public static void log_use_glib_logging ();
-}
--- /dev/null
+++ b/m4/ax_check_enable_debug.m4
@@ -0,0 +1,124 @@
+# ===========================================================================
+#   http://www.gnu.org/software/autoconf-archive/ax_check_enable_debug.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+#   AX_CHECK_ENABLE_DEBUG([enable by default=yes/info/profile/no], [ENABLE DEBUG VARIABLES ...], [DISABLE DEBUG VARIABLES NDEBUG ...], [IS-RELEASE])
+#
+# DESCRIPTION
+#
+#   Check for the presence of an --enable-debug option to configure, with
+#   the specified default value used when the option is not present.  Return
+#   the value in the variable $ax_enable_debug.
+#
+#   Specifying 'yes' adds '-g -O0' to the compilation flags for all
+#   languages. Specifying 'info' adds '-g' to the compilation flags.
+#   Specifying 'profile' adds '-g -pg' to the compilation flags and '-pg' to
+#   the linking flags. Otherwise, nothing is added.
+#
+#   Define the variables listed in the second argument if debug is enabled,
+#   defaulting to no variables.  Defines the variables listed in the third
+#   argument if debug is disabled, defaulting to NDEBUG.  All lists of
+#   variables should be space-separated.
+#
+#   If debug is not enabled, ensure AC_PROG_* will not add debugging flags.
+#   Should be invoked prior to any AC_PROG_* compiler checks.
+#
+#   IS-RELEASE can be used to change the default to 'no' when making a
+#   release.  Set IS-RELEASE to 'yes' or 'no' as appropriate. By default, it
+#   uses the value of $ax_is_release, so if you are using the AX_IS_RELEASE
+#   macro, there is no need to pass this parameter.
+#
+#     AX_IS_RELEASE([git-directory])
+#     AX_CHECK_ENABLE_DEBUG()
+#
+# LICENSE
+#
+#   Copyright (c) 2011 Rhys Ulerich <rhys.ulerich@gmail.com>
+#   Copyright (c) 2014, 2015 Philip Withnall <philip@tecnocode.co.uk>
+#
+#   Copying and distribution of this file, with or without modification, are
+#   permitted in any medium without royalty provided the copyright notice
+#   and this notice are preserved.
+
+#serial 5
+
+AC_DEFUN([AX_CHECK_ENABLE_DEBUG],[
+    AC_BEFORE([$0],[AC_PROG_CC])dnl
+    AC_BEFORE([$0],[AC_PROG_CXX])dnl
+    AC_BEFORE([$0],[AC_PROG_F77])dnl
+    AC_BEFORE([$0],[AC_PROG_FC])dnl
+
+    AC_MSG_CHECKING(whether to enable debugging)
+
+    ax_enable_debug_default=m4_tolower(m4_normalize(ifelse([$1],,[no],[$1])))
+    ax_enable_debug_is_release=m4_tolower(m4_normalize(ifelse([$4],,
+                                                              [$ax_is_release],
+                                                              [$4])))
+
+    # If this is a release, override the default.
+    AS_IF([test "$ax_enable_debug_is_release" = "yes"],
+      [ax_enable_debug_default="no"])
+
+    m4_define(ax_enable_debug_vars,[m4_normalize(ifelse([$2],,,[$2]))])
+    m4_define(ax_disable_debug_vars,[m4_normalize(ifelse([$3],,[NDEBUG],[$3]))])
+
+    AC_ARG_ENABLE(debug,
+	[AS_HELP_STRING([--enable-debug=]@<:@yes/info/profile/no@:>@,[compile with debugging])],
+	[],enable_debug=$ax_enable_debug_default)
+
+    # empty mean debug yes
+    AS_IF([test "x$enable_debug" = "x"],
+      [enable_debug="yes"])
+
+    # case of debug
+    AS_CASE([$enable_debug],
+      [yes],[
+	AC_MSG_RESULT(yes)
+	CFLAGS="${CFLAGS} -g -O0"
+	CXXFLAGS="${CXXFLAGS} -g -O0"
+	FFLAGS="${FFLAGS} -g -O0"
+	FCFLAGS="${FCFLAGS} -g -O0"
+	OBJCFLAGS="${OBJCFLAGS} -g -O0"
+      ],
+      [info],[
+	AC_MSG_RESULT(info)
+	CFLAGS="${CFLAGS} -g"
+	CXXFLAGS="${CXXFLAGS} -g"
+	FFLAGS="${FFLAGS} -g"
+	FCFLAGS="${FCFLAGS} -g"
+	OBJCFLAGS="${OBJCFLAGS} -g"
+      ],
+      [profile],[
+	AC_MSG_RESULT(profile)
+	CFLAGS="${CFLAGS} -g -pg"
+	CXXFLAGS="${CXXFLAGS} -g -pg"
+	FFLAGS="${FFLAGS} -g -pg"
+	FCFLAGS="${FCFLAGS} -g -pg"
+	OBJCFLAGS="${OBJCFLAGS} -g -pg"
+	LDFLAGS="${LDFLAGS} -pg"
+      ],
+      [
+	AC_MSG_RESULT(no)
+	dnl Ensure AC_PROG_CC/CXX/F77/FC/OBJC will not enable debug flags
+	dnl by setting any unset environment flag variables
+	AS_IF([test "x${CFLAGS+set}" != "xset"],
+	  [CFLAGS=""])
+	AS_IF([test "x${CXXFLAGS+set}" != "xset"],
+	  [CXXFLAGS=""])
+	AS_IF([test "x${FFLAGS+set}" != "xset"],
+	  [FFLAGS=""])
+	AS_IF([test "x${FCFLAGS+set}" != "xset"],
+	  [FCFLAGS=""])
+	AS_IF([test "x${OBJCFLAGS+set}" != "xset"],
+	  [OBJCFLAGS=""])
+      ])
+
+    dnl Define various variables if debugging is disabled.
+    dnl assert.h is a NOP if NDEBUG is defined, so define it by default.
+    AS_IF([test "x$enable_debug" = "xyes"],
+      [m4_map_args_w(ax_enable_debug_vars, [AC_DEFINE(], [,,[Define if debugging is enabled])])],
+      [m4_map_args_w(ax_disable_debug_vars, [AC_DEFINE(], [,,[Define if debugging is disabled])])])
+    ax_enable_debug=$enable_debug
+])
--- /dev/null
+++ b/test/gexiv2-regression.c
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2017 Jens Georg <mail@jensge.org>
+ *
+ * This library is free software. See COPYING for details
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+
+#include <gexiv2/gexiv2.h>
+
+#include <string.h>
+
+/* Check that gexiv2 correctly handles ratios with 0/0 as used by
+ * some cameras
+ */
+static void test_bgo_775249(void)
+{
+    GExiv2Metadata *meta = NULL;
+    gboolean result = FALSE;
+    gdouble lon = 0.0, lat = 0.0, alt = 0.0;
+    GError *error = NULL;
+
+    meta = gexiv2_metadata_new();
+    g_assert_nonnull(meta);
+    result = gexiv2_metadata_open_path(meta, SAMPLE_PATH "/CaorVN.jpeg", &error);
+    g_assert_no_error(error);
+    g_assert_true(result);
+    g_assert_true(gexiv2_metadata_get_gps_info(meta, &lon, &lat, &alt));
+
+    g_assert_cmpfloat(lon, ==, -1.508425);
+
+    /* Just check if it fits in there; The main issue is that it's not 0 */
+    g_assert_cmpfloat(lat, >=, 48.631806);
+    g_assert_cmpfloat(lat, <=, 48.631807);
+    g_assert_cmpfloat(alt, ==, -0.926000);
+
+    g_clear_object(&meta);
+}
+
+static const char test_bgo_730136_artist_data[] = {
+  0xc0, 0xeb, 0xe5, 0xea, 0xf1, 0xe0, 0xed, 0xe4,
+  0xf0,  ' ', 0xca, 0xee, 0xf8, 0xe5, 0xeb, 0xe5,
+  0xe2, 0x00
+};
+
+static void test_bgo_730136(void)
+{
+    GExiv2Metadata *meta = NULL;
+    gboolean result = FALSE;
+    GError *error = NULL;
+    GBytes *raw_tag = NULL;
+
+    meta = gexiv2_metadata_new ();
+    g_assert_nonnull (meta);
+    result = gexiv2_metadata_open_path (meta, SAMPLE_PATH "/sample-author-badencoding.jpg", &error);
+    g_assert_no_error(error);
+    g_assert_true(result);
+
+    raw_tag = gexiv2_metadata_get_tag_raw (meta, "Exif.Image.Artist");
+    g_assert_nonnull (raw_tag);
+    g_assert_cmpmem (g_bytes_get_data(raw_tag, NULL), g_bytes_get_size(raw_tag),
+                     test_bgo_730136_artist_data, sizeof(test_bgo_730136_artist_data));
+    g_clear_object (&meta);
+    g_clear_pointer (&raw_tag, g_bytes_unref);
+}
+
+int main(int argc, char *argv[static argc + 1])
+{
+    g_test_init(&argc, &argv, NULL);
+    g_test_add_func("/bugs/gnome/775249", test_bgo_775249);
+    g_test_add_func("/bugs/gnome/730136", test_bgo_730136);
+
+    return g_test_run();
+}
--- a/test/python/gexiv2.py
+++ b/test/python/gexiv2.py
@@ -29,8 +29,10 @@ import os
 import gi.overrides
 gi.overrides.__path__.append(os.path.join(os.path.dirname(__file__),
                                           'gi', 'overrides'))
+gi.overrides.__path__.append(os.path.join(os.path.dirname(__file__), '..', '..'))
 
 
+gi.require_version('GExiv2', '0.10')
 from gi.repository import GExiv2
 
 
@@ -44,10 +46,21 @@ class TestGexiv2(unittest.TestCase):
 
     def test_author_badencoding(self):
         sample = 'sample-author-badencoding.jpg'
-        md = GExiv2.Metadata(self.get_sample_path(sample))
+        md = GExiv2.Metadata()
+        md.open_path(self.get_sample_path(sample))
 
         self.assertEqual(md.get_raw('Exif.Image.Artist'), b'\xc0\xeb\xe5\xea\xf1\xe0\xed\xe4\xf0 \xca\xee\xf8\xe5\xeb\xe5\xe2\x00')
 
+    def test_gps_coordinates(self):
+        sample = 'CaorVN.jpeg'
+        md = GExiv2.Metadata()
+        md.open_path(self.get_sample_path(sample))
+
+        (lo, la, alt) = md.get_gps_info()
+        self.assertEqual(lo, -1.508425)
+        self.assertEqual(la, 48.631806166666664)
+        self.assertEqual(alt, -0.926000)
+
 
 if __name__ == '__main__':
     unittest.main()
--- /dev/null
+++ b/test/python2-test.in
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+@PYTHON2_PATH@ -m unittest gexiv2
--- /dev/null
+++ b/test/python3-test.in
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+@PYTHON3_PATH@ -m unittest gexiv2
--- /dev/null
+++ b/docs/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = reference
--- /dev/null
+++ b/docs/reference/Makefile.am
@@ -0,0 +1,85 @@
+# This is a blank Makefile.am for using gtk-doc.
+# Copy this to your project's API docs directory and modify the variables to
+# suit your project. See the GTK+ Makefiles in gtk+/docs/reference for examples
+# of using the various options.
+
+# The name of the module, e.g. 'glib'.
+DOC_MODULE=gexiv2
+
+# Uncomment for versioned docs and specify the version of the module, e.g. '2'.
+#DOC_MODULE_VERSION=2
+
+# The top-level XML file.
+DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.xml
+
+# Directories containing the source code.
+# gtk-doc will search all .c and .h files beneath these paths
+# for inline comments documenting functions and macros.
+# e.g. DOC_SOURCE_DIR=$(top_srcdir)/gtk $(top_srcdir)/gdk
+DOC_SOURCE_DIR=$(top_srcdir)/gexiv2
+
+# Extra options to pass to gtkdoc-scangobj. Normally not needed.
+SCANGOBJ_OPTIONS=
+
+# Extra options to supply to gtkdoc-scan.
+# e.g. SCAN_OPTIONS=--deprecated-guards="GTK_DISABLE_DEPRECATED"
+SCAN_OPTIONS=
+
+# Extra options to supply to gtkdoc-mkdb
+# e.g. MKDB_OPTIONS=--xml-mode --output-format=xml
+MKDB_OPTIONS=--xml-mode --output-format=xml --source-suffixes=h,c,cpp
+
+# Extra options to supply to gtkdoc-mkhtml
+MKHTML_OPTIONS=
+
+# Extra options to supply to gtkdoc-fixref. Normally not needed.
+# e.g. FIXXREF_OPTIONS=--extra-dir=../gdk-pixbuf/html --extra-dir=../gdk/html
+FIXXREF_OPTIONS=
+
+# Used for dependencies. The docs will be rebuilt if any of these change.
+# e.g. HFILE_GLOB=$(top_srcdir)/gtk/*.h
+# e.g. CFILE_GLOB=$(top_srcdir)/gtk/*.c
+HFILE_GLOB=$(top_srcdir)/gexiv2/*.h
+CFILE_GLOB=$(top_srcdir)/gexiv2/*.cpp
+
+# Extra header to include when scanning, which are not under DOC_SOURCE_DIR
+# e.g. EXTRA_HFILES=$(top_srcdir}/contrib/extra.h
+EXTRA_HFILES=
+
+# Header files or dirs to ignore when scanning. Use base file/dir names
+# e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h private_code
+IGNORE_HFILES=*-private.h
+
+# Images to copy into HTML directory.
+# e.g. HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png
+HTML_IMAGES=
+
+# Extra files that are included by $(DOC_MAIN_SGML_FILE).
+# e.g. content_files=running.xml building.xml changes-2.0.xml
+content_files=
+
+# Files where gtk-doc abbrevations (#GtkWidget) are expanded
+# e.g. expand_content_files=running.xml
+expand_content_files=
+
+# CFLAGS and LDFLAGS for compiling gtkdoc-scangobj with your library.
+# Only needed if you are using gtkdoc-scangobj to dynamically query widget
+# signals and properties.
+# e.g. GTKDOC_CFLAGS=-I$(top_srcdir) -I$(top_builddir) $(GTK_DEBUG_FLAGS)
+# e.g. GTKDOC_LIBS=$(top_builddir)/gtk/$(gtktargetlib)
+GTKDOC_CFLAGS=
+GTKDOC_LIBS=$(top_builddir)/lib@PACKAGE_NAME@.la
+
+# This includes the standard gtk-doc make rules, copied by gtkdocize.
+include $(top_srcdir)/gtk-doc.make
+
+# Comment this out if you want 'make check' to test you doc status
+# and run some sanity checks
+#if ENABLE_GTK_DOC
+#TESTS_ENVIRONMENT = \
+#  DOC_MODULE=$(DOC_MODULE) DOC_MAIN_SGML_FILE=$(DOC_MAIN_SGML_FILE) \
+#  SRCDIR=$(abs_srcdir) BUILDDIR=$(abs_builddir)
+#TESTS = $(GTKDOC_CHECK)
+#endif
+
+-include $(top_srcdir)/git.mk
--- /dev/null
+++ b/docs/reference/gexiv2-docs.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0"?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
+               "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
+[
+  <!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
+  <!ENTITY % gtkdocentities SYSTEM "xml/gtkdocentities.ent">
+  %gtkdocentities;
+]>
+<book id="index">
+  <bookinfo>
+    <title>&package_name; Reference Manual</title>
+    <releaseinfo>
+      for &package_string;.
+      The latest version of this documentation can be found on-line at
+      <ulink role="online-location" url="http://developer.gnome.org/&package_name;/unstable/">http://developer.gnome.org/&package_name;/unstable</ulink>.
+    </releaseinfo>
+  </bookinfo>
+
+  <chapter>
+      <title>GExiv2</title>
+      <xi:include href="xml/gexiv2-log.xml"/>
+      <xi:include href="xml/gexiv2-managed-stream.xml"/>
+      <xi:include href="xml/gexiv2-metadata.xml"/>
+      <xi:include href="xml/gexiv2-preview-image.xml"/>
+      <xi:include href="xml/gexiv2-preview-properties.xml"/>
+      <xi:include href="xml/gexiv2-startup.xml"/>
+      <xi:include href="xml/gexiv2-version.xml"/>
+
+  </chapter>
+  <chapter id="object-tree">
+    <title>Object Hierarchy</title>
+    <xi:include href="xml/tree_index.sgml"/>
+  </chapter>
+  <index id="api-index-full">
+    <title>API Index</title>
+    <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
+  </index>
+  <index id="deprecated-api-index" role="deprecated">
+    <title>Index of deprecated API</title>
+    <xi:include href="xml/api-index-deprecated.xml"><xi:fallback /></xi:include>
+  </index>
+  <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
+</book>
--- /dev/null
+++ b/docs/reference/gexiv2-sections.txt
@@ -0,0 +1,176 @@
+<SECTION>
+<FILE>gexiv2-log</FILE>
+GExiv2LogLevel
+GExiv2LogHandler
+gexiv2_log_get_level
+gexiv2_log_set_level
+gexiv2_log_get_handler
+gexiv2_log_get_default_handler
+gexiv2_log_set_handler
+gexiv2_log_use_glib_logging
+</SECTION>
+
+<SECTION>
+<FILE>gexiv2-managed-stream</FILE>
+WrapperSeekOrigin
+Stream_CanSeek
+Stream_CanRead
+Stream_CanWrite
+Stream_Length
+Stream_Position
+Stream_Read
+Stream_Write
+Stream_Seek
+Stream_Flush
+ManagedStreamCallbacks
+</SECTION>
+
+<SECTION>
+<FILE>gexiv2-metadata</FILE>
+<TITLE>GExiv2Metadata</TITLE>
+GExiv2Orientation
+GExiv2StructureType
+GExiv2XmpFormatFlags
+GExiv2Metadata
+gexiv2_metadata_new
+gexiv2_metadata_free
+gexiv2_metadata_open_path
+gexiv2_metadata_open_buf
+gexiv2_metadata_open_stream
+gexiv2_metadata_from_app1_segment
+gexiv2_metadata_save_file
+gexiv2_metadata_save_stream
+gexiv2_metadata_has_tag
+gexiv2_metadata_clear_tag
+gexiv2_metadata_clear
+gexiv2_metadata_is_exif_tag
+gexiv2_metadata_is_iptc_tag
+gexiv2_metadata_is_xmp_tag
+gexiv2_metadata_get_tag_label
+gexiv2_metadata_get_tag_description
+gexiv2_metadata_get_tag_type
+gexiv2_metadata_get_supports_exif
+gexiv2_metadata_get_supports_iptc
+gexiv2_metadata_get_supports_xmp
+gexiv2_metadata_get_mime_type
+gexiv2_metadata_get_pixel_width
+gexiv2_metadata_get_pixel_height
+gexiv2_metadata_get_tag_string
+gexiv2_metadata_set_tag_string
+gexiv2_metadata_set_xmp_tag_struct
+gexiv2_metadata_get_tag_interpreted_string
+gexiv2_metadata_get_tag_long
+gexiv2_metadata_set_tag_long
+gexiv2_metadata_get_tag_multiple
+gexiv2_metadata_set_tag_multiple
+gexiv2_metadata_get_tag_raw
+gexiv2_metadata_has_exif
+gexiv2_metadata_clear_exif
+gexiv2_metadata_get_exif_tags
+gexiv2_metadata_get_exif_tag_rational
+gexiv2_metadata_set_exif_tag_rational
+gexiv2_metadata_get_exif_thumbnail
+gexiv2_metadata_set_exif_thumbnail_from_file
+gexiv2_metadata_set_exif_thumbnail_from_buffer
+gexiv2_metadata_erase_exif_thumbnail
+gexiv2_metadata_has_xmp
+gexiv2_metadata_clear_xmp
+gexiv2_metadata_generate_xmp_packet
+gexiv2_metadata_get_xmp_packet
+gexiv2_metadata_get_xmp_tags
+gexiv2_metadata_register_xmp_namespace
+gexiv2_metadata_unregister_xmp_namespace
+gexiv2_metadata_unregister_all_xmp_namespaces
+gexiv2_metadata_has_iptc
+gexiv2_metadata_clear_iptc
+gexiv2_metadata_get_iptc_tags
+gexiv2_metadata_get_orientation
+gexiv2_metadata_set_orientation
+gexiv2_metadata_get_metadata_pixel_width
+gexiv2_metadata_get_metadata_pixel_height
+gexiv2_metadata_set_metadata_pixel_width
+gexiv2_metadata_set_metadata_pixel_height
+gexiv2_metadata_get_comment
+gexiv2_metadata_set_comment
+gexiv2_metadata_clear_comment
+gexiv2_metadata_get_exposure_time
+gexiv2_metadata_get_fnumber
+gexiv2_metadata_get_focal_length
+gexiv2_metadata_get_iso_speed
+gexiv2_metadata_get_gps_longitude
+gexiv2_metadata_get_gps_latitude
+gexiv2_metadata_get_gps_altitude
+gexiv2_metadata_get_gps_info
+gexiv2_metadata_set_gps_info
+gexiv2_metadata_delete_gps_info
+gexiv2_metadata_get_preview_properties
+gexiv2_metadata_get_preview_image
+<SUBSECTION Standard>
+GEXIV2_IS_METADATA
+GEXIV2_IS_METADATA_CLASS
+GEXIV2_METADATA
+GEXIV2_METADATA_CLASS
+GEXIV2_METADATA_GET_CLASS
+GEXIV2_TYPE_METADATA
+GExiv2MetadataClass
+GExiv2MetadataPrivate
+gexiv2_metadata_get_type
+</SECTION>
+
+<SECTION>
+<FILE>gexiv2-preview-image</FILE>
+<TITLE>GExiv2PreviewImage</TITLE>
+gexiv2_preview_image_free
+gexiv2_preview_image_get_data
+gexiv2_preview_image_get_mime_type
+gexiv2_preview_image_get_extension
+gexiv2_preview_image_get_width
+gexiv2_preview_image_get_height
+gexiv2_preview_image_write_file
+<SUBSECTION Standard>
+GEXIV2_IS_PREVIEW_IMAGE
+GEXIV2_IS_PREVIEW_IMAGE_CLASS
+GEXIV2_PREVIEW_IMAGE
+GEXIV2_PREVIEW_IMAGE_CLASS
+GEXIV2_PREVIEW_IMAGE_GET_CLASS
+GEXIV2_TYPE_PREVIEW_IMAGE
+GExiv2PreviewImage
+GExiv2PreviewImageClass
+GExiv2PreviewImagePrivate
+gexiv2_preview_image_get_type
+</SECTION>
+
+<SECTION>
+<FILE>gexiv2-preview-properties</FILE>
+<TITLE>GExiv2PreviewProperties</TITLE>
+gexiv2_preview_properties_get_mime_type
+gexiv2_preview_properties_get_extension
+gexiv2_preview_properties_get_size
+gexiv2_preview_properties_get_width
+gexiv2_preview_properties_get_height
+<SUBSECTION Standard>
+GEXIV2_IS_PREVIEW_PROPERTIES
+GEXIV2_IS_PREVIEW_PROPERTIES_CLASS
+GEXIV2_PREVIEW_PROPERTIES
+GEXIV2_PREVIEW_PROPERTIES_CLASS
+GEXIV2_PREVIEW_PROPERTIES_GET_CLASS
+GEXIV2_TYPE_PREVIEW_PROPERTIES
+GExiv2PreviewProperties
+GExiv2PreviewPropertiesClass
+GExiv2PreviewPropertiesPrivate
+gexiv2_preview_properties_get_type
+</SECTION>
+
+<SECTION>
+<FILE>gexiv2-startup</FILE>
+gexiv2_initialize
+</SECTION>
+
+<SECTION>
+<FILE>gexiv2-version</FILE>
+GEXIV2_MAJOR_VERSION
+GEXIV2_MINOR_VERSION
+GEXIV2_MICRO_VERSION
+GEXIV2_CHECK_VERSION
+gexiv2_get_version
+</SECTION>
--- /dev/null
+++ b/docs/reference/gexiv2.types
@@ -0,0 +1,3 @@
+gexiv2_metadata_get_type
+gexiv2_preview_image_get_type
+gexiv2_preview_properties_get_type
--- /dev/null
+++ b/gtk-doc.make
@@ -0,0 +1,256 @@
+# -*- mode: makefile -*-
+
+####################################
+# Everything below here is generic #
+####################################
+
+if GTK_DOC_USE_LIBTOOL
+GTKDOC_CC = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(INCLUDES) $(GTKDOC_DEPS_CFLAGS) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+GTKDOC_LD = $(LIBTOOL) --tag=CC --mode=link $(CC) $(GTKDOC_DEPS_LIBS) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS)
+GTKDOC_RUN = $(LIBTOOL) --mode=execute
+else
+GTKDOC_CC = $(CC) $(INCLUDES) $(GTKDOC_DEPS_CFLAGS) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+GTKDOC_LD = $(CC) $(GTKDOC_DEPS_LIBS) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS)
+GTKDOC_RUN =
+endif
+
+# We set GPATH here; this gives us semantics for GNU make
+# which are more like other make's VPATH, when it comes to
+# whether a source that is a target of one rule is then
+# searched for in VPATH/GPATH.
+#
+GPATH = $(srcdir)
+
+TARGET_DIR=$(HTML_DIR)/$(DOC_MODULE)
+
+SETUP_FILES = \
+	$(content_files)		\
+	$(DOC_MAIN_SGML_FILE)		\
+	$(DOC_MODULE)-sections.txt	\
+	$(DOC_MODULE)-overrides.txt
+
+EXTRA_DIST = 				\
+	$(HTML_IMAGES)			\
+	$(SETUP_FILES)
+
+DOC_STAMPS=setup-build.stamp scan-build.stamp sgml-build.stamp \
+	html-build.stamp pdf-build.stamp \
+	sgml.stamp html.stamp pdf.stamp
+
+SCANOBJ_FILES = 		 \
+	$(DOC_MODULE).args 	 \
+	$(DOC_MODULE).hierarchy  \
+	$(DOC_MODULE).interfaces \
+	$(DOC_MODULE).prerequisites \
+	$(DOC_MODULE).signals
+
+REPORT_FILES = \
+	$(DOC_MODULE)-undocumented.txt \
+	$(DOC_MODULE)-undeclared.txt \
+	$(DOC_MODULE)-unused.txt
+
+CLEANFILES = $(SCANOBJ_FILES) $(REPORT_FILES) $(DOC_STAMPS)
+
+if ENABLE_GTK_DOC
+if GTK_DOC_BUILD_HTML
+HTML_BUILD_STAMP=html-build.stamp
+else
+HTML_BUILD_STAMP=
+endif
+if GTK_DOC_BUILD_PDF
+PDF_BUILD_STAMP=pdf-build.stamp
+else
+PDF_BUILD_STAMP=
+endif
+
+all-local: $(HTML_BUILD_STAMP) $(PDF_BUILD_STAMP)
+else
+all-local:
+endif
+
+docs: $(HTML_BUILD_STAMP) $(PDF_BUILD_STAMP)
+
+$(REPORT_FILES): sgml-build.stamp
+
+#### setup ####
+
+setup-build.stamp:
+	-@if test "$(abs_srcdir)" != "$(abs_builddir)" ; then \
+	    echo '  DOC   Preparing build'; \
+	    files=`echo $(SETUP_FILES) $(expand_content_files) $(DOC_MODULE).types`; \
+	    if test "x$$files" != "x" ; then \
+	        for file in $$files ; do \
+	            test -f $(abs_srcdir)/$$file && \
+	                cp -pu $(abs_srcdir)/$$file $(abs_builddir)/ || true; \
+	        done; \
+	    fi; \
+	fi
+	@touch setup-build.stamp
+
+
+#### scan ####
+
+scan-build.stamp: $(HFILE_GLOB) $(CFILE_GLOB)
+	@echo '  DOC   Scanning header files'
+	@_source_dir='' ; \
+	for i in $(DOC_SOURCE_DIR) ; do \
+	    _source_dir="$${_source_dir} --source-dir=$$i" ; \
+	done ; \
+	gtkdoc-scan --module=$(DOC_MODULE) --ignore-headers="$(IGNORE_HFILES)" $${_source_dir} $(SCAN_OPTIONS) $(EXTRA_HFILES)
+	@if grep -l '^..*$$' $(DOC_MODULE).types > /dev/null 2>&1 ; then \
+	    echo "  DOC   Introspecting gobjects"; \
+	    scanobj_options=""; \
+	    gtkdoc-scangobj 2>&1 --help | grep  >/dev/null "\-\-verbose"; \
+	    if test "$(?)" = "0"; then \
+	        if test "x$(V)" = "x1"; then \
+	            scanobj_options="--verbose"; \
+	        fi; \
+	    fi; \
+	    CC="$(GTKDOC_CC)" LD="$(GTKDOC_LD)" RUN="$(GTKDOC_RUN)" CFLAGS="$(GTKDOC_CFLAGS) $(CFLAGS)" LDFLAGS="$(GTKDOC_LIBS) $(LDFLAGS)" \
+	    gtkdoc-scangobj $(SCANGOBJ_OPTIONS) $$scanobj_options --module=$(DOC_MODULE); \
+	else \
+	    for i in $(SCANOBJ_FILES) ; do \
+	        test -f $$i || touch $$i ; \
+	    done \
+	fi
+	@touch scan-build.stamp
+
+$(DOC_MODULE)-decl.txt $(SCANOBJ_FILES) $(DOC_MODULE)-sections.txt $(DOC_MODULE)-overrides.txt: scan-build.stamp
+	@true
+
+#### xml ####
+
+sgml-build.stamp: setup-build.stamp $(DOC_MODULE)-decl.txt $(SCANOBJ_FILES) $(DOC_MODULE)-sections.txt $(DOC_MODULE)-overrides.txt $(expand_content_files)
+	@echo '  DOC   Building XML'
+	@_source_dir='' ; \
+	for i in $(DOC_SOURCE_DIR) ; do \
+	    _source_dir="$${_source_dir} --source-dir=$$i" ; \
+	done ; \
+	gtkdoc-mkdb --module=$(DOC_MODULE) --output-format=xml --expand-content-files="$(expand_content_files)" --main-sgml-file=$(DOC_MAIN_SGML_FILE) $${_source_dir} $(MKDB_OPTIONS)
+	@touch sgml-build.stamp
+
+sgml.stamp: sgml-build.stamp
+	@true
+
+#### html ####
+
+html-build.stamp: sgml.stamp $(DOC_MAIN_SGML_FILE) $(content_files)
+	@echo '  DOC   Building HTML'
+	@rm -rf html
+	@mkdir html
+	@mkhtml_options=""; \
+	gtkdoc-mkhtml 2>&1 --help | grep  >/dev/null "\-\-verbose"; \
+	if test "$(?)" = "0"; then \
+	  if test "x$(V)" = "x1"; then \
+	    mkhtml_options="$$mkhtml_options --verbose"; \
+	  fi; \
+	fi; \
+	gtkdoc-mkhtml 2>&1 --help | grep  >/dev/null "\-\-path"; \
+	if test "$(?)" = "0"; then \
+	  mkhtml_options="$$mkhtml_options --path=\"$(abs_srcdir)\""; \
+	fi; \
+	cd html && gtkdoc-mkhtml $$mkhtml_options $(MKHTML_OPTIONS) $(DOC_MODULE) ../$(DOC_MAIN_SGML_FILE)
+	-@test "x$(HTML_IMAGES)" = "x" || \
+	for file in $(HTML_IMAGES) ; do \
+	  if test -f $(abs_srcdir)/$$file ; then \
+	    cp $(abs_srcdir)/$$file $(abs_builddir)/html; \
+	  fi; \
+	  if test -f $(abs_builddir)/$$file ; then \
+	    cp $(abs_builddir)/$$file $(abs_builddir)/html; \
+	  fi; \
+	done;
+	@echo '  DOC   Fixing cross-references'
+	@gtkdoc-fixxref --module=$(DOC_MODULE) --module-dir=html --html-dir=$(HTML_DIR) $(FIXXREF_OPTIONS)
+	@touch html-build.stamp
+
+#### pdf ####
+
+pdf-build.stamp: sgml.stamp $(DOC_MAIN_SGML_FILE) $(content_files)
+	@echo '  DOC   Building PDF'
+	@rm -f $(DOC_MODULE).pdf
+	@mkpdf_options=""; \
+	gtkdoc-mkpdf 2>&1 --help | grep  >/dev/null "\-\-verbose"; \
+	if test "$(?)" = "0"; then \
+	  if test "x$(V)" = "x1"; then \
+	    mkpdf_options="$$mkpdf_options --verbose"; \
+	  fi; \
+	fi; \
+	if test "x$(HTML_IMAGES)" != "x"; then \
+	  for img in $(HTML_IMAGES); do \
+	    part=`dirname $$img`; \
+	    echo $$mkpdf_options | grep >/dev/null "\-\-imgdir=$$part "; \
+	    if test $$? != 0; then \
+	      mkpdf_options="$$mkpdf_options --imgdir=$$part"; \
+	    fi; \
+	  done; \
+	fi; \
+	gtkdoc-mkpdf --path="$(abs_srcdir)" $$mkpdf_options $(DOC_MODULE) $(DOC_MAIN_SGML_FILE) $(MKPDF_OPTIONS)
+	@touch pdf-build.stamp
+
+##############
+
+clean-local:
+	@rm -f *~ *.bak
+	@rm -rf .libs
+
+distclean-local:
+	@rm -rf xml html $(REPORT_FILES) $(DOC_MODULE).pdf \
+	    $(DOC_MODULE)-decl-list.txt $(DOC_MODULE)-decl.txt
+	@if test "$(abs_srcdir)" != "$(abs_builddir)" ; then \
+	    rm -f $(SETUP_FILES) $(expand_content_files) $(DOC_MODULE).types; \
+	fi
+
+maintainer-clean-local: clean
+	@rm -rf xml html
+
+install-data-local:
+	@installfiles=`echo $(builddir)/html/*`; \
+	if test "$$installfiles" = '$(builddir)/html/*'; \
+	then echo 1>&2 'Nothing to install' ; \
+	else \
+	  if test -n "$(DOC_MODULE_VERSION)"; then \
+	    installdir="$(DESTDIR)$(TARGET_DIR)-$(DOC_MODULE_VERSION)"; \
+	  else \
+	    installdir="$(DESTDIR)$(TARGET_DIR)"; \
+	  fi; \
+	  $(mkinstalldirs) $${installdir} ; \
+	  for i in $$installfiles; do \
+	    echo ' $(INSTALL_DATA) '$$i ; \
+	    $(INSTALL_DATA) $$i $${installdir}; \
+	  done; \
+	  if test -n "$(DOC_MODULE_VERSION)"; then \
+	    mv -f $${installdir}/$(DOC_MODULE).devhelp2 \
+	      $${installdir}/$(DOC_MODULE)-$(DOC_MODULE_VERSION).devhelp2; \
+	  fi; \
+	  $(GTKDOC_REBASE) --relative --dest-dir=$(DESTDIR) --html-dir=$${installdir}; \
+	fi
+
+uninstall-local:
+	@if test -n "$(DOC_MODULE_VERSION)"; then \
+	  installdir="$(DESTDIR)$(TARGET_DIR)-$(DOC_MODULE_VERSION)"; \
+	else \
+	  installdir="$(DESTDIR)$(TARGET_DIR)"; \
+	fi; \
+	rm -rf $${installdir}
+
+#
+# Require gtk-doc when making dist
+#
+if ENABLE_GTK_DOC
+dist-check-gtkdoc:
+else
+dist-check-gtkdoc:
+	@echo "*** gtk-doc must be installed and enabled in order to make dist"
+	@false
+endif
+
+dist-hook: dist-check-gtkdoc dist-hook-local
+	@mkdir $(distdir)/html
+	@cp ./html/* $(distdir)/html
+	@-cp ./$(DOC_MODULE).pdf $(distdir)/
+	@-cp ./$(DOC_MODULE).types $(distdir)/
+	@-cp ./$(DOC_MODULE)-sections.txt $(distdir)/
+	@cd $(distdir) && rm -f $(DISTCLEANFILES)
+	@$(GTKDOC_REBASE) --online --relative --html-dir=$(distdir)/html
+
+.PHONY : dist-hook-local docs
