editing android build.prop with a script - android

I'm trying to create a script to modify the build.prop file 'automatically'.
I want the script to check for entries I define and:
1. If they do not exist add them
2. If they do exist, check the value, and if it does not match what I've define modify it.
I have created a script.
It runs but outputs nothing, not changing the build.prop
I've attached the script. Is it correct?
#!/system/bin/sh
# Definitions
file=/system/build.prop
tmpf=/system.buildprop.bak
line_list="wifi.supplicant_scan_interval=120 ro.sf.lcd_density=480"
# Function to get args as needed for loop
getargs() {
par=$1
line=`echo $par |cut -d"=" -f1`
arg=`echo $par |cut -d"=" -f2`
}
# Loop to make all changes in line_list
for x in $line_lst; do
# Get all needed arguments
getargs $x
# Write this change to a tmp file to check on it
oldarg=`grep $line $file |cut -d"=" -f2`
sed "s/$line=.*/$line=${arg}/g" $file > $tmpf
# Check if the change was made
chknewarg=`grep $line $tmpf |cut -d"=" -f2`
if [ "$chknewarg" = "$arg" ]; then
cp $tmpf $file
if [ -f $tmpf ]; then
rm $tmpf
fi
echo "File edited"
else
if [ -f $tmpf ]; then
rm $tmpf
fi
echo "Expected $arg, got $chknewarg instead"
exit 1
fi
# If it doesn't exist at all append it to the file
chkexists=`grep -c $line $file`
if [ $chkexists -eq 0 ]; then
echo "$x" >> $file
fi
done
exit 0

I've done a bit more playing and fundamentally changes the script.
#/system/bin/sh
mount -o remount,rw /system
FILE=/system/build.prop
TMPFILE=$FILE.tmp
line1=wifi.supplicant_scan_interval
line2=ro.sf.lcd_density
line3=ro.media.enc.jpeg.quality
line1Arg=120
line2Arg=390
line3Arg=100
lineNum=
prop=$line1
arg=$line1Arg
if grep -Fq $prop $FILE ; then
lineNum=`sed -n "/${prop}/=" $FILE`
echo $lineNum
sed -i "${lineNum} c${prop}=${arg}" $FILE
else
echo "$prop does not exist in build.prop"
echo "appending to end of build.prop"
echo $prop=$arg >> $FILE
fi
prop=$line2
arg=$line2Arg
if grep -Fq $prop $FILE ; then
lineNum=`sed -n "/${prop}/=" $FILE`
echo $lineNum
sed -i "${lineNum} c${prop}=${arg}" $FILE
else
echo "$prop does not exist in build.prop"
echo "appending to end of build.prop"
echo $prop=$arg >> $FILE
fi
prop=$line3
arg=$line3Arg
if grep -Fq $prop $FILE ; then
lineNum=`sed -n "/${prop}/=" $FILE`
echo $lineNum
sed -i "${lineNum} c${prop}=${arg}" $FILE
else
echo "$prop does not exist in build.prop"
echo "appending to end of build.prop"
echo $prop=$arg >> $FILE
fi
mount -o remount,r /system
However I get a 'mount: invalid argument' error?
Also, how would a loop over the line and lineArg variables to compete the actions?

Related

valgrind for Android devices (Crystax). configure: error: C compiler cannot create executables

