
PACKAGE = o3read
VERSION = 0.0.4

CC = gcc
CFLAGS = -Wall -ansi -pedantic -O -g
PREFIX = /usr/local
BINDIR = $(PREFIX)/bin
MANDIR = $(PREFIX)/man/man1
DOCS = COPYING INSTALL README TODO ChangeLog filformat.sxw
BINS = o3read o3totxt o3tohtml utf8tolatin1
SRCS = o3read.h main.c o3read.c o3totxt.c o3tohtml.c utf8tolatin1.c
MANS = o3read.1 o3tohtml.1 o3totxt.1 utf8tolatin1.1
ARCH=`uname -s`-`uname -m`
BINDISTDIR=/usr/local

all: $(BINS)

utf8tolatin1: utf8tolatin1.o
	$(CC) -o utf8tolatin1 utf8tolatin1.o

o3totxt: o3totxt.o o3read.o
	$(CC) -o o3totxt o3totxt.o o3read.o

o3tohtml: o3tohtml.o o3read.o
	$(CC) -o o3tohtml o3tohtml.o o3read.o

o3tosiag: o3tosiag.o o3read.o
	$(CC) -o o3tosiag o3tosiag.o o3read.o

o3read: main.o o3read.o
	$(CC) -o o3read main.o o3read.o

dist:
	rm -rf $(PACKAGE)-$(VERSION)
	mkdir $(PACKAGE)-$(VERSION)
	cp Makefile $(DOCS) $(MANS) $(SRCS) $(PACKAGE)-$(VERSION)
	tar cf - $(PACKAGE)-$(VERSION) | gzip > $(PACKAGE)-$(VERSION).tar.gz
	rm -rf $(PACKAGE)-$(VERSION)

strip: $(BINS)
	strip $(BINS)

install: $(BINS)
	mkdir -p $(BINDIR) $(MANDIR)
	cp $(BINS) $(BINDIR)
	cp $(MANS) $(MANDIR)

uninstall:
	cd $(BINDIR) && rm -f $(BINS)
	cd $(MANDIR) && rm -f $(MANS)

clean:
	rm -f *.o $(BINS) *~

nstest:
	unzip -p filformat.sxw content.xml|./o3tohtml|./utf8tolatin1>x.html
	netscape ./x.html

lytest:
	unzip -p filformat.sxw content.xml|./o3tohtml|./utf8tolatin1>x.html
	lynx ./x.html

binaries:
	rm -rf tmpinst
	make clean strip install PREFIX=`cd . && pwd`/tmpinst$(BINDISTDIR)
	(cd tmpinst && tar cf - .) | gzip > $(PACKAGE)-$(ARCH)-$(VERSION).tar.gz
	rm -rf tmpinst

tgz:
	rm -rf tmpinst
	make clean strip install PREFIX=`cd . && pwd`/tmpinst$(BINDISTDIR)
	cd tmpinst && makepkg ../$(PACKAGE)-$(ARCH)-$(VERSION).tgz

tgz2: binaries
	rm -rf builddir
	mkdir -p builddir
	mkdir builddir/install
	cp doinst.sh builddir/install
	(cd builddir; \
	tar zxf ../$(PACKAGE)-$(ARCH)-$(VERSION).tar.gz; \
	tar zcf ../$(PACKAGE)-$(ARCH)-$(VERSION).tgz)
	rm -rf builddir

rpm: tgz
	alien -r $(PACKAGE)-$(ARCH)-$(VERSION).tgz
