From 78680bf72d678964a0c149813791318399bef6f0 Mon Sep 17 00:00:00 2001 From: ied206 Date: Tue, 16 Jun 2015 13:02:40 +0900 Subject: [PATCH] Second Patch to compile smoothly in Cygwin --- README-Cygwin.md | 34 +++++++++++++++++--------------- telegram-cli-cygwin.patch | 41 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 16 deletions(-) create mode 100644 telegram-cli-cygwin.patch diff --git a/README-Cygwin.md b/README-Cygwin.md index 5de3888..42ed011 100755 --- a/README-Cygwin.md +++ b/README-Cygwin.md @@ -1,55 +1,57 @@ ### Installation on Windows To use telegram-cli in Windows, you should compile with Cygwin which has POSIX API functionality. -First, Clone GitHub Repository - - git clone --recursive https://github.com/vysheng/tg.git - Install [Cygwin](https://www.cygwin.com/) and cygwin's package manager, [apt-cyg](https://github.com/transcode-open/apt-cyg). -On Cygwin Terminal, install compiler and tools : +In Cygwin Terminal, install compiler and tools : apt-cyg install cygwin32-gcc-core cygwin32-gcc-g++ gcc-core gcc-g++ make wget patch diffutils grep tar gzip Now you have a compiler, but no libraries. You need readline, openssl, libconfig, liblua, python and libjansson to use telegram-cli's full functionality. -On Cygwin Terminal, type: + +Then Clone GitHub Repository in Cygwin Terminal + + git clone --recursive https://github.com/vysheng/tg.git + + +In Cygwin Terminal, type: apt-cyg install libevent-devel openssl-devel libreadline-devel lua-devel python3 (Install package 'python' to use Python 2.7, or install package 'python3' to use Python 3) libconfig and libjansson is not in cygwin's package, so you should compile yourself. -Compile libconfig : +Compile libconfig wget http://www.hyperrealm.com/libconfig/libconfig-1.5.tar.gz tar xvf libconfig-1.5.tar.gz && cd libconfig-1.5 ./configure make && make install && cd .. -Compile libjansson : +Compile libjansson wget http://www.digip.org/jansson/releases/jansson-2.7.tar.gz tar xvf jansson-2.7.tar.gz && cd jansson-2.7 ./configure make && make install && cd .. -Then, in telegram-cli's directory, - - ./configure - -We need to patch Makefile and loop.c to compile in cygwin. Download this [diff](https://gist.github.com/ied206/d774a445f36004d263ab) then untar. Then, patch in 'tg' directory. +Then, go to tg directory then generate Makefile. cd tg - patch -p1 < telegram-cli-cygwin.diff + ./configure + +We need to patch Makefile and loop.c to compile in cygwin. Download this [patch](https://gist.github.com/ied206/d774a445f36004d263ab) then untar. Then, patch in tg directory. + + patch -p1 < telegram-cli-cygwin.patch Then make -There will be some warnings, but you can ignore them. After compile is done, **telegram-cli.exe** will be generated in **bin** directory. +After compile is done, **telegram-cli.exe** will be generated in **bin** directory. To run telegram-cli, type bin/telegram-cli -k tg-server.pub -**Caution**: Binary compiled with Cygwin should be run in Cygwin Terminal, since it assumes unix-like shell, and it is dependent on cygwin dlls. +**Caution**: A binary compiled with Cygwin should be run in Cygwin Terminal. diff --git a/telegram-cli-cygwin.patch b/telegram-cli-cygwin.patch new file mode 100644 index 0000000..7fb3bbd --- /dev/null +++ b/telegram-cli-cygwin.patch @@ -0,0 +1,41 @@ +Binary files tg/.git/index and tg-cygwin/.git/index differ +diff -urN tg/Makefile tg-cygwin/Makefile +--- tg/Makefile 2015-06-16 12:39:34.931053900 +0900 ++++ tg-cygwin/Makefile 2015-06-16 12:44:12.584342300 +0900 +@@ -4,9 +4,9 @@ + LDFLAGS= -L/usr/local/lib -L/usr/lib -L/usr/lib -L/usr/lib + CPPFLAGS= -I/usr/local/include -I/usr/include -I/usr/include -I/usr/include/python3.4m -I/usr/include + DEFS=-DHAVE_CONFIG_H +-COMPILE_FLAGS=${CFLAGS} ${CPFLAGS} ${CPPFLAGS} ${DEFS} -Wall -Werror -Wextra -Wno-missing-field-initializers -Wno-deprecated-declarations -fno-strict-aliasing -fno-omit-frame-pointer -ggdb -Wno-unused-parameter -fPIC ++COMPILE_FLAGS=${CFLAGS} ${CPFLAGS} ${CPPFLAGS} ${DEFS} -Wall -Werror -Wextra -Wno-missing-field-initializers -Wno-deprecated-declarations -fno-strict-aliasing -fno-omit-frame-pointer -ggdb -Wno-unused-parameter + EXTRA_LIBS=-ljansson -lconfig -lz -levent -lm -lreadline -llua-5.2 -lpython3.4m -lssl -lcrypto +-LOCAL_LDFLAGS=-rdynamic -ggdb -levent ${EXTRA_LIBS} -ldl -lpthread -lutil ++LOCAL_LDFLAGS=-ggdb -levent ${EXTRA_LIBS} -ldl -lpthread -lutil + LINK_FLAGS=${LDFLAGS} ${LOCAL_LDFLAGS} + + DEP=dep +diff -urN tg/loop.c tg-cygwin/loop.c +--- tg/loop.c 2015-06-16 12:37:54.054112200 +0900 ++++ tg-cygwin/loop.c 2015-06-16 12:48:12.793954000 +0900 +@@ -383,8 +383,9 @@ + close (auth_file_fd); + } + +-void write_secret_chat (tgl_peer_t *_P, void *extra) { +- struct tgl_secret_chat *P = (void *)_P; ++// In Cygwin's Python, _P is marco constant. So change tgl_peer_t *_P -> tgl_peer_t *_Peer ++void write_secret_chat (tgl_peer_t *_Peer, void *extra) { ++ struct tgl_secret_chat *P = (void *)_Peer; + if (tgl_get_peer_type (P->id) != TGL_PEER_ENCR_CHAT) { return; } + if (P->state != sc_ok) { return; } + int *a = extra; +@@ -634,7 +635,8 @@ + vlogprintf (E_WARNING, "Accepting incoming connection\n"); + unsigned clilen = 0; + struct sockaddr_in cli_addr; +- int fd = accept (efd, (struct sockaddr *)&cli_addr, &clilen); ++ // In Cygwin, put unsigned int in socklen_t produce warning. Add (socklen_t *) casting ++ int fd = accept (efd, (struct sockaddr *)&cli_addr, (socklen_t *)&clilen); + + assert (fd >= 0); + struct bufferevent *bev = bufferevent_socket_new (TLS->ev_base, fd, 0);