Skip to content

Commit

Permalink
Using autotools build native library
Browse files Browse the repository at this point in the history
  • Loading branch information
judovana committed Sep 14, 2021
1 parent eb91a59 commit 5c8538c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 35 deletions.
16 changes: 13 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ JIGA_MAVEN_DIR = META-INF/maven/$(GROUP)/$(ARTIFACT)

JIGA_NATIVE_FUNCS = com/redhat/jigawatts/Jigawatts.java
JIGA_NATIVE_HDRS = $(subst .java,.h,$(subst /,_,$(JIGA_NATIVE_FUNCS)))
JIGA_NATIVE_HDRS_PREFIXED = $(addprefix $(JIGA_INCLUDEDIR)/,$(JIGA_NATIVE_HDRS))
JIGA_NATIVE_SRC = $(subst .java,.cpp,$(subst /,_,$(JIGA_NATIVE_FUNCS)))
JIGA_NATIVE_OBJS = $(subst .cpp,.o,$(JIGA_NATIVE_SRC))
JIGA_LIB = libJigawatts.so
Expand Down Expand Up @@ -74,16 +75,23 @@ $(JIGA_BUILDDIR)/source-files.txt:
clean-source-file-list:
$(RM) $(JIGA_BUILDDIR)/source-files.txt

$(JIGA_NATIVE_HDRS_PREFIXED): $(JIGA_BUILDDIR)/source-files.txt
$(SYSTEM_JDK_DIR)/bin/javac -g $(JAVACFLAGS) \
-d `mktemp -d` \
-h $(JIGA_INCLUDEDIR) \
-sourcepath $(JIGA_JAVA_SRCDIR) \
@$<;

$(JIGA_STAMPDIR)/classes.stamp: $(JIGA_BUILDDIR)/source-files.txt
$(SYSTEM_JDK_DIR)/bin/javac -g $(JAVACFLAGS) \
-d $(JIGA_BUILDDIR) -h $(JIGA_INCLUDEDIR) \
-d $(JIGA_BUILDDIR) \
-sourcepath $(JIGA_JAVA_SRCDIR) \
@$< ;
mkdir -p $(JIGA_STAMPDIR)
touch $@

clean-classes-and-headers:
$(RM) $(addprefix $(JIGA_INCLUDEDIR)/,$(JIGA_NATIVE_HDRS))
$(RM) $(JIGA_NATIVE_HDRS_PREFIXED)
$(RM) -r $(JIGA_BUILDDIR)/$(JAVA_ROOT_DIR)
$(RM) $(JIGA_STAMPDIR)/classes.stamp

Expand All @@ -95,7 +103,9 @@ $(JIGA_BUILDDIR)/%.o: $(JIGA_NATIVE_SRCDIR)/%.cpp
clean-native-objects:
$(RM) $(addprefix $(JIGA_BUILDDIR)/,$(JIGA_NATIVE_OBJS))

$(JIGA_BUILDDIR)/$(JIGA_LIB): $(addprefix $(JIGA_INCLUDEDIR)/,$(JIGA_NATIVE_HDRS)) \
natives: $(JIGA_BUILDDIR)/$(JIGA_LIB)

$(JIGA_BUILDDIR)/$(JIGA_LIB): $(JIGA_NATIVE_HDRS_PREFIXED) \
$(addprefix $(JIGA_BUILDDIR)/,$(JIGA_NATIVE_OBJS))
$(CC) $(LDFLAGS) $(addprefix $(JIGA_BUILDDIR)/,$(JIGA_NATIVE_OBJS)) -shared -o $@ $(CRIU_LIBS)

Expand Down
83 changes: 51 additions & 32 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,52 @@
<version>3.0.0</version>
<executions>
<execution>
<id>compile-cpp</id>
<id>default-autogen</id>
<goals>
<goal>exec</goal>
</goals>
<phase>process-classes</phase>
<configuration>
<executable>gcc</executable>
<executable>./autogen.sh</executable>
</configuration>
</execution>
<execution>
<id>default-configure</id>
<goals>
<goal>exec</goal>
</goals>
<phase>process-classes</phase>
<configuration>
<executable>./configure</executable>
<arguments>
<argument>-v</argument>
<argument>-shared</argument>
<argument>-fPIC</argument>
<argument>-I${java.includes}/include</argument>
<argument>-I${java.includes}/include/linux</argument>
<argument>-I/usr/lib64/</argument>
<argument>-I/usr/include/criu</argument>
<argument>-I${project.build.directory}/native/javah</argument>
<argument>-lcriu</argument>
<argument>-o${project.build.outputDirectory}/libJigawatts.so</argument>
<argument>${project.basedir}/src/main/cpp/com_redhat_jigawatts_Jigawatts.cpp
</argument>
<argument>--with-jdk=${env.JAVA_HOME}</argument> <!-- ensuring maven's jdk is used -->
</arguments>
</configuration>
</execution>
<execution>
<id>make-default-natives</id>
<goals>
<goal>exec</goal>
</goals>
<phase>process-classes</phase>
<configuration>
<executable>make</executable>
<arguments>
<argument>natives</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>copy-default-lib</id>
<goals>
<goal>exec</goal>
</goals>
<phase>process-classes</phase>
<configuration>
<executable>cp</executable>
<arguments>
<argument>build/libJigawatts.so</argument>
<argument>target/classes/libJigawats.so</argument>
</arguments>
</configuration>
</execution>
Expand All @@ -121,24 +147,6 @@
<source>8</source>
<target>8</target>
</configuration>
<executions>
<execution>
<id>header-generation</id>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<compilerArgs>
<arg>-h</arg>
<arg>${project.build.directory}/native/javah</arg>
</compilerArgs>
<includes>
<include>com/redhat/jigawatts/Jigawatts.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down Expand Up @@ -175,10 +183,21 @@
<directory>src/test/resources</directory>
<includes>
<include>jigawatts/*</include>
<include>jigawatts/testhooks/**</include>
<include>1*</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
<fileset>
<directory>build</directory>
<includes>
<include>**/*</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
<fileset>
<directory>build</directory>
</fileset>
</filesets>
</configuration>
</plugin>
Expand Down

0 comments on commit 5c8538c

Please sign in to comment.