Using and adapting the script(https://gist.github.com/smits/27060b310546ca6f76568f24838118c3) I get and error " C compiler cannot create executables":
#!/usr/bin/env bash
#set -x
function extract()
{
if [ -f "$1" ] ; then
case "$1" in
*.tar.bz2) tar xvjf "$1" ;;
*.tar.gz) tar xvzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) unrar x "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xvf "$1" ;;
*.tbz2) tar xvjf "$1" ;;
*.tgz) tar xvzf "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*.7z) 7z x "$1" ;;
*) echo "$1 cannot be extracted via >extract<" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
VALGRIND_VERSION="3.15.0"
VALGRIND_EXTENSION=".tar.bz2"
VALGRIND_DIRECTORY="valgrind-${VALGRIND_VERSION}"
VALGRIND_TARBALL="valgrind-${VALGRIND_VERSION}${VALGRIND_EXTENSION}"
# Only download Valgrind tarball again if not already downloaded
if [[ ! -f "${VALGRIND_TARBALL}" ]]; then
wget -v -nc "https://sourceware.org/pub/valgrind/${VALGRIND_TARBALL}"
fi
# Only extract Valgrind tarball again if not already extracted
if [[ ! -d "$VALGRIND_DIRECTORY" ]]; then
extract "$VALGRIND_TARBALL"
fi
# Ensure ANDROID_NDK is set
#if [[ ! -z "$ANDROID_NDK" ]]; then
export ANDROID_NDK="/home/userhome/src/crystax-ndk-10.3.1"
#fi
# Ensure ANDOID_SDK_HOME is set
#if [[ ! -z "$ANDROID_SDK" ]]; then
#export ANDROID_SDK="/opt/android-sdk-linux/"
#fi
if [[ ! -d "$VALGRIND_DIRECTORY" ]];
then
echo "Problem with extracting Valgrind from $VALGRIND_TARBALL into $VALGRIND_DIRECTORY!!!"
exit -1
fi
# Move to extracted directory
cd "$VALGRIND_DIRECTORY"
# ARM Toolchain
export PATH=$ANDROID_NDK/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin:$PATH
ARCH_ABI="arm-linux-androideabi-6"
export AR="$ANDROID_NDK/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar"
export LD="$ANDROID_NDK/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld"
export CC="$ANDROID_NDK/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc"
export CXX="$ANDROID_NDK/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++"
export RANLIB="$ANDROID_NDK/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ranlib"
export AS="$ANDROID_NDK/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-as"
export CPP="$ANDROID_NDK/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-cpp"
echo $ANDROID_NDK
echo $AR
echo $LD
echo $CC
echo $CXX
[[ ! -d "$ANDROID_NDK" || ! -f "$AR" || ! -f "$LD" || ! -f "$CC" || ! -f "$CXX" ]] && echo "Make sure AR, LD, CC, CXX variables are defined correctly. Ensure ANDROID_NDK is defined also" && exit -1
# Configure build
export HWKIND="generic"
ANDROID_PLATFORM=android-21
export CPPFLAGS="--sysroot=$ANDROID_NDK/platforms/${ANDROID_PLATFORM}/arch-arm -DANDROID_HARDWARE_$HWKIND"
export CFLAGS="--sysroot=$ANDROID_NDK/platforms/${ANDROID_PLATFORM}/arch-arm"
# BUG: For some reason file command is unable to detect if the file does not exist with ! -f , it says it doesn't exist even when it does!!!
BUILD=true
if [[ "${VALGRIND_DIRECTORY}/Inst/data/local/Inst/bin/valgrind" = *"No such file or directory"* ]]; then
BUILD=true
fi
if [[ "$BUILD" = true ]];
then
./configure --prefix="/data/local/Inst" \
--host="armv7-unknown-linux" \
--target="armv7-unknown-linux" \
--with-tmpdir="/sdcard"
[[ $? -ne 0 ]] && echo "Can't configure!" && exit -1
# Determine the number of jobs (commands) to be run simultaneously by GNU Make
NO_CPU_CORES=$(grep -c ^processor /proc/cpuinfo)
if [ $NO_CPU_CORES -le 8 ]; then
JOBS=$(($NO_CPU_CORES+1))
else
JOBS=${NO_CPU_CORES}
fi
# Compile Valgrind
make -j "${JOBS}"
[[ $? -ne 0 ]] && echo "Can't compile!" && exit -1
# Install Valgrind locally
make -j "${JOBS}" install DESTDIR="$(pwd)/Inst"
[[ $? -ne 0 ]] && echo "Can't install!" && exit -1
fi
# Push local Valgrind installtion to the phone
if [[ $(adb shell ls -ld /data/local/Inst/bin/valgrind) = *"No such file or directory"* ]];
then
adb root
adb remount
adb shell "[ ! -d /data/local/Inst ] && mkdir /data/local/Inst"
adb push Inst /
adb shell "ls -l /data/local/Inst"
# Ensure Valgrind on the phone is running
adb shell "/data/local/Inst/bin/valgrind --version"
# Add Valgrind executable to PATH (this might fail)
adb shell "export PATH=$PATH:/data/local/Inst/bin/"
fi
I got the following error ( C compiler cannot create executables):
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for armv7-unknown-linux-strip... no
checking for strip... strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking whether ln -s works... yes
checking for armv7-unknown-linux-gcc... /home/rubvacalz/src/crystax-ndk-10.3.1/toolchains/arm-linux-androideabi-6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
checking whether the C compiler works... no
configure: error: in `/home/rubvacalz/src/valgrind-3.15.0':
configure: error: C compiler cannot create executables
See `config.log' for more details
Can't configure!
And config.log says "error: cannot find -lcrystax":
configure:3723: checking whether the C compiler works
configure:3745: /home/rubvacalz/src/crystax-ndk-10.3.1/toolchains/arm-linux-androideabi-6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc --sysroot=/home/rubvacalz/src/crystax-ndk-10.3.1/platforms/android-21/arch-arm --sysroot=/home/rubvacalz/src/crystax-ndk-10.3.1/platforms/android-21/arch-arm -DANDROID_HARDWARE_yellowstone conftest.c >&5
/home/rubvacalz/src/crystax-ndk-10.3.1/toolchains/arm-linux-androideabi-6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/6.1/../../../../arm-linux-androideabi/bin/ld: **error: cannot find -lcrystax**
collect2: error: ld returned 1 exit status
configure:3749: $? = 1
configure:3787: result: no
configure: failed program was:
I don't know if the following includes are required and I don't know if it is included in the script process.
-I/home/userhome/src/crystax-ndk-10.3.1/sources/crystax/include -I/home/userhome/src/crystax-ndk-10.3.1/platforms/android-21/arch-arm/usr/include -I/home/userhome/src/crystax-ndk-10.3.1/sources/cxx-stl/gnu-libstdc++/6/include -I/home/userhome/src/crystax-ndk-10.3.1/sources/cxx-stl/gnu-libstdc++/6/libs/armeabi-v7a/include -I/home/userhome/src/crystax-ndk-10.3.1/sources/cxx-stl/gnu-libstdc++/6/include/backward
I fix the problem. It just add in the script the lines:
export LDFLAGS="-L/home/userhome/src/crystax-ndk-10.3.1/sources/crystax/libs/armeabi-v7a/thumb"
export LIBS="-lcrystax"

Android NDK building tcpdump for different arch

