GitHub

@@ -1,54 +1,138 @@

1+

# Environment Variable Configuration:

2+

#

3+

# MRUBY_MIRB_READLINE - Control which readline library mirb uses:

4+

# auto (default) - Auto-detect: try readline, then edit, then linenoise

5+

# readline, gnu - Force GNU readline only

6+

# edit, libedit - Force libedit only

7+

# linenoise - Force linenoise only

8+

# none, off, false, disabled - Use plain input mode (no readline)

9+

#

10+

# Example:

11+

# MRUBY_MIRB_READLINE=none rake

12+

# MRUBY_MIRB_READLINE=linenoise rake

13+114

MRuby::Gem::Specification.new('mruby-bin-mirb') do |spec|

215

spec.license = 'MIT'

316

spec.author = 'mruby developers'

417

spec.summary = 'mirb command'

5186-

if spec.build.cc.search_header_path 'readline/readline.h'

7-

spec.cc.defines << "MRB_USE_READLINE"

8-

spec.cc.defines << "MRB_READLINE_HEADER='<readline/readline.h>'"

9-

spec.cc.defines << "MRB_READLINE_HISTORY='<readline/history.h>'"

10-

if spec.build.cc.search_header_path 'termcap.h'

11-

if MRUBY_BUILD_HOST_IS_CYGWIN || MRUBY_BUILD_HOST_IS_OPENBSD

12-

if spec.build.cc.search_header_path 'termcap.h'

13-

if MRUBY_BUILD_HOST_IS_CYGWIN then

14-

spec.linker.libraries << 'ncurses'

15-

else

16-

spec.linker.libraries << 'termcap'

19+

# Allow user to override readline detection via environment variable

20+

readline_mode = (ENV['MRUBY_MIRB_READLINE'] || 'auto').downcase

21+22+

case readline_mode

23+

when 'auto'

24+

# Auto-detect: try readline, then edit, then linenoise (default behavior)

25+

if spec.build.cc.search_header_path 'readline/readline.h'

26+

spec.cc.defines << "MRB_USE_READLINE"

27+

spec.cc.defines << "MRB_READLINE_HEADER='<readline/readline.h>'"

28+

spec.cc.defines << "MRB_READLINE_HISTORY='<readline/history.h>'"

29+

if spec.build.cc.search_header_path 'termcap.h'

30+

if MRUBY_BUILD_HOST_IS_CYGWIN || MRUBY_BUILD_HOST_IS_OPENBSD

31+

if spec.build.cc.search_header_path 'termcap.h'

32+

if MRUBY_BUILD_HOST_IS_CYGWIN then

33+

spec.linker.libraries << 'ncurses'

34+

else

35+

spec.linker.libraries << 'termcap'

36+

end

1737

end

1838

end

1939

end

20-

end

21-

if RUBY_PLATFORM.include?('netbsd')

22-

spec.linker.libraries << 'edit'

23-

else

24-

spec.linker.libraries << 'readline'

25-

if RUBY_PLATFORM.include?('darwin')

26-

# Workaround to build with Homebrew's readline on Mac (#4537)

27-

lib_path = spec.build.cc.header_search_paths.find do |include_path|

28-

lib_path = File.expand_path("#{include_path}/../lib")

29-

break lib_path if File.exist?("#{lib_path}/libreadline.dylib") ||

30-

File.exist?("#{lib_path}/libreadline.a")

40+

if RUBY_PLATFORM.include?('netbsd')

41+

spec.linker.libraries << 'edit'

42+

else

43+

spec.linker.libraries << 'readline'

44+

if RUBY_PLATFORM.include?('darwin')

45+

# Workaround to build with Homebrew's readline on Mac (#4537)

46+

lib_path = spec.build.cc.header_search_paths.find do |include_path|

47+

lib_path = File.expand_path("#{include_path}/../lib")

48+

break lib_path if File.exist?("#{lib_path}/libreadline.dylib") ||

49+

File.exist?("#{lib_path}/libreadline.a")

50+

end

51+

spec.linker.library_paths << lib_path if lib_path

52+

elsif spec.build.cc.search_header_path 'curses.h'

53+

spec.linker.libraries << 'ncurses'

54+

if spec.build.cc.search_header_path 'term.h'

55+

spec.linker.libraries << 'tinfo'

56+

end

57+

elsif spec.build.cc.search_header_path 'ncursesw/curses.h'

58+

spec.linker.libraries << 'ncursesw'

59+

if spec.build.cc.search_header_path 'ncursesw/term.h'

60+

spec.linker.libraries << 'tinfow'

61+

end

3162

end

32-

spec.linker.library_paths << lib_path if lib_path

33-

elsif spec.build.cc.search_header_path 'curses.h'

34-

