Skip to content

Commit 92b2ea5

Browse files
committed
WII: add basic support
1 parent a199a5e commit 92b2ea5

File tree

4 files changed

+314
-2
lines changed

4 files changed

+314
-2
lines changed

platforms/build-wii.sh

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
export DEVKITPRO="/opt/devkitpro"
6+
export ARCH_DEVKIT_FOLDER="$DEVKITPRO/devkitPPC"
7+
export COMPILER_BIN="$ARCH_DEVKIT_FOLDER/bin"
8+
export PATH="$DEVKITPRO/tools/bin:$COMPILER_BIN:$PATH"
9+
10+
export OGC_CONSOLE="wii"
11+
export OGC_SUBDIR="wii"
12+
export OGC_MACHINE="rvl"
13+
14+
export PORTLIBS_PATH="$DEVKITPRO/portlibs"
15+
export LIBOGC="$DEVKITPRO/libogc"
16+
17+
export PORTLIBS_PATH_OGC="$PORTLIBS_PATH/$OGC_CONSOLE"
18+
export PORTLIBS_PATH_PPC="$PORTLIBS_PATH/ppc"
19+
20+
export PORTLIBS_LIB_OGC="$PORTLIBS_PATH_OGC/lib"
21+
export PORTLIBS_LIB_PPC="$PORTLIBS_PATH_PPC/lib"
22+
export LIBOGC_LIB="$LIBOGC/lib/$OGC_SUBDIR"
23+
24+
export PKG_CONFIG_PATH_OGC="$PORTLIBS_LIB_OGC/pkgconfig/"
25+
export PKG_CONFIG_PATH_PPC="$PORTLIBS_LIB_PPC/pkgconfig/"
26+
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH_OGC:$PKG_CONFIG_PATH_PPC"
27+
28+
export ROMFS="romfs"
29+
30+
export BUILD_DIR="build-wii"
31+
32+
export ROMFS="platforms/romfs"
33+
34+
export TOOL_PREFIX="powerpc-eabi"
35+
36+
export BIN_DIR_OGC="$PORTLIBS_PATH_OGC/bin"
37+
export BIN_DIR_PPC="$PORTLIBS_LIB_PPC/bin"
38+
export PKG_CONFIG_EXEC="$BIN_DIR_OGC/$TOOL_PREFIX-pkg-config"
39+
export CMAKE="$BIN_DIR_OGC/$TOOL_PREFIX-cmake"
40+
41+
export PATH="$BIN_DIR_PPC:$BIN_DIR_OGC:$PATH"
42+
43+
export CC="$COMPILER_BIN/$TOOL_PREFIX-gcc"
44+
export CXX="$COMPILER_BIN/$TOOL_PREFIX-g++"
45+
export AS="$COMPILER_BIN/$TOOL_PREFIX-as"
46+
export AR="$COMPILER_BIN/$TOOL_PREFIX-gcc-ar"
47+
export RANLIB="$COMPILER_BIN/$TOOL_PREFIX-gcc-ranlib"
48+
export NM="$COMPILER_BIN/$TOOL_PREFIX-gcc-nm"
49+
export OBJCOPY="$COMPILER_BIN/$TOOL_PREFIX-objcopy"
50+
export STRIP="$COMPILER_BIN/$TOOL_PREFIX-strip"
51+
52+
export ARCH="ppc"
53+
export CPU_VERSION="ppc750"
54+
export ENDIANESS="big"
55+
56+
export COMMON_FLAGS="'-m${OGC_MACHINE}','-mcpu=750','-meabi','-mhard-float','-ffunction-sections','-fdata-sections'"
57+
58+
export COMPILE_FLAGS="'-D__WII__','-D__CONSOLE__','-D__NINTENDO_CONSOLE__','-D_OGC_','-DGEKKO','-isystem', '$LIBOGC/include', '-I$PORTLIBS_PATH_PPC/include', '-I$PORTLIBS_PATH_OGC/include'"
59+
60+
export LINK_FLAGS="'-L$LIBOGC/lib','-L$PORTLIBS_LIB_PPC','-L$PORTLIBS_LIB_OGC'"
61+
62+
export CROSS_FILE="./platforms/crossbuild-wii.ini"
63+
64+
cat <<EOF >"$CROSS_FILE"
65+
[host_machine]
66+
system = 'wii'
67+
cpu_family = '$ARCH'
68+
cpu = '$CPU_VERSION'
69+
endian = '$ENDIANESS'
70+
71+
[target_machine]
72+
system = 'wii'
73+
cpu_family = '$ARCH'
74+
cpu = '$CPU_VERSION'
75+
endian = '$ENDIANESS'
76+
77+
[constants]
78+
devkitpro = '$DEVKITPRO'
79+
80+
[binaries]
81+
c = '$CC'
82+
cpp = '$CXX'
83+
c_ld = 'bfd'
84+
cpp_ld = 'bfd'
85+
ar = '$AR'
86+
as = '$AS'
87+
ranlib = '$RANLIB'
88+
strip = '$STRIP'
89+
objcopy = '$OBJCOPY'
90+
nm = '$NM'
91+
pkg-config = '$PKG_CONFIG_EXEC'
92+
cmake='$CMAKE'
93+
freetype-config='$BIN_DIR_PPC/freetype-config'
94+
libpng16-config='$BIN_DIR_PPC/libpng16-config'
95+
libpng-config='$BIN_DIR_PPC/libpng-config'
96+
sdl2-config='$BIN_DIR_OGC/sdl2-config'
97+
98+
[built-in options]
99+
c_std = 'c11'
100+
cpp_std = 'c++23'
101+
c_args = [$COMMON_FLAGS, $COMPILE_FLAGS]
102+
cpp_args = [$COMMON_FLAGS, $COMPILE_FLAGS]
103+
c_link_args = [$COMMON_FLAGS, $LINK_FLAGS]
104+
cpp_link_args = [$COMMON_FLAGS, $LINK_FLAGS]
105+
106+
107+
[properties]
108+
pkg_config_libdir = '$PKG_CONFIG_PATH'
109+
needs_exe_wrapper = true
110+
library_dirs= ['$LIBOGC_LIB', '$PORTLIBS_LIB_OGC','$PORTLIBS_LIB_PPC']
111+
112+
USE_META_XML = true
113+
114+
115+
APP_ROMFS='$ROMFS'
116+
117+
EOF
118+
119+
## options: "smart, complete_rebuild"
120+
export COMPILE_TYPE="smart"
121+
122+
export BUILDTYPE="debug"
123+
124+
if [ "$#" -eq 0 ]; then
125+
# nothing
126+
echo "Using compile type '$COMPILE_TYPE'"
127+
elif [ "$#" -eq 1 ]; then
128+
COMPILE_TYPE="$1"
129+
elif [ "$#" -eq 2 ]; then
130+
COMPILE_TYPE="$1"
131+
BUILDTYPE="$2"
132+
else
133+
echo "Too many arguments given, expected 1 or 2"
134+
exit 1
135+
fi
136+
137+
if [ "$COMPILE_TYPE" == "smart" ]; then
138+
: # noop
139+
elif [ "$COMPILE_TYPE" == "complete_rebuild" ]; then
140+
: # noop
141+
else
142+
echo "Invalid COMPILE_TYPE, expected: 'smart' or 'complete_rebuild'"
143+
exit 1
144+
fi
145+
146+
if [ ! -d "$ROMFS" ]; then
147+
148+
mkdir -p "$ROMFS"
149+
150+
cp -r assets "$ROMFS/"
151+
152+
fi
153+
154+
if [ "$COMPILE_TYPE" == "complete_rebuild" ] || [ ! -e "$BUILD_DIR" ]; then
155+
156+
meson setup "$BUILD_DIR" \
157+
"--wipe" \
158+
--cross-file "$CROSS_FILE" \
159+
"-Dbuildtype=$BUILDTYPE" \
160+
-Ddefault_library=static
161+
162+
fi
163+
164+
meson compile -C "$BUILD_DIR"

