if(NOT TOOLCHAIN_PREFIX)
    set(TOOLCHAIN_PREFIX "/usr")
endif()
set(TARGET_TRIPLET "x86_64-w64-mingw32")

set(TOOLCHAIN_BIN_DIR ${TOOLCHAIN_PREFIX}/bin)
set(TOOLCHAIN_INC_DIR ${TOOLCHAIN_PREFIX}/${TARGET_TRIPLET}/include)
set(TOOLCHAIN_LIB_DIR ${TOOLCHAIN_PREFIX}/${TARGET_TRIPLET}/lib)

set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
	 
set(CMAKE_C_COMPILER ${TOOLCHAIN_BIN_DIR}/${TARGET_TRIPLET}-gcc CACHE INTERNAL "")
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_BIN_DIR}/${TARGET_TRIPLET}-g++ CACHE INTERNAL "")
set(CMAKE_ASM_COMPILER ${TOOLCHAIN_BIN_DIR}/${TARGET_TRIPLET}-gcc CACHE INTERNAL "")

set(CMAKE_OBJCOPY ${TOOLCHAIN_BIN_DIR}/${TARGET_TRIPLET}-objcopy CACHE INTERNAL "")
set(CMAKE_OBJDUMP ${TOOLCHAIN_BIN_DIR}/${TARGET_TRIPLET}-objdump CACHE INTERNAL "")

set(COMMON_FLAGS "-mno-red-zone -DEFI_FUNCTION_WRAPPER -ffreestanding -fno-stack-protector -fPIC -fshort-wchar -nostdlib -e efi_main")
set(CMAKE_C_FLAGS ${COMMON_FLAGS} CACHE INTERNAL "")
set(CMAKE_CXX_FLAGS ${COMMON_FLAGS} CACHE INTERNAL "")

set(CMAKE_C_FLAGS_DEBUG "-Og -g" CACHE INTERNAL "")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Og -g" CACHE INTERNAL "")
set(CMAKE_C_FLAGS_RELEASE "-O3" CACHE INTERNAL "")
set(CMAKE_C_FLAGS_RELMINSIZE "-Os" CACHE INTERNAL "")
set(CMAKE_CXX_FLAGS_DEBUG "-Og -g" CACHE INTERNAL "")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-Og -g" CACHE INTERNAL "")
set(CMAKE_CXX_FLAGS_RELEASE "-O3" CACHE INTERNAL "")
set(CMAKE_CXX_FLAGS_RELMINSIZE "-Os" CACHE INTERNAL "")

set(CMAKE_EXE_LINKER_FLAGS "-Wl,-dll -shared -Wl,--subsystem,10" CACHE INTERNAL "")

set(CMAKE_C_COMPILER_WORKS   1)
set(CMAKE_CXX_COMPILER_WORKS 1)

set(CMAKE_DETERMINE_C_ABI_COMPILED   1)
set(CMAKE_DETERMINE_CXX_ABI_COMPILED 1)
set(CMAKE_DETERMINE_ASM_ABI_COMPILED 1)