? cygwin
? patch.diff
? patch.new.diff
Index: Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/Makefile,v
retrieving revision 1.217
diff -u -r1.217 Makefile
--- Makefile	25 Oct 2005 12:47:54 -0000	1.217
+++ Makefile	27 Oct 2005 18:06:26 -0000
@@ -216,6 +216,7 @@
 INCLUDE+=-Iinclude -I../include
 ASTCFLAGS+=-pipe  -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(DEBUG) $(INCLUDE) -D_REENTRANT -D_GNU_SOURCE #-DMAKE_VALGRIND_HAPPY
 ASTCFLAGS+=$(OPTIMIZE)
+ASTOBJ=-o asterisk
 
 ifeq ($(findstring BSD,${OSARCH}),BSD)
   PROC=$(shell uname -m)
@@ -263,6 +264,15 @@
   INCLUDE+=-Iinclude/solaris-compat -I$(CROSS_COMPILE_TARGET)/usr/local/ssl/include
 endif
 
+ifeq ($(findstring CYGWIN,${OSARCH}),CYGWIN)
+CYGLOADER=cygwin_a
+OSARCH=CYGWIN
+ASTOBJ=-shared -o asterisk.dll -Wl,--out-implib=libasterisk.dll.a -Wl,--export-all-symbols
+ASTLINK=
+LIBS+=-lpthread -lncurses -lm -lresolv
+ASTSBINDIR=${MODULES_DIR}
+endif
+
 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/linux/zaptel.h)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/zaptel.h)$(wildcard $(CROSS_COMPILE_TARGET)/usr/pkg/include/zaptel.h),)
   ASTCFLAGS+=-DZAPTEL_OPTIMIZATIONS
 endif
@@ -471,8 +481,11 @@
 		exit 1; \
 	fi
 
-asterisk: editline/libedit.a db1-ast/libdb1.a stdtime/libtime.a $(OBJS)
-	$(CC) $(DEBUG) -o asterisk $(ASTLINK) $(OBJS) $(LIBEDIT) db1-ast/libdb1.a stdtime/libtime.a $(LIBS)
+cygwin_a:
+	$(MAKE) -C cygwin all
+
+asterisk: ${CYGLOADER} editline/libedit.a db1-ast/libdb1.a stdtime/libtime.a $(OBJS)
+	$(CC) $(DEBUG) ${ASTOBJ} $(ASTLINK) $(OBJS) $(LIBEDIT) db1-ast/libdb1.a stdtime/libtime.a $(LIBS)
 
 muted: muted.o
 	$(CC) $(AUDIO_LIBS) -o muted muted.o
@@ -595,7 +608,9 @@
 	mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/system
 	mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/tmp
 	mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/meetme
-	$(INSTALL) -m 755 asterisk $(DESTDIR)$(ASTSBINDIR)/
+	if [ -f asterisk ]; then $(INSTALL) -m 755 asterisk $(DESTDIR)$(ASTSBINDIR)/; fi
+	if [ -f cygwin/asterisk.exe ]; then $(INSTALL) -m 755 cygwin/asterisk.exe $(DESTDIR)$(ASTSBINDIR)/; fi
+	if [ -f asterisk.dll ]; then $(INSTALL) -m 755 asterisk.dll $(DESTDIR)$(ASTSBINDIR)/; fi
 	ln -sf asterisk $(DESTDIR)$(ASTSBINDIR)/rasterisk
 	$(INSTALL) -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
 	$(INSTALL) -m 755 contrib/scripts/autosupport $(DESTDIR)$(ASTSBINDIR)/	
Index: acl.c
===================================================================
RCS file: /usr/cvsroot/asterisk/acl.c,v
retrieving revision 1.58
diff -u -r1.58 acl.c
--- acl.c	24 Oct 2005 20:12:04 -0000	1.58
+++ acl.c	27 Oct 2005 18:06:26 -0000
@@ -68,6 +68,7 @@
 #include "asterisk/utils.h"
 #include "asterisk/lock.h"
 #include "asterisk/srv.h"
+#include "asterisk/compat.h"
 
 #if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)
 AST_MUTEX_DEFINE_STATIC(routeseq_lock);
Index: ast_expr2.c
===================================================================
RCS file: /usr/cvsroot/asterisk/ast_expr2.c,v
retrieving revision 1.5
diff -u -r1.5 ast_expr2.c
--- ast_expr2.c	25 Sep 2005 17:03:18 -0000	1.5
+++ ast_expr2.c	27 Oct 2005 18:06:27 -0000
@@ -132,7 +132,7 @@
 #include <string.h>
 #include <locale.h>
 #include <ctype.h>
