<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ /* ******************************************************************************
  ~  *
  ~  *
  ~  * This program and the accompanying materials are made available under the
  ~  * terms of the Apache License, Version 2.0 which is available at
  ~  * https://www.apache.org/licenses/LICENSE-2.0.
  ~  *
  ~  *  See the NOTICE file distributed with this work for additional
  ~  *  information regarding copyright ownership.
  ~  * Unless required by applicable law or agreed to in writing, software
  ~  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  ~  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  ~  * License for the specific language governing permissions and limitations
  ~  * under the License.
  ~  *
  ~  * SPDX-License-Identifier: Apache-2.0
  ~  ******************************************************************************/
  -->

<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>

    <parent>
        <groupId>org.eclipse.deeplearning4j</groupId>
        <artifactId>nd4j-backend-impls</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>

    <artifactId>nd4j-native</artifactId>

    <name>nd4j-native</name>

    <properties>
        <javacpp.build.output.path>${project.build.directory}/classes/org/nd4j/linalg/cpu/nativecpu/bindings/${javacpp.platform}${javacpp.platform.extension}</javacpp.build.output.path>
        <module.name>nd4j.cpu</module.name>

        <compiler.flag.cpp.standard>-std=c++17</compiler.flag.cpp.standard>
        <javacpp.platform.compiler.output></javacpp.platform.compiler.output>
        <platform.linker.flag.no.undefined>-Wl,--no-undefined</platform.linker.flag.no.undefined>
        <platform.linker.flag.rdynamic>-rdynamic</platform.linker.flag.rdynamic>
        <platform.linker.flag.bsymbolic>-Bsymbolic</platform.linker.flag.bsymbolic>
        <platform.compiler.flag.optimize.none>-O0</platform.compiler.flag.optimize.none>
        <platform.compiler.flag.no.omit.fp>-fno-omit-frame-pointer</platform.compiler.flag.no.omit.fp>
        <platform.compiler.flag.no.optimize.sibling.calls>-fno-optimize-sibling-calls</platform.compiler.flag.no.optimize.sibling.calls>
        <platform.compiler.flag.debug>-g</platform.compiler.flag.debug>
        <platform.functrace.libs.unix>-ldl -lunwind -lbfd -ldw</platform.functrace.libs.unix>
        <libnd4j.outputPath>${project.build.directory}/../../../../../libnd4j/blasbuild/cpu</libnd4j.outputPath>
        <!-- NDK specific: https://github.com/android/ndk/issues/1690-->
        <javacpp.compiler.crtoption></javacpp.compiler.crtoption>

    </properties>


    <dependencies>
        <dependency>
            <groupId>${dependency.groupId}</groupId>
            <artifactId>${dependency.artifactId}</artifactId>
            <version>${dependency.version}</version>
            <type>${dependency.packaging}</type>
            <classifier>${dependency.classifier}</classifier>
        </dependency>
        <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>javacpp</artifactId>
        </dependency>

        <dependency>
            <groupId>org.eclipse.deeplearning4j</groupId>
            <artifactId>nd4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.eclipse.deeplearning4j</groupId>
            <artifactId>nd4j-native-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.eclipse.deeplearning4j</groupId>
            <artifactId>nd4j-native-preset</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.deeplearning4j</groupId>
            <artifactId>nd4j-cpu-backend-common</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>

            <plugin>
                <groupId>org.moditect</groupId>
                <artifactId>moditect-maven-plugin</artifactId>
            </plugin>

            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-jar</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <archive>
                                <manifestEntries>
                                    <Automatic-Module-Name>${module.name}</Automatic-Module-Name>
                                </manifestEntries>
                            </archive>
                            <excludes>
                                <exclude>
                                    org/nd4j/linalg/cpu/nativecpu/bindings/${javacpp.platform}${javacpp.platform.extension}/*
                                </exclude>
                                <exclude>lib/**</exclude>
                                <exclude>*.dll</exclude>
                                <exclude>*.dylib</exclude>
                                <exclude>*.so</exclude>
                                <exclude>*.vso</exclude>
                                <exclude>META-INF/native-image/${javacpp.platform}${javacpp.platform.extension}/</exclude>
                            </excludes>
                        </configuration>
                    </execution>
                    <execution>
                        <id>${javacpp.platform}${javacpp.platform.extension}</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <archive>
                                <manifestEntries>
                                    <Automatic-Module-Name>${module.name}.binary</Automatic-Module-Name>
                                </manifestEntries>
                            </archive>
                            <classifier>${javacpp.platform}${javacpp.platform.extension}</classifier>
                            <skipIfEmpty>true</skipIfEmpty>
                            <includes>
                                <include>
                                    org/nd4j/linalg/cpu/nativecpu/bindings/${javacpp.platform}${javacpp.platform.extension}/*
                                </include>
                                <include>lib/**</include>
                                <include>META-INF/native-image/${javacpp.platform}${javacpp.platform.extension}/</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <executions>
                    <execution>
                        <id>javacpp-parser</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                        <configuration>
                            <skipMain>${javacpp.parser.skip}</skipMain>
                            <includes>
                                <include>org/nd4j/linalg/nativecpu/bindings/*.java</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                    <compilerArgs>
                        <arg>--add-exports</arg>
                        <arg>java.base/java.nio=ALL-UNNAMED</arg>
                        <arg>--add-opens</arg>
                        <arg>java.base/java.nio=ALL-UNNAMED</arg>
                    </compilerArgs>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-deploy</id>
                        <phase>none</phase>
                    </execution>

                    <execution>
                        <id>java-classes</id>
                        <phase>deploy</phase>
                        <configuration>
                            <packaging>jar</packaging>
                            <artifactId>${project.artifactId}</artifactId>
                            <groupId>${project.groupId}</groupId>
                            <version>${project.version}</version>
                            <sources>${project.build.directory}/nd4j-native-${project.version}.jar</sources>
                        </configuration>
                    </execution>

                    <execution>
                        <id>native-deps</id>
                        <phase>deploy</phase>
                        <configuration>
                            <packaging>jar</packaging>
                            <artifactId>${project.artifactId}</artifactId>
                            <groupId>${project.groupId}</groupId>
                            <version>${project.version}</version>
                            <classifier>${javacpp.platform}</classifier>
                            <sources>${project.build.directory}/nd4j-native-${project.version}-${javacpp.platform}.jar</sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

    <profiles>

        <profile>
            <id>os-unix-flags</id>
            <activation>
                <os>
                    <family>unix</family>
                    <name>!mac os x</name> </os>
            </activation>
            <properties>
                <platform.linker.flag.no.undefined>-Wl,--no-undefined</platform.linker.flag.no.undefined>
                <platform.linker.flag.rdynamic>-rdynamic</platform.linker.flag.rdynamic>
                <platform.linker.flag.bsymbolic>-Bsymbolic</platform.linker.flag.bsymbolic>
                <platform.compiler.flag.optimize.none>-O0</platform.compiler.flag.optimize.none>
                <platform.compiler.flag.no.omit.fp>-fno-omit-frame-pointer</platform.compiler.flag.no.omit.fp>
                <platform.compiler.flag.no.optimize.sibling.calls>-fno-optimize-sibling-calls</platform.compiler.flag.no.optimize.sibling.calls>
                <platform.compiler.flag.debug>-g</platform.compiler.flag.debug>
                <platform.functrace.libs>${platform.functrace.libs.unix}</platform.functrace.libs>
                <platform.compiler.flag.windows.define></platform.compiler.flag.windows.define> </properties>
        </profile>

        <profile>
            <id>os-mac-flags</id>
            <activation>
                <os>
                    <family>mac</family>
                </os>
            </activation>
            <properties>
                <platform.linker.flag.no.undefined>-Wl,-undefined,error</platform.linker.flag.no.undefined> <platform.linker.flag.rdynamic></platform.linker.flag.rdynamic> <platform.linker.flag.bsymbolic></platform.linker.flag.bsymbolic> <platform.compiler.flag.optimize.none>-O0</platform.compiler.flag.optimize.none>
                <platform.compiler.flag.no.omit.fp>-fno-omit-frame-pointer</platform.compiler.flag.no.omit.fp>
                <platform.compiler.flag.no.optimize.sibling.calls>-fno-optimize-sibling-calls</platform.compiler.flag.no.optimize.sibling.calls>
                <platform.compiler.flag.debug>-g</platform.compiler.flag.debug>
                <platform.functrace.libs>${platform.functrace.libs.unix}</platform.functrace.libs> <platform.compiler.flag.windows.define></platform.compiler.flag.windows.define> </properties>
        </profile>

        <profile>
            <id>os-windows-flags</id>
            <activation>
                <os>
                    <family>windows</family>
                </os>
            </activation>
            <properties>
                <platform.linker.flag.no.undefined>-Wl,--no-undefined</platform.linker.flag.no.undefined> <platform.linker.flag.rdynamic></platform.linker.flag.rdynamic> <platform.linker.flag.bsymbolic></platform.linker.flag.bsymbolic> <platform.compiler.flag.optimize.none>-O0</platform.compiler.flag.optimize.none> <platform.compiler.flag.no.omit.fp>-fno-omit-frame-pointer</platform.compiler.flag.no.omit.fp> <platform.compiler.flag.no.optimize.sibling.calls>-fno-optimize-sibling-calls</platform.compiler.flag.no.optimize.sibling.calls> <platform.compiler.flag.debug>-g</platform.compiler.flag.debug> <platform.functrace.libs></platform.functrace.libs> <platform.compiler.flag.windows.define>-D_WIN32</platform.compiler.flag.windows.define>
            </properties>
        </profile>
        <profile>
            <id>non-functrace</id>
            <activation>
                <activeByDefault>true</activeByDefault>
                <property>
                    <name>!libnd4j.calltrace</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>javacpp</artifactId>
                        <version>${javacpp.version}</version>
                        <dependencies>
                            <dependency>
                                <groupId>org.eclipse.deeplearning4j</groupId>
                                <artifactId>nd4j-cpu-backend-common</artifactId>
                                <version>${project.version}</version>
                            </dependency>
                            <dependency>
                                <groupId>org.eclipse.deeplearning4j</groupId>
                                <artifactId>nd4j-native-preset</artifactId>
                                <version>${project.version}</version>
                            </dependency>
                            <dependency>
                                <groupId>org.eclipse.deeplearning4j</groupId>
                                <artifactId>nd4j-native-api</artifactId>
                                <version>${project.version}</version>
                            </dependency>
                            <dependency>
                                <groupId>org.bytedeco</groupId>
                                <artifactId>openblas</artifactId>
                                <version>${openblas.version}-${javacpp-presets.version}</version>
                                <optional>true</optional>
                            </dependency>
                            <dependency>
                                <groupId>org.bytedeco</groupId>
                                <artifactId>openblas</artifactId>
                                <version>${openblas.version}-${javacpp-presets.version}</version>
                                <classifier>${dependency.platform}</classifier>
                                <optional>true</optional>
                            </dependency>
                        </dependencies>
                        <configuration>
                            <properties>${javacpp.platform.properties}</properties>
                            <propertyKeysAndValues>
                                <property>
                                    <name>platform.root</name>
                                    <value>${javacpp.platform.root}</value>
                                </property>
                                <property>
                                    <name>platform.compiler</name>
                                    <value>${javacpp.platform.compiler}</value>
                                </property>
                                <property>
                                    <name>platform.sysroot</name>
                                    <value>${javacpp.platform.sysroot}</value>
                                </property>
                                <property>
                                    <name>platform.extension</name>
                                    <value>${javacpp.platform.extension}</value>
                                </property>
                            </propertyKeysAndValues>
                            <classPaths>
                                <classPath>${project.build.outputDirectory}</classPath>
                            </classPaths>
                            <includePaths>
                                <includePath>${libnd4jhome}/blasbuild/cpu/flatbuffers-target-build/include</includePath>
                                <includePath>${libnd4jhome}/blasbuild/cpu/flatbuffers-host-build/include</includePath>
                                <includePath>${libnd4jhome}/blasbuild/cpu/include</includePath>
                                <includePath>${libnd4jhome}/blasbuild/cpu/flatbuffers-src/include/
                                </includePath>
                                <includePath>${libnd4jhome}/blas</includePath>
                                <includePath>${libnd4jhome}/include</includePath>
                                <includePath>${libnd4jhome}/include/helpers</includePath>
                                <includePath>${libnd4jhome}/include/array</includePath>
                                <includePath>${libnd4jhome}/include/cnpy</includePath>
                                <includePath>${libnd4jhome}/include/execution</includePath>
                                <includePath>${libnd4jhome}/include/exceptions</includePath>
                                <includePath>${libnd4jhome}/include/graph</includePath>
                                <includePath>${libnd4jhome}/include/indexing</includePath>
                                <includePath>${libnd4jhome}/include/memory</includePath>
                            </includePaths>
                            <linkPaths>
                                <linkPath>${libnd4j.outputPath}</linkPath>
                                <linkPath>${env.OPENBLAS_PATH}/lib</linkPath>
                                <linkPath>${env.OPENBLAS_PATH}/</linkPath>
                            </linkPaths>
                            <resourcePath>${libnd4jhome}/blasbuild/cpu/blas</resourcePath>
                            <buildResources>
                                <buildResource>/${javacpp.platform.library.path}/</buildResource>
                                <buildResource>/org/bytedeco/openblas/${javacpp.platform}/</buildResource>
                                <buildResource>/lib/</buildResource>
                                <buildResource>/</buildResource>
                                <buildResource>${libnd4jhome}/blasbuild/cpu</buildResource>
                            </buildResources>
                            <includeResources>
                                <includeResource>/${javacpp.platform.library.path}/include/
                                </includeResource>
                                <includeResource>/org/bytedeco/openblas/${javacpp.platform}/include/
                                </includeResource>
                            </includeResources>
                            <linkResources>
                                <linkResource>/${javacpp.platform.library.path}/</linkResource>
                                <linkResource>/${javacpp.platform.library.path}/lib/</linkResource>
                                <linkResource>/org/bytedeco/openblas/${javacpp.platform}/</linkResource>
                                <linkResource>/org/bytedeco/openblas/${javacpp.platform}/lib/</linkResource>
                            </linkResources>
                            <compilerOptions>
                                <compilerOption>${compiler.flag.cpp.standard}</compilerOption>
                                <compilerOption>${platform.linker.flag.no.undefined}</compilerOption>
                            </compilerOptions>
                        </configuration>
                        <executions>
                            <execution>
                                <id>javacpp-validate</id>
                                <phase>validate</phase>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>javacpp-parser</id>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                                <configuration>
                                    <skip>${javacpp.parser.skip}</skip>
                                    <outputDirectory>${project.build.sourceDirectory}</outputDirectory>
                                    <classOrPackageName>org.nd4j.presets.cpu.Nd4jCpuPresets</classOrPackageName>
                                </configuration>
                            </execution>
                            <execution>
                                <id>javacpp-compiler</id>
                                <phase>process-classes</phase>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                                <configuration>
                                    <skip>${javacpp.compiler.skip}</skip>
                                    <classOrPackageName>org.nd4j.linalg.cpu.nativecpu.bindings.Nd4jCpu</classOrPackageName>
                                    <copyLibs>true</copyLibs>
                                    <copyResources>true</copyResources>
                                    <configDirectory>${project.build.directory}/classes/META-INF/native-image/${javacpp.platform}${javacpp.platform.extension}/</configDirectory>
                                    <outputDirectory>${javacpp.build.output.path}</outputDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>functrace</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <property>
                    <name>libnd4j.calltrace</name>
                    <value>ON</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>javacpp</artifactId>
                        <version>${javacpp.version}</version>
                        <dependencies>
                            <dependency>
                                <groupId>org.eclipse.deeplearning4j</groupId>
                                <artifactId>nd4j-cpu-backend-common</artifactId>
                                <version>${project.version}</version>
                            </dependency>
                            <dependency>
                                <groupId>org.eclipse.deeplearning4j</groupId>
                                <artifactId>nd4j-native-preset</artifactId>
                                <version>${project.version}</version>
                            </dependency>
                            <dependency>
                                <groupId>org.eclipse.deeplearning4j</groupId>
                                <artifactId>nd4j-native-api</artifactId>
                                <version>${project.version}</version>
                            </dependency>
                            <dependency>
                                <groupId>org.bytedeco</groupId>
                                <artifactId>openblas</artifactId>
                                <version>${openblas.version}-${javacpp-presets.version}</version>
                                <optional>true</optional>
                            </dependency>
                            <dependency>
                                <groupId>org.bytedeco</groupId>
                                <artifactId>openblas</artifactId>
                                <version>${openblas.version}-${javacpp-presets.version}</version>
                                <classifier>${dependency.platform}</classifier>
                                <optional>true</optional>
                            </dependency>
                        </dependencies>
                        <configuration>
                            <properties>${javacpp.platform.properties}</properties>
                            <propertyKeysAndValues>
                                <property>
                                    <name>libnd4j.calltrace</name>
                                    <value>${libnd4j.calltrace}</value>
                                </property>
                                <property>
                                    <name>platform.root</name>
                                    <value>${javacpp.platform.root}</value>
                                </property>
                                <property>
                                    <name>platform.compiler</name>
                                    <value>${javacpp.platform.compiler}</value>
                                </property>
                                <property>
                                    <name>platform.sysroot</name>
                                    <value>${javacpp.platform.sysroot}</value>
                                </property>
                                <property>
                                    <name>platform.extension</name>
                                    <value>${javacpp.platform.extension}</value>
                                </property>
                            </propertyKeysAndValues>
                            <classPaths>
                                <classPath>${project.build.outputDirectory}</classPath>
                            </classPaths>
                            <includePaths>
                                <includePath>${libnd4jhome}/blasbuild/cpu/flatbuffers-target-build/include</includePath>
                                <includePath>${libnd4jhome}/blasbuild/cpu/flatbuffers-host-build/include</includePath>
                                <includePath>${libnd4jhome}/blasbuild/cpu/include</includePath>
                                <includePath>${libnd4jhome}/blasbuild/cpu/flatbuffers-src/include/
                                </includePath>
                                <includePath>${libnd4jhome}/blas</includePath>
                                <includePath>${libnd4jhome}/include</includePath>
                                <includePath>${libnd4jhome}/include/helpers</includePath>
                                <includePath>${libnd4jhome}/include/array</includePath>
                                <includePath>${libnd4jhome}/include/cnpy</includePath>
                                <includePath>${libnd4jhome}/include/execution</includePath>
                                <includePath>${libnd4jhome}/include/exceptions</includePath>
                                <includePath>${libnd4jhome}/include/graph</includePath>
                                <includePath>${libnd4jhome}/include/indexing</includePath>
                                <includePath>${libnd4jhome}/include/memory</includePath>
                                <includePath>${libnd4jhome}/include/performance</includePath> </includePaths>
                            <linkPaths>
                                <linkPath>${libnd4j.outputPath}</linkPath>
                                <linkPath>${env.OPENBLAS_PATH}/lib</linkPath>
                                <linkPath>${env.OPENBLAS_PATH}/</linkPath>

                            </linkPaths>
                            <resourcePath>${libnd4jhome}/blasbuild/cpu/blas</resourcePath>
                            <buildResources>
                                <buildResource>/${javacpp.platform.library.path}/</buildResource>
                                <buildResource>/org/bytedeco/openblas/${javacpp.platform}/</buildResource>
                                <buildResource>/lib/</buildResource>
                                <buildResource>/</buildResource>
                                <buildResource>${libnd4jhome}/blasbuild/cpu/blas</buildResource>
                            </buildResources>
                            <includeResources>
                                <includeResource>/${javacpp.platform.library.path}/include/
                                </includeResource>
                                <includeResource>/org/bytedeco/openblas/${javacpp.platform}/include/
                                </includeResource>
                            </includeResources>
                            <linkResources>
                                <linkResource>/${javacpp.platform.library.path}/</linkResource>
                                <linkResource>/${javacpp.platform.library.path}/lib/</linkResource>
                                <linkResource>/org/bytedeco/openblas/${javacpp.platform}/</linkResource>
                                <linkResource>/org/bytedeco/openblas/${javacpp.platform}/lib/</linkResource>
                            </linkResources>
                            <compilerOptions>
                                <compilerOption>${compiler.flag.cpp.standard}</compilerOption>
                                <compilerOption>-DSD_GCC_FUNCTRACE=ON</compilerOption>
                                <compilerOption>${platform.linker.flag.no.undefined}</compilerOption>
                                <compilerOption>${platform.linker.flag.rdynamic}</compilerOption>
                                <compilerOption>${platform.linker.flag.bsymbolic}</compilerOption>
                                <compilerOption>${platform.compiler.flag.optimize.none}</compilerOption>
                                <compilerOption>${platform.compiler.flag.no.omit.fp}</compilerOption>
                                <compilerOption>${platform.compiler.flag.no.optimize.sibling.calls}</compilerOption>
                                <compilerOption>${platform.compiler.flag.debug}</compilerOption>
                            </compilerOptions>
                        </configuration>
                        <executions>
                            <execution>
                                <id>javacpp-validate</id>
                                <phase>validate</phase>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>javacpp-parser</id>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                                <configuration>
                                    <skip>${javacpp.parser.skip}</skip>
                                    <outputDirectory>${project.build.sourceDirectory}</outputDirectory>
                                    <classOrPackageName>org.nd4j.presets.cpu.Nd4jCpuPresets</classOrPackageName>
                                </configuration>
                            </execution>
                            <execution>
                                <id>javacpp-compiler</id>
                                <phase>process-classes</phase>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                                <configuration>
                                    <skip>${javacpp.compiler.skip}</skip>
                                    <classOrPackageName>org.nd4j.linalg.cpu.nativecpu.bindings.Nd4jCpu</classOrPackageName>
                                    <copyLibs>true</copyLibs>
                                    <copyResources>true</copyResources>
                                    <configDirectory>${project.build.directory}/classes/META-INF/native-image/${javacpp.platform}${javacpp.platform.extension}/</configDirectory>
                                    <outputDirectory>${javacpp.build.output.path}</outputDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>compat-profile</id>
            <activation>
                <property>
                    <name>javacpp.platform.extension</name>
                    <value>/.+/</value>
                </property>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.bytedeco</groupId>
                    <artifactId>javacpp</artifactId>
                    <version>${javacpp.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.bytedeco</groupId>
                    <artifactId>openblas</artifactId>
                    <version>${openblas.version}-${javacpp-presets.version}</version>
                    <optional>true</optional>
                </dependency>
                <dependency>
                    <groupId>org.bytedeco</groupId>
                    <artifactId>openblas</artifactId>
                    <version>${openblas.version}-${javacpp-presets.version}</version>
                    <classifier>linux-x86_64</classifier>
                    <optional>true</optional>
                </dependency>
            </dependencies>
        </profile>
        <profile>
            <id>default-javacpp</id>
            <activation>
                <property>
                    <name>!javacpp.platform.extension</name>
                </property>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.bytedeco</groupId>
                    <artifactId>javacpp</artifactId>
                    <classifier>${dependency.platform}</classifier>
                </dependency>
                <dependency>
                    <groupId>org.bytedeco</groupId>
                    <artifactId>openblas</artifactId>
                    <version>${openblas.version}-${javacpp-presets.version}</version>
                    <optional>true</optional>
                </dependency>
                <dependency>
                    <groupId>org.bytedeco</groupId>
                    <artifactId>openblas</artifactId>
                    <version>${openblas.version}-${javacpp-presets.version}</version>
                    <classifier>${dependency.platform}</classifier>
                    <optional>true</optional>
                </dependency>
            </dependencies>
        </profile>

        <profile>
            <id>android-arm-32-output</id>
            <activation>
                <property>
                    <name>javacpp.platform</name>
                    <value>android-arm</value>
                </property>
            </activation>
            <properties>
                <javacpp.build.output.path>${project.build.directory}/classes/lib/armeabi-v7a</javacpp.build.output.path>
            </properties>
        </profile>
        <profile>
            <id>android-arm-64-output</id>
            <activation>
                <property>
                    <name>javacpp.platform</name>
                    <value>android-arm64</value>
                </property>
            </activation>
            <properties>
                <javacpp.build.output.path>${project.build.directory}/classes/lib/arm64-v8a</javacpp.build.output.path>
                <platform.compiler.output>-Wl,-rpath,lib/ -D__ANDROID_API__=21 -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -march=armv8-a -Wall -nostdlib++ -fPIC -shared -Wl,--no-undefined -z text -o</platform.compiler.output>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>javacpp</artifactId>
                        <version>${javacpp.version}</version>
                        <configuration>
                            <includePaths>
                                <includePath>${libnd4jhome}/blasbuild/cpu/flatbuffers-target-build/include</includePath>
                                <includePath>${libnd4jhome}/blasbuild/cpu/flatbuffers-host-build/include</includePath>
                                <includePath>${libnd4jhome}/blasbuild/cpu/include</includePath>
                                <includePath>${libnd4jhome}/blasbuild/cpu/flatbuffers-src/include/</includePath>
                                <includePath>${libnd4jhome}/blas</includePath>
                                <includePath>${libnd4jhome}/include</includePath>
                                <includePath>${libnd4jhome}/include/helpers</includePath>
                                <includePath>${libnd4jhome}/include/array</includePath>
                                <includePath>${libnd4jhome}/include/cnpy</includePath>
                                <includePath>${libnd4jhome}/include/execution</includePath>
                                <includePath>${libnd4jhome}/include/exceptions</includePath>
                                <includePath>${libnd4jhome}/include/graph</includePath>
                                <includePath>${libnd4jhome}/include/indexing</includePath>
                                <includePath>${libnd4jhome}/include/memory</includePath>
                            </includePaths>
                            <linkPaths>
                                <linkPath>${libnd4j.outputPath}</linkPath>
                                <linkPath>${env.OPENBLAS_PATH}/lib</linkPath>
                                <linkPath>${env.OPENBLAS_PATH}/</linkPath>
                                <linkPath>${env.ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/21</linkPath>

                            </linkPaths>

                            <compilerOptions>
                                <compilerOption>${compiler.flag.cpp.standard}</compilerOption>
                                <compilerOption>${platform.linker.flag.no.undefined}</compilerOption>
                                <compilerOption>--target=aarch64-linux-android21</compilerOption>
                                <compilerOption>-D__ANDROID_API__=21</compilerOption>
                                <compilerOption>-DANDROID</compilerOption>
                            </compilerOptions>
                            <properties>${javacpp.platform.properties}</properties>
                            <propertyKeysAndValues>
                                <property>
                                    <name>platform.root</name>
                                    <value>${javacpp.platform.root}</value>
                                </property>
                                <property>
                                    <name>platform.compiler</name>
                                    <value>${javacpp.platform.compiler}</value>
                                </property>
                                <property>
                                    <name>platform.sysroot</name>
                                    <value>${javacpp.platform.sysroot}</value>
                                </property>
                                <property>
                                    <name>platform.extension</name>
                                    <value>${javacpp.platform.extension}</value>
                                </property>
                                <property>
                                    <name>platform.compiler.output</name>
                                    <value>-Wl,-rpath,lib/ -D__ANDROID_API__=21 -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -march=armv8-a -Wall -nostdlib++ -fPIC -shared -Wl,--no-undefined -z text -o </value>
                                </property>
                            </propertyKeysAndValues>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>android-x86-output</id>
            <activation>
                <property>
                    <name>javacpp.platform</name>
                    <value>android-x86</value>
                </property>
            </activation>
            <properties>
                <javacpp.build.output.path>${project.build.directory}/classes/lib/x86</javacpp.build.output.path>
            </properties>
        </profile>
        <profile>
            <id>android-x86_64-output</id>
            <activation>
                <property>
                    <name>javacpp.platform</name>
                    <value>android-x86_64</value>
                </property>
            </activation>
            <properties>
                <javacpp.build.output.path>${project.build.directory}/classes/lib/x86_64</javacpp.build.output.path>
                <!-- Remove -nostartfiles since we need the CRT objects -->
                <javacpp.compiler.crtoption></javacpp.compiler.crtoption>
                <!-- Add sysroot configuration for android-x86_64 -->
                <javacpp.platform.sysroot>${env.ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot</javacpp.platform.sysroot>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>javacpp</artifactId>
                        <version>${javacpp.version}</version>
                        <configuration>
                            <properties>${javacpp.platform.properties}</properties>
                            <propertyKeysAndValues>
                                <property>
                                    <name>platform.root</name>
                                    <value>${javacpp.platform.root}</value>
                                </property>
                                <property>
                                    <name>platform.compiler</name>
                                    <value>${javacpp.platform.compiler}</value>
                                </property>
                                <property>
                                    <name>platform.sysroot</name>
                                    <value>${env.ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot</value>
                                </property>
                                <property>
                                    <name>platform.extension</name>
                                    <value>${javacpp.platform.extension}</value>
                                </property>
                            </propertyKeysAndValues>
                            <linkPaths>
                                <linkPath>${libnd4j.outputPath}</linkPath>
                                <linkPath>${env.OPENBLAS_PATH}/lib</linkPath>
                                <linkPath>${env.OPENBLAS_PATH}/</linkPath>

                                <!-- Android NDK library paths -->
                                <linkPath>${env.ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/21</linkPath>
                                <linkPath>${env.ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android</linkPath>
                                <linkPath>${env.ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/17/lib/linux</linkPath>
                                <linkPath>${env.ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib</linkPath>
                                <linkPath>${env.ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/lib</linkPath>
                            </linkPaths>
                            <compilerOptions>
                                <compilerOption>${compiler.flag.cpp.standard}</compilerOption>
                                <compilerOption>${platform.linker.flag.no.undefined}</compilerOption>
                                <!-- Add explicit sysroot to compiler options -->
                                <compilerOption>--sysroot=${env.ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot</compilerOption>
                                <!-- Add multiple -B flags for different possible CRT locations -->
                                <compilerOption>-B${env.ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/17/lib/linux</compilerOption>
                                <compilerOption>-B${env.ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/17/lib/linux/x86_64</compilerOption>
                                <compilerOption>-B${env.ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/21</compilerOption>
                                <!-- Explicitly tell linker where to find CRT objects -->
                                <compilerOption>-Wl,--dynamic-linker=/system/bin/linker64</compilerOption>
                            </compilerOptions>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>avx2</id>
            <activation>
                <property>
                    <name>libnd4j.extension</name>
                    <value>avx2</value>
                </property>
            </activation>
            <properties>
                <javacpp.platform.extension>-avx2</javacpp.platform.extension>
            </properties>
        </profile>
        <profile>
            <id>avx512</id>
            <activation>
                <property>
                    <name>libnd4j.extension</name>
                    <value>avx512</value>
                </property>
            </activation>
            <properties>
                <javacpp.platform.extension>-avx512</javacpp.platform.extension>
            </properties>
        </profile>

        <profile>
            <id>mingw</id>
            <activation>
                <os>
                    <family>windows</family>
                </os>
                <property>
                    <name>!javacpp.platform</name> </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>javacpp</artifactId>
                        <configuration>
                            <properties>${javacpp.platform}-mingw</properties>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>mingw-windows-platform</id>
            <activation>
                <os>
                    <family>windows</family>
                </os>
                <property>
                    <name>javacpp.platform</name>
                    <value>windows-x86_64</value> </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>javacpp</artifactId>
                        <configuration>
                            <properties>${javacpp.platform}-mingw</properties>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>libnd4j-set</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <property>
                    <name>env.LIBND4J_HOME</name>
                </property>
            </activation>
            <properties>
                <libnd4jhome>${env.LIBND4J_HOME}</libnd4jhome>
            </properties>
        </profile>
        <profile>
            <id>libnd4j-assembly</id>
            <activation>
                <property>
                    <name>libnd4j-assembly</name>
                </property>
            </activation>
            <properties>
                <libnd4jhome>${project.build.directory}/libnd4j/</libnd4jhome>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.eclipse.deeplearning4j</groupId>
                    <artifactId>libnd4j</artifactId>
                    <version>${project.version}</version>
                    <type>zip</type>
                    <classifier>${javacpp.platform}${javacpp.platform.extension}</classifier>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>3.1.2</version> <executions>
                        <execution>
                            <id>unpack</id>
                            <phase>initialize</phase>
                            <goals>
                                <goal>unpack</goal>
                            </goals>
                            <configuration>
                                <artifactItems>
                                    <artifactItem>
                                        <groupId>org.eclipse.deeplearning4j</groupId>
                                        <artifactId>libnd4j</artifactId>
                                        <version>${project.version}</version>
                                        <type>zip</type>
                                        <classifier>
                                            ${javacpp.platform}${javacpp.platform.extension}
                                        </classifier>
                                        <overWrite>true</overWrite>
                                        <outputDirectory>${project.build.directory}
                                        </outputDirectory>
                                    </artifactItem>
                                </artifactItems>
                            </configuration>
                        </execution>
                    </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>