#######################################################################
#
# Filename:    makefile
# 
# Description: eCos semaphore program.
#
# Copyright (c) 2006 Anthony Massa and Michael Barr.  All rights reserved.
# This code is from the book Programming Embedded Systems, With C and
# GNU Development Tools, 2nd Edition.
# It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied.
# You may study, use, and modify it for any non-commercial purpose,
# including teaching and use in open-source projects.
# You may distribute it non-commercially as long as you retain this notice.
# For a commercial use license, or to purchase the book,
# please visit http://www.oreilly.com/catalog/embsys2.
#
#######################################################################


ECOS_INSTALL_DIR    = /opt/ProgEmbSys/chapter11/ecos/install
XCC                 = arm-elf-gcc
LD                  = arm-elf-gcc
STRIP               = arm-elf-strip
CFLAGS              = -mcpu=xscale -g -c -Wall -I$(ECOS_INSTALL_DIR)/include -I../../include \
	                  -ffunction-sections -fdata-sections
LDFLAGS             = -mcpu=xscale -nostartfiles -L$(ECOS_INSTALL_DIR)/lib -Wl,--gc-sections \
	                  -Wl,--Map -Wl,semaphore.map
LIBS                = -Ttarget.ld -nostdlib


all: semaphore.exe

led.o: led.c led.h
	$(XCC) -o $@ $(CFLAGS) $<

button.o: button.c button.h
	$(XCC) -o $@ $(CFLAGS) $<

semaphore.o: semaphore.c led.h button.h
	$(XCC) -o $@ $(CFLAGS) $<

semaphoredbg.exe: semaphore.o button.o led.o
	$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)

semaphore.exe: semaphoredbg.exe
	$(STRIP) --remove-section=.comment semaphoredbg.exe -o $@

clean:
	-rm -f *.exe *.o semaphore.map