-#ifndef SOLARIS
+#if !defined(SOLARIS) && !defined(__CYGWIN__)
 #include <err.h>
 #else
 #define quad_t int64_t
Index: ast_expr2.fl
===================================================================
RCS file: /usr/cvsroot/asterisk/ast_expr2.fl,v
retrieving revision 1.7
diff -u -r1.7 ast_expr2.fl
--- ast_expr2.fl	29 Aug 2005 22:03:37 -0000	1.7
+++ ast_expr2.fl	27 Oct 2005 18:06:27 -0000
@@ -5,7 +5,7 @@
 #include <string.h>
 #include <locale.h>
 #include <ctype.h>
-#ifndef SOLARIS
+#if !defined(SOLARIS) && !defined(__CYGWIN__)
 #include <err.h>
 #else
 #define quad_t int64_t
Index: ast_expr2.y
===================================================================
RCS file: /usr/cvsroot/asterisk/ast_expr2.y,v
retrieving revision 1.8
diff -u -r1.8 ast_expr2.y
--- ast_expr2.y	25 Sep 2005 17:03:18 -0000	1.8
+++ ast_expr2.y	27 Oct 2005 18:06:28 -0000
@@ -18,7 +18,7 @@
 #include <string.h>
 #include <locale.h>
 #include <ctype.h>
-#ifndef SOLARIS
+#if !defined(SOLARIS) && !defined(__CYGWIN__)
 #include <err.h>
 #else
 #define quad_t int64_t
Index: ast_expr2f.c
===================================================================
RCS file: /usr/cvsroot/asterisk/ast_expr2f.c,v
retrieving revision 1.5
diff -u -r1.5 ast_expr2f.c
--- ast_expr2f.c	26 Oct 2005 23:11:36 -0000	1.5
+++ ast_expr2f.c	27 Oct 2005 18:06:30 -0000
@@ -956,7 +956,7 @@
 #include <string.h>
 #include <locale.h>
 #include <ctype.h>
-#ifndef SOLARIS
+#if !defined(SOLARIS) && !defined(__CYGWIN__)
 #include <err.h>
 #else
 #define quad_t int64_t
Index: asterisk.c
===================================================================
RCS file: /usr/cvsroot/asterisk/asterisk.c,v
retrieving revision 1.186
diff -u -r1.186 asterisk.c
--- asterisk.c	26 Oct 2005 18:54:24 -0000	1.186
+++ asterisk.c	27 Oct 2005 18:06:31 -0000
@@ -2039,6 +2039,8 @@
 		ast_verbose("[ Reading Master Configuration ]");
 	ast_readconfig();
 
+#ifndef __CYGWIN__
+
 	if (!is_child_of_nonroot && ast_set_priority(option_highpriority)) {
 		exit(1);
 	}
@@ -2073,6 +2075,8 @@
 		if (option_verbose)
 			ast_verbose("Running as user '%s'\n", runuser);
 	}
+
+#endif /* __CYGWIN__ */
 
 	term_init();
 	printf(term_end());
Index: config.c
===================================================================
RCS file: /usr/cvsroot/asterisk/config.c,v
retrieving revision 1.80
diff -u -r1.80 config.c
--- config.c	26 Oct 2005 18:54:24 -0000	1.80
+++ config.c	27 Oct 2005 18:06:32 -0000
@@ -32,7 +32,7 @@
 #include <time.h>
 #define AST_INCLUDE_GLOB 1
 #ifdef AST_INCLUDE_GLOB
-#ifdef __Darwin__
+#if defined(__Darwin__) || defined(__CYGWIN__)
 #define GLOB_ABORTED GLOB_ABEND
 #endif
 # include <glob.h>
@@ -681,7 +681,11 @@
 	}
 	time(&t);
 	ast_copy_string(date, ctime(&t), sizeof(date));
