aboutsummaryrefslogtreecommitdiff
path: root/rakelib/compiler.rake
blob: 5cd19d5437c1345a9d187c3af26e41c4a93599b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at https://mozilla.org/MPL/2.0/. -}
# frozen_string_literal: true

require 'rake/loaders/makefile'
require 'rake/clean'

CLEAN.include 'build/gcc'

Rake.application.add_loader('d', Rake::MakefileLoader.new)
FileList['build/gcc/obj/**/*.d'].each { |file| import file }

rule(%r{gcc/obj/.+\.o$} => lambda { |file|
  source = Pathname.new('source') +
    Pathname.new(file).relative_path_from('build/gcc/obj').sub_ext('.elna')

  [source, 'build/host/install/bin/gelna']
}) do |t|
  Pathname.new(t.name).dirname.mkpath

  sh t.prerequisites.last, '-c', '-MD', '-MP', '-O0', '-g', '-I', 'source', '-o', t.name, t.source.to_s
end

sources = FileList['source/**/*.elna'].select { |file| file == file.downcase }
file 'build/gcc/bin/elna' => sources.map { |file|
  Pathname.new('build/gcc/obj') +
    Pathname.new(file).relative_path_from('source').sub_ext('.o')
} do |t|
  Pathname.new(t.name).dirname.mkpath

  sh 'build/host/install/bin/gcc', '-o', t.name, *t.prerequisites
end