-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3dskit.lua
147 lines (105 loc) · 4.43 KB
/
3dskit.lua
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
-- ys-3dskit toolchain definition 2025-01-07-2
local DEVKITPRO = os.getenv("DEVKITPRO")
if not DEVKITPRO then
DEVKITPRO = "/opt/devkitpro"
return
end
local DKP_TOOLS = path.join(DEVKITPRO, "/tools/bin")
toolchain("devkitarm")
set_kind("standalone")
set_toolset("cc", DEVKITPRO .. "/devkitARM/bin/" .. "arm-none-eabi-gcc")
set_toolset("cxx", DEVKITPRO .. "/devkitARM/bin/" .. "arm-none-eabi-g++")
set_toolset("ld", DEVKITPRO .. "/devkitARM/bin/" .. "arm-none-eabi-g++")
set_toolset("sh", DEVKITPRO .. "/devkitARM/bin/" .. "arm-none-eabi-g++")
set_toolset("ar", DEVKITPRO .. "/devkitARM/bin/" .. "arm-none-eabi-ar")
set_toolset("strip", DEVKITPRO .. "/devkitARM/bin/" .. "arm-none-eabi-strip")
set_toolset("objcopy", DEVKITPRO .. "/devkitARM/bin/" .. "arm-none-eabi-objcopy")
set_toolset("ranlib", DEVKITPRO .. "/devkitARM/bin/" .. "arm-none-eabi-ranlib")
set_toolset("as", DEVKITPRO .. "/devkitARM/bin/" .. "arm-none-eabi-gcc")
set_toolset("dc", "ldc2")
set_toolset("dcld", DEVKITPRO .. "/devkitARM/bin/" .. "arm-none-eabi-g++")
add_defines("__3DS__", "HAVE_LIBCTRU")
local arch = { "-march=armv6k", "-mtune=mpcore", "-mtp=soft", "-mfloat-abi=hard" }
local c_flags = table.join(arch, { "-g", "-Wall", "-mword-relocations", "-ffunction-sections"})
add_cxflags(c_flags)
add_asflags(c_flags)
add_cxxflags({ "-frtti", "-std=gnu++11", "-fexceptions" })
add_dcflags("-d-version=Horizon,N3DS", "-mtriple=arm-freestanding-eabihf", "-float-abi=hard", "-mcpu=mpcore", "-mattr=armv6k", "--conf=")
-- for some reason (xmake bug?) this does not work here
-- so we do it in rule("3ds") instead.
--add_ldflags("-specs=3dsx.specs", "-g", arch, {force = true})
--on_check("check")
-- handled by xmake package manager, not needed.
--add_linkdirs(path.join(DEVKITPRO, "/libctru/lib") --[[, path.join(DEVKITPRO, "/portlibs/3ds/lib")]])
--add_includedirs(path.join(DEVKITPRO, "/libctru/include") --[[, path.join(DEVKITPRO, "/portlibs/3ds/include")]])
add_links("m")
rule("3ds")
on_load(function(target)
if not target:is_plat("3ds") then
raise("Please make sure you have run `xmake f -y -p 3ds -m release -a arm --toolchain=devkitarm` to configure the project before building.")
end
if not target:kind() == "binary" then
raise('rule("3ds") only works with binary targets')
end
-- sadly does not apply to dependencies without running the appropriate `xmake f` first.
target:set("toolchains", "devkitarm")
target:add("ldflags", "-specs=3dsx.specs", "-g", "-march=armv6k", "-mtune=mpcore", "-mtp=soft", "-mfloat-abi=hard", {force = true})
end)
after_build(function(target)
local _3dsxtool = path.join(DKP_TOOLS, "3dsxtool")
local smdhtool = path.join(DKP_TOOLS, "smdhtool")
local name = target:values("3ds.name")
name = name or io.popen("pwd"):read() --"a"
local author = target:values("3ds.author")
author = author or "Unspecified Author"
local description = target:values("3ds.description")
description = description or "Built with devkitARM & libctru"
local icon = target:values("3ds.icon")
icon = icon or path.join(DEVKITPRO, "/libctru/default_icon.png")
local romfsdir = target:values("3ds.romfs")
cprint("${color.build.target}Generating smdh metadata")
local smdhfile = path.absolute(path.join(target:targetdir(), name .. ".smdh"))
local smdh_args = { "--create", name, description, author, icon, smdhfile }
vprint(smdhtool, table.unpack(smdh_args))
local outdata, errdata = os.iorunv(smdhtool, smdh_args)
vprint(outdata)
assert(errdata, errdata)
local target_file = target:targetfile()
local file_3dsx = target_file .. ".3dsx"
cprint("${color.build.target}Generating 3dsx file")
local _3dsxtool_args = { target_file, file_3dsx, "--smdh=".. smdhfile }
if romfsdir ~= nil and romfsdir ~= "" then
table.insert(_3dsxtool_args, "--romfs=" .. romfsdir)
end
vprint(_3dsxtool, table.unpack(_3dsxtool_args))
outdata, errdata = os.iorunv(_3dsxtool, _3dsxtool_args)
vprint(outdata)
assert(errdata, errdata)
end)
on_run(function(target)
if not target:kind() == "binary" then
return
end
import("core.base.option")
import("core.project.config")
local emu
try
{
function ()
os.iorun("citra --version")
emu = "citra"
end,
catch
{
function()
cprint("${color.build.target}Please install Citra first")
end
}
}
if not emu then
return
end
local target_file = target:targetfile()
local executable = target_file .. ".3dsx"
os.runv(emu, {executable})
end)