+#ifdef __CYGWIN__	
+	if ((f = fopen(fn, "w+"))) {
+#else
 	if ((f = fopen(fn, "w"))) {
+#endif	    
 		if ((option_verbose > 1) && !option_debug)
 			ast_verbose(  VERBOSE_PREFIX_2 "Saving '%s': ", fn);
 		fprintf(f, ";!\n");
Index: db.c
===================================================================
RCS file: /usr/cvsroot/asterisk/db.c,v
retrieving revision 1.25
diff -u -r1.25 db.c
--- db.c	26 Oct 2005 18:54:24 -0000	1.25
+++ db.c	27 Oct 2005 18:06:32 -0000
@@ -53,6 +53,10 @@
 #include "asterisk/manager.h"
 #include "db1-ast/include/db.h"
 
+#ifdef __CYGWIN__
+#define dbopen __dbopen
+#endif
+
 static DB *astdb;
 AST_MUTEX_DEFINE_STATIC(dblock);
 
Index: utils.c
===================================================================
RCS file: /usr/cvsroot/asterisk/utils.c,v
retrieving revision 1.79
diff -u -r1.79 utils.c
--- utils.c	26 Oct 2005 18:54:24 -0000	1.79
+++ utils.c	27 Oct 2005 18:06:32 -0000
@@ -44,6 +44,7 @@
 #include "asterisk/logger.h"
 #include "asterisk/md5.h"
 #include "asterisk/options.h"
+#include "asterisk/compat.h"
 
 #define AST_API_MODULE		/* ensure that inlinable API functions will be built in this module if required */
 #include "asterisk/strings.h"
@@ -57,7 +58,7 @@
 static char base64[64];
 static char b2a[256];
 
-#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined( __NetBSD__ ) || defined(__APPLE__)
+#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined( __NetBSD__ ) || defined(__APPLE__) || defined(__CYGWIN__)
 
 /* duh? ERANGE value copied from web... */
 #define ERANGE 34
@@ -741,10 +742,14 @@
 #endif
 
 #ifndef HAVE_STRTOQ
+#ifndef LONG_MIN
 #define LONG_MIN        (-9223372036854775807L-1L)
 	                                 /* min value of a "long int" */
+#endif
+#ifndef LONG_MAX
 #define LONG_MAX        9223372036854775807L
 	                                 /* max value of a "long int" */
+#endif
 
 /*
  * Convert a string to a quad integer.
Index: apps/Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/Makefile,v
retrieving revision 1.115
diff -u -r1.115 Makefile
--- apps/Makefile	18 Oct 2005 17:44:52 -0000	1.115
+++ apps/Makefile	27 Oct 2005 18:06:32 -0000
@@ -22,7 +22,7 @@
      app_enumlookup.so app_transfer.so app_setcidnum.so app_cdr.so \
      app_hasnewvoicemail.so app_sayunixtime.so app_cut.so app_read.so \
      app_setcdruserfield.so app_random.so app_ices.so app_eval.so \
-     app_nbscat.so app_sendtext.so app_exec.so app_sms.so \
+     app_nbscat.so app_sendtext.so app_exec.so \
      app_groupcount.so app_txtcidname.so app_controlplayback.so \
      app_talkdetect.so app_alarmreceiver.so app_userevent.so app_verbose.so \
      app_test.so app_forkcdr.so app_math.so app_realtime.so \
@@ -63,7 +63,13 @@
   endif 
 endif
 
+ifeq (${OSARCH},CYGWIN)
+CYGSOLINK=-Wl,--out-implib=lib$@.a -Wl,--export-all-symbols
+CYGSOLIB=-L.. -L. -L../res -lasterisk.dll -lres_features.so -lres_adsi.so -lres_monitor.so
+else
 CFLAGS+=-fPIC
+APPS+=app_sms.so
+endif
 
 #
 # If you have UnixODBC you can use ODBC voicemail
@@ -81,10 +87,10 @@
 	rm -f *.so *.o look .depend
 
 %.so : %.o
-	$(CC) $(SOLINK) -o $@ $<
-
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB}
+	
 app_rpt.so : app_rpt.o
-	$(CC) $(SOLINK) -o $@ $< -ltonezone
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -ltonezone
 
 install: all
 	for x in $(APPS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
@@ -92,16 +98,16 @@
 	rm -f $(DESTDIR)$(MODULES_DIR)/app_qcall.so
 
 app_curl.so: app_curl.o
-	$(CC) $(SOLINK) -o $@ $< $(CURLLIBS)
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} $(CURLLIBS)
 
 app_sql_postgres.o: app_sql_postgres.c
 	$(CC) -pipe -I/usr/local/pgsql/include $(CFLAGS) -c -o app_sql_postgres.o app_sql_postgres.c
 
 app_sql_postgres.so: app_sql_postgres.o
-	$(CC) $(SOLINK) -o $@ $< -L/usr/local/pgsql/lib -lpq
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -L/usr/local/pgsql/lib -lpq
 
 app_sql_odbc.so: app_sql_odbc.o
-	$(CC) $(SOLINK) -o $@ $< -lodbc
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lodbc
 
 look:	look.c
 	$(CC) -pipe -O6 -g look.c -o look -lncurses
Index: cdr/Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/cdr/Makefile,v
retrieving revision 1.31
diff -u -r1.31 Makefile
--- cdr/Makefile	30 Aug 2005 15:59:25 -0000	1.31
+++ cdr/Makefile	27 Oct 2005 18:06:33 -0000
@@ -13,7 +13,12 @@
 
 MODS=cdr_csv.so cdr_manager.so cdr_custom.so
 
+ifeq (${OSARCH},CYGWIN)
+CYGSOLINK=-Wl,--out-implib=lib$@.a -Wl,--export-all-symbols
+CYGSOLIB=-L.. -L. -lasterisk.dll
+else
 CFLAGS+=-fPIC
+endif
 
 ifeq ($(findstring BSD,${OSARCH}),BSD)
   CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include -L$(CROSS_COMPILE_TARGET)/usr/local/lib
@@ -101,23 +106,23 @@
 	rm -f *.so *.o .depend
 
 %.so : %.o
-	$(CC) $(SOLINK) -o $@ $<
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB}
 
 ifneq ($(wildcard .depend),)
   include .depend
 endif
 
 cdr_odbc.so: cdr_odbc.o
-	$(CC) $(SOLINK) -o $@ $< -lodbc $(MLFLAGS)
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lodbc $(MLFLAGS)
 
 cdr_tds.so: cdr_tds.o
-	$(CC) $(SOLINK) -o $@ $< -ltds $(MLFLAGS)
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -ltds $(MLFLAGS)
 
 cdr_pgsql.so: cdr_pgsql.o
-	$(CC) $(SOLINK) -o $@ $< -lpq -lz $(MLFLAGS)
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lpq -lz $(MLFLAGS)
 
 cdr_sqlite.so: cdr_sqlite.o
-	$(CC) $(SOLINK) -o $@ $< -lsqlite $(MLFLAGS)
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lsqlite $(MLFLAGS)
 
 depend: .depend
 
Index: channels/Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/Makefile,v
retrieving revision 1.74
diff -u -r1.74 Makefile
--- channels/Makefile	5 Oct 2005 00:17:57 -0000	1.74
+++ channels/Makefile	27 Oct 2005 18:06:33 -0000
@@ -14,11 +14,11 @@
 # the GNU General Public License
 #
 
-CHANNEL_LIBS=chan_modem.so chan_sip.so \
-	     chan_modem_aopen.so \
-             chan_modem_bestdata.so \
-             chan_agent.so chan_mgcp.so chan_iax2.so \
-	     chan_local.so chan_skinny.so chan_features.so
+CHANNEL_LIBS=chan_sip.so chan_agent.so chan_mgcp.so chan_iax2.so chan_local.so chan_skinny.so chan_features.so
+
+ifneq (${OSARCH},CYGWIN)
+CHANNEL_LIBS+=chan_modem.so chan_modem_aopen.so chan_modem_bestdata.so
+endif
 
 ifeq ($(findstring BSD,${OSARCH}),BSD)
  CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include -L$(CROSS_COMPILE_TARGET)/usr/local/lib
@@ -35,6 +35,13 @@
   CHANH323LIB=-ldl
 endif
 
+ifeq (${OSARCH},CYGWIN)
+CYGSOLINK=-Wl,--out-implib=lib$@.a -Wl,--export-all-symbols
+CYGSOLIB=-L.. -L. -L../res -lasterisk.dll -lres_features.so
+CYG_CHAN_AGENT=-lres_monitor.so
+CYG_CHAN_IAX2=-lres_crypto.so
+endif
+
 ifeq ($(PROC),sparc64)
   PROC=ultrasparc
   CFLAGS += -mtune=$(PROC) -O3 -pipe -fomit-frame-pointer -mcpu=v8
@@ -53,7 +60,9 @@
 
 ifneq (${OSARCH},Darwin)
   ifneq (${OSARCH},SunOS)
-    CHANNEL_LIBS+=chan_oss.so chan_modem_i4l.so 
+    ifneq (${OSARCH},CYGWIN)
+      CHANNEL_LIBS+=chan_oss.so chan_modem_i4l.so 
+    endif
   endif
 endif
 
@@ -109,7 +118,10 @@
 endif
 
 CFLAGS+=-DCRYPTO
+
+ifneq ($(OSARCH),CYGWIN)
 CFLAGS+=-fPIC
+endif
 
 CFLAGS+=#-DVOFRDUMPER
 
@@ -136,7 +148,7 @@
 	rm -f busy.h ringtone.h gentone gentone-ulaw
 
 %.so : %.o
-	$(CC) $(SOLINK) -o $@ $<
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} ${LIBS}
 
 ifneq ($(wildcard .depend),)
   include .depend
@@ -172,7 +184,7 @@
 endif
 
 chan_iax2.so: chan_iax2.o iax2-parser.o iax2-provision.o
-	$(CC) $(SOLINK) -o $@ chan_iax2.o iax2-parser.o iax2-provision.o
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} chan_iax2.o iax2-parser.o iax2-provision.o ${CYGSOLIB} ${CYG_CHAN_IAX2}
 
 chan_zap.o: chan_zap.c
 	$(CC) -c $(CFLAGS) -o chan_zap.o chan_zap.c
@@ -181,7 +193,10 @@
 	$(CC) $(SOLINK) -o $@ $<  $(ZAPPRI) $(ZAPR2) -ltonezone
 
 chan_sip.so: chan_sip.o
-	$(CC) $(SOLINK) -o $@ chan_sip.o
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} chan_sip.o ${CYGSOLIB}
+
+chan_agent.so: chan_agent.o
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} chan_agent.o ${CYGSOLIB} ${CYG_CHAN_AGENT}
 
 chan_alsa.o: $(ALSA_SRC)
 
Index: codecs/Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/codecs/Makefile,v
retrieving revision 1.32
diff -u -r1.32 Makefile
--- codecs/Makefile	5 Sep 2005 15:48:47 -0000	1.32
+++ codecs/Makefile	27 Oct 2005 18:06:33 -0000
@@ -11,6 +11,11 @@
 # the GNU General Public License
 #
 
+ifeq (${OSARCH},CYGWIN)
+CYGSOLINK=-Wl,--out-implib=lib$@.a -Wl,--export-all-symbols
+CYGSOLIB=-L.. -L. -lasterisk.dll
+endif
+
 ifneq ($(wildcard g723.1/coder.c),)
   MODG723=codec_g723_1.so
   LIBG723=g723.1/libg723.a
@@ -92,28 +97,28 @@
 	$(MAKE) -C ilbc all
 
 $(MODILBC): codec_ilbc.o $(LIBILBC)
-	$(CC) $(SOLINK) -o $@ $< $(LIBILBC)
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} $(LIBILBC)
 
 codec_g723_1.so : codec_g723_1.o $(LIBG723)
-	$(CC) $(SOLINK) -o $@ $< $(LIBG723)
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} $(LIBG723)
 
 codec_g723_1b.o : codec_g723_1.c
 	$(CC) -c -o $@ $(CFLAGS) -DANNEX_B -Dsingle $<
 
 codec_g723_1b.so : codec_g723_1b.o $(LIBG723B)
-	$(CC) $(SOLINK) -o $@ $< $(LIBG723B) -lm
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} $(LIBG723B) -lm
 
 codec_gsm.so: codec_gsm.o $(LIBGSMT) 
-	$(CC) $(SOLINK) -o $@ $< $(LIBGSM)
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} $(LIBGSM)
 
 $(MODSPEEX): codec_speex.o
-	$(CC) $(SOLINK) -o $@ $< $(LIBSPEEX)
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} $(LIBSPEEX)
 
 codec_lpc10.so: codec_lpc10.o $(LIBLPC10)
-	$(CC) $(SOLINK) -o $@ $< $(LIBLPC10) -lm
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} $(LIBLPC10) -lm
 
 %.so : %.o
-	$(CC) $(SOLINK) -o $@ $<
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB}
 
 ifneq ($(wildcard .depend),)
   include .depend
Index: codecs/gsm/Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/codecs/gsm/Makefile,v
retrieving revision 1.25
diff -u -r1.25 Makefile
--- codecs/gsm/Makefile	18 Jun 2005 17:54:15 -0000	1.25
+++ codecs/gsm/Makefile	27 Oct 2005 18:06:33 -0000
@@ -36,6 +36,7 @@
 ######### which support MMX instructions.  This should be newer pentiums,
 ######### ppro's, etc, as well as the AMD K6 and K7.  The compile will
 ######### probably require gcc. 
+PROC=$(shell uname -m)
 
 ifneq (${OSARCH},Darwin)
 ifneq (${OSARCH},SunOS)
@@ -90,7 +91,11 @@
 # CCFLAGS 	= -c -O
 
 CC		?= gcc
-CCFLAGS 	+= -c -DNeedFunctionPrototypes=1 -funroll-loops -fPIC $(OPTIMIZE)
+CCFLAGS 	+= -c -DNeedFunctionPrototypes=1 -funroll-loops $(OPTIMIZE)
+ifneq ($(findstring CYGWIN,${OSARCH}),CYGWIN)
+CCFLAGS   += -fPIC
+endif
+
 
 LD 		= $(CC)
 
Index: formats/Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/formats/Makefile,v
retrieving revision 1.23
diff -u -r1.23 Makefile
--- formats/Makefile	30 Aug 2005 02:54:02 -0000	1.23
+++ formats/Makefile	27 Oct 2005 18:06:34 -0000
@@ -35,25 +35,29 @@
 
 GSMLIB=../codecs/gsm/lib/libgsm.a
 
+ifeq (${OSARCH},CYGWIN)
+CYGSOLINK=-Wl,--out-implib=lib$@.a -Wl,--export-all-symbols
+CYGSOLIB=-L.. -L. -lasterisk.dll
+else
 CFLAGS+=-fPIC
-
+endif
 all: depend $(FORMAT_LIBS)
 
 clean:
 	rm -f *.so *.o .depend
 
 %.so : %.o
-	$(CC) $(SOLINK) -o $@ $<
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB}
 
 ifneq ($(wildcard .depend),)
   include .depend
 endif
 
 format_mp3.so : format_mp3.o
-	$(CC) $(SOLINK) -o $@ $< -lm
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lm
 
 format_ogg_vorbis.so : format_ogg_vorbis.o
-	$(CC) $(SOLINK) -o $@ $< -logg -lvorbis -lvorbisenc -lm
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -logg -lvorbis -lvorbisenc -lm
 
 install: all
 	for x in $(FORMAT_LIBS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
Index: funcs/Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/funcs/Makefile,v
retrieving revision 1.11
diff -u -r1.11 Makefile
--- funcs/Makefile	5 Oct 2005 00:17:57 -0000	1.11
+++ funcs/Makefile	27 Oct 2005 18:06:34 -0000
@@ -33,7 +33,12 @@
 
 FUNC_STRUCTS=$(shell grep 'struct ast_custom_function' $(FUNC_SOURCES) | awk '{print $$3};')
 
+ifeq (${OSARCH},CYGWIN)
+CYGSOLINK=-Wl,--out-implib=lib$@.a -Wl,--export-all-symbols
+CYGSOLIB=-L.. -L. -lasterisk.dll
+else
 CFLAGS+=-fPIC
+endif
 
 ifeq ($(findstring BSD,${OSARCH}),BSD)
   CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include -L$(CROSS_COMPILE_TARGET)/usr/local/lib
@@ -45,7 +50,7 @@
 	rm -f *.so *.o .depend pbx_functions.h
 
 %.so : %.o
-	$(CC) $(SOLINK) -o $@ $<
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB}
 
 #$(BUILTINS) : CFLAGS += -DBUILTIN_FUNC
 
@@ -59,7 +64,7 @@
 pbx_functions.o: pbx_functions.h
 
 pbx_functions.so: pbx_functions.o #$(BUILTINS)
-	$(CC) $(SOLINK) -o $@ $<
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB}
 
 install: all
 	for x in $(FUNCS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
Index: include/asterisk/compat.h
===================================================================
RCS file: /usr/cvsroot/asterisk/include/asterisk/compat.h,v
retrieving revision 1.3
diff -u -r1.3 compat.h
--- include/asterisk/compat.h	24 Oct 2005 20:12:06 -0000	1.3
+++ include/asterisk/compat.h	27 Oct 2005 18:06:34 -0000
@@ -63,8 +63,12 @@
 
 #ifdef __CYGWIN__
 #define _WIN32_WINNT 0x0500
-#include <windows.h>
-#include <w32api/ws2tcpip.h>
+#ifndef INET_ADDRSTRLEN
+#define INET_ADDRSTRLEN  16
+#endif
+#ifndef INET6_ADDRSTRLEN
+#define INET6_ADDRSTRLEN 46
+#endif
 #endif /* __CYGWIN__ */
 
 #define HAVE_VASPRINTF
Index: include/asterisk/lock.h
===================================================================
RCS file: /usr/cvsroot/asterisk/include/asterisk/lock.h,v
retrieving revision 1.38
diff -u -r1.38 lock.h
--- include/asterisk/lock.h	24 Oct 2005 20:12:06 -0000	1.38
+++ include/asterisk/lock.h	27 Oct 2005 18:06:34 -0000
@@ -41,6 +41,10 @@
 														 0x20 } }
 #endif
 
