From 1fed9bf1b869d39a6d03c1c70011b233af9ef2ec Mon Sep 17 00:00:00 2001
From: Sven Gestegard Robertz <sven.robertz@cs.lth.se>
Date: Mon, 19 Jan 2015 16:55:21 +0100
Subject: [PATCH] hacks to make it mostly work on MacOS X

---
 examples/Makefile                                           | 6 ++++++
 examples/twoway/Makefile                                    | 3 ++-
 examples/twoway/client.c                                    | 5 +++++
 examples/twoway/server.c                                    | 5 +++++
 ..._compat_arm_cortexm3.h => labcomm_compat_arm_cortexm3.h} | 0
 .../2006/{labcomm2006_compat_osx.h => labcomm_compat_osx.h} | 0
 ...abcomm2006_compat_vxworks.h => labcomm_compat_vxworks.h} | 0
 lib/c/Makefile                                              | 6 ++++++
 lib/c/os_compat.mk                                          | 1 +
 test/Makefile                                               | 2 +-
 10 files changed, 26 insertions(+), 2 deletions(-)
 rename lib/c/2006/{labcomm2006_compat_arm_cortexm3.h => labcomm_compat_arm_cortexm3.h} (100%)
 rename lib/c/2006/{labcomm2006_compat_osx.h => labcomm_compat_osx.h} (100%)
 rename lib/c/2006/{labcomm2006_compat_vxworks.h => labcomm_compat_vxworks.h} (100%)

diff --git a/examples/Makefile b/examples/Makefile
index f52f10c..fc39c55 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -7,12 +7,18 @@ all:
 	echo More to be done...
 	$(MAKE) -C twoway all
 
+UNAME_S=$(shell uname -s)
+
 .PHONY: test
 test:
 	echo More to be done...
+ifeq ($(UNAME_S),Darwin)
+	$(MAKE) -C user_types all 
+else	
 	cd simple ; sh compile.sh && sh run.sh
 	$(MAKE) -C  wiki_example test
 	$(MAKE) -C user_types test 
+endif	
 	$(MAKE) -C duck_typing test
 	$(MAKE) -C twoway test 
 
diff --git a/examples/twoway/Makefile b/examples/twoway/Makefile
index 5a686f1..d4e5c7e 100644
--- a/examples/twoway/Makefile
+++ b/examples/twoway/Makefile
@@ -2,7 +2,8 @@ TARGETS=client server
 LABCOMM_JAR=../../compiler/labcomm_compiler.jar
 LABCOMM=java -jar $(LABCOMM_JAR) 
 
-CFLAGS=-O3 -g -Wall -Werror -I../../lib/c/2014 -I. -Wno-unused-function
+include ../../lib/c/os_compat.mk
+CFLAGS+=-I../../lib/c/2014 -I.
 
 all: $(TARGETS:%=gen/%)
 
diff --git a/examples/twoway/client.c b/examples/twoway/client.c
index be82e9a..0166a35 100644
--- a/examples/twoway/client.c
+++ b/examples/twoway/client.c
@@ -21,7 +21,12 @@
 
 #include <errno.h>
 #include <arpa/inet.h>
+#ifndef LABCOMM_OS_DARWIN
 #include <linux/tcp.h>
+#else
+#include <netinet/in.h>
+#include <netinet/tcp.h> 
+#endif
 #include <netdb.h>
 #include <pthread.h>
 #include <stdio.h>
diff --git a/examples/twoway/server.c b/examples/twoway/server.c
index 3a34efa..e6eaac0 100644
--- a/examples/twoway/server.c
+++ b/examples/twoway/server.c
@@ -20,7 +20,12 @@
 */
 
 #include <arpa/inet.h>
+#ifndef LABCOMM_OS_DARWIN
 #include <linux/tcp.h>
+#else
+#include <netinet/in.h>
+#include <netinet/tcp.h> 
+#endif
 #include <errno.h>
 #include <pthread.h>
 #include <stdlib.h>
diff --git a/lib/c/2006/labcomm2006_compat_arm_cortexm3.h b/lib/c/2006/labcomm_compat_arm_cortexm3.h
similarity index 100%
rename from lib/c/2006/labcomm2006_compat_arm_cortexm3.h
rename to lib/c/2006/labcomm_compat_arm_cortexm3.h
diff --git a/lib/c/2006/labcomm2006_compat_osx.h b/lib/c/2006/labcomm_compat_osx.h
similarity index 100%
rename from lib/c/2006/labcomm2006_compat_osx.h
rename to lib/c/2006/labcomm_compat_osx.h
diff --git a/lib/c/2006/labcomm2006_compat_vxworks.h b/lib/c/2006/labcomm_compat_vxworks.h
similarity index 100%
rename from lib/c/2006/labcomm2006_compat_vxworks.h
rename to lib/c/2006/labcomm_compat_vxworks.h
diff --git a/lib/c/Makefile b/lib/c/Makefile
index 6067a26..a85a91c 100644
--- a/lib/c/Makefile
+++ b/lib/c/Makefile
@@ -4,3 +4,9 @@ all:
 
 %: 
 	for v in $(VERSIONS) ; do $(MAKE) -C $${v} $@ || exit 1 ; done
+
+
+.PHONY: distclean
+distclean: 
+	rm *.o *.so *.so.1 *.a
+
diff --git a/lib/c/os_compat.mk b/lib/c/os_compat.mk
index 23366e3..23b66f2 100644
--- a/lib/c/os_compat.mk
+++ b/lib/c/os_compat.mk
@@ -14,6 +14,7 @@ else ifeq ($(UNAME_S),Darwin)
   LD=$(CROSS_COMPILE)ld
   CFLAGS=-g -Wall -Werror -O3  -I. -Itest \
 	 -DLABCOMM_COMPAT=\"labcomm_compat_osx.h\" \
+	 -DLABCOMM_OS_DARWIN=1\
 	 -Wno-tautological-compare -Wno-unused-function
   LDFLAGS=-L..
   LDLIBS=-llabcomm$(LIBVERSION)
diff --git a/test/Makefile b/test/Makefile
index 0293534..106810b 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -2,7 +2,7 @@ TESTS=basic simple nested ref
 LABCOMM_JAR=../compiler/labcomm_compiler.jar
 LABCOMM=java -jar $(LABCOMM_JAR)
 
-CFLAGS=-O3 -g -Wall -Werror -Wno-unused-function
+include ../lib/c/os_compat.mk
 
 all:
 
-- 
GitLab