Hi i am using this script but i can't find why the compiler cannot find the header libraries.
This is the script i'm using :
#!/bin/sh
SCRIPT_VERSION=1.0
BUILD_DIR=build
DEFAULT_TCPDUMP_VERSION=4.9.2
DEFAULT_LIBPCAP_VERSION=1.8.1
GIT_LIBPCAP="https://github.com/the-tcpdump-group/libpcap.git"
GIT_TCPDUMP="https://github.com/the-tcpdump-group/tcpdump.git"
BASE_URL="http://www.tcpdump.org/release"
ALL_ARCHS="arm arm64 mips mips64 x86 x86_64"
TOOLCHAINS="arm:arm-linux-androideabi-4.9:21
arm64:aarch64-linux-android-4.9:21
mips64:mips64el-linux-android-4.9:21
x86:x86-4.9:21
x86_64:x86_64-4.9:21"
ARCH_TRANSLATIONS="arm:arm-linux
arm64:aarch64-linux
mips:mipsel-linux
mips64:mips64el-linux
x86:x86
x86_64:x86_64"
BASE_CFLAGS="-O2 -fPIC -fPIE"
BASE_LDFLAGS=""
EXTRA_CFLAGS_arm="-march=armv7-a -mthumb -mfloat-abi=softfp -mfpu=neon"
EXTRA_LDFLAGS_arm="-march=armv7-a -Wl,--fix-cortex-a8"
absolute_path() {
local ABS_PATH=$(cd "$1"; pwd)
echo $ABS_PATH
}
usage() {
PROGRAM=`basename $1`
echo "Usage: $PROGRAM [OPTIONS]"
echo "Version: ${SCRIPT_VERSION}"
echo "Automatically download and build tcpdump for Android devices"
echo "Also valid for Lollipop and Marshmallow"
echo ""
echo "OPTIONS:"
echo "-h Show this help"
echo "-a=ARCHS Space separated architectures to build or all. Default: all"
echo " Valid architectures: ${ALL_ARCHS}"
echo "-n=NDK_PATH Path of the Android NDK root"
echo " Default: Value of the NDK environment variable"
echo "-b=BUILD_DIR Destination of the compiled tcpdump. Default: build"
echo "-s Don't strip the final executable"
echo "-j=NPROCS Number of simultaneous jobs when compiling"
echo " Default: Number of cores of the machine"
echo "-t=TCPDUMP_VER Version of tcpdump or \"master\" for the latest revision in the repository"
echo " Default: ${DEFAULT_TCPDUMP_VERSION}"
echo "-l=LIBPCAP_VER Version of libpcap or \"master\" for the latest revision in the repository"
echo " Default: ${DEFAULT_LIBPCAP_VERSION}"
echo "-u=TCPDUMP_DIR Don't download tcpdump. Use the one in the specified directory"
echo "-m=LIBPCAP_DIR Don't download libpcap. Use the one in the specified directory"
echo
}
check_requirements() {
if [ ! -f "${NDK}/ndk-build" ]; then
echo "ERROR: Can't find the NDK directory"
exit 2
fi
flex -V > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR: flex not found"
exit 2
fi
bison -V > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR: bison not found"
exit 2
fi
if [ "${VERSION_LIBPCAP}" = "master" -o "${VERSION_TCPDUMP}" = "master" ]; then
git --version > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR: git not found"
exit 2
fi
fi
if [ "${VERSION_LIBPCAP}" != "master" -o "${VERSION_TCPDUMP}" != "master" ]; then
wget -V > /dev/null 2>&1
if [ $? -eq 0 ]; then
DOWNLOADER=wget
else
curl -V > /dev/null 2>&1
if [ $? -eq 0 ]; then
DOWNLOADER=curl
else
echo "ERROR: wget or curl not found"
exit 2
fi
fi
fi
}
download_file() {
local URL="$1"
if [ "${DOWNLOADER}" = "wget" ]; then
wget "${URL}"
elif [ "${DOWNLOADER}" = "curl" ]; then
curl -O "${URL}"
fi
if [ $? -ne 0 ]; then
echo "ERROR: Can't download ${URL}"
exit 3
fi
}
download() {
local PROGRAM="$1"
local VERSION="$2"
local GIT_URL="$3"
if [ "${VERSION}" = "master" ]; then
git clone "${GIT_URL}" "${PROGRAM}"
if [ $? -ne 0 ]; then
echo "ERROR: Can't download ${PROGRAM} repository from ${GIT_LIBPCAP}"
exit 3
fi
absolute_path "${PROGRAM}"
else
# Download and decompress from their web
DIR="${PROGRAM}-${VERSION}"
FILE="${DIR}.tar.gz"
download_file "${BASE_URL}/${FILE}"
tar xzf "${FILE}"
if [ $? -ne 0 ]; then
echo "ERROR: Can't extract ${FILE}"
exit 3
fi
absolute_path "${DIR}"
fi
}
check_archs() {
local IS_VALID=no
for arch in $1; do
IS_VALID=no
for valid_arch in ${ALL_ARCHS}; do
if [ "${valid_arch}" = "${arch}" ]; then
IS_VALID=yes
break
fi
done
if [ "${IS_VALID}" = "no" ]; then
echo "ERROR: The architecture ${arch} is not valid. Valid architectures are ${ALL_ARCHS}"
exit 3
fi
done
}
check_compiler_tools() {
local ARCH="$1"
local toolchain_dir=""
for toolchain_info in $TOOLCHAINS; do
t_arch="${toolchain_info%%:*}"
if [ "${t_arch}" = "${ARCH}" ]; then
toolchain_dir="${toolchain_info%:*}"
toolchain_dir="${toolchain_dir#*:}"
toolchain_platform=android-"${toolchain_info##*:}"
break
fi
done
if [ -z "${toolchain_dir}" ]; then
echo "ERROR: Can't find the toolchain directory for ${ARCH}"
exit 3
fi
local SYSROOT="${NDK}/platforms/${toolchain_platform}/arch-${ARCH}"
if [ ! -d "${SYSROOT}" ]; then
echo "ERROR: Can't find the platform directory ${toolchain_platform} for ${ARCH}"
exit 3
fi
CONFIG_ARCH=""
for arch_translation in $ARCH_TRANSLATIONS; do
t_arch="${arch_translation%%:*}"
if [ "${t_arch}" = "${ARCH}" ]; then
CONFIG_ARCH="${arch_translation##*:}"
break
fi
done
if [ -z "${CONFIG_ARCH}" ]; then
echo "ERROR: Can't determine the architecture for the \"configure\" script"
exit 3
fi
CC=""
COMPILERS=$(find "${NDK}/toolchains/${toolchain_dir}/prebuilt" -type f -name "*-gcc")
for compiler in $COMPILERS; do
printf "Testing ${compiler}... "
$compiler --version >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "OK"
CC="$compiler --sysroot=${SYSROOT}"
break
fi
echo "NOT VALID"
done
if [ -z "${CC}" ]; then
echo "ERROR: Can't find a valid compiler"
fi
RANLIB_TOOL=""
RANLIBS=$(find "${NDK}/toolchains/${toolchain_dir}/prebuilt" -type f -name "*-ranlib")
for ranlib in $RANLIBS; do
printf "Testing ${ranlib}... "
$ranlib --version >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "OK"
RANLIB_TOOL="${ranlib}"
break
fi
echo "NOT VALID"
done
if [ -z "${RANLIB_TOOL}" ]; then
echo "ERROR: Can't find a valid ranlib tool"
fi
if [ "${SHOULD_STRIP}" = "yes" ]; then
STRIP_TOOL=""
local STRIP_TOOLS=$(find "${NDK}/toolchains/${toolchain_dir}/prebuilt" -type f -name "*-strip")
for strip_tool in $STRIP_TOOLS; do
printf "Testing ${strip_tool}... "
$strip_tool --version >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "OK"
STRIP_TOOL="$strip_tool"
break
fi
echo "NOT VALID"
done
if [ -z "${STRIP_TOOL}" ]; then
echo "ERROR: Can't find a valid strip tool"
fi
fi
}
SHOULD_STRIP=yes
ARCHS="${ALL_ARCHS}"
TCPDUMP_VERSION="${DEFAULT_TCPDUMP_VERSION}"
LIBPCAP_VERSION="${DEFAULT_LIBPCAP_VERSION}"
NPROCS=`getconf _NPROCESSORS_ONLN`
DIR_LIBPCAP=""
DIR_TCPDUMP=""
while getopts "ha:n:b:sj:t:l:u:m:" arg; do
case "${arg}" in
a)
if [ "${OPTARG}" = "all" ]; then
ARCHS="${ALL_ARCHS}"
else
ARCHS="${OPTARG}"
check_archs "${ARCHS}"
fi
;;
t)
TCPDUMP_VERSION="${OPTARG}"
;;
l)
LIBPCAP_VERSION="${OPTARG}"
;;
n)
NDK="${OPTARG}"
;;
s)
SHOULD_STRIP=no
;;
b)
BUILD_DIR="${OPTARG}"
;;
j)
NPROCS="${OPTARG}"
;;
u)
DIR_TCPDUMP="${OPTARG}"
;;
m)
DIR_LIBPCAP="${OPTARG}"
;;
h)
usage $0
exit 0
;;
*)
usage $0
echo "ERROR: Invalid option"
exit 1
;;
esac
done
if [ ! -d "${BUILD_DIR}" ]; then
mkdir "${BUILD_DIR}" >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR: Can't create the directory ${BUILD_DIR}"
exit 3
fi
fi
BUILD_DIR=`absolute_path "${BUILD_DIR}"`
echo "Checking basic requirements..."
check_requirements
if [ -z "${DIR_LIBPCAP}" -o -z "${DIR_TCPDUMP}" ]; then
echo "Downloading source code..."
fi
if [ -z "${DIR_LIBPCAP}" ]; then
DIR_LIBPCAP=`download libpcap "${LIBPCAP_VERSION}" "${GIT_LIBPCAP}"`
fi
if [ -z "${DIR_TCPDUMP}" ]; then
DIR_TCPDUMP=`download tcpdump "${TCPDUMP_VERSION}" "${GIT_TCPDUMP}"`
fi
DIR_LIBPCAP=`absolute_path "${DIR_LIBPCAP}"`
DIR_TCPDUMP=`absolute_path "${DIR_TCPDUMP}"`
if [ ! -f "${DIR_LIBPCAP}/configure" ]; then
echo "ERROR: Can't find the \"configure\" libpcap script in ${DIR_LIBPCAP}"
exit 3
fi
if [ ! -f "${DIR_TCPDUMP}/configure" ]; then
echo "ERROR: Can't find the \"configure\" tcpdump script in ${DIR_TCPDUMP}"
exit 3
fi
GENERATED_FILES=""
for ARCH in ${ARCHS}; do
echo
echo "Checking compiler for ${ARCH}..."
check_compiler_tools "${ARCH}"
export CC
EXTRA_CFLAGS=$(eval echo \$EXTRA_CFLAGS_${ARCH})
export CFLAGS="${BASE_CFLAGS} ${EXTRA_CFLAGS}"
EXTRA_LDFLAGS=$(eval echo \$EXTRA_LDFLAGS_${ARCH})
export LDFLAGS="${BASE_LDFLAGS} ${EXTRA_LDFLAGS}"
echo "Compiling libpcap for ${ARCH}..."
cd "${DIR_LIBPCAP}"
CONFIGURE_COMMAND="./configure --host=${CONFIG_ARCH} --with-pcap=linux"
echo "${CONFIGURE_COMMAND}"
${CONFIGURE_COMMAND}
if [ $? -ne 0 ]; then
echo "ERROR: Failed configuring libpcap"
echo "CC = ${CC}"
echo "CFLAGS = ${CFLAGS}"
echo "LDFLAGS = ${LDFLAGS}"
exit 4
fi
make clean && make -j "${NPROCS}"
if [ $? -ne 0 ]; then
echo "ERROR: Failed compiling libpcap"
exit 4
fi
if [ ! -f libpcap.a ]; then
echo "ERROR: lipcap.a not generated"
exit 4
fi
${RANLIB_TOOL} libpcap.a
if [ $? -ne 0 ]; then
echo "ERROR: Failed executing ${RANLIB_TOOL} on libpcap.a"
exit 4
fi
echo "Compiling tcpdump for ${ARCH}..."
cd "${DIR_TCPDUMP}"
export CFLAGS="${CFLAGS} -I${DIR_LIBPCAP} -L${DIR_LIBPCAP}"
export LDFLAGS="${LDFLAGS} -pie"
CONFIGURE_COMMAND="./configure --host=${CONFIG_ARCH}"
echo "${CONFIGURE_COMMAND}"
${CONFIGURE_COMMAND}
echo "CC = $CC"
echo "CFLAGS = $CFLAGS"
echo "LDFLAGS = $LDFLAGS"
if [ $? -ne 0 ]; then
echo "ERROR: Failed configuring tcpdump"
exit 4
fi
make clean && make -j "${NPROCS}"
if [ $? -ne 0 ]; then
echo "ERROR: Failed compiling tcpdump"
exit 4
fi
mkdir "${BUILD_DIR}/${TCPDUMP_VERSION}" 2>/dev/null
mkdir "${BUILD_DIR}/${TCPDUMP_VERSION}/${ARCH}" 2>/dev/null
if [ -n "${STRIP_TOOL}" ]; then
echo "Stripping tcpdump..."
"${STRIP_TOOL}" tcpdump
fi
mv tcpdump "${BUILD_DIR}/${TCPDUMP_VERSION}/${ARCH}/tcpdump"
if [ $? -ne 0 ]; then
echo "ERROR: Can't move tcpdump to ${BUILD_DIR}/${TCPDUMP_VERSION}/${ARCH}/tcpdump"
exit 5
fi
echo "Created ${BUILD_DIR}/${TCPDUMP_VERSION}/${ARCH}/tcpdump"
GENERATED_FILES="${GENERATED_FILES} ${BUILD_DIR}/${TCPDUMP_VERSION}/${ARCH}/tcpdump"
done
if [ -n "${GENERATED_FILES}" ]; then
echo
echo "Generated files:"
for file in ${GENERATED_FILES}; do
echo $file
done
fi
I have tried changing the sysroot to :
local SYSROOT="${NDK}/sysroot"
But after that it says :
configure: error: C compiler cannot create executables
The configure error is :
ERROR: Failed configuring libpcap
CC = /home/ndk-r17b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc --sysroot=/home/ndk-r17b/platforms/android-21/arch-arm
CFLAGS = -O2 -fPIC -fPIE -march=armv7-a -mthumb -mfloat-abi=softfp -mfpu=neon
LDFLAGS = -march=armv7-a -Wl,--fix-cortex-a8
Can anyone help with configuring this script i have tried some changes but nothing at end ...
Or maybe is there any simple way to compile tcpdump with the latest NDK , because i have searched a lot and everything i have found there was old script and tools
Thank you
How are you calling the NDK compilers?
First of all, the NDK structure has changed a couple of times, after they properly integrated into Android Studio, followed by the removal of legacy headers and gcc.
For these type of compilations you should start by creating a standalone version of the toolchain, using the scripts provided by the NDK as described here.
https://developer.android.com/ndk/guides/standalone_toolchain

