# PKG_INSTALL_DIR might need to be edited.  Right now it is set
# assuming that a user ran pkgconf.tcl in //c/ecos-work on Windows NT,
# or used the Configuration Tool with C:\ecos-work as a build-tree.
#
# You can also override it on the make command-line, e.g.:
#   make PKG_INSTALL_DIR=/myecc/install
# or you can set it in your environment

PKG_INSTALL_DIR = //c/ecos-work/install

# You must also set XCC to the name of your cross-compiler. Uncomment
# one of the below, or invoke make with the name of the compiler you
# want, e.g.:
#   make XCC=mn10300-elf-gcc
# You can also set XCC in your environment

#XCC = mn10300-elf-gcc
#XCC = mips-tx39-elf-gcc
#XCC = powerpc-eabi-gcc

CFLAGS := -Wall -g -I${PKG_INSTALL_DIR}/include

LDFLAGS := -g -L$(PKG_INSTALL_DIR)/lib -Wl,--gc-sections
LIBS := -Ttarget.ld -nostdlib

LD := $(XCC)

all: hello twothreads simple-alarm serial

clean:
	-rm -f hello hello.o twothreads twothreads.o
	-rm -f simple-alarm simple-alarm.o serial serial.o
	-rm -f instrument-test instrument-test.o

CCCHECK:
ifeq ($(XCC),)
	@echo You must set XCC to the name of your cross-compiler
	@false
endif


%.o: %.c
	$(XCC) -c -o $*.o $(CFLAGS) $<

hello: CCCHECK hello.o
	$(LD) $(LDFLAGS) -o $@ $@.o $(LIBS)

twothreads: CCCHECK twothreads.o
	$(LD) $(LDFLAGS) -o $@ $@.o $(LIBS)

simple-alarm: CCCHECK simple-alarm.o
	$(LD) $(LDFLAGS) -o $@ $@.o $(LIBS)

serial: CCCHECK serial.o
	$(LD) $(LDFLAGS) -o $@ $@.o $(LIBS)

instrument-test: CCCHECK instrument-test.o
	$(LD) $(LDFLAGS) -o $@ $@.o $(LIBS)

.PHONY: all clean CCCHECK

