# -*- coding: utf-8; mode: tcl; tab-width: 8; truncate-lines: t; indent-tabs-mode: nil; c-basic-offset: 4
# $Id: Portfile 86205 2011-10-21 15:58:56Z krischik@macports.org $
# vim: set fileencoding=utf-8 tabstop=8 shiftwidth=4 softtabstop=4 noexpandtab filetype=tcl :

PortSystem 1.0

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

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

checksums           ${prog}						\
                    md5     812887018435382de8486f3bb26a5db4		\
                    sha1    51a21a1045a69def46561bbf6759d67369362d90	\
                    rmd160  d71f04888fb3f82b2bb86ed8e0f0983ccf41cc95	\
                    ${appbundles}					\
                    md5     297ca0750c6cea42dd238063d15ae374		\
                    sha1    4fb441d14c0a019ac1fe8428c1ddbafa8392c1d6	\
                    rmd160  6d6b3086a2499bd675489aa816dcbb1e6216a177

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}/add-ons;
	chmod -R g+w ${destroot}${prefix}/share/java/${distname}/platforms;
	chmod -R g-w ${destroot}${prefix}/share/java/${distname}/tools;
    "

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

