# -*- coding: utf-8; mode: tcl; tab-width: 8; truncate-lines: t; indent-tabs-mode: nil; c-basic-offset: 4
# $Id: Portfile 125345 2014-09-14 03:19:01Z khindenburg@macports.org $
# vim: set fileencoding=utf-8 tabstop=8 shiftwidth=4 softtabstop=4 noexpandtab filetype=tcl :

PortSystem 1.0

name		    android
version		    23
categories	    java devel emulators
maintainers	    openmaintainer krischik
license		    Apache-2
platforms	    darwin
description	    Android SDK
long_description							\
    The Android SDK allows development for the Android mobile platform.
supported_archs	    noarch

set patchversion    121820
set appbundles	    ${name}-appbundles-r${patchversion}.tar.gz
set tools	    ${name}-tools-r${patchversion}.tar.gz
set prog	    ${name}-sdk_r${version}-macosx.zip

homepage	    http://developer.${name}.com/
master_sites	    http://dl.google.com/${name}:prog			\
		    macports:${name}:appbundles
distfiles	    ${prog}:prog					\
		    ${appbundles}:appbundles				\
		    ${tools}:appbundles
distname	    ${name}-sdk-macosx
worksrcdir	    ${name}-sdk-macosx
extract.only	    ${appbundles} ${tools}

checksums	    ${prog}						\
		    md5     fe64ec74a943572da9cfa4a90243461d		\
		    sha1    7119841e5fcadd8ef2b75c1fe419c4cbc9a97336	\
		    rmd160  801b01eb49c04ca43507b2c5f2f7baac598db50f	\
		    ${appbundles}					\
		    md5     d363cae627e4922da942a1c115965eca		\
		    sha1    54468931ffa347540d8627a0addb54c844e2c9de	\
		    rmd160  623f21017f6d04c2a425f9e691fa138ad5ad2b7a	\
		    ${tools}						\
		    md5     46e2caebec7ca9e25f97a924d09fb982		\
		    sha1    2c9c56246ed15ae82c90ff5da1f1a9c531b6189a	\
		    rmd160  2dfbe666c93d701dab56728ad4eeaff0654ce608

use_configure	    no
build.cmd	    true

destroot.keepdirs						\
    ${destroot}${prefix}/share/java/${worksrcdir}/add-ons	\
    ${destroot}${prefix}/share/java/${worksrcdir}/docs		\
    ${destroot}${prefix}/share/java/${worksrcdir}/platforms	\
    ${destroot}${prefix}/share/java/${worksrcdir}/samples	\
    ${destroot}${prefix}/share/java/${worksrcdir}/temp

post-extract {
	system "unzip -q ${distpath}/${prog} -d ${workpath}"
}

destroot {
    xinstall -m 755 -d ${destroot}${prefix}/share/java/${distname}

    # file copy can not copy with rename and directory tree.
    #
    system "cp -r ${worksrcpath}/. ${destroot}${prefix}/share/java/${distname}/."

    xinstall -m 770 -d ${destroot}${prefix}/share/java/${distname}/docs
    xinstall -m 770 -d ${destroot}${prefix}/share/java/${distname}/samples
    xinstall -m 770 -d ${destroot}${prefix}/share/java/${distname}/temp

    system "
	chgrp -R _developer ${destroot}${prefix}/share/java/${distname};
	chmod -R g+w ${destroot}${prefix}/share/java/${distname};
    "

    ui_info "####################################################################"
    ui_info "# add-ons, docs, platforms, samples and temp have been made	#"
    ui_info "# group _developer writable. You need to be member of the		#"
    ui_info "# _developer group to use the android tools. If you are not use:	#"
    ui_info "#									#"
    ui_info "# sudo dscl . append /Groups/_developer GroupMembership <username> #"
    ui_info "####################################################################"
    ui_info "# you need to download the actual SDKs. Because of the licence	#"
    ui_info "# querys this can not be done automaticaly. Use:			#"
    ui_info "#									#"
    ui_info "# @PREFIX@/share/java/android-sdk-macosx/tools/android update sdk	#"
    ui_info "####################################################################"
}

platform macosx {
    post-destroot {
	xinstall -m 755 -d ${destroot}${applications_dir}/Developer

	system "touch ${destroot}${applications_dir}/Developer/.localized"

	copy										\
	    ${workpath}/tools-r${patchversion}/zipalign					\
	    ${destroot}${prefix}/share/java/android-sdk-macosx/tools/zipalign

	foreach comp { Android-DDMS Android-Draw9Patch Android-Emulator Android-Hierarchyviewer Android-Manager Android-Monitor} {
	    copy										\
		${workpath}/appbundles-r${patchversion}/${comp}.app				\
		${destroot}${applications_dir}/Developer
	    reinplace s|@PREFIX@|${prefix}|g							\
		${destroot}${applications_dir}/Developer/${comp}.app/Contents/MacOS/Start.command
	}
    }
}
#
#    post-install {
#	system "( sleep 5 && while [ 1 ]; do sleep 1; echo y; done ) | }${prefix}/share/java/android-sdk-macosx/tools/android update sdk --no-ui"
#    }

livecheck.type      regex
livecheck.url       ${homepage}sdk/index.html
livecheck.regex     ${name}-sdk_r(\[0-9.\]+)-macosx.zip
