From a9d2e9df18c499990ecbf776ff534e50beb76284 Mon Sep 17 00:00:00 2001 From: Adesh Deshmukh Date: Tue, 10 Nov 2026 20:39:16 +0530 Subject: [PATCH] Modernize build system and fix cupsArrayNew for CUPS 3.x/PAPPL 2.x - Replaced hardcoded cups-config with 3-tier pkg-config detection (cups3 -> cups -> cups-config) - Added pappl2 detection with fallback to pappl - Derived cupsserverbin from pkg-config prefix variable - Updated cupsArrayNew() calls in ps-printer-app.c to 6-argument libcups3 signature Fixes #40 --- Makefile | 32 +++++++++++++++++++++++++++----- ps-printer-app.c | 4 ++-- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 41b6b63..a2e75cf 100644 --- a/Makefile +++ b/Makefile @@ -21,13 +21,35 @@ statedir = $(localstatedir)/lib/ps-printer-app spooldir = $(localstatedir)/spool/ps-printer-app serverbin = $(prefix)/lib/ps-printer-app resourcedir = $(prefix)/share/ps-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 @@ -55,8 +77,8 @@ endif ifdef PACKAGE CFLAGS += -DSYSTEM_VERSION_ARR_3=$(PACKAGE) 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/ps-printer-app.c b/ps-printer-app.c index 31a15fc..75dd2fa 100644 --- a/ps-printer-app.c +++ b/ps-printer-app.c @@ -111,12 +111,12 @@ main(int argc, // I - Number of command-line arguments int ret; // Array of spooling conversions, most desirables first - spooling_conversions = cupsArrayNew(NULL, NULL); + spooling_conversions = cupsArrayNew(NULL, NULL, NULL, 0, NULL, NULL); cupsArrayAdd(spooling_conversions, (void *)&PR_CONVERT_PS_TO_PS); cupsArrayAdd(spooling_conversions, (void *)&PR_CONVERT_PDF_TO_PS); // Array of stream formats, most desirables first - stream_formats = cupsArrayNew(NULL, NULL); + stream_formats = cupsArrayNew(NULL, NULL, NULL, 0, NULL, NULL); cupsArrayAdd(stream_formats, (void *)&PR_STREAM_POSTSCRIPT); // Configuration record of the PostScript Printer Application