Use dlopen(2) for cups libraries to get rid of the cups flavor and

the evil circular dependencies.

Idea: bernd@
Tests: ajacoutot@
Catering: Sir Lancelot
Music: Dave Soldier and Komar & Melamid

ok ajacoutot@
This commit is contained in:
kili 2008-11-12 19:26:38 +00:00
parent b5496bf06d
commit fe63fbce40
5 changed files with 172 additions and 43 deletions

View File

@ -1,9 +1,10 @@
# $OpenBSD: Makefile,v 1.58 2008/10/28 17:53:42 kili Exp $
# $OpenBSD: Makefile,v 1.59 2008/11/12 19:26:38 kili Exp $
COMMENT= GNU PostScript interpreter
VERSION= 8.63
DISTNAME= ghostscript-${VERSION}
PKGNAME= ${DISTNAME}p0
CATEGORIES= print lang
SHARED_LIBS= gs 11.0
@ -13,7 +14,7 @@ HOMEPAGE= http://www.cs.wisc.edu/~ghost/
MAINTAINER= Matthias Kilian <kili@openbsd.org>
FLAVORS= a4 gtk no_x11 cups
FLAVORS= a4 gtk no_x11
FLAVOR?=
FLAVOR_STRING= ${FLAVOR_EXT:S/-/,/g}
@ -32,7 +33,7 @@ WANTLIB= m c pthread z
MODULES= converters/libiconv
RUN_DEPENDS= :ghostscript-fonts-*:print/ghostscript/gnu-fonts
BUILD_DEPENDS= ::print/cups
LIB_DEPENDS= jpeg.>=62::graphics/jpeg \
png.>=6::graphics/png \
ijs::print/ijs
@ -46,6 +47,10 @@ CFLAGS+= -DSYS_TYPES_HAS_STDINT_TYPES \
MAKE_FLAGS= BINDIR=./obj \
CFLAGS_STANDARD='${CFLAGS} -fPIC' \
CUPSCFLAGS="$$(cups-config --cflags)" \
CUPSSERVERBIN="$$(cups-config --serverbin)" \
CUPSSERVERROOT="$$(cups-config --serverroot)" \
CUPSDATA="$$(cups-config --datadir)" \
DEVICE_DEVS='${DEVICES:=$(DD)%.dev}' \
EXTRALIBS="${EXTRALIBS}" \
GLGENDIR=./obj \
@ -98,11 +103,8 @@ WANTLIB+= Xcomposite Xcursor Xdamage Xau Xdmcp Xfixes Xi Xinerama \
Xrandr Xrender atk-1.0 cairo expat fontconfig freetype \
glib-2.0 glitz gmodule-2.0 gobject-2.0 pango-1.0 \
pangocairo-1.0 pangoft2-1.0 pixman-1
MAKE_FLAGS+= SOC_CFLAGS="$$(pkg-config gtk+-2.0 --cflags)"
# This one is used in the addition of SOC_LIBS to MAKE_FLAGS later.
# We need this stunt to get gsc and gsx linked correctly when the cups
# flavor is enabled.
SOC_LIBS= $$(pkg-config gtk+-2.0 --libs) -pthread
MAKE_FLAGS+= SOC_CFLAGS="$$(pkg-config gtk+-2.0 --cflags)" \
SOC_LIBS="$$(pkg-config gtk+-2.0 --libs) -pthread"
ALL_TARGET= so
INSTALL_TARGET= install install-so
NOT_FOR_ARCHS= ${NO_SHARED_ARCHS}
@ -115,22 +117,6 @@ WANTLIB+= X11 Xt Xext
DEVICES+= ${X11_DEVICES}
.endif
.if ${FLAVOR:L:Mcups}
LIB_DEPENDS+= cups.>=3,cupsimage.>=2::print/cups
CUPSLIBS= $$(cups-config --image --libs)
EXTRALIBS+= ${CUPSLIBS}
SOC_LIBS+= ${CUPSLIBS}
DEVICES+= ${CUPS_DEVICES}
WANTLIB+= crypto ssl tiff
MAKE_FLAGS+= CUPSCFLAGS="$$(cups-config --cflags)" \
CUPSSERVERBIN="$$(cups-config --serverbin)" \
CUPSSERVERROOT="$$(cups-config --serverroot)" \
CUPSDATA="$$(cups-config --datadir)"
.endif
SOC_LIBS?=
MAKE_FLAGS+= SOC_LIBS="${SOC_LIBS}"
NO_REGRESS= Yes
# Avoid surprises in update-patches.
@ -174,11 +160,7 @@ post-install:
ln -sf ps2pdf.1 ps2pdf13.1 && \
ln -sf ps2pdf.1 ps2pdf14.1 && \
ln -sf ps2ps.1 eps2eps.1
.if ${FLAVOR:L:Mcups}
mv ${DESTDIR}/etc/cups/* ${PREFIX}/share/ghostscript/${VERSION}/examples
.else
rm -rf ${PREFIX}/libexec/cups
.endif
rm -rf ${DESTDIR}/etc/cups
# Device list based on configure.ac:
@ -291,7 +273,7 @@ DEVICES+= bit bitcmyk bitrgb bitrgbtags ccr cgm24 cgm8 cgmmono \
DEVICES+= ijs
# Cups
CUPS_DEVICES= cups
DEVICES+= cups
# gtk (display driver)
GTK_DEVICES= display

View File

@ -0,0 +1,150 @@
$OpenBSD: patch-cups_gdevcups_c,v 1.1 2008/11/12 19:26:38 kili Exp $
--- cups/gdevcups.c.orig Mon May 14 20:22:09 2007
+++ cups/gdevcups.c Thu Oct 30 15:47:00 2008
@@ -69,6 +69,7 @@
#include "gsexit.h"
#include "arch.h"
+#include <dlfcn.h>
#include <stdlib.h>
#include <ctype.h>
#include <cups/raster.h>
@@ -87,7 +88,7 @@
#ifdef CUPS_RASTER_SYNCv1
# define cups_page_header_t cups_page_header2_t
-# define cupsRasterWriteHeader cupsRasterWriteHeader2
+# define cupsRasterWriteHeader cups->cupsRasterWriteHeader2
#else
/* The RGBW colorspace is not defined until CUPS 1.2... */
# define CUPS_CSPACE_RGBW 17
@@ -204,6 +205,14 @@ typedef struct gx_device_cups_s
cups_raster_t *stream; /* Raster stream */
cups_page_header_t header; /* PostScript page device info */
int landscape; /* Non-zero if this is landscape */
+
+ /* cups stubs, initialized in cups_open() */
+ int libCupsReady;
+ void (*cupsRasterClose) (cups_raster_t *);
+ cups_raster_t *(*cupsRasterOpen) (int, cups_mode_t);
+ unsigned (*cupsRasterWriteHeader2) (cups_raster_t *, cups_page_header2_t *);
+ unsigned (*cupsRasterWritePixels) (cups_raster_t *, unsigned char *, unsigned);
+ ppd_file_t *(*ppdOpenFile) (const char *);
} gx_device_cups;
private gx_device_procs cups_procs =
@@ -352,7 +361,14 @@ gx_device_cups gs_cups_device =
0, /* cupsRowCount */
0, /* cupsRowFeed */
0 /* cupsRowStep */
- }
+ },
+ 0, /* landscape */
+ 0, /* libCupsReady */
+ NULL, /* cupsRasterClose */
+ NULL, /* cupsRasterOpen */
+ NULL, /* cupsRasterWriteHeader2 */
+ NULL, /* cupsRasterWritePixels */
+ NULL /* ppdOpenFile */
};
/*
@@ -426,7 +442,7 @@ cups_close(gx_device *pdev) /* I - Device info */
if (cups->stream != NULL)
{
- cupsRasterClose(cups->stream);
+ cups->cupsRasterClose(cups->stream);
cups->stream = NULL;
}
@@ -2496,6 +2512,35 @@ cups_open(gx_device *pdev) /* I - Device info */
dprintf1("DEBUG2: cups_open(%p)\n", pdev);
+ if (!cups->libCupsReady) {
+ void *handle;
+ if (!(handle = dlopen("libcupsimage.so.2", 0))) {
+ eprintf1("ERROR: libcupsimage.so.2: %s\n", dlerror());
+ return -1;
+ }
+ if (!(cups->cupsRasterClose = dlsym(handle, "cupsRasterClose"))) {
+ eprintf1("ERROR: cupsRasterClose: %s\n", dlerror());
+ return -1;
+ }
+ if (!(cups->cupsRasterOpen = dlsym(handle, "cupsRasterOpen"))) {
+ eprintf1("ERROR: cupsRasterOpen: %s\n", dlerror());
+ return -1;
+ }
+ if (!(cups->cupsRasterWriteHeader2 = dlsym(handle, "cupsRasterWriteHeader2"))) {
+ eprintf1("ERROR: cupsRasterWriteHeader2: %s\n", dlerror());
+ return -1;
+ }
+ if (!(cups->cupsRasterWritePixels = dlsym(handle, "cupsRasterWritePixels"))) {
+ eprintf1("ERROR: cupsRasterWritePixels: %s\n", dlerror());
+ return -1;
+ }
+ if (!(cups->ppdOpenFile = dlsym(handle, "ppdOpenFile"))) {
+ eprintf1("ERROR: ppdOpenFile: %s\n", dlerror());
+ return -1;
+ }
+ cups->libCupsReady = 1;
+ }
+
cups->printer_procs.get_space_params = cups_get_space_params;
if (cups->page == 0)
@@ -2510,7 +2555,7 @@ cups_open(gx_device *pdev) /* I - Device info */
return (code);
if (cupsPPD == NULL)
- cupsPPD = ppdOpenFile(getenv("PPD"));
+ cupsPPD = cups->ppdOpenFile(getenv("PPD"));
return (0);
}
@@ -2597,7 +2642,7 @@ cups_print_pages(gx_device_printer *pdev,
if (cups->stream == NULL)
{
- if ((cups->stream = cupsRasterOpen(fileno(cups->file),
+ if ((cups->stream = cups->cupsRasterOpen(fileno(cups->file),
CUPS_RASTER_WRITE)) == NULL)
{
perror("ERROR: Unable to open raster stream - ");
@@ -3669,7 +3714,7 @@ cups_print_chunked(gx_device_printer *pdev,
* Write the bitmap data to the raster stream...
*/
- cupsRasterWritePixels(cups->stream, dst, cups->header.cupsBytesPerLine);
+ cups->cupsRasterWritePixels(cups->stream, dst, cups->header.cupsBytesPerLine);
}
else
{
@@ -3677,7 +3722,7 @@ cups_print_chunked(gx_device_printer *pdev,
* Write the scanline data to the raster stream...
*/
- cupsRasterWritePixels(cups->stream, srcptr, cups->header.cupsBytesPerLine);
+ cups->cupsRasterWritePixels(cups->stream, srcptr, cups->header.cupsBytesPerLine);
}
}
}
@@ -4345,7 +4390,7 @@ cups_print_banded(gx_device_printer *pdev,
* Write the bitmap data to the raster stream...
*/
- cupsRasterWritePixels(cups->stream, dst, cups->header.cupsBytesPerLine);
+ cups->cupsRasterWritePixels(cups->stream, dst, cups->header.cupsBytesPerLine);
}
}
@@ -4716,7 +4761,7 @@ cups_print_planar(gx_device_printer *pdev,
* Write the bitmap data to the raster stream...
*/
- cupsRasterWritePixels(cups->stream, dst, cups->header.cupsBytesPerLine);
+ cups->cupsRasterWritePixels(cups->stream, dst, cups->header.cupsBytesPerLine);
}
}

View File

@ -4,6 +4,5 @@ many different printers, file formats and some displays.
Flavors:
a4 - Build with support for A4 page size
cups - Build with the cups device and ps2raster
gtk - Build with Gtk+ support
no_x11 - Build without X support

View File

@ -1,11 +0,0 @@
@comment $OpenBSD: PFRAG.cups,v 1.1 2007/11/19 20:06:56 kili Exp $
libexec/cups/
libexec/cups/filter/
libexec/cups/filter/pstopxl
libexec/cups/filter/pstoraster
share/cups/
share/cups/model/
share/cups/model/pxlcolor.ppd
share/cups/model/pxlmono.ppd
share/ghostscript/${VERSION}/examples/pstoraster.convs
@sample ${SYSCONFDIR}/cups/pstroaster.convs

View File

@ -1,5 +1,6 @@
@comment $OpenBSD: PLIST,v 1.14 2008/10/28 17:53:42 kili Exp $
@comment $OpenBSD: PLIST,v 1.15 2008/11/12 19:26:38 kili Exp $
@pkgpath print/ghostscript/afpl${FLAVOR_STRING}
@pkgpath print/ghostscript/gnu${FLAVOR_STRING},cups
bin/bdftops
bin/dumphint
bin/dvipdf
@ -32,6 +33,10 @@ bin/ps2ps2
bin/pv.sh
bin/unix-lpr.sh
bin/wftopfa
libexec/cups/
libexec/cups/filter/
libexec/cups/filter/pstopxl
libexec/cups/filter/pstoraster
man/de/
man/de/man1/
@man man/de/man1/dvipdf.1
@ -74,6 +79,10 @@ man/de/man1/
@man man/man1/ps2pdfwr.1
@man man/man1/ps2ps.1
@man man/man1/wftopfa.1
share/cups/
share/cups/model/
share/cups/model/pxlcolor.ppd
share/cups/model/pxlmono.ppd
share/ghostscript/${VERSION}/
share/ghostscript/${VERSION}/Resource/
share/ghostscript/${VERSION}/Resource/CMap/
@ -423,6 +432,7 @@ share/ghostscript/${VERSION}/examples/doretree.ps
share/ghostscript/${VERSION}/examples/escher.ps
share/ghostscript/${VERSION}/examples/golfer.eps
share/ghostscript/${VERSION}/examples/grayalph.ps
share/ghostscript/${VERSION}/examples/pstoraster.convs
share/ghostscript/${VERSION}/examples/ridt91.eps
share/ghostscript/${VERSION}/examples/snowflak.ps
share/ghostscript/${VERSION}/examples/tiger.eps
@ -658,5 +668,4 @@ share/ghostscript/${VERSION}/lib/winmaps.ps
share/ghostscript/${VERSION}/lib/wrfont.ps
share/ghostscript/${VERSION}/lib/xlatmap
share/ghostscript/${VERSION}/lib/zeroline.ps
%%cups%%
%%gtk%%