NOODBC=true

# Added for shared objects to resolve the DFM build errors
SHARECMD=

include ../../src/Makefile.common

.PHONY: release all dirs shareinc sharelib incstuff relinstall installlibs

CFLAGS += -DHAVE_CONFIG_H -I. -I./include -I../libnetapplm -I../libnetappcgi -I../libzapid
CFLAGS += -Wno-format-extra-args
CFLAGS += -Wall -Wformat-security -Winit-self -Wparentheses -Wpointer-arith -Wsign-compare
CFLAGS += -fstack-protector-strong
ifeq "$(NTAP_PLATFORM)" "linux-64"
CFLAGS += -fstack-clash-protection
endif

ifeq "$(NTAP_PLATFORM)" "freebsd-amd64"
CFLAGS += -I/usr/local/include
endif

SRCS = \
	HTMLparser.c \
	HTMLtree.c \
	SAX2.c \
	buf.c \
	catalog.c \
	chvalid.c \
	debugXML.c \
	dict.c \
	encoding.c \
	entities.c \
	error.c \
	globals.c \
	hash.c \
	list.c \
	nanohttp.c \
	parser.c \
	parserInternals.c \
	pattern.c \
	relaxng.c \
	threads.c \
	tree.c \
	uri.c \
	valid.c \
	xinclude.c \
	xlink.c \
	xmlIO.c \
	xmlmemory.c \
	xmlreader.c \
	xmlregexp.c \
	xmlsave.c \
	xmlschemas.c \
	xmlschemastypes.c \
	xmlstring.c \
	xpath.c \
	xpointer.c \

LIBXMLHDRS = \
	HTMLparser.h	\
	HTMLtree.h	\
	SAX.h	\
	SAX2.h	\
	catalog.h	\
	chvalid.h	\
	debugXML.h	\
	dict.h	\
	encoding.h	\
	entities.h	\
	globals.h	\
	hash.h	\
	list.h	\
	nanoftp.h	\
	nanohttp.h	\
	parser.h	\
	parserInternals.h	\
	pattern.h	\
	relaxng.h	\
	threads.h	\
	tree.h	\
	uri.h	\
	valid.h	\
	xinclude.h	\
	xlink.h	\
	xmlIO.h	\
	xmlerror.h	\
	xmlmemory.h	\
	xmlreader.h	\
	xmlregexp.h	\
	xmlsave.h	\
	xmlschemas.h	\
	xmlschemastypes.h	\
	xmlstring.h	\
	xmlunicode.h	\
	xmlversion.h	\
	xpath.h	\
	xpathInternals.h	\
	xpointer.h 	\

# added for static & shared libraries
SHARED_SUFFIX = .so

ifeq "$(PLATFORM)" "hpux"
SHARED_SUFFIX = .sl
endif

LIBNAME = libxml
STATIC_LIB = $(OD)/$(LIBNAME)$(STATIC_SUFFIX)
SHARED_LIB = $(OD)/$(LIBNAME)$(SHARED_SUFFIX)

STATIC_LIB_NAME = $(LIBNAME)$(STATIC_SUFFIX)
SHARED_LIB_NAME = $(LIBNAME)$(SHARED_SUFFIX)

BUILD_SHARED_LIB=1

# Note: DMF doesnot use our SDK Makefile.commom
# added to resolve the DFM build errors
# this will not build the shared objects for DFM 
ifeq "$(SHARECMD)" ""
BUILD_SHARED_LIB=0
endif

all: dirs release

dirs:
	-@mkdir -p $(OD)
	-@mkdir -p $(LIBD)


$(SHARED_LIB): $(OBJS)
	$(SHARECMD)

$(OBJS): $(THIRD_TOP)/Makefile.common

installlibs: $(SHARED_LIB)
	@if [ -n "$(LIBD)" ] ; then \
 		if [ $(BUILD_SHARED_LIB) -eq 1 ] ; then \
		echo "Installing $(SHARED_LIB_NAME) ... in $(LIBD)"; \
		[ -d $(LIBD) ] || mkdir -p $(LIBD); \
		$(CP) $(SHARED_LIB) $(LIBD); \
		fi \
	fi
	@if [ -n "$(SDKLIBD)" ] ; then \
		if [ $(BUILD_SHARED_LIB) -eq 1 ] ; then \
		echo "Installing $(SHARED_LIB_NAME) ... in $(SDKLIBD)"; \
                [ -d $(SDKLIBD) ] || mkdir -p $(SDKLIBD); \
		$(CP) $(SHARED_LIB) $(SDKLIBD); \
		fi \
	fi

incstuff:
	@echo "Installing $(LIBNAME) include files in $(INCD) ..."
	-@mkdir -p $(INCD)
	-@mkdir -p $(INCD)/libxml
	@for f in $(LIBXMLHDRS) ; do \
		$(CP) include/libxml/$$f $(INCD)/libxml/$$f ; \
	done

shareinc:
	@if [ "$(SHAREROOT)" = "" -o ! -d "$(SHAREROOT)" ] ; then \
		echo "SHAREROOT not set or doesn't exist" ;\
		exit 1;\
	fi
	@echo "Installing headers into $(SHAREINC_DIR)/zephyr/libxml)"
	@$(CPS) $(patsubst %.h, include/libxml/%.h, $(LIBXMLHDRS)) $(SHAREINC_DIR)/zephyr/libxml

sharelib: release
	@echo "Installing libs into $(SHARELIBD)"
#	@$(CPS) $(SHARELIBD)
	@$(CPS) $(SHARED_LIB) $(SHARELIBD)/shared

relinstall:

lint: $(LINTOBJS)

release: installlibs incstuff

clean: 
	$(RM) $(CLEANLIST) $(SHARED_LIB) core *.bak
	rm -rf ./obj/*

ifneq ($(DEPS),)
-include $(DEPS)
endif
ifdef COMMONRULES
include $(COMMONRULES)
endif