+#ifdef __CYGWIN__
+#define PTHREAD_MUTEX_RECURSIVE_NP					PTHREAD_MUTEX_RECURSIVE
+#endif
+
 #ifdef BSD
 #ifdef __GNUC__
 #define AST_MUTEX_INIT_W_CONSTRUCTORS
Index: pbx/Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/pbx/Makefile,v
retrieving revision 1.20
diff -u -r1.20 Makefile
--- pbx/Makefile	30 Aug 2005 02:54:02 -0000	1.20
+++ pbx/Makefile	27 Oct 2005 18:06:34 -0000
@@ -28,7 +28,14 @@
 MOC=$(QTDIR)/bin/moc
 KDE_FLAGS=-I$(KDEDIR)/include -I$(KDEDIR)/include/kde -I$(QTDIR)/include
 KDE_LIBS=-L$(KDEDIR)/lib -L$(QTDIR)/lib -lqt -lkdecore -lkdeui
+
+ifeq (${OSARCH},CYGWIN)
+CYGSOLINK=-Wl,--out-implib=lib$@.a -Wl,--export-all-symbols
+CYGSOLIB=-L.. -L. -L../res -lasterisk.dll 
+CYG_PBX_DUNDI=-lres_crypto.so
+else
 CFLAGS+=-fPIC
