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/.
30 require_relative 'compiler'
33 def initialize(settings_file, stamp_file)
34 @settings_file = settings_file
35 @stamp_file = stamp_file
36 @stamp_dir = File.dirname(@stamp_file)
37 @compiler = Compiler.new
42 buf << "CFLAGS = " << ENV["CFLAGS"] << "\n"
43 buf << "TARGET = " << ENV["TARGET"] << "\n"
44 buf << "CONFIG = " << hash_config() << "\n"
49 if File.file?(@stamp_file)
50 old_stamp = File.open(@stamp_file, 'rb') { |f| f.read }
53 File.open(@stamp_file, 'w') {|f| f.write(stamp)}
59 ["target.h", "platform.h", "cstddef"].each do |h|
60 buf << "#include \"#{h}\"\n"
62 FileUtils.mkdir_p @stamp_dir
63 input = File.join(@stamp_dir, "stamp.cpp")
64 File.open(input, 'w') {|file| file.write(buf.string)}
65 output = File.join(@stamp_dir, "stamp")
66 stdout, stderr = @compiler.run(input, output, ["-dM", "-E"])
71 return Digest::SHA1.hexdigest(stdout)
76 puts "Usage: ruby #{__FILE__} <settings_file> <stamp_file>"
81 settings_file = ARGV[0]
83 if settings_file.nil? || stamp_file.nil?
88 stamper = Stamper.new(settings_file, stamp_file)