aboutsummaryrefslogtreecommitdiff
path: root/rakelib/support/platform.rb
blob: a622c7f98a7f6fdc92359390eb1e79e22db21c6c (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
34
35
36
37
38
39
40
41
42
43
44
# 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'

# Platform and architecture helpers for build includes and targets.
module Platform
  def self.host_os
    case RUBY_PLATFORM
    when /darwin/ then 'darwin'
    when /linux/ then 'linux'
    end
  end

  def self.host_arch
    case RUBY_PLATFORM
    when /x86_64|x64/ then 'x64'
    when /arm64|aarch64/ then 'arm64'
    when /riscv64/ then 'riscv64'
    end
  end

  def self.directories(platform = host_os, arch = host_arch)
    [
      "arch/#{platform}/#{arch}",
      "arch/platform/#{platform}",
      'arch/platform/posix',
      "arch/#{arch}",
      'source'
    ].select { |dir| Dir.exist?(dir) }
  end

  def self.includes(platform = host_os, arch = host_arch)
    directories(platform, arch).flat_map { |dir| ['-I', dir] }
  end

  def self.sources(platform = host_os, arch = host_arch)
    FileList[*directories(platform, arch).map { |dir| "#{dir}/**/*.elna" }].select do |file|
      file == file.downcase
    end
  end
end