Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

pom and Makefile fixed to compile native code and place it in target/…

…. Makefile clean also integrated in pom to remove native library when doing mvn clean. pom now is formated with 4 spaces per tab
  • Loading branch information...
commit d7efbd6a2b788d84526bd812e1a8ab309944eb1a 1 parent 7c3fed4
Francisco Perez-Sorrosal authored
Showing with 120 additions and 76 deletions.
  1. +92 −56 pom.xml
  2. +28 −20 src/main/native/Makefile
View
148 pom.xml
@@ -32,63 +32,98 @@
</properties>
<build>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.9</version>
+ <configuration>
+ <argLine>-Xmx1G</argLine>
+ <forkMode>pertest</forkMode>
+ <argLine>-Djava.library.path=${basedir}/lib</argLine>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${basedir}/lib</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>1.7</version>
+ <executions>
+ <execution>
+ <!-- Build native code after .java compilation -->
+ <id>build-native</id>
+ <phase>process-classes</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <target name="jni"
+ description="Generate headers and compile the native code">
+ <echo>Generating JNI headers</echo>
+ <exec executable="javah">
+ <arg value="-d" />
+ <arg
+ value="${project.basedir}/target/main/native" />
+ <arg value="-classpath" />
+ <arg
+ value="${project.build.outputDirectory}" />
+ <arg value="-jni" />
+ <arg
+ value="com.yahoo.omid.tso.CommitHashMap" />
+ </exec>
+ <exec
+ dir="${project.basedir}/src/main/native"
+ executable="make" failonerror="true">
+ <arg value="all" />
+ </exec>
+ </target>
+ </configuration>
+ </execution>
+ <execution>
+ <!-- Make clean in the Maven clean phase -->
+ <id>clean-lib</id>
+ <phase>clean</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <target name="clean-lib" description="Delete native lib">
+ <echo>Deleting native lib</echo>
+ <exec
+ dir="${project.basedir}/src/main/native"
+ executable="make">
+ <arg value="clean" />
+ </exec>
+ </target>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+
<pluginManagement>
<plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.9</version>
- <configuration>
- <argLine>-Xmx1G</argLine>
- <forkMode>pertest</forkMode>
- <argLine>-Djava.library.path=${basedir}/src/main/native</argLine>
- </configuration>
- </plugin>
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.3.2</version>
- <configuration>
- <source>1.6</source>
- <target>1.6</target>
- </configuration>
- </plugin>
- <plugin>
- <artifactId>maven-dependency-plugin</artifactId>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- <configuration>
- <outputDirectory>${basedir}/lib</outputDirectory>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <artifactId>maven-antrun-plugin</artifactId>
- <executions>
- <execution>
- <id>build-native</id>
- <phase>process-classes</phase>
- <goals>
- <goal>run</goal>
- </goals>
- <configuration>
- <tasks>
- <property name="native.classpath"
- refid="maven.compile.classpath" />
- <echo
- file="${project.build.directory}/compile-classpath"
- message="${native.classpath}" />
- <exec dir="src/main/native"
- executable="make" failonerror="true" />
- </tasks>
- </configuration>
- </execution>
- </executions>
- </plugin>
<!--This plugin's configuration is used to store Eclipse
m2e settings only. It has no influence on the Maven build itself. -->
<plugin>
@@ -138,8 +173,9 @@
</plugin>
</plugins>
</pluginManagement>
+
</build>
-
+
<dependencies>
<dependency>
<groupId>junit</groupId>
View
48 src/main/native/Makefile
@@ -17,12 +17,18 @@
#
########################################################################
-OSTYPE := $(shell uname -s)
-CC = g++
-LDSHARED = $(CC) -shared -fPIC
-TSO_COMMITHASHMAP_SO = libtso-commithashmap.so
+OSTYPE=$(shell uname -s)
+
+SOURCESDIR=.
+OBJECTSDIR=../../../target/main/native
+LIBDIR=../../../lib
+
+CC=g++
+
+# This sets the name of the generated lib depending on the OS
+TSOCOMMITHASHMAP=libtso-commithashmap.so
ifeq ($(OSTYPE),Darwin)
-TSO_COMMITHASHMAP_SO = libtso-commithashmap.jnilib
+TSOCOMMITHASHMAP=libtso-commithashmap.jnilib
endif
INCLUDES=
@@ -31,25 +37,27 @@ INCLUDES=-I/System/Library/Frameworks/JavaVM.framework/Headers
else
INCLUDES=-I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
endif
+# The following includes the target dir where maven antrun places the .h file
+INCLUDES+=-I$(OBJECTSDIR)
-LDFLAGS=-lstdc++
+CFLAGS=-fPIC -O3 $(INCLUDES) -c
+LDFLAGS=-fPIC -lstdc++ -shared
ifneq ($(OSTYPE),Darwin)
-LDFLAGS += -Wl,-soname=$(TSO_COMMITHASHMAP_SO)
+LDFLAGS+=-Wl,-soname=$(TSOCOMMITHASHMAP)
endif
+SOURCES=$(shell find '$(SOURCESDIR)' -type f -name '*.cc')
+OBJECTS=$(SOURCES:$(SOURCESDIR)/%.cc=$(OBJECTSDIR)/%.o)
+LIB=$(LIBDIR)/$(TSOCOMMITHASHMAP)
-all: com_yahoo_omid_tso_CommitHashMap.h $(TSO_COMMITHASHMAP_SO)
-
-nativelib.o: nativelib.cc
- $(CC) -fPIC -O3 $(INCLUDES) -c -o nativelib.o nativelib.cc
-
-$(TSO_COMMITHASHMAP_SO): nativelib.o $(DEP_LIBS)
- $(LDSHARED) -o $@ $(LDFLAGS) nativelib.o $(LIBS)
-
-com_yahoo_omid_tso_CommitHashMap.h: nativelib.cc
- javah -classpath ../../../target/classes -jni com.yahoo.omid.tso.CommitHashMap
+all: $(LIB)
+$(LIB): $(OBJECTS)
+ $(CC) $(LDFLAGS) $(OBJECTS) -o $@
+
+$(OBJECTS): $(SOURCES)
+ mkdir -p $(OBJECTSDIR)
+ $(CC) $(CFLAGS) $< -o $@
+
clean:
- rm -f nativelib.o $(TSO_COMMITHASHMAP_SO)
-
-
+ rm -f $(LIB)
Please sign in to comment.
Something went wrong with that request. Please try again.