<?xml version="1.0" encoding="UTF-8"?>
<!--
	Ant
 
	Copyright 2024 MicroEJ Corp. All rights reserved.
	This library is provided in source code for use, modification and test, subject to license terms.
	Any modification of the source code will break MicroEJ Corp. warranties on the whole library.
-->

<project name="MicroEJGenerator" default="microej/platform">
	
	<target name="microej/environment">

		<fail unless="framework.dir" />
		<fail unless="platform.microej" />
		
		<property name="platform.archivepattern" value="${hardwarePartNumber}-${name}-${toolchain}" />
		<property name="platform.projectpattern" value="${hardwarePartNumber}-${name}-${toolchain}-${version}" />

		<property name="stylesheet.dir" location="${framework.dir}/stylesheets" />
		<property name="script.stylesheet" location="${stylesheet.dir}/script.xsl" />
		<property name="jpfproperties.stylesheet" location="${stylesheet.dir}/jpfProperties.xsl" />
		<property name="xpfproperties.stylesheet" location="${stylesheet.dir}/xpfProperties.xsl" />
		<property name="generateGroups.stylesheet" location="${stylesheet.dir}/groups.xsl" />
		<property name="generateGroup.stylesheet" location="${stylesheet.dir}/group.xsl" />
		<property name="withoutFragments.stylesheet" location="${stylesheet.dir}/withoutFragments.xsl" />
		<dirname file="${platform.microej}" property="platform.base.dir"/>
		<echo message="platform.base.dir=${platform.base.dir}" />
		<property name="architecture.output.dir" location="architecture" /> <!-- default -->
		<property name="veeport.output.dir" location="veeport" /> <!-- default -->
		<tempfile property="scripts.dir" prefix="microejscripts" deleteonexit="true" destdir="${java.io.tmpdir}" /> <!-- default -->
		<mkdir dir="${scripts.dir}" />
		<property name="main.script" location="${scripts.dir}/MicroEJFramework.xml" />
		<property name="generateGroups.script" location="${scripts.dir}/generateGroups.xml" />
	</target>
	
	<target name="microej/artifacts" depends="microej/environment">
		<property name="xpf.dir" location="${architecture.output.dir}" />
		<property name="xpf.path" location="${xpf.dir}" />
	</target>
		
	<target name="microej/scripts" depends="microej/environment" description="Generates the build scripts.">
		<copy todir="${scripts.dir}">
			<filelist dir="${framework.dir}/ant">
				<file name="MicroEJAPI.xml" />
				<file name="MicroEJArchitecture.xml" />
				<file name="MicroEJFramework.xml" />
			</filelist>
		</copy>
		<xslt style="${jpfproperties.stylesheet}" in="${platform.microej}" out="${scripts.dir}/jpf.properties" />
		<xslt style="${xpfproperties.stylesheet}" in="${platform.microej}" out="${scripts.dir}/xpf.properties" />
		<xslt style="${generateGroups.stylesheet}" in="${platform.microej}" out="${generateGroups.script}" />
		<xslt style="${withoutFragments.stylesheet}" in="${platform.microej}" out="${scripts.dir}/without.properties" />
		<ant antfile="${generateGroups.script}" />
	</target>
	
	<target name="microej/platformproject" depends="microej/environment, microej/artifacts, microej/scripts" description="Generates the platform project.">
		<ant antfile="${main.script}" target="platform/project" />
		<antcall target="microej/clean" />
	</target>
	
	<target name="microej/platform" depends="microej/environment, microej/artifacts, microej/scripts" description="Generates the platform.">
		<ant antfile="${main.script}" />
		<antcall target="microej/clean" />
	</target>
	
	<target name="microej/clean">
		<delete dir="${scripts.dir}" />
	</target>
	
	<macrodef name="eclipse.refreshLocal">
		<attribute name="resource"/>
		<sequential></sequential>
	</macrodef>
	<macrodef name="eclipse.incrementalBuild">
		<attribute name="project"/>
		<attribute name="kind"/>
		<sequential></sequential>
	</macrodef>
	
</project>