From 7d841b18857fab6417f93ee252ffe72fef4a9e8d Mon Sep 17 00:00:00 2001
From: "Kevin P. Fleming" <kpfleming@digium.com>
Date: Tue, 5 Jul 2005 19:30:18 +0000
Subject: [PATCH] make editline build properly on cygwin (bug #4624)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6029 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 editline/Makefile.in  | 11 ++++++++++-
 editline/config.h.in  |  4 ++++
 editline/configure    | 21 ++++++++++++++++++++-
 editline/configure.in | 21 ++++++++++++++++++++-
 4 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/editline/Makefile.in b/editline/Makefile.in
index 67ae6ad404..c4e5695154 100755
--- a/editline/Makefile.in
+++ b/editline/Makefile.in
@@ -3,6 +3,13 @@
 #
 
 OSTYPE=$(shell uname -s)
+cygx="$(shell uname -s | sed -e c\cygwin | tr [:upper:] [:lower:])"
+define cyg_subst_sys
+	if [ $(cygx) = "cygwin" ]; then \
+	cat $@ | sed -e s/"sys\.h"/"config.h"/g > $@.copy; \
+	mv --force $@.copy $@; \
+	fi
+endef
 
 SHELL = /bin/sh
 
@@ -184,7 +191,7 @@ $(LIB_A) : $(BGCSRCS:.c=.o_a) $(CCSRCS:.c=.o_a)
 	$(RANLIB) $@
 
 $(LIB_S) : $(BGCSRCS:.c=.o_s) $(CCSRCS:.c=.o_s)
-	$(CC) $(S_LDFLAGS) -o $@ $(BGCSRCS:.c=.o_s) $(CCSRCS:.c=.o_s)
+	$(CC) $(S_LDFLAGS) -o $@ $(BGCSRCS:.c=.o_s) $(CCSRCS:.c=.o_s) $(LIBS)
 
 $(TEST) : $(TCSRCS:.c=.o) $(LIB_A)
 	$(CC) -o $@ $(TCSRCS:.c=.o) $(LIB_A) $(LIBS)
@@ -203,12 +210,14 @@ fcns.h : $(AGHDRS)
 
 fcns.c : $(AGHDRS) fcns.h
 	$(SHELL) makelist -fc $(AGHDRS) > $@
+	$(cyg_subst_sys)
 
 help.h : $(ACSRCS)
 	$(SHELL) makelist -bh $(ACSRCS) > $@
 
 help.c : $(ACSRCS) help.h
 	$(SHELL) makelist -bc $(ACSRCS) > $@
+	$(cyg_subst_sys)
 
 editline.c : $(ACSRCS) $(BCSRCS) $(AGCSRCS)
 	$(SHELL) makelist -e $(ACSRCS) $(BCSRCS) $(AGCSRCS) > $@
diff --git a/editline/config.h.in b/editline/config.h.in
index a645a7f06f..151fb226db 100755
--- a/editline/config.h.in
+++ b/editline/config.h.in
@@ -1,4 +1,5 @@
 #undef SUNOS
+#undef CYGWIN
 
 #undef HAVE_SYS_CDEFS_H
 #undef HAVE_TERMCAP_H
@@ -15,3 +16,6 @@
 #undef HAVE_STRUNVIS
 
 #include "sys.h"
+#ifdef CYGWIN
+# include "cygdef.h"
+#endif
diff --git a/editline/configure b/editline/configure
index ce38a97a54..9dccffd0ff 100755
--- a/editline/configure
+++ b/editline/configure
@@ -894,7 +894,26 @@ case "${host}" in
   *-*-freebsd*)
 	ABI="elf"
 	;;
-  *-*-linux*)
+  *-*-linux* | *cygwin*)
+	cyg="$(echo ${host} | sed -e c\cygwin)"
+	if [ ${cyg} = cygwin ]; then \
+		echo "cygwin detected"; \
+		S_CFLAGS=""; \
+		echo "/* cygdef.h. Generated automatically by configure. */ 
+#ifndef _CYGDEF_H_
+#define _CYGDEF_H_ 1
+#include <sys/ioctl.h>
+#define __linux__ 1
+ 
+
+typedef void (*sig_t)(int);
+ 
+
+#endif /* _CYGDEF_H_ */" > cygdef.h; \
+	echo "
+ #define CYGWIN 1
+" > confdefs.h; \
+	fi
 	ABI="elf"
 	;;
   *-*-netbsd*)
diff --git a/editline/configure.in b/editline/configure.in
index 72ae9180bc..dcef07a91a 100755
--- a/editline/configure.in
+++ b/editline/configure.in
@@ -31,7 +31,26 @@ case "${host}" in
   *-*-freebsd*)
 	ABI="elf"
 	;;
-  *-*-linux*)
+  *-*-linux* | *cygwin*)
+	cyg="$(echo ${host} | sed -e c\cygwin)"
+	if [ ${cyg} = cygwin ]; then \
+		echo "cygwin detected"; \
+		S_CFLAGS=""; \
+		echo "/* cygdef.h. Generated automatically by configure. */ 
+#ifndef _CYGDEF_H_
+#define _CYGDEF_H_ 1
+#include <sys/ioctl.h>
+#define __linux__ 1
+ 
+
+typedef void (*sig_t)(int);
+ 
+
+#endif /* _CYGDEF_H_ */" > cygdef.h; \
+	echo "
+ #define CYGWIN 1
+" > confdefs.h; \
+	fi
 	ABI="elf"
 	;;
   *-*-netbsd*)
-- 
GitLab