#   src/db-api-app directory
#
# Sample/Dummy application to show how DB-API and YControl
# libraries are used in a polling loop in an application

# make all --> yp-ha-app  [sample YP-HA change mode program]

ifdef MAC
 INSTALL_PREFIX ?= /usr/local
else
 INSTALL_PREFIX ?= /usr
endif

############### SOURCE PROFILE ##############################

PROJECT_NM=yumapro
SUBDIR_NM=yp-ha-app
SUBDIR_CPP=-I../subsys-pro -I../ycontrol -I../db-api -I../agt -I../ncx

SRC_INST=$(DESTDIR)$(INSTALL_PREFIX)/share/yumapro/src/$(SUBDIR_NM)

############### TARGET PROFILE ##############################

TARGET=$(TBASE)/$(SUBDIR_NM)
BIN_INST=$(TBASE)/bin
REAL_INST=$(DESTDIR)$(INSTALL_PREFIX)/bin
PROG=$(SUBDIR_NM)

SUBSYS_TARGET=$(TBASE)/subsys-pro

##################### LIBRARIES ########################

# The order of these LIBS matters!
#
# If the linker can't find external symbols you know should
# be there and you get an Unresolved External error
#   file foo : unresolved external to bar
# Then put the library that contains foo BEFORE the one
# that contains bar.

STATIC_LIBDICT = -L../../../libdict/bin -ldict

LFIRST=
ifdef MAC
  ifndef COVERITY
LFIRST=-L/sw/lib/x86_64
  endif
endif  # MAC

LIBS = -lyumapro_db-api -lyumapro_ycontrol -lsendbuff -lyumapro_ncx

ifdef STATIC
LIBS += $(STATIC_LIBDICT) -lxml2
endif

ifdef WITH_YANG_CBOR
LIBS += -lcbor
endif # WITH_YANG_CBOR


LOBJS = $(SUBSYS_TARGET)/subsystem.o
LOBJS += $(SUBSYS_TARGET)/subsys_util.o

LIBTARGS= $(LBASE)/libyumapro_db-api.$(LIBNCXSUFFIX) \
	$(LBASE)/libyumapro_ycontrol.$(LIBNCXSUFFIX) \
	$(LBASE)/libyumapro_ncx.$(LIBNCXSUFFIX)

############################# MAKE RULES ##################

ALL_TARGETS=$(SUBDIR_NM)

all: $(ALL_TARGETS)

#################### PLATFORM DEFINITIONS ############
include ../platform/platform.profile
include ../platform/mac.config

################ DEPENDENCIES #########################
# depend rule must be included after the 'all' make rule

include ../platform/platform.profile.depend

clean:
	rm -f $(OBJS) $(BIN_INST)/$(PROG)


superclean:
	rm -f *~ *.D dependencies $(OBJS) $(BIN_INST)/$(PROG)

test:

TARGETS=

# probably needs to be done by root
ifdef DEBIAN
  ifeq "$(PACKAGE)" "SERVER"
    TARGETS=installdir
  else
   ifeq "$(PACKAGE)" "TOOLS"
    TARGETS=sources
   else
    TARGETS=installdir sources
   endif  # TOOLS
  endif # SERVER
else
  TARGETS=installdir sources
endif  # DEBIAN

install: $(TARGETS)

installdir:
	mkdir -p $(REAL_INST)
	install $(OWNER) $(GRP) $(BIN_INST)/$(PROG) $(REAL_INST)

sources:
	mkdir -p $(SRC_INST)
#	cp Makefile.standalone $(SRC_INST)/Makefile
	cp Makefile $(SRC_INST)/
	cp main.c $(SRC_INST)/

uninstall: superclean
	rm -f  $(REAL_INST)/$(PROG)
	rm -rf $(SRC_INST)

distclean: superclean

# this real rule keeps make from deleting the $(OBJS) as
# intermediate files
$(SUBDIR_NM): $(OBJS) $(LIBTARGS)
	$(LINK) $(LN_EXTRA) $(CFLAGS) $(CPPFLAGS) $(LFLAGS) $(OBJS) $(LOBJS) -o $(BIN_INST)/$(PROG) $(LPATH) $(FPATH) $(LIBS)


.PHONY: installdir sources $(SUBDIR_NM)

# prevent the make program from choking on all the symbols
# that get generated from autogenerated make rules
.NOEXPORT:

include ./dependencies
