GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: a tiny graphical app kit for ruby
Homepage: http://code.whytheluckystiff.net/shoes
Clone URL: git://github.com/why/shoes.git
commit  16c8da4a22da7023abd2800a3ecaa9642a03b47a
tree    2519e5c87d8a7b799f5519d07ede64ac511ba65e
parent  bcad64c008afbe6ad5db2a217356d6ff615d544e
shoes / Rakefile
100644 446 lines (399 sloc) 16.823 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
require 'rake'
require 'rake/clean'
require 'platform/skel'
require 'fileutils'
require 'find'
include FileUtils
 
APPNAME = ENV['APPNAME'] || "Shoes"
RELEASE_ID, RELEASE_NAME = 2, "Raisins"
NAME = APPNAME.downcase.gsub(/\W+/, '')
SONAME = 'shoes'
REVISION = (`#{ENV['GIT'] || "git"} rev-list HEAD`.split.length + 1).to_s
VERS = ENV['VERSION'] || "0.r#{REVISION}"
PKG = "#{NAME}-#{VERS}"
APPARGS = ENV['APPARGS']
FLAGS = %w[DEBUG VIDEO]
 
BIN = "*.{bundle,jar,o,so,obj,pdb,pch,res,lib,def,exp,exe,ilk}"
CLEAN.include ["{bin,shoes}/#{BIN}", "dist"]
 
# Guess the environment
unless ENV['MSVC'] or ENV['DDKBUILDENV']
  if ENV['MSVCDir']
    ENV['MSVC'] = ENV['MSVCDir']
  elsif ENV['VS71COMNTOOLS']
    ENV['MSVC'] = File.expand_path("../../Vc7", ENV['VS71COMNTOOLS'])
  elsif ENV['VCToolkitInstallDir']
    ENV['MSVC'] = ENV['VCToolkitInstallDir']
  end
end
 
# Check the environment
def env(x)
  unless ENV[x]
    abort "Your #{x} environment variable is not set!"
  end
  ENV[x]
end
 
# Subs in special variables
def rewrite before, after, reg = /\#\{(\w+)\}/, reg2 = '\1'
  File.open(after, 'w') do |a|
    File.open(before) do |b|
      b.each do |line|
        a << line.gsub(reg) do
          if reg2.include? '\1'
            reg2.gsub(%r!\\1!, Object.const_get($1))
          else
            reg2
          end
        end
      end
    end
  end
end
 
def copy_files glob, dir
  FileList[glob].each { |f| cp f, dir }
end
 
ruby_so = Config::CONFIG['RUBY_SO_NAME']
ext_ruby = "deps/ruby"
unless File.exists? ext_ruby
  ext_ruby = Config::CONFIG['prefix']
end
 
desc "Same as `rake build'"
task :default => [:build]
 
desc "Does a full compile, with installer"
task :package => [:build, :installer]
 
