From 7fb210365ad968646a0088d80f709165bf068950 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Fri, 29 Apr 2011 14:19:08 -0400 Subject: [PATCH] Use dynamic shared libraries, list formats We need to make the format librarires dynamically linked to be able to get the constructor to run. Signed-off-by: Mathieu Desnoyers --- converter/Makefile.am | 6 +++--- converter/babeltrace.c | 17 ++++++++++++++++- formats/Makefile.am | 4 ++-- formats/ctf/Makefile.am | 11 +++++++---- formats/ctf/ctf.c | 4 +--- formats/ctf/metadata/Makefile.am | 16 ++++++++++------ formats/ctf/types/Makefile.am | 4 ++-- formats/registry.c | 18 ++++++++++++++++++ include/babeltrace/format.h | 2 ++ types/Makefile.am | 4 ++-- 10 files changed, 63 insertions(+), 23 deletions(-) diff --git a/converter/Makefile.am b/converter/Makefile.am index 66032beb..75215f8a 100644 --- a/converter/Makefile.am +++ b/converter/Makefile.am @@ -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 diff --git a/converter/babeltrace.c b/converter/babeltrace.c index 8ec3d64b..63ade113 100644 --- a/converter/babeltrace.c +++ b/converter/babeltrace.c @@ -17,6 +17,7 @@ */ #include +#include #include #include #include @@ -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; diff --git a/formats/Makefile.am b/formats/Makefile.am index 41ccc06d..f56df7e2 100644 --- a/formats/Makefile.am +++ b/formats/Makefile.am @@ -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 diff --git a/formats/ctf/Makefile.am b/formats/ctf/Makefile.am index a20d7c4a..5e665429 100644 --- a/formats/ctf/Makefile.am +++ b/formats/ctf/Makefile.am @@ -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 diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index 580133cc..57357b79 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -19,8 +19,6 @@ #include #include -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; diff --git a/formats/ctf/metadata/Makefile.am b/formats/ctf/metadata/Makefile.am index ddd7d1e0..527ae0c6 100644 --- a/formats/ctf/metadata/Makefile.am +++ b/formats/ctf/metadata/Makefile.am @@ -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 diff --git a/formats/ctf/types/Makefile.am b/formats/ctf/types/Makefile.am index 9ce41a6b..a2861dca 100644 --- a/formats/ctf/types/Makefile.am +++ b/formats/ctf/types/Makefile.am @@ -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 \ diff --git a/formats/registry.c b/formats/registry.c index 4f9dc244..17bc3bce 100644 --- a/formats/registry.c +++ b/formats/registry.c @@ -19,6 +19,7 @@ #include #include #include +#include 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) diff --git a/include/babeltrace/format.h b/include/babeltrace/format.h index ad2f0cd1..590ab4cb 100644 --- a/include/babeltrace/format.h +++ b/include/babeltrace/format.h @@ -21,6 +21,7 @@ #include #include +#include #include 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 */ diff --git a/types/Makefile.am b/types/Makefile.am index 36c4337b..21131910 100644 --- a/types/Makefile.am +++ b/types/Makefile.am @@ -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 \ -- 2.34.1