# $Id: Makefile.in,v 1.18 1997/04/13 09:11:40 dps Exp dps $
#
# My test system is Linux 2.1.30, gcc 2.7.2, libc 5.4.27

CC=@CC@
CPP=@CXX@

#seek_set_hdr is a hack for Sun OS (and others? I hope not)
CPPFLAGS=-g -Wall @DEFS@ @seek_set_hdr@
LD=@ld@

CCFLAGS=-O3 @DEFS@
LIBOBJS=wordwrap.o nullproc.o tblock.o scan_num.o map_chars.o col-align.o \
	compat.o num_unit_probe.o part_num_probe.o
AR=ar
RANLIB=@RANLIB@
MYLIBS=liboutfmt.a
READER=reader.o strip.o
FMTS=fmt-text.o fmt-latex.o fmt-html.o
DATEFMTS=dedate.o deL1date.o deHTMLdate.o ukdate.o usdate.o
#Set to gopt.o if you lack getopt_long
GETOPT=@getopt@
ALLOCA=@ALLOCA@
PROGOBJS=$(READER) word2x.o $(FMTS) $(DATEFMTS) $(GETOPT) $(ALLOCA) $(MYLIBS) 
TARGETS=word2x rtest2
MANP=word2x.1
prefix=@prefix@
exec_prefix=@exec_prefix@

%.o: %.cc
	$(CPP) $(CPPFLAGS) -c -o $@ $<

%.o: $.c $(CC) $(CCFLAGS) -c -o $@ $<

all:	config.h $(TARGETS)

config.h:	configure.in Makefile.in config.h.in
	./configure

configure: configure.in
	autoconf

Makefile: Makefile.in configure
	./configure

clean:
	rm -f *.o
	rm -f $(MYLIBS)

clobber: clean
	rm -f $(TARGETS)
	rm -f config.h Makefile
	rm -f config.cache config.status config.log *~
	rm -f cfg-script make-script

word2x.tar.gz: clobber configure config.h.in configure.in Makefile.in transcript
	chmod a-w configure
	tar -C .. -czf word2x.tar.gz word2x \
	    --exclude word2x/RCS --exclude word2x/word2x.tar.gz \
	    --exclude word2x/samples --exclude word2x/config.cache \
	    --exclude word2x/config.status --exclude word2x/config.log \
	    --exclude word2x/catdoc.c --exclude word2x/catdoc.msg \
	    --exclude word2x/config.h --exclude word2x/Makefile \
	    --exclude word2x/config.cache --exclude word2x/config.status \
	    --exclude word2x/config.log
	chmod 755 configure

transcript:  cfg-script make-script
	@echo "word2x build transcript" >transcript
	@echo "Note: the prompts are simulated. All the rest is real." >>transcript
	@echo "Simulation> ./configure" >>transcript
	@cat cfg-script >>transcript
	@echo "Simulation> make all" >>transcript
	@cat make-script >>transcript
	rm -f cfg-script make-script

cfg-script:
	@rm -f config.cache config.h
	./configure 2>&1 | tee cfg-script

make-script: config.h
	make all 2>&1 | tee make-script

liboutfmt.a: $(LIBOBJS)
	$(AR) rc $@ $(LIBOBJS)
	$(RANLIB) $@

rtest2:	rtest2.o $(READER) tblock.o
	g++ -o rtest2 rtest2.o $(READER) tblock.o

fmt-text.o: text-fmt.o text-table.o
	$(LD) -r -o $@ text-fmt.o text-table.o

fmt-latex.o: latex-fmt.o latex-table.o latex-embed.o
	$(LD) -r -o $@ latex-fmt.o latex-table.o latex-embed.o

fmt-html.o: html-fmt.o html-table.o html-embed.o
	$(LD) -r -o $@ html-fmt.o html-table.o html-embed.o

getopt.o: getopt.c
	$(CC) $(CFLAGS) -D_LIBC=1 -c -o $@ $<

getopt1.o: getopt1.c
	$(CC) $(CFLAGS) -D_LIBC=1 -c -o $@ $<

gopt.o: getopt.o getopt1.o
	$(LD) -r -o gopt.o getopt.o getopt1.o

word2x: $(PROGOBJS)
	$(CPP) -o $@ $(PROGOBJS)

install: $(TARGETS) $(MANP)
	@INSTALL@ $(MANP) -m 644 @mandir@/man1
	for I in $(TARGETS); do \
		@INSTALL@ $${I} -m 755 @bindir@; \
	done
