<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<!-- MAVEN ARTIFACT INFORMATION -->
	<artifactId>pi4j-native</artifactId>
	<name>Pi4J :: JNI Native Library</name>
	<description>Pi4J JNI Native Library</description>
	<packaging>pom</packaging>
	<parent>
		<groupId>com.pi4j</groupId>
		<artifactId>pi4j-parent</artifactId>
		<version>0.0.4</version>
	</parent>

	<!-- BUILD PROFILES -->
	<profiles>

		<!-- This profile is used to dynamically rebuild the native library .H 
			header files from the defined JNI jar classes. This profile should only be 
			used when changes have been made to the JNI Java wrapper classes and new 
			native method signatures are required. To use this profile, simply include 
			the "-generate-jni-headers" command argument with the maven build command. -->
		<profile>
			<id>generate-jni-headers</id>

			<!-- SPECIAL PROFILE DEPENDENCIES -->
			<dependencies>

				<!-- we define the pi4j Java project as a dependency so that the .H header 
					files can be generated based on the Java native wrapper classes -->
				<dependency>
					<groupId>com.pi4j</groupId>
					<artifactId>pi4j-core</artifactId>
					<version>${project.version}</version>
					<scope>compile</scope>
				</dependency>

			</dependencies>

			<!-- SPECIAL PROFILE BUILD INSTRUCTIONS -->
			<build>
				<plugins>

					<!-- Generate .h header files for JNI wrapper -->
					<plugin>
						<groupId>org.codehaus.mojo</groupId>
						<artifactId>native-maven-plugin</artifactId>
						<extensions>true</extensions>
						<executions>
							<execution>
								<id>javah-generate</id>
								<phase>generate-sources</phase>
								<goals>
									<goal>javah</goal>
								</goals>
								<configuration>

									<!-- trigger javah execution -->
									<javahClassNames>
										<javahClassName>com.pi4j.jni.I2C</javahClassName>
										<javahClassName>com.pi4j.jni.Serial</javahClassName>
										<javahClassName>com.pi4j.wiringpi.Gpio</javahClassName>
										<javahClassName>com.pi4j.wiringpi.GpioInterrupt</javahClassName>
										<javahClassName>com.pi4j.wiringpi.GpioUtil</javahClassName>
										<javahClassName>com.pi4j.wiringpi.Serial</javahClassName>
										<javahClassName>com.pi4j.wiringpi.Lcd</javahClassName>
										<javahClassName>com.pi4j.wiringpi.Shift</javahClassName>
										<javahClassName>com.pi4j.wiringpi.SoftPwm</javahClassName>
										<javahClassName>com.pi4j.wiringpi.Spi</javahClassName>
										<javahClassName>com.pi4j.wiringpi.Gertboard</javahClassName>
										<javahClassName>com.pi4j.wiringpi.Nes</javahClassName>
									</javahClassNames>

									<!-- enable additional javah interface in dependencies list -->
									<javahSearchJNIFromDependencies>true</javahSearchJNIFromDependencies>

									<!-- specify the output directory for generated header files -->
									<javahOutputDirectory>src/main/native</javahOutputDirectory>

								</configuration>
							</execution>
						</executions>
					</plugin>
				</plugins>
			</build>
		</profile>
		
		<profile>
			<id>soft-float</id>
			<activation>
			  <property>
			    <name>release-build</name>
			  </property>
			</activation>			
			<properties>
				<pi.build.soft-float>true</pi.build.soft-float>
			</properties>
			<build>
				<plugins>			
					<!-- ATTACH COMPILED NATIVE LIBRARY -->
					<plugin>
						<groupId>org.codehaus.mojo</groupId>
						<artifactId>build-helper-maven-plugin</artifactId>
						<executions>
							<execution>
								<id>attach-artifacts</id>
								<phase>package</phase>
								<goals>
									<goal>attach-artifact</goal>
								</goals>
								<configuration>
									<artifacts>
										<artifact>
											<file>${project.build.directory}/soft-float/libpi4j.so</file>
											<type>so</type>
											<classifier>soft-float</classifier>									
										</artifact>
									</artifacts>
								</configuration>
							</execution>
						</executions>
					</plugin>			
				</plugins>
			</build>			
		</profile>

		<profile>
			<id>hard-float</id>
			<activation>
			  <property>
			    <name>release-build</name>
			  </property>
			</activation>						
			<properties>
				<pi.build.hard-float>true</pi.build.hard-float>
			</properties>
			<build>
				<plugins>			
					<!-- ATTACH COMPILED NATIVE LIBRARY -->
					<plugin>
						<groupId>org.codehaus.mojo</groupId>
						<artifactId>build-helper-maven-plugin</artifactId>
						<executions>
							<execution>
								<id>attach-artifacts</id>
								<phase>package</phase>
								<goals>
									<goal>attach-artifact</goal>
								</goals>
								<configuration>
									<artifacts>
										<artifact>
											<file>${project.build.directory}/hard-float/libpi4j.so</file>
											<type>so</type>
											<classifier>hard-float</classifier>									
										</artifact>
									</artifacts>
								</configuration>
							</execution>
						</executions>
					</plugin>			
				</plugins>
			</build>			
		</profile>
				
	</profiles>


	<!-- BUILD INSTRUCTIONS -->
	<build>
		<finalName>libpi4j</finalName>

		<plugins>

			<!-- GENERATE LICENSE HEADERS IN SOURCE FILES -->
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>license-maven-plugin</artifactId>
			</plugin>

			<plugin>
				<artifactId>maven-antrun-plugin</artifactId>
				<executions>

					<!-- ensure that a target directory has been created platform -->
					<execution>
						<id>generate-sources</id>
						<phase>generate-sources</phase>
						<configuration>
							<tasks>
								<mkdir dir="target" />
								<mkdir dir="target/classes" />
								
								<taskdef resource="net/sf/antcontrib/antcontrib.properties"
								                  classpathref="maven.plugin.classpath" />
				                <if>
				                  <equals arg1="${pi.build.hard-float}" arg2="true" />
				                  <then>
								   <mkdir dir="target/hard-float" />
				                  </then>
				                </if>							
				                <if>
				                  <equals arg1="${pi.build.soft-float}" arg2="true" />
				                  <then>
								   <mkdir dir="target/soft-float" />
				                  </then>
				                </if>
							</tasks>
						</configuration>
						<goals>
							<goal>run</goal>
						</goals>
					</execution>

					<!-- copy the native source files and compile them with gcc on the RaspberyPi 
						platform -->
					<execution>
						<id>build-native-so</id>
						<phase>compile</phase>
						<goals>
							<goal>run</goal>
						</goals>
						<configuration>
							<tasks>
								<taskdef resource="net/sf/antcontrib/antcontrib.properties"
								                  classpathref="maven.plugin.classpath" />
				                <property name="compile_classpath" 
				                          refid="maven.compile.classpath"/>
				                <property name="project-build-directory"
				                          value="${project.build.directory}"/>		
				                <property name="pi-dirBuildTemp" value="${pi.dirBuildTemp}"/>
				                <if>
				                  <equals arg1="${pi.build.hard-float}" arg2="true" />
				                  <then>
								    <ant target="build-libpi4j.so" >
								    	<property name="pi-abi" value="hard-float"/>
						                <property name="pi-port" value="${pi.port.hard-float}"/>							
						                <property name="pi-host" value="${pi.host.hard-float}"/>							
						                <property name="pi-user" value="${pi.user.hard-float}"/>		
						                <property name="pi-password" value="${pi.password.hard-float}"/>
								    </ant>
				                  </then>
				                </if>							
				                <if>
				                  <equals arg1="${pi.build.soft-float}" arg2="true" />
				                  <then>
								    <ant target="build-libpi4j.so">
								    	<property name="pi-abi" value="soft-float"/> 
						                <property name="pi-port" value="${pi.port.soft-float}"/>							
						                <property name="pi-host" value="${pi.host.soft-float}"/>							
						                <property name="pi-user" value="${pi.user.soft-float}"/>		
						                <property name="pi-password" value="${pi.password.soft-float}"/>
								    </ant>
				                  </then>
				                </if>							
							</tasks>
						</configuration>
					</execution>
				</executions>
				<dependencies>
					<dependency>
						<groupId>org.apache.ant</groupId>
						<artifactId>ant-jsch</artifactId>
						<version>1.7.1</version>
					</dependency>
					<dependency>
						<groupId>com.jcraft</groupId>
						<artifactId>jsch</artifactId>
						<version>0.1.42</version>
					</dependency>
					<dependency>
						<groupId>ant-contrib</groupId>
						<artifactId>ant-contrib</artifactId>
						<version>20020829</version>
					</dependency>
				</dependencies>
			</plugin>

		</plugins>

		<pluginManagement>
			<plugins>
				<!--This plugin's configuration is used to store Eclipse m2e settings 
					only. It has no influence on the Maven build itself. -->
				<plugin>
					<groupId>org.eclipse.m2e</groupId>
					<artifactId>lifecycle-mapping</artifactId>
					<version>1.0.0</version>
					<configuration>
						<lifecycleMappingMetadata>
							<pluginExecutions>
								<pluginExecution>
									<pluginExecutionFilter>
										<groupId>
											org.codehaus.mojo
										</groupId>
										<artifactId>
											license-maven-plugin
										</artifactId>
										<versionRange>
											[1.3,)
										</versionRange>
										<goals>
											<goal>
												update-project-license
											</goal>
										</goals>
									</pluginExecutionFilter>
									<action>
										<ignore></ignore>
									</action>
								</pluginExecution>
							</pluginExecutions>
						</lifecycleMappingMetadata>
					</configuration>
				</plugin>
			</plugins>
		</pluginManagement>
	</build>
</project>