From abf4aa4d807c561c66bd6c250184086734c05e52 Mon Sep 17 00:00:00 2001 From: Eric House Date: Fri, 30 Sep 2016 11:13:30 -0700 Subject: [PATCH] switch to clang add option, and invoke it, to build jni code with clang rather than gcc. --- xwords4/android/XWords4/jni/Android.mk | 9 +++++---- xwords4/android/XWords4/jni/anddict.c | 8 ++++---- xwords4/android/XWords4/jni/utilwrapper.c | 2 +- xwords4/android/scripts/common_targets.xml | 8 ++++---- xwords4/android/scripts/ndksetup.sh | 23 +++++++++++++++++++++- xwords4/common/board.c | 2 +- xwords4/common/board.h | 2 +- xwords4/common/engine.c | 3 +-- xwords4/common/mscore.c | 14 ++++++++----- xwords4/common/server.c | 6 +++--- xwords4/common/server.h | 3 +-- 11 files changed, 52 insertions(+), 28 deletions(-) diff --git a/xwords4/android/XWords4/jni/Android.mk b/xwords4/android/XWords4/jni/Android.mk index 910b6e29a..8ed0ede71 100644 --- a/xwords4/android/XWords4/jni/Android.mk +++ b/xwords4/android/XWords4/jni/Android.mk @@ -92,10 +92,11 @@ LOCAL_LDLIBS := -L${SYSROOT}/usr/lib -llog -lz include $(BUILD_SHARED_LIBRARY) -ifneq ($(shell which ccache),) - TARGET_CC = ccache $(TOOLCHAIN_PREFIX)gcc - TARGET_CXX = ccache $(TOOLCHAIN_PREFIX)g++ -endif +# This recipe doesn't work with clang. Fix if using gcc again +# ifneq ($(shell which ccache),) +# TARGET_CC = ccache $(TOOLCHAIN_PREFIX)gcc +# TARGET_CXX = ccache $(TOOLCHAIN_PREFIX)g++ +# endif COMMON_SRC_FILES := COMMON_PATH := diff --git a/xwords4/android/XWords4/jni/anddict.c b/xwords4/android/XWords4/jni/anddict.c index 5888b1e47..2f01d7e8a 100644 --- a/xwords4/android/XWords4/jni/anddict.c +++ b/xwords4/android/XWords4/jni/anddict.c @@ -104,13 +104,13 @@ andCountSpecials( AndDictionaryCtxt* ctxt ) static XP_Bool andMakeBitmap( AndDictionaryCtxt* ctxt, XP_U8 const** ptrp, - const XP_U8 const* end, XP_Bitmap* result ) + const XP_U8* end, XP_Bitmap* result ) { XP_Bool success = XP_TRUE; XP_U8 const* ptr = *ptrp; + jobject bitmap = NULL; CHECK_PTR( ptr, 1, end ); XP_U8 nCols = *ptr++; - jobject bitmap = NULL; if ( nCols > 0 ) { CHECK_PTR( ptr, 1, end ); XP_U8 nRows = *ptr++; @@ -157,7 +157,7 @@ andMakeBitmap( AndDictionaryCtxt* ctxt, XP_U8 const** ptrp, static XP_Bool andLoadSpecialData( AndDictionaryCtxt* ctxt, XP_U8 const** ptrp, - const XP_U8 const* end ) + const XP_U8* end ) { XP_Bool success = XP_TRUE; XP_U16 nSpecials = andCountSpecials( ctxt ); @@ -305,7 +305,7 @@ parseDict( AndDictionaryCtxt* ctxt, XP_U8 const* ptr, XP_U32 dictLength, { XP_Bool success = XP_TRUE; XP_ASSERT( !!ptr ); - const XP_U8 const* end = ptr + dictLength; + const XP_U8* end = ptr + dictLength; XP_U32 offset; XP_U16 nFaces, numFaceBytes = 0; XP_U16 flags; diff --git a/xwords4/android/XWords4/jni/utilwrapper.c b/xwords4/android/XWords4/jni/utilwrapper.c index e040dec79..3dc4c7be8 100644 --- a/xwords4/android/XWords4/jni/utilwrapper.c +++ b/xwords4/android/XWords4/jni/utilwrapper.c @@ -502,7 +502,7 @@ and_util_warnIllegalWord( XW_UtilCtxt* uc, BadWordInfo* bwi, #ifdef XWFEATURE_CHAT static void -and_util_showChat( XW_UtilCtxt* uc, const XP_UCHAR const* msg, XP_S16 from ) +and_util_showChat( XW_UtilCtxt* uc, const XP_UCHAR* msg, XP_S16 from ) { UTIL_CBK_HEADER( "showChat", "(Ljava/lang/String;ILjava/lang/String;)V" ); jstring jname = NULL; diff --git a/xwords4/android/scripts/common_targets.xml b/xwords4/android/scripts/common_targets.xml index e06f2367d..5a497dc4d 100644 --- a/xwords4/android/scripts/common_targets.xml +++ b/xwords4/android/scripts/common_targets.xml @@ -9,9 +9,9 @@ - - + @@ -23,8 +23,8 @@ - + failonerror="true" > + diff --git a/xwords4/android/scripts/ndksetup.sh b/xwords4/android/scripts/ndksetup.sh index 05d6ec201..3368d2bd6 100755 --- a/xwords4/android/scripts/ndksetup.sh +++ b/xwords4/android/scripts/ndksetup.sh @@ -2,13 +2,34 @@ set -u -e +USE_CLANG='' + APPMK=./jni/Application.mk TMP_MK=/tmp/tmp_$$_Application.mk XWORDS_DEBUG_ARMONLY=${XWORDS_DEBUG_ARMONLY:-""} XWORDS_DEBUG_X86ONLY=${XWORDS_DEBUG_X86ONLYx:-""} +usage() { + echo "usage $0 [--with-clang]" + exit 1 +} + +while [ $# -gt 0 ]; do + case $1 in + --with-clang) + USE_CLANG=1 + ;; + *) + usage "Unexpected param $1" + ;; + esac + shift +done + echo "# Generated by $0; do not edit!!!" > $TMP_MK +[ -n "$USE_CLANG" ] && echo "NDK_TOOLCHAIN_VERSION := clang" >> $TMP_MK + if [ -n "$XWORDS_DEBUG_ARMONLY" ]; then echo "APP_ABI := armeabi" >> $TMP_MK elif [ -n "$XWORDS_DEBUG_X86ONLY" ]; then @@ -24,7 +45,7 @@ fi if [ ! -f $APPMK ]; then cp $TMP_MK $APPMK -elif ! diff $APPMK $TMP_MK; then +elif ! diff -q $APPMK $TMP_MK >/dev/null; then cp $TMP_MK $APPMK fi rm -f $TMP_MK diff --git a/xwords4/common/board.c b/xwords4/common/board.c index 2b2161791..6422a7600 100644 --- a/xwords4/common/board.c +++ b/xwords4/common/board.c @@ -835,7 +835,7 @@ board_canHint( const BoardCtxt* board ) } void -board_sendChat( const BoardCtxt* board, const XP_UCHAR const* msg ) +board_sendChat( const BoardCtxt* board, const XP_UCHAR* msg ) { server_sendChat( board->server, msg, board->selPlayer ); } diff --git a/xwords4/common/board.h b/xwords4/common/board.h index ff1e600c2..7ffb6140e 100644 --- a/xwords4/common/board.h +++ b/xwords4/common/board.h @@ -133,7 +133,7 @@ XP_Bool board_canHideRack( const BoardCtxt* board ); XP_Bool board_canTrade( BoardCtxt* board ); XP_Bool board_canTogglePending( const BoardCtxt* board ); XP_Bool board_canHint( const BoardCtxt* board ); -void board_sendChat( const BoardCtxt* board, const XP_UCHAR const* msg ); +void board_sendChat( const BoardCtxt* board, const XP_UCHAR* msg ); /* zoomBy: >0: zoom in; < 0: zoom out; 0: query only */ XP_Bool board_zoom( BoardCtxt* board, XP_S16 zoomBy, XP_Bool* canInOut ); diff --git a/xwords4/common/engine.c b/xwords4/common/engine.c index 0d3ffbe44..b1595acac 100644 --- a/xwords4/common/engine.c +++ b/xwords4/common/engine.c @@ -514,9 +514,8 @@ engine_findMove( EngineCtxt* engine, const ModelCtxt* model, engine->searchHorizontal = XP_FALSE; } } /* forever */ - outer: - result = result; /* c++ wants a statement after the label */ } + outer: /* Search is finished. Choose (or just return) the best move found. */ if ( engine->returnNOW ) { result = XP_FALSE; diff --git a/xwords4/common/mscore.c b/xwords4/common/mscore.c index ea8a1af64..246ddad62 100644 --- a/xwords4/common/mscore.c +++ b/xwords4/common/mscore.c @@ -784,11 +784,15 @@ wordScoreFormatterAddTile( WordScoreFormatter* fmtr, Tile tile, } fullBufPtr = fmtr->fullBuf + fmtr->bufLen; - fmtr->bufLen += - XP_SNPRINTF( fullBufPtr, - (XP_U16)(sizeof(fmtr->fullBuf) - fmtr->bufLen), - (XP_UCHAR*)(tileMultiplier > 1?"%s(%dx%d)":"%s%d"), - prefix, tileScore, tileMultiplier ); + XP_U16 len = sizeof(fmtr->fullBuf) - fmtr->bufLen; + if ( tileMultiplier > 1 ) { + fmtr->bufLen += XP_SNPRINTF( fullBufPtr, len, + "%s(%dx%d)", prefix, tileScore, + tileMultiplier ); + } else { + fmtr->bufLen += XP_SNPRINTF( fullBufPtr, len, + "%s%d", prefix, tileScore ); + } XP_ASSERT( XP_STRLEN(fmtr->fullBuf) == fmtr->bufLen ); XP_ASSERT( fmtr->bufLen < sizeof(fmtr->fullBuf) ); diff --git a/xwords4/common/server.c b/xwords4/common/server.c index 0d134db3f..c69438c95 100644 --- a/xwords4/common/server.c +++ b/xwords4/common/server.c @@ -636,7 +636,7 @@ server_initClientConnection( ServerCtxt* server, XWStreamCtxt* stream ) #ifdef XWFEATURE_CHAT static void -sendChatTo( ServerCtxt* server, XP_U16 devIndex, const XP_UCHAR const* msg, +sendChatTo( ServerCtxt* server, XP_U16 devIndex, const XP_UCHAR* msg, XP_S8 from ) { if ( comms_canChat( server->vol.comms ) ) { @@ -652,7 +652,7 @@ sendChatTo( ServerCtxt* server, XP_U16 devIndex, const XP_UCHAR const* msg, static void sendChatToClientsExcept( ServerCtxt* server, XP_U16 skip, - const XP_UCHAR const* msg, XP_S8 from ) + const XP_UCHAR* msg, XP_S8 from ) { XP_U16 devIndex; for ( devIndex = 1; devIndex < server->nv.nDevices; ++devIndex ) { @@ -663,7 +663,7 @@ sendChatToClientsExcept( ServerCtxt* server, XP_U16 skip, } void -server_sendChat( ServerCtxt* server, const XP_UCHAR const* msg, XP_S16 from ) +server_sendChat( ServerCtxt* server, const XP_UCHAR* msg, XP_S16 from ) { if ( server->vol.gi->serverRole == SERVER_ISCLIENT ) { sendChatTo( server, SERVER_DEVICE, msg, from ); diff --git a/xwords4/common/server.h b/xwords4/common/server.h index e85a18c35..931dd9c8f 100644 --- a/xwords4/common/server.h +++ b/xwords4/common/server.h @@ -122,8 +122,7 @@ XP_Bool server_initClientConnection( ServerCtxt* server, XWStreamCtxt* stream ); #endif #ifdef XWFEATURE_CHAT -void server_sendChat( ServerCtxt* server, const XP_UCHAR const* msg, - XP_S16 from ); +void server_sendChat( ServerCtxt* server, const XP_UCHAR* msg, XP_S16 from ); #endif void server_formatDictCounts( ServerCtxt* server, XWStreamCtxt* stream,