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

PortSystem 1.0

name		    android
version		    9
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    75853
set appbundles	    ${name}-appbundles-r${patchversion}.tar.gz
set prog	    ${name}-sdk_r0${version}-mac_x86.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_r0${version}-mac_x86
worksrcdir	    ${name}-sdk-mac_x86
extract.only	    ${appbundles}

checksums           ${prog}						\
                    md5     ef3102fdbbbbd9bf4d9b572624aa9dc1		\
                    sha1    9cbf21249000f235580efb4fa549c91d4275d6d4	\
                    rmd160  48f4861e24da8ceeaac949d84ffd9e9bb15ca328	\
                    ${appbundles}					\
                    md5     d5d934e5698827ed3493bfbd74c99ce2		\
                    sha1    cb2a210a5425aaef04b4135ec09703541542c048	\
                    rmd160  dee6568b4bcfe46e7233f62f07e6716b2743da76

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

    file copy ${worksrcpath} ${destroot}${prefix}/share/java/

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

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

