Use dynamic shared libraries, list formats
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 29 Apr 2011 18:19:08 +0000 (14:19 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 29 Apr 2011 18:19:08 +0000 (14:19 -0400)
We need to make the format librarires dynamically linked to be able to
get the constructor to run.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
converter/Makefile.am
converter/babeltrace.c
formats/Makefile.am
formats/ctf/Makefile.am
formats/ctf/ctf.c
formats/ctf/metadata/Makefile.am
formats/ctf/types/Makefile.am
formats/registry.c
include/babeltrace/format.h
types/Makefile.am

index 66032beb290f71d45b5861f23625668a54db4704..75215f8a54382de45c44cd69d6e8ca6f3095d7aa 100644 (file)
@@ -6,6 +6,6 @@ babeltrace_SOURCES = \
        babeltrace.c
 
 babeltrace_LDADD = \
-       $(top_srcdir)/types/libtypes.a \
-       $(top_srcdir)/formats/libregistry.a
-
+       $(top_builddir)/types/libbabeltrace_types.la \
+       $(top_builddir)/formats/libbabeltrace_registry.la \
+       $(top_builddir)/formats/ctf/libctf.la
index 8ec3d64b9b892c9c9071c2e8432db24a21713599..63ade113c81f719a1cb4b1a5b0178a5567fb826b 100644 (file)
@@ -17,6 +17,7 @@
  */
 
 #include <babeltrace/babeltrace.h>
+#include <babeltrace/format.h>
 #include <popt.h>
 #include <errno.h>
 #include <stdlib.h>
@@ -32,6 +33,7 @@ int babeltrace_verbose, babeltrace_debug;
 enum {
        OPT_NONE = 0,
        OPT_HELP,
+       OPT_LIST,
        OPT_VERBOSE,
        OPT_DEBUG,
 };
@@ -41,11 +43,18 @@ static struct poptOption long_options[] = {
        { "input-format", 'i', POPT_ARG_STRING, &opt_input_format, OPT_NONE, NULL, NULL },
        { "output-format", 'o', POPT_ARG_STRING, &opt_output_format, OPT_NONE, NULL, NULL },
        { "help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL },
+       { "list", 'l', POPT_ARG_NONE, NULL, OPT_LIST, NULL, NULL },
        { "verbose", 'v', POPT_ARG_NONE, NULL, OPT_VERBOSE, NULL, NULL },
        { "debug", 'd', POPT_ARG_NONE, NULL, OPT_DEBUG, NULL, NULL },
        { NULL, 0, 0, NULL, 0, NULL, NULL },
 };
 
+static void list_formats(FILE *fp)
+{
+       fprintf(fp, "\n");
+       bt_fprintf_format_list(fp);
+}
+
 static void usage(FILE *fp)
 {
        fprintf(fp, "Babeltrace %u.%u\n\n", BABELTRACE_VERSION_MAJOR,
@@ -59,8 +68,10 @@ static void usage(FILE *fp)
        fprintf(fp, "  -o, --output-format Input trace path\n");
        fprintf(fp, "\n");
        fprintf(fp, "  -h, --help          This help message\n");
+       fprintf(fp, "  -l, --list          List available formats\n");
        fprintf(fp, "  -v, --verbose       Verbose mode\n");
        fprintf(fp, "  -d, --debug         Debug mode\n");
+       list_formats(fp);
        fprintf(fp, "\n");
 }
 
@@ -79,9 +90,13 @@ static int parse_options(int argc, const char **argv)
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stderr);
+                       usage(stdout);
                        ret = 1;        /* exit cleanly */
                        goto end;
+               case OPT_LIST:
+                       list_formats(stdout);
+                       ret = 1;
+                       goto end;
                case OPT_VERBOSE:
                        babeltrace_verbose = 1;
                        break;
index 41ccc06d25b6464f76fca8ae4c58c5c5ed7eca51..f56df7e2bb651898a914205a02b4070574e4f309 100644 (file)
@@ -2,6 +2,6 @@ AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include
 
 SUBDIRS = . ctf
 
-noinst_LIBRARIES = libregistry.a
+lib_LTLIBRARIES = libbabeltrace_registry.la
 
-libregistry_a_SOURCES = registry.c
+libbabeltrace_registry_la_SOURCES = registry.c
index a20d7c4aeb037a8f8e67a901498ee967d709f457..5e665429bf6fbb2d38e53f6a1268db2f199a0c48 100644 (file)
@@ -1,10 +1,13 @@
 AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include
 
-SUBDIRS = . types metadata
+SUBDIRS = types metadata .
 
 lib_LTLIBRARIES = libctf.la
 
 libctf_la_SOURCES = \
-       ctf.c \
-       types/libctf-types.a
-       metadata/libctf-parser.a
+       ctf.c
+
+libctf_la_LIBADD = \
+       types/libctf-types.la \
+       metadata/libctf-parser.la \
+       metadata/libctf-ast.la
index 580133cc86c873fef4225e0bf3fbd65ff2019bb8..57357b792aa2a117f2242464e429f8adc4e659ff 100644 (file)
@@ -19,8 +19,6 @@
 #include <babeltrace/format.h>
 #include <babeltrace/ctf/types.h>
 
-void __attribute__((constructor)) ctf_init(void);
-
 static struct format ctf_format = {
        .uint_read = ctf_uint_read,
        .int_read = ctf_int_read,
@@ -45,7 +43,7 @@ static struct format ctf_format = {
        .sequence_end = ctf_sequence_end,
 };
 
-void ctf_init(void)
+void __attribute__((constructor)) ctf_init(void)
 {
        int ret;
 
index ddd7d1e089d7bec8e2a815dfc8daf6d1feff1cbb..527ae0c6b5acbd9d95685856c6b1bab4eb0c1329 100644 (file)
@@ -2,17 +2,21 @@ AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include
 BUILT_SOURCES = ctf-parser.h
 AM_YFLAGS = -t -d -v
 
-noinst_LIBRARIES = libctf-parser.a libctf-ast.a
+lib_LTLIBRARIES = libctf-parser.la libctf-ast.la
 
-libctf_parser_a_SOURCES = ctf-lexer.l ctf-parser.y
+libctf_parser_la_SOURCES = ctf-lexer.l ctf-parser.y
 
-libctf_ast_a_SOURCES = ctf-visitor-xml.c \
+libctf_ast_la_SOURCES = ctf-visitor-xml.c \
                ctf-visitor-parent-links.c \
                ctf-visitor-semantic-validator.c \
                ctf-visitor-generate-io-struct.c
 
+libctf_ast_la_LIBADD = \
+                $(top_builddir)/types/libbabeltrace_types.la
+
 bin_PROGRAMS = ctf-parser-test
 ctf_parser_test_SOURCES = ctf-parser-test.c
-ctf_parser_test_LDADD = libctf-parser.a \
-               libctf-ast.a \
-               $(top_builddir)/types/libtypes.a
+
+ctf_parser_test_LDADD = \
+               libctf-parser.la \
+               libctf-ast.la
index 9ce41a6bec267ab8a4cb5b53c08426f527236b72..a2861dcade9c81bb03f452a169e58f0d3fac0f59 100644 (file)
@@ -1,8 +1,8 @@
 AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include
 
-noinst_LIBRARIES = libctf-types.a
+lib_LTLIBRARIES = libctf-types.la
 
-libctf_types_a_SOURCES = \
+libctf_types_la_SOURCES = \
        array.c \
        enum.c \
        float.c \
index 4f9dc244a3618451c54e0f4265563d0a7a0bc739..17bc3bce7d36a3d68a9975ee5ac4b7d5c006b0e5 100644 (file)
@@ -19,6 +19,7 @@
 #include <babeltrace/format.h>
 #include <glib.h>
 #include <errno.h>
+#include <stdio.h>
 
 static int init_done;
 void __attribute__((constructor)) format_init(void);
@@ -39,6 +40,23 @@ struct format *bt_lookup_format(GQuark qname)
                                   (gconstpointer) (unsigned long) qname);
 }
 
+static void show_format(gpointer key, gpointer value, gpointer user_data)
+{
+       FILE *fp = user_data;
+
+       fprintf(fp, "format: %s\n",
+               g_quark_to_string((GQuark) (unsigned long) key));
+}
+
+void bt_fprintf_format_list(FILE *fp)
+{
+       fprintf(fp, "Formats available:\n");
+       if (!init_done)
+               return;
+       g_hash_table_foreach(format_registry, show_format, fp);
+       fprintf(fp, "End of formats available.\n");
+}
+
 int bt_register_format(struct format *format)
 {
        if (!init_done)
index ad2f0cd10f41435b09a3647aa47338a2d464d046..590ab4cb1cca73ef14c14aff98d3e7d45a261b35 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <babeltrace/types.h>
 #include <stdint.h>
+#include <stdio.h>
 #include <glib.h>
 
 struct format {
@@ -82,6 +83,7 @@ struct format {
 };
 
 struct format *bt_lookup_format(GQuark qname);
+void bt_fprintf_format_list(FILE *fp);
 int bt_register_format(struct format *format);
 
 /* TBD: format unregistration */
index 36c4337b4c4c19464b82e094bcb5b31e39fd7df7..2113191071c45f0de08d0f5a4a8226720aec1059 100644 (file)
@@ -1,8 +1,8 @@
 AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include
 
-noinst_LIBRARIES = libtypes.a
+lib_LTLIBRARIES = libbabeltrace_types.la
 
-libtypes_a_SOURCES = \
+libbabeltrace_types_la_SOURCES = \
        array.c \
        enum.c \
        float.c \
This page took 0.041637 seconds and 4 git commands to generate.