include Makefile.inc

# If you know what your system's byte order is, define XML_BYTE_ORDER:
# use -DXML_BYTE_ORDER=12 for little-endian byte order;
# use -DXML_BYTE_ORDER=21 for big-endian (network) byte order.
# -DXML_NS adds support for checking of lexical aspects of XML namespaces spec
# -DXML_MIN_SIZE makes a smaller but slower parser
# -DXML_DTD adds full support for parsing DTDs
CFLAGS+=--pipe -DXML_NS -DXML_DTD $(BYTE_ORDER)
INCLUDES+=-Ixmltok -Ixmlparse
# Use one of the next two lines; unixfilemap is better if it works.
FILEMAP_OBJ=xmlwf/unixfilemap.o
#FILEMAP_OBJ=xmlwf/readfilemap.o
# if you want to make the libraries and shlibs
MAKE_LIBS=true

ELF_SO_VERSION=1		# major library version
LIB_VERSION=1.2			# full library version
LIBS=xmltok/libxmltok.a xmlparse/libxmlparse.a
ELF_LIBS=xmltok/libxmltok.so.$(LIB_VERSION) \
  xmlparse/libxmlparse.so.$(LIB_VERSION)
ELF_OTHER_LIBS=-lc		# other libs to link shlib with
ELF_FLAGS=-fpic -D_REENTRANT	# flags for compiling shlibs

ifndef MAKE_LIBS
  OBJS=$(FILEMAP_OBJ) \
    xmlparse/xmlparse.o \
    xmltok/xmltok.o \
    xmltok/xmlrole.o \
    xmlwf/xmlwf.o \
    xmlwf/xmlfile.o \
    xmlwf/codepage.o
else
  OBJS=$(FILEMAP_OBJ) \
    xmlwf/xmlwf.o \
    xmlwf/xmlfile.o \
    xmlwf/codepage.o
  LIBS_TO_BUILD=$(ELF_LIBS) \
    $(LIBS)
endif

EXE=
XMLWF=xmlwf/xmlwf$(EXE)

# export these variables to sub-makes
export

all: $(XMLWF)

shlib-version:
	@echo $(LIB_VERSION)

$(XMLWF): $(OBJS) $(LIBS_TO_BUILD)
ifndef MAKE_LIBS
	$(CC) $(CFLAGS) $(INCLUDES) -o $@ $(OBJS)
else
	$(CC) $(CFLAGS) $(INCLUDES) -o $@ $(OBJS) -Lxmlparse -lxmlparse \
		-Lxmltok -lxmltok
endif

$(LIBS) $(ELF_LIBS):
	$(MAKE) -C$(dir $@) $(notdir $@)

clean:
	rm -f $(OBJS) $(XMLWF) gennmtab/gennmtab$(EXE)
ifdef MAKE_LIBS
	$(MAKE) -Cxmltok clean
	$(MAKE) -Cxmlparse clean
endif

xmltok/nametab.h: gennmtab/gennmtab$(EXE)
	rm -f $@
	gennmtab/gennmtab$(EXE) >$@

gennmtab/gennmtab$(EXE): gennmtab/gennmtab.c
	$(CC) $(CFLAGS) $(INCLUDES) -o $@ gennmtab/gennmtab.c

xmltok/xmltok.o: xmltok/nametab.h

.c.o:
	$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<

shared/%.o:	%.c
	$(CC) $(CFLAGS) $(INCLUDES) $(ELF_FLAGS) -c -o $@ $<

install:
ifdef MAKE_LIBS
	$(MAKE) -Cxmltok install
	$(MAKE) -Cxmlparse install
endif
