2018-09-06 20:58:30 +10:00
# wut makefile beta - let's just stick with cmake, yeah?
# should work for out-of-tree builds
# Scroll to the bottom for predefined/utility variables
# If V isn't given as 1 on the commandline, prepend "@" onto all our commands
# See uses of $(Q) later - this stops make echoing our commands
i f n e q ( $( strip $ ( V ) ) , 1 )
Q ?= @
e n d i f
2019-04-23 21:22:19 +10:00
# ------------------------------------------------------------------------------
# wut 1.0.0-beta9 and later ships wut_rules, in line with normal devkitPro
# makefiles - please use that!
$(warning "Using wut.mk is deprecated, and will be removed in a future release! Please switch to wut_rules as soon as possible - see https : //github .com /devkitPro /wut /blob /master /samples /make /helloworld /Makefile for an example .")
2018-09-06 20:58:30 +10:00
# ------------------------------------------------------------------------------
# Toolchain includes and path setup
# Make sure we have devkitPPC
i f e q ( $( strip $ ( DEVKITPRO ) ) , )
$( error "Please set DEVKITPRO in your environment." )
e n d i f
# May as well have a guess. ?= means an existing DEVKITPPC value isn't touched.
export DEVKITPPC ?= $( DEVKITPRO) /devkitPPC
# Pull in devkitPPC bits - this gets $(CC) and friends set up
i n c l u d e $( DEVKITPPC ) / b a s e _ t o o l s
2019-04-09 18:29:44 +10:00
# Have a guess at WUT_ROOT
export WUT_ROOT ?= $( DEVKITPRO) /wut
2018-09-06 20:58:30 +10:00
# Grab wut tools we need.
2019-02-19 22:23:33 +01:00
WUT_ELF2RPL := $( DEVKITPRO) /tools/bin/elf2rpl
WUT_RPLEXPORTGEN := $( DEVKITPRO) /tools/bin/rplexportgen
2018-09-06 20:58:30 +10:00
# If DEPSDIR isn't defined, assume this is an out-of-tree build and that we're
# already running in the build folder - thus, put deps in CURDIR
DEPSDIR ?= $( CURDIR)
# Default to .d for depends
DEPSEXT ?= d
# ------------------------------------------------------------------------------
# Get our flags in order
# There's some default wut flags, they need to be added
# cpu type and hardware flags, keep all relocations (for elf2rpl), wut includes
2018-09-06 21:27:01 +10:00
WUT_CFLAGS := -mcpu= 750 -meabi -mhard-float -isystem $( WUT_ROOT) /include
2018-09-06 20:58:30 +10:00
# Defines to tell code about this environment
WUT_CFLAGS += -D__WIIU__ -D__WUT__ -D__WUT_MAKEFILE__
# keep relocations, use wut linker script
2019-04-23 21:22:19 +10:00
WUT_LDFLAGS := -specs= $( WUT_ROOT) /share/wut.specs
2018-09-06 20:58:30 +10:00
# Path for wut libraries, Always link against coreinit
2019-04-23 21:22:19 +10:00
WUT_LDFLAGS += -L$( WUT_ROOT) /lib -L$( WUT_ROOT) /lib/stubs -lwut
2018-09-06 20:58:30 +10:00
# Append that to user-provided cflags and others
CFLAGS += $( WUT_CFLAGS)
CXXFLAGS += $( WUT_CFLAGS)
OBJCFLAGS += $( WUT_CFLAGS)
# assembler-with-cpp allows using #defines and stuff in Assembly source
# It's forced on devkitPPC, so it's forced here
ASFLAGS += $( WUT_CFLAGS) -x assembler-with-cpp
LDFLAGS += $( WUT_LDFLAGS)
# Linking sucks... this make the ordering of libraries irrelevant, but the
# manuals reckon it's not good for performance. Set WUT_NO_LDGROUPS=1 to disable
# or DIY this bit (_PRE and _POST are included no matter what)
i f n e q ( $( strip $ ( WUT_NO_LDGROUPS ) ) , 1 )
LDFLAGS_PRE += -Wl,--start-group
LDFLAGS_POST += -Wl,--end-group
e n d i f
# RPX and RPL need slightly different crts (init code)
2019-05-03 18:02:15 +10:00
#%.rpx: LDFLAGS += -specs=$(WUT_ROOT)/share/rpx.specs
2019-04-23 21:22:19 +10:00
%.rpl : LDFLAGS += -specs =$( WUT_ROOT ) /share /rpl .specs
2018-09-06 20:58:30 +10:00
# ------------------------------------------------------------------------------
# Linking bits
# What should we call files that have been linked but not run through elf2rpl?
WUT_RPLELF_SUFFIX := .elf
# If we're making an rpl, pass --rpl into elf2rpl
%.rpl : WUT_ELF 2RPLFLAGS += --rpl
# Main RPX/RPL linking rule. This process is basically identical for both types,
# aside from a few flags (which we've already set)
%.rpx %.rpl :
# Use CXX to link our initial output file, ready for elf2rpl
@echo LD $( notdir $@ ) $( WUT_RPLELF_SUFFIX)
$( Q) $( CXX) $^ $( LDFLAGS_PRE) $( LDFLAGS) $( LDFLAGS_POST) -o $@ $( WUT_RPLELF_SUFFIX)
2018-11-07 10:42:49 +11:00
$( Q) if [ " $( WUT_NO_STRIP) " = "" ] ; then \
echo STRIP $( notdir $@ ) $( WUT_RPLELF_SUFFIX) ; \
$( PREFIX) strip -g $@ $( WUT_RPLELF_SUFFIX) ; \
fi
2018-09-06 20:58:30 +10:00
# Run elf2rpl on it
@echo ELF2RPL $( notdir $@ )
$( Q) $( WUT_ELF2RPL) $( WUT_ELF2RPLFLAGS) $@ $( WUT_RPLELF_SUFFIX) $@
# Unless we're told not to, delete the initial output file
2018-09-18 08:07:38 +10:00
$( Q) if [ " $( WUT_KEEP_RPLELF) " = "" ] ; then \
2018-09-06 20:58:30 +10:00
rm -f $@ $( WUT_RPLELF_SUFFIX) ; \
fi
# ------------------------------------------------------------------------------
# Compilation rules
# Bog-standard compilation rules. Only using these and not devkitPPC's
# base_rules because the mkdir bits are needed
2018-09-09 19:29:03 +10:00
# Allow turning off the compilation rules
i f n e q ( $( strip $ ( WUT_NO_COMPRULES ) ) , 1 )
2018-09-06 20:58:30 +10:00
%.o : %.cpp
@echo CXX $( notdir $<)
@mkdir -p $( dir $* )
$( Q) $( CXX) -MMD -MP -MF $( DEPSDIR) /$* .$( DEPSEXT) $( CXXFLAGS) -c $< -o $@ $( ERROR_FILTER)
%.o : %.c
@echo CC $( notdir $<)
@mkdir -p $( dir $* )
$( Q) $( CC) -MMD -MP -MF $( DEPSDIR) /$* .$( DEPSEXT) $( CFLAGS) -c $< -o $@ $( ERROR_FILTER)
%.o : %.m
@echo CC $( notdir $<)
@mkdir -p $( dir $* )
$( Q) $( CC) -MMD -MP -MF $( DEPSDIR) /$* .$( DEPSEXT) $( OBJCFLAGS) -c $< -o $@ $( ERROR_FILTER)
%.o : %.s
@echo CC $( notdir $<)
@mkdir -p $( dir $* )
$( Q) $( CC) -MMD -MP -MF $( DEPSDIR) /$* .$( DEPSEXT) $( ASFLAGS) -c $< -o $@ $( ERROR_FILTER)
%.o : %.S
@echo CC $( notdir $<)
@mkdir -p $( dir $* )
$( Q) $( CC) -MMD -MP -MF $( DEPSDIR) /$* .$( DEPSEXT) $( ASFLAGS) -c $< -o $@ $( ERROR_FILTER)
%.a :
@echo AR $( notdir $@ )
@mkdir -p $( dir $* )
@rm -f $@
$( Q) $( AR) -rc $@ $^
2018-09-09 19:29:03 +10:00
e n d i f
# Allow turning off the depend rules
i f n e q ( $( strip $ ( WUT_NO_DEPEND_INCS ) ) , 1 )
2018-09-06 20:58:30 +10:00
# Add the dependency rules, if they exist
i n c l u d e $( shell find $ ( DEPSDIR ) -name "*.$ ( DEPSEXT ) ")
2018-09-09 19:29:03 +10:00
e n d i f
2018-09-06 20:58:30 +10:00
# ------------------------------------------------------------------------------
# Optional Extras
# Maybe you want libc/newlib? or a devoptab? These contain the flags you need to
# do it.
# Enable newlib support, making more complex libc functions work. Basic stuff
# like memset doesn't need this, but time functions and malloc do.
# Unless you also use WUT_MALLOC_LDFLAGS, this will dedicate most of the default
# Cafe heap to libc malloc.
# To use:
# LDFLAGS += $(WUT_NEWLIB_LDFLAGS)
2019-04-23 21:22:19 +10:00
#WUT_NEWLIB_LDFLAGS := -Wl,--whole-archive -lwutnewlib -Wl,--no-whole-archive
WUT_NEWLIB_LDFLAGS = $( warning "WUT_NEWLIB_LDFLAGS is deprecated and does nothing" )
2018-09-06 20:58:30 +10:00
# Wrap calls to malloc and friends with calls to Cafe's MEMDefaultHeap
# functions, effectivley bypassing the libc heap for most allocations. Forces
# libc heap to be very small.
# To use:
# LDFLAGS += $(WUT_MALLOC_LDFLAGS)
2019-04-23 21:22:19 +10:00
#WUT_MALLOC_LDFLAGS := -Wl,--whole-archive -lwutmalloc -Wl,--no-whole-archive
WUT_MALLOC_LDFLAGS = $( warning "WUT_MALLOC_LDFLAGS is deprecated and does nothing" )
2018-09-06 20:58:30 +10:00
# Enable libstdc++ support. Allows use of C++11 threads, along with other C++
# functionality. Make sure to use WUT_NEWLIB_LDFLAGS too.
# To use:
# LDFLAGS += $(WUT_STDCPP_LDFLAGS)
2019-04-23 21:22:19 +10:00
#WUT_STDCPP_LDFLAGS := -lstdc++
#WUT_STDCPP_LDFLAGS += -Wl,--whole-archive -lwutstdc++ -Wl,--no-whole-archive
WUT_STDCPP_LDFLAGS = $( warning "WUT_STDCPP_LDFLAGS is deprecated and does nothing" )
2018-09-06 20:58:30 +10:00
# Simple devoptab to allow filesystem access. Mounts the SD alongside the default
# Cafe mounts (/vol/content etc.)
# To use:
# LDFLAGS += $(WUT_DEVOPTAB_LDFLAGS)
2019-04-23 21:22:19 +10:00
#WUT_DEVOPTAB_LDFLAGS := -Wl,--whole-archive -lwutdevoptab -Wl,--no-whole-archive
WUT_DEVOPTAB_LDFLAGS = $( warning "WUT_DEVOPTAB_LDFLAGS is deprecated and does nothing" )