Permalink
Browse files

Move openslide-tools-common and test-common to new static library

  • Loading branch information...
1 parent 489c47f commit 79e23d781f8474a0422a7956b16b4812a6bfbd80 @bgilbert bgilbert committed Sep 8, 2015
View
@@ -1,4 +1,5 @@
*~
+*.a
*.la
*.lo
*.loT
View
@@ -74,6 +74,7 @@ pkginclude_HEADERS = \
src/openslide-features.h
noinst_HEADERS = \
+ common/openslide-common.h \
src/openslide-cairo.h \
src/openslide-decode-gdkpixbuf.h \
src/openslide-decode-jp2k.h \
@@ -85,41 +86,51 @@ noinst_HEADERS = \
src/openslide-decode-xml.h \
src/openslide-error.h \
src/openslide-hash.h \
- src/openslide-private.h \
- test/test-common.h \
- tools/openslide-tools-common.h
+ src/openslide-private.h
+# common program code
+
+noinst_LIBRARIES = common/libopenslide-common.a
+
+common_libopenslide_common_a_CPPFLAGS = $(COMMON_CPPFLAGS)
+common_libopenslide_common_a_SOURCES = \
+ common/openslide-common-cmdline.c \
+ common/openslide-common-fd.c
+
+COMMON_CPPFLAGS = $(GLIB2_CFLAGS) -I$(top_srcdir)/src -I$(top_srcdir)/common
+COMMON_LDADD = src/libopenslide.la common/libopenslide-common.a $(GLIB2_LIBS)
+
+
+# test
noinst_PROGRAMS = test/test test/try_open test/parallel test/query \
test/extended test/mosaic test/profile
noinst_SCRIPTS = test/driver
CLEANFILES += test/driver
EXTRA_DIST += test/driver.in
-test_test_CPPFLAGS = $(GLIB2_CFLAGS) $(CAIRO_CFLAGS) $(VALGRIND_CFLAGS) -I$(top_srcdir)/src
+test_test_CPPFLAGS = $(COMMON_CPPFLAGS) $(CAIRO_CFLAGS) $(VALGRIND_CFLAGS)
# VALGRIND_LIBS not needed
-test_test_LDADD = src/libopenslide.la $(GLIB2_LIBS) $(CAIRO_LIBS)
+test_test_LDADD = $(COMMON_LDADD) $(CAIRO_LIBS)
-test_try_open_SOURCES = test/test-common.c test/try_open.c
-test_try_open_CPPFLAGS = $(GLIB2_CFLAGS) -I$(top_srcdir)/src
-test_try_open_LDADD = src/libopenslide.la $(GLIB2_LIBS)
+test_try_open_CPPFLAGS = $(COMMON_CPPFLAGS)
+test_try_open_LDADD = $(COMMON_LDADD)
-test_parallel_CPPFLAGS = $(GLIB2_CFLAGS) -I$(top_srcdir)/src
-test_parallel_LDADD = src/libopenslide.la $(GLIB2_LIBS)
+test_parallel_CPPFLAGS = $(COMMON_CPPFLAGS)
+test_parallel_LDADD = $(COMMON_LDADD)
-test_query_CPPFLAGS = $(GLIB2_CFLAGS) -I$(top_srcdir)/src
-test_query_LDADD = src/libopenslide.la $(GLIB2_LIBS)
+test_query_CPPFLAGS = $(COMMON_CPPFLAGS)
+test_query_LDADD = $(COMMON_LDADD)
-test_extended_SOURCES = test/test-common.c test/extended.c
-test_extended_CPPFLAGS = $(GLIB2_CFLAGS) -I$(top_srcdir)/src
-test_extended_LDADD = src/libopenslide.la $(GLIB2_LIBS)
+test_extended_CPPFLAGS = $(COMMON_CPPFLAGS)
+test_extended_LDADD = $(COMMON_LDADD)
-test_mosaic_CPPFLAGS = $(GLIB2_CFLAGS) $(CAIRO_CFLAGS) -I$(top_srcdir)/src
-test_mosaic_LDADD = src/libopenslide.la $(GLIB2_LIBS) $(CAIRO_LIBS)
+test_mosaic_CPPFLAGS = $(COMMON_CPPFLAGS) $(CAIRO_CFLAGS)
+test_mosaic_LDADD = $(COMMON_LDADD) $(CAIRO_LIBS)
-test_profile_CPPFLAGS = $(GLIB2_CFLAGS) $(VALGRIND_CFLAGS) -I$(top_srcdir)/src
-test_profile_LDADD = src/libopenslide.la $(GLIB2_LIBS)
+test_profile_CPPFLAGS = $(COMMON_CPPFLAGS) $(VALGRIND_CFLAGS)
+test_profile_LDADD = $(COMMON_LDADD)
if CYGWIN_CROSS_TEST
noinst_PROGRAMS += test/symlink
@@ -142,23 +153,20 @@ test/driver: test/driver.in Makefile
# show-properties
bin_PROGRAMS = tools/openslide-show-properties
man_MANS = tools/openslide-show-properties.1
-tools_openslide_show_properties_SOURCES = tools/openslide-tools-common.c tools/openslide-show-properties.c
-tools_openslide_show_properties_CPPFLAGS = -I$(top_srcdir)/src $(GLIB2_CFLAGS)
-tools_openslide_show_properties_LDADD = src/libopenslide.la $(GLIB2_LIBS)
+tools_openslide_show_properties_CPPFLAGS = $(COMMON_CPPFLAGS)
+tools_openslide_show_properties_LDADD = $(COMMON_LDADD)
# quickhash1sum
bin_PROGRAMS += tools/openslide-quickhash1sum
man_MANS += tools/openslide-quickhash1sum.1
-tools_openslide_quickhash1sum_SOURCES = tools/openslide-tools-common.c tools/openslide-quickhash1sum.c
-tools_openslide_quickhash1sum_CPPFLAGS = -I$(top_srcdir)/src $(GLIB2_CFLAGS)
-tools_openslide_quickhash1sum_LDADD = src/libopenslide.la $(GLIB2_LIBS)
+tools_openslide_quickhash1sum_CPPFLAGS = $(COMMON_CPPFLAGS)
+tools_openslide_quickhash1sum_LDADD = $(COMMON_LDADD)
# write-png
bin_PROGRAMS += tools/openslide-write-png
man_MANS += tools/openslide-write-png.1
-tools_openslide_write_png_SOURCES = tools/openslide-tools-common.c tools/openslide-write-png.c
-tools_openslide_write_png_CPPFLAGS = -I$(top_srcdir)/src $(LIBPNG_CFLAGS) $(GLIB2_CFLAGS)
-tools_openslide_write_png_LDADD = src/libopenslide.la $(LIBPNG_LIBS) $(GLIB2_LIBS)
+tools_openslide_write_png_CPPFLAGS = $(COMMON_CPPFLAGS) $(LIBPNG_CFLAGS)
+tools_openslide_write_png_LDADD = $(COMMON_LDADD) $(LIBPNG_LIBS)
# man pages
EXTRA_DIST += $(man_MANS:=.in)
@@ -30,7 +30,7 @@
#include <string.h>
#include <glib.h>
#include "openslide.h"
-#include "openslide-tools-common.h"
+#include "openslide-common.h"
#include "config.h"
static const char *version_format = "%s " SUFFIXED_VERSION ", "
@@ -53,7 +53,7 @@ static const GOptionEntry options[] = {
};
-static GOptionContext *make_option_context(const struct openslide_tools_usage_info *info) {
+static GOptionContext *make_option_context(const struct common_usage_info *info) {
GOptionContext *octx = g_option_context_new(info->parameter_string);
g_option_context_set_summary(octx, info->summary);
g_option_context_add_main_entries(octx, options, NULL);
@@ -67,7 +67,7 @@ static void free_argv(void) {
g_strfreev(fixed_argv);
}
-bool _openslide_tools_fix_argv(int *argc, char ***argv) {
+bool common_fix_argv(int *argc, char ***argv) {
if (fixed_argv == NULL) {
#ifdef G_OS_WIN32
fixed_argv = g_win32_get_command_line();
@@ -81,21 +81,19 @@ bool _openslide_tools_fix_argv(int *argc, char ***argv) {
return true;
}
#else
-bool _openslide_tools_fix_argv(int *argc G_GNUC_UNUSED,
- char ***argv G_GNUC_UNUSED) {
+bool common_fix_argv(int *argc G_GNUC_UNUSED, char ***argv G_GNUC_UNUSED) {
return false;
}
#endif
-void _openslide_tools_parse_commandline(const struct openslide_tools_usage_info *info,
- int *argc,
- char ***argv) {
+void common_parse_commandline(const struct common_usage_info *info,
+ int *argc, char ***argv) {
GError *err = NULL;
GOptionContext *octx = make_option_context(info);
// use modern parsing functions if possible, so we can properly handle
// Unicode arguments on Windows
- bool free_args = _openslide_tools_fix_argv(argc, argv);
+ bool free_args = common_fix_argv(argc, argv);
if (free_args) {
g_option_context_parse_strv(octx, argv, &err);
*argc = g_strv_length(*argv);
@@ -107,7 +105,7 @@ void _openslide_tools_parse_commandline(const struct openslide_tools_usage_info
if (err) {
fprintf(stderr, "%s: %s\n\n", g_get_prgname(), err->message);
g_error_free(err);
- _openslide_tools_usage(info);
+ common_usage(info);
} else if (show_version) {
fprintf(stderr, version_format, g_get_prgname(), openslide_get_version());
@@ -129,7 +127,7 @@ void _openslide_tools_parse_commandline(const struct openslide_tools_usage_info
}
}
-void _openslide_tools_usage(const struct openslide_tools_usage_info *info) {
+void common_usage(const struct common_usage_info *info) {
GOptionContext *octx = make_option_context(info);
gchar *help = g_option_context_get_help(octx, TRUE, NULL);
@@ -38,9 +38,9 @@
#include <libproc.h>
#endif
-#include "test-common.h"
+#include "openslide-common.h"
-char *get_fd_path(int fd) {
+char *common_get_fd_path(int fd) {
struct stat st;
if (fstat(fd, &st)) {
return NULL;
@@ -19,9 +19,28 @@
*
*/
-#ifndef OPENSLIDE_TEST_TEST_COMMON_H
-#define OPENSLIDE_TEST_TEST_COMMON_H
+#ifndef OPENSLIDE_COMMON_H
+#define OPENSLIDE_COMMON_H
-char *get_fd_path(int fd);
+#include <stdbool.h>
+#include <glib.h>
+
+// cmdline
+
+struct common_usage_info {
+ const char *parameter_string;
+ const char *summary;
+};
+
+void common_parse_commandline(const struct common_usage_info *info,
+ int *argc, char ***argv);
+
+void common_usage(const struct common_usage_info *info) G_GNUC_NORETURN;
+
+bool common_fix_argv(int *argc, char ***argv);
+
+// fd
+
+char *common_get_fd_path(int fd);
#endif
View
@@ -33,7 +33,7 @@
#include <glib.h>
#include <openslide.h>
-#include "test-common.h"
+#include "openslide-common.h"
#include "config.h"
#define MAX_LEAK_FD 128
@@ -100,7 +100,7 @@ static gpointer cloexec_thread(const gpointer prog) {
static void child_check_open_fds(void) {
for (int i = 3; i < MAX_LEAK_FD; i++) {
- gchar *path = get_fd_path(i);
+ gchar *path = common_get_fd_path(i);
if (path != NULL) {
printf("%s\n", path);
g_free(path);
View
@@ -27,7 +27,7 @@
#include <unistd.h>
#include <glib.h>
#include "openslide.h"
-#include "test-common.h"
+#include "openslide-common.h"
#define MAX_FDS 128
#define TIME_ITERATIONS 5
@@ -255,7 +255,7 @@ int main(int argc, char **argv) {
// Check for file descriptor leaks
for (int i = 0; i < MAX_FDS; i++) {
if (!g_hash_table_lookup(fds, GINT_TO_POINTER(i))) {
- char *path = get_fd_path(i);
+ char *path = common_get_fd_path(i);
if (path != NULL) {
// leaked
fprintf(stderr, "Leaked file descriptor to %s\n", path);
@@ -22,7 +22,7 @@
#include <stdio.h>
#include <glib.h>
#include "openslide.h"
-#include "openslide-tools-common.h"
+#include "openslide-common.h"
static gboolean process(const char *file) {
openslide_t *osr = openslide_open(file);
@@ -58,15 +58,15 @@ static gboolean process(const char *file) {
}
-static const struct openslide_tools_usage_info usage_info = {
+static const struct common_usage_info usage_info = {
"FILE...",
"Print OpenSlide quickhash-1 (256-bit) checksums.",
};
int main (int argc, char **argv) {
- _openslide_tools_parse_commandline(&usage_info, &argc, &argv);
+ common_parse_commandline(&usage_info, &argc, &argv);
if (argc < 2) {
- _openslide_tools_usage(&usage_info);
+ common_usage(&usage_info);
}
int ret = 0;
@@ -22,7 +22,7 @@
#include <stdio.h>
#include <glib.h>
#include "openslide.h"
-#include "openslide-tools-common.h"
+#include "openslide-common.h"
static gboolean process(const char *file, int successes, int total) {
openslide_t *osr = openslide_open(file);
@@ -65,15 +65,15 @@ static gboolean process(const char *file, int successes, int total) {
}
-static const struct openslide_tools_usage_info usage_info = {
+static const struct common_usage_info usage_info = {
"FILE...",
"Print OpenSlide properties for a slide.",
};
int main (int argc, char **argv) {
- _openslide_tools_parse_commandline(&usage_info, &argc, &argv);
+ common_parse_commandline(&usage_info, &argc, &argv);
if (argc < 2) {
- _openslide_tools_usage(&usage_info);
+ common_usage(&usage_info);
}
int successes = 0;
@@ -1,41 +0,0 @@
-/*
- * OpenSlide, a library for reading whole slide image files
- *
- * Copyright (c) 2007-2012 Carnegie Mellon University
- * All rights reserved.
- *
- * OpenSlide is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, version 2.1.
- *
- * OpenSlide is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with OpenSlide. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- */
-
-#ifndef _OPENSLIDE_TOOLS_COMMON_H
-#define _OPENSLIDE_TOOLS_COMMON_H
-
-#include <glib.h>
-
-struct openslide_tools_usage_info {
- const char *parameter_string;
- const char *summary;
-};
-
-void _openslide_tools_parse_commandline(const struct openslide_tools_usage_info *info,
- int *argc,
- char ***argv);
-
-void _openslide_tools_usage(const struct openslide_tools_usage_info *info)
- G_GNUC_NORETURN;
-
-bool _openslide_tools_fix_argv(int *argc, char ***argv);
-
-#endif
@@ -20,7 +20,7 @@
*/
#include "openslide.h"
-#include "openslide-tools-common.h"
+#include "openslide-common.h"
#include <png.h>
#include <inttypes.h>
@@ -172,15 +172,15 @@ static void write_png(openslide_t *osr, FILE *f,
}
-static const struct openslide_tools_usage_info usage_info = {
+static const struct common_usage_info usage_info = {
"slide x y level width height output.png",
"Write a region of a virtual slide to a PNG.",
};
int main (int argc, char **argv) {
- _openslide_tools_parse_commandline(&usage_info, &argc, &argv);
+ common_parse_commandline(&usage_info, &argc, &argv);
if (argc != 8) {
- _openslide_tools_usage(&usage_info);
+ common_usage(&usage_info);
}
// get args

0 comments on commit 79e23d7

Please sign in to comment.