+endif
 
 KDE_CONSOLE_OBJS=pbx_kdeconsole_main.o pbx_kdeconsole.o 
 
@@ -53,13 +60,13 @@
 	$(CC) $(SOLINK) -o $@ $(KDE_CONSOLE_OBJS) $(KDE_LIBS)
 
 pbx_dundi.so: dundi-parser.o pbx_dundi.o
-	$(CC) $(SOLINK) -o $@ pbx_dundi.o dundi-parser.o -lz
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} pbx_dundi.o dundi-parser.o -lz ${CYGSOLIB} ${CYG_PBX_DUNDI}
 
 %.moc : %.h
 	$(MOC) $< -o $@
 
 %.so : %.o
-	$(CC) $(SOLINK) -o $@ $<
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB}
 
 ifneq ($(wildcard .depend),)
   include .depend
Index: res/Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/res/Makefile,v
retrieving revision 1.25
diff -u -r1.25 Makefile
--- res/Makefile	16 Oct 2005 03:10:33 -0000	1.25
+++ res/Makefile	27 Oct 2005 18:06:35 -0000
@@ -11,8 +11,7 @@
 # the GNU General Public License
 #
 
-MODS=res_adsi.so res_features.so res_musiconhold.so res_indications.so res_monitor.so \
-     res_agi.so
+MODS=res_indications.so res_monitor.so res_adsi.so res_agi.so res_features.so
 
 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/odbcinst.h)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/odbcinst.h),)
   ifneq (${OSARCH},FreeBSD)
