3 # This file is part of INAV.
5 # author: Alberto Garcia Hierro <alberto@garciahierro.com>
7 # This Source Code Form is subject to the terms of the Mozilla Public
8 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
9 # You can obtain one at http://mozilla.org/MPL/2.0/.
11 # Alternatively, the contents of this file may be used under the terms
12 # of the GNU General Public License Version 3, as described below:
14 # This file is free software: you may copy, redistribute and/or modify
15 # it under the terms of the GNU General Public License as published by the
16 # Free Software Foundation, either version 3 of the License, or (at your
17 # option) any later version.
19 # This file is distributed in the hope that it will be useful, but
20 # WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
22 # Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program. If not, see http://www.gnu.org/licenses/.
33 def initialize(use_host_gcc)
34 # Look for the compiler in PATH manually, since there
35 # are some issues with the built-in search by spawn()
36 # on Windows if PATH contains spaces.
37 #dirs = ((ENV["CPP_PATH"] || "") + File::PATH_SEPARATOR + (ENV["PATH"] || "")).split(File::PATH_SEPARATOR)
38 dirs = ((ENV["CPP_PATH"] || "") + File::PATH_SEPARATOR + (ENV["PATH"] || "")).split(File::PATH_SEPARATOR)
39 bin = ENV["SETTINGS_CXX"]
44 bin = "arm-none-eabi-g++"
48 p = File.join(dir, bin)
49 ['', '.exe'].each do |suffix|
51 if File.executable?(f)
53 puts "Found #{bin} at #{f}"
60 raise "Could not find #{bin} in PATH, looked in #{dirs}"
61 @verbose = ENV["V"] == "1"
65 cflags = Shellwords.split(ENV["CFLAGS"] || "")
69 # Don't generate temporary files
70 if flag == "" || flag == "-MMD" || flag == "-MP" || flag.start_with?("-save-temps")
73 # -Wstrict-prototypes is not valid for C++
74 if flag == "-Wstrict-prototypes"
77 if flag.start_with? "-std="
80 if flag.start_with? "-D'"
81 # Cleanup flag. Done by the shell when called from
82 # it but we must do it ourselves becase we're not
83 # calling the compiler via shell.
84 flag = "-D" + flag[3..-2]
91 def run(input, output, args = nil, options = { noerror: false })
92 all_args = default_args
97 all_args << "-o" << output
100 stdout, stderr, compile_status = Open3.capture3(join_args(all_args))
101 raise "Compiler error:\n#{all_args.join(' ')}\n#{stderr}" if not options[:noerror] and not compile_status.success?
102 return stdout, stderr
108 if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
109 return args.join(' ')
111 return Shellwords.join(args)