From efdaafe0b211f006ae9c831b132773151eac4cb3 Mon Sep 17 00:00:00 2001 From: Li-Wen Hsu Date: Tue, 17 Dec 2013 02:30:36 +0800 Subject: [PATCH] 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