@@ -41,6 +40,15 @@
   CFLAGS+=-I$(CROSS_COMPILE_TARGET)/usr/local/include -L$(CROSS_COMPILE_TARGET)/usr/local/lib
 endif
 
+ifeq (${OSARCH},CYGWIN)
+CYGSOLINK=-Wl,--out-implib=lib$@.a -Wl,--export-all-symbols
+CYGSOLIB=-L.. -L. -lasterisk.dll
+CYG_RES_CONFIG_ODBC_LIB=-lres_odbc.so
+CYG_RES_FEATURES_LIB=-lres_adsi.so -lres_monitor.so
+else
+MODS+=res_musiconhold.so 
+endif
+
 CRYPTO_LIBS=-lssl -lcrypto
 
 CFLAGS+=
@@ -52,7 +60,11 @@
 #
 # Work around buggy RedHat 9.0
 #
+ifeq (${OSARCH},CYGWIN)
+CFLAGS+=-DOPENSSL_NO_KRB5
+else
 CFLAGS+=-DOPENSSL_NO_KRB5 -fPIC
+endif
 
 all: depend $(MODS)
 
@@ -63,19 +75,25 @@
 	for x in $(MODS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
 
 res_crypto.so: res_crypto.o
-	$(CC) $(SOLINK) -o $@ $< $(CRYPTO_LIBS)
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} $(CRYPTO_LIBS)
 
 clean:
 	rm -f *.so *.o .depend
 
 res_odbc.so: res_odbc.o
