本文簡要介紹ruby語言中 MakeMakefile.create_makefile
的用法。
用法
create_makefile(target, srcprefix = nil) { |conf| ... }
為您的擴展生成 Makefile,傳遞您可能通過其他方法生成的任何選項和預處理器常量。
target
名稱應對應於 C 擴展中定義的全局函數名稱,減去 Init_
。例如,如果您的 C 擴展被定義為 Init_foo
,那麽您的目標將隻是 “foo”。
如果目標名稱中出現任何“/” 字符,則隻有姓氏被解釋為目標名稱,其餘的被視為頂級目錄名稱,生成的 Makefile 將相應地更改以遵循該目錄結構。
例如,如果您將“test/foo” 作為目標名稱傳遞,您的擴展將安裝在“test” 目錄下。這意味著為了稍後在 Ruby 程序中加載文件,必須遵循該目錄結構,例如require 'test/foo'
。
當您的源文件與構建腳本不在同一目錄中時,應使用srcprefix
。這不僅消除了您手動將源文件複製到與構建腳本相同的目錄的需要,而且還在生成的 Makefile 中設置了正確的target_prefix
。
設置 target_prefix
將反過來將生成的二進製文件安裝在 RbConfig::CONFIG['sitearchdir']
下的目錄中,該目錄在您運行時模仿本地文件係統 make install
。
例如,給定以下文件樹:
ext/
extconf.rb
test/
foo.c
並給出以下代碼:
create_makefile('test/foo', 'test')
這會將生成的 Makefile 中的 target_prefix
設置為 “test”。反過來,當通過make install
命令安裝時,將創建以下文件樹:
/path/to/ruby/sitearchdir/test/foo.so
建議您使用這種方法來生成您的 makefile,而不是手動複製文件,因為某些第三方庫可能依賴於正確設置的 target_prefix
。
srcprefix
參數可用於覆蓋默認源目錄,即當前目錄。它作為 VPATH
的一部分包含在 INCFLAGS
列表中。
相關用法
- Ruby MakeMakefile.create_header用法及代碼示例
- Ruby MakeMakefile.convertible_int用法及代碼示例
- Ruby MakeMakefile.enable_config用法及代碼示例
- Ruby MakeMakefile.have_const用法及代碼示例
- Ruby MakeMakefile.with_config用法及代碼示例
- Ruby MatchData.pre_match用法及代碼示例
- Ruby Matrix lup()用法及代碼示例
- Ruby Matrix unitary?()用法及代碼示例
- Ruby Matrix symmetric?()用法及代碼示例
- Ruby Matrix t()用法及代碼示例
- Ruby Matrix identity()用法及代碼示例
- Ruby Matrix hash()用法及代碼示例
- Ruby Matrix hadamard_product()用法及代碼示例
- Ruby Matrix singular?()用法及代碼示例
- Ruby Math sqrt()用法及代碼示例
- Ruby Matrix round()用法及代碼示例
- Ruby Matrix collect()用法及代碼示例
- Ruby Math.acosh用法及代碼示例
- Ruby Markdown類用法及代碼示例
- Ruby Matrix hermitian?()用法及代碼示例
- Ruby Matrix row_vectors()用法及代碼示例
- Ruby Matrix conjugate()用法及代碼示例
- Ruby Math.asinh用法及代碼示例
- Ruby Matrix cofactor()用法及代碼示例
- Ruby Matrix rectangular()用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 MakeMakefile.create_makefile。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。