Can not run android app with valgrind

I create project Hello JNI and write state to test leak such as:
int* requieData = malloc(sizeof(int)*100);
This is my script build_valgrind.sh
I can run ./configure but does not any valgrind log can show.
My build_valgrind.sh:
#!/usr/bin/env bash
#set -x
function extract()
{
if [ -f "$1" ] ; then
case "$1" in
*.tar.bz2) tar xvjf "$1" ;;
*.tar.gz) tar xvzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) unrar x "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xvf "$1" ;;
*.tbz2) tar xvjf "$1" ;;
*.tgz) tar xvzf "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*.7z) 7z x "$1" ;;
*) echo "$1 cannot be extracted via >extract<" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
RUN_HELLO_JNI_THROUGH_VALGRIND=true
VALGRIND_VERSION="3.13.0"
VALGRIND_EXTENSION=".tar.bz2"
VALGRIND_DIRECTORY="valgrind-${VALGRIND_VERSION}"
VALGRIND_TARBALL="valgrind-${VALGRIND_VERSION}${VALGRIND_EXTENSION}"
# Only download Valgrind tarball again if not already downloaded
if [[ ! -f "${VALGRIND_TARBALL}" ]]; then
wget -v -nc "ftp://sourceware.org/pub/valgrind/${VALGRIND_TARBALL}"
fi
# Only extract Valgrind tarball again if not already extracted
if [[ ! -d "$VALGRIND_DIRECTORY" ]]; then
extract "$VALGRIND_TARBALL"
fi
echo "HOME: $HOME"
export ANDROID_NDK_HOME="$HOME/Android/Sdk/ndk-bundle"
# Ensure ANDROID_NDK_HOME is set
if [[ ! -z "$ANDROID_NDK_HOME" ]]; then
export ANDROID_NDK_HOME="$HOME/Android/Sdk/ndk-bundle"
fi
echo "NDK: $ANDROID_NDK_HOME"
# Ensure ANDOID_SDK_HOME is set
export ANDROID_SDK_HOME="$HOME/Android/Sdk/"
if [[ ! -z "$ANDROID_SDK_HOME" ]]; then
export ANDROID_SDK_HOME="$HOME/Android/Sdk/"
fi
echo "SDK: $ANDROID_SDK_HOME"
if [[ ! -d "$VALGRIND_DIRECTORY" ]];
then
echo "Problem with extracting Valgrind from $VALGRIND_TARBALL into $VALGRIND_DIRECTORY!!!"
exit -1
fi
echo "VALGRIND: $VALGRIND_DIRECTORY"
# Move to extracted directory
cd "$VALGRIND_DIRECTORY"
# ARM Toolchain
ARCH_ABI="arm-linux-androideabi-4.9"
export AR="$ANDROID_NDK_HOME/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar"
export LD="$ANDROID_NDK_HOME/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld"
export CC="$ANDROID_NDK_HOME/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc"
export CXX="$ANDROID_NDK_HOME/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++"
[[ ! -d "$ANDROID_NDK_HOME" || ! -f "$AR" || ! -f "$LD" || ! -f "$CC" || ! -f "$CXX" ]] && echo "Make sure AR, LD, CC, CXX variables are defined correctly. Ensure ANDROID_NDK_HOME is defined also" && exit -1
# Configure build
export HWKIND="lenovo"
ANDROID_PLATFORM=android-18
export CPPFLAGS="--sysroot=$ANDROID_NDK_HOME/platforms/${ANDROID_PLATFORM}/arch-arm -DANDROID_HARDWARE_$HWKIND"
export CFLAGS="--sysroot=$ANDROID_NDK_HOME/platforms/${ANDROID_PLATFORM}/arch-arm"
# BUG: For some reason file command is unable to detect if the file does not exist with ! -f , it says it doesn't exist even when it does!!!
echo "VALGRIND_DIRECTORY: $VALGRIND_DIRECTORY"
# ModeBuildTest
BUILD=true
if [[ "$BUILD" = true ]];
then
./configure --prefix="/data/local/Inst" \
--host="armv7-unknown-linux" \
--target="armv7-unknown-linux" \
--with-tmpdir="/sdcard"
[[ $? -ne 0 ]] && echo "Can't configure!" && exit -1
# Determine the number of jobs (commands) to be run simultaneously by GNU Make
NO_CPU_CORES=$(grep -c ^processor /proc/cpuinfo)
if [ $NO_CPU_CORES -le 8 ]; then
JOBS=$(($NO_CPU_CORES+1))
else
JOBS=${NO_CPU_CORES}
fi
# Compile Valgrind
make -j "${JOBS}"
[[ $? -ne 0 ]] && echo "Can't compile!" && exit -1
# Install Valgrind locally
make -j "${JOBS}" install DESTDIR="$(pwd)/Inst"
[[ $? -ne 0 ]] && echo "Can't install!" && exit -1
fi
# Push local Valgrind installtion to the phone
if [[ $(adb shell ls -ld /data/local/Inst/bin/valgrind) = *"No such file or directory"* ]];
then
adb root
adb remount
adb shell "[ ! -d /data/local/Inst ] && mkdir /data/local/Inst"
adb push Inst /
adb shell "ls -l /data/local/Inst"
# Ensure Valgrind on the phone is running
adb shell "/data/local/Inst/bin/valgrind --version"
# Add Valgrind executable to PATH (this might fail)
adb shell "export PATH=$PATH:/data/local/Inst/bin/"
echo "Push local Valgrind installtion"
fi
echo "Buil Valgrind end"
if [ $RUN_HELLO_JNI_THROUGH_VALGRIND = true ];
then
PACKAGE="com.example.hellojni"
# The location of the Hello JNI sample application
HELLO_JNI_PATH="$HOME/Documents/Project/HelloJNI"
# Workaround INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES error
adb uninstall "$PACKAGE"
cd $HELLO_JNI_PATH
./gradlew assembleArmDebug
./gradlew installArmDebug
# Build Hello JNI project in debug mode and install it on the device
echo "Finish Installation"
# Start HelloJNI app
#adb shell am start -a android.intent.action.MAIN -n $PACKAGE/.HelloJni
cd $HOME/Documents/Application/valgrindTool
# Make the script executable
chmod a+x bootstrap_valgrind.sh
# Run application through Valgrind on the phone
/usr/bin/env bash bootstrap_valgrind.sh
adb shell ls -lR "/sdcard/*grind*"
adb shell ls -lR "/storage/sdcard0/*grind*"
adb shell ls -lR "/storage/sdcard1/*grind*"
fi
echo "Call helloWord"
exit 0
And this is bootstrap_valgrind.sh
#!/usr/bin/env bash
PACKAGE="com.example.hellojni"
adb push start_valgrind.sh /data/local/
adb shell chmod 777 /data/local/start_valgrind.sh
adb root
adb shell setprop wrap.$PACKAGE "logwrapper /data/local/start_valgrind.sh"
echo "wrap.$PACKAGE: $(adb shell getprop wrap.$PACKAGE)"
adb shell am force-stop $PACKAGE
adb shell am start -a android.intent.action.MAIN -n $PACKAGE/.HelloJni
adb logcat -c
adb logcat
exit 0
This is start_valgrind.sh
# Define the package name
PACKAGE="com.example.hellojni"
# Memcheck tool: a memory error detector
VGPARAMS='-v --error-limit=no --log-file=/sdcard/hellojni.log.%p --leak-check=yes --leak-resolution=high --show-reachable=yes --undef-value-errors --read-var-info=yes'
# Massif tool: a heap profiler
# VGPARAMS='-v --error-limit=no --trace-children=yes --log-file=/sdcard/enzo_lync_profiles/enzo_lync_profile.log.%p --tool=massif --massif-out-file=/sdcard/enzo_lync_profiles/enzo_lync_profile.massif.out.%p'
# Callgrind tool: a cache and branch-prediction profiler
# VGPARAMS='-v --error-limit=no --trace-children=yes --log-file=/sdcard/enzo_lync_profiles/enzo_lync_profile.log.%p --tool=callgrind --callgrind-out-file=/sdcard/enzo_lync_profiles/enzo_lync_profile.callgrind.out.%p'
# Helgrind tool: a thread error detector
# VGPARAMS='-v --error-limit=no --trace-children=yes --log-file=/sdcard/enzo_lync_profiles/enzo_lync_profile.log.%p --tool=helgrind --helgrind-out-file=/sdcard/enzo_lync_profiles/enzo_lync_profile.helgrind.out.%p'
# DHAT: a dynamic heap analysis tool
# VGPARAMS='-v --error-limit=no --trace-children=yes --log-file=/sdcard/enzo_lync_profiles/enzo_lync_profile.log.%p --tool=exp-dhat --exp-dhat-out-file=/sdcard/enzo_lync_profiles/enzo_lync_profile.dhat.out.%p'
export TMPDIR=/data/local/Ints/
exec /data/local/Inst/bin/valgrind $VGPARAMS $*
My device armeabi-v7(show by android studio) but when I use this cript, device show:
Hello from JNI leak valgrind ! Compiled with ABI armeabi.
My question: Why output show armeabi? I think it is armeabi-v7.
And I can not see anylog about memory leak. What is wrong in the script?
Thank you so much.

