From 15ac4023f54b195a89a23f6c6cc05582b5e18e6b Mon Sep 17 00:00:00 2001
From: Steffen Vogel <post@steffenvogel.de>
Date: Wed, 26 Sep 2018 22:19:10 +0000
Subject: [PATCH] fixes for compiling VILLASnode on ARM

---
 CMakeLists.txt       | 6 ++++++
 include/villas/log.h | 4 ++--
 lib/CMakeLists.txt   | 6 +++++-
 lib/log.c            | 2 +-
 lib/memory.c         | 2 +-
 lib/queue.c          | 2 +-
 6 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 066137d4d..bd832c6e3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -62,6 +62,12 @@ else()
     add_compile_options(-Wall -Werror)
 endif()
 
+execute_process( 
+	COMMAND uname -m
+	COMMAND tr -d '\n'
+	OUTPUT_VARIABLE ARCH
+)
+
 # Check OS
 check_include_file("sys/eventfd.h" HAS_EVENTFD)
 check_include_file("semaphore.h" HAS_SEMAPHORE)
diff --git a/include/villas/log.h b/include/villas/log.h
index 36ce7aead..031c16d11 100644
--- a/include/villas/log.h
+++ b/include/villas/log.h
@@ -74,7 +74,7 @@ enum log_facilities {
 	LOG_WEBSOCKET =		(1L << 29),
 	LOG_OPAL =		(1L << 30),
 	LOG_COMEDI =		(1L << 31),
-	LOG_IB =		(1L << 32),
+	LOG_IB =		(1LL << 32),
 
 	/* Classes */
 	LOG_NODES =	LOG_NODE | LOG_SOCKET | LOG_FILE | LOG_FPGA | LOG_NGSI | LOG_WEBSOCKET | LOG_OPAL | LOG_IB,
@@ -148,7 +148,7 @@ void log_print(struct log *l, const char *lvl, const char *fmt, ...)
 void log_vprint(struct log *l, const char *lvl, const char *fmt, va_list va);
 
 /** Printf alike debug message with level. */
-void debug(long lvl, const char *fmt, ...)
+void debug(long long lvl, const char *fmt, ...)
 	__attribute__ ((format(printf, 2, 3)));
 
 /** Printf alike info message. */
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index b46be03ea..9015ef96d 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -73,9 +73,13 @@ set(LIB_SRC
     table.c
     bitset.c
     signal.c
-    tsc.c
 )
 
+
+if(ARCH STREQUAL "x86_64")
+	list(APPEND LIB_SRC tsc.c)
+endif()
+
 if(IBVERBS_FOUND AND RDMACM_FOUND)
     list(APPEND LIB_SRC memory/ib.c)
 endif()
diff --git a/lib/log.c b/lib/log.c
index 66627a129..d472db6c7 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -216,7 +216,7 @@ int log_set_facility_expression(struct log *l, const char *expression)
 {
 	bool negate;
 	char *copy, *token;
-	long mask = 0, facilities = 0;
+	long long mask = 0, facilities = 0;
 
 	copy = strdup(expression);
 	token = strtok(copy, ",");
diff --git a/lib/memory.c b/lib/memory.c
index 436527198..86a6c9c5a 100644
--- a/lib/memory.c
+++ b/lib/memory.c
@@ -85,7 +85,7 @@ int memory_init(int hugepages)
 	if (l.rlim_cur < lock) {
 		if (l.rlim_max < lock) {
 			if (getuid() != 0) {
-				warn("Failed to in increase ressource limit of locked memory from %zu to %zu bytes", l.rlim_cur, lock);
+				warn("Failed to in increase ressource limit of locked memory from %lu to %zu bytes", l.rlim_cur, lock);
 				warn("Please re-run as super-user or raise manually via:");
 				warn("   $ ulimit -Hl %zu", lock);
 
diff --git a/lib/queue.c b/lib/queue.c
index 0b020b192..3f69079c9 100644
--- a/lib/queue.c
+++ b/lib/queue.c
@@ -44,7 +44,7 @@ int queue_init(struct queue *q, size_t size, struct memory_type *m)
 	if (!IS_POW2(size)) {
 		size_t old_size = size;
 		size = LOG2_CEIL(size);
-		warn("A queue size was changed from %lu to %lu", old_size, size);
+		warn("A queue size was changed from %zu to %zu", old_size, size);
 	}
 
 	q->buffer_mask = size - 1;