#
# SNiFF+ - Makefile configuration for Rtems
#

# RTEMS BSP Path
RTEMS_BSP_NAME = cpu2000
RTEMS_BSP_PATH = /opt/rtems/bsp-$(RTEMS_BSP_NAME)
RTEMS_MAKEFILE_PATH = $(RTEMS_BSP_PATH)/m68k-rtems/$(RTEMS_BSP_NAME)
RTEMS_LIB_PATH = $(RTEMS_MAKEFILE_PATH)/lib
CROSS_COMPILE = m68k-rtems-
export RTEMS_MAKEFILE_PATH

# Native platform definition
NATIVE_PLATFORM	:=	$(shell sniff_arch;)

# First include the native platform definition
include $(SNIFF_DIR)/make_support/$(NATIVE_PLATFORM).mk

# Now cutomize for Rtems use

CC_FOR_TARGET = $(CROSS_COMPILE)gcc --pipe
AR_FOR_TARGET = $(CROSS_COMPILE)ar
LD_FOR_TARGET = $(CROSS_COMPILE)ld
CXX_FOR_TARGET = $(CROSS_COMPILE)g++
NM_FOR_TARGET = $(CROSS_COMPILE)nm
SIZE_FOR_TARGET = $(CROSS_COMPILE)size
OBJCOPY_FOR_TARGET = $(CROSS_COMPILE)objcopy
OBJDUMP_FOR_TARGET = $(CROSS_COMPILE)objdump

PACKHEX = $(RTEMS_BSP_PATH)/bin/packhex

# C++ compiler
CXX 		= 	$(CXX_FOR_TARGET)
CXXFLAGS 	= 	-B$(RTEMS_LIB_PATH) -specs bsp_specs -qrtems -g -Wall -O4 -fomit-frame-pointer -g -m68000 -Wno-deprecated

# C compiler
CC 		= 	$(CC_FOR_TARGET)
CFLAGS 		= 	-B$(RTEMS_LIB_PATH) -specs bsp_specs -qrtems -g -Wall -O4 -fomit-frame-pointer -g -m68000

# program for linking an executable
LINK 		= 	$(CXX) $(CXXFLAGS)
LINKCMDS	=	$(RTEMS_LIB_PATH)/linkcmds

# program for linking relocatable object files
LD 		= 	$(LD_FOR_TARGET)
LDFLAGS  	= 

AR      	= 	$(AR_FOR_TARGET)
ARFLAGS 	= 	
RANLIB  	= 	true

# X11 include files and library (not available)
X11_INCL 	= 	
X11_LIB  	=	

prom :
	@echo Building RTEMS SREC for $(RTEMS_BSP_NAME)
	$(OBJCOPY_FOR_TARGET) -O srec $(TARGET_DIR)/$(LINK_TARGET) $(TARGET_DIR)/$(LINK_TARGET).srec
	@echo Building RTEMS PROM for $(RTEMS_BSP_NAME)
	$(OBJCOPY_FOR_TARGET) -O binary $(TARGET_DIR)/$(LINK_TARGET) $(TARGET_DIR)/$(LINK_TARGET).prom
	@echo Building RTEMS PSREC for $(RTEMS_BSP_NAME)
	sed -e 's/.$$//' -e '/^S0/d' $(TARGET_DIR)/$(LINK_TARGET).srec | $(PACKHEX) > $(TARGET_DIR)/$(LINK_TARGET).psrec
	@echo Building RTEMS MAP for $(RTEMS_BSP_NAME)
	$(NM_FOR_TARGET) -g -n $(TARGET_DIR)/$(LINK_TARGET) > $(TARGET_DIR)/$(LINK_TARGET).map
	@echo Building RTEMS DUMP for $(RTEMS_BSP_NAME)
	$(OBJDUMP_FOR_TARGET) -dxC $(TARGET_DIR)/$(LINK_TARGET) > $(TARGET_DIR)/$(LINK_TARGET).dump
	@echo Printing RTEMS SIZE for $(RTEMS_BSP_NAME)
	$(SIZE_FOR_TARGET) $(TARGET_DIR)/$(LINK_TARGET)


