Top Level Namespace
Defined Under Namespace
Modules: SevenZipRuby
Constant Summary collapse
- SO_TARGET_DIR =
File.(File.join(RbConfig::CONFIG["sitearchdir"], "seven_zip_ruby"))
Instance Method Summary collapse
- #check_ostype ⇒ Object
- #create_p7zip_makefile(type) ⇒ Object
- #dummy_makefile ⇒ Object
- #main ⇒ Object
- #real_makefile ⇒ Object
- #sample_cpp_source ⇒ Object
- #sample_for_nullptr ⇒ Object
- #sample_for_rb_thread_call_without_gvl(have_ruby_thread_h) ⇒ Object
Instance Method Details
#check_ostype ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'ext/p7zip/extconf.rb', line 46 def check_ostype if (RUBY_PLATFORM.include?("darwin")) return :macosx elsif (RUBY_PLATFORM.include?("linux")) return :linux else raise "Unsupported platform" end end |
#create_p7zip_makefile(type) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'ext/p7zip/extconf.rb', line 8 def create_p7zip_makefile(type) config = RbConfig::CONFIG allflags = config["ARCH_FLAG"] + ' -O -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_REENTRANT -DENV_UNIX ' case(type) when :macosx allflags += ' -DENV_MACOSX ' cc_shared = nil link_shared = "-bundle" local_libs = "-framework CoreFoundation" local_libs_dll = '$(LOCAL_LIBS)' when :linux allflags += ' -DNDEBUG -D_7ZIP_LARGE_PAGES -pipe -s ' cc_shared = "-fPIC" link_shared = "-fPIC -shared" local_libs = "-lpthread" local_libs_dll = '$(LOCAL_LIBS) -ldl' end cc_shared_content = (cc_shared ? "CC_SHARED=#{cc_shared}" : "") makefile_content = "ALLFLAGS=\#{allflags} $(LOCAL_FLAGS)\nCXX=\#{config['CXX']} $(ALLFLAGS)\nCC=\#{config['CC']} $(ALLFLAGS)\n\#{cc_shared_content}\nLINK_SHARED=\#{link_shared}\n\nLOCAL_LIBS=\#{local_libs}\nLOCAL_LIBS_DLL=\#{local_libs_dll}\nOBJ_CRC32=$(OBJ_CRC32_C)\n" File.open("makefile.machine", "w") do |file| file.puts makefile_content end end |
#dummy_makefile ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'ext/p7zip/extconf.rb', line 56 def dummy_makefile return "all: dummy\n.PHONY: all dummy install\ninstall:\ndummy:\n" end |
#main ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'ext/p7zip/extconf.rb', line 86 def main if (RUBY_PLATFORM.include?("mswin") || RUBY_PLATFORM.include?("mingw")) mfile = open("Makefile", "wb") mfile.puts dummy_makefile mfile.close else ostype = check_ostype create_p7zip_makefile(ostype) MakeMakefile.rm_f "makefile" mfile = open("Makefile", "w") mfile.puts real_makefile mfile.close end end |
#real_makefile ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'ext/p7zip/extconf.rb', line 65 def real_makefile mf = ".PHONY: all 7zso clean\n\nall: 7zso\n\n7zso:\n mkdir -p bin\n $(MAKE) -C CPP/7zip/Bundles/Format7zFree all\n\nclean:\n $(MAKE) -C CPP/7zip/Bundles/Format7zFree clean\n rm -fr bin\n\ninstall:\n" dest = File.(File.join(File.dirname(__FILE__), "../../lib/seven_zip_ruby")) mf += "\tcp bin/7z.so #{dest}\n" return mf end |
#sample_cpp_source ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'ext/seven_zip_ruby/extconf.rb', line 6 def sample_cpp_source # Check the following features. # - lambda # - std::function # - std::array # - memset_s defined, on Darwin and BSD return "#include <functional>\n#include <algorithm>\n#include <array>\n#include <iostream>\n\n#include <ruby.h>\n\n// see the test on memset_s below, which is a purely BSD thing\n#if defined(__APPLE__) || defined(BSD)\n#include <string.h>\n#endif\n\nvoid test()\n{\n int array[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };\n const int size = sizeof(array)/sizeof(array[0]);\n std::array<int, size> var_list;\n\n std::function<int (int, int)> convert = [&](int arg1, int arg2){\n return arg1 * arg2;\n };\n\n const int value = 10;\n\n std::transform(array, array + size, var_list.begin(), [&](int arg){\n return convert(arg, value);\n });\n\n std::for_each(var_list.begin(), var_list.end(), [](int num){ std::cout << num << std::endl; });\n\n#if defined(__APPLE__) || defined(BSD)\n char str[] = \"imareallycoolstringright\";\n memset_s(str, sizeof str, 'b', 5);\n#endif\n}\n" end |
#sample_for_nullptr ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'ext/seven_zip_ruby/extconf.rb', line 67 def sample_for_nullptr return "#include <stdio.h>\nint main(int argc, char *argv[])\n{\n printf(\"%p\\n\", nullptr);\n return 0;\n}\n" end |
#sample_for_rb_thread_call_without_gvl(have_ruby_thread_h) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'ext/seven_zip_ruby/extconf.rb', line 51 def sample_for_rb_thread_call_without_gvl(have_ruby_thread_h) header = "#include <ruby.h>\n" header += "#include <ruby/thread.h>\n" if (have_ruby_thread_h) body = "\n#include <stdio.h>\n\nint main(int argc, char *argv[])\n{\n printf(\"%p\\n\", rb_thread_call_without_gvl);\n return 0;\n}\n" return header + body end |