VERSION=1.1.2.7
include Makefile.sets
LDFLAGS=

ARCHDIR=archives/
ARCHNAME=charconv-$(VERSION)

ARCHFILES=parse.cc parse.hh main.cc charsets.hh charsets.cc \
          entities.h unicode.cc charconv.cc \
          charmap.hh \
          Makefile.sets extrafiles.php COPYING README TODO progdesc.php \
          extrafiles.mak unicode/everything \
          unicode/Makefile unicode/index.html \
          unicode/table2h.cc unicode/charsets.mak

OBJS=main.o parse.o charsets.o unicode.o converters.a unicode/charsets.a
COBJS=charconv.o charsets.o unicode.o converters.a unicode/charsets.a

BINDIR=/usr/local/bin
INSTALL=install
INSTALLPROGS=charconv
SUBDIRS=unicode

all: main charconv

subdirs: $(SUBDIRS)
$(SUBDIRS):
	@$(MAKE) -C $@

unicode/charsets.hh: subdirs
unicode/converters.hh: subdirs
unicode/charsets.a: FORCE
	@$(MAKE) -C unicode charsets.a
unicode.o: unicode.cc unicode/converters.hh

# Uses $(VERSION)
charconv.o: Makefile

charconv: unicode/charsets.a $(COBJS)
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(COBJS)
main: unicode/charsets.a $(OBJS)
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJS)

extrafiles.mak: extrafiles.php unicode/everything Makefile
	- php -q "$<" > "$@".tmp && sort < "$@.tmp" | uniq > "$@"
	rm -f "$@".tmp

include extrafiles.mak

converters.a: $(CONVOBJS)
	ar -rc $@ $^
algoguesser: algoguesser.o
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^

include depfun.mak

clean:
	rm -f $(OBJS) main $(COBJS) charconv
	make -C unicode $@
distclean: clean
	make -C unicode $@
	rm -f extrafiles.mak
realclean: distclean
	rm -f *~ unicode/*~

FORCE: ;
.PHONY: clean distclean realclean \
        all \
        $(SUBDIRS) subdirs FORCE
