<?xml version="1.0" encoding="UTF-8"?>
<!--
	ANT
 
	Copyright 2012-2022 IS2T. All rights reserved.
	Modification and distribution is permitted under certain conditions.
	IS2T PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
-->
<project name="partialLink">
	
	<!-- 
		Partial link the file generated by the SOAR.
		
		Output property:
			- partialLink.output.file: partially linked file  
	-->


	<import file="partialLinkDefinition.xml"/>
	<import file="soar.xml"/>
	<import file="activity.xml"/>
	
	<target name="partialLink" depends="soar, activity/partialLink, partialLink/prepare, partialLink/do" description="Partial Link">
		<property name="partialLink.output.file" location="${partialLink.output.dir}/${partialLink.output.name}.o"/>
	</target>
	
	<!-- Target without dependencies that can be overridden -->
	<target name="partialLink/do">
		<!-- Use default presetdef -->
		<partialLink />
	</target>
	
	<target name="activity/partialLink">
		<start.subactivity
			activity.id="${linker.activity.id}"
			message="${linker.activity.msg}"
			parent.activity.id="${activity.root.id}"
		/>
	</target>
	
	<target name="partialLink/prepare" depends="partialLink/clean, partialLink/defaultProperties, partialLink/checkProperties">
		<!-- Add the generated SOAR file to the object files to link  -->
		<fail unless="soar.output.file" message="Please define the 'soar.output.file' property"/>
		
		<augment id="partialLink.objects.files">
			<fileset file="${soar.output.file}"/>
		</augment>
	</target>
	
	<target name="partialLink/defaultProperties">		
		<condition property="linker.verbose.level" value="2" else="0">
			<isset property="execution.verbose"/>
		</condition>
		<condition property="linker.noWarning" value="true" else="false">
			<not>
				<isset property="execution.verbose"/>
			</not>
		</condition>
		
		<fail unless="application.output.dir" message="Please define the 'application.output.dir' property"/>
		<property name="partialLink.output.dir" location="${application.output.dir}"/>
		<property name="partialLink.output.name" value="SOAR"/>
		<property name="partialLink.partial" value="true"/> <!-- Obvious :-) -->
		<property name="partialLink.hidePrivateSymbols" value="true"/>
		<property name="partialLink.hideSymbols" value="false"/>
	</target>
	
	<!-- Check that mandatory properties are set -->
	<target name="partialLink/checkProperties">		
		<fail unless="arch.link.target" message="Please define the 'arch.link.target' property"/>
		<fail unless="arch.endianness" message="Please define the 'arch.endianness' property"/>
		<fail unless="arch.symbol.prefix" message="Please define the 'arch.symbol.prefix' property "/>
		<fail unless="arch.convertToRela" message="Please define the 'arch.convertToRela' property"/>
	</target>
	
	<target name="partialLink/clean" depends="partialLink/defaultProperties">
		<delete failonerror="false">
			<fileset dir="${partialLink.output.dir}">
    			<include name="**/*${partialLink.output.name}*"/>
			</fileset>
		</delete>
	</target>
	
</project>
