###########################################################################
#
# Copyright (c) 2002 Xilinx, Inc.  All rights reserved.
#
# Xilinx, Inc.
# XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A 
# COURTESY TO YOU.  BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
# ONE POSSIBLE   IMPLEMENTATION OF THIS FEATURE, APPLICATION OR 
# STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION
# IS FREE FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE 
# FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.  
# XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO 
# THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO 
# ANY WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE 
# FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY 
# AND FITNESS FOR A PARTICULAR PURPOSE.
# 
#
# Makefile to build the test programs.
#
# $Id: Makefile,v 1.1.2.3 2003/03/19 18:50:44 mohan Exp $
#
##############################################################################

#CFLAGS = -O2 -g
MYCFLAGS = 
CFLAGS0 = -O0 -g -Wl,-defsym -Wl,_HEAP_SIZE=600
CFLAGST = -O2 -g -Wl,-defsym -Wl,_HEAP_SIZE=100

TOPDIR = ../../..
SYSTEMDIR = ../../../../../..
INCLUDEDIR = $(SYSTEMDIR)/include
LIBDIR = ${SYSTEMDIR}/lib
INCLUDES = -I${TOPDIR}/include -I$(INCLUDEDIR)
LIBS = -L${LIBDIR} -L${TOPDIR}

# INCLUDES = -I$(PROJDIR)/$(SYSTEMNAME)/include/ -I$(TOPDIR)/include
# LIBS = -L$(PROJDIR)/$(SYSTEMNAME)/lib -L$(TOPDIR) 

LIBRARIES = -lw

#
# obj files for testing different examples.
#
SHELL_OBJS = shell.o
SIMPLE_OBJS = print.o
THREAD_OBJS = prodcon.o print_thread.o
IPC_OBJS = producer_nb.o consumer_nb.o producer.o consumer.o
MEM_OBJS = llist.o 

#
# Linker options for the elf files. Each elf file is located at diff location
#
LFLAGS1 = -xl-mode-xilkernel -Wl,-defsym -Wl,_TEXT_START_ADDR=0xffe00000
LFLAGS2 = -xl-mode-xilkernel -Wl,-defsym -Wl,_TEXT_START_ADDR=0xffe03000
LFLAGS3 = -xl-mode-xilkernel -Wl,-defsym -Wl,_TEXT_START_ADDR=0xffe04000
LFLAGS4 = -xl-mode-xilkernel -Wl,-defsym -Wl,_TEXT_START_ADDR=0xffe05000
LFLAGS5 = -xl-mode-xilkernel -Wl,-defsym -Wl,_TEXT_START_ADDR=0xffe06000
LFLAGS6 = -xl-mode-xilkernel -Wl,-defsym -Wl,_TEXT_START_ADDR=0xffe07000
LFLAGS7 = -xl-mode-xilkernel -Wl,-defsym -Wl,_TEXT_START_ADDR=0xffe08000

help:
	@echo "Makefile to build example programs to test kernel modules"
	@echo "   Available targets for Makefile"
	@echo "   shell  : Build the shell interface"
	@echo "   simple : A simple test program"
	@echo "   thread : Producer consumer with threads and semaphores"
	@echo "   ipc    : Producer Consumer with message Q and shared mem"
	@echo "   memory : Linked list program, dynamic mem. mgmt"
	@echo "   all    : All examples"
	@echo "   help   : This help menu"
	@echo " All of the above programs are loaded at particular locations"
	@echo " This Makefile is just for reference. This or the programs"
	@echo " can be altered to test other kernel modules."

all : shell simple thread ipc memory mfs

shell: $(SHELL_OBJS)
	$(CC) $(CFLAGS) -o shell.elf $(SHELL_OBJS) $(LFLAGS1) $(LIBS) $(LIBRARIES)
	@echo "shell.elf created at location 0xffe00000"

simple: $(SIMPLE_OBJS)
	$(CC) $(CFLAGS) -o print.elf $(SIMPLE_OBJS) $(LFLAGS2) $(LIBS) $(LIBRARIES)
	@echo "print.elf created at location 0xffe03000"

thread: $(THREAD_OBJS)
	$(CC) $(CFLAGST) -o prodcon.elf prodcon.o $(LFLAGS3) $(LIBS) $(LIBRARIES)
	@echo "prodcon.elf created at location 0xffe04000"
	$(CC) $(CFLAGST) -o print_thread.elf print_thread.o $(LFLAGS3) $(LIBS) $(LIBRARIES)
	@echo "print_thread.elf created at location 0xffe04000"

ipc: $(IPC_OBJS)
	$(CC) $(CFLAGS0) -o producer.elf producer.o $(LFLAGS4) $(LIBS) $(LIBRARIES)
	$(CC) $(CFLAGS0) -o consumer.elf consumer.o $(LFLAGS5) $(LIBS) $(LIBRARIES)
	@echo "producer.elf created at location 0xffe05000"
	@echo "consumer.elf created at location 0xffe06000"
	$(CC) $(CFLAGS0) -o producer_nb.elf producer_nb.o $(LFLAGS4) $(LIBS) $(LIBRARIES)
	$(CC) $(CFLAGS0) -o consumer_nb.elf consumer_nb.o $(LFLAGS5) $(LIBS) $(LIBRARIES)
	@echo "producer_nb.elf created at location 0xffe05000"
	@echo "consumer_nb.elf created at location 0xffe06000"

memory: $(MEM_OBJS)
	$(CC) $(CFLAGS) -o llist.elf $(MEM_OBJS) $(LFLAGS6) $(LIBS) $(LIBRARIES)
	@echo "llist.elf created at location 0xffe07000"

mfs: testmfsflashrom.o
	$(CC) $(CFLAGS) -o testmfs.elf testmfsflashrom.o $(LFLAGS7) $(LIBS) $(LIBRARIES)
	@echo "testmfs.elf created at location 0xffe08000"

%.o:%.c
	$(CC) $(CFLAGS) -c $< -o $@ $(INCLUDES)

%.o:%.s
	$(CC) $(CFLAGS) -c $< -o $@ 

clean:
	rm -f $(SHELL_OBJS) $(SIMPLE_OBJS) $(THREAD_OBJS) $(IPC_OBJS) $(MEM_OBJS) *.elf *~
