Replace zlib dependency by miniz single header library.

I've chosen the minimal invasive way for this:

  * Import miniz and remove -lz linker flags.
  * Create a short header minizconf.h roviding everything we need
    originally defined by zconf.h and not provided by miniz.
  * Replace zlib.h with miniz.h and minizconf.h.
This commit is contained in:
Yamagi Burmeister 2018-08-10 10:16:13 +02:00
parent 9d4df05c22
commit e7fa5518a9
9 changed files with 8955 additions and 14 deletions

View File

@ -95,9 +95,6 @@ if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "FreeBSD")
endif()
if(${ZIP_SUPPORT})
find_package(ZLIB REQUIRED)
list(APPEND yquake2IncludeDirectories ${ZLIB_INCLUDE_DIRS})
list(APPEND yquake2ZLibLinkerFlags ${ZLIB_LIBRARIES})
add_definitions(-DZIP -DNOUNCRYPT)
if(NOT CMAKE_SYSTEM_NAME MATCHES "Linux" OR NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
@ -332,6 +329,7 @@ set(Client-Source
${COMMON_SRC_DIR}/shared/rand.c
${COMMON_SRC_DIR}/shared/shared.c
${COMMON_SRC_DIR}/unzip/ioapi.c
${COMMON_SRC_DIR}/unzip/miniz.c
${COMMON_SRC_DIR}/unzip/unzip.c
${SERVER_SRC_DIR}/sv_cmd.c
${SERVER_SRC_DIR}/sv_conless.c
@ -367,6 +365,8 @@ set(Client-Header
${COMMON_SRC_DIR}/header/shared.h
${COMMON_SRC_DIR}/header/zone.h
${COMMON_SRC_DIR}/unzip/ioapi.h
${COMMON_SRC_DIR}/unzip/miniz.h
${COMMON_SRC_DIR}/unzip/minizconf.h
${COMMON_SRC_DIR}/unzip/unzip.h
${SERVER_SRC_DIR}/header/server.h
)
@ -390,6 +390,7 @@ set(Server-Source
${COMMON_SRC_DIR}/shared/rand.c
${COMMON_SRC_DIR}/shared/shared.c
${COMMON_SRC_DIR}/unzip/ioapi.c
${COMMON_SRC_DIR}/unzip/miniz.c
${COMMON_SRC_DIR}/unzip/unzip.c
${SERVER_SRC_DIR}/sv_cmd.c
${SERVER_SRC_DIR}/sv_conless.c
@ -411,6 +412,8 @@ set(Server-Header
${COMMON_SRC_DIR}/header/shared.h
${COMMON_SRC_DIR}/header/zone.h
${COMMON_SRC_DIR}/unzip/ioapi.h
${COMMON_SRC_DIR}/unzip/miniz.h
${COMMON_SRC_DIR}/unzip/minizconf.h
${COMMON_SRC_DIR}/unzip/unzip.h
${SERVER_SRC_DIR}/header/server.h
)

View File

@ -347,7 +347,6 @@ endif
ifeq ($(WITH_ZIP),yes)
release/yquake2.exe : CFLAGS += -DZIP -DNOUNCRYPT
release/yquake2.exe : LDFLAGS += -lz
endif
release/yquake2.exe : LDFLAGS += -mwindows
@ -399,7 +398,6 @@ endif # WITH_OPENAL
ifeq ($(WITH_ZIP),yes)
release/quake2 : CFLAGS += $(ZIPCFLAGS) -DZIP -DNOUNCRYPT
release/quake2 : LDFLAGS += -lz
endif
ifeq ($(YQ2_OSTYPE), FreeBSD)
@ -440,11 +438,9 @@ build/server/%.o: %.c
${Q}$(CC) -c $(CFLAGS) $(INCLUDE) -o $@ $<
release/q2ded.exe : CFLAGS += -DDEDICATED_ONLY
release/q2ded.exe : LDFLAGS += -lz
ifeq ($(WITH_ZIP),yes)
release/q2ded.exe : CFLAGS += -DZIP -DNOUNCRYPT
release/q2ded.exe : LDFLAGS += -lz
endif
else # not Windows
server:
@ -461,7 +457,6 @@ release/q2ded : CFLAGS += -DDEDICATED_ONLY -Wno-unused-result
ifeq ($(WITH_ZIP),yes)
release/q2ded : CFLAGS += $(ZIPCFLAGS) -DZIP -DNOUNCRYPT
release/q2ded : LDFLAGS += -lz
endif
ifeq ($(YQ2_OSTYPE), FreeBSD)
@ -734,6 +729,7 @@ CLIENT_OBJS_ := \
src/common/shared/rand.o \
src/common/shared/shared.o \
src/common/unzip/ioapi.o \
src/common/unzip/miniz.o \
src/common/unzip/unzip.o \
src/server/sv_cmd.o \
src/server/sv_conless.o \
@ -885,6 +881,7 @@ SERVER_OBJS_ := \
src/common/shared/rand.o \
src/common/shared/shared.o \
src/common/unzip/ioapi.o \
src/common/unzip/miniz.o \
src/common/unzip/unzip.o \
src/server/sv_cmd.o \
src/server/sv_conless.o \

View File

@ -39,7 +39,7 @@
// If we build with zip support, zlib is available and
// we can use that for better PNG compression.
#include <zlib.h>
#include "../../common/unzip/miniz.h"
static unsigned char*
compress_for_stbiw(unsigned char *data, int data_len, int *out_len, int quality)

View File

@ -43,7 +43,8 @@
#include <stdio.h>
#include <stdlib.h>
#include "zlib.h"
#include "miniz.h"
#include "minizconf.h"
#if defined(USE_FILE32API)
#define fopen64 fopen

7563
src/common/unzip/miniz.c Normal file

File diff suppressed because it is too large Load Diff

1328
src/common/unzip/miniz.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,49 @@
/*
* Copyright (c) 2018 Yamagi Burmeister
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* --------------------------------------------------------------------
*
* Some additional definitions required by minizip and not provided
* by the miniz library.
*
* --------------------------------------------------------------------
*/
#ifndef COMMON_UNZIP_MINIZCONF_H
#define COMMON_UNZIP_MINIZCONF_H
#ifndef OF
#define OF(args) args
#endif
#ifndef ZEXPORT
#define ZEXPORT
#endif
#ifndef z_off_t
#define z_off_t long
#endif
#endif

View File

@ -72,7 +72,8 @@
#define NOUNCRYPT
#endif
#include "zlib.h"
#include "miniz.h"
#include "minizconf.h"
#include "unzip.h"
#ifdef STDC

View File

@ -47,9 +47,8 @@
extern "C" {
#endif
#ifndef _ZLIB_H
#include "zlib.h"
#endif
#include "miniz.h"
#include "minizconf.h"
#ifndef _ZLIBIOAPI_H
#include "ioapi.h"