2016-04-08 16:28:43 +02:00
|
|
|
#: * `ln`, `link` [`--overwrite`] [`--dry-run`] [`--force`] <formula>:
|
|
|
|
#: Symlink all of <formula>'s installed files into the Homebrew prefix. This
|
|
|
|
#: is done automatically when you install formulae but can be useful for DIY
|
|
|
|
#: installations.
|
|
|
|
#:
|
|
|
|
#: If `--overwrite` is passed, Homebrew will delete files which already exist in
|
|
|
|
#: the prefix while linking.
|
|
|
|
#:
|
|
|
|
#: If `--dry-run` or `-n` is passed, Homebrew will list all files which would
|
|
|
|
#: be linked or which would be deleted by `brew link --overwrite`, but will not
|
|
|
|
#: actually link or delete any files.
|
|
|
|
#:
|
2017-04-02 10:14:21 +01:00
|
|
|
#: If `--force` (or `-f`) is passed, Homebrew will allow keg-only formulae to be linked.
|
2016-04-08 16:28:43 +02:00
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
require "ostruct"
|
2012-10-20 20:54:11 -05:00
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2016-09-26 01:44:51 +02:00
|
|
|
module_function
|
|
|
|
|
2010-09-11 20:22:54 +01:00
|
|
|
def link
|
2012-02-04 00:01:29 -06:00
|
|
|
raise KegUnspecifiedError if ARGV.named.empty?
|
|
|
|
|
2012-10-20 20:54:11 -05:00
|
|
|
mode = OpenStruct.new
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
mode.overwrite = true if ARGV.include? "--overwrite"
|
2012-10-20 20:54:11 -05:00
|
|
|
mode.dry_run = true if ARGV.dry_run?
|
2012-06-17 16:54:20 -05:00
|
|
|
|
2010-09-11 20:22:54 +01:00
|
|
|
ARGV.kegs.each do |keg|
|
2018-06-05 23:19:18 -04:00
|
|
|
keg_only = Formulary.keg_only?(keg.rack)
|
2016-07-31 18:44:24 +01:00
|
|
|
if HOMEBREW_PREFIX.to_s == "/usr/local" && keg_only &&
|
|
|
|
keg.name.start_with?("openssl", "libressl")
|
2017-10-15 02:28:32 +02:00
|
|
|
opoo <<~EOS
|
2016-07-31 18:44:24 +01:00
|
|
|
Refusing to link: #{keg.name}
|
|
|
|
Linking keg-only #{keg.name} means you may end up linking against the insecure,
|
|
|
|
deprecated system OpenSSL while using the headers from Homebrew's #{keg.name}.
|
2016-07-28 16:49:08 -06:00
|
|
|
Instead, pass the full include/library paths to your compiler e.g.:
|
2016-07-31 18:44:24 +01:00
|
|
|
-I#{HOMEBREW_PREFIX}/opt/#{keg.name}/include -L#{HOMEBREW_PREFIX}/opt/#{keg.name}/lib
|
2016-07-28 16:49:08 -06:00
|
|
|
EOS
|
|
|
|
next
|
|
|
|
elsif keg.linked?
|
2012-03-19 12:24:13 +00:00
|
|
|
opoo "Already linked: #{keg}"
|
2014-06-24 19:04:52 -05:00
|
|
|
puts "To relink: brew unlink #{keg.name} && brew link #{keg.name}"
|
2012-03-19 12:24:13 +00:00
|
|
|
next
|
2016-07-31 18:44:24 +01:00
|
|
|
elsif keg_only && !ARGV.force?
|
2014-06-24 19:04:52 -05:00
|
|
|
opoo "#{keg.name} is keg-only and must be linked with --force"
|
2013-05-20 21:55:01 -05:00
|
|
|
puts "Note that doing so can interfere with building software."
|
2017-03-23 08:42:27 +00:00
|
|
|
puts_keg_only_path_message(keg)
|
2013-05-20 21:55:01 -05:00
|
|
|
next
|
|
|
|
elsif mode.dry_run && mode.overwrite
|
2014-03-27 15:50:06 -05:00
|
|
|
puts "Would remove:"
|
|
|
|
keg.link(mode)
|
2012-06-17 16:54:20 -05:00
|
|
|
|
2012-10-20 20:54:11 -05:00
|
|
|
next
|
|
|
|
elsif mode.dry_run
|
2014-03-27 15:50:06 -05:00
|
|
|
puts "Would link:"
|
|
|
|
keg.link(mode)
|
2017-03-23 08:42:27 +00:00
|
|
|
puts_keg_only_path_message(keg) if keg_only
|
2012-10-20 20:54:11 -05:00
|
|
|
|
2012-06-17 16:54:20 -05:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2013-01-23 00:26:25 -06:00
|
|
|
keg.lock do
|
2014-04-21 09:40:24 -05:00
|
|
|
print "Linking #{keg}... "
|
|
|
|
puts if ARGV.verbose?
|
|
|
|
|
|
|
|
begin
|
|
|
|
n = keg.link(mode)
|
|
|
|
rescue Keg::LinkError
|
|
|
|
puts
|
|
|
|
raise
|
|
|
|
else
|
|
|
|
puts "#{n} symlinks created"
|
2013-01-23 00:26:25 -06:00
|
|
|
end
|
2017-03-23 08:42:27 +00:00
|
|
|
|
2017-05-29 18:24:52 +01:00
|
|
|
puts_keg_only_path_message(keg) if keg_only && !ARGV.homebrew_developer?
|
2012-03-19 00:15:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-23 08:42:27 +00:00
|
|
|
def puts_keg_only_path_message(keg)
|
|
|
|
bin = keg/"bin"
|
|
|
|
sbin = keg/"sbin"
|
|
|
|
return if !bin.directory? && !sbin.directory?
|
|
|
|
|
|
|
|
opt = HOMEBREW_PREFIX/"opt/#{keg.name}"
|
|
|
|
puts "\nIf you need to have this software first in your PATH instead consider running:"
|
2017-04-22 16:28:07 +01:00
|
|
|
puts " #{Utils::Shell.prepend_path_in_profile(opt/"bin")}" if bin.directory?
|
|
|
|
puts " #{Utils::Shell.prepend_path_in_profile(opt/"sbin")}" if sbin.directory?
|
2017-03-23 08:42:27 +00:00
|
|
|
end
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|