rakepp 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -4,15 +4,15 @@ require 'rake/gempackagetask'
4
4
  desc "Default Task"
5
5
  task :default => :package
6
6
 
7
- PKG_VERSION = '0.0.1'
7
+ PKG_VERSION = '0.1.0'
8
8
  PKG_FILES = FileList[
9
- 'lib/**/*.rb',
9
+ 'lib/**/*.rb',
10
10
  '*.xml',
11
11
  'Rakefile'
12
12
  # 'test/**/*.rb',
13
13
  # 'doc/**/*'
14
14
  ]
15
-
15
+
16
16
  spec = Gem::Specification.new do |s|
17
17
  s.name = 'rakepp'
18
18
  s.version = PKG_VERSION
@@ -22,16 +22,14 @@ spec = Gem::Specification.new do |s|
22
22
  EOF
23
23
  s.files = PKG_FILES.to_a
24
24
  s.require_path = 'lib'
25
- s.autorequire = 'rakepp'
26
25
  # s.has_rdoc = true
27
26
  s.author = "Christian Koestlin"
28
27
  s.email = 'gizmoATflopcodeDOTcom'
29
- s.homepage = "[http address which can't be saved due to external link blocker...]"
30
- s.rubyforge_project = "rakepp"
28
+ s.homepage = 'http://www.flopcode.com'
29
+ s.rubyforge_project = 'rakepp'
31
30
  s.add_dependency('progressbar', '>=0.0.3')
32
- end
33
-
34
-
31
+ end
32
+
35
33
  Rake::GemPackageTask.new(spec) do |pkg|
36
34
  # pkg.need_tar = true
37
35
  # pkg.need_zip = true
