-
Notifications
You must be signed in to change notification settings - Fork 0
/
flags.cr
39 lines (33 loc) · 1.19 KB
/
flags.cr
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
class Crystal::Program
@flags : Set(String)?
# Returns the flags for this program. By default these
# are computed from the target triple (for example x86_64,
# darwin, linux, etc.), but can be overwritten with `flags=`
# and also added with the `-D` command line argument.
#
# See `Compiler#flags`.
def flags
@flags ||= parse_flags(target_machine.triple.split('-'))
end
# Overrides the default flags with the given ones.
def flags=(flags : String)
@flags = parse_flags(flags.split)
end
# Returns `true` if *name* is in the program's flags.
def has_flag?(name : String)
flags.includes?(name)
end
private def parse_flags(flags_name)
set = flags_name.map(&.downcase).to_set
set.add "darwin" if set.any?(&.starts_with?("macosx")) || set.any?(&.starts_with?("darwin"))
set.add "freebsd" if set.any?(&.starts_with?("freebsd"))
set.add "openbsd" if set.any?(&.starts_with?("openbsd"))
set.add "x86_64" if set.any?(&.starts_with?("amd64"))
set.add "i686" if set.any? { |flag| %w(i586 i486 i386).includes?(flag) }
if set.any?(&.starts_with?("arm"))
set.add "arm"
set.add "armhf" if set.includes?("gnueabihf")
end
set
end
end