Skip to content

Commit

Permalink
Fix compilation on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
glebm committed May 20, 2019
1 parent 10a743c commit 2c6035d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
25 changes: 16 additions & 9 deletions ext/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,34 @@
fail 'Could not fetch libsass'
end

dl_ext =
case RUBY_PLATFORM
when /darwin/
'bundle'
else
'so'
end

File.write 'Makefile', <<-MAKEFILE
ifndef DESTDIR
LIBSASS_OUT = #{gem_root}/lib/sassc/libsass.so
LIBSASS_OUT = #{gem_root}/lib/sassc/libsass.#{dl_ext}
else
LIBSASS_OUT = $(DESTDIR)$(PREFIX)/libsass.so
LIBSASS_OUT = $(DESTDIR)$(PREFIX)/libsass.#{dl_ext}
endif
SUB_DIR := #{libsass_dir}
SUB_TARGET := lib/libsass.so
libsass.so:#{' clean' if ENV['CLEAN']}
libsass.#{dl_ext}:#{' clean' if ENV['CLEAN']}
$(MAKE) -C '$(SUB_DIR)' lib/libsass.so
cp '$(SUB_DIR)/lib/libsass.so' libsass.so
strip libsass.so
cp '$(SUB_DIR)/lib/libsass.so' libsass.#{dl_ext}
strip -x libsass.#{dl_ext}
install: libsass.so
cp libsass.so '$(LIBSASS_OUT)'
install: libsass.#{dl_ext}
cp libsass.#{dl_ext} '$(LIBSASS_OUT)'
clean:
$(MAKE) -C '$(SUB_DIR)' clean
rm -f '$(LIBSASS_OUT)' libsass.so
rm -f '$(LIBSASS_OUT)' libsass.#{dl_ext}
.PHONY: clean install
MAKEFILE
5 changes: 3 additions & 2 deletions lib/sassc/native.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ module Native
spec = Gem.loaded_specs["sassc"]
gem_root = spec.gem_dir

ruby_version_so_path = "#{gem_root}/lib/sassc/#{RUBY_VERSION[/\d+.\d+/]}/libsass.so"
dl_ext = (RUBY_PLATFORM =~ /darwin/ ? 'bundle' : 'so')
ruby_version_so_path = "#{gem_root}/lib/sassc/#{RUBY_VERSION[/\d+.\d+/]}/libsass.#{dl_ext}"
if File.exist?(ruby_version_so_path)
ffi_lib ruby_version_so_path
else
ffi_lib "#{gem_root}/lib/sassc/libsass.so"
ffi_lib "#{gem_root}/lib/sassc/libsass.#{dl_ext}"
end

require_relative "native/sass_value"
Expand Down

0 comments on commit 2c6035d

Please sign in to comment.