add_definitions(-DHAVE_BUILTIN_CTZL)
endif()
+#
+# check for ptrdiff_t support
+#
+check_c_source_compiles(
+ "#include <stddef.h>
+ int main() { ptrdiff_t *a; return 0; }"
+ HAVE_PTRDIFF_T
+)
+if(NOT HAVE_PTRDIFF_T)
+ set(NEED_PTRDIFF_T 1)
+
+ check_type_size("void *" SIZEOF_DATA_PTR)
+ message(STATUS "sizeof(void *) is ${SIZEOF_DATA_PTR} bytes")
+
+ if(${SIZEOF_DATA_PTR} MATCHES "4")
+ set(PTRDIFF_TYPE "uint32_t")
+ elseif(${SIZEOF_DATA_PTR} MATCHES "8")
+ set(PTRDIFF_TYPE "uint64_t")
+ else()
+ message(FATAL_ERROR "sizeof(void *) is neither 32 nor 64 bit")
+ endif()
+endif()
+
# Macro to check if source compiles when cross-compiling
# or runs when compiling natively
macro(check_c_source_compile_or_run source flag)
foreach(_line IN LISTS _lines)
file(APPEND ${output} "${_line}\n")
- if (_line STREQUAL "#define ZCONF_H")
+ if (_line STREQUAL "#define ZCONF_H" OR _line STREQUAL "#define ZCONFNG_H")
file(APPEND ${output} "#cmakedefine Z_HAVE_UNISTD_H\n")
+ if(NOT HAVE_PTRDIFF_T)
+ file(APPEND ${output} "#cmakedefine NEED_PTRDIFF_T\n")
+ file(APPEND ${output} "#cmakedefine PTRDIFF_TYPE ${PTRDIFF_TYPE}\n")
+ endif()
endif()
endforeach()
endmacro(generate_cmakein)
# Reset zconf.h and zconf.h.cmakein if building inside source tree
@if [ -f zconf.h.in ]; then \
cp -p $(SRCDIR)/zconf.h.in zconf.h ; \
- TEMPFILE=zconfh_$$ ; \
- echo "/#define ZCONF_H/ a\\\n#cmakedefine Z_HAVE_UNISTD_H\\n" >> $$TEMPFILE &&\
- sed -f $$TEMPFILE $(SRCDIR)/zconf.h.in > zconf.h.cmakein &&\
- touch -r $(SRCDIR)/zconf.h.in zconf.h.cmakein &&\
- rm $$TEMPFILE ; fi
+ grep -v '^#cmakedefine' $(SRCDIR)/zconf.h.in > zconf.h.cmakein &&\
+ touch -r $(SRCDIR)/zconf.h.in zconf.h.cmakein ; fi
# Cleanup these files if building outside source tree
@if [ ! -f zlib.3 ]; then rm -f zlib.3.pdf Makefile; fi
# Remove arch and test directory if building outside source tree
echo >> configure.log
+# check for ptrdiff_t and save result in zconf.h
+echo -n "Checking for ptrdiff_t... " | tee -a configure.log
+cat > $test.c <<EOF
+#include <stddef.h>
+int fun(ptrdiff_t *a) { return 0; }
+EOF
+if try $CC -c $CFLAGS $test.c; then
+ echo "Yes." | tee -a configure.log
+else
+ echo "No." | tee -a configure.log
+ sed < zconf${SUFFIX}.h "/^#ifdef NEED_PTRDIFF_T.* may be/s/def NEED_PTRDIFF_T\(.*\) may be/ 1\1 was/" > zconf${SUFFIX}.temp.h
+ mv zconf${SUFFIX}.temp.h zconf${SUFFIX}.h
+
+ echo -n "Checking for sizeof(void *)... " | tee -a configure.log
+ cat > $test.c <<EOF
+#include <stdint.h>
+#define COMPILE_TIME_ASSERT(pred) struct s { int x: (pred) ? 1 : -1; };
+COMPILE_TIME_ASSERT(sizeof(int32_t) == sizeof(void *));
+EOF
+ if try $CC -c $CFLAGS $test.c; then
+ echo "sizeof(int32_t)." | tee -a configure.log
+ sed < zconf${SUFFIX}.h "s/^typedef PTRDIFF_TYPE ptrdiff_t;/typedef int32_t ptrdiff_t;/g" > zconf${SUFFIX}.temp.h
+ mv zconf${SUFFIX}.temp.h zconf${SUFFIX}.h
+ else
+ cat > $test.c <<EOF
+#include <stdint.h>
+#define COMPILE_TIME_ASSERT(pred) struct s { int x: (pred) ? 1 : -1; };
+COMPILE_TIME_ASSERT(sizeof(int64_t) == sizeof(void *));
+EOF
+ if try $CC -c $CFLAGS $test.c; then
+ echo "sizeof(int64_t)." | tee -a configure.log
+ sed < zconf${SUFFIX}.h "s/^typedef PTRDIFF_TYPE ptrdiff_t;/typedef int64_t ptrdiff_t;/g" > zconf${SUFFIX}.temp.h
+ mv zconf${SUFFIX}.temp.h zconf${SUFFIX}.h
+ else
+ echo "unknown." | tee -a configure.log
+ exit 1
+ fi
+ fi
+fi
+
# if --zlib-compat was requested
if test $compat -eq 1; then
gzfileops=1
# define Z_HAVE_UNISTD_H
#endif
+#ifdef NEED_PTRDIFF_T /* may be set to #if 1 by ./configure */
+typedef PTRDIFF_TYPE ptrdiff_t;
+#endif
+
#include <sys/types.h> /* for off_t */
#include <stdarg.h> /* for va_list */
# define Z_HAVE_UNISTD_H
#endif
+#ifdef NEED_PTRDIFF_T /* may be set to #if 1 by ./configure */
+typedef PTRDIFF_TYPE ptrdiff_t;
+#endif
+
#include <sys/types.h> /* for off_t */
#include <stdarg.h> /* for va_list */