# **COPYRIGHT*******************************************************************
#    INTEL CONFIDENTIAL
#    Copyright (C) 2017 Intel Corporation
#    Copyright (C) 2004 - Infineon Technologies
# *******************************************************************COPYRIGHT**
# **DISCLAIMER******************************************************************
#    The source code contained or described herein and all documents related
#    to the source code ("Material") are owned by Intel Corporation or its
#    suppliers or licensors. Title to the Material remains with Intel
#    Corporation or its suppliers and licensors. The Material may contain
#    trade secrets and proprietary and confidential information of Intel
#    Corporation and its suppliers and licensors, and is protected by
#    worldwide copyright and trade secret laws and treaty provisions. No part
#    of the Material may be used, copied, reproduced, modified, published,
#    uploaded, posted, transmitted, distributed, or disclosed in any way
#    without Intel's prior express written permission.
#
#    No license under any patent, copyright, trade secret or other
#    intellectual property right is granted to or conferred upon you by
#    disclosure or delivery of the Materials, either expressly, by
#    implication, inducement, estoppel or otherwise. Any license under
#    such intellectual property rights must be express and approved by
#    Intel in writing.
# ******************************************************************DISCLAIMER**
# ==============================================================================
#
# The 'CCASE' lines will be filled by ClearCase upon checkin,
# please do not change this information manually!
#
# ==============================================================================
#
# All rights reserved.
# ==============================================================================
#
# ==============================================================================
#
# This document contains proprietary information belonging to Infineon
# Technologies. Passing on and copying of this document, and communication of
# its contents is not permitted without prior written authorisation.
#
# ==============================================================================
#
# This Makefile is used to generate VDSL2 sram_test code.
#
# Make targets:
#
#    make              - generates sram_test.elf
#    make all          - as above all libraries will be verified
#    make clean        - delete all output files (in build)
#    make cleanelf     - delete sram_test.elf (in build)
#
# CCASE_FILE      =   "makefile"
# CCASE_DATE      =   "Fri Dec 10 12:14:05 2004"
# CCASE_USER      =   "schmidch"
# CCASE_VERSION   =   "\main\3"
#

#
# Implicit rules
#
%.d: %.c

	@echo ************************************************
	@echo * Generating dependencies for $(<F)
	@echo ************************************************
	$(CC) -Hnoobject -Hnocopyr -Hmakeof=$(OBJ_DIR)/$@ $(CPPFLAGS) $<

%.o: %.c %.d

	@echo ************************************************
	@echo * Compiling $(<F)
	@echo ************************************************
	$(CC) $(CFLAGS) -c $(CPPFLAGS) $< > $(OBJ_DIR)/$(@:%.o=%.lst)

%.o: %.s

	@echo ************************************************
	@echo * Assembling $(<F)
	@echo ************************************************
	$(AS) -c $(AS_FLAGS) $(DEFS) $<

#
# Base drive
#
BASE_DRIVE = Y:/VDSL2

#
# Make dir
#
MAKE_DIR = $(BASE_DRIVE)/online/Modem/source/Vdsl_IFX/sram_test

#
# Tools dir
#
TOOLS_DIR = $(BASE_DRIVE)/tools/hcarc_4.5a/bin

#
# Tools:
#
CC = $(TOOLS_DIR)/hcarc
LD = $(TOOLS_DIR)/hcarc
AS = $(TOOLS_DIR)/hcarc
AR = $(TOOLS_DIR)/ararc
NM = $(TOOLS_DIR)/nmarc

#
# Common defines
#
DEFS = -D__MET__

#
# Assembler flags
#
AS_FLAGS  = -arc8
AS_FLAGS += -Xadds
AS_FLAGS += -Xxmac_d16
AS_FLAGS += -Xxy
AS_FLAGS += -Xnorm
AS_FLAGS += -Xbarrel_shifter
AS_FLAGS += -Xmin_max
AS_FLAGS += -c
AS_FLAGS += -HL
AS_FLAGS += -g
AS_FLAGS += -Hnocopyr
AS_FLAGS += -Hobjdir=$(OBJ_DIR)
ifeq ($(NODEBUG),1)
AS_FLAGS += -DNODEBUG
else
AS_FLAGS += -g
endif

