6 pwd = File.expand_path(File.dirname(__FILE__))
9 diff = "#{pwd}/#{dir}.diff"
12 url = "http://sourceforge.net/projects/lwes/files/lwes-c/#{v}/#{tgz}/download"
28 # from Net::HTTP example
29 def fetch(uri_str, limit = 10)
30 raise ArgumentError, 'HTTP redirect too deep' if limit == 0
32 response = Net::HTTP.get_response(URI.parse(uri_str))
34 when Net::HTTPSuccess then response
35 when Net::HTTPRedirection then fetch(response['location'], limit - 1)
41 unless have_library('lwes') && have_header('lwes.h')
42 warn "LWES library not found, building locally"
46 File.open("#{tgz}.#{$$}.#{rand}.tmp", "wb") do |fp|
47 fp.write(response.body)
48 File.rename(fp.path, tgz)
51 unless test ?r, "#{inst}/.ok"
53 system('tar', 'zxf', tgz) or abort "tar failed with #{$?}"
55 system("patch", "-p1", "-i", diff) or abort "patch failed: #{$?}"
56 args = %w(--disable-shared
59 --disable-dependency-tracking)
60 system("./configure", "--prefix=#{inst}", *args) or
61 abort "configure failed with #{$?}"
62 system("make") or abort "make failed with #{$?}"
63 system("make", "install") or abort "make install failed with #{$?}"
66 File.open("#{inst}/.ok", "wb") { }
68 $CFLAGS = "-I#{inst}/include/lwes-0 #{$CFLAGS}"
69 $LIBS += " #{inst}/lib/liblwes.a"
70 have_header('lwes.h') or
71 abort "installation failed"
75 create_makefile('lwes_ext')