root/branches/raggi/tasks/cpp.rake

Revision 741, 2.2 kB (checked in by raggi, 11 months ago)

Merge forward from 712 to HEAD from trunk

Line 
1 # EventMachine C++ Rakefile Stab Case
2 # TODO : track header files as a build dependency...
3 # TODO : cross platform support
4 # TODO : configure style functionality
5 namespace :cpp do
6
7   require 'rake/clean'
8
9   # *nix only atm...
10   module Cpp
11     class <<self
12       def cpp; "g++"; end
13       def archive; "ar"; end
14       def compile file, output, includes=nil, flags=nil
15         sh %{#{cpp} #{file} #{includes} #{flags} -c -o #{output}}
16       end
17       def link file, output, libs=nil, flags=nil
18         sh %{#{cpp} #{file} #{libs} #{flags} -o #{output}}
19       end
20       def static output, files
21         sh %{#{archive} cr #{output} #{files}}
22       end
23     end
24   end
25
26   module EmConfig
27     Path = ENV['EVENTMACHINE_SOURCE'] || 'ext'
28     Sources = FileList["#{Path}/*.cpp"]
29     Sources.delete_if { |s| /ruby/ =~ s }
30     Compiled = Sources.sub(%r{^#{Path}/(.*)\.cpp}, "#{Path}/\\1.o")
31
32     Flags = "-O2 -pipe -fno-common -DOS_UNIX -DWITHOUT_SSL"
33     Includes = ""
34     Libs = ''
35   end
36   CLEAN.include(EmConfig::Compiled)
37
38   rule %r{^#{EmConfig::Path}/.*\.o$} => [proc { |targ|
39     targ.sub(%r{^#{EmConfig::Path}/(.*)\.o$}, "#{EmConfig::Path}/\\1.cpp")
40     }] do |t|
41     Cpp.compile t.source, t.name, EmConfig::Includes, EmConfig::Flags
42   end
43
44   file "#{EmConfig::Path}/libeventmachine.a" => EmConfig::Compiled do |t|
45     Cpp.static t.name, EmConfig::Compiled
46   end
47   CLEAN.include("#{EmConfig::Path}/libeventmachine.a")
48
49   module AppConfig
50     Appname = 'echo_em'
51     Sources = FileList['*.cpp']
52     Compiled = Sources.sub(%r{^(.*)\.cpp}, '\\1.o')
53
54     Flags = ["", EmConfig::Flags].join(' ')
55     Includes = ["-I. -I#{EmConfig::Path}", EmConfig::Includes].join(' ')
56     Libs = ["-L#{EmConfig::Path} -leventmachine", EmConfig::Libs].join(' ')
57   end
58   CLEAN.include(AppConfig::Compiled)
59   CLEAN.include(AppConfig::Appname)
60
61   rule %r{^.*\.o$} => [proc { |targ|
62     targ.sub(%r{^(.*)\.o$}, '\\1.cpp')
63     }] do |t|
64     Cpp.compile t.source, t.name, AppConfig::Includes, AppConfig::Flags
65   end
66
67   file AppConfig::Appname => ["#{EmConfig::Path}/libeventmachine.a", AppConfig::Compiled] do |t|
68     Cpp.link AppConfig::Compiled, t.name, AppConfig::Libs, AppConfig::Flags
69   end
70
71   task :build => AppConfig::Appname
72
73   task :run => AppConfig::Appname do
74     sh "./#{AppConfig::Appname}"
75   end
76
77 end
Note: See TracBrowser for help on using the browser.