diff --git a/ext/date/config.m4 b/ext/date/config.m4 index c9bfadfa061..bd7fd39b1b9 100644 --- a/ext/date/config.m4 +++ b/ext/date/config.m4 @@ -1,9 +1,22 @@ dnl $Id$ dnl config.m4 for date extension -PHP_DATE_CFLAGS="-I@ext_srcdir@/lib" +sinclude(ext/date/lib/timelib.m4) +sinclude(lib/timelib.m4) + +PHP_DATE_CFLAGS="-I@ext_builddir@/lib" timelib_sources="lib/dow.c lib/parse_date.c lib/parse_tz.c lib/timelib.c lib/tm2unixtime.c lib/unixtime2tm.c" PHP_NEW_EXTENSION(date, php_date.c $timelib_sources, no,, $PHP_DATE_CFLAGS) -PHP_ADD_BUILD_DIR([$ext_builddir/lib]) +PHP_ADD_BUILD_DIR([$ext_builddir/lib], 1) + +cat >> $ext_builddir/lib/tl_config.h < +#endif +EOF diff --git a/ext/date/lib/dow.c b/ext/date/lib/dow.c index 4066d61b4ce..f37f5c1cf60 100644 --- a/ext/date/lib/dow.c +++ b/ext/date/lib/dow.c @@ -18,6 +18,8 @@ /* $Id$ */ +#include + #include "timelib_structs.h" static int m_table_common[13] = { -1, 0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5 }; /* 1 = jan */ diff --git a/ext/date/lib/parse_date.c b/ext/date/lib/parse_date.c index da9da38d3a2..8cde2675a1d 100644 --- a/ext/date/lib/parse_date.c +++ b/ext/date/lib/parse_date.c @@ -20,9 +20,19 @@ /* $Id$ */ -#include +#include + #include + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H #include +#else +#include +#endif + #include "timelib.h" #if defined(_MSC_VER) diff --git a/ext/date/lib/parse_date.re b/ext/date/lib/parse_date.re index 22c3b24d7d1..af4e95c2ea7 100644 --- a/ext/date/lib/parse_date.re +++ b/ext/date/lib/parse_date.re @@ -18,9 +18,19 @@ /* $Id$ */ -#include +#include + #include + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H #include +#else +#include +#endif + #include "timelib.h" #if defined(_MSC_VER) diff --git a/ext/date/lib/parse_tz.c b/ext/date/lib/parse_tz.c index b3680c5d429..fd6bf8ff3cb 100644 --- a/ext/date/lib/parse_tz.c +++ b/ext/date/lib/parse_tz.c @@ -18,13 +18,15 @@ /* $Id$ */ +#include + #include -#ifdef WIN32 -#include -#else -#include -#endif + +#ifdef HAVE_STRING_H #include +#else +#include +#endif #include "timelib.h" #include "timezonedb.h" diff --git a/ext/date/lib/resource/parse_date.re b/ext/date/lib/resource/parse_date.re index 22c3b24d7d1..af4e95c2ea7 100644 --- a/ext/date/lib/resource/parse_date.re +++ b/ext/date/lib/resource/parse_date.re @@ -18,9 +18,19 @@ /* $Id$ */ -#include +#include + #include + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H #include +#else +#include +#endif + #include "timelib.h" #if defined(_MSC_VER) diff --git a/ext/date/lib/timelib.c b/ext/date/lib/timelib.c index f5fb5e0b165..a0bc0314724 100644 --- a/ext/date/lib/timelib.c +++ b/ext/date/lib/timelib.c @@ -18,6 +18,8 @@ /* $Id$ */ +#include + #include "timelib_structs.h" #include "timelib.h" #include diff --git a/ext/date/lib/timelib.h b/ext/date/lib/timelib.h index 347c5213d85..53bd5c72f74 100644 --- a/ext/date/lib/timelib.h +++ b/ext/date/lib/timelib.h @@ -18,6 +18,9 @@ /* $Id$ */ +#ifndef __TIMELIB_H__ +#define __TIMELIB_H__ + #include "timelib_structs.h" #define TIMELIB_NONE 0x00 @@ -31,7 +34,6 @@ #define LONG_MIN (- LONG_MAX - 1) #endif - /* From dow.c */ timelib_sll timelib_day_of_week(timelib_sll y, timelib_sll m, timelib_sll d); timelib_sll timelib_daynr_from_weeknr(timelib_sll y, timelib_sll w, timelib_sll d); @@ -71,3 +73,4 @@ void timelib_time_offset_dtor(timelib_time_offset* t); signed long timelib_date_to_int(timelib_time *d, int *error); void timelib_dump_date(timelib_time *d, int options); +#endif diff --git a/ext/date/lib/timelib.m4 b/ext/date/lib/timelib.m4 new file mode 100644 index 00000000000..b99dc0c7867 --- /dev/null +++ b/ext/date/lib/timelib.m4 @@ -0,0 +1,50 @@ +dnl +dnl $Id$ +dnl +dnl +dnl TL_DEF_HAVE(what [, why]) +dnl +dnl Generates 'AC_DEFINE(HAVE_WHAT, 1, [WHY])' +dnl +AC_DEFUN([TL_DEF_HAVE],[AC_DEFINE([HAVE_]translit($1,a-z_.-,A-Z___),1,[ $2 ])])dnl + +dnl +dnl TL_CHECK_INT_TYPE(type) +dnl +AC_DEFUN([TL_CHECK_INT_TYPE],[ +AC_CACHE_CHECK([for $1], ac_cv_int_type_$1, [ +AC_TRY_COMPILE([ +#if HAVE_SYS_TYPES_H +# include +#endif +#if HAVE_INTTYPES_H +# include +#elif HAVE_STDINT_H +# include +#endif], +[if (($1 *) 0) + return 0; +if (sizeof ($1)) + return 0; +], [ac_cv_int_type_$1=yes], [ac_cv_int_type_$1=no]) +]) +if test "$ac_cv_int_type_$1" = "yes"; then + TL_DEF_HAVE($1, [Define if $1 type is present.]) +fi +])dnl + +dnl Check for types, sizes, etc. needed by timelib +AC_CHECK_SIZEOF(long, 8) +AC_CHECK_SIZEOF(int, 4) +TL_CHECK_INT_TYPE(int32_t) +TL_CHECK_INT_TYPE(uint32_t) + +dnl Check for headers needed by timelib +AC_CHECK_HEADERS([ \ +sys/types.h \ +inttypes.h \ +stdint.h \ +string.h \ +stdlib.h +]) + diff --git a/ext/date/lib/timelib_structs.h b/ext/date/lib/timelib_structs.h index edc11351dea..830595777ce 100644 --- a/ext/date/lib/timelib_structs.h +++ b/ext/date/lib/timelib_structs.h @@ -21,13 +21,42 @@ #ifndef __TIMELIB_STRUCTS_H__ #define __TIMELIB_STRUCTS_H__ -#include -#include -#include -#ifdef WIN32 -#include -#else +#ifdef HAVE_SYS_TYPES_H +#include +#endif + +#if defined(HAVE_INTTYPES_H) #include +#elif defined(HAVE_STDINT_H) +#include +#endif + +#ifndef HAVE_INT32_T +# if SIZEOF_INT == 4 +typedef int int32_t; +# elif SIZEOF_LONG == 4 +typedef long int int32_t; +# endif +#endif + +#ifndef HAVE_UINT32_T +# if SIZEOF_INT == 4 +typedef unsigned int uint32_t; +# elif SIZEOF_LONG == 4 +typedef unsigned long int uint32_t; +# endif +#endif + +#include + +#ifdef HAVE_STDLIB_H +#include +#endif + +#ifdef HAVE_STRING_H +#include +#else +#include #endif #if defined(_MSC_VER) && _MSC_VER < 1300 @@ -125,4 +154,5 @@ typedef struct timelib_time { #define is_leap(y) ((y) % 4 == 0 && ((y) % 100 != 0 || (y) % 400 == 0)) #define DEBUG(s) if (0) { s } + #endif diff --git a/ext/date/lib/tm2unixtime.c b/ext/date/lib/tm2unixtime.c index 12f621112e5..f08558bcfe7 100644 --- a/ext/date/lib/tm2unixtime.c +++ b/ext/date/lib/tm2unixtime.c @@ -18,6 +18,7 @@ /* $Id$ */ +#include #include "timelib.h" /* jan feb mrt apr may jun jul aug sep oct nov dec */ diff --git a/ext/date/lib/unixtime2tm.c b/ext/date/lib/unixtime2tm.c index e8b8078a88e..035af27ff99 100644 --- a/ext/date/lib/unixtime2tm.c +++ b/ext/date/lib/unixtime2tm.c @@ -18,9 +18,19 @@ /* $Id$ */ -#include +#include + #include + +#ifdef HAVE_STDLIB_H +#include +#endif + +#ifdef HAVE_STRING_H #include +#else +#include +#endif #if defined(_MSC_VER) #define TIMELIB_LL_CONST(n) n ## i64 diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 744342bb9d9..bbcd95e7fbe 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -25,7 +25,6 @@ #include "php_ini.h" #include "ext/standard/info.h" #include "php_date.h" -#include "lib/timelib_structs.h" #include "lib/timelib.h" #include