platforms/wii/meson.build

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
## get the options object and "unpack" it
2+
3+
wii_exe_name = wii_options[0]
4+
wii_src_files = wii_options[1]
5+
wii_deps = wii_options[2]
6+
7+
8+
# libraries
9+
10+
wii_dependencies = [
11+
'freetype2',
12+
'harfbuzz',
13+
'ogg',
14+
'vorbis',
15+
'vorbisfile',
16+
'vorbisidec',
17+
'zlib',
18+
]
19+
20+
wii_dependencies_native = [
21+
'bte',
22+
'bz2',
23+
'fat',
24+
'jpeg',
25+
'm',
26+
'modplug',
27+
'ogc',
28+
'png16',
29+
'SDL2main',
30+
'wiikeyboard',
31+
'wiiuse',
32+
]
33+
34+
foreach dep : wii_dependencies
35+
wii_deps += dependency(
36+
dep,
37+
required: true,
38+
allow_fallback: false,
39+
native: false,
40+
)
41+
endforeach
42+
43+
wii_library_dirs = meson.get_external_property('library_dirs', [''])
44+
if wii_library_dirs.length() == 0
45+
error('property \'library_dirs\' has to be set!')
46+
endif
47+
48+
c = meson.get_compiler('c')
49+
foreach dep : wii_dependencies_native
50+
wii_deps += c.find_library(
51+
dep,
52+
required: true,
53+
dirs: wii_library_dirs,
54+
)
55+
endforeach
56+
57+
## ROMFS handling, this is special in the case of the wii
58+
59+
APP_ROMFS = meson.get_external_property('APP_ROMFS', '')
60+
61+
if APP_ROMFS != ''
62+
fs = import('fs')
63+
64+
if not fs.is_absolute(APP_ROMFS)
65+
APP_ROMFS = meson.project_source_root() / APP_ROMFS
66+
endif
67+
68+
if not fs.exists(APP_ROMFS)
69+
error('APP_ROMFS should exist, but doesn\'t: \'' + APP_ROMFS + '\'')
70+
endif
71+
72+
wii_deps = dependency(
73+
'libromfs',
74+
required: true,
75+
allow_fallback: true,
76+
native: false,
77+
default_options: {'romfs_dir': APP_ROMFS},
78+
)
79+
80+
81+
endif
82+
83+
84+
85+
## compilation
86+
87+
wii_elf_file = build_target(
88+
wii_exe_name + '.elf',
89+
wii_src_files,
90+
dependencies: wii_deps,
91+
override_options: {
92+
'warning_level': '3',
93+
'werror': true,
94+
},
95+
native: false,
96+
target_type: 'executable',
97+
)
98+
99+
DOL_DEPS = [wii_elf_file]
100+
101+
102+
elf2dol = find_program('elf2dol')
103+
104+
# elf2dol <exe_name>.elf <exe_name>.dol
105+
custom_target(
106+
wii_exe_name + '.dol',
107+
command: [elf2dol, wii_elf_file.full_path(), wii_exe_name + '.dol'],
108+
depends: DOL_DEPS,
109+
output: [wii_exe_name + '.dol'],
110+
build_by_default: true,
111+
)
112+
113+
use_meta_xml = ['true', 'True', '1', true].contains(
114+
meson.get_external_property('USE_META_XML', ''),
115+
)
116+
117+
if use_meta_xml
118+
119+
wii_meta_xml_conf = configuration_data(
120+
{
121+
'OOPETRIS_VERSION': meson.project_version(),
122+
'OOPETRIS_NAME': oopetris_name,
123+
'OOPETRIS_AUTHOR': oopetris_author,
124+
'OOPETRIS_SHORT_DESCRIPTION': oopetris_desc,
125+
'OOPETRIS_LONG_DESCRIPTION': oopetris_desc,
126+
},
127+
)
128+
129+
wii_meta_xml = configure_file(
130+
input: 'meta.xml.in',
131+
output: 'meta.xml',
132+
configuration: wii_meta_xml_conf,
133+
install: true,
134+
)
135+
136+
endif

platforms/wii/meta.xml.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<app version="1">
3+
<name>@OOPETRIS_NAME@</name>
4+
<coder>@OOPETRIS_AUTHOR@</coder>
5+
<version>@OOPETRIS_VERSION@</version>
6+
<short_description>@OOPETRIS_SHORT_DESCRIPTION@</short_description>
7+
<long_description>@OOPETRIS_LONG_DESCRIPTION@</long_description>
8+
<no_ios_reload/>
9+
</app>

tools/dependencies/meson.build

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,11 @@ online_multiplayer_supported = true
222222

223223
if (
224224
meson.is_cross_build()
225-
and (host_machine.system() == 'switch'
226-
or host_machine.system() == '3ds')
225+
and (
226+
host_machine.system() == 'switch'
227+
or host_machine.system() == '3ds'
228+
or host_machine.system() == 'wii'
229+
)
227230
)
228231
online_multiplayer_supported = false
229232

0 commit comments

Comments
 (0)