.PHONY: debug boot all clean menuconfig

CC = $(RTT_EXEC_PATH)/$(RTT_CC_PREFIX)gcc
CXX = $(RTT_EXEC_PATH)/$(RTT_CC_PREFIX)g++
CPP = $(RTT_EXEC_PATH)/$(RTT_CC_PREFIX)gcc -E -P -x c
STRIP = $(RTT_EXEC_PATH)/$(RTT_CC_PREFIX)strip --strip-unneeded
OBJCOPY = $(RTT_EXEC_PATH)/$(RTT_CC_PREFIX)objcopy
OBJDUMP = $(RTT_EXEC_PATH)/$(RTT_CC_PREFIX)objdump
LD = $(RTT_EXEC_PATH)/$(RTT_CC_PREFIX)ld
AR = $(RTT_EXEC_PATH)/$(RTT_CC_PREFIX)ar rcs
NM = $(RTT_EXEC_PATH)/$(RTT_CC_PREFIX)nm
OD = $(RTT_EXEC_PATH)/$(RTT_CC_PREFIX)objdump

include .config

ifdef CONFIG_E2000Q_DEMO_BOARD
RTCONFIG := e2000q_demo
endif

ifdef CONFIG_E2000D_DEMO_BOARD
RTCONFIG := e2000d_demo
endif

ifdef CONFIG_TARGET_PHYTIUMPI
RTCONFIG := phytium_pi
endif

ifdef CONFIG_RT_USING_SMART
RTCONFIG := $(RTCONFIG)_rtsmart
else
RTCONFIG := $(RTCONFIG)_rtthread
endif

ifdef CONFIG_PHYTIUM_RTT_TEST
RTCONFIG := $(RTCONFIG)_test
endif

boot:
	make all
	cp rtthread_a32.elf /mnt/d/tftboot
	cp rtthread_a32.bin /mnt/d/tftboot

debug:
	@$(OD) -D rtthread_a32.elf > rtthread_a32.asm
	@$(OD) -S rtthread_a32.elf > rtthread_a32.dis
	
all:
	@echo "Build started..."
	scons -j1024

clean:
	@echo "Cleaning..."
	scons -c

menuconfig:
	@echo "Running menuconfig..."
	scons --menuconfig

saveconfig:
	@echo "Save configs to" ./configs/$(RTCONFIG)
	@cp ./.config ./configs/$(RTCONFIG) -f
	@cp ./rtconfig.h ./configs/$(RTCONFIG).h -f

load_e2000q_demo_rtsmart:
	@echo "Load configs from ./configs/e2000q_demo_rtsmart"
	@cp ./configs/e2000q_demo_rtsmart ./.config -f
	@cp ./configs/e2000q_demo_rtsmart.h ./rtconfig.h -f
	@scons -c

load_e2000q_demo_rtsmart_test:
	@echo "Load configs from ./configs/e2000q_demo_rtsmart_test"
	@cp ./configs/e2000q_demo_rtsmart_test ./.config -f
	@cp ./configs/e2000q_demo_rtsmart_test.h ./rtconfig.h -f
	@scons -c

load_e2000q_demo_rtthread:
	@echo "Load configs from ./configs/e2000q_demo_rtthread"
	@cp ./configs/e2000q_demo_rtthread ./.config -f
	@cp ./configs/e2000q_demo_rtthread.h ./rtconfig.h -f
	@scons -c

load_e2000q_demo_rtthread_test:
	@echo "Load configs from ./configs/e2000q_demo_rtthread_test"
	@cp ./configs/e2000q_demo_rtthread_test ./.config -f
	@cp ./configs/e2000q_demo_rtthread_test.h ./rtconfig.h -f
	@scons -c

load_e2000d_demo_rtsmart:
	@echo "Load configs from ./configs/e2000d_demo_rtsmart"
	@cp ./configs/e2000d_demo_rtsmart ./.config -f
	@cp ./configs/e2000d_demo_rtsmart.h ./rtconfig.h -f
	@scons -c

load_e2000d_demo_rtsmart_test:
	@echo "Load configs from ./configs/e2000d_demo_rtsmart_test"
	@cp ./configs/e2000d_demo_rtsmart_test ./.config -f
	@cp ./configs/e2000d_demo_rtsmart_test.h ./rtconfig.h -f
	@scons -c

load_e2000d_demo_rtthread:
	@echo "Load configs from ./configs/e2000d_demo_rtthread"
	@cp ./configs/e2000d_demo_rtthread ./.config -f
	@cp ./configs/e2000d_demo_rtthread.h ./rtconfig.h -f
	scons -c

load_e2000d_demo_rtthread_test:
	@echo "Load configs from ./configs/e2000d_demo_rtthread_test"
	@cp ./configs/e2000d_demo_rtthread_test ./.config -f
	@cp ./configs/e2000d_demo_rtthread_test.h ./rtconfig.h -f
	scons -c

load_phytium_pi_rtthread:
	@echo "Load configs from ./configs/phytium_pi_rtthread"
	@cp ./configs/phytium_pi_rtthread ./.config -f
	@cp ./configs/phytium_pi_rtthread.h ./rtconfig.h -f
	scons -c

load_phytium_pi_rtsmart:
	@echo "Load configs from ./configs/phytium_pi_rtsmart"
	@cp ./configs/phytium_pi_rtsmart ./.config -f
	@cp ./configs/phytium_pi_rtsmart.h ./rtconfig.h -f
	@scons -c