| ######################################################################## |
| # |
| # Pass1: Determine CROSS_COMPILE only. |
| # We need CROSS_COMPILE in order to validate various KBUILD_CFLAGS |
| # GCC CROSS_COMILE is needed in order to validate compiler options |
| # via constructs such as: |
| # KBUILD_CFLAGS += $(call cc-option,-option,) |
| # |
| # Pass2: Determine LIB_INCLUDE_DIR and TOOLCHAIN_CFLAGS. |
| # Knowing KBUILD_CFLAGS, we can query GCC compiler for the location |
| # of the libraries corresponding to the KBUILD_CFLAGS. |
| # |
| ####################################################################### |
| |
| REQUIRED_SDK_VER=0.9.1 |
| |
| ifndef ZEPHYR_SDK_INSTALL_DIR |
| |
| $(error ZEPHYR_SDK_INSTALL_DIR is not set) |
| else |
| SDK_VERSION = $(shell cat ${ZEPHYR_SDK_INSTALL_DIR}/sdk_version) |
| SDK_CHECK = $(shell ${ZEPHYR_BASE}/scripts/vercomp $(REQUIRED_SDK_VER) $(SDK_VERSION) || echo $$?) |
| |
| SDK_MESSAGE=" \ |
| The SDK version you are using is old, please update your SDK. \ |
| \ |
| You need at least SDK version $(REQUIRED_SDK_VER). \ |
| \ |
| The new version of the SDK can be download from: \ |
| \ |
| https://github.com/zephyrproject-rtos/meta-zephyr-sdk/releases/download/$(REQUIRED_SDK_VER)/zephyr-sdk-$(REQUIRED_SDK_VER)-setup.run \ |
| \ |
| \ |
| " |
| |
| ifeq ($(SDK_CHECK),1) |
| $(error $(SDK_MESSAGE)) |
| endif |
| endif |
| |
| TOOLCHAIN_VENDOR := zephyr |
| TOOLCHAIN_ARCH := x86_64 |
| |
| # TODO remove once we retire 0.8.2 in favor of 0.9 |
| # See also conditional below near iamcu (pass1) |
| ifeq ($(SDK_VERSION),0.8.2) |
| TOOLCHAIN_VENDOR := poky |
| TOOLCHAIN_ARCH := i686 |
| endif |
| |
| # TODO remove once we have a replacement for 0.9 that fixes ZEP-1882 |
| # See https://jira.zephyrproject.org/browse/ZEP-1882 |
| ifeq ($(SDK_VERSION),0.9) |
| ifeq ($(ARCH),arc) |
| ifneq ($(CONFIG_DEBUG),y) |
| KBUILD_CFLAGS_OPTIMIZE := -O2 |
| endif |
| endif |
| endif |
| |
| ifeq ($(HOST_OS),MINGW) |
| TOOLCHAIN_HOME = ${ZEPHYR_SDK_INSTALL_DIR}/sysroots/i686-pokysdk-mingw32 |
| else |
| TOOLCHAIN_HOME = ${ZEPHYR_SDK_INSTALL_DIR}/sysroots/$(TOOLCHAIN_ARCH)-pokysdk-linux |
| endif |
| |
| ifndef MAKEFILE_TOOLCHAIN_DO_PASS2 |
| |
| # arm (pass1) |
| CROSS_COMPILE_TARGET_arm = arm-$(TOOLCHAIN_VENDOR)-eabi |
| SYSROOT_TARGET_arm = armv5-$(TOOLCHAIN_VENDOR)-eabi |
| CROSS_COMPILE_arm=$(TOOLCHAIN_HOME)/usr/bin/$(CROSS_COMPILE_TARGET_arm)/$(CROSS_COMPILE_TARGET_arm)- |
| |
| # arc (pass1) |
| CROSS_COMPILE_TARGET_arc = arc-$(TOOLCHAIN_VENDOR)-elf |
| SYSROOT_TARGET_arc = arc-$(TOOLCHAIN_VENDOR)-elf |
| CROSS_COMPILE_arc=$(TOOLCHAIN_HOME)/usr/bin/$(CROSS_COMPILE_TARGET_arc)/$(CROSS_COMPILE_TARGET_arc)- |
| |
| # iamcu (pass1) |
| CROSS_COMPILE_TARGET_iamcu = i586-$(TOOLCHAIN_VENDOR)-elfiamcu |
| SYSROOT_TARGET_iamcu = iamcu-$(TOOLCHAIN_VENDOR)-elfiamcu |
| ifeq ($(SDK_VERSION),0.8.2) |
| CROSS_COMPILE_iamcu=$(TOOLCHAIN_HOME)/usr/bin/iamcu-poky-elfiamcu/$(CROSS_COMPILE_TARGET_iamcu)- |
| else |
| CROSS_COMPILE_iamcu=$(TOOLCHAIN_HOME)/usr/bin/$(CROSS_COMPILE_TARGET_iamcu)/$(CROSS_COMPILE_TARGET_iamcu)- |
| endif |
| |
| # x86 (pass1) |
| CROSS_COMPILE_TARGET_x86 = i586-$(TOOLCHAIN_VENDOR)-elf |
| SYSROOT_TARGET_x86 = i586-$(TOOLCHAIN_VENDOR)-elf |
| CROSS_COMPILE_x86=$(TOOLCHAIN_HOME)/usr/bin/$(CROSS_COMPILE_TARGET_x86)/$(CROSS_COMPILE_TARGET_x86)- |
| |
| # nios2 (pass1) |
| CROSS_COMPILE_TARGET_nios2 = nios2-$(TOOLCHAIN_VENDOR)-elf |
| SYSROOT_TARGET_nios2 = nios2-$(TOOLCHAIN_VENDOR)-elf |
| CROSS_COMPILE_nios2=$(TOOLCHAIN_HOME)/usr/bin/$(CROSS_COMPILE_TARGET_nios2)/$(CROSS_COMPILE_TARGET_nios2)- |
| |
| # xtensa (pass1) |
| CROSS_COMPILE_TARGET_xtensa = xtensa-$(TOOLCHAIN_VENDOR)-elf |
| SYSROOT_TARGET_xtensa = xtensa-$(TOOLCHAIN_VENDOR)-elf |
| CROSS_COMPILE_xtensa=$(TOOLCHAIN_HOME)/usr/bin/$(CROSS_COMPILE_TARGET_xtensa)/$(CROSS_COMPILE_TARGET_xtensa)- |
| ifeq ($(ARCH),xtensa) |
| SYSROOT := ${ZEPHYR_SDK_INSTALL_DIR}/sysroots/${SYSROOT_TARGET_${ARCH}} |
| common_xtensa_flags := --sysroot=$(SYSROOT) -I=/usr/include -I=/usr/include/arch/include |
| CFLAGS += $(common_xtensa_flags) |
| CXXFLAGS += $(common_xtensa_flags) |
| endif |
| TOOLCHAIN_LIBS_xtensa = hal |
| |
| # riscv32 (pass1) |
| CROSS_COMPILE_TARGET_riscv32 = riscv32-$(TOOLCHAIN_VENDOR)-elf |
| SYSROOT_TARGET_riscv32 = riscv32-$(TOOLCHAIN_VENDOR)-elf |
| CROSS_COMPILE_riscv32=$(TOOLCHAIN_HOME)/usr/bin/$(CROSS_COMPILE_TARGET_riscv32)/$(CROSS_COMPILE_TARGET_riscv32)- |
| |
| else |
| |
| # Test CONFIG_TOOLCHAIN_VARIANT value with surrounding quotes removed (if any) |
| ifneq ($(CONFIG_TOOLCHAIN_VARIANT:"%"=%),) |
| SYSROOT := ${ZEPHYR_SDK_INSTALL_DIR}/sysroots/${SYSROOT_TARGET_$(subst $\",,${CONFIG_TOOLCHAIN_VARIANT})} |
| else |
| SYSROOT := ${ZEPHYR_SDK_INSTALL_DIR}/sysroots/${SYSROOT_TARGET_${ARCH}} |
| endif |
| |
| LIBGCC_DIR = $(shell dirname `$(CROSS_COMPILE)gcc --sysroot=$(SYSROOT) $(KBUILD_CFLAGS) -print-libgcc-file-name`) |
| NEWLIB_DIR = $(shell $(CROSS_COMPILE)gcc --sysroot=$(SYSROOT) $(KBUILD_CFLAGS) -print-multi-directory) |
| TOOLCHAIN_CFLAGS = -I $(SYSROOT)/usr/include |
| LIB_INCLUDE_DIR += -L $(LIBGCC_DIR) -L $(SYSROOT)/usr/lib/$(NEWLIB_DIR) |
| endif |
| |
| ifneq ($(CONFIG_TOOLCHAIN_VARIANT:"%"=%),) |
| CROSS_COMPILE = $(CROSS_COMPILE_$(subst $\",,$(CONFIG_TOOLCHAIN_VARIANT))) |
| else |
| CROSS_COMPILE = $(CROSS_COMPILE_$(ARCH)) |
| endif |
| |
| QEMU_BIN_PATH ?= $(TOOLCHAIN_HOME)/usr/bin |
| QEMU_BIOS=$(TOOLCHAIN_HOME)/usr/share/qemu |
| |
| TOOLCHAIN_LIBS = gcc ${TOOLCHAIN_LIBS_${ARCH}} |
| |
| DTC = ${TOOLCHAIN_HOME}/usr/bin/dtc |
| OPENOCD ?= ${TOOLCHAIN_HOME}/usr/bin/openocd |
| OPENOCD_DEFAULT_PATH ?= ${TOOLCHAIN_HOME}/usr/share/openocd/scripts |
| |
| BOSSAC ?= ${TOOLCHAIN_HOME}/usr/bin/bossac |
| |
| export LIB_INCLUDE_DIR CROSS_COMPILE TOOLCHAIN_LIBS QEMU_BIN_PATH QEMU TOOLCHAIN_CFLAGS OPENOCD OPENOCD_DEFAULT_PATH DTC BOSSAC |
| |
| ifndef MAKEFILE_TOOLCHAIN_DO_PASS2 |
| MAKEFILE_TOOLCHAIN_DO_PASS2=true |
| endif |