From d46d8bd8d962712807ccd14a6f5e0932865e68d5 Mon Sep 17 00:00:00 2001
From: Pau Espin Pedrol <pespin@sysmocom.de>
Date: Sat, 20 Oct 2018 17:33:39 +0200
Subject: [PATCH] Fix build against new libosmocore

Built with: make -C target/firmware CROSS_COMPILE=arm-none-eabi-

Still failing at link time:
lib/libosmocore.a(msgb.o): In function `msgb_alloc':
git/libosmocore/src/msgb.c:82: undefined reference to `talloc_named_const'
lib/libosmocore.a(logging.o): In function `const_basename':
git/libosmocore/src/logging.c:317: undefined reference to `strrchr'
lib/libosmocore.a(logging.o): In function `assert_loginfo':
git/libosmocore/src/logging.c:177: undefined reference to `fprintf'
git/libosmocore/src/logging.c:181: undefined reference to `_impure_ptr'
lib/libosmocore.a(logging.o): In function `_output':
git/libosmocore/src/logging.c:359: undefined reference to `time'
git/libosmocore/src/logging.c:360: undefined reference to `ctime'
make: *** [Makefile.inc:135: board/compal_e88/hello_world.highram.elf] Error 1
make: Leaving directory 'git/osmocom-bb/src/target/firmware'

talloc_named_const is proobably still missing in libosmocore
pseudotalloc.

Change-Id: I3d38f1ce21c79fa7ed54c8651457d3faac59344a
---
 src/target/firmware/Makefile      | 9 +++++----
 src/target/firmware/Makefile.mtk  | 5 +++--
 src/target/firmware/comm/msgb.c   | 6 ++++--
 src/target/firmware/solve_envs.py | 2 +-
 4 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/target/firmware/Makefile b/src/target/firmware/Makefile
index 22fa7461..8b0d0cec 100644
--- a/src/target/firmware/Makefile
+++ b/src/target/firmware/Makefile
@@ -95,15 +95,16 @@ FLASH_OBJS=flash/cfi_flash.o
 ABB_OBJS=abb/twl3025.o
 RF_OBJS=rf/trf6151.o
 
+LIBOSMOCORE_PREFIX=/build/new/out
 # Objects that go in all applications
 ANY_APP_OBJS+=$(ABB_OBJS) $(RF_OBJS) $(FLASH_OBJS)
 ANY_APP_LIBS+=	calypso/libcalypso.a \
 		layer1/liblayer1.a \
 		lib/libmini.a \
 		comm/libcomm.a \
-		../../shared/libosmocore/build-target/src/.libs/libosmocore.a \
-		../../shared/libosmocore/build-target/src/gsm/.libs/libosmogsm.a \
-		../../shared/libosmocore/build-target/src/codec/.libs/libosmocodec.a
+		$(LIBOSMOCORE_PREFIX)/lib/libosmocore.a \
+		$(LIBOSMOCORE_PREFIX)/lib/libosmogsm.a \
+		$(LIBOSMOCORE_PREFIX)/lib/libosmocodec.a
 
 
 #
@@ -111,7 +112,7 @@ ANY_APP_LIBS+=	calypso/libcalypso.a \
 #
 
 # Global include path
-INCLUDES=-Iinclude/ -I../../../include -I../../shared/libosmocore/include -I../../shared/libosmocore/build-target/include
+INCLUDES=-Iinclude/ -I../../../include -I$(LIBOSMOCORE_PREFIX)/include
 
 # Libraries are defined in subdirectories
 -include calypso/Makefile
diff --git a/src/target/firmware/Makefile.mtk b/src/target/firmware/Makefile.mtk
index 927e31a0..23bb095e 100644
--- a/src/target/firmware/Makefile.mtk
+++ b/src/target/firmware/Makefile.mtk
@@ -15,8 +15,9 @@ mtk_COMMON_OBJS=board/mediatek/uart.o
 BOARD_mt62xx_OBJS=$(mtk_COMMON_OBJS) board/mt62xx/init.o
 BOARD_mt62xx_ENVIRONMENTS=mtkram
 
+LIBOSMOCORE_PREFIX=/build/new/out
 # Global include path
-INCLUDES=-Iinclude/ -I../../../include -I../../shared/libosmocore/include
+INCLUDES=-Iinclude/ -I../../../include -I$(LIBOSMOCORE_PREFIX)/include
 
 FLASH_OBJS=flash/cfi_flash.o
 
@@ -24,7 +25,7 @@ FLASH_OBJS=flash/cfi_flash.o
 ANY_APP_OBJS+=$(FLASH_OBJS)
 
 # Various objects that are currently linked into all applications
-ANY_APP_LIBS+=lib/libmini.a comm/libcomm.a ../../shared/libosmocore/build-target/src/.libs/libosmocore.a
+ANY_APP_LIBS+=lib/libmini.a comm/libcomm.a $(LIBOSMOCORE_PREFIX)/lib/libosmocore.a
 
 # Libraries are defined in subdirectories
 -include comm/Makefile
diff --git a/src/target/firmware/comm/msgb.c b/src/target/firmware/comm/msgb.c
index 3524ba58..43ced3fe 100644
--- a/src/target/firmware/comm/msgb.c
+++ b/src/target/firmware/comm/msgb.c
@@ -44,7 +44,7 @@ struct supermsg {
 	uint8_t buf[MSGB_DATA_SIZE];
 };
 static struct supermsg msgs[MSGB_NUM];
-void *_talloc_zero(void *ctx, unsigned int size, const char *name)
+void *_talloc_zero(const void *ctx, size_t size, const char *name)
 {
 	unsigned long flags;
 	unsigned int i;
@@ -70,10 +70,12 @@ panic:
 
 	return NULL; /* not reached */
 }
-void talloc_free(void *msg)
+
+int _talloc_free(void *msg, const char *location)
 {
 	struct supermsg *smsg = container_of(msg, struct supermsg, msg);
 	/* no locking required, since this is atomic */
 	smsg->allocated = 0;
+	return 0;
 }
 #endif
diff --git a/src/target/firmware/solve_envs.py b/src/target/firmware/solve_envs.py
index d6414d69..0e5f5e8c 100755
--- a/src/target/firmware/solve_envs.py
+++ b/src/target/firmware/solve_envs.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python2
 
 import sys
 
-- 
2.19.1