-	$(CC) $(SOLINK) -o $@ $< -lodbc
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lodbc
 
 res_osp.so: res_osp.o $(OSPLIB)
-	$(CC) $(SOLINK) -o $@ $^
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} $(OSPLIB)
 
 %.so : %.o
-	$(CC) $(SOLINK) -o $@ $<
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB}
+
+res_features.so: res_features.o
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} ${CYG_RES_FEATURES_LIB}
+
+res_config_odbc.so: res_config_odbc.o
+	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} ${CYG_RES_CONFIG_ODBC_LIB}
 
 ifneq ($(wildcard .depend),)
   include .depend
Index: stdtime/private.h
===================================================================
RCS file: /usr/cvsroot/asterisk/stdtime/private.h,v
retrieving revision 1.1
diff -u -r1.1 private.h
--- stdtime/private.h	13 Sep 2003 20:51:48 -0000	1.1
+++ stdtime/private.h	27 Oct 2005 18:06:35 -0000
@@ -9,9 +9,11 @@
 */
 
 /* Stuff moved from Makefile.inc to reduce clutter */
+#ifndef __CYGWIN__
 #ifndef TM_GMTOFF
 #define TM_GMTOFF	tm_gmtoff
 #define TM_ZONE		tm_zone
+#endif
 #define STD_INSPIRED	1
 #define PCTS		1
 #define HAVE_LONG_DOUBLE 1
