# Project: DeskLib Example
# Make: make
# Wimpslot: 5000k
#
# GNU Make makefile for a DeskLib example.
# Defaults to using Norcroft as the compiler.
#
# Various things passed on the command line can alter this makefile's behaviour;
# these are:
#
#   COMPILER - either "gcc" or "norcroft", depends on what you want to use
#   PREFIX   - this is only used when COMPILER is gcc; it gives a prefix for all
#              gcc commands executed.  Default is "gccbin:".
#
# e.g. make COMPILER=gcc

# Defaults
COMPILER = norcroft
PREFIX = gccbin:

# Defaults for norcy
ifeq (norcroft, $(COMPILER))

  CC = cc
  CFLAGS = -throwback 

  LINK = link
  LINKFLAGS = C:o.stubs 
endif

# Defaults for gcc
ifeq (gcc, $(COMPILER))

  WARNINGS = -ansi -pedantic -Wall -Wundef -Wpointer-arith \
             -Wcast-align -Wwrite-strings -Wstrict-prototypes \
             -Wmissing-prototypes -Wmissing-declarations -Wnested-externs \
             -Winline -Wno-unused -Wno-long-long -W -Wcast-qual -Wshadow

  CC = $(PREFIX)gcc
  CFLAGS = -mlibscl -mthrowback -O2 $(WARNINGS) 

  LINK = $(PREFIX)gcc
  LINKFLAGS = -mlibscl -mthrowback
endif

# We link against the main library and the pipetype and Signal debugging libs
LIBS := DeskLib:o.DeskLib DeskLib:o.Debug.pipetype DeskLib:o.Debug.Signal

# The default is to make the plain and the debug runimages
all: !RunImage !RunImageD

# Plain version
!RunImage: TestApp.o
	$(LINK) $(LINKFLAGS) -o $@ $< $(LIBS)

# Debugging version
!RunImageD: TestAppD.o
	$(LINK) $(LINKFLAGS) -o $@ $< $(LIBS)

# Debug object depends on the single source file, but compiles with
# the DeskLib_DEBUG macro defined
TestAppD.o: TestApp.c
	@mkdir -p o
	$(CC) $(CFLAGS) -DDeskLib_DEBUG -c $< -o $@

.c.o:
	@mkdir -p o
	$(CC) $(CFLAGS) -c $< -o $@

