<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.deephacks.lmdb</groupId>
    <artifactId>lmdb-project</artifactId>
    <version>0.1.2</version>
  </parent>

  <artifactId>lmdb-win64</artifactId>
  <version>0.1.2</version>
  <packaging>jar</packaging>

  <name>${project.artifactId}</name>
  <description>lmdb</description>
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2.1</version>
        <executions>
          <execution>
            <id>build-native</id>
            <phase>compile</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>make</executable>
              <arguments>
                <!-- The stack options are necessary because we will try to link the object produced by this build with a non-GCC
                     linker (i.e. the MS one), and using the stack protection stuff generates a use of 1 symbol which is made
                     available by libgcc. Obviously this a non-started with the MS linker.

                     The -ffunction-sections option is needed for a differen treason. If you try to control the object layout with
                     mingw-w64 (I tried x86_64-4.9.0-posix-seh-rt_v3-rev2 and x86_64-4.9.1-win32-sjlj-rt_v3-rev0) then it seems to
                     produce an unordered .pdata section and then you'll get LNK1223 from the MS linker. I guess the GNU linker
                     doesn't care if the intermediate object files are badly formed? Using -ffunction-sections seems to work around
                     this, albeit possibly at the cost of throwing away Howard's clever-clever ESECT code placement hacks. -->
                <argument>XCFLAGS=-fno-stack-check -fno-stack-protector -mno-stack-arg-probe -ffunction-sections</argument>
              </arguments>
              <workingDirectory>${basedir}/../lmdb/src/main/native</workingDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
        <executions>
          <execution>
            <id>copy-resources</id>
            <phase>process-classes</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${basedir}/target/META-INF/native/${project.artifactId}</outputDirectory>
              <resources>
                <resource>
                  <directory>${basedir}/../lmdb/src/main/native</directory>
                  <filtering>false</filtering>
                  <includes>
                    <include>**/lmdb.h</include>
                    <include>**/liblmdb.a</include>
                    <include>**/liblmdb.so</include>
                    <include>**/mdb_stat</include>
                    <include>**/mdb_copy</include>
                    <include>**/COPYRIGHT</include>
                    <include>**/LICENSE</include>
                    <include>**/CHANGES</include>
                  </includes>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <classesDirectory>${basedir}/target</classesDirectory>
          <includes>
            <include>META-INF/**</include>
          </includes>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