Index: utils/streamplayer.c
===================================================================
RCS file: /usr/cvsroot/asterisk/utils/streamplayer.c,v
retrieving revision 1.7
diff -u -r1.7 streamplayer.c
--- utils/streamplayer.c	18 Oct 2005 03:24:41 -0000	1.7
+++ utils/streamplayer.c	27 Oct 2005 18:06:35 -0000
@@ -31,7 +31,7 @@
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/socket.h>
-#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__Darwin__)
+#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__Darwin__) || defined(__CYGWIN__)
 #include <netinet/in.h>
 #endif
 #include <sys/time.h>
--- /dev/null	1969-12-31 19:00:00.000000000 -0500
+++ cygwin/Makefile	2005-10-27 13:57:12.984670400 -0400
@@ -0,0 +1,6 @@
+OBJS=cygloader.o
+all: $(OBJS)
+$(OBJS) : %.o: %.c
+	$(CC) $< -o asterisk.exe
+clean:
+	rm -f asterisk.exe
--- /dev/null	1969-12-31 19:00:00.000000000 -0500
+++ cygwin/cygloader.c	2005-10-27 13:57:38.010656000 -0400
@@ -0,0 +1,33 @@
+#include <unistd.h>
+#include <dlfcn.h>
+#include <stdio.h>
+
+#define OK					0
+#define MODULE_NOT_FOUND			1
+#define INVALID_NUMBER_ARGUMENTS	2
+
+int main(int argc, char **argv) {
+	/* Asterisk entry point */
+	char* error = NULL;
+	int (*ast_main)(int argc, char **argv);
+
+	void *handle = dlopen ("asterisk.dll", RTLD_GLOBAL);
+	if (handle == NULL) {
+		fputs (dlerror(), stderr);
+		fputs ("\r\n", stderr);
+		return MODULE_NOT_FOUND;
+	}
+	printf("\r\nAsterisk module loaded successfully");
+	ast_main = dlsym(handle, "main");
+		if ((error = dlerror()) != NULL) {
+			fputs("Asterisk main not found", stderr);
+			fputs(error, stderr);
+			exit(1);
+		}
+	printf("\r\nAsterisk entry point found");
+	/* run asterisk main */
+	(*ast_main)(argc, argv);
+	dlclose(handle);
+	printf("\r\nAsterisk stopped");
+	return OK;
+}
