Fix libdeflate.pc on Windows

Use Cflags.private to make the pkgconfig file specify the appropriate
flag when linking to libdeflate.dll on Windows.  To do this cleanly,
also invert the meaning of the flag, replacing LIBDEFLATE_DLL with
LIBDEFLATE_STATIC.  So now the DLL is the default, and LIBDEFLATE_STATIC
has to be defined when linking to the static library on Windows.

Fixes https://github.com/ebiggers/libdeflate/issues/229
This commit is contained in:
Eric Biggers committed 2022-09-16 22:10:22 -05:00
1 parent 4a9b7008d1
commit 8a26b31bf8
4 files changed
+21 -13

No files matched your search

+7 -2
View File
@@ -223,12 +223,13 @@ SHARED_LIB_OBJ := $(LIB_SRC:.c=.shlib.o)
# Compile static library object files
$(STATIC_LIB_OBJ): %.o: %.c $(LIB_HEADERS) $(COMMON_HEADERS) .build-config
$(QUIET_CC) $(CC) -o $@ -c $(CPPFLAGS) $(LIB_CFLAGS) $<
$(QUIET_CC) $(CC) -o $@ -c $(CPPFLAGS) $(LIB_CFLAGS) \
-DLIBDEFLATE_STATIC $<
# Compile shared library object files
$(SHARED_LIB_OBJ): %.shlib.o: %.c $(LIB_HEADERS) $(COMMON_HEADERS) .build-config
$(QUIET_CC) $(CC) -o $@ -c $(CPPFLAGS) $(LIB_CFLAGS) \
$(SHARED_LIB_CFLAGS) -DLIBDEFLATE_DLL $<
$(SHARED_LIB_CFLAGS) $<
# Create static library
$(STATIC_LIB):$(STATIC_LIB_OBJ)
@@ -263,6 +264,10 @@ PROG_CFLAGS += $(CFLAGS) \
-D_FILE_OFFSET_BITS=64 \
-DHAVE_CONFIG_H
ifndef USE_SHARED_LIB
PROG_CFLAGS += -DLIBDEFLATE_STATIC
endif
ALL_PROG_COMMON_HEADERS := programs/config.h \
programs/prog_util.h \
programs/test_util.h
+2 -2
View File
@@ -40,10 +40,10 @@ PROG_CFLAGS = $(CFLAGS) -Iprograms
all: $(STATIC_LIB) $(SHARED_LIB) $(IMPORT_LIB) gzip.exe gunzip.exe
.c.obj:
$(CC) -c /Fo$@ $(CFLAGS) $**
$(CC) -c /Fo$@ $(CFLAGS) /DLIBDEFLATE_STATIC $**
.c.dllobj:
$(CC) -c /Fo$@ $(CFLAGS) /DLIBDEFLATE_DLL $**
$(CC) -c /Fo$@ $(CFLAGS) $**
$(STATIC_LIB): $(STATIC_LIB_OBJ)
$(AR) $(ARFLAGS) -out:$@ $(STATIC_LIB_OBJ)
+11 -9
View File
@@ -17,18 +17,20 @@ extern "C" {
#include <stdint.h>
/*
* On Windows, if you want to link to the DLL version of libdeflate, then
* #define LIBDEFLATE_DLL. Note that the calling convention is "cdecl".
* On Windows, you must define LIBDEFLATE_STATIC if you are linking to the
* static library version of libdeflate instead of the DLL. On other platforms,
* LIBDEFLATE_STATIC has no effect.
*/
#ifdef LIBDEFLATE_DLL
# ifdef BUILDING_LIBDEFLATE
# define LIBDEFLATEEXPORT LIBEXPORT
# elif defined(_WIN32) || defined(__CYGWIN__)
#ifdef _WIN32
# if defined(LIBDEFLATE_STATIC)
# define LIBDEFLATEEXPORT
# elif defined(BUILDING_LIBDEFLATE)
# define LIBDEFLATEEXPORT __declspec(dllexport)
# else
# define LIBDEFLATEEXPORT __declspec(dllimport)
# endif
#endif
#ifndef LIBDEFLATEEXPORT
# define LIBDEFLATEEXPORT
#else
# define LIBDEFLATEEXPORT __attribute__((visibility("default")))
#endif
#if defined(BUILDING_LIBDEFLATE) && defined(__GNUC__) && defined(__i386__)
+1
View File
@@ -3,3 +3,4 @@ Description: Fast implementation of DEFLATE, zlib, and gzip
Version: @VERSION@
Libs: -L@LIBDIR@ -ldeflate
Cflags: -I@INCDIR@
Cflags.private: -DLIBDEFLATE_STATIC