diff options
author | Dawid 'nCore' Opis <ncore@ncore.com.pl> | 2015-09-16 20:14:03 +0200 |
---|---|---|
committer | Dawid 'nCore' Opis <ncore@ncore.com.pl> | 2015-09-16 20:14:03 +0200 |
commit | 199787953243d91449ac5f4a5ac16edc2497e438 (patch) | |
tree | 697d87f921bc0fddd54ee3a27b3cb65c13e302cb | |
parent | 83790e5faf3de5ddb447e29ebe3490bdc30b1624 (diff) |
* fix: Possibility to compile on Mac OS platform
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | BUILD.md | 15 | ||||
-rw-r--r-- | Makefile.mac | 28 | ||||
-rw-r--r-- | client.c | 6 | ||||
-rw-r--r-- | mach.c | 20 | ||||
-rw-r--r-- | mach.h | 14 | ||||
-rw-r--r-- | main.c | 6 |
7 files changed, 91 insertions, 2 deletions
@@ -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 | ||
32 | tuntox | ||
33 | gitversion.h | ||
@@ -4,4 +4,17 @@ | |||
4 | * cd tuntox | 4 | * cd tuntox |
5 | * make | 5 | * make |
6 | 6 | ||
7 | The 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. | 7 | The makefile creates a static binary by default. If you're not a fan of static binaries, remove `-static` from `LDFLAGS`. |
8 | |||
9 | 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`). | ||
10 | |||
11 | Static linking breaks hostname resolution, but IMHO the pros overweight the cons. | ||
12 | |||
13 | ## MacOS build | ||
14 | Basically 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 | |||
19 | If 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 @@ | |||
1 | SOURCES = $(wildcard *.c) | ||
2 | DEPS=libtoxcore | ||
3 | CC=gcc | ||
4 | CFLAGS=-g #-std=c99 | ||
5 | CFLAGS += $(shell pkg-config --cflags $(DEPS)) | ||
6 | LDFLAGS=-g -lm | ||
7 | LDFLAGS += $(shell pkg-config --libs $(DEPS)) | ||
8 | OBJECTS=$(SOURCES:.c=.o) | ||
9 | INCLUDES = $(wildcard *.h) | ||
10 | |||
11 | all: cscope.out tuntox | ||
12 | |||
13 | gitversion.h: .git/HEAD .git/index | ||
14 | echo "#define GITVERSION \"$(shell git rev-parse HEAD)\"" > $@ | ||
15 | |||
16 | gitversion.c: gitversion.h | ||
17 | |||
18 | .c.o: $(INCLUDES) | ||
19 | $(CC) $(CFLAGS) $< -c -o $@ | ||
20 | |||
21 | tuntox: $(OBJECTS) $(INCLUDES) | ||
22 | $(CC) -o $@ $(OBJECTS) -ltoxcore $(LDFLAGS) /usr/local/lib/libsodium.a /usr/local/lib/libtoxcore.a | ||
23 | |||
24 | cscope.out: | ||
25 | cscope -bv ./*.[ch] | ||
26 | |||
27 | clean: | ||
28 | rm -rf *.o tuntox gitversion.h | ||
@@ -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" |
@@ -0,0 +1,20 @@ | |||
1 | #include "mach.h" | ||
2 | |||
3 | /* there is no clock_gettime on MacOS platform */ | ||
4 | int 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 | } | ||
@@ -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 | ||
@@ -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 | |||
6 | static struct Tox_Options tox_options; | 10 | static struct Tox_Options tox_options; |
7 | Tox *tox; | 11 | Tox *tox; |
8 | int client_socket = 0; | 12 | int 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 | ||