#
# Copyright (C) 2012-2013 Xilinx, Inc.
#
# This file is part of the port for FreeRTOS made by Xilinx to allow FreeRTOS
# to operate with Xilinx Zynq devices.
#
# This file is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License (version 2) as published by the
# Free Software Foundation AND MODIFIED BY the FreeRTOS exception
# (see text further below).
#
# This file is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License; if not it
# can be viewed here: <http://www.gnu.org/licenses/>
#
# The following exception language was found at
# http://www.freertos.org/a00114.html on May 8, 2012.
#
# GNU General Public License Exception
#
# Any FreeRTOS source code, whether modified or in its original release form,
# or whether in whole or in part, can only be distributed by you under the
# terms of the GNU General Public License plus this exception. An independent
# module is a module which is not derived from or based on FreeRTOS.
#
# EXCEPTION TEXT:
#
# Clause 1
#
# Linking FreeRTOS statically or dynamically with other modules is making a
# combined work based on FreeRTOS. Thus, the terms and conditions of the
# GNU General Public License cover the whole combination.
#
# As a special exception, the copyright holder of FreeRTOS gives you permission
# to link FreeRTOS with independent modules that communicate with FreeRTOS
# solely through the FreeRTOS API interface, regardless of the license terms
# of these independent modules, and to copy and distribute the resulting
# combined work under terms of your choice, provided that
#
# Every copy of the combined work is accompanied by a written statement that
# details to the recipient the version of FreeRTOS used and an offer by
# yourself to provide the FreeRTOS source code (including any modifications
# you may have  made) should the recipient request it.
# The combined work is not itself an RTOS, scheduler, kernel or related product.
# The independent modules add significant and primary functionality to FreeRTOS
# and do not merely extend the existing functionality already present
# in FreeRTOS.
#
# Clause 2
#
# FreeRTOS may not be used for any competitive or comparative purpose,
# including the publication of any form of run time or compile time metric,
# without the express permission of Real Time Engineers Ltd. (this is the norm
# within the industry and is intended to ensure information accuracy).
#

#
# Processor architecture
# ps7_cortexa9
#
ARCH = ps7_cortexa9

SYSTEMDIR = ../../..

TOPDIR = .

ARCH_PREFIX = arm-none-eabi

#
# gnu tools for Makefile
#
CC = $(ARCH_PREFIX)-gcc
AS = arm-none-eabi-as
AR = $(ARCH_PREFIX)-ar
CP = cp

#
# Compiler, linker and other options.
#
CFLAGS = ${COMPILER_FLAGS} ${EXTRA_COMPILER_FLAGS}

#
# System project directories.
#
LIBDIR = $(SYSTEMDIR)/lib
INCLUDEDIR = $(SYSTEMDIR)/include

# Kernel library.
LIBFREERTOS = ${LIBDIR}/libfreertos.a
LIBXIL = ${LIBDIR}/libxil.a

INCLUDEFILES =	${TOPDIR}/*.h

INCLUDES = -I$(INCLUDEDIR) \
	-I${TOPDIR}

KERNEL_AR_OBJS = *.c *.S

OUTS = *.o

OBJECTS =	$(addsuffix .o, $(basename $(wildcard *.c)))

STANDALONE_VERSION = $(wildcard ../../standalone_*)


libs:	$(KERNEL_AR_OBJS)
	$(MAKE) -f Makefile_depends -e "COMPILER_FLAGS=$(COMPILER_FLAGS)" "EXTRA_COMPILER_FLAGS=$(EXTRA_COMPILER_FLAGS)" -C ${STANDALONE_VERSION}/src libs
	@echo "Compiling FreeRTOS"
	@$(COMPILER) $(COMPILER_FLAGS) $(EXTRA_COMPILER_FLAGS) $(INCLUDES) $^
	@$(ARCHIVER) -r ${LIBFREERTOS} ${OUTS}
	@$(ARCHIVER) -d ${LIBXIL} asm_vectors.o
	@$(ARCHIVER) -s ${LIBXIL}

	make clean




include_standalone:
	@echo "includes"
	$(MAKE) -f Makefile_depends -e "COMPILER_FLAGS=$(COMPILER_FLAGS)" "EXTRA_COMPILER_FLAGS=$(EXTRA_COMPILER_FLAGS)" -C ${STANDALONE_VERSION}/src include
	$(CP) -rf $(INCLUDEFILES) $(INCLUDEDIR)


.PHONY: include
include:
	@echo "include"
	$(MAKE) -f Makefile_depends -e "COMPILER_FLAGS=$(COMPILER_FLAGS)" "EXTRA_COMPILER_FLAGS=$(EXTRA_COMPILER_FLAGS)" -C ${STANDALONE_VERSION}/src include
	${CP} ${INCLUDEFILES} ${INCLUDEDIR}

clean:
	rm -rf ${OBJECTS}
