#
# Makefile for a complex application.
#
# We access the "libfoo" library within the source tree rather than the
# install directory.  This is okay if we're not using FMS_OBJECTTOP,
# but starts to get ugly if we are.  The key lesson is that we can't use
# the same defines for both situations, so copying "libfoo" out to the
# FMS_PRIV_LIBDIR and linking there is a better idea.
#
FMS_TOP = ..
include $(FMS_TOP)/build/makedefs.mk

# build these libraries first
FMS_SUBDIRS = libfoo libshared

# explicitly list source files
SRCS = $(wildcard *.cpp)

# tell FMS that we want all SRCS to be built into an executable
FMS_BUILD_APP = app_three

ifdef FMS_OBJECTTOP
 LOCAL_LDLIBS = -L$(FMS_OBJDIR)/../libfoo/obj-$(FMS_BUILDSPEC)
 LOCAL_BUILD_DEPS = $(FMS_OBJDIR)/../libfoo/obj-$(FMS_BUILDSPEC)/libfoo.a
else
 LOCAL_LDLIBS = -Llibfoo/$(FMS_OBJDIR)
 LOCAL_BUILD_DEPS = $(FMS_DIST_LIBDIR)/liblog.a
endif


# extra libraries
LDLIBS = $(LOCAL_LDLIBS) -L$(FMS_DIST_LIBDIR) -lfoo -llog -lshared

# relink if liblog.a or libfoo.a changes; no need to depend on shared lib
# (note we're accessing libfoo.a from local lib, not install lib)
#
# we could use $(wildcard dir/*.a) here as well if we want to be general
FMS_BUILD_DEPS = \
	$(FMS_DIST_LIBDIR)/liblog.a \
	$(LOCAL_BUILD_DEPS)

# just for fun, have a local clean target
FMS_CLEAN_HERE = clean-here


#
# rules start here
#
include $(FMS_TOP)/build/makerules.mk

# build
here: $(FMS_BUILD_APP)

# install
install-here:
	@echo "   Copying $(FMS_BUILD_APP) to $(FMS_DIST_BINDIR)"
	@$(CPIFNEW) $(FMS_OBJDIR)/$(FMS_BUILD_APP) $(FMS_DIST_BINDIR)

