# Makefile - makefile for building the scopeutils libraries
#
# modification history
# --------------------
# 01d,30jun11,wzc  Porting stacktrace-1.0 into analysis.(RQ:WIND00061556)
# 01c,01nov10,pca  Exclude unnecessary objects from LP64 builds
# 01b,01sep10,pca  Removed thread_lock.o (defect 230278)
# 01a,26mar08,c_c  created.
#
# DESCRIPTION
# This file contains the makefile rules for building common Analysis Tools
# utilities.
#
#*/

TGT_DIR=$(WIND_BASE)/target
TOOLS_SRC_ROOT = ..
LIB_BASE_NAME   = scopeutils


# defs.library to pull in automatic definition of the VX_CPU_FAMILY, based on
# the value of CPU.
include $(TGT_DIR)/h/make/defs.library

ifeq ($(VX_CPU_FAMILY),)
$(error VX_CPU_FAMILY undefined!)
endif

# detect simulator target arches, we'll need to change a few things based on
# this fact later
ifeq ($(VX_CPU_FAMILY),simlinux)
	IS_SIM_ARCH = true
endif

ifeq ($(VX_CPU_FAMILY),simpc)
	IS_SIM_ARCH = true
endif

ifeq ($(VX_CPU_FAMILY),simso)
	IS_SIM_ARCH = true
endif


DKMS = $(LIB_ROOT)/$(DKMDIRBASE)/scopeutils.so

ifndef _WRS_CONFIG_LP64
DKMS += $(LIB_ROOT)/$(DKMDIRBASE)/patchutils.so
endif

PATCHUTILS_OBJS = $(LIB_ROOT)/$(LIBDIRBASE)/objfilter/*.o \


ifneq (true,$(IS_SIM_ARCH))
# real hardware targets need patch, param, and strtpsupportlib.so.
PATCHUTILS_OBJS += $(wildcard $(LIB_ROOT)/$(LIBDIRBASE)/objpatch/*.o \
	$(LIB_ROOT)/$(LIBDIRBASE)/objparam/*.o)

ifndef _WRS_CONFIG_LP64
DKMS +=  $(LIB_ROOT)/$(DKMDIRBASE)/strtpsupportlib.so
RTP_SUPPORT_LIB_OBJS = stRtpSupportLib.o
endif

else
# Unless we're building headers, don't build the param or patch sub components
# for the simulator architectures (they're not supported yet).
	ifneq (headers,$(TARGET))
		EXCLUDE_SUBDIRS = param patch
	endif
endif


# The SUBDIRS variable needs to be manually defined to make sure the
# subdirectories are built in the correct order.  Normally this would be done
# by specifying dependencies, for example:
#	context: hash
# Unfortunately the Vx make rule fragments specify the phony subdirectory goals
# as double-colon rules (e.g., context::) which prevents other makefiles from
# adding meaningful dependencies.

ifndef _WRS_CONFIG_LP64
SUBDIRS = hash clock filter msgq param patch wvEvents xml
else
SUBDIRS = xml
endif

# The "all" rule is solely here to cause the dkms to be built by default.
# Unfortunately it doesn't work yet because the PATCHUTILS_OBJS wildcards are
# evaluated before the objects are built.  We get around the problem with
# SCOPEUTILS by specifying objects explicitly.  To do the same thing with
# PATCHUTILS, we'd need a good way to switch on a per-arch basis for files like
# ctx_(arch).o, param_(arch).o, etc.
#
#.PHONY: all dkms
#all: Default dkms


include $(TOOLS_SRC_ROOT)/make/common_rules.mk


# this approach doesn't work well when building a target from scratch using the
# "all" rule above. the *.o wildcards are evaluated before the objects are
# built...
#SCOPEUTILS_OBJS = $(wildcard $(LIB_ROOT)/$(LIBDIRBASE)/objscopeutils/*.o \
	$(LIB_ROOT)/$(LIBDIRBASE)/objrtilib/*.o)

vpath %.o		$(LIB_ROOT)/$(LIBDIRBASE)/objrtilib \
	$(LIB_ROOT)/$(LIBDIRBASE)/objpatch

SCOPEUTILS_OBJS = $(patsubst %, $(LIB_ROOT)/$(LIBDIRBASE)/objscopeutils/%, \
	lexer.o register.o xmlutils.o y.tab.o) \
		\
	common.o connect.o dgram.o endian.o errorapi.o errorimpl.o \
	netioGlobals.o netioUtils.o netio_common.o netio_new.o \
	osapiVerbosity.o rti_mutex.o rti_semaphore_common.o rti_semaphore_vx.o \
	rtitime.o sleep.o tcp.o thread_common.o thread_vx.o

ifndef _WRS_CONFIG_LP64
SCOPEUTILS_OBJS += $(patsubst %, $(LIB_ROOT)/$(LIBDIRBASE)/objscopeutils/%, \
	triggers.o wvEvents.o dtHashLib.o hash.o) \
	fastBuffer.o
endif

# There ought to be a way to do something like this:
#DKM_OBJS = $(TGT_DIR)/lib/$(LIBDIRBASE)/libscopeutils.a(*.o)
# to specify linking all the members of the given archive.  Unfortunately,
# I haven't found a way to get the output to work with vpath; the objects are
# named correctly, but not located.

dkms: $(LIB_ROOT)/$(DKMDIRBASE) $(DKMS)


$(LIB_ROOT)/$(DKMDIRBASE)/scopeutils.so: $(SCOPEUTILS_OBJS)
	$(LD_PARTIAL) $^ -o $@

$(LIB_ROOT)/$(DKMDIRBASE)/patchutils.so: $(filter-out %/stRtpSupportLib.o, $(PATCHUTILS_OBJS))
	$(LD_PARTIAL) $^ -o $@

$(LIB_ROOT)/$(DKMDIRBASE)/strtpsupportlib.so: $(RTP_SUPPORT_LIB_OBJS)
	$(LD_PARTIAL) $^ -o $@

LOCAL_CLEAN += $(DKMS)
