Skip to content

Commit

Permalink
Make this compatible with Windows `kindlegen.exe' binary
Browse files Browse the repository at this point in the history
Modify extconf.rb to change target based on platform because Windows binary is
`kindlegen.exe' and not `kindlegen'. Include simple tests to see if `curl' and
`unzip' exist in Windows PATH. Make code cleaner.

Modify kindlegen.rb to get command by joining binary directory and "kindlegen".
The previous scheme fails to return the correct command if the binary is
`kindlegen.exe'
  • Loading branch information
i-give-up committed Oct 3, 2015
1 parent 7db71a1 commit 97c3e68
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.gem
*.swp
/pkg/*
/.bundle
/vendor/bundle
Expand Down
33 changes: 25 additions & 8 deletions ext/kindlegen/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,51 @@

require 'rbconfig'
File::open('Makefile', 'w') do |w|
tarball = case RbConfig::CONFIG['host_os']
case RbConfig::CONFIG['host_os']
when /mac|darwin/i
unzip = 'unzip'
"KindleGen_Mac_i386_v2_9.zip"
tarball = 'KindleGen_Mac_i386_v2_9.zip'
target = 'kindlegen'
when /linux|cygwin/i
unzip = 'tar -zx --no-same-owner -f'
"kindlegen_linux_2.6_i386_v2_9.tar.gz"
tarball = 'kindlegen_linux_2.6_i386_v2_9.tar.gz'
target = 'kindlegen'
when /mingw32/i
unzip = 'unzip'
"kindlegen_win32_v2_9.zip"
# Abort if either `unzip' or `curl' if not found
`where #{unzip}`
unless ($?.success?)
STDERR.puts "The program `unzip' not found. Aborting."
exit(1)
end
`where curl`
unless ($?.success?)
STDERR.puts "The program `curl` not found. Aborting."
exit(1)
end
tarball = 'kindlegen_win32_v2_9.zip'
target = 'kindlegen.exe'
else
STDERR.puts "Host OS unsupported!"
exit(1)
end

bindir = File.join(File.expand_path('../../..', __FILE__), "bin")

config = RbConfig::CONFIG.merge({
"unzip" => unzip,
"tarball" => tarball
"tarball" => tarball,
"target" => target,
"bindir" => bindir,
})

bindir = File.join(File.expand_path('../../..', __FILE__), "bin")
w.puts RbConfig.expand(DATA.read, config.merge('bindir' => bindir))
w.puts RbConfig.expand(DATA.read, config)
end


__END__
AMAZON = http://kindlegen.s3.amazonaws.com
TARGET = kindlegen
TARGET = $(target)
BINDIR = $(bindir)
TARBALL = $(tarball)
CURL = curl
Expand Down
6 changes: 1 addition & 5 deletions lib/kindlegen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@
module Kindlegen
Root = Pathname.new(File.expand_path('../..', __FILE__))
Bin = Root.join('bin')
Executables = Bin.children.inject({}) { |h, p|
h[p.basename.to_s.to_sym] = p.to_s
h
}

#
# Getting command path of kindlegen.
#
def self.command
Executables[:kindlegen]
Bin.join('kindlegen')
end

#
Expand Down

0 comments on commit 97c3e68

Please sign in to comment.