#
# Makefile for antiword (Solaris version)
#
# Original version by: Mark Leisher <mleisher@crl.NMSU.Edu>
# Based on a Makefile by: Gary Mills <mills@cc.UManitoba.CA>
#

CC	= gcc
LD	= gcc
INSTALL	= /usr/ucb/install

# must be equal to DEBUG or NDEBUG
DB	= NDEBUG
# Optimization: -O<n> or debugging: -g
OPT	= -O2

LDLIBS	=

CFLAGS	= $(OPT) -D$(DB) -D__STDC_ISO_10646__
LDFLAGS	=

OBJS	=\
	main_u.o asc85enc.o blocklist.o chartrans.o datalist.o depot.o\
	dib2eps.o doclist.o fail.o finddata.o findtext.o fmt_text.o fontlist.o\
	fonts.o fonts_u.o hdrftrlist.o imgexam.o imgtrans.o jpeg2eps.o\
	listlist.o misc.o notes.o options.o out2window.o output.o pdf.o\
	pictlist.o png2eps.o postscript.o prop0.o prop2.o prop6.o prop8.o\
	properties.o propmod.o rowlist.o sectlist.o stylelist.o stylesheet.o\
	summary.o tabstop.o text.o unix.o utf8.o word2text.o worddos.o\
	wordlib.o wordmac.o wordole.o wordwin.o xmalloc.o xml.o

PROGS =\
	antiword

LOCAL_INSTALL_DIR = $(HOME)/bin
LOCAL_RESOURCES_DIR = $(HOME)/.antiword

GLOBAL_INSTALL_DIR = /usr/local/bin
GLOBAL_RESOURCES_DIR = /usr/local/share/antiword
MAN_DIR = /usr/local/man/man1

all:		$(PROGS)

local_install:	all
	mkdir -p $(LOCAL_INSTALL_DIR)
	cp -pf $(PROGS) $(LOCAL_INSTALL_DIR)
	mkdir -p $(LOCAL_RESOURCES_DIR)
	cp -pf Resources/* $(LOCAL_RESOURCES_DIR)

# NOTE: you must be root to do this
install:	all
	$(INSTALL) -c -o bin -g bin -m 755 $(PROGS) $(GLOBAL_INSTALL_DIR)
	$(INSTALL) -c -o bin -g bin -m 644 Docs/antiword.1 $(MAN_DIR)
	$(INSTALL) -d -o bin -g bin -m 755 $(GLOBAL_RESOURCES_DIR)
	$(INSTALL) -c -o bin -g bin -m 644 Resources/*.txt $(GLOBAL_RESOURCES_DIR)
	$(INSTALL) -c -o bin -g bin -m 644 Resources/fontnames $(GLOBAL_RESOURCES_DIR)

clean:
	rm -f $(OBJS)
	rm -f $(PROGS)

antiword:	$(OBJS)
	@rm -f $@
	$(LD) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@
	@chmod 750 $@

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

main_u.o:	version.h
postscript.o:	version.h
pdf.o:		version.h
fonts_u.o:	fontinfo.h

fontinfo.h:	Unix-only/fontinfo.h
	cp -rp $? $@

Unix-only/fontinfo.h:	Unix-only/fontinfo.pl
	Unix-only/fontinfo.pl > Unix-only/fontinfo.h
