#!/system/bin/sh # # Script to init the environment for clang # # Usage: see below or execute the script with the parameter "--help" # # # History # 30.10.2024 v1.0.0 /bs # initial release # 11.11.2024 v1.0.1 /bs # the script now exports the variable TMP with /data/local/tmp if /tmp does not exist and TMP is not set # 25.12.2024 v1.0.2 /bs # added code to define the variable TMPDIR if not already set # 15.04.2025 v1.1.0 /bs # added support for a user defined init script # added functions for Logging and changing environment variables # default API version is now 31 # 04.06.2025 v1.2.0 /bs # if 'uname -m" returns "armv8*" the script sets CPU_TYPE now to aarch64 # the script now prints warning messages if the directories from the NDK are missing # __TRUE=0 __FALSE=1 USER_DEFINED_INIT_SCRIPT="/data/local/tmp/local_init_clang19_env" STANDALONE_SCRIPT=${__FALSE} CONTINUE=${__TRUE} PRINT_EXAMPLES=${__FALSE} # --------------------------------------------------------------------- # the variable TMPDIR is used by the /system/bin/sh to get the default directory for temporary files # export TMPDIR="${TMPDIR:=/data/local/tmp}" # --------------------------------------------------------------------- function LogMsg { echo "$*" } function LogWarning { [ $# -ne 0 ] && echo "WARNING: $*" >&2 || echo "" >&2 } function LogError { [ $# -ne 0 ] && echo "ERROR: $*" >&2 || echo "" >&2 } function LogInfo { if [ "${VERBOSE}"x != ""x ] ; then [ $# -ne 0 ] && echo "INFO: $*" >&2 || echo "" >&2 fi } function LogDebug { if [ "${DEBUG}"x != ""x ] ; then [ $# -ne 0 ] && echo "DEBUG: $*" >&2 || echo "" >&2 fi } # --------------------------------------------------------------------- # add_string - add a string to the value of an environment variable if it is not yet part of the value # # Usage: add_string {environment_variable} {new_string} [separator] [c|b|e] # # Default separator is a blank if there is at least one blank in the existing value. # In all other cases the default separator is the colon (:). # # The known values for the 4th parameter are: # c - check only: do NOT change valiue of the variable # b - add the new value before the existing value # e - add the new value after the existing value (this is the default) # function add_string { if [ "${DEBUG}"x != ""x ] ; then LogDebug "Executing \"$0 $*\" " set -x fi typeset ENV_VAR="" typeset NEW_VALUE="" typeset SEPARATOR="" typeset POSITION="e" typeset CUR_VALUE="" typeset THISRC=${__TRUE} if [ $# -ge 2 -a $# -le 4 ] ; then ENV_VAR="$1" NEW_VALUE="$2" eval CUR_VALUE="\"\$${ENV_VAR}\"" if [ $# -eq 4 ] ; then case $4 in c | check ) POSITION="" ;; e ) POSITION="e" ;; b ) POSITION="b" ;; * ) LogError "$0 - unknown value for the action parameter: \"$4\" " THISRC=${__FALSE} ;; esac fi if [ ${THISRC} = ${__TRUE} ] ; then if [ $# -eq 3 ] ; then SEPARATOR="$3" else echo "${CUR_VALUE}" | grep " " >/dev/null && SEPARATOR=" " || SEPARATOR=":" fi echo "${SEPARATOR}${CUR_VALUE}${SEPARATOR}" | grep -- "${SEPARATOR}${NEW_VALUE}${SEPARATOR}" >/dev/null if [ $? -ne 0 ] ; then case ${POSITION} in e ) eval export "${ENV_VAR}=\"\${CUR_VALUE}${SEPARATOR}${NEW_VALUE}\"" ;; b ) eval export "${ENV_VAR}=\"${NEW_VALUE}${SEPARATOR}\${CUR_VALUE}\"" ;; esac THISRC=${__TRUE} fi fi else LogError "$0 - wrong number of parameter: \"$*\" " THISRC=${__FALSE} fi return ${THISRC} } # --------------------------------------------------------------------- # for testing only # while false ; do printf ">> " read USER_INPUT set -x eval ${USER_INPUT} set +x done # --------------------------------------------------------------------- if [ ${CONTINUE} = ${__TRUE} ] ; then while [ $# -ne 0 ] ; do CUR_PARAMETER="$1" shift case ${CUR_PARAMETER} in -h | --help | help ) cat <