pandoc_rb 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +45 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +24 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +48 -0
- data/LICENSE +30 -0
- data/LICENSE.txt +31 -0
- data/README.md +83 -0
- data/Rakefile +31 -0
- data/Setup.hs +2 -0
- data/bench/bench.rb +69 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ext/pandoc_rb/extconf.rb +130 -0
- data/ext/pandoc_rb/pandoc-rb.cabal +74 -0
- data/ext/pandoc_rb/pandoc_rb.c +100 -0
- data/ext/pandoc_rb/src/PandocRb.hs +26 -0
- data/ext/pandoc_rb/src/Text/Pandoc/C.hs +147 -0
- data/ext/pandoc_rb/src/Text/Pandoc/C/Types.hs +73 -0
- data/ext/pandoc_rb/src/Text/Pandoc/C/Utils.hs +78 -0
- data/ext/pandoc_rb/stack.yaml +70 -0
- data/ext/pandoc_rb/test/DetailedSpec.hs +173 -0
- data/lib/pandoc_rb.rb +96 -0
- data/lib/pandoc_rb/error.rb +6 -0
- data/lib/pandoc_rb/parse_failure.rb +11 -0
- data/lib/pandoc_rb/parsec_error.rb +13 -0
- data/lib/pandoc_rb/readers.rb +27 -0
- data/lib/pandoc_rb/version.rb +5 -0
- data/lib/pandoc_rb/writers.rb +46 -0
- data/pandoc_rb.gemspec +37 -0
- data/src/Text/Pandoc/C.hs +217 -0
- data/src/Text/Pandoc/C_stub.h +9 -0
- metadata +206 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c27ff79488f9163a4b41df80ae1d95e84f89e824
|
4
|
+
data.tar.gz: 0513060bf403e6030a1b0a4404a87a60260aa04d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 53e519be108994e836a6607d628c21e710df3d5b1cf05de9946073bf358e7c5d85f16dc8e2359b5e8b8e552ee28103320faa664a650c9b78dd603a3630a3e018
|
7
|
+
data.tar.gz: c18837eeb3c34ef302ab17cdc5dd2ca8678679cafc26b5f8ecd538515f043a9e2696354ca00e29900a65b77e1bb91052c1953e7149002ed9661f5d426a73851a
|
data/.gitignore
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
*.aux
|
2
|
+
*.chi
|
3
|
+
*.chs.h
|
4
|
+
*.dyn_hi
|
5
|
+
*.dyn_o
|
6
|
+
*.eventlog
|
7
|
+
*.gem
|
8
|
+
*.hi
|
9
|
+
*.hp
|
10
|
+
*.log
|
11
|
+
*.o
|
12
|
+
*.out
|
13
|
+
*.prof
|
14
|
+
*.rbc
|
15
|
+
*.so
|
16
|
+
*.swp
|
17
|
+
.HTF/
|
18
|
+
.cabal-sandbox/
|
19
|
+
.hpc
|
20
|
+
.hsenv
|
21
|
+
.rvmrc
|
22
|
+
.stack-work/
|
23
|
+
/.bundle/
|
24
|
+
/.config
|
25
|
+
/.yardoc/
|
26
|
+
/InstalledFiles
|
27
|
+
/_yardoc/
|
28
|
+
/coverage/
|
29
|
+
/doc/
|
30
|
+
/ext/pandoc_rb/Makefile
|
31
|
+
/lib/Text_Pandoc_C.so
|
32
|
+
/lib/bundler/man/
|
33
|
+
/pkg/
|
34
|
+
/rdoc/
|
35
|
+
/spec/examples.txt
|
36
|
+
/spec/reports/
|
37
|
+
/test/tmp/
|
38
|
+
/test/version_tmp/
|
39
|
+
/tmp/
|
40
|
+
/vendor/bundle
|
41
|
+
cabal-dev
|
42
|
+
cabal.project.local
|
43
|
+
cabal.sandbox.config
|
44
|
+
dist
|
45
|
+
dist-*
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pandoc_rb
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.3.1
|
data/.travis.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
language: ruby
|
2
|
+
cache: bundler
|
3
|
+
cache:
|
4
|
+
directories:
|
5
|
+
- $HOME/.ghc
|
6
|
+
- $HOME/.cabal
|
7
|
+
- $HOME/.stack
|
8
|
+
sudo: required
|
9
|
+
rvm:
|
10
|
+
- 2.3.1
|
11
|
+
|
12
|
+
before_install:
|
13
|
+
- sudo apt-get -qq update
|
14
|
+
- sudo apt-get install -y libgmp-dev
|
15
|
+
- sudo apt-get install -y build-essential
|
16
|
+
- mkdir -p ~/.local/bin
|
17
|
+
- export PATH=$HOME/.local/bin:$PATH
|
18
|
+
- travis_retry curl -L https://www.stackage.org/stack/linux-x86_64 | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'
|
19
|
+
- stack update
|
20
|
+
|
21
|
+
install:
|
22
|
+
- bundle install
|
23
|
+
- bundle exec rake compile
|
24
|
+
- bundle exec rake build
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
pandoc_rb (0.2.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
benchmark-ips (2.7.2)
|
10
|
+
byebug (9.0.6)
|
11
|
+
coderay (1.1.1)
|
12
|
+
kalibera (0.1)
|
13
|
+
memoist (~> 0.11.0)
|
14
|
+
rbzip2 (~> 0.2.0)
|
15
|
+
memoist (0.11.0)
|
16
|
+
method_source (0.8.2)
|
17
|
+
minitest (5.8.3)
|
18
|
+
pandoc-ruby (2.0.1)
|
19
|
+
pry (0.10.4)
|
20
|
+
coderay (~> 1.1.0)
|
21
|
+
method_source (~> 0.8.1)
|
22
|
+
slop (~> 3.4)
|
23
|
+
pry-byebug (3.4.2)
|
24
|
+
byebug (~> 9.0)
|
25
|
+
pry (~> 0.10)
|
26
|
+
rake (10.5.0)
|
27
|
+
rake-compiler (1.0.4)
|
28
|
+
rake
|
29
|
+
rbzip2 (0.2.0)
|
30
|
+
slop (3.6.0)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
benchmark-ips
|
37
|
+
bundler (~> 1.15.1)
|
38
|
+
kalibera
|
39
|
+
minitest (~> 5.0)
|
40
|
+
pandoc-ruby
|
41
|
+
pandoc_rb!
|
42
|
+
pry
|
43
|
+
pry-byebug
|
44
|
+
rake (~> 10.0)
|
45
|
+
rake-compiler
|
46
|
+
|
47
|
+
BUNDLED WITH
|
48
|
+
1.15.1
|
data/LICENSE
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
Copyright Michael Klein (c) 2017
|
2
|
+
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
7
|
+
|
8
|
+
* Redistributions of source code must retain the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
10
|
+
|
11
|
+
* Redistributions in binary form must reproduce the above
|
12
|
+
copyright notice, this list of conditions and the following
|
13
|
+
disclaimer in the documentation and/or other materials provided
|
14
|
+
with the distribution.
|
15
|
+
|
16
|
+
* Neither the name of Michael Klein nor the names of other
|
17
|
+
contributors may be used to endorse or promote products derived
|
18
|
+
from this software without specific prior written permission.
|
19
|
+
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
24
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
26
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
27
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
28
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
29
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
Copyright Michael Klein (c) 2017
|
2
|
+
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
7
|
+
|
8
|
+
* Redistributions of source code must retain the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
10
|
+
|
11
|
+
* Redistributions in binary form must reproduce the above
|
12
|
+
copyright notice, this list of conditions and the following
|
13
|
+
disclaimer in the documentation and/or other materials provided
|
14
|
+
with the distribution.
|
15
|
+
|
16
|
+
* Neither the name of Michael Klein nor the names of other
|
17
|
+
contributors may be used to endorse or promote products derived
|
18
|
+
from this software without specific prior written permission.
|
19
|
+
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
24
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
26
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
27
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
28
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
29
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
[](https://travis-ci.org/michaeljklein/pandoc-ruby)
|
2
|
+
|
3
|
+
|
4
|
+
# PandocRb
|
5
|
+
|
6
|
+
Like [PandocRuby](https://github.com/alphabetum/pandoc-ruby), but its interface is more limited:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
module PandocRb
|
10
|
+
def self.raise_exception(result)
|
11
|
+
..
|
12
|
+
|
13
|
+
def self.convert(in_format_str, out_format_str, input_str, extract_media_path='')
|
14
|
+
..
|
15
|
+
|
16
|
+
def self.reader_from_ext(extension)
|
17
|
+
..
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
The primary benefit is that instead of using `system` calls,
|
22
|
+
`pandoc_rb` directly uses the memory allocated for Ruby [String](https://ruby-doc.org/core-2.2.1/String.html)s
|
23
|
+
through the FFI.
|
24
|
+
|
25
|
+
The benchmark results indicate that both significant constant (from initialization) and linear (from streaming through bash pipes)
|
26
|
+
overhead for `PandocRuby` is eliminated in `pandoc_rb`.
|
27
|
+
|
28
|
+
## Installation
|
29
|
+
|
30
|
+
Requires Haskell-[`stack`](https://docs.haskellstack.org/en/stable/README/)
|
31
|
+
|
32
|
+
Add this line to your application's Gemfile:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
gem 'pandoc_rb'
|
36
|
+
```
|
37
|
+
|
38
|
+
And then execute:
|
39
|
+
|
40
|
+
$ bundle install
|
41
|
+
|
42
|
+
Or install it yourself as:
|
43
|
+
|
44
|
+
$ gem install pandoc_rb
|
45
|
+
|
46
|
+
## Usage
|
47
|
+
|
48
|
+
`pandoc_rb`'s main interface is contained in the `PandocRb` module.
|
49
|
+
|
50
|
+
The public interface consists of constants and a main conversion function
|
51
|
+
|
52
|
+
The constants include:
|
53
|
+
```ruby
|
54
|
+
PandocRb::Version # The current version
|
55
|
+
PandocRb::Readers # A list of allowed readers
|
56
|
+
PandocRb::Writers # A list of allowed writers
|
57
|
+
```
|
58
|
+
|
59
|
+
And the main conversion function is:
|
60
|
+
```ruby
|
61
|
+
# General conversion function
|
62
|
+
PandocRb.convert input_format, output_format, input_string, (optional) extract_media_path
|
63
|
+
|
64
|
+
# Convert `markdown` to `latex`
|
65
|
+
PandocRb.convert 'markdown', 'latex', '_italic text_'
|
66
|
+
|
67
|
+
# Convert `docx` to `latex` from file
|
68
|
+
PandocRb.convert 'docx', 'latex', File.binread('some_doc.docx'), `extract/figures/dir`
|
69
|
+
|
70
|
+
# Convert `markdown` to `docx`, writing to a `docx` file
|
71
|
+
File.open 'some_doc.docx', 'wb' do |file|
|
72
|
+
file.write PandocRb.convert('markdown', 'docx', '_italic text_')
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
1. Fork it ( https://github.com/michaeljklein/pandoc_rb/fork )
|
79
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
80
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
81
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
82
|
+
5. Create a new Pull Request
|
83
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
require 'rake/extensiontask'
|
4
|
+
|
5
|
+
Rake::ExtensionTask.new 'pandoc_rb', $gemspec do |ext|
|
6
|
+
ext.lib_dir = "lib/pandoc_rb"
|
7
|
+
end
|
8
|
+
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << "test"
|
11
|
+
t.libs << "lib"
|
12
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
13
|
+
end
|
14
|
+
|
15
|
+
task :build => :compile
|
16
|
+
|
17
|
+
desc "Run tests"
|
18
|
+
task :default => :test
|
19
|
+
|
20
|
+
task :nuke do
|
21
|
+
Dir.chdir(__dir__) do
|
22
|
+
FileUtils.rm_rf 'tmp'
|
23
|
+
FileUtils.rm_rf 'ext/pandoc_rb/.stack-work'
|
24
|
+
FileUtils.rm_f 'ext/pandoc_rb/a.out'
|
25
|
+
Dir['**/*.so'].each do |so|
|
26
|
+
FileUtils.rm_f so
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
data/Setup.hs
ADDED
data/bench/bench.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'pandoc_rb'
|
2
|
+
require 'benchmark/ips'
|
3
|
+
require 'pandoc-ruby'
|
4
|
+
|
5
|
+
|
6
|
+
def test_files_hash(dir='test/files')
|
7
|
+
@test_files_hash ||= begin
|
8
|
+
hash = {}
|
9
|
+
Dir["#{dir}/*"].each do |file|
|
10
|
+
extension = PandocRb.reader_from_ext File.extname(file)
|
11
|
+
hash[extension] ||= []
|
12
|
+
hash[extension] << file
|
13
|
+
end
|
14
|
+
hash
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
Benchmark.ips do |bench|
|
20
|
+
10.times do
|
21
|
+
PandocRb.convert 'markdown', 'latex', 'warmup'
|
22
|
+
end
|
23
|
+
|
24
|
+
10.times do
|
25
|
+
PandocRuby.convert 'warmup', from: 'markdown', to: 'latex'
|
26
|
+
end
|
27
|
+
|
28
|
+
# Number of seconds to run each benchmark
|
29
|
+
bench.time = 5 # seconds
|
30
|
+
|
31
|
+
bench.stats = :bootstrap
|
32
|
+
bench.confidence = 95 # percent
|
33
|
+
|
34
|
+
test_files_hash.each do |reader, file_paths|
|
35
|
+
if PandocRb::Readers.include? reader
|
36
|
+
file_paths.each do |file_path|
|
37
|
+
file = File.binread file_path
|
38
|
+
file.force_encoding "UTF-8"
|
39
|
+
bench.report "from: #{reader}, to: Fixnum, file: #{File.basename(file_path)}, sum bytes" do
|
40
|
+
file.each_byte.reduce(:+)
|
41
|
+
end
|
42
|
+
['markdown', 'latex', 'html', 'docx'].each do |writer|
|
43
|
+
GC.start(full_mark: true, immediate_sweep: true)
|
44
|
+
|
45
|
+
# Convert by telling pandoc through a C extension to read the string
|
46
|
+
bench.report "from: #{reader}, to: #{writer}, file: #{File.basename(file_path)}, pandoc_rb" do
|
47
|
+
PandocRb.convert reader, writer, file
|
48
|
+
end
|
49
|
+
|
50
|
+
# Convert by telling pandoc through PandocRuby to read the file
|
51
|
+
bench.report "from: #{reader}, to: #{writer}, file: #{File.basename(file_path)}, pandoc-ruby (read file)" do
|
52
|
+
PandocRuby.convert [file_path], from: reader, to: writer
|
53
|
+
end
|
54
|
+
|
55
|
+
# PandocRuby is incapable of accepting a raw docx file as input
|
56
|
+
unless file_path.match(/\.docx/)
|
57
|
+
# Convert by telling pandoc through PandocRuby to read stdin
|
58
|
+
bench.report "from: #{reader}, to: #{writer}, file: #{File.basename(file_path)}, pandoc-ruby" do
|
59
|
+
PandocRuby.convert file , from: reader, to: writer
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
bench.compare!
|
68
|
+
end
|
69
|
+
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "pandoc_rb"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
# Loads mkmf which is used to make makefiles for Ruby extensions
|
2
|
+
require 'mkmf'
|
3
|
+
require 'pry'
|
4
|
+
require 'open3'
|
5
|
+
|
6
|
+
|
7
|
+
module OS
|
8
|
+
def OS.windows?
|
9
|
+
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def OS.mac?
|
13
|
+
(/darwin/ =~ RUBY_PLATFORM) != nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def OS.unix?
|
17
|
+
!OS.windows?
|
18
|
+
end
|
19
|
+
|
20
|
+
def OS.linux?
|
21
|
+
OS.unix? and not OS.mac?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
def system_indent(command)
|
27
|
+
puts "running #{command}"
|
28
|
+
exit_status = system command
|
29
|
+
if exit_status
|
30
|
+
puts "ran #{command}"
|
31
|
+
else
|
32
|
+
puts ["failed:", "<command>", command.split(' '), "</command>"].flatten
|
33
|
+
raise "#{command} failed"
|
34
|
+
end
|
35
|
+
exit_status
|
36
|
+
end
|
37
|
+
|
38
|
+
Dir.chdir(__dir__){ system_indent 'stack setup' }
|
39
|
+
|
40
|
+
Dir.chdir(__dir__){ system_indent 'stack build' }
|
41
|
+
|
42
|
+
def stack_path
|
43
|
+
@stack_path ||= begin
|
44
|
+
Dir.chdir(__dir__) do
|
45
|
+
temp_stack_path = `stack path`.lines.map do |line|
|
46
|
+
/^(?<var>[^:]+): (?<val>.*)$/ =~ line.chomp
|
47
|
+
[var, File.absolute_path(val)]
|
48
|
+
end.to_h
|
49
|
+
temp_stack_path['compiler-lib'] = temp_stack_path['compiler-bin'].sub(/bin$/, 'lib')
|
50
|
+
temp_stack_path['compiler'] = temp_stack_path['compiler-bin'].sub(/^.*\/([^\/]+)\/bin$/, '\1')
|
51
|
+
temp_stack_path
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
# Give it a name
|
58
|
+
extension_name = 'pandoc_rb/pandoc_rb'
|
59
|
+
|
60
|
+
LIBDIR = ::CONFIG['libdir']
|
61
|
+
INCLUDEDIR = ::CONFIG['includedir']
|
62
|
+
|
63
|
+
HEADER_DIRS = [
|
64
|
+
File.join(stack_path['compiler-lib'], stack_path['compiler'], "rts"),
|
65
|
+
File.join(stack_path['local-install-root'], "bin"),
|
66
|
+
|
67
|
+
# /home/hsolo/.stack/programs/x86_64-linux/ghc-8.0.2/lib/ghc-8.0.2/include/
|
68
|
+
File.join(stack_path['compiler-lib'], stack_path['compiler'], "include"),
|
69
|
+
|
70
|
+
# .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/PandocRb.dylib/PandocRb.dylib-tmp/
|
71
|
+
File.join(stack_path['dist-dir'], "build/PandocRb.dylib/PandocRb.dylib-tmp"),
|
72
|
+
|
73
|
+
# Then search /usr/local for people that installed from source
|
74
|
+
'/usr/local/include',
|
75
|
+
|
76
|
+
# Check the ruby install locations
|
77
|
+
INCLUDEDIR,
|
78
|
+
|
79
|
+
# Finally fall back to /usr
|
80
|
+
'/usr/include',
|
81
|
+
]
|
82
|
+
|
83
|
+
LIB_DIRS = [
|
84
|
+
# /home/hsolo/.stack/programs/x86_64-linux/ghc-8.0.2/lib/ghc-8.0.2/rts/
|
85
|
+
File.join(stack_path['compiler-lib'], stack_path['compiler'], "rts"),
|
86
|
+
File.join(stack_path['local-install-root'], "bin"),
|
87
|
+
File.join(stack_path['dist-dir'], "build/PandocRb.dylib/PandocRb.dylib-tmp"), # PandocRb_stub.h
|
88
|
+
File.join(stack_path['compiler-lib'], stack_path['compiler'], "include"),
|
89
|
+
|
90
|
+
# First search /opt/local for macports
|
91
|
+
'/opt/local/lib',
|
92
|
+
|
93
|
+
# Then search /usr/local for people that installed from source
|
94
|
+
'/usr/local/lib',
|
95
|
+
|
96
|
+
# Check the ruby install locations
|
97
|
+
LIBDIR,
|
98
|
+
|
99
|
+
# Finally fall back to /usr
|
100
|
+
'/usr/lib',
|
101
|
+
]
|
102
|
+
|
103
|
+
dir_config extension_name, HEADER_DIRS, LIB_DIRS
|
104
|
+
|
105
|
+
have_header 'stdio.h'
|
106
|
+
have_header 'ruby.h'
|
107
|
+
have_header 'HsFFI.h'
|
108
|
+
have_header 'PandocRb_stub.h', 'HsFFI.h'
|
109
|
+
find_library 'HSrts-ghc8.0.2', nil
|
110
|
+
find_library 'PandocRb', nil
|
111
|
+
|
112
|
+
$INCFLAGS = File.join(stack_path['local-install-root'], "bin/PandocRb.dylib") + ' ' + $INCFLAGS
|
113
|
+
$INCFLAGS += " -I#{File.join(stack_path['compiler-lib'], stack_path['compiler'], "include")}" # HsFFI.h
|
114
|
+
$INCFLAGS += " -I#{File.join(stack_path['dist-dir'], "build/PandocRb.dylib/PandocRb.dylib-tmp")}" # PandocRb_stub.h
|
115
|
+
$INCFLAGS += " -L#{File.join(stack_path['compiler-lib'], stack_path['compiler'], "rts")}"
|
116
|
+
$INCFLAGS += " -lHSrts-ghc8.0.2"
|
117
|
+
|
118
|
+
$LDFLAGS = File.join(stack_path['local-install-root'], "bin/PandocRb.dylib") + ' ' + $LDFLAGS
|
119
|
+
$LDFLAGS += " -I#{File.join(stack_path['compiler-lib'], stack_path['compiler'], "include")}" # HsFFI.h
|
120
|
+
$LDFLAGS += " -I#{File.join(stack_path['dist-dir'], "build/PandocRb.dylib/PandocRb.dylib-tmp")}" # PandocRb_stub.h
|
121
|
+
$LDFLAGS += " -L#{File.join(stack_path['compiler-lib'], stack_path['compiler'], "rts")}"
|
122
|
+
$LDFLAGS += " -Wl,-rpath,'#{File.join(stack_path['compiler-lib'], stack_path['compiler'], "rts")}'"
|
123
|
+
$LDFLAGS += " -Wl,-R'#{File.join(stack_path['local-install-root'], "bin")}'" unless OS.mac?
|
124
|
+
$LDFLAGS += " -Wl,-rpath,'#{File.join(stack_path['local-install-root'], "bin")}'"
|
125
|
+
$LDFLAGS += " -lHSrts-ghc8.0.2"
|
126
|
+
|
127
|
+
create_makefile extension_name
|
128
|
+
|
129
|
+
system_indent 'make'
|
130
|
+
|