#=============================================================================
# Lattice Utilities Makefile
#
# This makefile is used to build a collection of utility sub-projects into a
# relocatable object file named Utils.obj (not an archive library).
# The intent is to link this relocatable "library" of utilties with other
# project object files and the application to produce the final 
# executable.
#
# The sub-projects are built with their own Makefiles.
#
# Needs environment variable PLATFORM_DIR to find rules.make
# Uses definitions in rules.make for actual building
#=============================================================================

# Can be overridden
EVENTLOG_DIR = EventLog

# Use the build rule of this platform
include $(PLATFORM_DIR)/rules.make


TARGET = Utils.obj

# List of potential utilities to include
VERSION = Version/Version.obj
EVENTLOG = $(EVENTLOG_DIR)/EventLog.obj
REGACCESS = RegisterAccess/RegisterAccess.obj
#BITFIELD = BitField/BitField.obj
CMDLINERW = CmdLineRW/CmdLineRW.obj



# Include utilities needed by this project
PROJ_UTILS = $(VERSION) $(EVENTLOG) $(REGACCESS) $(CMDLINERW)


#--------------------------------------------------
#      Build Rules
#--------------------------------------------------

$(TARGET) : $(PROJ_UTILS)
	$(LD) $(LDFLAGS) $(PROJ_UTILS) -o $(TARGET)


# Rules to build the individual utilities using their makefiles
.PHONY : $(VERSION)
$(VERSION) : 
	$(MAKE) -f Makefile -C Version

.PHONY : $(EVENTLOG)
$(EVENTLOG) : 
	$(MAKE) -f Makefile -C $(EVENTLOG_DIR)

.PHONY : $(REGACCESS)
$(REGACCESS) : 
	$(MAKE) -f Makefile -C RegisterAccess

.PHONY : $(BITFIELD)
$(BITFIELD) : 
	$(MAKE) -f Makefile -C BitField

.PHONY : $(CMDLINERW)
$(CMDLINERW) : 
	$(MAKE) -f Makefile -C CmdLineRW



.PHONY : clean
clean:
	-$(MAKE) -f Makefile -C Version         clean
	-$(MAKE) -f Makefile -C $(EVENTLOG_DIR) clean
	-$(MAKE) -f Makefile -C RegisterAccess  clean
#	-$(MAKE) -f Makefile -C BitField        clean
	-$(MAKE) -f Makefile -C CmdLineRW       clean
	-$(RM) $(TARGET)


# Rebuild the library dependencies
.PHONY : depends
depends:
	-$(MAKE) -f Makefile -C Version         depends
	-$(MAKE) -f Makefile -C $(EVENTLOG_DIR) depends
	-$(MAKE) -f Makefile -C RegisterAccess  depends
#	-$(MAKE) -f Makefile -C BitField        depends
	-$(MAKE) -f Makefile -C CmdLineRW       depends

