From 0941c32d38efef90cb3dafe463740b78329d1aa1 Mon Sep 17 00:00:00 2001
From: "Kevin P. Fleming" <kpfleming@digium.com>
Date: Tue, 8 Nov 2005 04:13:19 +0000
Subject: [PATCH] issue #5569 minus lock.h changes

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7024 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 ChangeLog                 |  2 ++
 asterisk.c                |  1 +
 codecs/Makefile           |  3 ++-
 codecs/ilbc/Makefile      |  5 ++++-
 codecs/lpc10/Makefile     |  5 ++++-
 include/asterisk/compat.h |  4 ++++
 include/asterisk/utils.h  |  4 ++++
 pbx.c                     |  1 +
 stdtime/localtime.c       | 13 +++++++------
 utils.c                   |  2 +-
 10 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b00225a0c0..7cc6d3073a 100755
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2005-11-07  Kevin P. Fleming  <kpfleming@digium.com>
 
+	* many files: more Cygwin compatibility, and proper getloadavg() prototype/macro (issue #5569)
+
 	* include/asterisk/lock.h (__ast_pthread_mutex_lock): correct build with DETECT_DEADLOCKS defined (issue #5570)
 
 2005-11-07  Russell Bryant  <russell@digium.com>
diff --git a/asterisk.c b/asterisk.c
index 04602d9643..f2f7ace539 100755
--- a/asterisk.c
+++ b/asterisk.c
@@ -107,6 +107,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/version.h"
 #include "asterisk/linkedlists.h"
 #include "asterisk/devicestate.h"
+#include "asterisk/compat.h"
 
 #include "asterisk/doxyref.h"		/* Doxygen documentation */
 
diff --git a/codecs/Makefile b/codecs/Makefile
index edf0292198..d1feb8a546 100755
--- a/codecs/Makefile
+++ b/codecs/Makefile
@@ -14,6 +14,8 @@
 ifeq (${OSARCH},CYGWIN)
 CYGSOLINK=-Wl,--out-implib=lib$@.a -Wl,--export-all-symbols
 CYGSOLIB=-L.. -L. -lasterisk.dll
+else
+CFLAGS+=-fPIC
 endif
 
 ifneq ($(wildcard g723.1/coder.c),)
@@ -57,7 +59,6 @@ ifneq ($(wildcard ilbc/iLBC_decode.h),)
   LIBILBC=ilbc/libilbc.a
 endif
 
-CFLAGS+=-fPIC
 
 LIBGSM=gsm/lib/libgsm.a
 LIBGSMT=gsm/lib/libgsm.a
diff --git a/codecs/ilbc/Makefile b/codecs/ilbc/Makefile
index 8bccc4a9ae..1540c140fc 100755
--- a/codecs/ilbc/Makefile
+++ b/codecs/ilbc/Makefile
@@ -1,5 +1,8 @@
 ARCH=$(PROC)
-CFLAGS+=-Wall -fPIC -O3 -funroll-loops
+CFLAGS+=-Wall -O3 -funroll-loops
+ifneq (${OSARCH},CYGWIN)
+CFLAGS += -fPIC
+endif
 LIB=libilbc.a
 
 OBJS= anaFilter.o iCBSearch.o packing.o \
diff --git a/codecs/lpc10/Makefile b/codecs/lpc10/Makefile
index 01f7a7b813..b56a59ba4e 100755
--- a/codecs/lpc10/Makefile
+++ b/codecs/lpc10/Makefile
@@ -22,7 +22,10 @@ LIB_TARGET_DIR = .
 # 
 
 WARNINGS = -Wall -Wno-comment -Wno-error
-CFLAGS += $(OPTIMIZE) -I$(LIB_TARGET_DIR) $(WARNINGS) -fPIC
+CFLAGS += $(OPTIMIZE) -I$(LIB_TARGET_DIR) $(WARNINGS)
+ifneq (${OSARCH},CYGWIN)
+CFLAGS += -fPIC
+endif
 #CFLAGS+= $(shell if uname -m | grep -q 86; then echo "-mpentium" ; fi)
 
 #fix for PPC processors and ALPHA, And UltraSparc too
diff --git a/include/asterisk/compat.h b/include/asterisk/compat.h
index fb6a5d59fa..139f4f81b9 100755
--- a/include/asterisk/compat.h
+++ b/include/asterisk/compat.h
@@ -74,6 +74,10 @@ int unsetenv(const char *name);
 #define HAVE_VASPRINTF
 #define HAVE_STRTOQ
 
+#ifdef _BSD_SOURCE
+#define HAVE_GETLOADAVG
+#endif
+
 #ifdef __linux__
 #define HAVE_STRCASESTR
 #define HAVE_STRNDUP
diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h
index 8eed095f0b..b6b85df4e8 100755
--- a/include/asterisk/utils.h
+++ b/include/asterisk/utils.h
@@ -231,4 +231,8 @@ int ast_pthread_create_stack(pthread_t *thread, pthread_attr_t *attr, void *(*st
 */
 char *ast_process_quotes_and_slashes(char *start, char find, char replace_with);
 
+#ifndef HAVE_GETLOADAVG
+int getloadavg(double *list, int nelem);
+#endif
+
 #endif /* _ASTERISK_UTILS_H */
diff --git a/pbx.c b/pbx.c
index 29a1d893a6..40285bb31b 100755
--- a/pbx.c
+++ b/pbx.c
@@ -56,6 +56,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/musiconhold.h"
 #include "asterisk/app.h"
 #include "asterisk/devicestate.h"
+#include "asterisk/compat.h"
 
 /*!
  * \note I M P O R T A N T :
diff --git a/stdtime/localtime.c b/stdtime/localtime.c
index 67dc71d2c6..db125d9e69 100755
--- a/stdtime/localtime.c
+++ b/stdtime/localtime.c
@@ -77,6 +77,12 @@ static const char elsieid[] = "@(#)localtime.c	7.57";
 #define OPEN_MODE	O_RDONLY
 #endif /* !defined O_BINARY */
 
+#ifdef SOLARIS
+#undef TM_ZONE
+#undef TM_GMTOFF 
+#endif
+
+#ifdef TM_ZONE
 #ifndef WILDABBR
 /*! \note
  * Someone might make incorrect use of a time zone abbreviation:
@@ -101,6 +107,7 @@ static const char elsieid[] = "@(#)localtime.c	7.57";
 #endif /* !defined WILDABBR */
 
 static char		wildabbr[] = "WILDABBR";
+#endif /* TM_ZONE */
 
 /*! \brief FreeBSD defines 'zone' in 'struct tm' as non-const, so don't declare this
    string as const. */
@@ -130,12 +137,6 @@ struct lsinfo {
 #define MY_TZNAME_MAX	255
 #endif /* !defined TZNAME_MAX */
 
-#ifdef SOLARIS
-#undef TM_ZONE
-#undef TM_GMTOFF 
-#endif
-
-
 struct state {
 	char	name[TZ_STRLEN_MAX + 1];
 	int		leapcnt;
diff --git a/utils.c b/utils.c
index 9dffe253a5..89fc262117 100755
--- a/utils.c
+++ b/utils.c
@@ -842,7 +842,7 @@ uint64_t strtoq(const char *nptr, char **endptr, int base)
 }
 #endif /* !HAVE_STRTOQ */
 
-#if (!defined(_BSD_SOURCE))
+#ifndef HAVE_GETLOADAVG
 #ifdef linux
 /* Alternative method of getting load avg on Linux only */
 int getloadavg(double *list, int nelem)
-- 
GitLab