libusb 0.3.3-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0d18541f453e558cf50d82137a307dfda9752beb
4
+ data.tar.gz: a5e5bee3ff8935925240f3dd7efc1883050da5fe
5
+ SHA512:
6
+ metadata.gz: 569c2f1906fbaf6b533c9f386ec3072f4f73352562d16c22722c87ff7b9404f009745bbbc74ba49ca2e2ff677f13885f66e7eccf0e8c5716b936835697afe06d
7
+ data.tar.gz: 2df95cfe0d73ac4ecd4047f147a0385ff253849eaadbe788417a5bdc5fcd64b259eb38af311d9a5746bb1aeef43c143ae29a664d5a3258f6b2a44702982447ff
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ lib/libusb-1.0*
6
+ lib/pkgconfig
7
+ include
8
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.8.7"
4
+ - "1.9.2"
5
+ - "1.9.3"
6
+ - jruby-18mode # JRuby in 1.8 mode
7
+ - jruby-19mode # JRuby in 1.9 mode
8
+ - rbx-18mode
9
+ - rbx-19mode
10
+ script: bundle exec rake travis
data/.yardopts ADDED
@@ -0,0 +1,6 @@
1
+ --title "libusb-1.0 Ruby Interface"
2
+ --no-private
3
+ lib/**/*.rb
4
+ -
5
+ README.md
6
+ History.md
data/COPYING ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in libusb.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'eventmachine'
8
+ end
9
+
10
+ platforms :rbx do
11
+ # travis currently runs a slightly older version of rbx,
12
+ # that needs this special ffi version.
13
+ if ENV['TRAVIS']
14
+ gem 'ffi', :git => "git://github.com/ffi/ffi.git", :ref => '5f31908'
15
+ end
16
+ end
data/History.md ADDED
@@ -0,0 +1,77 @@
1
+ 0.3.3 / 2013-04-05
2
+ ------------------
3
+ * Build and package binary x64 version of libusb for Windows in addition to x86.
4
+ * Fix build on Windows from source gem (although may take almost an hour).
5
+
6
+ 0.3.2 / 2013-02-16
7
+ ------------------
8
+ * Don't enforces DevKit installation on Windows.
9
+ * Fix error check on libusb_get_device_list(). Thanks to Paul Kunysch for the bug report.
10
+ * Add support for Cygwin. Requires ffi-1.4.0.
11
+
12
+ 0.3.1 / 2013-01-22
13
+ ------------------
14
+ * Fix loading of compiled libusb library on OSX
15
+
16
+ 0.3.0 / 2013-01-21
17
+ ------------------
18
+ * Build bundled libusbx sources in case libusb-1.0.so can not be loaded from the system
19
+ * Replace Hoe with Bundler
20
+ * Add timeout and completion_flag to Context#handle_events
21
+ * Add asynchronous DevHandle#{control|interrupt|bulk}_transfer method variants
22
+ * Add the ability to retrieve the data already transfered when it comes to an exception
23
+ * Add notification API for libusb's file describtors for event driven USB transfers
24
+ * Add experimental integration to EventMachine
25
+ * Add several convenience methods to descriptors
26
+ * Add missing return code checks to libusb_init() and libusb_get_device_list()
27
+
28
+ 0.2.2 / 2012-10-19
29
+ ------------------
30
+ * Add method Interface#bInterfaceNumber
31
+ * Fix methods (#claim_interface, #detach_kernel_driver) with Interface-type parameter
32
+ * update to libusbx-1.0.14 for windows build
33
+
34
+ 0.2.1 / 2012-09-25
35
+ ------------------
36
+ * Rename Configuration#maxPower to #bMaxPower as done in libusbx-1.0.13 and in ruby-usb.gem
37
+ * update to libusbx-1.0.13 for windows build (with support for libusbK and libusb0)
38
+
39
+ 0.2.0 / 2012-06-15
40
+ ------------------
41
+ * Divide up the libusb library across multiple files, required with autoload
42
+ * add methods: LIBUSB.has_capability?, Device#device_speed (libusb-1.0.9+)
43
+ * add possibility to read out libusb version: LIBUSB.version (libusbx-1.0.10+)
44
+ * add methods: Device#parent, Device#port_number, Device#port_path (libusbx-1.0.12+)
45
+ * switch to libusbx-1.0.12 for windows build
46
+
47
+ 0.1.3 / 2012-03-15
48
+ -------------------
49
+ * Add documentation of descriptor accessors
50
+ * Fix #extra accessor of Configuration, Setting and Endpoint
51
+
52
+ 0.1.2 / 2012-03-14
53
+ ------------------
54
+ * Mark all blocking functions as blocking in FFI, so that parallel threads are not blocked
55
+ * Add method Device#open_interface
56
+ * Add block variant to #claim_interface
57
+ * update API documentation
58
+
59
+ 0.1.1 / 2011-12-09
60
+ ------------------
61
+ * avoid ffi calls with :blocking=>true, als long as it isn't stable on win32
62
+
63
+ 0.1.0 / 2011-10-01
64
+ ------------------
65
+ * add test suite based on mass storage devices
66
+ * usable async transfers
67
+ * migration to rake-compiler and hoe
68
+ * cross compiled Windows gems
69
+ * distinct exception classes
70
+ * new compatibility layer for ruby-usb.gem
71
+ * many helper methods for different USB descriptors
72
+ * add LIBUSB constants
73
+ * downcase methods names
74
+
75
+ 0.0.1 / 2009-06-23
76
+ ------------------
77
+ * first public release
data/README.md ADDED
@@ -0,0 +1,144 @@
1
+ <!-- -*- coding: utf-8 -*- -->
2
+
3
+ [![Build Status](https://travis-ci.org/larskanis/libusb.png?branch=debug_travis)](https://travis-ci.org/larskanis/libusb)
4
+
5
+ Access USB devices from Ruby
6
+ ============================
7
+
8
+ LIBUSB is a Ruby binding that gives Ruby programmers access to arbitrary USB devices.
9
+
10
+ * [libusb](http://libusbx.org) is a library that gives full access to devices connected via the USB bus. No special kernel driver is thus necessary for accessing USB devices.
11
+ * This Ruby binding supports the API version 1.0 of [libusb](http://libusbx.org). Note that the old "legacy" version 0.1.x of libusb uses a completely different API that is covered by the ruby extension [ruby-usb](http://www.a-k-r.org/ruby-usb/) .
12
+
13
+
14
+ LIBUSB for Ruby is covered by the GNU Lesser General Public License version 3.
15
+
16
+ Features
17
+ --------
18
+
19
+ * Access to descriptors of devices, configurations, interfaces, settings and endpoints
20
+ * Synchronous and asynchronous communication for bulk, control, interrupt and isochronous transfers
21
+ * Compatibility layer for [ruby-usb](http://www.a-k-r.org/ruby-usb/) (API based on libusb-0.1). See {::USB} for description.
22
+
23
+ Synopsis
24
+ --------
25
+ See [the documentation](http://rubydoc.info/gems/libusb/frames) for a full API description.
26
+
27
+ ```ruby
28
+ require "libusb"
29
+
30
+ usb = LIBUSB::Context.new
31
+ device = usb.devices(:idVendor => 0x04b4, :idProduct => 0x8613).first
32
+ device.open_interface(0) do |handle|
33
+ handle.control_transfer(:bmRequestType => 0x40, :bRequest => 0xa0, :wValue => 0xe600, :wIndex => 0x0000, :dataOut => 1.chr)
34
+ end
35
+ ```
36
+ {LIBUSB::Context#devices} is used to get all or only particular devices.
37
+ After {LIBUSB::Device#open_interface opening and claiming} the {LIBUSB::Device} the resulting {LIBUSB::DevHandle} can be
38
+ used to communicate with the connected USB device
39
+ by {LIBUSB::DevHandle#control_transfer}, {LIBUSB::DevHandle#bulk_transfer},
40
+ {LIBUSB::DevHandle#interrupt_transfer} or by using the {LIBUSB::Transfer} classes.
41
+
42
+ A {LIBUSB::Device} can also be used to retrieve information about it,
43
+ by using the device descriptor attributes.
44
+ A {LIBUSB::Device} could have several configurations. You can then decide of which
45
+ configuration to enable. You can only enable one configuration at a time.
46
+
47
+ Each {LIBUSB::Configuration} has one or more interfaces. These can be seen as functional group
48
+ performing a single feature of the device.
49
+
50
+ Each {LIBUSB::Interface} has at least one {LIBUSB::Setting}. The first setting is always default.
51
+ An alternate setting can be used independent on each interface.
52
+
53
+ Each {LIBUSB::Setting} specifies it's own set of communication endpoints.
54
+ Each {LIBUSB::Endpoint} specifies the type of transfer, direction, polling interval and
55
+ maximum packet size.
56
+
57
+
58
+ Prerequisites
59
+ -------------
60
+
61
+ * Linux, MacOSX or Windows system with Ruby MRI 1.8.7/1.9.x, JRuby or recent version of Rubinius
62
+ * [libusb](http://libusb.org) or [libusbx](http://libusbx.org) library version 1.0.8+ :
63
+ * Debian or Ubuntu:
64
+
65
+ ```
66
+ $ sudo apt-get install libusb-1.0-0-dev
67
+ ```
68
+ * OS-X: install with homebrew:
69
+
70
+ ```
71
+ $ brew install libusb
72
+ ```
73
+ or macports:
74
+
75
+ ```
76
+ $ port install libusb
77
+ ```
78
+ * Windows: libusb.gem already comes with a precompiled `libusb.dll`, but you need to install a device driver (see below)
79
+
80
+
81
+ Install
82
+ -------
83
+
84
+ $ gem install libusb
85
+
86
+ Latest code can be used in this way:
87
+
88
+ $ git clone git://github.com/larskanis/libusb.git
89
+ $ rake install_gem
90
+
91
+
92
+ Usage on Windows
93
+ ----------------
94
+
95
+ In contrast to Linux, any access to an USB device by LIBUSB on Windows requires a proper driver
96
+ installed in the system. Fortunately creating such a driver is quite easy with
97
+ [Zadig](http://sourceforge.net/projects/libwdi/files/zadig/). Select the interesting USB device,
98
+ choose WinUSB driver and press "Install Driver". That's it. You may take the generated output directory
99
+ with it's INI-file and use it for driver installation on other 32 or 64 bit Windows
100
+ systems.
101
+
102
+
103
+ Cross compiling for Windows
104
+ ---------------------------
105
+
106
+ Libusb-gem can be build on a linux or darwin host for the win32 platform,
107
+ using the mingw cross compiler collection. Libusb is downloaded from source
108
+ git repo, cross compiled and included in the generated libusb.gem.
109
+
110
+ Install mingw32. On a debian based system this should work:
111
+
112
+ $ apt-get install mingw32
113
+
114
+ On MacOS X, if you have MacPorts installed:
115
+
116
+ $ port install i386-mingw32-gcc
117
+
118
+ Download and cross compile libusb for win32:
119
+
120
+ $ rake cross gem
121
+
122
+ If everything works, there should be `libusb-VERSION-x86-mingw32.gem` in the pkg
123
+ directory.
124
+
125
+ EventMachine integration
126
+ ------------------------
127
+
128
+ Libusb for Ruby comes with an experimental integration to [EventMachine](http://rubyeventmachine.com/).
129
+ That API is currently proof of concept - see {LIBUSB::Context#eventmachine_register}.
130
+ If you're experienced with EventMachine, please leave a comment.
131
+
132
+
133
+ Resources
134
+ ---------
135
+
136
+ * Project's home page: http://github.com/larskanis/libusb
137
+ * API documentation: http://rubydoc.info/gems/libusb/frames
138
+ * Mailinglist: http://rubyforge.org/mailman/listinfo/libusb-hackers
139
+ * Overall introduction to USB: http://www.usbmadesimple.co.uk
140
+
141
+ Todo
142
+ ----
143
+
144
+ * stabilize EventMachine interface
data/Rakefile ADDED
@@ -0,0 +1,185 @@
1
+ # -*- coding: utf-8 -*-
2
+ # -*- ruby -*-
3
+
4
+ require 'bundler/gem_tasks'
5
+ require 'rubygems/package_task'
6
+ require 'pathname'
7
+ require 'uri'
8
+ require 'ostruct'
9
+ require 'rake/clean'
10
+
11
+ task :gem => :build
12
+ task :compile do
13
+ sh "ruby ext/extconf.rb"
14
+ end
15
+ task :test=>:compile do
16
+ sh "ruby -w -W2 -I. -Ilib -e \"#{Dir["test/test_*.rb"].map{|f| "require '#{f}';"}.join}\" -- -v"
17
+ end
18
+ travis_tests = %w[test_libusb_capability.rb test_libusb_structs.rb test_libusb_version.rb]
19
+ task :travis=>:compile do
20
+ sh "ruby -w -W2 -I. -Ilib -e \"#{travis_tests.map{|f| "require 'test/#{f}';"}.join}\" -- -v"
21
+ end
22
+ task :default => :test
23
+
24
+ COMPILE_HOME = Pathname( "./tmp" ).expand_path
25
+ STATIC_SOURCESDIR = COMPILE_HOME + 'sources'
26
+
27
+ # Fetch tarball from sourceforge
28
+ # LIBUSB_VERSION = ENV['LIBUSB_VERSION'] || '1.0.9'
29
+ # LIBUSB_SOURCE_URI = URI( "http://downloads.sourceforge.net/project/libusb/libusb-1.0/libusb-#{LIBUSB_VERSION}/libusb-#{LIBUSB_VERSION}.tar.bz2" )
30
+ # LIBUSB_TARBALL = STATIC_SOURCESDIR + File.basename( LIBUSB_SOURCE_URI.path )
31
+
32
+ # Fetch tarball from git repo
33
+ # LIBUSB_VERSION = ENV['LIBUSB_VERSION'] || '295c9d1'
34
+ # LIBUSB_SOURCE_URI = URI( "http://git.libusb.org/?p=libusb.git;a=snapshot;h=#{LIBUSB_VERSION};sf=tbz2" )
35
+ # LIBUSB_TARBALL = STATIC_SOURCESDIR + "libusb-#{LIBUSB_VERSION}.tar.bz2"
36
+
37
+ # Fetch tarball from libusbx
38
+ LIBUSB_VERSION = ENV['LIBUSB_VERSION'] || '1.0.14'
39
+ LIBUSB_SOURCE_URI = URI( "http://downloads.sourceforge.net/project/libusbx/releases/#{LIBUSB_VERSION[/^\d+\.\d+\.\d+/]}/source/libusbx-#{LIBUSB_VERSION}.tar.bz2" )
40
+ LIBUSB_TARBALL = STATIC_SOURCESDIR + File.basename( LIBUSB_SOURCE_URI.path )
41
+
42
+ # Fetch tarball from Pete Batard's git repo
43
+ # LIBUSB_VERSION = ENV['LIBUSB_VERSION'] || '4cc72d0'
44
+ # LIBUSB_SOURCE_URI = URI( "http://git.libusb.org/?p=libusb-pbatard.git;a=snapshot;h=#{LIBUSB_VERSION};sf=tbz2" )
45
+ # LIBUSB_TARBALL = STATIC_SOURCESDIR + "libusb-pbatard-#{LIBUSB_VERSION}.tar.bz2"
46
+
47
+ EXT_BUILDDIR = Pathname( "./ext" ).expand_path
48
+ EXT_LIBUSB_BUILDDIR = EXT_BUILDDIR + LIBUSB_TARBALL.basename(".tar.bz2")
49
+
50
+ directory STATIC_SOURCESDIR.to_s
51
+
52
+ # libusb source file should be stored there
53
+ file LIBUSB_TARBALL => STATIC_SOURCESDIR do |t|
54
+ # download the source file using wget or curl
55
+ chdir File.dirname(t.name) do
56
+ url = LIBUSB_SOURCE_URI
57
+ sh "wget '#{url}' -O #{LIBUSB_TARBALL}"
58
+ end
59
+ end
60
+
61
+
62
+ class CrossLibrary < OpenStruct
63
+ include Rake::DSL
64
+
65
+ def initialize(ruby_platform, host_platform)
66
+ super()
67
+
68
+ self.ruby_platform = ruby_platform
69
+ self.host_platform = host_platform
70
+
71
+ self.static_builddir = COMPILE_HOME + 'builds' + ruby_platform
72
+ self.ruby_build = RbConfig::CONFIG["host"]
73
+
74
+ # Static libusb build vars
75
+ self.static_libusb_builddir = static_builddir + LIBUSB_TARBALL.basename(".tar.bz2")
76
+ self.libusb_configure = static_libusb_builddir + 'configure'
77
+ self.libusb_makefile = static_libusb_builddir + 'Makefile'
78
+ self.libusb_dll = static_libusb_builddir + 'libusb/.libs/libusb-1.0.dll'
79
+
80
+ #
81
+ # Static libusb build tasks
82
+ #
83
+ CLEAN.include static_libusb_builddir.to_s
84
+
85
+ directory static_libusb_builddir.to_s
86
+
87
+ # Extract the libusb builds
88
+ file static_libusb_builddir => LIBUSB_TARBALL do |t|
89
+ sh 'tar', '-xjf', LIBUSB_TARBALL.to_s, '-C', static_libusb_builddir.parent.to_s
90
+ libusb_makefile.unlink if libusb_makefile.exist?
91
+ end
92
+
93
+ file libusb_configure => static_libusb_builddir do |t|
94
+ Dir.chdir( static_libusb_builddir ) do
95
+ sh "sh autogen.sh && make distclean"
96
+ end
97
+ end
98
+
99
+ libusb_env = [
100
+ "CFLAGS='-fno-omit-frame-pointer'",
101
+ ]
102
+
103
+ # generate the makefile in a clean build location
104
+ file libusb_makefile => libusb_configure do |t|
105
+ Dir.chdir( static_libusb_builddir ) do
106
+ options = [
107
+ "--target=#{host_platform}",
108
+ "--host=#{host_platform}",
109
+ "--build=#{ruby_build}",
110
+ ]
111
+
112
+ configure_path = static_libusb_builddir + 'configure'
113
+ sh "env #{[libusb_env, configure_path.to_s, *options].join(" ")}"
114
+ end
115
+ end
116
+
117
+ # make libusb-1.0.dll
118
+ task libusb_dll => [ libusb_makefile ] do |t|
119
+ Dir.chdir( static_libusb_builddir ) do
120
+ sh 'make'
121
+ end
122
+ end
123
+
124
+ task "libusb_dll:#{ruby_platform}" => libusb_dll
125
+
126
+ desc "compile static libusb libraries"
127
+ task :libusb_dll => "libusb_dll:#{ruby_platform}"
128
+
129
+ desc 'Cross compile libusb for win32'
130
+ task :cross => [ "libusb_dll:#{ruby_platform}" ] do |t|
131
+ spec = Gem::Specification::load("libusb.gemspec")
132
+ spec.instance_variable_set(:"@cache_file", nil) if spec.respond_to?(:cache_file)
133
+ spec.platform = Gem::Platform.new(ruby_platform)
134
+ spec.files << "lib/#{File.basename(libusb_dll)}"
135
+ spec.files -= `git ls-files ext`.split("\n")
136
+ spec.extensions = []
137
+
138
+ # Generate a package for this gem
139
+ pkg = Gem::PackageTask.new(spec) do |pkg|
140
+ pkg.need_zip = false
141
+ pkg.need_tar = false
142
+ # Do not copy any files per PackageTask, because
143
+ # we need the files from the platform specific directory
144
+ pkg.package_files.clear
145
+ end
146
+
147
+ # copy files of the gem to pkg directory
148
+ file pkg.package_dir_path => spec.files do
149
+ spec.files.each do |fn|
150
+ next if fn == "lib/#{File.basename(libusb_dll)}"
151
+ f = File.join(pkg.package_dir_path, fn)
152
+ fdir = File.dirname(f)
153
+ mkdir_p(fdir) if !File.exist?(fdir)
154
+ rm_f f
155
+ safe_ln(fn, f)
156
+ end
157
+ end
158
+ # copy libusb.dll to pkg directory
159
+ file pkg.package_dir_path => [libusb_dll] do
160
+ f = "#{pkg.package_dir_path}/lib/#{File.basename(libusb_dll)}"
161
+ rm_f f
162
+ safe_ln libusb_dll, f
163
+ end
164
+ end
165
+ end
166
+ end
167
+
168
+ CrossLibraries = [
169
+ ['i386-mingw32', 'i686-w64-mingw32'],
170
+ ['x64-mingw32', 'x86_64-w64-mingw32'],
171
+ ].map do |ruby_platform, host_platform|
172
+ CrossLibrary.new ruby_platform, host_platform
173
+ end
174
+
175
+ desc "Download and update bundled libusb(x)"
176
+ task :update_libusb => LIBUSB_TARBALL do
177
+ sh 'rm', '-r', (EXT_BUILDDIR + "libusbx-*").to_s do end
178
+ sh 'git', 'rm', '-rfq', (EXT_BUILDDIR + "libusbx-*").to_s do end
179
+ sh 'tar', '-xjf', LIBUSB_TARBALL.to_s, '-C', EXT_LIBUSB_BUILDDIR.parent.to_s
180
+ drops = %w[msvc].map{|f| (EXT_LIBUSB_BUILDDIR+f).to_s }
181
+ sh 'rm', '-r', '-f', *drops
182
+ sh 'git', 'add', EXT_LIBUSB_BUILDDIR.to_s
183
+ end
184
+
185
+ # vim: syntax=ruby