noinst_HEADERS = pack.h
if BUILD_UPKG
-bin_PROGRAMS = upkg
-upkg_SOURCES = upkg.c exportable.c serializable.c music.c
-upkg_CFLAGS = $(GLIB_CFLAGS)
-upkg_LDFLAGS = $(GLIB_LIBS)
-upkg_LDADD = libupkg.la $(LIBLTDL)
+
+bin_PROGRAMS = upkg
+upkg_SOURCES = upkg.c module.c exportable.c serializable.c music.c
+upkg_CPPFLAGS = $(GLIB_CFLAGS) $(LTDLINCL)
+upkg_LDFLAGS = $(GLIB_LIBS)
+upkg_LDADD = libupkg.la $(LIBLTDL)
+
endif
--- /dev/null
+#include <stdio.h>
+#include <glib-object.h>
+#include <ltdl.h>
+
+#include "module.h"
+
+static unsigned initialized;
+
+static void dl_print_errors(const char *prefix)
+{
+ const char *err;
+ while (err = lt_dlerror()) {
+ if (prefix) fprintf(stderr, "%s: ", prefix);
+ puts(lt_dlerror());
+ }
+}
+
+int module_init(void)
+{
+ if (!initialized) {
+ if (lt_dlinit() != 0) {
+ dl_print_errors(__func__);
+ return -1;
+ }
+
+ g_type_init();
+ }
+
+ initialized++;
+ return 0;
+}
+
+int module_exit(void)
+{
+ if (--initialized)
+ return 0;
+
+ if (lt_dlexit() != 0) {
+ dl_print_errors(__func__);
+ return -1;
+ }
+}
--- /dev/null
+#ifndef MODULE_H_
+#define MODULE_H_
+
+int module_init(void);
+int module_exit(void);
+
+#endif
#include <glib-object.h>
#include "upkg.h"
+#include "module.h"
#include "serializable.h"
#include "exportable.h"
#include "music.h"
{
struct upkg *pkg;
- g_type_init();
-
if (argc < 2) {
fprintf(stderr, "usage: upkg file\n");
return EXIT_FAILURE;
}
+ if (module_init() != 0)
+ return EXIT_FAILURE;
+
pkg = upkg_fopen(argv[1]);
if (!pkg) {
fprintf(stderr, "failed to open package!\n");
printf("Wrote %s\n", name);
upkg_close(pkg);
+ module_exit();
+
return 0;
}