From bb53f75e2bb565054b5cf30f3af96fd4cae546bb Mon Sep 17 00:00:00 2001 From: Li-Wen Hsu Date: Tue, 17 Dec 2013 02:30:36 +0800 Subject: [PATCH 1/7] Make it compile on FreeBSD. --- Makefile | 10 +++++----- Makefile.in | 4 ++-- config.h | 2 +- loop.c | 1 + mtproto-client.c | 18 ++++++++++++------ net.c | 5 ++++- 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index c7e68f3..23f76ac 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,13 @@ srcdir=. -CFLAGS=-g -O2 -LDFLAGS= +CFLAGS=-I/usr/local/include +LDFLAGS=-L/usr/local/lib CPPFLAGS= DEFS=-DHAVE_CONFIG_H -COMPILE_FLAGS=${CFLAGS} ${CPPFLAGS} ${DEFS} -Wall -Wextra -Werror -Wno-deprecated -fno-strict-aliasing -fno-omit-frame-pointer -ggdb +COMPILE_FLAGS=${CFLAGS} ${CPPFLAGS} ${DEFS} -Wall -Wextra -Werror -fno-strict-aliasing -fno-omit-frame-pointer -ggdb -EXTRA_LIBS= -lreadline -lrt -lconfig -LOCAL_LDFLAGS=-lm -lcrypto -lz -lssl -rdynamic -ggdb ${EXTRA_LIBS} +EXTRA_LIBS= +LOCAL_LDFLAGS=-lm -lcrypto -lz -lssl -rdynamic -ggdb -lconfig -lreadline -lexecinfo ${EXTRA_LIBS} LINK_FLAGS=${LDFLAGS} ${LOCAL_LDFLAGS} HEADERS= ${srcdir}/constants.h ${srcdir}/include.h ${srcdir}/interface.h ${srcdir}/LICENSE.h ${srcdir}/loop.h ${srcdir}/mtproto-client.h ${srcdir}/mtproto-common.h ${srcdir}/net.h ${srcdir}/no-preview.h ${srcdir}/queries.h ${srcdir}/structures.h ${srcdir}/telegram.h ${srcdir}/tree.h ${srcdir}/config.h ${srcdir}/binlog.h diff --git a/Makefile.in b/Makefile.in index 1bf9014..68e199c 100644 --- a/Makefile.in +++ b/Makefile.in @@ -4,10 +4,10 @@ CFLAGS=@CFLAGS@ LDFLAGS=@LDFLAGS@ CPPFLAGS=@CPPFLAGS@ DEFS=@DEFS@ -COMPILE_FLAGS=${CFLAGS} ${CPPFLAGS} ${DEFS} -Wall -Wextra -Werror -Wno-deprecated -fno-strict-aliasing -fno-omit-frame-pointer -ggdb +COMPILE_FLAGS=${CFLAGS} ${CPPFLAGS} ${DEFS} -Wall -Wextra -Werror -fno-strict-aliasing -fno-omit-frame-pointer -ggdb EXTRA_LIBS=@EXTRA_LIBS@ -LOCAL_LDFLAGS=-lm -lcrypto -lz -lssl -rdynamic -ggdb ${EXTRA_LIBS} +LOCAL_LDFLAGS=-lm -lcrypto -lz -lssl -rdynamic -ggdb -lconfig -lreadline -lexecinfo ${EXTRA_LIBS} LINK_FLAGS=${LDFLAGS} ${LOCAL_LDFLAGS} HEADERS= ${srcdir}/constants.h ${srcdir}/include.h ${srcdir}/interface.h ${srcdir}/LICENSE.h ${srcdir}/loop.h ${srcdir}/mtproto-client.h ${srcdir}/mtproto-common.h ${srcdir}/net.h ${srcdir}/no-preview.h ${srcdir}/queries.h ${srcdir}/structures.h ${srcdir}/telegram.h ${srcdir}/tree.h ${srcdir}/config.h ${srcdir}/binlog.h diff --git a/config.h b/config.h index 73aaaf3..538a278 100644 --- a/config.h +++ b/config.h @@ -24,7 +24,7 @@ #define HAVE_MALLOC 1 /* Define to 1 if you have the header file. */ -#define HAVE_MALLOC_H 1 +/* #undef HAVE_MALLOC_H */ /* Define to 1 if you have the header file. */ #define HAVE_MEMORY_H 1 diff --git a/loop.c b/loop.c index d9f3bf3..3a0dcbf 100644 --- a/loop.c +++ b/loop.c @@ -20,6 +20,7 @@ #include "config.h" #include +#define _WITH_GETLINE #include #include diff --git a/mtproto-client.c b/mtproto-client.c index 944d05a..d8a2e48 100644 --- a/mtproto-client.c +++ b/mtproto-client.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -34,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -46,6 +48,10 @@ #include "structures.h" #include "binlog.h" +#if defined(__FreeBSD__) +#define __builtin_bswap32(x) bswap32(x) +#endif + #define sha1 SHA1 #include "mtproto-common.h" @@ -1589,7 +1595,7 @@ int rpc_execute (struct connection *c, int op, int len) { logprintf ( "have %d Response bytes\n", Response_len); } -#ifndef __MACH__ +#if !defined(__MACH__) && !defined(__FreeBSD__) setsockopt (c->fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){0}, 4); #endif int o = c_state; @@ -1597,19 +1603,19 @@ int rpc_execute (struct connection *c, int op, int len) { switch (o) { case st_reqpq_sent: process_respq_answer (c, Response/* + 8*/, Response_len/* - 12*/); -#ifndef __MACH__ +#if !defined(__MACH__) && !defined(__FreeBSD__) setsockopt (c->fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){0}, 4); #endif return 0; case st_reqdh_sent: process_dh_answer (c, Response/* + 8*/, Response_len/* - 12*/); -#ifndef __MACH__ +#if !defined(__MACH__) && !defined(__FreeBSD__) setsockopt (c->fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){0}, 4); #endif return 0; case st_client_dh_sent: process_auth_complete (c, Response/* + 8*/, Response_len/* - 12*/); -#ifndef __MACH__ +#if !defined(__MACH__) && !defined(__FreeBSD__) setsockopt (c->fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){0}, 4); #endif return 0; @@ -1619,7 +1625,7 @@ int rpc_execute (struct connection *c, int op, int len) { } else { process_rpc_message (c, (void *)(Response/* + 8*/), Response_len/* - 12*/); } -#ifndef __MACH__ +#if !defined(__MACH__) && !defined(__FreeBSD__) setsockopt (c->fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){0}, 4); #endif return 0; @@ -1647,7 +1653,7 @@ int tc_becomes_ready (struct connection *c) { assert (write_out (c, &byte, 1) == 1); flush_out (c); -#ifndef __MACH__ +#if !defined(__MACH__) && !defined(__FreeBSD__) setsockopt (c->fd, IPPROTO_TCP, TCP_QUICKACK, (int[]){0}, 4); #endif int o = c_state; diff --git a/net.c b/net.c index 7d5db84..22eec8c 100644 --- a/net.c +++ b/net.c @@ -21,8 +21,11 @@ #include #include #include +#include #include #include +#include +#include #include #include #include @@ -37,7 +40,7 @@ #include "tree.h" #include "interface.h" -#ifdef __MACH__ +#if defined(__MACH__) || defined(__FreeBSD__) #define POLLRDHUP 0 #endif From cacf0582bcbb9663c262afc87531ae069f5562c4 Mon Sep 17 00:00:00 2001 From: Li-Wen Hsu Date: Thu, 19 Dec 2013 01:58:51 +0800 Subject: [PATCH 2/7] Define _GNU_SOURCE for getline(3) --- loop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loop.c b/loop.c index 3a0dcbf..ed6bf91 100644 --- a/loop.c +++ b/loop.c @@ -18,9 +18,9 @@ */ #define READLINE_CALLBACKS #include "config.h" +#define _GNU_SOURCE #include -#define _WITH_GETLINE #include #include From 0d80f5e298604cb6c098ddff24162c33e190a1a2 Mon Sep 17 00:00:00 2001 From: Li-Wen Hsu Date: Thu, 19 Dec 2013 02:17:21 +0800 Subject: [PATCH 3/7] Restore flags not supported by gcc 4.2 --- Makefile | 2 +- Makefile.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 23f76ac..c28f79e 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ CFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib CPPFLAGS= DEFS=-DHAVE_CONFIG_H -COMPILE_FLAGS=${CFLAGS} ${CPPFLAGS} ${DEFS} -Wall -Wextra -Werror -fno-strict-aliasing -fno-omit-frame-pointer -ggdb +COMPILE_FLAGS=${CFLAGS} ${CPPFLAGS} ${DEFS} -Wall -Wextra -Werror -Wno-deprecated -fno-strict-aliasing -fno-omit-frame-pointer -ggdb EXTRA_LIBS= LOCAL_LDFLAGS=-lm -lcrypto -lz -lssl -rdynamic -ggdb -lconfig -lreadline -lexecinfo ${EXTRA_LIBS} diff --git a/Makefile.in b/Makefile.in index 68e199c..eef20d9 100644 --- a/Makefile.in +++ b/Makefile.in @@ -4,7 +4,7 @@ CFLAGS=@CFLAGS@ LDFLAGS=@LDFLAGS@ CPPFLAGS=@CPPFLAGS@ DEFS=@DEFS@ -COMPILE_FLAGS=${CFLAGS} ${CPPFLAGS} ${DEFS} -Wall -Wextra -Werror -fno-strict-aliasing -fno-omit-frame-pointer -ggdb +COMPILE_FLAGS=${CFLAGS} ${CPPFLAGS} ${DEFS} -Wall -Wextra -Werror -Wno-deprecated -fno-strict-aliasing -fno-omit-frame-pointer -ggdb EXTRA_LIBS=@EXTRA_LIBS@ LOCAL_LDFLAGS=-lm -lcrypto -lz -lssl -rdynamic -ggdb -lconfig -lreadline -lexecinfo ${EXTRA_LIBS} From 715378408b4b92163273513b8ab67696b1298fcc Mon Sep 17 00:00:00 2001 From: Li-Wen Hsu Date: Thu, 19 Dec 2013 02:19:37 +0800 Subject: [PATCH 4/7] Remove generated files and add .gitignore --- .gitignore | 2 + Makefile | 35 ------------------ config.h | 106 ----------------------------------------------------- 3 files changed, 2 insertions(+), 141 deletions(-) create mode 100644 .gitignore delete mode 100644 Makefile delete mode 100644 config.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..547646a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +Makefile +config.h diff --git a/Makefile b/Makefile deleted file mode 100644 index c28f79e..0000000 --- a/Makefile +++ /dev/null @@ -1,35 +0,0 @@ -srcdir=. - -CFLAGS=-I/usr/local/include -LDFLAGS=-L/usr/local/lib -CPPFLAGS= -DEFS=-DHAVE_CONFIG_H -COMPILE_FLAGS=${CFLAGS} ${CPPFLAGS} ${DEFS} -Wall -Wextra -Werror -Wno-deprecated -fno-strict-aliasing -fno-omit-frame-pointer -ggdb - -EXTRA_LIBS= -LOCAL_LDFLAGS=-lm -lcrypto -lz -lssl -rdynamic -ggdb -lconfig -lreadline -lexecinfo ${EXTRA_LIBS} -LINK_FLAGS=${LDFLAGS} ${LOCAL_LDFLAGS} - -HEADERS= ${srcdir}/constants.h ${srcdir}/include.h ${srcdir}/interface.h ${srcdir}/LICENSE.h ${srcdir}/loop.h ${srcdir}/mtproto-client.h ${srcdir}/mtproto-common.h ${srcdir}/net.h ${srcdir}/no-preview.h ${srcdir}/queries.h ${srcdir}/structures.h ${srcdir}/telegram.h ${srcdir}/tree.h ${srcdir}/config.h ${srcdir}/binlog.h -INCLUDE=-I. -I${srcdir} -CC=gcc -OBJECTS=main.o loop.o interface.o net.o mtproto-common.o mtproto-client.o queries.o structures.o binlog.o - -.SUFFIXES: - -.SUFFIXES: .c .h .o - -all: telegram - -${OBJECTS}: ${HEADERS} - -telegram: ${OBJECTS} - ${CC} ${OBJECTS} ${LINK_FLAGS} -o $@ - -.c.o : - ${CC} ${COMPILE_FLAGS} ${INCLUDE} -c $< -o $@ - - -clean: - rm -rf *.o telegram > /dev/null || echo "all clean" - diff --git a/config.h b/config.h deleted file mode 100644 index 538a278..0000000 --- a/config.h +++ /dev/null @@ -1,106 +0,0 @@ -/* config.h. Generated from config.h.in by configure. */ -/* config.h.in. Generated from configure.ac by autoheader. */ - -/* enable libconfig */ -#define ENABLE_LIBCONFIG 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_FCNTL_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_INTTYPES_H 1 - -/* Define to 1 if you have the `crypto' library (-lcrypto). */ -#define HAVE_LIBCRYPTO 1 - -/* Define to 1 if you have the `edit' library (-ledit). */ -/* #undef HAVE_LIBEDIT */ - -/* Define to 1 if you have the `m' library (-lm). */ -#define HAVE_LIBM 1 - -/* Define to 1 if your system has a GNU libc compatible `malloc' function, and - to 0 otherwise. */ -#define HAVE_MALLOC 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_MALLOC_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_MEMORY_H 1 - -/* Define to 1 if you have the `memset' function. */ -#define HAVE_MEMSET 1 - -/* Define to 1 if your system has a GNU libc compatible `realloc' function, - and to 0 otherwise. */ -#define HAVE_REALLOC 1 - -/* Define to 1 if you have the `select' function. */ -#define HAVE_SELECT 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDINT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the `strdup' function. */ -#define HAVE_STRDUP 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRINGS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the `strndup' function. */ -#define HAVE_STRNDUP 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_SOCKET_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_UNISTD_H 1 - -/* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "" - -/* Define to the full name of this package. */ -#define PACKAGE_NAME "telegram" - -/* Define to the full name and version of this package. */ -#define PACKAGE_STRING "telegram 0.1" - -/* Define to the one symbol short name of this package. */ -#define PACKAGE_TARNAME "telegram" - -/* Define to the home page for this package. */ -#define PACKAGE_URL "" - -/* Define to the version of this package. */ -#define PACKAGE_VERSION "0.1" - -/* Use libedit */ -/* #undef READLINE_EDIT */ - -/* Use gnu libreadline */ -#define READLINE_GNU 1 - -/* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Define to rpl_malloc if the replacement function should be used. */ -/* #undef malloc */ - -/* Define to rpl_realloc if the replacement function should be used. */ -/* #undef realloc */ - -/* Define to `unsigned int' if does not define. */ -/* #undef size_t */ From 7c42025800978e9ebc8719faac733a69ec24ae13 Mon Sep 17 00:00:00 2001 From: Li-Wen Hsu Date: Thu, 19 Dec 2013 02:25:34 +0800 Subject: [PATCH 5/7] Clean up more generated files --- Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index eef20d9..6600ce9 100644 --- a/Makefile.in +++ b/Makefile.in @@ -31,5 +31,5 @@ telegram: ${OBJECTS} clean: - rm -rf *.o telegram > /dev/null || echo "all clean" + rm -rf *.o telegram config.log config.status > /dev/null || echo "all clean" From c05bb7599b1059f13ecfb55dc7f651a3c1bf8a44 Mon Sep 17 00:00:00 2001 From: Li-Wen Hsu Date: Thu, 19 Dec 2013 02:26:29 +0800 Subject: [PATCH 6/7] Add instructions to build on FreeBSD --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index c82dee5..9620f2b 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,15 @@ The client depends on [readline library](http://cnswww.cns.cwru.edu/php/chet/rea $ ./configure && make Thanks to [@jfontan](https://github.com/vysheng/tg/issues/3#issuecomment-28293731) for this solution. + +#### FreeBSD + +Install these ports: +* devel/libconfig +* devel/libexecinfo + + $ env CC=clang CFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib ./configure + $ make #### Other UNIX From edc4d2eba148638a98144719e92095b573a82dc4 Mon Sep 17 00:00:00 2001 From: Li-Wen Hsu Date: Thu, 19 Dec 2013 02:37:46 +0800 Subject: [PATCH 7/7] Insert newlines and some words for markdown formating --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 9620f2b..e82c523 100644 --- a/README.md +++ b/README.md @@ -42,9 +42,12 @@ Thanks to [@jfontan](https://github.com/vysheng/tg/issues/3#issuecomment-2829373 #### FreeBSD Install these ports: + * devel/libconfig * devel/libexecinfo +Then build: + $ env CC=clang CFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib ./configure $ make