#
# Common C flags
#
CFLAGS  = -arc8
CFLAGS += -Hobjdir=$(OBJ_DIR)
CFLAGS += -Xadds
CFLAGS += -Xxmac_d16
CFLAGS += -Xxy
CFLAGS += -Xnorm
CFLAGS += -Xbarrel_shifter
CFLAGS += -Xmin_max
CFLAGS += -Hoff=ldst_from_code
CFLAGS += -Hon=scalars_in_bss
CFLAGS += -Hoff=multiple_var_defs
CFLAGS += -Hoff=volatile_cache_bypass
CFLAGS += -Hon=Pointers_compatible
CFLAGS += -Hasopt=-l
CFLAGS += -Hasopt=-fl80p0
CFLAGS += -Hnocrt
CFLAGS += -Hnocplus
CFLAGS += -Hanno
CFLAGS += -Hnothread
CFLAGS += -Hnocopyr
CFLAGS += -Hldopt=-lharvard
CFLAGS += -Bhardalign

ifeq ($(NODEBUG),1)
CFLAGS += -Hi
CFLAGS += -0s
CFLAGS += -DNODEBUG
else
CFLAGS += -g
CFLAGS += -O0
endif

#
# Linker flags
#
LDFLAGS  = -arc8
LDFLAGS += -Bstatic
LDFLAGS += -Hldopt=-Xnocompress
LDFLAGS += -Bgrouplib
LDFLAGS += -Hhostlink
LDFLAGS += -Hnocplus
LDFLAGS += -Hheap=0
LDFLAGS += -m
LDFLAGS += -Hldopt=-q
LDFLAGS += -Hnocrt
LDFLAGS += -Hnolib
LDFLAGS += -Hnocopyr
LDFLAGS += -Hldopt=-Cpage=0

# set target
TARGET := sram_test

# set source and object directories (will be used in implicit rules)
SRC_DIR = $(MAKE_DIR)/source
OBJ_DIR = $(MAKE_DIR)/build

# set MS-DOS path of object directory (used for MS-DOS shell calls)
DOS_OBJ_DIR = $(subst /,\, $(OBJ_DIR))

# extend include path
INCS := -Iinclude
INCS += -I$(BASE_DRIVE)/tools/RegisterGeneration/productive_xml/h

# set path for source directories
VPATH = $(OBJ_DIR); $(SRC_DIR);

# list of all object files as dependencies for sram_test library
SRAM_TEST_OBJS := sram_test.o ocmem_io.o xdma_io.o

# set startup object (assembler file including startup code)
# STARTUP_OBJ    := startup.o
# STARTUP_LD_OBJ := $(OBJ_DIR)/startup.o

# set additional assembler objects
ASM_OBJS := startup.o

# list of all sram_test objects
ALL_SRAM_TEST_OBJS := $(ASM_OBJS) $(SRAM_TEST_OBJS)

# list of all dependencies
SRAM_TEST_DEPS    := $(patsubst %.o, $(OBJ_DIR)/%.d, $(SRAM_TEST_OBJS))
# list of all sram_test objects with complete paths
SRAM_TEST_OBJS_PATH := $(patsubst %.o, $(OBJ_DIR)/%.o, $(ALL_SRAM_TEST_OBJS))

# name of SRAM_TEST map file
SRAM_TEST_MAP := sram_test.map

# common compiler flags (will be used in implicit rules)
CPPFLAGS := $(INCS) $(DEFS)


#
# Target to create ELF file
#
$(TARGET).elf: $(ALL_SRAM_TEST_OBJS) $(SRAM_TEST_MAP)

	@echo ************************************************
	@echo *** Linking $@
	@echo ************************************************

	$(LD) $(LDFLAGS) $(SRAM_TEST_OBJS_PATH) $(SRAM_TEST_MAP) -o $(OBJ_DIR)/$(TARGET).elf > $(OBJ_DIR)/$(TARGET).map
	$(NM) $(OBJ_DIR)/$(TARGET).elf > $(OBJ_DIR)/$(TARGET).sym

	@echo ************************************************
	@echo *** Build complete
	@echo ************************************************


#
# Target to create all
#
.PHONY: all

all: $(TARGET).elf

-include $(SRAM_TEST_DEPS)


#
# Target to delete all
#
.PHONY: clean

clean: cleanelf

	-del $(DOS_OBJ_DIR)\*.o
	-del $(DOS_OBJ_DIR)\*.d
	-del $(DOS_OBJ_DIR)\*.map
	-del $(DOS_OBJ_DIR)\*.sym
	-del $(DOS_OBJ_DIR)\*.lst


#
# Target to delete only ELF file
#
.PHONY: cleanelf

cleanelf:
	-del $(DOS_OBJ_DIR)\*.elf