Android NDK: WARNING: Ignoring unknown import directory: C

I'm working with cocos2dx 2.1.4 ndk-r8e.When I compile the
./build_native.sh I get the error as show I have tryed to solve the
solution provide by googling but didnt helped can any one plz point
out the problem below:
here is image
here is my build_native.sh file :
NDK_ROOT="C:\Users\Documents\Downloads\android-ndk-r8e-windows-x86_64\android-ndk-r8e"
APPNAME="hellowWorld"
# options
buildexternalsfromsource=
usage(){
cat << EOF
usage: $0 [options]
Build C/C++ code for $APPNAME using Android NDK
OPTIONS:
-s Build externals from source
-h this help
EOF
}
while getopts "sh" OPTION; do
case "$OPTION" in
s)
buildexternalsfromsource=1
;;
h)
usage
exit 0
;;
esac
done
# paths
if [ -z "${NDK_ROOT+aaa}" ];then
echo "please define NDK_ROOT"
exit 1
fi
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# ... use paths relative to current directory
COCOS2DX_ROOT="C:\Users\monika\AppData\Local\Temp\cocos2d-x-2.1.4\cocos2d-x-2.1.4"
APP_ROOT="C:\Users\monika\AppData\Local\Temp\cocos2d-x-2.1.4\cocos2d-x-2.1.4\monicahello"
APP_ANDROID_ROOT="C:\Users\monika\AppData\Local\Temp\cocos2d-x-2.1.4\cocos2d-x-2.1.4\monicahello\proj.android"
echo "NDK_ROOT = $NDK_ROOT"
echo "COCOS2DX_ROOT = $COCOS2DX_ROOT"
echo "APP_ROOT = $APP_ROOT"
echo "APP_ANDROID_ROOT = $APP_ANDROID_ROOT"
# make sure assets is exist
if [ -d "$APP_ANDROID_ROOT"/assets ]; then
rm -rf "$APP_ANDROID_ROOT"/assets
fi
mkdir "$APP_ANDROID_ROOT"/assets
# copy resources
for file in "$APP_ROOT"/Resources/*
do
if [ -d "$file" ]; then
cp -rf "$file" "$APP_ANDROID_ROOT"/assets
fi
if [ -f "$file" ]; then
cp "$file" "$APP_ANDROID_ROOT"/assets
fi
done
# copy icons (if they exist)
file="$APP_ANDROID_ROOT"/assets/Icon-72.png
if [ -f "$file" ]; then
cp "$file" "$APP_ANDROID_ROOT"/res/drawable-hdpi/icon.png
fi
file="$APP_ANDROID_ROOT"/assets/Icon-48.png
if [ -f "$file" ]; then
cp "$file" "$APP_ANDROID_ROOT"/res/drawable-mdpi/icon.png
fi
file="$APP_ANDROID_ROOT"/assets/Icon-32.png
if [ -f "$file" ]; then
cp "$file" "$APP_ANDROID_ROOT"/res/drawable-ldpi/icon.png
fi
if [[ "$buildexternalsfromsource" ]]; then
echo "Building external dependencies from source"
"$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \
"NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/source"
else
echo "Using prebuilt externals"
"$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \
"NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/prebuilt"
fi
I think the paths provided are wrong, if you are using windows then paths must be relative from cygwin, because they are with the forward slash (/) rather the backward () that is common in windows. So instead of adding path from C directory, go to cygwin and browse drives and go to the folder from there using cd command and at the directory of which you want path of type command pwd it will give you the exact path of that folder. Copy paste it here and done.

How do I pass a -fpermissive parameter to the compiler in a ./build_native.sh file?

Alright, please don't kill me.
I know this is a bad coding practice, but I'm just trying to grasp the fundamentals of an API, and there are only outdated tutorials about this, so where does it go in this file?
APPNAME="samplecocos2dxandroid"
NDK_ROOT="/Users/n/Documents/android-ndk-r8d"
# options
buildexternalsfromsource=
usage(){
cat << EOF
usage: $0 [options]
Build C/C++ code for $APPNAME using Android NDK
OPTIONS:
-s Build externals from source
-h this help
EOF
}
while getopts "sh" OPTION; do
case "$OPTION" in
s)
buildexternalsfromsource=1
;;
h)
usage
exit 0
;;
esac
done
# paths
if [ -z "${NDK_ROOT+aaa}" ];then
echo "please define NDK_ROOT"
exit 1
fi
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# ... use paths relative to current directory
COCOS2DX_ROOT="$DIR/../.."
APP_ROOT="$DIR/.."
APP_ANDROID_ROOT="$DIR"
echo "NDK_ROOT = $NDK_ROOT"
echo "COCOS2DX_ROOT = $COCOS2DX_ROOT"
echo "APP_ROOT = $APP_ROOT"
echo "APP_ANDROID_ROOT = $APP_ANDROID_ROOT"
# make sure assets is exist
if [ -d "$APP_ANDROID_ROOT"/assets ]; then
rm -rf "$APP_ANDROID_ROOT"/assets
fi
mkdir "$APP_ANDROID_ROOT"/assets
# copy resources
for file in "$APP_ROOT"/Resources/*
do
if [ -d "$file" ]; then
cp -rf "$file" "$APP_ANDROID_ROOT"/assets
fi
if [ -f "$file" ]; then
cp "$file" "$APP_ANDROID_ROOT"/assets
fi
done
# copy icons (if they exist)
file="$APP_ANDROID_ROOT"/assets/Icon-72.png
if [ -f "$file" ]; then
cp "$file" "$APP_ANDROID_ROOT"/res/drawable-hdpi/icon.png
fi
file="$APP_ANDROID_ROOT"/assets/Icon-48.png
if [ -f "$file" ]; then
cp "$file" "$APP_ANDROID_ROOT"/res/drawable-mdpi/icon.png
fi
file="$APP_ANDROID_ROOT"/assets/Icon-32.png
if [ -f "$file" ]; then
cp "$file" "$APP_ANDROID_ROOT"/res/drawable-ldpi/icon.png
fi
if [[ "$buildexternalsfromsource" ]]; then
echo "Building external dependencies from source"
"$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \
"NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/source"
else
echo "Using prebuilt externals"
"$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \
"NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/prebuilt"
fi
Tested this solution but failed, is this how it's suppose to be done?
In android-ndk-r8b/build/core/default-build-commands.mk:
TARGET_CC = $(TOOLCHAIN_PREFIX)gcc
TARGET_CFLAGS =
TARGET_CXX = $(TOOLCHAIN_PREFIX)g++
TARGET_CXXFLAGS = $(TARGET_CFLAGS) -fno-exceptions -fno-rtti -fpermissive
TARGET_LD = $(TOOLCHAIN_PREFIX)ld
TARGET_LDFLAGS :=
TARGET_AR = $(TOOLCHAIN_PREFIX)ar
TARGET_ARFLAGS := crs
TARGET_STRIP = $(TOOLCHAIN_PREFIX)strip
-fpermissive would go as one of the compiler flags, which this script (itself) does not do. It only packages the assets and such.
It would go into here: android-ndk-r8b/build/core/default-build-commands.mk
Keep in mind, that this change will affect all builds. Though, it sounds like that is what you want.

Categories

Resources