if(DEFINED ENV{DEVKITPRO})
        set(DEVKITPRO $ENV{DEVKITPRO})
else()
        message(FATAL_ERROR "Could not find DEVKITPRO in environment")
endif()

if(DEFINED ENV{DEVKITPPC})
        set(DEVKITPPC $ENV{DEVKITPPC})
else()
        set(DEVKITPPC ${DEVKITPRO}/devkitPPC)
endif()

set(toolchain_bin_dir ${DEVKITPPC}/bin)
set(cross_prefix ${toolchain_bin_dir}/powerpc-eabi-)
set(inc_flags -I${DEVKITPRO}/libogc/include)
set(arch_flags "-mrvl -mcpu=750 -meabi -mhard-float -g")
set(link_flags "-L${DEVKITPRO}/libogc/lib/wii ${arch_flags}")

set(CMAKE_SYSTEM_NAME Generic CACHE INTERNAL "system name")
set(CMAKE_SYSTEM_PROCESSOR arm CACHE INTERNAL "processor")
set(CMAKE_LIBRARY_ARCHITECTURE powerpc-none-eabi CACHE INTERNAL "abi")
set(CMAKE_AR ${cross_prefix}ar CACHE INTERNAL "archiver")
set(CMAKE_C_COMPILER ${cross_prefix}gcc CACHE INTERNAL "c compiler")
set(CMAKE_CXX_COMPILER ${cross_prefix}g++ CACHE INTERNAL "cxx compiler")
set(CMAKE_ASM_COMPILER ${cross_prefix}gcc CACHE INTERNAL "assembler")
set(common_flags "${arch_flags} ${inc_flags}")
set(CMAKE_C_FLAGS ${common_flags} CACHE INTERNAL "c compiler flags")
set(CMAKE_ASM_FLAGS ${common_flags} CACHE INTERNAL "c compiler flags")
set(CMAKE_CXX_FLAGS ${common_flags} CACHE INTERNAL "cxx compiler flags")
set(CMAKE_LINKER ${cross_prefix}ld CACHE INTERNAL "linker")

set(CMAKE_EXE_LINKER_FLAGS ${link_flags} CACHE INTERNAL "exe link flags")
set(CMAKE_MODULE_LINKER_FLAGS ${link_flags} CACHE INTERNAL "module link flags")
set(CMAKE_SHARED_LINKER_FLAGS ${link_flags} CACHE INTERNAL "shared link flags")

set(ELF2DOL ${toolchain_bin_dir}/elf2dol)
set(GXTEXCONV ${toolchain_bin_dir}/gxtexconv)
set(RAW2C ${toolchain_bin_dir}/raw2c)

set(WII ON)
add_definitions(-DGEKKO)
