Skip to content

Commit

Permalink
Add chemfiles patches
Browse files Browse the repository at this point in the history
  • Loading branch information
Luthaf committed Sep 27, 2023
1 parent 04f42ce commit 570c1ab
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 0 deletions.
5 changes: 5 additions & 0 deletions 0-chemfiles/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build/
zlib/
zlib.tar.gz

!*.patch
16 changes: 16 additions & 0 deletions 0-chemfiles/0-apple-off64_t.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/zconf.h.cmakein b/zconf.h.cmakein
index a7f24cce6..b8f2d4ad5 100644
--- a/zconf.h.cmakein
+++ b/zconf.h.cmakein
@@ -519,6 +519,11 @@ typedef uLong FAR uLongf;
# define z_off_t long
#endif

+// Apple does not define off64_t, but off_t is 64-bit
+#ifdef __APPLE__
+# define off64_t off_t
+#endif
+
#if !defined(_WIN32) && defined(Z_LARGE64)
# define z_off64_t off64_t
#else
13 changes: 13 additions & 0 deletions 0-chemfiles/1-apple-lseek64.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/gzlib.c b/gzlib.c
index 4105e6aff..50a9a9fd6 100644
--- a/gzlib.c
+++ b/gzlib.c
@@ -8,7 +8,7 @@
#if defined(_WIN32) && !defined(__BORLANDC__)
# define LSEEK _lseeki64
#else
-#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
+#if !defined(__APPLE__) && defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
# define LSEEK lseek64
#else
# define LSEEK lseek
13 changes: 13 additions & 0 deletions 0-chemfiles/2-win-gnu-z_off64_t.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/zconf.h.cmakein b/zconf.h.cmakein
index 3a00233d9..95e4c90a2 100644
--- a/zconf.h.cmakein
+++ b/zconf.h.cmakein
@@ -527,7 +527,7 @@ typedef uLong FAR uLongf;
#if !defined(_WIN32) && defined(Z_LARGE64)
# define z_off64_t off64_t
#else
-# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
+# if defined(_WIN32) && !defined(Z_SOLO)
# define z_off64_t __int64
# else
# define z_off64_t z_off_t
86 changes: 86 additions & 0 deletions 0-chemfiles/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
cmake_minimum_required(VERSION 3.16)
project(chemfiles-zlib C)

if (POLICY CMP0063)
# Use of `<LANG>_VISIBILITY_PRESET` in OBJECT libraries
cmake_policy(SET CMP0063 NEW)
endif()

set(VERSION "1.2.13-chemfiles")

include(CheckTypeSize)
include(CheckFunctionExists)
include(CheckIncludeFile)

check_include_file(sys/types.h HAVE_SYS_TYPES_H)
check_include_file(stdint.h HAVE_STDINT_H)
check_include_file(stddef.h HAVE_STDDEF_H)

# Check for fseeko
check_function_exists(fseeko HAVE_FSEEKO)
# Check for unistd.h
check_include_file(unistd.h Z_HAVE_UNISTD_H)

# parse the full version number from zlib.h and include in ZLIB_FULL_VERSION
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents)
string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*"
"\\1" ZLIB_FULL_VERSION ${_zlib_h_contents})

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein
${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY
)

set(ZLIB_PUBLIC_HDRS
${CMAKE_CURRENT_BINARY_DIR}/zconf.h
zlib.h
)
set(ZLIB_PRIVATE_HDRS
crc32.h
deflate.h
gzguts.h
inffast.h
inffixed.h
inflate.h
inftrees.h
trees.h
zutil.h
)
set(ZLIB_SRCS
adler32.c
compress.c
crc32.c
deflate.c
gzclose.c
gzlib.c
gzread.c
gzwrite.c
inflate.c
infback.c
inftrees.c
inffast.c
trees.c
uncompr.c
zutil.c
)

add_library(chemfiles_zlib OBJECT ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})

set_target_properties(chemfiles_zlib PROPERTIES C_VISIBILITY_PRESET hidden)

target_include_directories(chemfiles_zlib PUBLIC
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)

if(NOT HAVE_FSEEKO)
target_compile_options(chemfiles_zlib PUBLIC -DNO_FSEEKO)
endif()

# Require support for large (64-bit) files
target_compile_options(chemfiles_zlib PUBLIC -D_LARGEFILE64_SOURCE=1 -D_LFS64_LARGEFILE=1)

if(MSVC)
target_compile_options(chemfiles_zlib PUBLIC -D_CRT_SECURE_NO_DEPRECATE)
target_compile_options(chemfiles_zlib PUBLIC -D_CRT_NONSTDC_NO_DEPRECATE)
endif()
27 changes: 27 additions & 0 deletions 0-chemfiles/create-archive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

set -eu

SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)

cd "$SCRIPT_DIR"

# Create archive with only required files
rm -rf zlib.tar.gz zlib
mkdir zlib
cp ../{*.c,*.h,zconf.h.cmakein,Changelog,README,LICENSE} zlib
cp CMakeLists.txt zlib
rm -f zlib/zconf.h

# apply custom patches
cd zlib
patch -p1 < ../0-apple-off64_t.patch
patch -p1 < ../1-apple-lseek64.patch
patch -p1 < ../2-win-gnu-z_off64_t.patch

cd ..

tar cf zlib.tar zlib/
gzip -9 -f zlib.tar

echo "created 0-chemfiles/zlib.tar.gz"

0 comments on commit 570c1ab

Please sign in to comment.