ROOT=..
CFLAGS = -Wall -g -I.. $(LIHATA_CFLAGS)
OBJS_PARSER = parser.o lihata.o
OBJS_DOM = hash_str.o dom.o dom_hash.o dom_list.o dom_table.o
OBJS_TREE = tree.o tree_list.o tree_hash.o tree_table.o tree_path.o tree_symlink.o
OBJS = test_parser.o test_dom.o test_tree.o  $(OBJS_PARSER) $(OBJS_DOM) $(OBJS_TREE)
TESTERS = test_parser test_dom test_tree
LIBS = liblihata.a
include $(ROOT)/Makefile.conf
LDLIBS=$(LIBGENHT)


all: $(TESTERS) $(LIBS)

test_parser: test_parser.o $(OBJS_PARSER) $(LIBGENHT_DEP)
	$(CC) $(LDFLAGS) test_parser.o $(OBJS_PARSER) $(LDLIBS) -o $@

test_dom: test_dom.o $(OBJS_DOM) $(OBJS_PARSER) $(LIBGENHT_DEP)
	$(CC) $(LDFLAGS) test_dom.o $(OBJS_DOM) $(OBJS_PARSER) $(LDLIBS) -o $@

test_tree: test_tree.o $(OBJS_TREE) $(OBJS_DOM) $(OBJS_PARSER) $(LIBGENHT_DEP)
	$(CC) $(LDFLAGS) test_tree.o $(OBJS_TREE) $(OBJS_DOM) $(OBJS_PARSER) $(LDLIBS) -o $@

liblihata.a: $(OBJS_DOM) $(OBJS_PARSER) $(OBJS_TREE)
	ar rvu $@ $(OBJS_DOM) $(OBJS_PARSER) $(OBJS_TREE)
	-ar s $@
	-ranlib $@


../genht/htsp.o:
	$(CC) $(CFLAGS) -c ../genht/htsp.c -o ../genht/htsp.o

# dependencies

include Makefile.dep

depend:
	@echo "# Generated by \"make depend\"" > Makefile.dep
	gcc $(CFLAGS) -MM `echo $(OBJS) | sed "s/\.o/.c/g"` | sed "s/^htsp.o.*//; s%[.][.]/genht/[a-zA-Z0-9_]*[.][hoc]%%g" >> Makefile.dep

ns: liblihata.a
	@echo Namespace pollution in objects:
	@nm liblihata.a | awk '/ [ABCDGNRSTVW] / { if (($$(NF) ~ "^lht_") || ($$(NF) ~ "^hts._")) next; print $$0}'

test:
	cd regression && make

clean:
	-rm $(OBJS) $(TESTERS) $(LIBS) 2>/dev/null

dist-clean: clean

install_:
	mkdir -p $(LIBDIR) $(INCDIR)
	$(CP) $(PWD)/liblihata.a $(LIBDIR)/liblihata.a
	$(CP) $(PWD)/dom.h $(INCDIR)/dom.h
	$(CP) $(PWD)/hash_str.h $(INCDIR)/hash_str.h
	$(CP) $(PWD)/lihata.h $(INCDIR)/lihata.h
	$(CP) $(PWD)/parser.h $(INCDIR)/parser.h
	$(CP) $(PWD)/tree.h $(INCDIR)/tree.h

uninstall:
	rm $(LIBDIR)/liblihata.a
	rm -rf $(INCDIR)

install:
	make install_ CP="cp" PWD=`pwd`

linstall:
	make install_ CP="ln -sf" PWD=`pwd`

include $(ROOT)/Makefile.common