task "shoes/version.h" do |t|
  File.open(t.name, 'w') do |f|
    f << %{#define SHOES_RELEASE_ID #{RELEASE_ID}\n#define SHOES_RELEASE_NAME "#{RELEASE_NAME}"\n#define SHOES_REVISION #{REVISION}\n#define SHOES_BUILD_DATE #{Time.now.strftime("%Y%m%d")}\n#define SHOES_PLATFORM "#{RUBY_PLATFORM}"\n}
  end
end
 
task "dist/VERSION.txt" do |t|
  File.open(t.name, 'w') do |f|
    f << %{shoes #{RELEASE_NAME.downcase} (0.r#{REVISION})\n}
  end
end
 
desc "Does a full compile, for the OS you're running on"
task :build => [:build_os, "dist/VERSION.txt"] do
  mkdir_p "dist/ruby"
  cp_r "#{ext_ruby}/lib/ruby/1.8", "dist/ruby/lib"
  unless ENV['STANDARD']
    %w[rdoc rss soap wsdl xsd].each do |libn|
      rm_rf "dist/ruby/lib/#{libn}"
    end
  end
  %w[req/rubygems/* req/sqlite3/lib/* req/hpricot/lib/* req/ftsearch/lib/*].each do |rdir|
    FileList[rdir].each { |rlib| cp_r rlib, "dist/ruby/lib" }
  end
  %w[req/binject/ext/binject_c req/sqlite3/ext/sqlite3_api req/hpricot/ext/hpricot_scan req/ftsearch/ext/ftsearchrt].each do |xdir|
    case PLATFORM when /win32/, /darwin/
      copy_files "#{xdir}/*.dll", "dist/ruby/lib/#{RUBY_PLATFORM}"
    else
      Dir.chdir(xdir) do
        `ruby extconf.rb; make`
      end
      copy_files "#{xdir}/*.so", "dist/ruby/lib/#{RUBY_PLATFORM}"
    end
  end
 
  case PLATFORM when /win32/
    copy_files "#{ext_ruby}/bin/*", "dist/"
    copy_files "deps/cairo/bin/*", "dist/"
    copy_files "deps/pango/bin/*", "dist/"
    if ENV['VIDEO']
      copy_files "deps/vlc/bin/*", "dist/"
    end
  when /darwin/
    if ENV['SHOES_DEPS_PATH']
      dylibs = %w[lib/libcairo.2.dylib lib/libpixman-1.0.dylib lib/libgmodule-2.0.0.dylib lib/libintl.8.dylib lib/libruby.dylib
lib/libglib-2.0.0.dylib lib/libgobject-2.0.0.dylib lib/libpng12.0.dylib lib/libpango-1.0.0.dylib
lib/pango/1.6.0/modules/pango-basic-atsui.la lib/libpangocairo-1.0.0.dylib
lib/pango/1.6.0/modules/pango-basic-atsui.so etc/pango/pango.modules
lib/pango/1.6.0/modules/pango-arabic-lang.so lib/pango/1.6.0/modules/pango-arabic-lang.la
lib/pango/1.6.0/modules/pango-indic-lang.so lib/pango/1.6.0/modules/pango-indic-lang.la
lib/libjpeg.62.dylib lib/libungif.4.dylib]
      if ENV['VIDEO']
        dylibs.push *%w[lib/liba52.0.dylib lib/libfaac.0.dylib lib/libfaad.0.dylib lib/libmp3lame.0.dylib
lib/libvorbis.0.dylib lib/libogg.0.dylib
lib/libvorbisenc.2.dylib lib/libpostproc.dylib lib/libavformat.dylib lib/libavcodec.dylib lib/libavutil.dylib]
      end
      dylibs.each do |libn|
        cp "#{ENV['SHOES_DEPS_PATH']}/#{libn}", "dist/"
      end.each do |libn|
        next unless libn =~ %r!^lib/(.+?\.dylib)$!
        libf = $1
        sh "install_name_tool -id /tmp/dep/#{libn} dist/#{libf}"
        ['dist/shoes-bin', *Dir['dist/*.dylib']].each do |lib2|
          sh "install_name_tool -change /tmp/dep/#{libn} @executable_path/#{libf} #{lib2}"
        end
      end
      if ENV['VIDEO']
        mkdir_p "dist/plugins"
        sh "cp -r deps/lib/vlc/**/*.dylib dist/plugins"
        sh "strip -x dist/*.dylib"
        sh "strip -x dist/plugins/*.dylib"
        sh "strip -x dist/ruby/lib/**/*.bundle"
      end
    end
  else
    cp "#{ext_ruby}/lib/lib#{ruby_so}.so", "dist/lib#{ruby_so}.so.1.8"
    cp "/usr/lib/libgif.so", "dist/libgif.so.4"
    cp "/usr/lib/libjpeg.so", "dist/libjpeg.so.62"
    if ENV['VIDEO']
      cp "/usr/lib/libvlc.so", "dist"
      ln_s "libvlc.so", "dist/libvlc.so.0"
    end
    sh "strip -x dist/*.so.*"
    sh "strip -x dist/*.so"
  end
 
  cp_r "lib", "dist/lib"
  cp_r "samples", "dist/samples"
  cp_r "static", "dist/static"
  cp "README", "dist/README.txt"
  cp "CHANGELOG", "dist/CHANGELOG.txt"
  cp "COPYING", "dist/COPYING.txt"
  
  case PLATFORM when /darwin/
    rm_rf "#{APPNAME}.app"
    mkdir "#{APPNAME}.app"
    mkdir "#{APPNAME}.app/Contents"
    cp_r "dist", "#{APPNAME}.app/Contents/MacOS"
    mkdir "#{APPNAME}.app/Contents/Resources"
    mkdir "#{APPNAME}.app/Contents/Resources/English.lproj"
    sh "ditto static/Shoes.icns #{APPNAME}.app/"
    sh "ditto static/Shoes.icns #{APPNAME}.app/Contents/Resources/"
    rewrite "platform/mac/Info.plist", "#{APPNAME}.app/Contents/Info.plist"
    cp "platform/mac/version.plist", "#{APPNAME}.app/Contents/"
    cp "platform/mac/pangorc", "#{APPNAME}.app/Contents/MacOS/"
    cp "platform/mac/command-manual.rb", "#{APPNAME}.app/Contents/MacOS/"
    rewrite "platform/mac/shoes-launch", "#{APPNAME}.app/Contents/MacOS/shoes-launch"
    chmod 0755, "#{APPNAME}.app/Contents/MacOS/shoes-launch"
    rewrite "platform/mac/shoes", "#{APPNAME}.app/Contents/MacOS/shoes"
    chmod 0755, "#{APPNAME}.app/Contents/MacOS/shoes"
    # cp InfoPlist.strings YourApp.app/Contents/Resources/English.lproj/
    `echo -n 'APPL????' > "#{APPNAME}.app/Contents/PkgInfo"`
  when /win32/
    cp "platform/msw/shoes.exe.manifest", "dist/#{NAME}.exe.manifest"
    cp "dist/zlib1.dll", "dist/zlib.dll"
  end
end
 
# use the platform Ruby claims
case PLATFORM
when /win32/
  SRC = FileList["shoes/*.c", "shoes/native/windows.c", "shoes/http/winhttp.c"]
  OBJ = SRC.map do |x|
    x.gsub(/\.c$/, '.obj')
  end
 
  # MSVC build environment
  MSVC_LIBS = %[msvcrt-ruby18.lib pango-1.0.lib pangocairo-1.0.lib gobject-2.0.lib glib-2.0.lib cairo.lib giflib.lib jpeg.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib shell32.lib comctl32.lib ole32.lib oleaut32.lib advapi32.lib oleacc.lib winhttp.lib]
  MSVC_LIBS << " libvlc.lib" if ENV['VIDEO']
  MSVC_LIBS2 = ""
  MSVC_LIBS2 << " bufferoverflowu.lib" if ENV['DDKBUILDENV']
  MSVC_LIBS << MSVC_LIBS2
 
  MSVC_CFLAGS = %q[/ML /DWIN32 /DSHOES_WIN32 /DWIN32_LEAN_AND_MEAN /DCINTERFACE /DCOBJMACROS
/Ideps\vlc\include
/Ideps\cairo\include
/Ideps\cairo\include\cairo
/Ideps\pango\include\pango-1.0
/Ideps\pango\include\glib-2.0
/Ideps\pango\lib\glib-2.0\include
/Ideps\ruby\lib\ruby\1.8\i386-mswin32
/Ideps\curl\include
/I.
/O2 /GR /EHsc
].gsub(/\n\s*/, ' ')
 
  MSVC_LDFLAGS = "/NOLOGO"
 
  FLAGS.each do |flag|
    MSVC_CFLAGS << " /D#{flag}" if ENV[flag]
  end
  if ENV['DEBUG']
    MSVC_CFLAGS << " /Zi"
    MSVC_LDFLAGS << " /DEBUG"
  end
  MSVC_CFLAGS << " /I#{ENV['CRT_INC_PATH']}" if ENV['CRT_INC_PATH']
  MSVC_LDFLAGS << " /LIBPATH:#{ENV['CRT_LIB_PATH'][0..-2]}\i386" if ENV['CRT_LIB_PATH']
  MSVC_LDFLAGS << " /LIBPATH:#{ENV['SDK_LIB_PATH'][0..-2]}\i386" if ENV['SDK_LIB_PATH']
 
  # MSVC build tasks
  task :build_os => [:buildenv_win32, :build_skel, "dist/#{NAME}.exe"]
 
  task :buildenv_win32 do
    unless ENV['DDKBUILDENV']
      vcvars32_bat = File.join(env('MSVC'), "vcvars32.bat")
      unless File.exists?(vcvars32_bat)
        vcvars32_bat = File.join(env('MSVC'), "bin/vcvars32.bat")
      end
      `"#{vcvars32_bat}" x86 && set`.each do |line|
        if line =~ /(\w+)=(.+)/
          ENV[$1] = $2
        end
      end
    end
    mkdir_p "dist/pkg"
  end
 
  task :stub => ["dist/pkg/shoes-stub.exe", "dist/pkg/shoes-stub-inject.exe"]
 
  ['stub', 'stub-inject'].each do |s|
    task "dist/pkg/shoes-#{s}.exe" => ["shoes/version.h", "shoes/http/winhttp.obj", "platform/msw/stub32.res", "platform/msw/#{s}.obj"] do |t|
      rm_f t.name
      sh "link #{MSVC_LDFLAGS} /OUT:#{t.name} /LIBPATH:dist " +
        "/SUBSYSTEM:WINDOWS platform/msw/stub32.res shoes/http/winhttp.obj platform/msw/#{s}.obj shell32.lib user32.lib comctl32.lib winhttp.lib bufferoverflowu.lib advapi32.lib"
    end
  end
 
  task "dist/#{NAME}.exe" => ["dist/lib#{SONAME}.dll", "bin/main.obj", "shoes/appwin32.res"] do |t|
    rm_f t.name
    sh "link #{MSVC_LDFLAGS} /OUT:#{t.name} /LIBPATH:dist " +
      "/SUBSYSTEM:WINDOWS bin/main.obj shoes/appwin32.res lib#{SONAME}.lib #{MSVC_LIBS2}"
  end
 
  task "dist/pull.exe" => ["bin/pull.obj"] do |t|
    rm_f t.name
    sh "link #{MSVC_LDFLAGS} /OUT:#{t.name} /LIBPATH:deps/curl/lib " +
      "/SUBSYSTEM:WINDOWS bin/pull.obj libcurl.lib #{MSVC_LIBS2}"
  end
 
  task "dist/lib#{SONAME}.dll" => ["shoes/version.h"] + OBJ do |t|
    sh "link #{MSVC_LDFLAGS} /OUT:#{t.name} /dll " +
      "/LIBPATH:#{ext_ruby}/lib " +
      "/LIBPATH:deps/cairo/lib " +
      "/LIBPATH:deps/pango/lib " +
      "/LIBPATH:deps/vlc/lib #{OBJ.join(' ')} #{MSVC_LIBS}"
  end
 
  rule ".obj" => ".c" do |t|
    sh "cl /c /nologo /TP /Fo#{t.name} #{MSVC_CFLAGS} #{t.source}"
  end
 
  rule ".res" => ".rc" do |t|
    sh "rc /Fo#{t.name} #{t.source}"
  end
 
  task :installer do
    mkdir_p "pkg"
    rm_rf "dist/nsis"
    cp_r "platform/msw", "dist/nsis"
    cp "shoes/appwin32.ico", "dist/nsis/setup.ico"
    rewrite "dist/nsis/base.nsi", "dist/nsis/#{NAME}.nsi"
    Dir.chdir("dist/nsis") do
      sh "\"#{env('NSIS')}\\makensis.exe\" #{NAME}.nsi"
    end
    mv "dist/nsis/#{PKG}.exe", "pkg"
  end
else
  require 'rbconfig'
 
  CC = "gcc"
  SRC = FileList["shoes/*.c",
    PLATFORM =~ /darwin/ ? "shoes/native/cocoa.m" : "shoes/native/gtk.c",
    PLATFORM =~ /darwin/ ? "shoes/http/nsurl.m" : "shoes/http/curl.c"]
  OBJ = SRC.map do |x|
    x.gsub(/\.\w+$/, '.o')
  end
 
  # Linux build environment
  CAIRO_CFLAGS = ENV['CAIRO_CFLAGS'] || `pkg-config --cflags cairo`.strip
  CAIRO_LIB = ENV['CAIRO_LIB'] ? "-L#{ENV['CAIRO_LIB']}" : `pkg-config --libs cairo`.strip
  PANGO_CFLAGS = ENV['PANGO_CFLAGS'] || `pkg-config --cflags pango`.strip
  PANGO_LIB = ENV['PANGO_LIB'] ? "-L#{ENV['PANGO_LIB']}" : `pkg-config --libs pango`.strip
 
  LINUX_CFLAGS = %[-I#{ENV['SHOES_DEPS_PATH'] || "/usr"}/include #{CAIRO_CFLAGS} #{PANGO_CFLAGS} -I#{Config::CONFIG['archdir']}]
  LINUX_LIB_NAMES = %W[#{ruby_so} png cairo pangocairo-1.0 ungif]
  FLAGS.each do |flag|
    LINUX_CFLAGS << " -D#{flag}" if ENV[flag]
  end
  if ENV['DEBUG']
    LINUX_CFLAGS << " -g"
  end
 
  case PLATFORM when /darwin/
    DLEXT = "dylib"
    LINUX_CFLAGS << " -DSHOES_QUARTZ -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -fpascal-strings #{Config::CONFIG["CFLAGS"]} -x objective-c"
    LINUX_LDFLAGS = "-framework Cocoa -framework Carbon -dynamiclib -Wl,-single_module #{Config::CONFIG["LDFLAGS"]} INSTALL_NAME"
    LINUX_LIB_NAMES << 'pixman-1' << 'jpeg.62'
    if ENV['VIDEO']
      LINUX_LDFLAGS << " ./deps/lib/libvlc.a ./deps/lib/vlc/libmemcpymmx.a ./deps/lib/vlc/libi420_rgb_mmx.a ./deps/lib/vlc/libi422_yuy2_mmx.a ./deps/lib/vlc/libi420_ymga_mmx.a ./deps/lib/vlc/libi420_yuy2_mmx.a ./deps/lib/vlc/libmemcpymmxext.a ./deps/lib/vlc/libmemcpy3dn.a ./deps/lib/vlc/libffmpeg.a ./deps/lib/vlc/libstream_out_switcher.a ./deps/lib/vlc/libquicktime.a ./deps/lib/vlc/libxvideo.a ./deps/lib/vlc/libauhal.a ./deps/lib/vlc/libmacosx.a -framework vecLib -lpthread -lm -liconv -lintl -liconv -lc -lpostproc -lavformat -lavcodec -lz -la52 -lfaac -lfaad -lmp3lame -lx264 -lxvidcore -lvorbisenc -lavutil -lvorbis -lm -logg -lm -lavformat -lavcodec -lz -la52 -lfaac -lfaad -lmp3lame -lx264 -lxvidcore -lvorbisenc -lavutil -lvorbis -lm -logg -framework QuickTime -lm -lXxf86vm -lXinerama -L/usr/X11R6/lib -lSM -lICE -lX11 -lXext -lXv -framework CoreAudio -framework AudioUnit -framework AudioToolbox -framework IOKit -lobjc -ObjC -framework OpenGL -framework AGL -read_only_relocs suppress"
    end
    if ENV['UNIVERSAL']
      LINUX_CFLAGS << " -O -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
      LINUX_LDFLAGS << " -arch i386 -arch ppc"
      ENV['MACOSX_DEPLOYMENT_TARGET'] = '10.4'
    elsif ENV['PPC']
      LINUX_CFLAGS << " -O -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc"
      LINUX_LDFLAGS << " -arch ppc"
      ENV['MACOSX_DEPLOYMENT_TARGET'] = '10.4'
    end
  else
    DLEXT = "so"
    LINUX_CFLAGS << " -DSHOES_GTK -fPIC #{`pkg-config --cflags gtk+-2.0`.strip} #{`curl-config --cflags`.strip}"
    LINUX_LDFLAGS =" #{`pkg-config --libs gtk+-2.0`.strip} #{`curl-config --libs`.strip} -fPIC -shared"
    LINUX_LIB_NAMES << 'jpeg'
    LINUX_LIB_NAMES << 'rt'
    LINUX_LIB_NAMES << "vlc" if ENV['VIDEO']
  end
  LINUX_LIBS = LINUX_LIB_NAMES.map { |x| "-l#{x}" }.join(' ')
 
  task :build_os => [:buildenv_linux, :build_skel, "dist/#{NAME}"]
 
  task :buildenv_linux do
    rm_rf "dist"
    mkdir_p "dist"
  end
 
  LINUX_LIBS << " -L#{Config::CONFIG['libdir']} #{CAIRO_LIB} #{PANGO_LIB}"
 
  task "dist/#{NAME}" => ["dist/lib#{SONAME}.#{DLEXT}", "bin/main.o"] do |t|
    bin = "#{t.name}-bin"
    rm_f t.name
    rm_f bin
    sh "#{CC} -Ldist -o #{bin} bin/main.o #{LINUX_LIBS} -lshoes #{Config::CONFIG['LDFLAGS']}"
    if PLATFORM !~ /darwin/
      rewrite "platform/nix/shoes.launch", t.name, %r!/shoes-bin!, "/#{NAME}-bin"
      sh %{echo 'LD_LIBRARY_PATH=$APPPATH $APPPATH/#{File.basename(bin)} $@' >> #{t.name}}
      chmod 0755, t.name
    end
  end
 
  task "dist/lib#{SONAME}.#{DLEXT}" => ['shoes/version.h'] + OBJ do |t|
    ldflags = LINUX_LDFLAGS.sub! /INSTALL_NAME/, "-install_name @executable_path/lib#{SONAME}.#{DLEXT}"
    sh "#{CC} -o #{t.name} #{OBJ.join(' ')} #{LINUX_LDFLAGS} #{LINUX_LIBS}"
    case PLATFORM when /darwin/
      %w[libpostproc.dylib libavformat.dylib libavcodec.dylib libavutil.dylib libruby.dylib].each do |libn|
        sh "install_name_tool -change /tmp/dep/lib/#{libn} ./deps/lib/#{libn} #{t.name}"
      end
    end
  end
 
  rule ".o" => ".m" do |t|
    sh "#{CC} -I. -O -c -o#{t.name} #{LINUX_CFLAGS} #{t.source}"
  end
 
  rule ".o" => ".c" do |t|
    sh "#{CC} -I. -O -c -o#{t.name} #{LINUX_CFLAGS} #{t.source}"
  end
 
  case PLATFORM when /darwin/
    task :stub do
      ENV['MACOSX_DEPLOYMENT_TARGET'] = '10.4'
      sh "gcc -O -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc -framework Cocoa -o stub platform/mac/stub.m -I."
    end
 
    task :installer do
      mkdir_p "pkg"
      rm_rf "dmg"
      mkdir_p "dmg"
      cp_r "#{APPNAME}.app", "dmg"
      mv "dmg/#{APPNAME}.app/Contents/MacOS/samples", "dmg/samples"
      ln_s "/Applications", "dmg/Applications"
      sh "DYLD_LIBRARY_PATH= platform/mac/pkg-dmg --target pkg/#{PKG}.dmg --source dmg --volname '#{APPNAME}' --copy platform/mac/dmg_ds_store:/.DS_Store --mkdir /.background --copy static/shoes-dmg.jpg:/.background" # --format UDRW"
      rm_rf "dmg"
    end
  else
    task :installer do
      mkdir_p "pkg"
      sh "makeself dist pkg/#{PKG}.run '#{APPNAME}' ./#{NAME}"
    end
  end
end
 
task :tarball => ['bin/main.c', 'shoes/version.h'] do
  mkdir_p "pkg"
  rm_rf PKG
  sh "git-checkout-index --prefix=#{PKG}/ -a"
  rm "#{PKG}/bin/main.skel"
  rm "#{PKG}/Rakefile"
  rm "#{PKG}/.gitignore"
  rm "#{PKG}/use-deps"
  cp "bin/main.c", "#{PKG}/bin/main.c"
  cp "shoes/version.h", "#{PKG}/shoes/version.h"
  rewrite "README", "#{PKG}/README",
/^.+STAYING CURRENT/, File.read("platform/nix/INSTALL")
  rewrite "platform/nix/Makefile", "#{PKG}/Makefile", /^(REVISION) = .+?$/, 'REVISION = \1'
  sh "tar czvf pkg/#{PKG}.tar.gz #{PKG}"
  rm_rf PKG
end
 
# shoes is small, if any include changes, go ahead and build from scratch.
SRC.zip(OBJ).each do |c, o|
  file o => [c] + Dir["shoes/*.h"]
end
 
desc "build TAGS file for emacs hackers"
task :tags do
  files = ""
  Find.find(".") do |path|
    next if path !~ /\.(c|h)$/
    files += path + " "
  end
  system("etags #{files}")
end