From b6edaa59dac7ba241468ef06ec4c6313e14634cb Mon Sep 17 00:00:00 2001 From: Adesh Deshmukh Date: Thu, 12 Nov 2026 11:03:08 +0530 Subject: [PATCH] Support CUPS 3.x and PAPPL 2.x --- Makefile | 32 +++++++++++++++++++++++++++----- ghostscript-printer-app.c | 6 +++--- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index ba31b6d..e1eed3e 100644 --- a/Makefile +++ b/Makefile @@ -21,13 +21,35 @@ statedir = $(localstatedir)/lib/ghostscript-printer-app spooldir = $(localstatedir)/spool/ghostscript-printer-app serverbin = $(prefix)/lib/ghostscript-printer-app resourcedir = $(prefix)/share/ghostscript-printer-app -cupsserverbin = `cups-config --serverbin` -unitdir := $(DESTDIR)`pkg-config --variable=systemdsystemunitdir systemd` +# CUPS detection: prioritize CUPS 3.x (cups3), then CUPS 2.5 (cups), then legacy cups-config +CUPS_PKG := $(shell pkg-config --exists cups3 && echo cups3 || (pkg-config --exists cups && echo cups || echo "")) + +ifneq ($(CUPS_PKG),) +CUPS_CFLAGS := $(shell pkg-config --cflags $(CUPS_PKG)) +CUPS_LDFLAGS := +CUPS_LIBS := $(shell pkg-config --libs $(CUPS_PKG)) +cupsserverbin := $(shell pkg-config --variable=prefix $(CUPS_PKG))/lib/cups +else +CUPSCONFIG := $(shell which cups-config 2>/dev/null) +ifneq ($(CUPSCONFIG),) +CUPS_CFLAGS := $(shell cups-config --cflags) +CUPS_LDFLAGS := $(shell cups-config --ldflags) +CUPS_LIBS := $(shell cups-config --image --libs 2>/dev/null || cups-config --libs) +cupsserverbin := $(shell cups-config --serverbin) +else +cupsserverbin := +endif +endif + +# PAPPL detection: prioritize PAPPL 2.x (pappl2), fallback to PAPPL 1.x (pappl) +PAPPL_PKG := $(shell pkg-config --exists pappl2 && echo pappl2 || echo pappl) + +unitdir := $(DESTDIR)`pkg-config --variable=systemdsystemunitdir systemd 2>/dev/null || echo ""` # Compiler/linker options... OPTIM = -Os -g -CFLAGS += `pkg-config --cflags pappl` `cups-config --cflags` `pkg-config --cflags libppd` `pkg-config --cflags libcupsfilters` `pkg-config --cflags libpappl-retrofit` $(OPTIM) +CFLAGS += `pkg-config --cflags $(PAPPL_PKG)` $(CUPS_CFLAGS) `pkg-config --cflags libppd` `pkg-config --cflags libcupsfilters` `pkg-config --cflags libpappl-retrofit` $(OPTIM) ifdef VERSION CFLAGS += -DSYSTEM_VERSION_STR="\"$(VERSION)\"" ifndef MAJOR @@ -58,8 +80,8 @@ endif ifdef SNAP CFLAGS += -DSNAP=$(SNAP) endif -LDFLAGS += $(OPTIM) `cups-config --ldflags` -LIBS += `pkg-config --libs pappl` `cups-config --image --libs` `pkg-config --libs libppd` `pkg-config --libs libcupsfilters` `pkg-config --libs libpappl-retrofit` +LDFLAGS += $(OPTIM) $(CUPS_LDFLAGS) +LIBS += `pkg-config --libs $(PAPPL_PKG)` $(CUPS_LIBS) `pkg-config --libs libppd` `pkg-config --libs libcupsfilters` `pkg-config --libs libpappl-retrofit` # Targets... diff --git a/ghostscript-printer-app.c b/ghostscript-printer-app.c index 4aca074..0006be7 100644 --- a/ghostscript-printer-app.c +++ b/ghostscript-printer-app.c @@ -149,7 +149,7 @@ main(int argc, // I - Number of command-line arguments // Keeping vector formats (like PS -> PDF) is usually more desirable // but as many printers have buggy PS interpreters we prefer converting // PDF to Raster and not to PS - spooling_conversions = cupsArrayNew(NULL, NULL); + spooling_conversions = cupsArrayNew(NULL, NULL, NULL, 0, NULL, NULL); // Special conversion rule for fxlinuxprint driver (Fuji Xerox // non-IPP-driverless PDF printers) @@ -168,14 +168,14 @@ main(int argc, // I - Number of command-line arguments // PDF comes last because it is generally not streamable. // PostScript comes second as it is Ghostscript's streamable // input format. - stream_formats = cupsArrayNew(NULL, NULL); + stream_formats = cupsArrayNew(NULL, NULL, NULL, 0, NULL, NULL); cupsArrayAdd(stream_formats, (void *)&PR_STREAM_CUPS_RASTER); cupsArrayAdd(stream_formats, (void *)&PR_STREAM_POSTSCRIPT); cupsArrayAdd(stream_formats, (void *)&PR_STREAM_PDF); // Array of regular expressions for driver priorization // For some printers the "(recommended)" is missing ... - driver_selection_regex_list = cupsArrayNew(NULL, NULL); + driver_selection_regex_list = cupsArrayNew(NULL, NULL, NULL, 0, NULL, NULL); cupsArrayAdd(driver_selection_regex_list, "-recommended-"); cupsArrayAdd(driver_selection_regex_list, "-pdf-"); cupsArrayAdd(driver_selection_regex_list, "-postscript-");