#
# Makefile for an application that depends on a static library and has
# a generated C++ source file.
#
FMS_TOP = ..
include $(FMS_TOP)/build/makedefs.mk

# wildcard the sources
SRCS = $(wildcard *.c *.cc *.cpp)

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

GENERATED_OBJS = $(FMS_OBJDIR)/generated.o

# we need to include these explicitly
LDLIBS = $(GENERATED_OBJS) -llog

# cause creation of generated code, and relink if liblog.a changes
FMS_BUILD_DEPS = \
	$(GENERATED_OBJS) \
	$(FMS_DIST_LIBDIR)/liblog.a



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

# build
here: $(FMS_BUILD_APP)

# create our generated source file
#
# We're generating this into the objects directory rather than the source
# directory.  If we don't do it this way:
#	- We won't regenerate the sources for different builds.  This could
#	  be good or bad.  Probably bad.
#	- We have to remove the generated code manually for "make clean".  This
#	  can be done by setting CLEAN_HERE=clean-here.
#	- We have to be careful when setting up $(SRCS).  The first time we
#	  build it will see only the "real" sources, the second time it will
#	  see the "real" stuff and the generated stuff.  Since we create OBJS
#	  from SRCS, this can cause objects to be included twice.
# The make rules allow generated source code to be in either the source
# directory or the object directory.
#
$(FMS_OBJDIR)/generated.cpp: generated.cpp.in
	@echo "    Generating $@"
	@sed -e "s/_HOST_NAME_/`hostname`/" < generated.cpp.in \
		> $(FMS_OBJDIR)/generated.cpp


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

