# -*- coding: utf-8; mode: tcl; tab-width: 8; truncate-lines: t; indent-tabs-mode: nil; c-basic-offset: 4
# $Id: Portfile 99828 2012-11-18 18:30:15Z krischik@macports.org $
# vim: set fileencoding=utf-8 tabstop=8 shiftwidth=4 softtabstop=4 noexpandtab filetype=tcl :

PortSystem 1.0

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

set patchversion    91270
set appbundles	    ${name}-appbundles-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
distname	    ${name}-sdk-macosx
worksrcdir	    ${name}-sdk-macosx
extract.only	    ${appbundles}

checksums           ${prog}						\
                    md5     67e46adca90dd18d7291443f6c15d6af \
                    sha1    0c29f5f5ab556ce4555682264d9c6414fc905c20 \
                    rmd160  ed76f904700c822b436d2443b6d44712ad0f3310 \
                    ${appbundles}					\
                    md5     408ea03d28968f0d55937920c7886aa0 \
                    sha1    da35b8f67f1e5bef1bf1e272e20c4e303ee42a27 \
                    rmd160  c51afc1d2d0ade1f018f6cac662f614fb1c0e23b

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 "####################################################################"
}

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

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

	foreach comp { Android-DDMS Android-Draw9Patch Android-Emulator Android-Hierarchyviewer Android-Manager } {
	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
	}
    }
}