spec.linker.libraries << 'ncurses'

35-

if spec.build.cc.search_header_path 'term.h'

36-

spec.linker.libraries << 'tinfo'

63+

end

64+

elsif spec.build.cc.search_header_path 'edit/readline/readline.h'

65+

spec.cc.defines << "MRB_USE_READLINE"

66+

spec.cc.defines << "MRB_READLINE_HEADER='<edit/readline/readline.h>'"

67+

spec.cc.defines << "MRB_READLINE_HISTORY='<edit/readline/history.h>'"

68+

spec.linker.libraries << "edit"

69+

elsif spec.build.cc.search_header_path 'linenoise.h'

70+

spec.cc.defines << "MRB_USE_LINENOISE"

71+

end

72+73+

when 'readline', 'gnu'

74+

# Force GNU readline only

75+

if spec.build.cc.search_header_path 'readline/readline.h'

76+

spec.cc.defines << "MRB_USE_READLINE"

77+

spec.cc.defines << "MRB_READLINE_HEADER='<readline/readline.h>'"

78+

spec.cc.defines << "MRB_READLINE_HISTORY='<readline/history.h>'"

79+

if spec.build.cc.search_header_path 'termcap.h'

80+

if MRUBY_BUILD_HOST_IS_CYGWIN || MRUBY_BUILD_HOST_IS_OPENBSD

81+

if spec.build.cc.search_header_path 'termcap.h'

82+

if MRUBY_BUILD_HOST_IS_CYGWIN then

83+

spec.linker.libraries << 'ncurses'

84+

else

85+

spec.linker.libraries << 'termcap'

86+

end

87+

end

3788

end

38-

elsif spec.build.cc.search_header_path 'ncursesw/curses.h'

39-

spec.linker.libraries << 'ncursesw'

40-

if spec.build.cc.search_header_path 'ncursesw/term.h'

41-

spec.linker.libraries << 'tinfow'

89+

end

90+

if RUBY_PLATFORM.include?('netbsd')

91+

spec.linker.libraries << 'edit'

92+

else

93+

spec.linker.libraries << 'readline'

94+

if RUBY_PLATFORM.include?('darwin')

95+

lib_path = spec.build.cc.header_search_paths.find do |include_path|

96+

lib_path = File.expand_path("#{include_path}/../lib")

97+

break lib_path if File.exist?("#{lib_path}/libreadline.dylib") ||

98+

File.exist?("#{lib_path}/libreadline.a")

99+

end

100+

spec.linker.library_paths << lib_path if lib_path

101+

elsif spec.build.cc.search_header_path 'curses.h'

102+

spec.linker.libraries << 'ncurses'

103+

if spec.build.cc.search_header_path 'term.h'

104+

spec.linker.libraries << 'tinfo'

105+

end

106+

elsif spec.build.cc.search_header_path 'ncursesw/curses.h'

107+

spec.linker.libraries << 'ncursesw'

108+

if spec.build.cc.search_header_path 'ncursesw/term.h'

109+

spec.linker.libraries << 'tinfow'

110+

end

42111

end

43112

end

44113

end

45-

elsif spec.build.cc.search_header_path 'edit/readline/readline.h'

46-

spec.cc.defines << "MRB_USE_READLINE"

47-

spec.cc.defines << "MRB_READLINE_HEADER='<edit/readline/readline.h>'"

48-

spec.cc.defines << "MRB_READLINE_HISTORY='<edit/readline/history.h>'"

49-

spec.linker.libraries << "edit"

50-

elsif spec.build.cc.search_header_path 'linenoise.h'

51-

spec.cc.defines << "MRB_USE_LINENOISE"

114+115+

when 'edit', 'libedit'

116+

# Force libedit only

117+

if spec.build.cc.search_header_path 'edit/readline/readline.h'

118+

spec.cc.defines << "MRB_USE_READLINE"

119+

spec.cc.defines << "MRB_READLINE_HEADER='<edit/readline/readline.h>'"

120+

spec.cc.defines << "MRB_READLINE_HISTORY='<edit/readline/history.h>'"

121+

spec.linker.libraries << "edit"

122+

end

123+124+

when 'linenoise'

125+

# Force linenoise only

126+

if spec.build.cc.search_header_path 'linenoise.h'

127+

spec.cc.defines << "MRB_USE_LINENOISE"

128+

end

129+130+

when 'none', 'off', 'false', 'disabled'

131+

# Disable readline - use plain input mode

132+133+

else

134+

fail "Invalid MRUBY_MIRB_READLINE='#{readline_mode}'. " \

135+

"Valid values: auto, readline, gnu, edit, libedit, linenoise, none, off, false, disabled"

52136

end

5313754138

spec.bins = %w(mirb)

Read the original on github.com ↗