Permalink
Browse files

Add Rakefile and rakelib

  • Loading branch information...
nasser committed Aug 10, 2011
1 parent 4305849 commit ab74f13a36a37df990436704241557007f502c62
Showing with 68 additions and 0 deletions.
  1. +44 −0 Rakefile
  2. +15 −0 rakelib/cli.rake
  3. +9 −0 rakelib/helpers.rb
View
@@ -0,0 +1,44 @@
+require "rakelib/helpers.rb"
+
+ZAJAL_DIR = "src"
+BUILD_DIR = "build"
+BIN_DIR = "bin"
+BINARY = "#{BIN_DIR}/zajal"
+LIBRARY = "#{BIN_DIR}/libzajal.a"
+CLI_FRONTEND_DIR = "frontends/cli"
+
+DEFINES = PrefixArray.new "-D"
+DEFINES << "HAVE_STRUCT_TIMEZONE"
+DEFINES << "HAVE_STRUCT_TIMESPEC"
+DEFINES << "OF_SOUND_PLAYER_QUICKTIME"
+
+CC = "gcc"
+CXX = "g++"
+CXXFLAGS = "-arch i386 -g #{DEFINES}"
+GIT = "git"
+
+# openFrameworks
+OF_DIR = "lib/openframeworks"
+OF_LIB = "#{OF_DIR}/libof.a"
+OF_INCLUDE_DIR = "#{OF_DIR}/include"
+OF_INCLUDES = PrefixArray.new "-idirafter ", Dir["#{OF_INCLUDE_DIR}/**/*/"]
+OF_FRAMEWORKS = PrefixArray.new "-framework ", %w[OpenGL Glut QuickTime CoreAudio Carbon]
+
+# ruby
+RUBY_DIR = "lib/ruby"
+RUBY_LIB = "#{RUBY_DIR}/libruby.a"
+RUBY_INCLUDE_DIR = "#{RUBY_DIR}/include"
+RUBY_INCLUDES = PrefixArray.new "-I", Dir["#{RUBY_INCLUDE_DIR}/**/*/"]
+RUBY_INCLUDES << RUBY_INCLUDE_DIR
+
+# zajal interperter
+ZAJAL_GIT_BRANCH = `#{GIT} name-rev --name-only HEAD`
+ZAJAL_GIT_HASH = `#{GIT} log -1 --pretty=format:%H`
+ZAJAL_GIT_SHORT_HASH = `#{GIT} log -1 --pretty=format:%h`
+
+ZAJAL_INCLUDES = "-I#{ZAJAL_DIR}"
+ZAJAL_SRC = Dir["#{ZAJAL_DIR}/*.cc"] + Dir["#{CLI_FRONTEND_DIR}/*.cc"]
+ZAJAL_OBJ = ZAJAL_SRC.map { |f| f.sub("cc", "o") }
+ZAJAL_LIBRARIES = "#{OF_LIB} #{RUBY_LIB}"
+
+task :default => "cli:bin"
View
@@ -0,0 +1,15 @@
+namespace :cli do
+ desc "Make CLI binary"
+ task :bin => BINARY do
+ puts "Built Zajal #{ZAJAL_GIT_SHORT_HASH} CLI binary to #{BINARY}"
+ end
+
+ file BINARY => ZAJAL_OBJ do
+ directory BIN_DIR
+ sh "#{CXX} #{CXXFLAGS} #{OF_INCLUDES} #{RUBY_INCLUDES} #{ZAJAL_INCLUDES} #{OF_FRAMEWORKS} #{ZAJAL_LIBRARIES} #{ZAJAL_OBJ.join " "} -o #{BINARY}"
+ end
+
+ rule ".o" => ".cc" do |t|
+ sh "#{CXX} #{CXXFLAGS} #{OF_INCLUDES} #{RUBY_INCLUDES} #{ZAJAL_INCLUDES} -c -o #{t.name} #{t.source}"
+ end
+end
View
@@ -0,0 +1,9 @@
+class PrefixArray < Array
+ def initialize pfx, *args; @pfx = pfx; super *args end
+ def to_s; map { |i| @pfx + i }.join " " end
+end
+
+class SuffixArray < Array
+ def initialize sfx, *args; @sfx = sfx; super *args end
+ def to_s; map { |i| i + @sfx }.join " " end
+end

0 comments on commit ab74f13

Please sign in to comment.