<?xml version="1.0" encoding="UTF-8"?>
<!--
  ANT Buildfile
 
  Copyright 2013-2023 MicroEJ Corp. All rights reserved.
  MicroEJ Corp. PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
-->
<project name="kfInitMicroJvm-dd" xmlns:if="ant:if">
	<!-- This script enables the KF dynamic Feature loader for SOAR and Simulator -->
	
	<import file="${scripts.dir}/extension-init.xml" />
	
	<!-- By default if no option provided -->
	<property name="kf.dd.enabled" value="true"/>
	
	<target name="init/kf-dd">
		<condition property="kf.dd.soar.enabled" value="true" else="false">
			<and>
				<isset property="onBoard"/>
				<isTrue value="${kf.dd.enabled}"/>
			</and>
		</condition>
		
		<loadproperties srcfile="${scripts.dir}/core.properties"/>
		<fail unless="arch.symbol.prefix"/>
		<property name="com.microej.runtime.kf.link.symbol.prefix" value="${arch.symbol.prefix}"/>
		
		<!-- Select the dynamic loader for SOARv2 or Simulator -->
		<condition property="com.is2t.kf.dynamic.loader" value="com.is2t.kf.FoFeatureLoader" else="com.is2t.kf.DynamicFeatureLoader">
			<istrue value="${kf.dd.soar.enabled}"/>
		</condition>
	</target>
		
	<!-- Add dynamic download library in classpath if explicitly needed -->
	<target name="init/kf-dd/soar" extensionOf="init/execution" depends="init/kf-dd, init/kf-dd/embed">
	</target>
	
	<target name="init/kf-dd/embed" if="${kf.dd.enabled}" depends="init/kf-dd">
		<augment id="init.application.classpath">
			<!-- Use 'vm.dir' to select either MICROJVM or S3 dynamic loader library -->
			<fileset dir="${vm.dir}/javaLibs">
				<include name="kf-dd-*.jar"/>
			</fileset>
		</augment>
		<augment id="init.properties">
			<propertyRef name="com.is2t.kf.dynamic.loader"/>
		</augment>		
		<augment id="init.requires">
			<string value="${com.is2t.kf.dynamic.loader}"/>
		</augment>
		<property name="com.microej.runtime.kf.link.debug.enabled" value="false"/>
		
		<!-- Set a default value without a warning for "com.microej.runtime.kf.link.chunk.relocations.count" when running on S3 -->
		<property name="com.microej.runtime.kf.link.chunk.relocations.count" value="0" if:set="onS3"/>
		
		<!-- Set a default value without a warning for "com.microej.runtime.kf.link.transferbuffer.size" when running on S3 -->
		<property name="com.microej.runtime.kf.link.transferbuffer.size" value="0" if:set="onS3"/>

		<!-- Public options --> 
		<defineOption name="com.microej.runtime.kf.link.chunk.relocations.count" defaultValue="128">
			<deprecated name="com.microej.runtime.kf.link.chunk.relocations.nb"/>
		</defineOption>		
		<defineOption name="com.microej.runtime.kf.link.transferbuffer.size" defaultValue="512"/>
		
		<augment id="init.constants">
			<propertyref name="com.microej.runtime.kf.link.symbol.prefix"/>
			<propertyref name="com.microej.runtime.kf.link.debug.enabled"/>
			<propertyref name="com.microej.runtime.kf.link.chunk.relocations.count"/>
			<propertyref name="com.microej.runtime.kf.link.transferbuffer.size"/>
		</augment>
	</target>
</project>