From f061f76704ce983220dc549d1d66ef787cda2daa Mon Sep 17 00:00:00 2001 From: Marcus Meissner Date: Tue, 12 Nov 2002 02:22:24 +0000 Subject: [PATCH] Do not link against -lcups directly, but dynamically load it if present (just like freetype etc.) --- configure | 243 ++++++++++---------------------------- configure.ac | 21 +--- dlls/wineps/Makefile.in | 1 - dlls/wineps/init.c | 58 ++++++--- dlls/winspool/Makefile.in | 1 - dlls/winspool/info.c | 50 ++++++-- include/config.h.in | 7 +- 7 files changed, 150 insertions(+), 231 deletions(-) diff --git a/configure b/configure index aebe44601b2..114f2fdc41e 100755 --- a/configure +++ b/configure @@ -305,7 +305,7 @@ ac_includes_default="\ # include #endif" -ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS LIBEXT OPTIONS WIN16_FILES WIN16_INSTALL build build_cpu build_vendor build_os host host_cpu host_vendor host_os SET_MAKE CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP TOOLSDIR X_CFLAGS X_PRE_LIBS X_LIBS X_EXTRA_LIBS YACC LEX LEXLIB LEX_OUTPUT_ROOT XYACC XLEX LD ac_ct_LD AR ac_ct_AR RANLIB ac_ct_RANLIB STRIP ac_ct_STRIP WINDRES ac_ct_WINDRES INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA LN_S LN C2MAN LDCONFIG LINT LINTFLAGS JPEGLIB EGREP XLIB XFILES OPENGLFILES GLU32FILES NASLIBS CURSESLIBS CUPSLIBS sane_devel SANELIBS SANEINCL ft_devel ft_devel2 FREETYPEINCL ARTSCCONFIG ARTSLIBS ARTSINCL ALSALIBS AUDIOIOLIBS DLLEXT DLLFLAGS DLLIBS LDDLLFLAGS LDSHARED DLLWRAP ac_ct_DLLWRAP CROSSTEST CROSSCC DLLTOOL LDPATH CRTLIBS LDD ALLOCA LIBOBJS LTLIBOBJS' +ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS LIBEXT OPTIONS WIN16_FILES WIN16_INSTALL build build_cpu build_vendor build_os host host_cpu host_vendor host_os SET_MAKE CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP TOOLSDIR X_CFLAGS X_PRE_LIBS X_LIBS X_EXTRA_LIBS YACC LEX LEXLIB LEX_OUTPUT_ROOT XYACC XLEX LD ac_ct_LD AR ac_ct_AR RANLIB ac_ct_RANLIB STRIP ac_ct_STRIP WINDRES ac_ct_WINDRES INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA LN_S LN C2MAN LDCONFIG LINT LINTFLAGS JPEGLIB EGREP XLIB XFILES OPENGLFILES GLU32FILES NASLIBS CURSESLIBS sane_devel SANELIBS SANEINCL ft_devel ft_devel2 FREETYPEINCL ARTSCCONFIG ARTSLIBS ARTSINCL ALSALIBS AUDIOIOLIBS DLLEXT DLLFLAGS DLLIBS LDDLLFLAGS LDSHARED DLLWRAP ac_ct_DLLWRAP CROSSTEST CROSSCC DLLTOOL LDPATH CRTLIBS LDD ALLOCA LIBOBJS LTLIBOBJS' ac_subst_files='MAKE_RULES MAKE_DLL_RULES MAKE_TEST_RULES MAKE_PROG_RULES' # Initialize some variables set by options. @@ -7855,176 +7855,6 @@ done fi -CUPSLIBS="" -wine_cv_warn_cups_h=no -echo "$as_me:$LINENO: checking for cupsGetPPD in -lcups" >&5 -echo $ECHO_N "checking for cupsGetPPD in -lcups... $ECHO_C" >&6 -if test "${ac_cv_lib_cups_cupsGetPPD+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lcups $LIBS" -cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -#include "confdefs.h" - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char cupsGetPPD (); -int -main () -{ -cupsGetPPD (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_lib_cups_cupsGetPPD=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_cv_lib_cups_cupsGetPPD=no -fi -rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -echo "$as_me:$LINENO: result: $ac_cv_lib_cups_cupsGetPPD" >&5 -echo "${ECHO_T}$ac_cv_lib_cups_cupsGetPPD" >&6 -if test $ac_cv_lib_cups_cupsGetPPD = yes; then - if test "${ac_cv_header_cups_cups_h+set}" = set; then - echo "$as_me:$LINENO: checking for cups/cups.h" >&5 -echo $ECHO_N "checking for cups/cups.h... $ECHO_C" >&6 -if test "${ac_cv_header_cups_cups_h+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -fi -echo "$as_me:$LINENO: result: $ac_cv_header_cups_cups_h" >&5 -echo "${ECHO_T}$ac_cv_header_cups_cups_h" >&6 -else - # Is the header compilable? -echo "$as_me:$LINENO: checking cups/cups.h usability" >&5 -echo $ECHO_N "checking cups/cups.h usability... $ECHO_C" >&6 -cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -#include "confdefs.h" -$ac_includes_default -#include -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_header_compiler=yes -else - echo "$as_me: failed program was:" >&5 -cat conftest.$ac_ext >&5 -ac_header_compiler=no -fi -rm -f conftest.$ac_objext conftest.$ac_ext -echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -echo "${ECHO_T}$ac_header_compiler" >&6 - -# Is the header present? -echo "$as_me:$LINENO: checking cups/cups.h presence" >&5 -echo $ECHO_N "checking cups/cups.h presence... $ECHO_C" >&6 -cat >conftest.$ac_ext <<_ACEOF -#line $LINENO "configure" -#include "confdefs.h" -#include -_ACEOF -if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_c_preproc_warn_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - ac_header_preproc=yes -else - echo "$as_me: failed program was:" >&5 - cat conftest.$ac_ext >&5 - ac_header_preproc=no -fi -rm -f conftest.err conftest.$ac_ext -echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -echo "${ECHO_T}$ac_header_preproc" >&6 - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc in - yes:no ) - { echo "$as_me:$LINENO: WARNING: cups/cups.h: accepted by the compiler, rejected by the preprocessor!" >&5 -echo "$as_me: WARNING: cups/cups.h: accepted by the compiler, rejected by the preprocessor!" >&2;} - { echo "$as_me:$LINENO: WARNING: cups/cups.h: proceeding with the preprocessor's result" >&5 -echo "$as_me: WARNING: cups/cups.h: proceeding with the preprocessor's result" >&2;};; - no:yes ) - { echo "$as_me:$LINENO: WARNING: cups/cups.h: present but cannot be compiled" >&5 -echo "$as_me: WARNING: cups/cups.h: present but cannot be compiled" >&2;} - { echo "$as_me:$LINENO: WARNING: cups/cups.h: check for missing prerequisite headers?" >&5 -echo "$as_me: WARNING: cups/cups.h: check for missing prerequisite headers?" >&2;} - { echo "$as_me:$LINENO: WARNING: cups/cups.h: proceeding with the preprocessor's result" >&5 -echo "$as_me: WARNING: cups/cups.h: proceeding with the preprocessor's result" >&2;};; -esac -echo "$as_me:$LINENO: checking for cups/cups.h" >&5 -echo $ECHO_N "checking for cups/cups.h... $ECHO_C" >&6 -if test "${ac_cv_header_cups_cups_h+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_cv_header_cups_cups_h=$ac_header_preproc -fi -echo "$as_me:$LINENO: result: $ac_cv_header_cups_cups_h" >&5 -echo "${ECHO_T}$ac_cv_header_cups_cups_h" >&6 - -fi -if test $ac_cv_header_cups_cups_h = yes; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_CUPS 1 -_ACEOF - - CUPSLIBS="-lcups" -else - wine_cv_warn_cups_h=yes -fi - - - -fi - - - # Extract the first word of "sane-config", so it can be a program name with args. set dummy sane-config; ac_word=$2 echo "$as_me:$LINENO: checking for $ac_word" >&5 @@ -10858,6 +10688,66 @@ cat >>confdefs.h <<_ACEOF #define SONAME_LIBFREETYPE "$ac_cv_lib_soname_freetype" _ACEOF fi + +echo "$as_me:$LINENO: checking for -lcups soname" >&5 +echo $ECHO_N "checking for -lcups soname... $ECHO_C" >&6 +if test "${ac_cv_lib_soname_cups+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_get_soname_save_LIBS=$LIBS +LIBS="-lcups $LIBS" + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +#include "confdefs.h" + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char cupsGetDefault (); +int +main () +{ +cupsGetDefault (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_soname_cups=`$ac_cv_path_LDD conftest$ac_exeext | grep libcups\\.so | sed 's/^[ ]*\([^ ]*\)[ ]*=>.*$/\1/'` + if test "x$ac_cv_lib_soname_cups" = "x" + then + ac_cv_lib_soname_cups="libcups.so" + fi +else + echo "$as_me: failed program was:" >&5 +cat conftest.$ac_ext >&5 +ac_cv_lib_soname_cups="libcups.so" +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext + LIBS=$ac_get_soname_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_soname_cups" >&5 +echo "${ECHO_T}$ac_cv_lib_soname_cups" >&6 +if test "x$ac_cv_lib_soname_cups" != xNONE +then +cat >>confdefs.h <<_ACEOF +#define SONAME_LIBCUPS "$ac_cv_lib_soname_cups" +_ACEOF +fi fi @@ -11649,11 +11539,13 @@ done + for ac_header in \ arpa/inet.h \ arpa/nameser.h \ + cups/cups.h \ direct.h \ elf.h \ float.h \ @@ -14496,7 +14388,6 @@ s,@OPENGLFILES@,$OPENGLFILES,;t t s,@GLU32FILES@,$GLU32FILES,;t t s,@NASLIBS@,$NASLIBS,;t t s,@CURSESLIBS@,$CURSESLIBS,;t t -s,@CUPSLIBS@,$CUPSLIBS,;t t s,@sane_devel@,$sane_devel,;t t s,@SANELIBS@,$SANELIBS,;t t s,@SANEINCL@,$SANEINCL,;t t @@ -15169,14 +15060,6 @@ then echo "*** support before reporting bugs." fi -if test "$wine_cv_warn_cups_h" = "yes" -then - echo - echo "*** Note: You have cups runtime libraries, but no development" - echo "*** libraries. Install the cups-devel package or whichever package" - echo "*** contains cups.h to enable CUPS support in Wine." -fi - if test "$wine_cv_msg_freetype" = "yes" then echo diff --git a/configure.ac b/configure.ac index c4095d4221a..ab2e71f1cb3 100644 --- a/configure.ac +++ b/configure.ac @@ -362,17 +362,6 @@ then fi AC_SUBST(CURSESLIBS) -CUPSLIBS="" -dnl **** Check for CUPS **** -wine_cv_warn_cups_h=no -AC_CHECK_LIB(cups,cupsGetPPD, - [AC_CHECK_HEADER(cups/cups.h, - [AC_DEFINE(HAVE_CUPS, 1, [Define if we have CUPS]) - CUPSLIBS="-lcups"], - wine_cv_warn_cups_h=yes)] -) -AC_SUBST(CUPSLIBS) - dnl **** Check for SANE **** AC_CHECK_PROG(sane_devel,sane-config,sane-config,no) if test "$sane_devel" = "no" @@ -856,6 +845,7 @@ then WINE_GET_SONAME(Xext,XextCreateExtension,[$X_LIBS -lX11 $X_EXTRA_LIBS]) WINE_GET_SONAME(Xrender,XRenderQueryExtension,[$X_LIBS -lXext -lX11 $X_EXTRA_LIBS]) WINE_GET_SONAME(freetype,FT_Init_FreeType,[$X_LIBS]) + WINE_GET_SONAME(cups,cupsGetDefault) fi @@ -969,6 +959,7 @@ dnl **** Check for header files **** AC_CHECK_HEADERS(\ arpa/inet.h \ arpa/nameser.h \ + cups/cups.h \ direct.h \ elf.h \ float.h \ @@ -1597,14 +1588,6 @@ then echo "*** support before reporting bugs." fi -if test "$wine_cv_warn_cups_h" = "yes" -then - echo - echo "*** Note: You have cups runtime libraries, but no development" - echo "*** libraries. Install the cups-devel package or whichever package" - echo "*** contains cups.h to enable CUPS support in Wine." -fi - if test "$wine_cv_msg_freetype" = "yes" then echo diff --git a/dlls/wineps/Makefile.in b/dlls/wineps/Makefile.in index 5ce0d51c84e..cfc0cfae5cf 100644 --- a/dlls/wineps/Makefile.in +++ b/dlls/wineps/Makefile.in @@ -5,7 +5,6 @@ VPATH = @srcdir@ MODULE = wineps.dll IMPORTS = user32 gdi32 winspool.drv advapi32 kernel32 ALTNAMES = wineps16.dll -EXTRALIBS = @CUPSLIBS@ EXTRAINCL = @FREETYPEINCL@ LDDLLFLAGS = @LDDLLFLAGS@ diff --git a/dlls/wineps/init.c b/dlls/wineps/init.c index e8cabb1e64b..fa6e9da300a 100644 --- a/dlls/wineps/init.c +++ b/dlls/wineps/init.c @@ -20,6 +20,7 @@ */ #include "config.h" +#include "wine/port.h" #include #ifdef HAVE_UNISTD_H @@ -33,11 +34,17 @@ #include "winspool.h" #include "winerror.h" -#ifdef HAVE_CUPS -# include +WINE_DEFAULT_DEBUG_CHANNEL(psdrv); + +#ifdef HAVE_CUPS_CUPS_H +#include + +#ifndef CUPS_SONAME +#define CUPS_SONAME "libcups.so" #endif -WINE_DEFAULT_DEBUG_CHANNEL(psdrv); +static void *cupshandle = NULL; +#endif static PSDRV_DEVMODEA DefaultDevmode = { @@ -127,12 +134,25 @@ BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved ) HeapDestroy(PSDRV_Heap); return FALSE; } +#ifdef HAVE_CUPS_CUPS_H + /* dynamically load CUPS if not yet loaded */ + if (!cupshandle) { + cupshandle = wine_dlopen(CUPS_SONAME, RTLD_NOW, NULL, 0); + if (!cupshandle) cupshandle = (void*)-1; + } +#endif break; case DLL_PROCESS_DETACH: DeleteObject( PSDRV_DefaultFont ); HeapDestroy( PSDRV_Heap ); +#ifdef HAVE_CUPS_CUPS_H + if (cupshandle && (cupshandle != (void*)-1)) { + wine_dlclose(cupshandle, NULL, 0); + cupshandle = NULL; + } +#endif break; } @@ -491,24 +511,28 @@ PRINTERINFO *PSDRV_FindPrinterInfo(LPCSTR name) goto cleanup; } -#ifdef HAVE_CUPS - { - ppd = cupsGetPPD(name); +#ifdef HAVE_CUPS_CUPS_H + if (cupshandle != (void*)-1) { + typeof(cupsGetPPD) * pcupsGetPPD = NULL; - if (ppd) { - needed=strlen(ppd)+1; - ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed); - memcpy(ppdFileName, ppd, needed); - ppdType=REG_SZ; - res = ERROR_SUCCESS; - /* we should unlink() that file later */ - } else { - res = ERROR_FILE_NOT_FOUND; - WARN("Did not find ppd for %s\n",name); + pcupsGetPPD = wine_dlsym(cupshandle, "cupsGetPPD", NULL, 0); + if (pcupsGetPPD) { + ppd = pcupsGetPPD(name); + + if (ppd) { + needed=strlen(ppd)+1; + ppdFileName=HeapAlloc(PSDRV_Heap, 0, needed); + memcpy(ppdFileName, ppd, needed); + ppdType=REG_SZ; + res = ERROR_SUCCESS; + /* we should unlink() that file later */ + } else { + res = ERROR_FILE_NOT_FOUND; + WARN("Did not find ppd for %s\n",name); + } } } #endif - if (!ppdFileName) { res = GetPrinterDataA(hPrinter, "PPD File", NULL, NULL, 0, &needed); if ((res==ERROR_SUCCESS) || (res==ERROR_MORE_DATA)) { diff --git a/dlls/winspool/Makefile.in b/dlls/winspool/Makefile.in index 2e5f8e64437..84826c79cf4 100644 --- a/dlls/winspool/Makefile.in +++ b/dlls/winspool/Makefile.in @@ -5,7 +5,6 @@ SRCDIR = @srcdir@ VPATH = @srcdir@ MODULE = winspool.drv IMPORTS = advapi32 kernel32 -EXTRALIBS = @CUPSLIBS@ LDDLLFLAGS = @LDDLLFLAGS@ SYMBOLFILE = $(MODULE).tmp.o diff --git a/dlls/winspool/info.c b/dlls/winspool/info.c index a7d0f7e908c..93c9c0d09d5 100644 --- a/dlls/winspool/info.c +++ b/dlls/winspool/info.c @@ -23,14 +23,19 @@ */ #include "config.h" +#include "wine/port.h" +#include "wine/library.h" #include #include #include #include #include -#ifdef HAVE_CUPS +#ifdef HAVE_CUPS_CUPS_H # include +# ifndef CUPS_SONAME +# define CUPS_SONAME "libcups.so" +# endif #endif #include "winspool.h" #include "winbase.h" @@ -115,21 +120,39 @@ WINSPOOL_SetDefaultPrinter(const char *devname, const char *name,BOOL force) { } } -#ifdef HAVE_CUPS +#ifdef HAVE_CUPS_CUPS_H BOOL CUPS_LoadPrinters(void) { + typeof(cupsGetPrinters) *pcupsGetPrinters = NULL; + typeof(cupsGetDefault) *pcupsGetDefault = NULL; + typeof(cupsGetPPD) *pcupsGetPPD = NULL; char **printers; int i,nrofdests,hadprinter = FALSE; PRINTER_INFO_2A pinfo2a; - const char* def = cupsGetDefault(); + const char* def; + void *cupshandle = NULL; - nrofdests = cupsGetPrinters(&printers); + cupshandle = wine_dlopen(CUPS_SONAME, RTLD_NOW, NULL, 0); + if (!cupshandle) + return FALSE; + +#define DYNCUPS(x) \ + p##x = wine_dlsym(cupshandle, #x, NULL,0); \ + if (!p##x) return FALSE; + + DYNCUPS(cupsGetDefault); + DYNCUPS(cupsGetPPD); + DYNCUPS(cupsGetPrinters); +#undef DYNCUPS + + def = pcupsGetDefault(); if (def && !strcmp(def,"none")) /* CUPS has "none" for no default printer */ def = NULL; + nrofdests = pcupsGetPrinters(&printers); for (i=0;i header file. */ +#undef HAVE_CUPS_CUPS_H /* Define to 1 if you have the header file. */ #undef HAVE_CURSES_H @@ -686,6 +686,9 @@ /* The size of a `long long', as computed by sizeof. */ #undef SIZEOF_LONG_LONG +/* Define to the soname of the libcups library. */ +#undef SONAME_LIBCUPS + /* Define to the soname of the libfreetype library. */ #undef SONAME_LIBFREETYPE