summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGDR! <gdr@gdr.name>2015-09-17 10:30:10 +0200
committerGDR! <gdr@gdr.name>2015-09-17 10:30:10 +0200
commitba90921d46f3bfffbb87f4b271ba0276b113dc2f (patch)
tree697d87f921bc0fddd54ee3a27b3cb65c13e302cb
parent83790e5faf3de5ddb447e29ebe3490bdc30b1624 (diff)
parent199787953243d91449ac5f4a5ac16edc2497e438 (diff)
Merge pull request #15 from nCore/mac
Possibility to compile on Mac OS platform
-rw-r--r--.gitignore4
-rw-r--r--BUILD.md15
-rw-r--r--Makefile.mac28
-rw-r--r--client.c6
-rw-r--r--mach.c20
-rw-r--r--mach.h14
-rw-r--r--main.c6
7 files changed, 91 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index edf6645..8b6eea7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,3 +27,7 @@
27*.i*86 27*.i*86
28*.x86_64 28*.x86_64
29*.hex 29*.hex
30
31# tuntox related, not needed in repo
32tuntox
33gitversion.h
diff --git a/BUILD.md b/BUILD.md
index c0d340c..5de078c 100644
--- a/BUILD.md
+++ b/BUILD.md
@@ -4,4 +4,17 @@
4* cd tuntox 4* cd tuntox
5* make 5* make
6 6
7The makefile creates a static binary by default. If you're not a fan of static binaries, remove "-static" from LDFLAGS. One reason to do so may be if you'd like to resolve hostnames on the tuntox server (invoke client with -L 80:reddit.com:80 instead of -L 80:198.41.208.138:80). Static linking breaks hostname resolution, but IMHO the pros overweight the cons. 7The makefile creates a static binary by default. If you're not a fan of static binaries, remove `-static` from `LDFLAGS`.
8
9One reason to do so may be if you'd like to resolve hostnames on the tuntox server (invoke client with `-L 80:reddit.com:80` instead of `-L 80:198.41.208.138:80`).
10
11Static linking breaks hostname resolution, but IMHO the pros overweight the cons.
12
13## MacOS build
14Basically the same as above but:
15
16* static compiling is removed - you can't do this on MacOS platform (no, just don't)
17* because of removed `-static` you can't resolve hostnames (you can always put it into `hosts` file in your system)
18
19If you'd like to build on Mac do: `make -f Makefile.mac`
20
diff --git a/Makefile.mac b/Makefile.mac
new file mode 100644
index 0000000..ee41cda
--- /dev/null
+++ b/Makefile.mac
@@ -0,0 +1,28 @@
1SOURCES = $(wildcard *.c)
2DEPS=libtoxcore
3CC=gcc
4CFLAGS=-g #-std=c99
5CFLAGS += $(shell pkg-config --cflags $(DEPS))
6LDFLAGS=-g -lm
7LDFLAGS += $(shell pkg-config --libs $(DEPS))
8OBJECTS=$(SOURCES:.c=.o)
9INCLUDES = $(wildcard *.h)
10
11all: cscope.out tuntox
12
13gitversion.h: .git/HEAD .git/index
14 echo "#define GITVERSION \"$(shell git rev-parse HEAD)\"" > $@
15
16gitversion.c: gitversion.h
17
18.c.o: $(INCLUDES)
19 $(CC) $(CFLAGS) $< -c -o $@
20
21tuntox: $(OBJECTS) $(INCLUDES)
22 $(CC) -o $@ $(OBJECTS) -ltoxcore $(LDFLAGS) /usr/local/lib/libsodium.a /usr/local/lib/libtoxcore.a
23
24cscope.out:
25 cscope -bv ./*.[ch]
26
27clean:
28 rm -rf *.o tuntox gitversion.h
diff --git a/client.c b/client.c
index fff4620..bfcab14 100644
--- a/client.c
+++ b/client.c
@@ -1,4 +1,10 @@
1#include <time.h> 1#include <time.h>
2
3/* MacOS related */
4#ifdef __MACH__
5#include "mach.h"
6#endif
7
2#include "log.h" 8#include "log.h"
3#include "main.h" 9#include "main.h"
4#include "client.h" 10#include "client.h"
diff --git a/mach.c b/mach.c
new file mode 100644
index 0000000..35ac3a9
--- /dev/null
+++ b/mach.c
@@ -0,0 +1,20 @@
1#include "mach.h"
2
3/* there is no clock_gettime on MacOS platform */
4int clock_gettime(int clk_id, struct timespec *t)
5{
6 mach_timebase_info_data_t timebase;
7 mach_timebase_info(&timebase);
8
9 uint64_t time;
10
11 time = mach_absolute_time();
12
13 double nseconds = ((double)time * (double)timebase.numer) / ((double)timebase.denom);
14 double seconds = ((double)time * (double)timebase.numer) / ((double)timebase.denom * 1e9);
15
16 t->tv_sec = seconds;
17 t->tv_nsec = nseconds;
18
19 return 0;
20}
diff --git a/mach.h b/mach.h
new file mode 100644
index 0000000..5ac9a4e
--- /dev/null
+++ b/mach.h
@@ -0,0 +1,14 @@
1#ifndef _MACH_H
2#define _MACH_H
3
4#include <time.h>
5#include <mach/mach_time.h>
6
7// there is no CLOCK_REALTIME or CLOCK_MONOTONIC on MacOS platform
8#define CLOCK_REALTIME 0
9#define CLOCK_MONOTONIC 0
10
11// MacOS doesn't support the flag MSG_NOSIGNAL
12#define MSG_NOSIGNAL SO_NOSIGPIPE
13
14#endif \ No newline at end of file
diff --git a/main.c b/main.c
index 129e97c..72d18f4 100644
--- a/main.c
+++ b/main.c
@@ -3,6 +3,10 @@
3#include "tox_bootstrap.h" 3#include "tox_bootstrap.h"
4#include "log.h" 4#include "log.h"
5 5
6#ifdef __MACH__
7 #include "mach.h"
8#endif
9
6static struct Tox_Options tox_options; 10static struct Tox_Options tox_options;
7Tox *tox; 11Tox *tox;
8int client_socket = 0; 12int client_socket = 0;
@@ -1108,7 +1112,7 @@ int main(int argc, char *argv[])
1108 do_daemonize(); 1112 do_daemonize();
1109 } 1113 }
1110 1114
1111 on_exit(cleanup, NULL); 1115 atexit(cleanup);
1112 1116
1113 print_version(); 1117 print_version();
1114 1118