From ed58698df4dd64ed4996544265039b90366080da Mon Sep 17 00:00:00 2001 From: Andrea Canciani Date: Tue, 3 Nov 2009 22:51:29 +0100 Subject: [PATCH] [trace] Fix compilation on MacOS X Enable "ld_preload" (DYLD_INSERT_LIBRARIES + DYLD_FORCE_FLAT_NAMESPACE) and build cairo-trace as a library instead of a module to make it work also on MacOS X. --- configure.ac | 17 ++++++++++++++++- util/cairo-trace/Makefile.am | 22 +++++++++++----------- util/cairo-trace/cairo-trace.in | 6 +++++- util/cairo-trace/trace.c | 2 +- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index 2680f21..f811027 100644 --- a/configure.ac +++ b/configure.ac @@ -652,11 +652,26 @@ AM_CONDITIONAL(BUILD_ANY2PPM, -o "x$any2ppm_cs" = "xyes") dnl =========================================================================== +dnl Some utilities need to dlopen the shared libraries, so they need to +dnl know how libtools will name them + +case $host in +*-*-darwin*) + SHLIB_EXT="dylib" + ;; +*) + SHLIB_EXT="so" + ;; +esac +AC_DEFINE_UNQUOTED(SHARED_LIB_EXT, "${SHLIB_EXT}", [Shared library file extension]) +AC_SUBST(SHLIB_EXT) + +dnl =========================================================================== dnl The tracing utility requires LD_PRELOAD, so only build it for systems dnl that are known to work. case $host in -*-linux*|*-*bsd*|*-solaris*) +*-linux*|*-*bsd*|*-solaris*|*-*-darwin*) have_ld_preload="yes" ;; *) diff --git a/util/cairo-trace/Makefile.am b/util/cairo-trace/Makefile.am index 5b6e781..16403a8 100644 --- a/util/cairo-trace/Makefile.am +++ b/util/cairo-trace/Makefile.am @@ -2,37 +2,37 @@ cairolibdir = $(libdir)/cairo cairooutdir = $(localstatedir)/lib/cairo-trace bin_SCRIPTS = cairo-trace -cairolib_LTLIBRARIES = cairo-trace.la +cairolib_LTLIBRARIES = libcairo-trace.la AM_CPPFLAGS = -I$(top_srcdir)/src \ -I$(top_builddir)/src -cairo_trace_la_SOURCES = trace.c -cairo_trace_la_CPPFLAGS = -DCAIRO_TRACE_OUTDIR="\"$(cairooutdir)\"" \ +libcairo_trace_la_SOURCES = trace.c +libcairo_trace_la_CPPFLAGS = -DCAIRO_TRACE_OUTDIR="\"$(cairooutdir)\"" \ $(AM_CPPFLAGS) -cairo_trace_la_CFLAGS = $(CAIRO_CFLAGS) -cairo_trace_la_LDFLAGS = -module -no-undefined +libcairo_trace_la_CFLAGS = $(CAIRO_CFLAGS) +libcairo_trace_la_LDFLAGS = -no-undefined -cairo_trace_la_LIBADD = -lz $(pthread_LIBS) +libcairo_trace_la_LIBADD = -lz $(pthread_LIBS) if CAIRO_HAS_DL -cairo_trace_la_LIBADD += -ldl +libcairo_trace_la_LIBADD += -ldl endif if CAIRO_HAS_SYMBOL_LOOKUP -cairo_trace_la_SOURCES += \ +libcairo_trace_la_SOURCES += \ lookup-symbol.c \ lookup-symbol.h -cairo_trace_la_LIBADD += $(BFD_LIBS) +libcairo_trace_la_LIBADD += $(BFD_LIBS) endif system-install: install -mkdir -p $(cairooutdir) -chmod 01777 $(cairooutdir) - grep -sq $(cairolibdir)/cairo-trace.so /etc/ld.so.preload || echo $(cairolibdir)/cairo-trace.so >> /etc/ld.so.preload + grep -sq $(cairolibdir)/libcairo-trace.so /etc/ld.so.preload || echo $(cairolibdir)/libcairo-trace.so >> /etc/ld.so.preload system-uninstall: uninstall - sed -e '/cairo-trace.so/d' < /etc/ld.so.preload > /tmp/ld.so.preload && mv /tmp/ld.so.preload /etc/ld.so.preload; + sed -e '/libcairo-trace.so/d' < /etc/ld.so.preload > /tmp/ld.so.preload && mv /tmp/ld.so.preload /etc/ld.so.preload; EXTRA_DIST = \ COPYING \ diff --git a/util/cairo-trace/cairo-trace.in b/util/cairo-trace/cairo-trace.in index fc830bf..1fc3de6 100644 --- a/util/cairo-trace/cairo-trace.in +++ b/util/cairo-trace/cairo-trace.in @@ -90,7 +90,7 @@ export CAIRO_TRACE_PROG_NAME if test "x$CAIRO_TRACE_SO" = "x"; then CAIRO_TRACE_SO="" - for lib in @libdir@/cairo/cairo-trace.so @libdir@/cairo/cairo-trace.so*; do + for lib in @libdir@/cairo/libcairo-trace.@SHLIB_EXT@ @libdir@/cairo/libcairo-trace.@SHLIB_EXT@* @libdir@/cairo/libcairo-trace.*.@SHLIB_EXT@ ; do if test -h "$lib" -o -f "$lib"; then CAIRO_TRACE_SO="$lib" break @@ -104,7 +104,11 @@ if test "x$CAIRO_TRACE_SO" = "x"; then fi LD_PRELOAD="$CAIRO_TRACE_SO" +DYLD_INSERT_LIBRARIES="$CAIRO_TRACE_SO" +DYLD_FORCE_FLAT_NAMESPACE=1 export LD_PRELOAD +export DYLD_INSERT_LIBRARIES +export DYLD_FORCE_FLAT_NAMESPACE if test -n "$nocallers"; then CAIRO_TRACE_LINE_INFO=0 diff --git a/util/cairo-trace/trace.c b/util/cairo-trace/trace.c index 82172aa..ce2feb5 100644 --- a/util/cairo-trace/trace.c +++ b/util/cairo-trace/trace.c @@ -95,7 +95,7 @@ static void *_dlhandle = RTLD_NEXT; if (name##_real == NULL) { \ name##_real = (typeof (&name))(dlsym (_dlhandle, #name)); \ if (name##_real == NULL && _dlhandle == RTLD_NEXT) { \ - _dlhandle = dlopen ("libcairo.so", RTLD_LAZY); \ + _dlhandle = dlopen ("libcairo." SHARED_LIB_EXT, RTLD_LAZY); \ name##_real = (typeof (&name))(dlsym (_dlhandle, #name)); \ assert (name##_real != NULL); \ } \ -- 1.6.4.4