2017-12-23 05:29:39 +00:00
|
|
|
const builtin = @import("builtin");
|
2017-12-12 04:34:59 +00:00
|
|
|
const c = @import("c.zig");
|
|
|
|
|
2017-12-23 05:29:39 +00:00
|
|
|
pub const CrossTarget = struct {
|
|
|
|
arch: builtin.Arch,
|
|
|
|
os: builtin.Os,
|
|
|
|
environ: builtin.Environ,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const Target = union(enum) {
|
|
|
|
Native,
|
|
|
|
Cross: CrossTarget,
|
|
|
|
|
2018-01-25 09:10:11 +00:00
|
|
|
pub fn oFileExt(self: &const Target) []const u8 {
|
2017-12-23 05:29:39 +00:00
|
|
|
const environ = switch (*self) {
|
|
|
|
Target.Native => builtin.environ,
|
|
|
|
Target.Cross => |t| t.environ,
|
|
|
|
};
|
|
|
|
return switch (environ) {
|
|
|
|
builtin.Environ.msvc => ".obj",
|
|
|
|
else => ".o",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-01-25 09:10:11 +00:00
|
|
|
pub fn exeFileExt(self: &const Target) []const u8 {
|
2017-12-23 05:29:39 +00:00
|
|
|
return switch (self.getOs()) {
|
|
|
|
builtin.Os.windows => ".exe",
|
|
|
|
else => "",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-01-25 09:10:11 +00:00
|
|
|
pub fn getOs(self: &const Target) builtin.Os {
|
2017-12-23 05:29:39 +00:00
|
|
|
return switch (*self) {
|
|
|
|
Target.Native => builtin.os,
|
|
|
|
Target.Cross => |t| t.os,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-01-25 09:10:11 +00:00
|
|
|
pub fn isDarwin(self: &const Target) bool {
|
2017-12-23 05:29:39 +00:00
|
|
|
return switch (self.getOs()) {
|
2018-01-07 04:10:53 +00:00
|
|
|
builtin.Os.ios, builtin.Os.macosx => true,
|
2017-12-23 05:29:39 +00:00
|
|
|
else => false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-01-25 09:10:11 +00:00
|
|
|
pub fn isWindows(self: &const Target) bool {
|
2017-12-23 05:29:39 +00:00
|
|
|
return switch (self.getOs()) {
|
|
|
|
builtin.Os.windows => true,
|
|
|
|
else => false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-01-25 09:10:11 +00:00
|
|
|
pub fn initializeAll() void {
|
2017-12-12 04:34:59 +00:00
|
|
|
c.LLVMInitializeAllTargets();
|
|
|
|
c.LLVMInitializeAllTargetInfos();
|
|
|
|
c.LLVMInitializeAllTargetMCs();
|
|
|
|
c.LLVMInitializeAllAsmPrinters();
|
|
|
|
c.LLVMInitializeAllAsmParsers();
|
|
|
|
}
|