<project name="buildHandlers" default="compileHandlers" basedir="..">

	<!--
	  Compile Handler
	  -->
	<target name="compileTestHandler" if="isHandler">
		<mkdir dir="${dir.test.generated}/${test.clientLang}/${test.name}/handlers/${handlerLibraryName}"/>
		<if>
			<not>
				<isset property="aix"/>
			</not>
			<then>
				<cc incremental="false"
				 outfile="${dir.test.generated}/${test.clientLang}/${test.name}/${handlerLibraryName}"
				 objdir="${dir.test.generated}/${test.clientLang}/${test.name}/handlers/${handlerLibraryName}" exceptions="true"
				 failonerror="false" outtype="shared" multithreaded="true">
					<compiler refid="VisualC++"/>
					<compiler refid="Linuxgcc"/>
					<compiler refid="SolarisCC"/>
					<compiler refid="HP-UXaC++"/>
                    <compiler extends="OS400icc"> 
 			            <compilerarg value="-g"/>
                    </compiler>
					<linker refid="VisualC++Linker"/>
					<linker refid="LinuxLinker"/>
					<linker refid="SolarisLinker"/>
					<linker refid="HP-UXLinker"/>
		            <linker extends="OS400Linker">
  		                <linkerarg location="end" value="${dir.lib}/lib${clientLibraryName}.so"/>
		            </linker>

					<includepath path="${dir.include}"/>
					<fileset dir="${handlerDir}">
						<include name="*.cpp"/>
					</fileset>
				</cc>
			</then>
			<else>
				<cc incremental="false"
				 outfile="${dir.test.generated}/${test.clientLang}/${test.name}/${libraryPrefix}${handlerLibraryName}${librarySuffix}"
				 objdir="${dir.test.generated}/${test.clientLang}/${test.name}/handlers/${handlerLibraryName}" exceptions="true"
				 failonerror="false" multithreaded="true">
					<compiler refid="AIXxlc"/>
					<linker refid="AIXLinker"/>
					<includepath path="${dir.include}"/>
					<fileset dir="${handlerDir}">
						<include name="*.cpp"/>
					</fileset>
				</cc>
			</else>
		</if>
	</target>

	<target name="setHandlerLibraryName">
		<basename file="${handlerDir}" property="handlerLibraryName"/>
		<condition property="isHandler">
			<not>
				<equals arg1="${handlerLibraryName}" arg2="${test.handler.directory}"/>
			</not>
		</condition>
	</target>

	<target name="checkIfDebugName" if="debug">
		<if>
			<and>
				<isset property="windows"/>
				<equals arg1="${debug}" arg2="true" casesensitive="false"/>
			</and>
			<then>
				<property name="handlerLibraryName_D" value="${handlerLibraryName}_D"/>
				<propertycopy property="handlerLibraryName" from="handlerLibraryName_D" override="true"/>
			</then>
		</if>
	</target>

	<!--
	  Builds a test handler
	  -->
	<target name="buildTestHandler" depends="setHandlerLibraryName, checkIfDebugName, compileTestHandler, validateHandlerCompilation, insertEntriesInWSDDFile"/>

	<!--
	  Locate all Handlers needing to be build for this client
	  -->
	<target name="compileTestHandlers" if="HandlersPresent" unless="runOnly">
		<path id="serviceHandlers">
			<dirset dir="${dir.autotests}/handlers/${test.handler.directory}"/>
		</path>


		<foreach target="buildTestHandler" param="handlerDir" inheritall="true">
			<path refid="serviceHandlers"/>
			<param name="test.name" value="${test.name}"/>
			<param name="client.wsdd" value="${client.wsdd}"/>
		</foreach>
	</target>

	<!--
	  Compile Handlers
	  -->
	<target name="compileHandlers" depends="createStartOfWSDDFile, compileTestHandlers, createEndOfWSDDFile, updateConfigurationWithClientWSDDEntry"/>

	<!--
	  If this client has associated handlers, update configuration file with
	  an client.wsdd entry
	  -->
	<target name="updateConfigurationWithClientWSDDEntry" if="HandlersPresent" unless="runOnly">
		<echo file="${axiscpp.conf}" append="true"
		 message="ClientWSDDFilePath:${client.wsdd}"/>
	</target>

	<!--
	  Create start of WSDD File
	  -->
	<target name="createStartOfWSDDFile" if="HandlersPresent">
		<property name="client.wsdd" value="${dir.test.generated}/${test.clientLang}/${test.name}/client.wsdd"/>
		<copy file="${dir.autotests}/handlers/templ_head.wsdd" tofile="${client.wsdd}" overwrite="true"/>
		<replace file="${client.wsdd}" token="XXXX" value="${test.handler.service}"/>
	</target>

	<!--
	  Add handler entry into WSDD File
	  -->
	<target name="insertEntriesInWSDDFile" if="successfulHandlerCompilation">
		<concat destfile="${client.wsdd}" append="true">
			<filelist dir="${dir.autotests}/handlers" files="templ_lib.wsdd"/>
		</concat>
		<replace file="${client.wsdd}" token="DDDD" value="${dir.test.generated}/${test.clientLang}/${test.name}"/>
		<replace file="${client.wsdd}" token="LLLL" value="${handlerLibraryName}"/>
		<replace file="${client.wsdd}" token="PPP" value="${libraryPrefix}"/>
		<replace file="${client.wsdd}" token="SSS" value="${librarySuffix}"/>
	</target>

	<!--
	  Create end of WSDD file
	  -->
	<target name="createEndOfWSDDFile" if="HandlersPresent">
		<concat destfile="${client.wsdd}" append="true">
			<filelist dir="${dir.autotests}/handlers" files="templ_foot.wsdd"/>
		</concat>
	</target>

</project>

