#
#                             IPSTB Project
#                   ---------------------------------
#
# Copyright (C) 2008 NXP B.V.,
#
# Filename: tmmanifest/makefile
#
#
# Rev Date       Author      Comments
#-------------------------------------------------------------------------------
#   1 20080519   batelaan    Initial
#   2 20080725   batelaan    Compile for host PC if CROSS_COMPILE is undefined
#   3 20081017   batelaan    Add -MF ... to -MD to solve ccache bug
#   4 20081103   batelaan    Add -MT ... to -MD to solve ccache bug

PROGRAM = tmmanifest

C_SOURCES = $(wildcard src/*.c)

ifdef CROSS_COMPILE
  include $(PRJROOT)/etc/application_first.mk

  LOCAL_PREFIXES = \
    /usr/local

  LOCAL_CFLAGS = \

  LOCAL_LDFLAGS = \

  LIBS = \

  include $(PRJROOT)/etc/application_last.mk

else # ifdef CROSS_COMPILE

  Q=$(if $V,,@)

  DESTDIR = $(BUILDROOT)/bin
  BUILDDIR = $(BUILDROOT)/bin.build/$(PROGRAM)
  OBJECTS = $(patsubst %.c,$(BUILDDIR)/%.o,$(C_SOURCES))
  DEPFILES = $(patsubst %.o,%.d,$(OBJECTS))

  CFLAGS = \
    -I$(_TMROOT)/inc \
    -I$(_TMROOT)/inc/x86gnu_linux_el_i486
  CFLAGS += -g
  LDFLAGS =

  all: $(DESTDIR)/$(PROGRAM)
  clean:
	@echo 'CLEAN tmmanifest'
	$(Q)rm -rf $(OBJECTS) $(DESTDIR)/$(PROGRAM)

  .PHONY: all clean

  $(DESTDIR)/$(PROGRAM): $(OBJECTS)
	@echo 'LD $@'
	$(Q)mkdir -p $(dir $@)
	$(Q)$(CC) $(CFLAGS) -o $@ $(OBJECTS)

  $(BUILDDIR)/%.o : %.c
	@echo 'CC $<'
	$(Q)mkdir -p $(dir $@)
	$(Q)$(CC) $(CFLAGS) -c -MD -MF $(@:.o=.d) -MT $@ -o $@ $<
  -include $(DEPFILES)

endif # ifdef CROSS_COMPILE
