changeset 610:92f77b6d0d99

Utilities for enabling access to Android SDK.
author Oleksandr Gavenko <gavenkoa@gmail.com>
date Mon, 18 Jan 2016 01:06:17 +0200
parents 4e7490f809c8
children 256d506d8601
files android/.dir-locals.el android/Makefile android/my-android-activate android/my-android-symlink
diffstat 4 files changed, 161 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/android/.dir-locals.el	Mon Jan 18 01:06:17 2016 +0200
@@ -0,0 +1,5 @@
+;;; Directory Local Variables
+;;; For more information see (info "(emacs) Directory Variables")
+
+((sh-mode
+  (sh-basic-offset . 2)))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/android/Makefile	Mon Jan 18 01:06:17 2016 +0200
@@ -0,0 +1,54 @@
+SHELL = /bin/sh
+
+# Disable built in pattern rules.
+MAKEFLAGS += -r
+# Disable built in variables.
+MAKEFLAGS += -R
+# Disable built in suffix rules.
+.SUFFIXES:
+# Delete target file if command fails.
+.DELETE_ON_ERROR:
+# Default target.
+.DEFAULT_GOAL = all
+
+ifeq '' '$(prefix)'
+  ifneq '' '$(HOME)'
+    prefix = $(HOME)/usr
+  else
+    $(error HOME env var and prefix var are not set!)
+  endif
+endif
+
+bindir = $(prefix)/bin
+
+FILES = my-android-activate my-android-symlink
+
+.PHONY: all
+all:
+
+.PHONY: check
+check:
+
+.PHONY: install
+install:
+	[ -d $(bindir) ] || mkdir -p $(bindir)
+	for file in $(FILES); do \
+		filenoext=$${file%.sh}; \
+		filenoext=$${filenoext%.py}; \
+		install -m 755 $$file $(bindir)/$$filenoext; \
+	done
+
+.PHONY: uninstall
+uninstall:
+	for file in $(FILES); do \
+		filenoext=$${file%.sh}; \
+		filenoext=$${filenoext%.py}; \
+		[ -e $(bindir)/$$file ] && if rm $(bindir)/$$file; then :; else echo Unable to delete $(bindir)/$$file; exit 1; fi || :; \
+		[ -e $(bindir)/$$filenoext ] && if rm $(bindir)/$$filenoext; then :; else echo Unable to delete $(bindir)/$$filenoext; exit 1; fi || :; \
+	done
+
+.PHONY: distclean
+distclean: clean
+
+.PHONY: clean
+clean:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/android/my-android-activate	Mon Jan 18 01:06:17 2016 +0200
@@ -0,0 +1,45 @@
+#!/bin/bash
+
+root=
+for f in /opt/*/platform-tools/adb; do
+  if [[ -f $f ]]; then
+    root=${f%/platform-tools/adb}
+    break
+  fi
+done
+
+if [[ -z "$root" ]]; then
+  echo "Can't find /opt/*/sdk/platform-tools/adb like file..."
+  exit 1
+fi
+
+echo root: $root
+
+if [[ $PATH == *$root/platform-tools* ]]; then
+  echo SKIP: $root/platform-tools already in PATH
+else
+  PATH=$root/platform-tools:$PATH
+  echo add to PATH: $root/platform-tools
+fi
+if [[ $PATH == *$root/tools* ]]; then
+  echo SKIP: $root/tools already in PATH
+else
+  PATH=$root/tools:$PATH
+  echo add to PATH: $root/tools
+fi
+
+for f in $root/build-tools/*/aapt; do
+  if [[ -x $f ]]; then
+    bt=${f%/aapt}
+    if [[ $PATH == *$bt/* ]]; then
+      echo SKIP: $bt already in PATH
+    else
+      PATH=$bt:$PATH
+      echo add to PATH: $bt
+    fi
+    break
+  fi
+done
+
+export PATH
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/android/my-android-symlink	Mon Jan 18 01:06:17 2016 +0200
@@ -0,0 +1,57 @@
+#!/bin/bash
+
+LANG=C
+LC_ALL=C
+
+prefix=~/usr
+bindir=$prefix/bin
+
+sdk=
+# Find first available.
+for f in /opt/*/platform-tools/adb; do
+  if [[ -f $f ]]; then
+    sdk=${f%/platform-tools/adb}
+    break
+  fi
+done
+
+if [[ -z "$sdk" ]]; then
+  echo "Can't find Androidf SDK dir. I try search in /opt/*"
+  exit 1
+fi
+if [[ ! -d "$bindir" ]]; then
+  echo "$bindir does not exist*"
+  exit 1
+fi
+
+create_link() {
+  if [[ -f "$1" ]]; then
+    ln -s -f "$1" "$2"
+  else
+    echo "Can't find $1"
+    exit 1
+  fi
+}
+
+create_link $sdk/platform-tools/adb $bindir/adb
+create_link $sdk/platform-tools/fastboot $bindir/fastboot
+create_link $sdk/tools/android $bindir/android
+create_link $sdk/tools/ddms $bindir/ddms
+
+maxver=$(for d in $sdk/build-tools/*[0-9].[0-9]*; do
+  [[ -d $d ]] && echo ${d##*/}
+done | sort -t. -k 1,1nr -k 2,2nr -k 3,3nr | head -n 1)
+if [[ -z "$maxver" ]]; then
+  echo "You have no platform-tools in $sdk/platform-tools/"
+  exit 0
+fi
+btools=$sdk/build-tools/$maxver
+if [[ ! -d "$btools" ]]; then
+  echo "$btools isn't a directory"
+  exit 1
+fi
+
+create_link $btools/aapt $bindir/aapt
+create_link $btools/aapt $bindir/dexdump
+create_link $btools/aapt $bindir/dx
+