data/lib/rakepp/all.rb ADDED
@@ -0,0 +1,29 @@
1
+ class All
2
+ @@tasks = Array.new
3
+ @@objects = Array.new
4
+ @@depFiles = Array.new
5
+
6
+ def self.add(task)
7
+ @@tasks << task
8
+ end
9
+
10
+ def self.addObject(o)
11
+ @@objects << o
12
+ end
13
+ def self.addDepFile(filename)
14
+ @@depFiles << filename
15
+ end
16
+
17
+ def self.tasks
18
+ return @@tasks
19
+ end
20
+
21
+ def self.objects
22
+ return @@objects
23
+ end
24
+
25
+ def self.depFiles
26
+ return @@depFiles
27
+ end
28
+
29
+ end
@@ -0,0 +1,13 @@
1
+ class BinaryLib
2
+ attr_reader :name, :includes, :outFile, :libs, :path
3
+ attr_writer :outFile
4
+
5
+ def initialize(compiler, name, libs=[], includes=[], path=nil)
6
+ @name = name
7
+ @libs = libs
8
+ @includes = includes
9
+ @path = path
10
+ compiler.addTasks(self)
11
+ end
12
+
13
+ end
@@ -0,0 +1,17 @@
1
+ class Cleaner
2
+ def initialize()
3
+
4
+ desc "Clean all artifacts"
5
+ task :clean do
6
+ Rake::Task.tasks.reverse_each do | t |
7
+ FileUtils.rm_rf(t.name) if File.exists?(t.name)
8
+ end
9
+ end
10
+
11
+ desc "Force Recalc of dependencies"
12
+ task :cleanDeps do
13
+ All.depFiles.each {|f|FileUtils.rm(f)}
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ class Compiler
2
+ attr_reader :targetDir
3
+ def initialize(targetDir, defines)
4
+ @targetDir = targetDir
5
+ @defines = defines
6
+ end
7
+ def addTasks(artifact)
8
+ if (artifact.instance_of?(Exe)) then
9
+ addExeTasks(artifact)
10
+ elsif (artifact.instance_of?(SourceLib)) then
11
+ addSourceLibTasks(artifact)
12
+ elsif (artifact.instance_of?(ObjectFile)) then
13
+ addObjectTasks(artifact)
14
+ elsif (artifact.instance_of?(Framework)) then
15
+ addFrameworkTasks(artifact)
16
+ elsif (artifact.instance_of?(BinaryLib)) then
17
+ addBinaryLibTasks(artifact)
18
+ elsif (artifact.instance_of?(SharedLib)) then
19
+ addSharedLibTasks(artifact)
20
+ else
21
+ raise "unknown type " + artifact.to_s
22
+ end
23
+ end
24
+ end
data/lib/rakepp/exe.rb ADDED
@@ -0,0 +1,5 @@
1
+ class Exe < SourceLib
2
+ def initialize(compiler, base, name, sources, libs, includes)
3
+ super(compiler, base, name, sources, libs, includes)
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ require 'pathname'
2
+
3
+ class Files
4
+ def self.relative(base, pattern)
5
+ globPattern = Pathname.new(base) + pattern
6
+ return Pathname.glob(globPattern.to_s).collect do |path|
7
+ f = path.to_s
8
+ SourceFile.new(f, f.sub(base, ''))
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ class Framework < BinaryLib
2
+ def initialize(compiler, name, libs)
3
+ super(compiler, name, libs, ["/System/Library/Frameworks/#{name}.framework/Versions/Current/Headers"])
4
+ end
5
+ end
@@ -0,0 +1,205 @@
1
+ require 'rubygems'
2
+ require 'progressbar'
3
+ require 'yaml'
4
+
5
+ class GccCompiler < Compiler
6
+ def addObjectTasks(artifact)
7
+ outName = File.join(artifact.targetDir, artifact.source.to_o)
8
+ artifact.outFile = outName
9
+ depFile = artifact.depFile
10
+
11
+ depFileTask = file depFile => artifact.source.fullPath do | task |
12
+ calcDependencies(artifact, depFile)
13
+ end
14
+
15
+ outFile = file outName => depFile do |task|
16
+ command = "#{compiler(artifact)} -c #{defines(artifact)} #{includes(artifact)} -o #{outName} #{artifact.source.fullPath}"
17
+ sh command
18
+ end
19
+
20
+ applyTask = task "#{depFile}.apply" => depFile do |task|
21
+ deps = YAML.load_file(depFile)
22
+ if (deps)
23
+ outFile.enhance(deps)
24
+ depFileTask.enhance(deps[1..-1])
25
+ end
26
+ end
27
+
28
+ outFile.enhance([applyTask])
29
+
30
+ directory artifact.targetDir
31
+ directory File.dirname(outName)
32
+
33
+ dirs = [artifact.targetDir, File.dirname(outName)]
34
+ outFile.enhance(dirs)
35
+ depFileTask.enhance(dirs)
36
+
37
+ All.addObject(artifact)
38
+ All.addDepFile(depFile)
39
+ end
40
+
41
+ def compiler(artifact)
42
+ if ((artifact.source.fullPath.index(".cpp") != nil) ||
43
+ (artifact.source.fullPath.index(".cxx") != nil)) then
44
+ return "g++ -arch #{ARCH} #{OPTIMIZE} -Wall"
45
+ else
46
+ return "gcc -arch #{ARCH} #{OPTIMIZE} -Wall"
47
+ end
48
+ end
49
+
50
+ def defines(artifact)
51
+ res = ""
52
+ allDefines = @defines + artifact.privateDefines
53
+ allDefines.each do |define|
54
+ res << "-D#{define} "
55
+ end
56
+ return res
57
+ end
58
+
59
+ def includes(artifact)
60
+ res = ""
61
+ artifact.includes.each do |aInclude|
62
+ res << "-I#{aInclude} "
63
+ end
64
+ return res
65
+ end
66
+
67
+ def calcDependencies(artifact, taskToEnhance)
68
+ source = artifact.source
69
+ command = "#{compiler(artifact)} -MM #{defines(artifact)} #{includes(artifact)} #{source.fullPath}"
70
+ puts command
71
+ deps = `#{command}`
72
+ if deps.length == 0
73
+ raise 'cannot calc dependencies'
74
+ end
75
+ deps = deps.gsub(/\\\n/,'').split()[1..-1]
76
+ File.open(artifact.depFile, 'wb') do |f|
77
+ f.write(deps.to_yaml)
78
+ end
79
+ end
80
+ def startOfSourceLibCommand(outName, artifact)
81
+ return "ar -r #{outName}"
82
+ end
83
+
84
+ def addSourceLibTasks(artifact)
85
+ outDir = File.join(@targetDir, artifact.name)
86
+
87
+ objects = []
88
+ artifact.sources.each do |source|
89
+ objects << ObjectFile.new(self, source, outDir, artifact.tr_includes, artifact.privateDefines).outFile
90
+ end
91
+
92
+ libsName = File.join(@targetDir, 'libs')
93
+ outName = File.join(libsName, "lib#{artifact.name}.a")
94
+
95
+ artifact.outFile = outName
96
+ desc "Create SourceLib #{outName}"
97
+ theTask = file outName => objects do | task |
98
+ command = startOfSourceLibCommand(outName, artifact)
99
+ objects.each do | o |
100
+ command += " #{o}"
101
+ end
102
+ sh command
103
+ end
104
+
105
+ addTransitiveLibraryPrerequisites(theTask, artifact)
106
+
107
+ file outName => [libsName]
108
+ All.add(outName)
109
+ directory libsName
110
+ end
111
+
112
+ def addSharedLibTasks(artifact)
113
+ outDir = File.join(@targetDir, artifact.name)
114
+ objects = []
115
+ artifact.sources.each do |source|
116
+ objects << ObjectFile.new(self, source, outDir, artifact.tr_includes, artifact.privateDefines).outFile
117
+ end
118
+ libsName = File.join(@targetDir, 'libs')
119
+ outName = File.join(libsName, "#{artifact.name}.#{sharedExtension}")
120
+ artifact.outFile = outName
121
+ desc "Create SharedLib #{outName}"
122
+ theTask = file outName => objects do | task |
123
+ command = startOfSharedLibCommand(outName, artifact)
124
+ objects.each do |o|
125
+ command += " #{o}"
126
+ end
127
+
128
+ LibHelper.tr_libs(artifact.libs).each do |lib|
129
+ command += addLib(task, lib)
130
+ end
131
+
132
+ command += " -o #{outName}"
133
+ sh command
134
+ end
135
+
136
+ addTransitiveLibraryPrerequisites(theTask, artifact)
137
+
138
+ file outName => [libsName]
139
+ All.add(outName)
140
+ directory libsName
141
+ end
142
+
143
+ def addBinaryLibTasks(artifact)
144
+ artifact.outFile = "lib#{artifact.name}.a"
145
+ end
146
+
147
+ def addFrameworkTasks(artifact)
148
+ artifact.outFile = artifact.name
149
+ end
150
+
151
+
152
+ def addExeTasks(artifact)
153
+ outDir = File.join(@targetDir, artifact.name)
154
+
155
+ objects = []
156
+ artifact.sources.each do |source|
157
+ objects << ObjectFile.new(self, source, outDir, artifact.tr_includes).outFile
158
+ end
159
+
160
+ exesName = File.join(@targetDir, 'exes')
161
+ artifact.outFile = File.join(exesName, artifact.name + '.exe')
162
+ desc "Create Exe #{artifact.outFile}"
163
+ theTask = file artifact.outFile => objects do | task |
164
+ command = "g++ -arch #{ARCH} -o #{artifact.outFile}"
165
+ objects.each do |o|
166
+ command += " #{o}"
167
+ end
168
+
169
+ LibHelper.tr_libs(artifact.libs).each do |lib|
170
+ command += addLib(task, lib)
171
+ end
172
+
173
+ sh command
174
+ doAdditionalWorkForExe(artifact)
175
+ end
176
+
177
+ addTransitiveLibraryPrerequisites(theTask, artifact)
178
+
179
+ file artifact.outFile => [exesName]
180
+ All.add(artifact.outFile)
181
+ directory exesName
182
+ end
183
+
184
+ def doAdditionalWorkForExe(artifact)
185
+ end
186
+
187
+ def addTransitiveLibraryPrerequisites(theTask, artifact)
188
+ LibHelper.tr_libs(artifact.libs).each do |lib|
189
+ theTask.prerequisites << lib.outFile unless lib.kind_of?(BinaryLib)
190
+ end
191
+ end
192
+
193
+ def addLib(task, lib)
194
+ if (lib.instance_of?(BinaryLib)) then
195
+ return " -L#{lib.path||'/usr/lib'} -l#{lib.name} "
196
+ elsif (lib.instance_of?(SourceLib)) then
197
+ return " -L#{targetDir}/libs -l#{lib.name}"
198
+ elsif (lib.instance_of?(SharedLib)) then
199
+ return " #{targetDir}/libs/#{lib.name}.so "
200
+ else
201
+ raise "#{lib} not supported"
202
+ end
203
+ end
204
+
205
+ end
@@ -0,0 +1,25 @@
1
+ class GccWin32Compiler < GccCompiler
2
+ def initialize(defines)
3
+ super('w32', defines)
4
+ end
5
+
6
+ def startOfSharedLibCommand(libName)
7
+ return "g++ -shared -Wl,--out-implib=#{libName}.a"
8
+ end
9
+
10
+ def sharedExtension
11
+ return 'dll'
12
+ end
13
+
14
+ def addLib(task, lib)
15
+ if (lib.instance_of?(BinaryLib)) then
16
+ return " -l#{lib.name}"
17
+ elsif (lib.instance_of?(SourceLib)) then
18
+ return " -L#{targetDir}/libs -l#{lib.name}"
19
+ elsif (lib.instance_of?(SharedLib)) then
20
+ return " #{targetDir}/libs/#{lib.name}.#{sharedExtension}.a"
21
+ else
22
+ raise "#{lib} not supported"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,29 @@
1
+ class LibHelper
2
+
3
+ attr_reader :all_libs
4
+
5
+ def self.tr_libs(libs)
6
+ return LibHelper.new(libs).all_libs
7
+ end
8
+
9
+ private
10
+
11
+ def addUnique(lib)
12
+ @all_libs.delete(lib)
13
+ @all_libs.push(lib)
14
+ end
15
+
16
+ def add(lib)
17
+ addUnique(lib)
18
+ lib.libs.each do |aLib|
19
+ add(aLib)
20
+ end
21
+ end
22
+
23
+ def initialize(libs)
24
+ @all_libs = Array.new
25
+ libs.each do | lib |
26
+ add(lib)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ class LinuxCompiler < GccCompiler
2
+ def initialize(defines)
3
+ super('linux', defines)
4
+ end
5
+ def startOfSharedLibCommand(libName, artifact)
6
+ return "g++ -shared"
7
+ end
8
+ def sharedExtension
9
+ return 'so'
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ class ObjectFile
2
+ attr_reader :source, :targetDir, :includes, :outFile, :privateDefines
3
+ attr_writer :outFile
4
+ def initialize(compiler, source, targetDir, includes, privateDefines=[])
5
+ @source = source
6
+ @targetDir = targetDir
7
+ @includes = includes
8
+ @privateDefines = privateDefines
9
+ compiler.addTasks(self)
10
+ end
11
+ def depFile()
12
+ return "#{outFile}.dependencies"
13
+ end
14
+ end
data/lib/rakepp/os.rb ADDED
@@ -0,0 +1,11 @@
1
+ class OS
2
+ def self.windows?
3
+ return (RUBY_PLATFORM =~ /win32/i) != nil
4
+ end
5
+ def self.osx?
6
+ return RUBY_PLATFORM.index('darwin') != nil
7
+ end
8
+ def self.linux?
9
+ return RUBY_PLATFORM.index('linux') != nil
10
+ end
11
+ end
@@ -0,0 +1,38 @@
1
+ class OsxCompiler < GccCompiler
2
+
3
+ def initialize(defines, gui=true)
4
+ super('osx', defines)
5
+ @gui = gui
6
+ end
7
+
8
+ def startOfSourceLibCommand(outname, artifact)
9
+ return "libtool -static -arch_only #{ARCH} -o #{outname}"
10
+ end
11
+
12
+ def startOfSharedLibCommand(libName, artifact)
13
+ name = artifact.options[:name]
14
+ if name == nil
15
+ name = File.basename(libName)
16
+ end
17
+ return "g++ -arch #{ARCH} -dynamiclib -install_name #{name}"
18
+ end
19
+
20
+ def sharedExtension
21
+ return 'so'
22
+ end
23
+
24
+ def addLib(task, lib)
25
+ if (lib.instance_of?(Framework)) then
26
+ return " -framework #{lib.name}"
27
+ else
28
+ return super(task, lib)
29
+ end
30
+ end
31
+
32
+ def doAdditionalWorkForExe(artifact)
33
+ if @gui
34
+ sh "/Developer/Tools/Rez -o #{artifact.outFile} appResources.r"
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,9 @@
1
+ class SharedLib < SourceLib
2
+ attr_reader :options
3
+
4
+ def initialize(compiler, base, name, sources, libs, includes, options={}, privateDefines=[])
5
+ super(compiler, base, name, sources, libs, includes, privateDefines)
6
+ @options = options
7
+ end
8
+
9
+ end
@@ -0,0 +1,16 @@
1
+ class SourceFile
2
+ attr_reader :fullPath, :fileName
3
+ def initialize(fullPath, fileName)
4
+ @fullPath = fullPath
5
+ @fileName = fileName
6
+ end
7
+
8
+ def to_o
9
+ return fileName.sub(/\.[^.]+$/, '.o')
10
+ end
11
+
12
+ def to_s
13
+ return "SourceFile #{fullPath}"
14
+ end
15
+
16
+ end
@@ -0,0 +1,30 @@
1
+ class SourceLib
2
+ attr_reader :name, :sources, :includes, :outFile, :libs, :privateDefines
3
+ attr_writer :outFile, :privateDefines
4
+ def initialize(compiler, base, name, sources, libs, includes, privateDefines=[])
5
+ @name = name
6
+ @sources = sources
7
+ @libs = libs
8
+ @includes = includes.collect do |i|
9
+ if (i[0].chr == '/')
10
+ i
11
+ else
12
+ File.join(base, i)
13
+ end
14
+ end
15
+ @privateDefines = privateDefines
16
+ compiler.addTasks(self)
17
+ end
18
+
19
+ def tr_includes
20
+ res = Array.new(@includes)
21
+ LibHelper.tr_libs(libs).each do |lib|
22
+ if !res.include?(lib) then
23
+ lib.includes.each do |i|
24
+ res << i unless res.include?(i)
25
+ end
26
+ end
27
+ end
28
+ return res
29
+ end
30
+ end
data/lib/rakepp.rb CHANGED
@@ -1,9 +1,27 @@
1
- require 'rakepp/Gcc'
2
- require 'rakepp/Msvt'
3
- require 'rakepp/CompilerHelper'
4
- require 'rakepp/SourceLib'
5
- require 'rakepp/BinaryLib'
6
- require 'rakepp/Files'
7
- require 'rakepp/Framework'
8
- require 'rakepp/Exe'
9
- require 'rakepp/DependencyHandler'
1
+ require 'rakepp/os'
2
+
3
+ #OPTIMIZE = '-O3'
4
+ #OPTIMIZE = ''
5
+
6
+ #if OS.osx?
7
+ # ARCH = '-arch i386 -O0 -gdwarf-2 -mfix-and-continue -fmessage-length=0'
8
+ #else
9
+ # ARCH = ''
10
+ #end
11
+
12
+ require 'rakepp/cleaner'
13
+ require 'rakepp/all'
14
+ require 'rakepp/compiler'
15
+ require 'rakepp/gcccompiler'
16
+ require 'rakepp/linuxcompiler'
17
+ require 'rakepp/osxcompiler'
18
+ require 'rakepp/gccwin32compiler'
19
+ require 'rakepp/libhelper'
20
+ require 'rakepp/sourcelib'
21
+ require 'rakepp/sharedlib'
22
+ require 'rakepp/exe'
23
+ require 'rakepp/objectfile'
24
+ require 'rakepp/sourcefile'
25
+ require 'rakepp/binarylib'
26
+ require 'rakepp/framework'
27
+ require 'rakepp/files'