aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2013-05-21 19:30:04 +0200
committerJakob Odersky <jodersky@gmail.com>2013-05-21 19:30:04 +0200
commit15b42451d124564b9ccf4a6365d2f50f7f3896c9 (patch)
tree48025113c45e4b54b2c1911203530cabef088990
parent60cac1f48d76329fa94034cea84499fb93337953 (diff)
downloadakka-serial-15b42451d124564b9ccf4a6365d2f50f7f3896c9.tar.gz
akka-serial-15b42451d124564b9ccf4a6365d2f50f7f3896c9.tar.bz2
akka-serial-15b42451d124564b9ccf4a6365d2f50f7f3896c9.zip
extract native libraries
-rw-r--r--.gitignore1
-rw-r--r--project/Build.scala18
-rw-r--r--project/JNIBuild.scala5
-rw-r--r--src/main/java/com/github/jodersky/flow/NativeSerial.java2
-rw-r--r--src/main/scala/com/github/jodersky/flow/NativeLoader.scala35
5 files changed, 51 insertions, 10 deletions
diff --git a/.gitignore b/.gitignore
index 20e1c2d..2112789 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,6 +10,7 @@ project/boot/
project/plugins/project/
# Scala-IDE specific
+.settings
.scala_dependencies
.project
.classpath
diff --git a/project/Build.scala b/project/Build.scala
index 714c9d0..9efb049 100644
--- a/project/Build.scala
+++ b/project/Build.scala
@@ -11,7 +11,7 @@ object FlowBuild extends Build {
lazy val root = Project(
id = "flow",
base = file("."),
- settings = buildSettings ++ jniSettings ++ runSettings)
+ settings = buildSettings ++ jniSettings ++ runSettings ++ Seq(libraryDependencies ++= Dependencies.all))
lazy val buildSettings = Defaults.defaultSettings ++ Seq(
organization := Organization,
@@ -19,8 +19,8 @@ object FlowBuild extends Build {
scalaVersion := ScalaVersion,
resolvers += "Typesafe Repo" at "http://repo.typesafe.com/typesafe/releases/",
scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature"),
- compileOrder in Compile := CompileOrder.JavaThenScala)
-
+ compileOrder in Compile := CompileOrder.Mixed)
+
lazy val jniSettings = JNIBuild.defaults ++ Seq(
jdkHome := file(System.getProperty("java.home")) / "..",
javaClass := "com.github.jodersky.flow.NativeSerial",
@@ -29,9 +29,13 @@ object FlowBuild extends Build {
NativeBuild.includeDirectories <<= jdkHome apply (jdk => Seq(jdk / "include", jdk / "include" / "linux")),
linker := "gcc",
linkerOptions := Seq("-shared", "-Wl,-soname,libflow.so.1"),
- linkerOutput <<= NativeBuild.outputDirectory(_ / "libflow.so")
+ linkerOutput <<= NativeBuild.outputDirectory(_ / "libflow.so"),
+ mappings in (Compile, packageBin) <+= linkerOutput map { out =>
+ out -> ("native/" + System.getProperty("os.name").toLowerCase + "/" + System.getProperty("os.arch").toLowerCase + "/libflow.so")
+ },
+ Keys.`package` in (Compile, packageBin) <<= (Keys.`package` in (Compile, packageBin)).dependsOn(NativeBuild.link)
)
-
+
lazy val runSettings = Seq(
fork := true,
connectInput in run := true,
@@ -41,7 +45,7 @@ object FlowBuild extends Build {
object Dependencies {
lazy val all = Seq()
- //lazy val io = "com.github.scala-incubator.io" %% "scala-io-core" % "0.4.2"
- //lazy val file = "com.github.scala-incubator.io" %% "scala-io-file" % "0.4.2"
+ lazy val io = "com.github.scala-incubator.io" %% "scala-io-core" % "0.4.2"
+ lazy val file = "com.github.scala-incubator.io" %% "scala-io-file" % "0.4.2"
}
diff --git a/project/JNIBuild.scala b/project/JNIBuild.scala
index 95509fb..ed0d05e 100644
--- a/project/JNIBuild.scala
+++ b/project/JNIBuild.scala
@@ -13,9 +13,10 @@ object JNIBuild {
{}
} dependsOn (Keys.compile in Compile)
- val defaults = NativeBuild.defaults ++ Seq(
+ val defaults: Seq[Setting[_]] = NativeBuild.defaults ++ Seq(
javahTask,
- NativeBuild.compile <<= NativeBuild.compile.dependsOn(javah))
+ NativeBuild.compile <<= NativeBuild.compile.dependsOn(javah)
+ )
}
diff --git a/src/main/java/com/github/jodersky/flow/NativeSerial.java b/src/main/java/com/github/jodersky/flow/NativeSerial.java
index 10a82c9..f5d708e 100644
--- a/src/main/java/com/github/jodersky/flow/NativeSerial.java
+++ b/src/main/java/com/github/jodersky/flow/NativeSerial.java
@@ -3,7 +3,7 @@ package com.github.jodersky.flow;
public class NativeSerial {
static {
- System.loadLibrary("flow");
+ NativeLoader.load();
}
final static int E_PERMISSION = -1;
diff --git a/src/main/scala/com/github/jodersky/flow/NativeLoader.scala b/src/main/scala/com/github/jodersky/flow/NativeLoader.scala
new file mode 100644
index 0000000..91b3fd8
--- /dev/null
+++ b/src/main/scala/com/github/jodersky/flow/NativeLoader.scala
@@ -0,0 +1,35 @@
+package com.github.jodersky.flow
+
+import java.io.File
+import java.io.FileOutputStream
+
+object NativeLoader {
+
+ def load = {
+ val os = System.getProperty("os.name").toLowerCase
+ val arch = System.getProperty("os.arch").toLowerCase
+
+ val in = NativeLoader.getClass().getResourceAsStream("/native/" + os + "/" + arch + "/" + "libflow.so")
+ val temp = File.createTempFile("flow" + os + arch, ".so");
+ temp.deleteOnExit()
+ val out = new FileOutputStream(temp);
+
+ try {
+ var read: Int = 0; ;
+ val buffer = new Array[Byte](4096);
+ do {
+ read = in.read(buffer)
+ if (read != -1) {
+ out.write(buffer, 0, read);
+ }
+ } while (read != -1)
+ } finally {
+ in.close()
+ out.close
+ }
+
+ System.load(temp.getAbsolutePath())
+
+ }
+
+} \ No newline at end of file