<?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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <artifactId>junixsocket-native</artifactId>
  <packaging>nar</packaging>
  <parent>
    <groupId>com.kohlschutter.junixsocket</groupId>
    <artifactId>junixsocket-parent</artifactId>
    <version>2.4.0</version>
    <relativePath>../pom.xml</relativePath>
  </parent>
  <name>junixsocket-native</name>

  <description>The native JNI library</description>

  <properties>
    <kohlschutter.project.base.directory>${project.parent.basedir}</kohlschutter.project.base.directory>
    <nar.aolProperties>${project.build.outputDirectory}/aol.properties</nar.aolProperties>
    <!-- <nar.aolProperties>${project.basedir}/aol.properties</nar.aolProperties> -->

    <!-- IMPORTANT: junixsocket.native properties that end up in aol.properties:
      Use CDATA to prevent line breaks when formatting —
      line breaks will break nar-maven-plugin, and may not trigger an error
    -->
    <junixsocket.native.default.options><![CDATA[-Wall -Wextra -Wno-reserved-id-macro -Wno-undef -Wno-cast-qual -Wno-disabled-macro-expansion -Wno-language-extension-token -Wno-gnu-auto-type -Wno-c++11-extensions -Wno-c++98-compat -Wno-empty-translation-unit -Wno-gnu-empty-initializer -Werror-implicit-function-declaration -Wint-conversion -Wno-unused-command-line-argument -Werror-implicit-function-declaration -fno-strict-overflow -finline-functions -fwrapv -fno-c++-static-destructors -fPIC -fvisibility=hidden -fno-common -Os]]></junixsocket.native.default.options>
    <junixsocket.native.default.linker.options><![CDATA[ -shared ]]></junixsocket.native.default.linker.options>
    <junixsocket.native.default.c.options>${junixsocket.native.default.options}<![CDATA[ -std=gnu11]]></junixsocket.native.default.c.options>
    <junixsocket.native.default.cpp.options>${junixsocket.native.default.options}<![CDATA[ -std=gnu++17]]></junixsocket.native.default.cpp.options>
    <junixsocket.native.default.c.includes><![CDATA[**/*.c **/*.m]]></junixsocket.native.default.c.includes>
    <junixsocket.native.default.cpp.includes><![CDATA[**/*.cc **/*.cpp **/*.cxx **/*.mm]]></junixsocket.native.default.cpp.includes>
    <!-- NOTE: if some of these options above turn out to be non-portable,
      move them to the clang-specific property below -->
    <junixsocket.native.clang.c.options>${junixsocket.native.default.c.options}</junixsocket.native.clang.c.options>
    <junixsocket.native.clang.cpp.options>${junixsocket.native.default.cpp.options}</junixsocket.native.clang.cpp.options>

    <junixsocket.install.skip></junixsocket.install.skip>
  </properties>
  <profiles>
    <profile>
      <id>current-arch</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>com.github.maven-nar</groupId>
            <artifactId>nar-maven-plugin</artifactId>
            <configuration>
              <c>
                <toolPath>${junixsocket.native.default.toolPath}</toolPath>
              </c>
              <linker>
                <prefix>${junixsocket.native.default.toolPath}</prefix>
                <toolPath></toolPath>
                <name>${junixsocket.native.default.linkerName}</name>
              </linker>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>cross</id>
      <build>
        <plugins>
          <plugin>
            <groupId>com.github.maven-nar</groupId>
            <artifactId>nar-maven-plugin</artifactId>
            <version>3.6.0</version>
            <configuration>
              <aol>${junixsocket.native.aol.llvm}</aol>
              <c>
                <toolPath>${junixsocket.native.llvm.toolPath}</toolPath>
              </c>
              <linker>
                <prefix>${junixsocket.native.llvm.toolPath}/</prefix>
                <toolPath></toolPath>
                <name>clang</name>
              </linker>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>llvm</id>
      <build>
        <plugins>
          <plugin>
            <groupId>com.github.maven-nar</groupId>
            <artifactId>nar-maven-plugin</artifactId>
            <configuration>
              <aol>${junixsocket.native.aol.llvm}</aol>
              <c>
                <toolPath>${junixsocket.native.llvm.toolPath}</toolPath>
                <defines>
                  <!-- Add the following define to work-around an issue
                    on custom platforms that do not respect socket timeout -->
                  <!--
                    <define>junixsocket_use_poll</define>
                  -->
                </defines>
              </c>
              <linker>
                <prefix>${junixsocket.native.llvm.toolPath}/</prefix>
                <toolPath></toolPath>
                <name>clang</name>
              </linker>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>custom-build-directory</id>
      <activation>
        <property>
          <name>junixsocket.build.directory</name>
        </property>
      </activation>
      <build>
        <directory>${junixsocket.build.directory}</directory>
      </build>
    </profile>
  </profiles>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>prepare-aol</id>
            <phase>clean</phase>
            <goals>
              <goal>resources</goal>
            </goals>
            <configuration>
              <resources>
                <resource>
                  <directory>src/main/nar</directory>
                  <includes>
                    <include>aol.properties</include>
                  </includes>
                  <filtering>true</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>com.github.maven-nar</groupId>
        <artifactId>nar-maven-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
          <aol>${junixsocket.native.aol}</aol>
          <libraries>
            <library>
              <type>jni</type>
              <linkCPP>false</linkCPP>
            </library>
          </libraries>
          <java>
            <include>true</include>
          </java>
        </configuration>
        <executions>
          <execution>
            <!-- disabled to allow building with Java 10+ -->
            <id>default-nar-javah</id>
            <phase>none</phase>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>fix-jnilib</id>
            <phase>prepare-package</phase>
            <configuration>
              <!-- nar-maven-plugin may hardcode jnilib extension, but we
                need dylib -->
              <target>
                <move todir="${project.build.directory}/nar">
                  <fileset dir="${project.build.directory}/nar" />
                  <globmapper from="*.so"
                    to="*.${junixsocket.native.jnilib.extension}" />
                </move>
                <move todir="${project.build.directory}/nar">
                  <fileset dir="${project.build.directory}/nar" />
                  <globmapper from="*.jnilib"
                    to="*.${junixsocket.native.jnilib.extension}" />
                </move>
                <move todir="${project.build.directory}/nar">
                  <fileset dir="${project.build.directory}/nar" />
                  <globmapper
                    from="**/${junixsocket.native.jnilib.strip.prefix}*"
                    to="*" />
                </move>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-install-plugin</artifactId>
        <configuration>
          <skip>${junixsocket.install.skip}</skip>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
  </dependencies>
</project>
