aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2013-05-21 17:16:23 +0200
committerJakob Odersky <jodersky@gmail.com>2013-05-21 17:16:23 +0200
commit4403f3cfcdba57657918b47d86799a6b10455022 (patch)
tree97a290cf177cdea57d8b8ae0475efa111cc61f45
parent122c6cdd3d8aa598b38a83c3c6aff73eb9fdb14e (diff)
downloadakka-serial-4403f3cfcdba57657918b47d86799a6b10455022.tar.gz
akka-serial-4403f3cfcdba57657918b47d86799a6b10455022.tar.bz2
akka-serial-4403f3cfcdba57657918b47d86799a6b10455022.zip
move native build to sbt
-rw-r--r--Makefile19
-rw-r--r--build.sbt9
-rw-r--r--project/Build.scala43
-rw-r--r--project/NativeBuild.scala75
4 files changed, 118 insertions, 28 deletions
diff --git a/Makefile b/Makefile
deleted file mode 100644
index 01c1b6a..0000000
--- a/Makefile
+++ /dev/null
@@ -1,19 +0,0 @@
-TARGET=target
-SCALA_VERSION=2.10
-CLASSPATH=$(TARGET)/scala-$(SCALA_VERSION)/classes
-TARGETDIR=target
-
-all: flow.so
-
-javah: $(CLASSPATH)
- javah -d src/main/c/ -classpath $(CLASSPATH) com.github.jodersky.flow.NativeSerial
-
-flow.o:
- gcc -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -fPIC -c src/main/c/flow.c -o flow.o
-
-flow.so: flow.o
- gcc -shared -Wl,-soname,libflow.so.1 -o libflow.so $< -lc
-
-clean:
- rm -f *.o
- rm -f *.so
diff --git a/build.sbt b/build.sbt
deleted file mode 100644
index 0ae0f6f..0000000
--- a/build.sbt
+++ /dev/null
@@ -1,9 +0,0 @@
-name := "flow"
-
-scalaVersion := "2.10.1"
-
-fork := true
-
-connectInput in run := true
-
-javaOptions in run += "-Djava.library.path=." \ No newline at end of file
diff --git a/project/Build.scala b/project/Build.scala
new file mode 100644
index 0000000..be1febc
--- /dev/null
+++ b/project/Build.scala
@@ -0,0 +1,43 @@
+import sbt._
+import Keys._
+import NativeBuild._
+
+object FlowBuild extends Build {
+ val Organization = "com.github.jodersky"
+ val Version = "1.0-SNAPSHOT"
+ val ScalaVersion = "2.10.1"
+
+ lazy val root = Project(
+ id = "flow",
+ base = file("."),
+ settings = buildSettings ++ nativeSettings ++ runSettings)
+
+ lazy val buildSettings = Defaults.defaultSettings ++ Seq(
+ organization := Organization,
+ version := Version,
+ scalaVersion := ScalaVersion,
+ resolvers += "Typesafe Repo" at "http://repo.typesafe.com/typesafe/releases/",
+ scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature"),
+ compileOrder in Compile := CompileOrder.JavaThenScala)
+
+ lazy val nativeSettings = NativeBuild.defaults ++ Seq(
+ NativeBuild.compiler := "gcc",
+ options := Seq("-fPIC"),
+ linker := "gcc",
+ linkerOptions := Seq("-shared", "-Wl,-soname,libflow.so.1"),
+ linkerOutput <<= NativeBuild.outputDirectory(_ / "libflow.so")
+ )
+
+ lazy val runSettings = Seq(
+ fork := true,
+ connectInput in run := true,
+ javaOptions in run += "-Djava.library.path=.")
+}
+
+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"
+
+}
diff --git a/project/NativeBuild.scala b/project/NativeBuild.scala
new file mode 100644
index 0000000..a77e8f8
--- /dev/null
+++ b/project/NativeBuild.scala
@@ -0,0 +1,75 @@
+import sbt._
+import Keys._
+
+object NativeBuild {
+
+ //settings
+ val sourceDirectory = SettingKey[File]("native-source-directory", "Native source directory containing files to compile.")
+ val compiler = SettingKey[String]("native-compiler", "Native compiler.")
+ val options = SettingKey[Seq[String]]("native-options", "Flags for native compiler.")
+ val includeDirectories = SettingKey[Seq[File]]("native-include-directories", "Include directories for native compiler.")
+ val outputDirectory = SettingKey[File]("native-output-directory", "Directory for native output.")
+ val linker = SettingKey[String]("native-linker", "Native linker.")
+ val linkerOutput = SettingKey[File]("native-linker-output", "Name of linker output.")
+ val linkerOptions = SettingKey[Seq[String]]("native-linker-options", "Native linker options.")
+ val linkerLibraries = SettingKey[Seq[String]]("native-linker-libraries", "Libraries against which to link.")
+
+ //tasks
+ val outputFromSource = TaskKey[File => File]("native-output-from-source", "Get name of native binary from source file.")
+ val sources = TaskKey[Seq[File]]("native-source", "Native source files to compile.")
+ val makeOutputDirectory = TaskKey[Unit]("native-make-output-directory", "Make native output directory.")
+ val compile = TaskKey[Unit]("native-compile", "Compiles native sources.")
+ val link = TaskKey[Unit]("native-link", "Link native sources.")
+
+ //task implementations
+ val outputFromSourceTask = outputFromSource <<= (outputDirectory) map {
+ outputDir =>
+ ((src: File) => {file((outputDir / src.base).absolutePath + ".o")})
+ }
+
+ val makeOutputDirectoryTask = makeOutputDirectory <<= (outputDirectory) map {o => o.mkdirs(); {}}
+
+ def compileSingleFile(compiler: String, options: Seq[String], includeDirectories: Seq[File], source: File, s2o: File => File): Unit = {
+ val cmdParts =
+ List(compiler) ++
+ options ++
+ includeDirectories.map(i => "-I" + i.absolutePath) ++
+ List("-c", source.absolutePath) ++
+ List("-o", s2o(source))
+
+ val cmd = cmdParts.mkString(" ")
+ cmd !
+ }
+
+ val compileTask = compile <<= (compiler, options, includeDirectories, sources, outputFromSource) map {
+ (c, f, i, srcs, out) => for (s <- srcs) compileSingleFile(c,f,i,s,out)
+ } dependsOn(makeOutputDirectory)
+
+ val linkTask = link <<= (linker, linkerOptions, linkerLibraries, linkerOutput, sources, outputFromSource) map { (l, opts, libs, out, srcs, s2o) =>
+ val outs = srcs.map(s2o(_))
+ val cmd: Seq[String] = Seq(l) ++ opts ++ Seq("-o", out.absolutePath) ++ outs.map(_.absolutePath) ++ libs.map(lib => "-l" + lib)
+ cmd !;
+ {}
+ } dependsOn(compile)
+
+
+
+ lazy val defaults = Seq(
+ compiler := "gcc",
+ options := Seq(),
+ sourceDirectory <<= Keys.sourceDirectory(_ / "main" / "c"),
+ sources <<= sourceDirectory map (dir => (dir ** "*.c").get),
+ includeDirectories <<= sourceDirectory(dir => Seq(dir)),
+ outputDirectory <<= target(_ / "c"),
+ linker := "gcc",
+ linkerOutput <<= outputDirectory(_ / "a.out"),
+ linkerOptions := Seq(),
+ linkerLibraries := Seq(),
+
+ outputFromSourceTask,
+ makeOutputDirectoryTask,
+ compileTask,
+ linkTask
+ )
+
+} \ No newline at end of file