Index: configure.ac
===================================================================
RCS file: /cvs/gstreamer/gstreamer/configure.ac,v
retrieving revision 1.364
diff -u -r1.364 configure.ac
--- configure.ac	20 Jun 2005 11:27:36 -0000	1.364
+++ configure.ac	24 Jun 2005 10:03:08 -0000
@@ -253,7 +253,7 @@
 dnl === GLib 2 ===
 dnl Minimum required version of GLib2
 dnl required for compilation without warnings
-GLIB2_REQ="2.4"
+GLIB2_REQ="2.6"
 AC_SUBST(GLIB2_REQ)
 
 dnl Check for glib2 with sugar on top
@@ -283,34 +283,6 @@
   GST_LIBXML2_CHECK(2.4.9)
 fi
 
-dnl popt checks
-dnl FIXME: This test passes on popt 1.6.2, maybe earlier, but popt 1.6.2
-dnl        causes segfaults on gst_init. Write a working test if possible.
-GST_CHECK_LIBHEADER(POPT, popt, poptStrippedArgv,, popt.h, POPT_LIBS="-lpopt",
-  AC_MSG_ERROR([popt 1.6.3 or newer is required to build gstreamer. You can
-                download the latest version from 
-                ftp://ftp.rpm.org/pub/rpm/dist/])
-)
-AC_MSG_NOTICE(Checking for POPT_TABLEEND)
-AC_COMPILE_IFELSE([
-#include <popt.h>
-int main ()
-{
-#ifndef POPT_TABLEEND
-#error
-#else
-  return 0;
-#endif
-}
-],, [
-  dnl it failed
-  AC_MSG_ERROR([popt 1.6.3 or newer is required to build gstreamer. You can
-                download the latest version from 
-                ftp://ftp.rpm.org/pub/rpm/dist/])
-])
-AC_SUBST(POPT_CFLAGS)
-AC_SUBST(POPT_LIBS)
-
 dnl Check for ucontext.h
 AC_CHECK_HEADER(ucontext.h, AC_DEFINE(HAVE_UCONTEXT_H, 1, [defined if we have ucontext.h]))
 
Index: docs/gst/Makefile.am
===================================================================
RCS file: /cvs/gstreamer/gstreamer/docs/gst/Makefile.am,v
retrieving revision 1.91
diff -u -r1.91 Makefile.am
--- docs/gst/Makefile.am	6 May 2005 17:33:54 -0000	1.91
+++ docs/gst/Makefile.am	24 Jun 2005 10:03:08 -0000
@@ -106,8 +106,8 @@
 
 # CFLAGS and LDFLAGS for compiling scan program. Only needed if your app/lib
 # contains GtkObjects/GObjects and you want to document signals and properties.
-GTKDOC_CFLAGS = $(GST_OBJ_CFLAGS) $(POPT_CFLAGS) -I$(top_builddir)
-GTKDOC_LIBS = $(GST_OBJ_LIBS) $(POPT_LIBS) $(SCANOBJ_DEPS)
+GTKDOC_CFLAGS = $(GST_OBJ_CFLAGS) -I$(top_builddir)
+GTKDOC_LIBS = $(GST_OBJ_LIBS) $(SCANOBJ_DEPS)
 
 GTKDOC_CC=$(LIBTOOL) --mode=compile $(CC)
 GTKDOC_LD=$(LIBTOOL) --mode=link $(CC)
Index: docs/gst/tmpl/gst.sgml
===================================================================
RCS file: /cvs/gstreamer/gstreamer/docs/gst/tmpl/gst.sgml,v
retrieving revision 1.28
diff -u -r1.28 gst.sgml
--- docs/gst/tmpl/gst.sgml	29 Mar 2005 10:55:38 -0000	1.28
+++ docs/gst/tmpl/gst.sgml	24 Jun 2005 10:03:08 -0000
@@ -103,40 +103,7 @@
 
 @argc: 
 @argv: 
-@Returns: 
-
-
-<!-- ##### FUNCTION gst_init_with_popt_table ##### -->
-<para>
-
-</para>
-
-@argc: 
-@argv: 
-@popt_options: 
-<!-- # Unused Parameters # -->
-@Param3: 
-@Returns: 
-
-
-<!-- ##### FUNCTION gst_init_check_with_popt_table ##### -->
-<para>
-
-</para>
-
-@argc: 
-@argv: 
-@popt_options: 
-@Returns: 
-<!-- # Unused Parameters # -->
-@Param3: 
-
-
-<!-- ##### FUNCTION gst_init_get_popt_table ##### -->
-<para>
-
-</para>
-
+@err: 
 @Returns: 
 
 
Index: docs/libs/Makefile.am
===================================================================
RCS file: /cvs/gstreamer/gstreamer/docs/libs/Makefile.am,v
retrieving revision 1.41
diff -u -r1.41 Makefile.am
--- docs/libs/Makefile.am	29 Mar 2005 14:12:47 -0000	1.41
+++ docs/libs/Makefile.am	24 Jun 2005 10:03:10 -0000
@@ -80,8 +80,8 @@
 
 # CFLAGS and LDFLAGS for compiling scan program. Only needed if your app/lib
 # contains GtkObjects/GObjects and you want to document signals and properties.
-GTKDOC_CFLAGS = $(GST_OBJ_CFLAGS) $(POPT_CFLAGS) -I$(top_builddir)
-GTKDOC_LIBS = $(GST_OBJ_LIBS) $(POPT_LIBS) $(SCANOBJ_DEPS)
+GTKDOC_CFLAGS = $(GST_OBJ_CFLAGS) -I$(top_builddir)
+GTKDOC_LIBS = $(GST_OBJ_LIBS) $(SCANOBJ_DEPS)
 
 GTKDOC_CC=$(LIBTOOL) --mode=compile $(CC)
 GTKDOC_LD=$(LIBTOOL) --mode=link $(CC)
Index: docs/manual/basics-init.xml
===================================================================
RCS file: /cvs/gstreamer/gstreamer/docs/manual/basics-init.xml,v
retrieving revision 1.9
diff -u -r1.9 basics-init.xml
--- docs/manual/basics-init.xml	15 Dec 2004 17:32:49 -0000	1.9
+++ docs/manual/basics-init.xml	24 Jun 2005 10:03:10 -0000
@@ -57,13 +57,13 @@
   </sect1>
 
   <sect1>
-    <title>The popt interface</title>
+    <title>The GOption interface</title>
     <para>
-      You can also use a popt table to initialize your own parameters as
+      You can also use a GOption table to initialize your own parameters as
       shown in the next example:
     </para>
     <programlisting>
-<!-- example-begin popt.c -->
+<!-- example-begin goption.c -->
 #include &lt;gst/gst.h&gt;
 
 int
@@ -72,28 +72,38 @@
 {
   gboolean silent = FALSE;
   gchar *savefile = NULL;
-  struct poptOption options[] = {
-    {"silent",	's',  POPT_ARG_NONE|POPT_ARGFLAG_STRIP,   &amp;silent,   0,
-     "do not output status information", NULL},
-    {"output",	'o',  POPT_ARG_STRING|POPT_ARGFLAG_STRIP, &amp;savefile, 0,
-     "save xml representation of pipeline to FILE and exit", "FILE"},
-    POPT_TABLEEND
+  GOptionContext *ctx;
+  GError *err = NULL;
+  GOptionEntry entries[] = {
+    { "silent", 's', 0, G_OPTION_ARG_NONE, &amp;silent, 0,
+      "do not output status information", NULL },
+    { "output", 'o', 0, G_OPTION_ARG_STRING, &amp;savefile, 0,
+      "save xml representation of pipeline to FILE and exit", "FILE" },
+    { NULL }
   };
 
-  gst_init_with_popt_table (&amp;argc, &amp;argv, options);
+  ctx = g_option_context_new ("- Your application");
+  g_option_context_add_main_entries (ctx, entries, GETTEXT_PACKAGE);
+  g_option_context_add_group (ctx, gst_init_get_option_group ());
+  if (!g_option_context_parse (ctx, &amp;argc, &amp;argv, &amp;err)) {
+    g_print ("Failed to initialize: %s\n", err->message);
+    g_error_free (err);
+    return 1;
+  }
 
   printf ("Run me with --help to see the Application options appended.\n");
 
   return 0;
 }
-<!-- example-end popt.c -->
+<!-- example-end goption.c -->
     </programlisting>
     <para>
       As shown in this fragment, you can use a <ulink
-      url="http://developer.gnome.org/doc/guides/popt/"
-      type="http">popt</ulink> table to define your application-specific
-      command line options, and pass this table to the
-      function <function>gst_init_with_popt_table</function>. Your
+      url="http://developer.gnome.org/doc/API/2.0/glib/glib-Commandline-option-parser.html"
+      type="http">GOption</ulink> table to define your application-specific
+      command line options, and pass this table to the GLib initialization
+      function along with the option group returned from the
+      function <function>gst_init_get_option_group</function>. Your
       application options will be parsed in addition to the standard
       <application>GStreamer</application> options.
     </para>
Index: examples/manual/Makefile.am
===================================================================
RCS file: /cvs/gstreamer/gstreamer/examples/manual/Makefile.am,v
retrieving revision 1.17
diff -u -r1.17 Makefile.am
--- examples/manual/Makefile.am	23 Dec 2004 14:26:14 -0000	1.17
+++ examples/manual/Makefile.am	24 Jun 2005 10:03:11 -0000
@@ -12,6 +12,8 @@
 
 INCLUDES = $(GST_OBJ_CFLAGS)
 
+goption_CFLAGS = -DGETTEXT_PACKAGE="\"gstreamer-0.9\""
+
 #dynamic_LDADD = $(GST_OBJ_LIBS) $(LIBGNOMEUI_LIBS)
 #dynamic_CFLAGS = $(GST_OBJ_CFLAGS) $(LIBGNOMEUI_CFLAGS)
 gnome_LDADD = $(GST_OBJ_LIBS) $(LIBGNOMEUI_LIBS)
@@ -32,7 +34,7 @@
 	ghostpad \
 	helloworld \
 	init \
-	popt \
+	goption \
 	query \
 	threads \
 	typefind \
@@ -61,7 +63,7 @@
 	$(PERL_PATH) $(srcdir)/extract.pl $@ \
 		$(top_srcdir)/docs/manual/basics-helloworld.xml
 
-init.c popt.c: $(top_srcdir)/docs/manual/basics-init.xml
+init.c goption.c: $(top_srcdir)/docs/manual/basics-init.xml
 	$(PERL_PATH) $(srcdir)/extract.pl $@ \
 		$(top_srcdir)/docs/manual/basics-init.xml
 
@@ -93,7 +95,7 @@
 # they actually run
 include $(top_srcdir)/testsuite/Rules
                                                                                 
-tests_pass = elementmake elementget init popt
+tests_pass = elementmake elementget init goption
 tests_fail =
 tests_ignore =
 
Index: gst/gst.c
===================================================================
RCS file: /cvs/gstreamer/gstreamer/gst/gst.c,v
retrieving revision 1.153
diff -u -r1.153 gst.c
--- gst/gst.c	8 Jun 2005 22:16:27 -0000	1.153
+++ gst/gst.c	24 Jun 2005 10:03:12 -0000
@@ -48,8 +48,6 @@
 
 static gboolean gst_initialized = FALSE;
 
-/* this will be set in popt callbacks when a problem has been encountered */
-static gboolean _gst_initialization_failure = FALSE;
 extern gint _gst_trace_on;
 
 /* set to TRUE when segfaults need to be left as is */
@@ -57,11 +55,10 @@
 
 
 static void load_plugin_func (gpointer data, gpointer user_data);
-static void init_popt_callback (poptContext context,
-    enum poptCallbackReason reason,
-    const GstPoptOption * option, const char *arg, void *data);
 static gboolean init_pre (void);
 static gboolean init_post (void);
+static gboolean parse_goption_arg (const gchar * s_opt,
+    const gchar * arg, gpointer data, GError ** err);
 
 static GSList *preload_plugins = NULL;
 
@@ -88,7 +85,6 @@
   ARG_DEBUG_NO_COLOR,
   ARG_DEBUG_HELP,
 #endif
-  ARG_DISABLE_CPU_OPT,
   ARG_PLUGIN_SPEW,
   ARG_PLUGIN_PATH,
   ARG_PLUGIN_LOAD,
@@ -133,99 +129,80 @@
 #endif
 
 /**
- * gst_init_get_popt_table:
+ * gst_init_get_option_group:
  *
- * Returns a popt option table with GStreamer's argument specifications. The
- * table is set up to use popt's callback method, so whenever the parsing is
- * actually performed (via poptGetContext), the GStreamer libraries will
- * be initialized.
+ * Returns a #GOptionGroup with GStreamer's argument specifications. The
+ * group is set up to use standard GOption callbacks, so when using this
+ * group in combination with GOption parsing methods, all argument parsing
+ * and initialization is automated.
  *
  * This function is useful if you want to integrate GStreamer with other
- * libraries that use popt.
+ * libraries that use GOption.
  *
- * Returns: a pointer to the static GStreamer option table.
- * No free is necessary.
+ * Returns: a pointer to a GStreamer option group. Should be dereferenced
+ * after use.
  */
-const GstPoptOption *
-gst_init_get_popt_table (void)
-{
-  static GstPoptOption gstreamer_options[] = {
-    {NULL, NUL, POPT_ARG_CALLBACK | POPT_CBFLAG_PRE | POPT_CBFLAG_POST,
-        (void *) &init_popt_callback, 0, NULL, NULL},
-    /* make sure we use our GETTEXT_PACKAGE as the domain for popt translations */
-    {NULL, NUL, POPT_ARG_INTL_DOMAIN, GETTEXT_PACKAGE, 0, NULL, NULL},
-    {"gst-version", NUL, POPT_ARG_NONE | POPT_ARGFLAG_STRIP, NULL, ARG_VERSION,
-        N_("Print the GStreamer version"), NULL},
-    {"gst-fatal-warnings", NUL, POPT_ARG_NONE | POPT_ARGFLAG_STRIP, NULL,
-        ARG_FATAL_WARNINGS, N_("Make all warnings fatal"), NULL},
 
+GOptionGroup *
+gst_init_get_option_group (void)
+{
+  GOptionGroup *group;
+  static GOptionEntry gst_args[] = {
+    { "gst-version", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Print the GStreamer version"), NULL },
+    { "gst-fatal-warnings", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+       N_("Make all warnings fatal"), NULL },
 #ifndef GST_DISABLE_GST_DEBUG
-    {"gst-debug-help", NUL, POPT_ARG_NONE | POPT_ARGFLAG_STRIP, NULL,
-        ARG_DEBUG_HELP, N_("Print available debug categories and exit"), NULL},
-    {"gst-debug-level", NUL, POPT_ARG_INT | POPT_ARGFLAG_STRIP, NULL,
-          ARG_DEBUG_LEVEL,
-          N_("Default debug level from 1 (only error) to 5 (anything) or "
-              "0 for no output"),
-        N_("LEVEL")},
-    {"gst-debug", NUL, POPT_ARG_STRING | POPT_ARGFLAG_STRIP, NULL, ARG_DEBUG,
-          N_("Comma-separated list of category_name:level pairs to set "
-              "specific levels for the individual categories. Example: "
-              "GST_AUTOPLUG:5,GST_ELEMENT_*:3"),
-        N_("LIST")},
-    {"gst-debug-no-color", NUL, POPT_ARG_NONE | POPT_ARGFLAG_STRIP, NULL,
-        ARG_DEBUG_NO_COLOR, N_("Disable colored debugging output"), NULL},
-    {"gst-debug-disable", NUL, POPT_ARG_NONE | POPT_ARGFLAG_STRIP, NULL,
-        ARG_DEBUG_DISABLE, N_("Disable debugging")},
+    { "gst-debug-help", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Print available debug categories and exit"), NULL },
+    { "gst-debug-level", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Default debug level from 1 (only error) to 5 (anything) or "
+         "0 for no output"),
+      N_("LEVEL") },
+    { "gst-debug", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Comma-separated list of category_name:level pairs to set "
+         "specific levels for the individual categories. Example: "
+         "GST_AUTOPLUG:5,GST_ELEMENT_*:3"),
+      N_("LIST") },
+    { "gst-debug-no-color", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Disable colored debugging output"), NULL },
+    { "gst-debug-disable", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Disable debugging"), NULL },
 #endif
-
-    {"gst-plugin-spew", NUL, POPT_ARG_NONE | POPT_ARGFLAG_STRIP, NULL,
-        ARG_PLUGIN_SPEW, N_("Enable verbose plugin loading diagnostics"), NULL},
-    {"gst-plugin-path", NUL, POPT_ARG_STRING | POPT_ARGFLAG_STRIP, NULL,
-        ARG_PLUGIN_PATH, NULL, N_("PATHS")},
-    {"gst-plugin-load", NUL, POPT_ARG_STRING | POPT_ARGFLAG_STRIP, NULL,
-          ARG_PLUGIN_LOAD,
-          N_("Comma-separated list of plugins to preload in addition to the "
-              "list stored in environment variable GST_PLUGIN_PATH"),
-        N_("PLUGINS")},
-    {"gst-disable-segtrap", NUL, POPT_ARG_NONE | POPT_ARGFLAG_STRIP, NULL,
-          ARG_SEGTRAP_DISABLE,
-          N_("Disable trapping of segmentation faults during plugin loading"),
-        NULL},
-    {"gst-scheduler", NUL, POPT_ARG_STRING | POPT_ARGFLAG_STRIP, NULL,
-        ARG_SCHEDULER, NULL, N_("SCHEDULER")},
-    {"gst-registry", NUL, POPT_ARG_STRING | POPT_ARGFLAG_STRIP, NULL,
-        ARG_REGISTRY, N_("Registry to use"), N_("REGISTRY")},
-    POPT_TABLEEND
+    { "gst-plugin-spew", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Enable verbose plugin loading diagnostics"), NULL },
+    { "gst-plugin-path", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Colon-separated paths containing plugins"), N_("PATHS") },
+    { "gst-plugin-load", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Comma-separated list of plugins to preload in addition to the "
+         "list stored in environment variable GST_PLUGIN_PATH"),
+      N_("PLUGINS") },
+    { "gst-disable-segtrap", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Disable trapping of segmentation faults during plugin loading"),
+      NULL },
+    { "gst-scheduler", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Scheduler to use"), N_("SCHEDULER") },
+    { "gst-registry", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Registry to use"), N_("REGISTRY") },
+    { NULL }
   };
-  static gboolean inited = FALSE;
 
-  if (!inited) {
-    int i;
+  group = g_option_group_new ("gst", _("GStreamer Options"),
+      _("Show GStreamer Options"), NULL, NULL);
+  g_option_group_set_parse_hooks (group, (GOptionParseFunc) init_pre,
+      (GOptionParseFunc) init_post);
 
-    for (i = 0; i < G_N_ELEMENTS (gstreamer_options); i++) {
-      if (gstreamer_options[i].longName == NULL) {
-      } else if (strcmp (gstreamer_options[i].longName, "gst-plugin-path") == 0) {
-        gstreamer_options[i].descrip =
-            g_strdup_printf (_
-            ("path list for loading plugins (separated by '%s')"),
-            G_SEARCHPATH_SEPARATOR_S);
-      } else if (strcmp (gstreamer_options[i].longName, "gst-scheduler") == 0) {
-        gstreamer_options[i].descrip =
-            g_strdup_printf (_("Scheduler to use (default is '%s')"),
-            GST_SCHEDULER_DEFAULT_NAME);
-      }
-    }
-
-    inited = TRUE;
-  }
+  g_option_group_add_entries (group, gst_args);
+  g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
 
-  return gstreamer_options;
+  return group;
 }
 
 /**
  * gst_init_check:
  * @argc: pointer to application's argc
  * @argv: pointer to application's argv
+ * @err: pointer to a #GError to which a message will be posted on error
  *
  * Initializes the GStreamer library, setting up internal path lists,
  * registering built-in elements, and loading standard plugins.
@@ -237,9 +214,28 @@
  * Returns: %TRUE if GStreamer could be initialized.
  */
 gboolean
-gst_init_check (int *argc, char **argv[])
+gst_init_check (int *argc, char **argv[], GError ** err)
 {
-  return gst_init_check_with_popt_table (argc, argv, NULL);
+  GOptionGroup *group;
+  GOptionContext *ctx;
+  gboolean res;
+
+  if (gst_initialized) {
+    GST_DEBUG ("already initialized gst");
+    return TRUE;
+  }
+
+  ctx = g_option_context_new ("- GStreamer initialization");
+  group = gst_init_get_option_group ();
+  g_option_context_add_group (ctx, group);
+  res = g_option_context_parse (ctx, argc, argv, err);
+  g_option_context_free (ctx);
+
+  if (res) {
+    gst_initialized = TRUE;
+  }
+
+  return res;
 }
 
 /**
@@ -262,124 +258,16 @@
 void
 gst_init (int *argc, char **argv[])
 {
-  gst_init_with_popt_table (argc, argv, NULL);
-}
-
-/**
- * gst_init_with_popt_table:
- * @argc: pointer to application's argc
- * @argv: pointer to application's argv
- * @popt_options: pointer to a popt table to append
- *
- * Initializes the GStreamer library, parsing the options,
- * setting up internal path lists,
- * registering built-in elements, and loading standard plugins.
- *
- * This function will terminate your program if it was unable to initialize
- * GStreamer for some reason.  If you want your program to fall back,
- * use gst_init_check_with_popt_table() instead.
- */
-void
-gst_init_with_popt_table (int *argc, char **argv[],
-    const GstPoptOption * popt_options)
-{
-  if (!gst_init_check_with_popt_table (argc, argv, popt_options)) {
-    g_print ("Could not initialize GStreamer !\n");
-    exit (1);
-  }
-}
-
-/**
- * gst_init_check_with_popt_table:
- * @argc: pointer to application's argc
- * @argv: pointer to application's argv
- * @popt_options: pointer to a popt table to append
- *
- * Initializes the GStreamer library, parsing the options,
- * setting up internal path lists,
- * registering built-in elements, and loading standard plugins.
- *
- * Returns: %TRUE if GStreamer could be initialized.
- */
-gboolean
-gst_init_check_with_popt_table (int *argc, char **argv[],
-    const GstPoptOption * popt_options)
-{
-  poptContext context;
-  gint nextopt;
-  GstPoptOption *options;
-  const gchar *gst_debug_env = NULL;
-
-  GstPoptOption options_with[] = {
-    {NULL, NUL, POPT_ARG_INCLUDE_TABLE, poptHelpOptions, 0, "Help options:",
-        NULL},
-    {NULL, NUL, POPT_ARG_INCLUDE_TABLE,
-          (GstPoptOption *) gst_init_get_popt_table (), 0,
-        "GStreamer options:", NULL},
-    {NULL, NUL, POPT_ARG_INCLUDE_TABLE, (GstPoptOption *) popt_options, 0,
-        "Application options:", NULL},
-    POPT_TABLEEND
-  };
-  GstPoptOption options_without[] = {
-    {NULL, NUL, POPT_ARG_INCLUDE_TABLE, poptHelpOptions, 0, "Help options:",
-        NULL},
-    {NULL, NUL, POPT_ARG_INCLUDE_TABLE,
-          (GstPoptOption *) gst_init_get_popt_table (), 0,
-        "GStreamer options:", NULL},
-    POPT_TABLEEND
-  };
-
-  if (gst_initialized) {
-    GST_DEBUG ("already initialized gst");
-    return TRUE;
-  }
-  if (!argc || !argv) {
-    if (argc || argv)
-      g_warning ("gst_init: Only one of argc or argv was NULL");
-
-    if (!init_pre ())
-      return FALSE;
-    if (!init_post ())
-      return FALSE;
-    gst_initialized = TRUE;
-    return TRUE;
-  }
-
-  if (popt_options == NULL) {
-    options = options_without;
-  } else {
-    options = options_with;
-  }
-  context = poptGetContext ("GStreamer", *argc, (const char **) *argv,
-      options, 0);
-
-  /* check for GST_DEBUG environment variable */
-  gst_debug_env = g_getenv ("GST_DEBUG");
-  if (gst_debug_env)
-    parse_debug_list (gst_debug_env);
-
-  /* Scan until we reach the end (-1), ignoring errors */
-  while ((nextopt = poptGetNextOpt (context)) != -1) {
-
-    /* If an error occurred and it's not an missing options, throw an error
-     * We don't want to show the "unknown option" message, since it'll
-     * might interfere with the applications own command line parsing
-     */
-    if (nextopt < 0 && nextopt != POPT_ERROR_BADOPT) {
-      g_print ("Error on option %s: %s.\nRun '%s --help' "
-          "to see a full list of available command line options.\n",
-          poptBadOption (context, 0), poptStrerror (nextopt), (*argv)[0]);
+  GError *err = NULL;
 
-      poptFreeContext (context);
-      return FALSE;
+  if (!gst_init_check (argc, argv, &err)) {
+    g_print ("Could not initialized GStreamer: %s\n",
+        err ? err->message : "unknown error occurred");
+    if (err) {
+      g_error_free (err);
     }
+    exit (1);
   }
-
-  *argc = poptStrippedArgv (context, *argc, *argv);
-
-  poptFreeContext (context);
-
-  return TRUE;
 }
 
 #ifndef GST_DISABLE_REGISTRY
@@ -722,86 +610,110 @@
 }
 #endif
 
-static void
-init_popt_callback (poptContext context, enum poptCallbackReason reason,
-    const GstPoptOption * option, const char *arg, void *data)
+static gboolean
+parse_one_option (gint opt, const gchar * arg, GError ** err)
 {
-  GLogLevelFlags fatal_mask;
-
-  if (gst_initialized)
-    return;
-  switch (reason) {
-    case POPT_CALLBACK_REASON_PRE:
-      if (!init_pre ())
-        _gst_initialization_failure = TRUE;
-      break;
-    case POPT_CALLBACK_REASON_OPTION:
-      switch (option->val) {
-        case ARG_VERSION:
-          g_print ("GStreamer Core Library version %s\n", GST_VERSION);
-          exit (0);
-        case ARG_FATAL_WARNINGS:
-          fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
-          fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
-          g_log_set_always_fatal (fatal_mask);
-          break;
+  switch (opt) {
+    case ARG_VERSION:
+      g_print ("GStreamer Core Library version %s\n", GST_VERSION);
+      exit (0);
+    case ARG_FATAL_WARNINGS: {
+      GLogLevelFlags fatal_mask;
+
+      fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
+      fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
+      g_log_set_always_fatal (fatal_mask);
+      break;
+    }
 #ifndef GST_DISABLE_GST_DEBUG
-        case ARG_DEBUG_LEVEL:{
-          gint tmp = 0;
+    case ARG_DEBUG_LEVEL:{
+      gint tmp = 0;
 
-          tmp = strtol (arg, NULL, 0);
-          if (tmp >= 0 && tmp < GST_LEVEL_COUNT) {
-            gst_debug_set_default_threshold (tmp);
-          }
-          break;
-        }
-        case ARG_DEBUG:
-          parse_debug_list (arg);
-          break;
-        case ARG_DEBUG_NO_COLOR:
-          gst_debug_set_colored (FALSE);
-          break;
-        case ARG_DEBUG_DISABLE:
-          gst_debug_set_active (FALSE);
-          break;
-        case ARG_DEBUG_HELP:
-          gst_debug_help ();
-          exit (0);
+      tmp = strtol (arg, NULL, 0);
+      if (tmp >= 0 && tmp < GST_LEVEL_COUNT) {
+        gst_debug_set_default_threshold (tmp);
+      }
+      break;
+    }
+    case ARG_DEBUG:
+      parse_debug_list (arg);
+      break;
+    case ARG_DEBUG_NO_COLOR:
+      gst_debug_set_colored (FALSE);
+      break;
+    case ARG_DEBUG_DISABLE:
+      gst_debug_set_active (FALSE);
+      break;
+    case ARG_DEBUG_HELP:
+      gst_debug_help ();
+      exit (0);
 #endif
-        case ARG_PLUGIN_SPEW:
-          break;
-        case ARG_PLUGIN_PATH:
+    case ARG_PLUGIN_SPEW:
+      break;
+    case ARG_PLUGIN_PATH:
 #ifndef GST_DISABLE_REGISTRY
-          split_and_iterate (arg, G_SEARCHPATH_SEPARATOR_S, add_path_func,
-              _user_registry);
+      split_and_iterate (arg, G_SEARCHPATH_SEPARATOR_S, add_path_func,
+          _user_registry);
 #endif /* GST_DISABLE_REGISTRY */
-          break;
-        case ARG_PLUGIN_LOAD:
-          split_and_iterate (arg, ",", prepare_for_load_plugin_func, NULL);
-          break;
-        case ARG_SEGTRAP_DISABLE:
-          _gst_disable_segtrap = TRUE;
-          break;
-        case ARG_SCHEDULER:
-          gst_scheduler_factory_set_default_name (arg);
-          break;
-        case ARG_REGISTRY:
+      break;
+    case ARG_PLUGIN_LOAD:
+      split_and_iterate (arg, ",", prepare_for_load_plugin_func, NULL);
+      break;
+    case ARG_SEGTRAP_DISABLE:
+      _gst_disable_segtrap = TRUE;
+      break;
+    case ARG_SCHEDULER:
+      gst_scheduler_factory_set_default_name (arg);
+      break;
+    case ARG_REGISTRY:
 #ifndef GST_DISABLE_REGISTRY
-          g_object_set (G_OBJECT (_user_registry), "location", arg, NULL);
-          _gst_registry_fixed = TRUE;
+      g_object_set (G_OBJECT (_user_registry), "location", arg, NULL);
+      _gst_registry_fixed = TRUE;
 #endif /* GST_DISABLE_REGISTRY */
-          break;
-        default:
-          g_warning ("option %d not recognized", option->val);
-          break;
-      }
       break;
-    case POPT_CALLBACK_REASON_POST:
-      if (!init_post ())
-        _gst_initialization_failure = TRUE;
-      gst_initialized = TRUE;
+    default:
+      g_set_error (err, G_OPTION_ERROR, G_OPTION_ERROR_UNKNOWN_OPTION,
+          _("Unknown option"));
+      return FALSE;
+  }
+
+  return TRUE;
+}
+
+static gboolean
+parse_goption_arg (const gchar * opt,
+    const gchar * arg, gpointer data, GError ** err)
+{
+  const struct {
+    gchar *opt; int val;
+  } options[] = {
+    { "gst-version", ARG_VERSION },
+    { "gst-fatal-warnings", ARG_FATAL_WARNINGS },
+#ifndef GST_DISABLE_GST_DEBUG
+    { "gst-debug-level", ARG_DEBUG_LEVEL },
+    { "gst-debug", ARG_DEBUG },
+    { "gst-debug-disable", ARG_DEBUG_DISABLE },
+    { "gst-debug-no-color", ARG_DEBUG_NO_COLOR },
+    { "gst-debug-help", ARG_DEBUG_HELP },
+#endif
+    { "gst-plugin-spew", ARG_PLUGIN_SPEW },
+    { "gst-plugin-path", ARG_PLUGIN_PATH },
+    { "gst-plugin-load", ARG_PLUGIN_LOAD },
+    { "gst-disable-segtrap", ARG_SEGTRAP_DISABLE },
+    { "gst-scheduler", ARG_SCHEDULER },
+    { "gst-registry", ARG_REGISTRY },
+    { NULL }
+  };
+  gint val = 0, n;
+
+  for (n = 0; options[n].opt; n++) {
+    if (!strcmp (opt, options[n].opt)) {
+      val = n;
       break;
+    }
   }
+
+  return parse_one_option (val, arg, err);
 }
 
 /**
Index: gst/gst.h
===================================================================
RCS file: /cvs/gstreamer/gstreamer/gst/gst.h,v
retrieving revision 1.79
diff -u -r1.79 gst.h
--- gst/gst.h	8 Jun 2005 22:16:27 -0000	1.79
+++ gst/gst.h	24 Jun 2005 10:03:12 -0000
@@ -25,7 +25,6 @@
 #define __GST_H__
 
 #include <glib.h>
-#include <popt.h>
 
 #include <gst/gstenumtypes.h>
 #include <gst/gsttypes.h>
@@ -75,30 +74,15 @@
 
 G_BEGIN_DECLS
 
-/* make our own type for poptOption because gtkdoc-1.2 can not handle functions
- * with return types like 'struct abc'
- * Filed as http://bugzilla.gnome.org/show_bug.cgi?id=148507
- *
- * Btw. popt provides a typedef, but it is:
- * typedef struct poptOption *poptOption
- */
-typedef struct poptOption GstPoptOption;
-
 #ifndef GST_DISABLE_REGISTRY
 GST_EXPORT gboolean _gst_registry_auto_load;
 #endif
 
 /* initialize GST */
 void		gst_init			(int *argc, char **argv[]);
-gboolean	gst_init_check			(int *argc, char **argv[]);
-void		gst_init_with_popt_table	(int *argc, char **argv[],
-						 const GstPoptOption
-						 *popt_options);
-gboolean	gst_init_check_with_popt_table	(int *argc, char **argv[],
-						 const GstPoptOption
-						 *popt_options);
-
-const GstPoptOption *	gst_init_get_popt_table		(void);
+gboolean	gst_init_check			(int *argc, char **argv[],
+						 GError ** err);
+GOptionGroup *	gst_init_get_option_group	(void);
 
 G_END_DECLS
 
Index: tests/Makefile.am
===================================================================
RCS file: /cvs/gstreamer/gstreamer/tests/Makefile.am,v
retrieving revision 1.51
diff -u -r1.51 Makefile.am
--- tests/Makefile.am	19 Jun 2005 10:31:42 -0000	1.51
+++ tests/Makefile.am	24 Jun 2005 10:03:13 -0000
@@ -8,7 +8,7 @@
 
 endif
 
-noinst_PROGRAMS = $(LAT) mass_elements complexity
+noinst_PROGRAMS = $(LAT) mass_elements complexity init
 
 AM_CFLAGS = $(GST_OBJ_CFLAGS)
 LIBS = $(GST_OBJ_LIBS) \
Index: tools/Makefile.am
===================================================================
RCS file: /cvs/gstreamer/gstreamer/tools/Makefile.am,v
retrieving revision 1.61
diff -u -r1.61 Makefile.am
--- tools/Makefile.am	4 Jul 2004 23:36:29 -0000	1.61
+++ tools/Makefile.am	24 Jun 2005 10:03:13 -0000
@@ -97,10 +97,10 @@
 gst_xmlinspect_@GST_MAJORMINOR@_LDADD = ../libs/gst/control/libgstcontrol-@GST_MAJORMINOR@.la
 
 # CFLAGS and libs for nonversioned frontend binaries
-AM_CFLAGS = $(GLIB_ONLY_CFLAGS) $(POPT_CFLAGS)
-LDADD = $(GLIB_ONLY_LIBS) $(POPT_LIBS)
+AM_CFLAGS = $(GLIB_ONLY_CFLAGS)
+LDADD = $(GLIB_ONLY_LIBS)
 # due to depcomp not using AM_CFLAGS for rh9/yd3, we also set AM_CPPFLAGS
-AM_CPPFLAGS = $(GLIB_ONLY_CFLAGS) $(POPT_CFLAGS)
+AM_CPPFLAGS = $(GLIB_ONLY_CFLAGS)
 
 ### man pages we want to install
 if GST_DISABLE_REGISTRY
Index: tools/gst-inspect.c
===================================================================
RCS file: /cvs/gstreamer/gstreamer/tools/gst-inspect.c,v
retrieving revision 1.84
diff -u -r1.84 gst-inspect.c
--- tools/gst-inspect.c	8 Jun 2005 22:16:27 -0000	1.84
+++ tools/gst-inspect.c	24 Jun 2005 10:03:14 -0000
@@ -1082,11 +1082,13 @@
 main (int argc, char *argv[])
 {
   gboolean print_all = FALSE;
-  struct poptOption options[] = {
-    {"print-all", 'a', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &print_all, 0,
+  GOptionEntry options[] = {
+    {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
         N_("Print all elements"), NULL},
-    POPT_TABLEEND
+    {NULL}
   };
+  GOptionContext *ctx;
+  GError *err = NULL;
 
 #ifdef GETTEXT_PACKAGE
   bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
@@ -1094,7 +1096,13 @@
   textdomain (GETTEXT_PACKAGE);
 #endif
 
-  gst_init_with_popt_table (&argc, &argv, options);
+  ctx = g_option_context_new ("gst-inspect");
+  g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
+  g_option_context_add_group (ctx, gst_init_get_option_group ());
+  if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
+    g_print ("Error initializing: %s\n", err->message);
+    exit (1);
+  }
   gst_control_init (&argc, &argv);
 
   if (print_all && argc > 2) {
Index: tools/gst-launch.c
===================================================================
RCS file: /cvs/gstreamer/gstreamer/tools/gst-launch.c,v
retrieving revision 1.71
diff -u -r1.71 gst-launch.c
--- tools/gst-launch.c	23 Jun 2005 10:37:09 -0000	1.71
+++ tools/gst-launch.c	24 Jun 2005 10:03:15 -0000
@@ -424,26 +424,27 @@
   gboolean trace = FALSE;
   gchar *savefile = NULL;
   gchar *exclude_args = NULL;
-  struct poptOption options[] = {
-    {"tags", 't', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &tags, 0,
-        N_("Output tags (also known as metadata)"), NULL},
-    {"verbose", 'v', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &verbose, 0,
+  GOptionEntry options[] = {
+    {"tags", 't', 0, G_OPTION_ARG_NONE, &tags,
+        N_("Output tags (also known as metadata)"), NULL },
+    {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
         N_("Output status information and property notifications"), NULL},
-    {"exclude", 'X', POPT_ARG_STRING | POPT_ARGFLAG_STRIP, &exclude_args, 0,
+    {"exclude", 'X', 0, G_OPTION_ARG_NONE, &exclude_args,
         N_("Do not output status information of TYPE"), N_("TYPE1,TYPE2,...")},
 #ifndef GST_DISABLE_LOADSAVE
-    {"output", 'o', POPT_ARG_STRING | POPT_ARGFLAG_STRIP, &savefile, 0,
+    {"output", 'o', 0, G_OPTION_ARG_STRING, &savefile,
         N_("Save xml representation of pipeline to FILE and exit"), N_("FILE")},
 #endif
-    {"no-fault", 'f', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &no_fault, 0,
+    {"no-fault", 'f', 0, G_OPTION_ARG_NONE, &no_fault,
         N_("Do not install a fault handler"), NULL},
-    {"trace", 'T', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &trace, 0,
+    {"trace", 'T', 0, G_OPTION_ARG_NONE, &trace,
         N_("Print alloc trace (if enabled at compile time)"), NULL},
-    {"iterations", 'i', POPT_ARG_INT | POPT_ARGFLAG_STRIP, &max_iterations, 0,
+    {"iterations", 'i', 0, G_OPTION_ARG_INT, &max_iterations,
         N_("Number of times to iterate pipeline"), NULL},
-    POPT_TABLEEND
+    {NULL}
   };
-
+  GOptionContext *ctx;
+  GError *err = NULL;
   gchar **argvn;
   GError *error = NULL;
   gint res = 0;
@@ -458,7 +459,13 @@
 
   gst_alloc_trace_set_flags_all (GST_ALLOC_TRACE_LIVE);
 
-  gst_init_with_popt_table (&argc, &argv, options);
+  ctx = g_option_context_new ("gst-launch");
+  g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
+  g_option_context_add_group (ctx, gst_init_get_option_group ());
+  if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
+    g_print ("Error initializing: %s\n", err->message);
+    exit (1);
+  }
 
   /* FIXpopt: strip short args, too. We do it ourselves for now */
   j = 1;
Index: tools/gst-run.c
===================================================================
RCS file: /cvs/gstreamer/gstreamer/tools/gst-run.c,v
retrieving revision 1.6
diff -u -r1.6 gst-run.c
--- tools/gst-run.c	15 Mar 2004 19:27:17 -0000	1.6
+++ tools/gst-run.c	24 Jun 2005 10:03:16 -0000
@@ -27,86 +27,24 @@
 #include <string.h>
 #include <unistd.h>
 #include <errno.h>
-#include <popt.h>
 #include <glib.h>
 
-enum
-{
-  ARG_MM = 1,
-  ARG_LIST_MM,
-  ARG_PRINT,
-  ARG_HELP
-};
-
 /* global statics for option parsing */
 static gboolean _print = FALSE;
 static gchar *_arg_mm = NULL;
 static gboolean _arg_list_mm = FALSE;
 
-/* callback to parse arguments */
-static void
-popt_callback (poptContext context, enum poptCallbackReason reason,
-    const struct poptOption *option, const char *arg, void *data)
-{
-  if (reason == POPT_CALLBACK_REASON_OPTION) {
-    switch (option->val) {
-      case ARG_MM:
-        _arg_mm = g_strdup (arg);
-        break;
-      case ARG_LIST_MM:
-        _arg_list_mm = TRUE;
-        break;
-      case ARG_PRINT:
-        _print = TRUE;
-        break;
-      case ARG_HELP:
-        poptPrintHelp (context, stdout, 0);
-        g_print ("\n");
-        break;
-    }
-  } else {
-    g_print ("Unknown reason for callback\n");
-  }
-}
-
 /* popt options table for the wrapper */
-static struct poptOption wrapper_options[] = {
-  {NULL, '\0',
-        POPT_ARG_CALLBACK,
-      (void *) &popt_callback, 0, NULL, NULL},
-  {"help", '\0',
-        POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN,
-      NULL, ARG_HELP, ("Show help"), NULL},
-  {"?", '\0',
-        POPT_ARG_NONE | POPT_ARGFLAG_STRIP | POPT_ARGFLAG_ONEDASH
-        | POPT_ARGFLAG_DOC_HIDDEN,
-      NULL, ARG_HELP, NULL, NULL},
-  /* We cheat by specifying -p as long "p" with onedash, so that it
-     also gets stripped properly from our arg flags */
-  {"p", '\0',
-        POPT_ARG_NONE | POPT_ARGFLAG_STRIP | POPT_ARGFLAG_ONEDASH
-        | POPT_ARGFLAG_DOC_HIDDEN,
-      NULL, ARG_PRINT, NULL, NULL},
-  {"print", '\0',
-        POPT_ARG_NONE | POPT_ARGFLAG_STRIP,
-      NULL, ARG_PRINT, ("Print wrapped command line"), NULL},
-  {"gst-mm", '\0',
-        POPT_ARG_STRING | POPT_ARGFLAG_STRIP,
-      NULL, ARG_MM, ("Force major/minor version"), NULL},
-  {"gst-list-mm", '\0',
-        POPT_ARG_NONE | POPT_ARGFLAG_STRIP,
-      NULL, ARG_LIST_MM, ("List found major/minor versions"), NULL},
-  POPT_TABLEEND
+static GOptionEntry wrapper_options[] = {
+  { "print", 'p', 0, G_OPTION_ARG_NONE, &_print,
+    "print wrapped command line options", NULL },
+  { "gst-mm", 0, 0, G_OPTION_ARG_STRING, &_arg_mm,
+    "Force major/minor version", "VERSION" },
+  { "gst-list-mm", 0, 0, G_OPTION_ARG_NONE, &_arg_list_mm,
+    "List found major/minor versions", NULL },
+  { NULL }
 };
 
-/* helper table including our wrapper options */
-static struct poptOption options[] = {
-  {NULL, '\0', POPT_ARG_INCLUDE_TABLE, wrapper_options, 0,
-      "Wrapper options:", NULL},
-  POPT_TABLEEND
-};
-
-
 /* print out the major/minor, which is the hash key */
 static void
 hash_print_key (gchar * key, gchar * value)
@@ -294,18 +232,18 @@
   gchar *highest = NULL;
   gchar *binary;                /* actual binary we're going to run */
   gchar *path = NULL;           /* and its path */
-  poptContext ctx;
+  GOptionContext *ctx;
+  GError *err = NULL;
   int nextopt;
 
   /* parse command line options */
-  ctx = poptGetContext ("gst-run", argc, (const char **) argv, options, 0);
-  poptReadDefaultConfig (ctx, TRUE);
-  while ((nextopt = poptGetNextOpt (ctx)) > 0)
-    /* keep looping to parse */ ;
-
-  argc = poptStrippedArgv (ctx, argc, argv);
-  argv[argc] = NULL;
-  poptFreeContext (ctx);
+  ctx = g_option_context_new ("gst-run");
+  g_option_context_set_ignore_unknown_options (ctx, TRUE);
+  g_option_context_add_main_entries (ctx, wrapper_options, GETTEXT_PACKAGE);
+  if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
+    g_print ("Error initializing: %s\n", err->message);
+    exit (1);
+  }
 
   /* detect stuff */
   dir = get_dir_of_binary (argv[0]);
Index: tools/gst-xmlinspect.c
===================================================================
RCS file: /cvs/gstreamer/gstreamer/tools/gst-xmlinspect.c,v
retrieving revision 1.26
diff -u -r1.26 gst-xmlinspect.c
--- tools/gst-xmlinspect.c	8 Jun 2005 22:16:27 -0000	1.26
+++ tools/gst-xmlinspect.c	24 Jun 2005 10:03:16 -0000
@@ -825,18 +825,25 @@
   GstElementFactory *factory;
   GstPlugin *plugin;
   gchar *so;
-  struct poptOption options[] = {
-    {"gst-inspect-plugin", 'p', POPT_ARG_STRING | POPT_ARGFLAG_STRIP, NULL, 0,
+  GOptionEntry options[] = {
+    {"gst-inspect-plugin", 'p', 0, G_OPTION_ARG_STRING,
         "Show plugin details", NULL},
-    {"gst-inspect-scheduler", 's', POPT_ARG_STRING | POPT_ARGFLAG_STRIP, NULL,
-          0,
+    {"gst-inspect-scheduler", 's', 0, G_OPTION_ARG_STRING,
         "Show scheduler details", NULL},
-    POPT_TABLEEND
+    {NULL}
   };
+  GOptionContext *ctx;
+  GError *err = NULL;
 
   setlocale (LC_ALL, "");
 
-  gst_init_with_popt_table (&argc, &argv, options);
+  ctx = g_option_context_new ("gst-xmlinspect");
+  g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
+  g_option_context_add_group (ctx, gst_init_get_option_group ());
+  if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
+    g_print ("Error initializing: %s\n", err->message);
+    exit (1);
+  }
   gst_control_init (&argc, &argv);
 
   PUT_STRING (0, "<?xml version=\"1.0\"?>");
