Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update libmagic; link system ICU on Darwin; use RbConfig CFLAGS, etc. #55

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 49 additions & 30 deletions ext/charlock_holmes/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,62 @@ def sys(cmd)
exit(1)
end

# Make sure we're using the right compiler and flags.

ENV['CC'] = RbConfig::MAKEFILE_CONFIG['CC']
ENV['CXX'] = RbConfig::MAKEFILE_CONFIG['CXX']
ENV['CFLAGS'] = '-O2 -fPIC -std=gnu99'
ENV['CXXFLAGS'] = '-O2 -fPIC'

# Make sure we're using our headers rather than ones elsewhere.
$INCFLAGS[0,0] = " -I#{CWD} "; $INCFLAGS << " -I#{CWD} "
$LDFLAGS << " -L#{CWD} "

##
# ICU dependency
#

dir_config 'icu'

# detect homebrew installs
if !have_library 'icui18n'
base = if !`which brew`.empty?
`brew --prefix`.strip
elsif File.exists?("/usr/local/Cellar/icu4c")
'/usr/local/Cellar'
end

if base and icu4c = Dir[File.join(base, 'Cellar/icu4c/*')].sort.last
$INCFLAGS << " -I#{icu4c}/include "
$LDFLAGS << " -L#{icu4c}/lib "
end
if %x(uname).chomp == "Darwin" # Use the system ICU on Darwin 10.7+
if %x(sw_vers -productVersion | cut -c4-5).chomp.to_i > 6

%x(cd #{CWD}; tar xf src/darwin-icu-headers.tar.gz)
$LDFLAGS << " -L/usr/lib "; $LDFLAGS.insert(0," -L/usr/lib -Wl,-search_dylibs_first ")
have_library 'icucore' and have_header 'unicode/ucnv.h' or abort 'ICU missing.'

elsif not have_library 'icui18n' # Otherwise check Homebrew.

base = if not %x(which brew).empty? %x(brew --prefix).strip
elsif File.exists?("/usr/local/Cellar/icu4c") then '/usr/local/Cellar' end
if base and icu4c = Dir[File.join(base, 'Cellar/icu4c/*')].sort.last
$INCFLAGS << " -I#{icu4c}/include "
$LDFLAGS << " -L#{icu4c}/lib "

unless have_library 'icui18n' and have_header 'unicode/ucnv.h'
STDERR.puts "\n\n"
STDERR.puts "**********************************************************"
STDERR.puts "*********** icu required (brew install icu4c) ************"
STDERR.puts "**********************************************************"
exit(1)
end
end
end # !Darwin
else
unless have_library 'icui18n' and have_library 'icudata' and have_header 'unicode/ucnv.h'
STDERR.puts "\n\n"
STDERR.puts "***********************************************************************"
STDERR.puts "*********** icu required (i.e., apt-get install libicu-dev) ***********"
STDERR.puts "***********************************************************************"
exit(1)
end
end

unless have_library 'icui18n' and have_header 'unicode/ucnv.h'
STDERR.puts "\n\n"
STDERR.puts "***************************************************************************************"
STDERR.puts "*********** icu required (brew install icu4c or apt-get install libicu-dev) ***********"
STDERR.puts "***************************************************************************************"
exit(1)
end

have_library 'z' or abort 'libz missing'
have_library 'icuuc' or abort 'libicuuc missing'
have_library 'icudata' or abort 'libicudata missing'

##
# libmagic dependency
#

src = File.basename('file-5.08.tar.gz')
src = File.basename('file-5.16.tar.gz')
dir = File.basename(src, '.tar.gz')
libdir = 'lib'

Expand All @@ -62,19 +81,19 @@ def sys(cmd)

sys("tar zxvf #{src}")
Dir.chdir(dir) do
sys("./configure --prefix=#{CWD}/dst/ --disable-shared --enable-static --with-pic")
sys("./configure --prefix=#{CWD}/dst --disable-shared --enable-static --with-pic")
sys("patch -p0 < ../file-soft-check.patch")
sys("make -C src install")
sys("make -C magic install")
sys("cd src; make install")
sys("cd magic; make install")
# this should evaluate to either 'lib' or 'lib64'
libdir = `grep ^libdir config.log`.strip().split("'")[1].split('/')[-1]
end
end

FileUtils.cp "#{CWD}/dst/#{libdir}/libmagic.a", "#{CWD}/libmagic_ext.a"
FileUtils.cp "#{CWD}/dst/include/magic.h", "#{CWD}/magic.h"

$INCFLAGS[0,0] = " -I#{CWD}/dst/include "
$LDFLAGS << " -L#{CWD} "
%x(cd #{CWD}; rm -rf dst)

dir_config 'magic'
unless have_library 'magic_ext' and have_header 'magic.h'
Expand Down
Binary file added ext/charlock_holmes/src/darwin-icu-headers.tar.gz
Binary file not shown.
Binary file removed ext/charlock_holmes/src/file-5.08.tar.gz
Binary file not shown.
Binary file added ext/charlock_holmes/src/file-5.16.tar.gz
Binary file not shown.
13 changes: 3 additions & 10 deletions ext/charlock_holmes/src/file-soft-check.patch
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
--- src/funcs.c.orig 2013-01-27 01:23:01.000000000 -0800
+++ src/funcs.c 2013-01-27 01:23:46.000000000 -0800
@@ -300,7 +300,7 @@
protected int
file_reset(struct magic_set *ms)
{
- if (ms->mlist == NULL) {
Index: src/funcs.c --- src/funcs.c +++ src/funcs.c
@@ -304 +304 @@
- if (ms->mlist[0] == NULL) {
+ if (!(ms->flags & MAGIC_NO_CHECK_SOFT) && ms->mlist == NULL) {
file_error(ms, 0, "no magic files loaded");
return -1;
}