########################################################################
#  Use TARG_COMPILER_FAMILY to set the C compiler name

ifeq ($(TARG_COMPILER_FAMILY),gcc)
   CC := gcc
endif

ifeq ($(TARG_COMPILER_FAMILY),intel)
   CC := icc
endif

########################################################################
#  Use O_DIR as equal to $(TARG)/ so that if TARG is empty then O_DIR
#  will be empty.  But if $(TARG) as a value then O_DIR will have a
#  trailing slash.

ifneq ($(TARG),)
  override O_DIR := $(TARG)/
endif

########################################################################
#  Use TARG_BUILD_SCENARIO to set the compiler options for either
#  debug or optimize.

ifeq ($(TARG_BUILD_SCENARIO),dbg)
  CF := -g -O0
endif

ifeq ($(TARG_BUILD_SCENARIO),opt)
  CF := -O3
endif

EXEC              := $(O_DIR)hello
SRC               := main.c hello.c
override CFLAGS   := $(CFLAGS) $(CF)

OBJS := $(O_DIR)main.o $(O_DIR)hello.o

all: $(O_DIR) $(EXEC)

$(O_DIR):
	mkdir -p $(O_DIR)

$(EXEC): $(OBJS)
	$(LINK.c) -o $@ $^

neat:
	$(RM) *~
clean: neat
	$(RM) $(OBJS)
clobber: clean
	$(RM) $(EXEC)



######################## compilation rules ###############################

$(O_DIR)%.o : %.c
	$(COMPILE.c) -o $@ -c $<


######################## Dependancies ####################################

$(O_DIR)main.o : main.c hello.h

$(O_DIR)hello.o: hello.c hello.h

