@ -32,6 +32,8 @@ ANDROID_64BIT_API_MIN = 21 # minimal API level that supports 64-bit targets
@@ -32,6 +32,8 @@ ANDROID_64BIT_API_MIN = 21 # minimal API level that supports 64-bit targets
NSWITCH_ENVVARS = [ ' DEVKITPRO ' ]
PSVITA_ENVVARS = [ ' VITASDK ' ]
# This class does support ONLY r10e and r19c/r20 NDK
class Android :
ctx = None # waf context
@ -399,7 +401,7 @@ class NintendoSwitch:
@@ -399,7 +401,7 @@ class NintendoSwitch:
return self . gen_gcc_toolchain_path ( ) + ' strip '
def pkgconfig ( self ) :
# counter-intuitively, this motherfucker is in portlibs/switch/bin
# counter-intuitively, this motherfucker is in $DEVKITPRO/ portlibs/switch/bin
return os . path . join ( self . portlibs_dir , ' bin ' , self . gen_toolchain_prefix ( ) + ' pkg-config ' )
def cflags ( self , cxx = False ) :
@ -410,10 +412,8 @@ class NintendoSwitch:
@@ -410,10 +412,8 @@ class NintendoSwitch:
cflags + = [ ' -ffunction-sections ' , ' -fdata-sections ' ]
# base include dirs
cflags + = [ ' -isystem %s /include ' % self . libnx_dir , ' -I %s /include ' % self . portlibs_dir ]
# the game wants GNU extensions
if cxx :
# while these are supported, they could fuck up the crappy dynamic linker
cflags + = [ ' -fno-exceptions ' , ' -fno-rtti ' ]
# the game wants GNU extensions
cflags + = [ ' -std=gnu++17 ' , ' -D_GNU_SOURCE ' ]
else :
cflags + = [ ' -std=gnu11 ' , ' -D_GNU_SOURCE ' ]
@ -434,6 +434,70 @@ class NintendoSwitch:
@@ -434,6 +434,70 @@ class NintendoSwitch:
ldflags = [ ] # ['-lm', '-lstdc++']
return ldflags
class PSVita :
ctx = None # waf context
arch = ' armeabi-v7a-hard '
vitasdk_dir = None
def __init__ ( self , ctx ) :
self . ctx = ctx
for i in PSVITA_ENVVARS :
self . vitasdk_dir = os . getenv ( i )
if self . vitasdk_dir != None :
break
else :
ctx . fatal ( ' Set %s environment variable pointing to the VitaSDK directory! ' %
' or ' . join ( PSVITA_ENVVARS ) )
def gen_toolchain_prefix ( self ) :
return ' arm-vita-eabi- '
def gen_gcc_toolchain_path ( self ) :
return os . path . join ( self . vitasdk_dir , ' bin ' , self . gen_toolchain_prefix ( ) )
def cc ( self ) :
return self . gen_gcc_toolchain_path ( ) + ' gcc '
def cxx ( self ) :
return self . gen_gcc_toolchain_path ( ) + ' g++ '
def strip ( self ) :
return self . gen_gcc_toolchain_path ( ) + ' strip '
def ar ( self ) :
return self . gen_gcc_toolchain_path ( ) + ' ar '
def pkgconfig ( self ) :
return self . gen_gcc_toolchain_path ( ) + ' pkg-config '
def cflags ( self , cxx = False ) :
cflags = [ ]
# arch flags
cflags + = [ ' -D__vita__ ' , ' -mtune=cortex-a9 ' , ' -mfpu=neon ' ]
# necessary linker flags
cflags + = [ ' -Wl,-q ' , ' -Wl,-z,nocopyreloc ' ]
# this optimization is broken in vitasdk
cflags + = [ ' -fno-optimize-sibling-calls ' ]
# disable some ARM bullshit
cflags + = [ ' -fno-short-enums ' , ' -Wno-attributes ' ]
# base include dir
cflags + = [ ' -isystem %s /arm-vita-eabi/include ' % self . vitasdk_dir ]
# SDL include dir
cflags + = [ ' -I %s /arm-vita-eabi/include/SDL2 ' % self . vitasdk_dir ]
return cflags
# they go before object list
def linkflags ( self ) :
linkflags = [ ' -Wl,--hash-style=sysv ' , ' -Wl,-q ' , ' -Wl,-z,nocopyreloc ' , ' -mtune=cortex-a9 ' , ' -mfpu=neon ' ]
# enforce no-short-enums again
linkflags + = [ ' -Wl,-no-enum-size-warning ' , ' -fno-short-enums ' ]
return linkflags
def ldflags ( self ) :
ldflags = [ ]
return ldflags
def options ( opt ) :
xc = opt . add_option_group ( ' Cross compile options ' )
xc . add_option ( ' --android ' , action = ' store ' , dest = ' ANDROID_OPTS ' , default = None ,
@ -444,6 +508,8 @@ def options(opt):
@@ -444,6 +508,8 @@ def options(opt):
help = ' enable building with MSVC using Wine [default: %d efault] ' )
xc . add_option ( ' --nswitch ' , action = ' store_true ' , dest = ' NSWITCH ' , default = False ,
help = ' enable building for Nintendo Switch [default: %d efault] ' )
xc . add_option ( ' --psvita ' , action = ' store_true ' , dest = ' PSVITA ' , default = False ,
help = ' enable building for PlayStation Vita [default: %d efault] ' )
def configure ( conf ) :
if conf . options . ANDROID_OPTS :
@ -509,10 +575,25 @@ def configure(conf):
@@ -509,10 +575,25 @@ def configure(conf):
conf . env . HAVE_M = True
conf . env . LIB_M = [ ' m ' ]
conf . env . DEST_OS = ' nswitch '
elif conf . options . PSVITA :
conf . psvita = psvita = PSVita ( conf )
conf . environ [ ' CC ' ] = psvita . cc ( )
conf . environ [ ' CXX ' ] = psvita . cxx ( )
conf . environ [ ' STRIP ' ] = psvita . strip ( )
conf . environ [ ' AR ' ] = psvita . ar ( )
conf . env . PKGCONFIG = psvita . pkgconfig ( )
conf . env . CFLAGS + = psvita . cflags ( )
conf . env . CXXFLAGS + = psvita . cflags ( True )
conf . env . LINKFLAGS + = psvita . linkflags ( )
conf . env . LDFLAGS + = psvita . ldflags ( )
conf . env . HAVE_M = True
conf . env . LIB_M = [ ' m ' ]
conf . env . VRTLD = [ ' vrtld ' ]
conf . env . DEST_OS = ' psvita '
conf . env . MAGX = conf . options . MAGX
conf . env . MSVC_WINE = conf . options . MSVC_WINE
MACRO_TO_DESTOS = OrderedDict ( { ' __ANDROID__ ' : ' android ' , ' __SWITCH__ ' : ' nswitch ' } )
MACRO_TO_DESTOS = OrderedDict ( { ' __ANDROID__ ' : ' android ' , ' __SWITCH__ ' : ' nswitch ' , ' __vita__ ' : ' psvita ' } )
for k in c_config . MACRO_TO_DESTOS :
MACRO_TO_DESTOS [ k ] = c_config . MACRO_TO_DESTOS [ k ] # ordering is important
c_config . MACRO_TO_DESTOS = MACRO_TO_DESTOS