# Makefile for THE
#
# The variable 'srcdir' refers to the source-distribution, and can be set with
# the configure script by "--srcdir=DIR".
#

SHELL		= /bin/sh
THIS		= Makefile

@SET_MAKE@

VERSION=@VERSION@
VERSION_UNQUOTED=@VERSION_UNQUOTED@
VERSION_BASE_UNQUOTED=@VERSION_BASE_UNQUOTED@
VERSION_NODOT=@VERSION_NODOT@
VER_DATE=@VER_DATE@
THE_DIR=@FULL_PACKAGE_NAME@
PACKAGE_RELEASE=@PACKAGE_RELEASE@

srcdir		= @srcdir@
abs_srcdir		= @abs_srcdir@
prefix		= @prefix@
target		= @target@
exec_prefix	= @exec_prefix@
libdir		= @libdir@
bindir		= @bindir@
includedir		= @includedir@
mandir		= @mandir@
datarootdir		= @datarootdir@
datadir		= @datadir@
docdir		= @docdir@

srcdocdir		= $(srcdir)/doc
imagedir		= $(srcdir)/images
contribdir		= $(srcdir)/contrib
thisdir		=@thisdir@
packagesdir = @packagesdir@
rpmtopdir =   @rpmtopdir@
debtopdir =   @debtopdir@
apktopdir = @apktopdir@

INSTALL		= $(srcdir)/install-sh

HTML_EXT		= @HTML_EXT@

CC		= @CC@
CFLAGS		= @CFLAGS@
LIBS		= @LIBS@
DEBUG =            @DEBUG@
DEBUGGING =        @DEBUGGING@

BASE_INSTALL = @BASE_INSTALL@
BASE_BINARY = @BASE_BINARY@
THEBIN = @THEBIN@
THETYPE = @THETYPE@
MYDISTRO=@MYDISTRO@
MACH_ARCH=@MACH_ARCH@
REXX_BUILD = @REXX_BUILD@
CURSES_BUILD = @CURSES_BUILD@
CURSES_INC_DIR_BUILD = @CURSES_INC_DIR_BUILD@
CURSES_LIB_DIR_BUILD = @CURSES_LIB_DIR_BUILD@

INCDIR		= $(srcdir)
CPPFLAGS	= -I. -I$(INCDIR) -I$(contribdir) $(DEBUG) @DEFS@ @SYS_DEFS@ -DTHE_HOME_DIRECTORY=\"$(datadir)/@THE_PACKAGE_NAME@/\"

CCFLAGS		= -c $(CFLAGS) $(CPPFLAGS) @MH_CURSES_INC@ @REXX_INCLUDES@ @WIDE_CHAR@

LINK		= @PURIFY@ $(CC)
LDFLAGS		= @EEXTRA@ $(DEBUGGING) @LDFLAGS@ @MH_CURSES_LIB@ @REXX_LIBS@ $(LIBS) @MH_EXTRA_LIBS@ @EFENCE@
THELDFLAGS		= @EEXTRA@ $(DEBUGGING) @LDFLAGS@ $(LIBS) @MH_EXTRA_LIBS@ @EFENCE@

################################################################################

COMM = \
 $(srcdir)/comm1.c \
 $(srcdir)/comm2.c \
 $(srcdir)/comm3.c \
 $(srcdir)/comm4.c \
 $(srcdir)/comm5.c

COMMSOS = \
 $(srcdir)/commsos.c

COMMSET = \
 $(srcdir)/commset1.c \
 $(srcdir)/commset2.c

QUERY = $(srcdir)/query.c

APPENDIX1 = $(srcdir)/appendix.1
APPENDIX2 = $(srcdir)/appendix.2
APPENDIX3 = $(srcdir)/appendix.3
APPENDIX4 = $(srcdir)/appendix.4
APPENDIX7 = $(srcdir)/appendix.7
APPENDIX = $(APPENDIX1) $(APPENDIX2) $(APPENDIX3) $(APPENDIX4) $(APPENDIX7)

GLOSSARY = $(srcdir)/glossary
OVERVIEW = $(srcdir)/overview

H0=	./config.h $(srcdir)/regex.h
H1=	./config.h $(srcdir)/the.h $(srcdir)/vars.h $(srcdir)/thedefs.h $(srcdir)/proto.h
H2=	./config.h $(srcdir)/the.h $(srcdir)/vars.h $(srcdir)/command.h $(srcdir)/thedefs.h $(srcdir)/proto.h $(srcdir)/getch.h $(srcdir)/key.h
H3=	./config.h $(srcdir)/getch.h $(srcdir)/vars.h $(srcdir)/thedefs.h $(srcdir)/proto.h
H4=	./config.h $(srcdir)/the.h $(srcdir)/vars.h $(srcdir)/query.h $(srcdir)/thedefs.h $(srcdir)/proto.h
H5=	./config.h $(srcdir)/the.h $(srcdir)/vars.h $(srcdir)/thematch.h
H6=	./config.h $(srcdir)/the.h $(srcdir)/vars.h $(srcdir)/directry.h $(srcdir)/thedefs.h $(srcdir)/proto.h
H7=	./config.h $(srcdir)/the.h $(srcdir)/vars.h $(srcdir)/therexx.h $(srcdir)/proto.h $(srcdir)/thedefs.h $(srcdir)/query.h
H8=	./config.h $(srcdir)/the.h $(srcdir)/vars.h $(srcdir)/therexx.h $(srcdir)/thedefs.h

ARCHIVE_FILES = \
 ./README ./INSTALL ./FAQ ./TODO ./COPYING ./HISTORY ./THE_Help.txt \
 ./overview ./appendix.1 ./appendix.2 ./appendix.3 ./appendix.4 ./appendix.7 ./glossary ./README.OS2 ./README.Amiga \
 ./box.c ./colour.c ./comm*.c ./cursor.c ./default.c ./directry.c ./execthe.c \
 ./edit.c ./error.c ./scroll.c ./column.c ./execute.c ./print.c ./alloca.c \
 ./file.c ./thematch.c ./getch.c ./mygetopt.c ./linked.c ./mouse.c ./memory.c \
 ./nonansi.c ./os2eas.c ./prefix.c ./query.c ./query2.c ./query1.c ./reserved.c ./parser.c ./regex.c \
 ./rexx.c ./show.c ./single.c ./sort.c ./target.c ./the.c ./trace.c ./util.c \
 ./command.h ./thedefs.h ./directry.h ./thematch.h ./getch.h ./vars.h ./regex.h ./mygetopt.h \
 ./key.h ./query.h ./proto.h ./therexx.h ./the.h ./contrib/*.c ./contrib/*.h \
 ./manext.c ./*.rsp ./*.def ./*.diz ./files.rcs ./the*.xbm \
 ./*.ico ./the.res ./*.rc ./the.eas ./doc/THE_Help* ./doc/*.htm ./doc/*.the ./doc/*.gif \
 ./append.the ./comm.the ./uncomm.the ./total.the ./match.the ./rm.the ./build.the ./setbuild.the ./nl.the \
 ./words.the ./l.the ./compile.the ./spell.the ./demo.the ./demo.txt ./cua.the ./config.the ./tags.the \
 ./codecomp.the ./syntax.the ./complete.the ./diff.the \
 ./the.nsi ./the.ver \
 ./*.mak ./*.tld ./thedit.lnk ./the.1 \
 ./common/config.guess ./common/config.sub ./install-sh \
 ./aclocal.m4 ./configure.in ./common/accommon.m4 ./common/*.nsh \
 ./Makefile.in ./config.h.in ./configure \
 ./man2html.rex ./man2hv.rex ./makehtml.rex ./makehv.rex ./makedist.cmd ./tld2c.rex \
 ./THE*.spec ./the64.xpm ./images/*.png ./images/*.bmp ./descrip.mms ./build.com \
 ./syntax/*.syntax \
 ./pkgconfig/*.pc ./pkgconfig/README \
 ./fixdebian.rexx \
 ./APKBUILD.in \
 ./haiku/PackageInfo*.in \
 ./debian/compat ./debian/control.in ./debian/copyright ./debian/rules.in ./debian/changelog \
 ./debian/prerm ./debian/postinst

################################################################################
all:	$(THEBIN) the the.man THE_Help.txt html helpviewer

the.man:	manext $(OVERVIEW) $(COMM) $(COMMSOS) $(COMMSET) $(QUERY) $(APPENDIX) $(GLOSSARY)
	-chmod u+w *
	-cp $(srcdocdir)/* .
	./manext $(OVERVIEW) $(COMM) $(COMMSOS) $(COMMSET) $(QUERY) $(APPENDIX) $(GLOSSARY) > the.man

THE_Help.txt:	manext $(COMM) $(COMMSET) $(COMMSOS) $(srcdocdir)/THE_Help_head $(srcdocdir)/THE_Help_set $(srcdocdir)/THE_Help_sos $(srcdocdir)/THE_Help_tail
	-chmod u+w *
	-cp $(srcdocdir)/* .
	echo "                         THE Quick Reference" > THE_Help_part01
	echo "                             Version $(VERSION)" > THE_Help_part02
	cp THE_Help_head THE_Help_part03
	./manext -q $(COMM) > THE_Help_part04
	cp THE_Help_set THE_Help_part05
	./manext -q $(COMMSET) > THE_Help_part06
	cp THE_Help_sos THE_Help_part07
	./manext -q $(COMMSOS) > THE_Help_part08
	cp THE_Help_tail THE_Help_part09
	cat THE_Help_part?? > THE_Help.txt
	rm -f THE_Help_*

doc/html:
	mkdir -p doc/html

html:	manext doc/html doc/html/index.html

doc/html/index.html: $(srcdir)/*.c $(APPENDIX) $(GLOSSARY) $(OVERVIEW)
#	-rm -fr *$(HTML_EXT) *.man
	cp $(imagedir)/the64.png .
	rexx $(srcdir)/makehtml.rex src=$(srcdir) ext=$(HTML_EXT) ver=$(VERSION) dest=./doc/html doc=$(srcdocdir) \
		overview=$(OVERVIEW)  \
		comm=$(COMM)      \
		commset=$(COMMSET)   \
		commsos=$(COMMSOS)   \
		query=$(QUERY)     \
		glossary=$(GLOSSARY)  \
		appendix1=$(APPENDIX1) \
		appendix2=$(APPENDIX2) \
		appendix3=$(APPENDIX3) \
		appendix4=$(APPENDIX4) \
		appendix7=$(APPENDIX7)

doc/helpviewer:
	mkdir -p doc/helpviewer

helpviewer: manext doc/helpviewer doc/helpviewer/index.html

doc/helpviewer/index.html: $(srcdir)/*.c $(APPENDIX) $(GLOSSARY) $(OVERVIEW)
#	-rm -f *$(HTML_EXT) *.man comm/* commsos/* commset/* misc/*
	cp $(imagedir)/the64.png .
	rexx $(srcdir)/makehv.rex src=$(srcdir) ext=$(HTML_EXT) ver=$(VERSION) dest=./doc/helpviewer doc=$(srcdocdir) \
		overview=$(OVERVIEW)  \
		comm=$(COMM)      \
		commset=$(COMMSET)   \
		commsos=$(COMMSOS)   \
		query=$(QUERY)     \
		glossary=$(GLOSSARY)  \
		appendix1=$(APPENDIX1) \
		appendix2=$(APPENDIX2) \
		appendix3=$(APPENDIX3) \
		appendix4=$(APPENDIX4) \
		appendix7=$(APPENDIX7)

doc/combined:
	mkdir -p doc/combined

combined: doc/combined
	-rm -fr doc/combined/*$(HTML_EXT) doc/combined/*.man doc/combined/comm/* doc/combined/commsos/* doc/combined/commset/* doc/combined/misc/*
	cp $(imagedir)/the64.png doc/combined
	rexx $(srcdir)/makehtml.rex src=$(srcdir) ext=$(HTML_EXT) ver=$(VERSION) dest=doc/combined doc=$(srcdocdir) \
		overview=$(OVERVIEW)  \
		comm=$(COMM)      \
		commset=$(COMMSET)   \
		commsos=$(COMMSOS)   \
		query=$(QUERY)     \
		glossary=$(GLOSSARY)  \
		appendix1=$(APPENDIX1) \
		appendix2=$(APPENDIX2) \
		appendix3=$(APPENDIX3) \
		appendix4=$(APPENDIX4) \
		appendix7=$(APPENDIX7)
	./$(THEBIN) -w 15000 -b -p $(srcdocdir)/preparecomb.the \
		doc/combined/index$(HTML_EXT) \
		doc/combined/overview$(HTML_EXT) \
		doc/combined/comm$(HTML_EXT) \
		doc/combined/commset$(HTML_EXT) \
		doc/combined/commsos$(HTML_EXT) \
		doc/combined/query$(HTML_EXT) \
		doc/combined/glossary$(HTML_EXT) \
		doc/combined/app1$(HTML_EXT) \
		doc/combined/app2$(HTML_EXT) \
		doc/combined/app3$(HTML_EXT) \
		doc/combined/app4$(HTML_EXT) \
		doc/combined/app5$(HTML_EXT) \
		doc/combined/app6$(HTML_EXT) \
		doc/combined/app7$(HTML_EXT) \
		doc/combined/history$(HTML_EXT) \
		doc/combined/quickref$(HTML_EXT) \
		doc/combined/fdl$(HTML_EXT)
	cat doc/combined/index$(HTML_EXT).new \
		doc/combined/overview$(HTML_EXT).new \
		doc/combined/comm$(HTML_EXT).new \
		doc/combined/commset$(HTML_EXT).new \
		doc/combined/commsos$(HTML_EXT).new \
		doc/combined/query$(HTML_EXT).new \
		doc/combined/glossary$(HTML_EXT).new \
		doc/combined/app1$(HTML_EXT).new \
		doc/combined/app2$(HTML_EXT).new \
		doc/combined/app3$(HTML_EXT).new \
		doc/combined/app4$(HTML_EXT).new \
		doc/combined/app5$(HTML_EXT).new \
		doc/combined/app6$(HTML_EXT).new \
		doc/combined/app7$(HTML_EXT).new \
		doc/combined/history$(HTML_EXT).new \
		doc/combined/quickref$(HTML_EXT).new \
		doc/combined/fdl$(HTML_EXT)> \
		doc/combined/the-$(VERSION)$(HTML_EXT).save
	rm -f doc/combined/*.new doc/combined/*.man doc/combined/*.html
	mv doc/combined/the-$(VERSION)$(HTML_EXT).save doc/combined/the-$(VERSION)$(HTML_EXT)

doc/pdf:
	mkdir -p doc/pdf

pdf: doc/pdf
	-rm -fr doc/pdf/*$(HTML_EXT) doc/pdf/*.man doc/pdf/comm/* doc/pdf/commsos/* doc/pdf/commset/* doc/pdf/misc/*
	cp $(srcdocdir)/*.gif doc/pdf
	cp $(srcdocdir)/title.htm doc/pdf/title$(HTML_EXT)
	rexx $(srcdir)/makehtml.rex src=$(srcdir) ext=$(HTML_EXT) ver=$(VERSION) dest=doc/pdf doc=$(srcdocdir) \
		overview=$(OVERVIEW)  \
		comm=$(COMM)      \
		commset=$(COMMSET)   \
		commsos=$(COMMSOS)   \
		query=$(QUERY)     \
		glossary=$(GLOSSARY)  \
		appendix1=$(APPENDIX1) \
		appendix2=$(APPENDIX2) \
		appendix3=$(APPENDIX3) \
		appendix4=$(APPENDIX4) \
		appendix7=$(APPENDIX7)
	./$(THEBIN) -w 15000 -b -p $(srcdocdir)/preparecomb.the -a "pdf $(VERSION)" \
		doc/pdf/title$(HTML_EXT) \
		doc/pdf/overview$(HTML_EXT) \
		doc/pdf/comm$(HTML_EXT) \
		doc/pdf/commset$(HTML_EXT) \
		doc/pdf/commsos$(HTML_EXT) \
		doc/pdf/query$(HTML_EXT) \
		doc/pdf/glossary$(HTML_EXT) \
		doc/pdf/app1$(HTML_EXT) \
		doc/pdf/app2$(HTML_EXT) \
		doc/pdf/app3$(HTML_EXT) \
		doc/pdf/app4$(HTML_EXT) \
		doc/pdf/app5$(HTML_EXT) \
		doc/pdf/app6$(HTML_EXT) \
		doc/pdf/app7$(HTML_EXT) \
		doc/pdf/history$(HTML_EXT) \
		doc/pdf/quickref$(HTML_EXT) \
		doc/pdf/fdl$(HTML_EXT) title$(HTML_EXT)
	-htmldoc -v --firstpage p1 --titlefile doc/pdf/title$(HTML_EXT).new --compression=9 --bodycolor "#FFFFFF" --size universal -f doc/pdf/the-$(VERSION).pdf doc/pdf/overview$(HTML_EXT).new doc/pdf/comm$(HTML_EXT).new doc/pdf/commset$(HTML_EXT).new doc/pdf/commsos$(HTML_EXT).new doc/pdf/query$(HTML_EXT).new doc/pdf/glossary$(HTML_EXT).new doc/pdf/app1$(HTML_EXT).new doc/pdf/app2$(HTML_EXT).new doc/pdf/app3$(HTML_EXT).new doc/pdf/app4$(HTML_EXT).new doc/pdf/app5$(HTML_EXT).new doc/pdf/app6$(HTML_EXT).new doc/pdf/app7$(HTML_EXT).new doc/pdf/history$(HTML_EXT).new doc/pdf/quickref$(HTML_EXT).new doc/pdf/fdl$(HTML_EXT).new
	rm -f doc/pdf/*.new doc/pdf/*.man doc/pdf/*.html doc/pdf/*.gif

website: helpviewer
	-mkdir images
	-cp $(srcdir)/images/*.png images
	-rm thedoc*.zip
	zip -r thedoc$(VERSION_NODOT) index.html images comm commset commsos misc

perminstall:
	-chmod u+x $(INSTALL)

install: perminstall $(BASE_INSTALL) installbinary

uninstall: un$(BASE_INSTALL)

installbase: the the.man THE_Help.txt installrpm installcommon

uninstallbase: uninstallrpm uninstalldoc uninstallcommon

installrpm: perminstall $(THEBIN)
	$(INSTALL) -m 755 -d $(DESTDIR)$(bindir)
#	$(INSTALL) -m 755 -c ./the $(DESTDIR)$(bindir)/the
	$(INSTALL) -m 755 -c $(THEBIN) $(DESTDIR)$(bindir)/$(THEBIN)

uninstallrpm: $(THEBIN)
	-rm -f $(DESTDIR)$(bindir)/the
	-rm -f $(DESTDIR)$(bindir)/$(THEBIN)
	-rmdir $(DESTDIR)$(bindir)

installbinary: $(THEBIN)
	$(INSTALL) -m 755 -d $(DESTDIR)$(bindir)
	$(INSTALL) -m 755 -c ./$(THEBIN) $(DESTDIR)$(bindir)/$(THEBIN)

#installdoc: the.man THE_Help.txt html helpviewer
installdoc:
	-$(INSTALL) -m 755 -d $(DESTDIR)$(docdir)
	-$(INSTALL) -c -m 644 $(srcdir)/images/the64.png $(DESTDIR)$(docdir)/the64.png
	for a in doc/html/*.html; do \
		bn=`basename $$a`; \
		$(INSTALL) -m 644 -c $$a $(DESTDIR)$(docdir)/$$bn; \
	done;

installcommon: perminstall the
	$(INSTALL) -m 755 -d $(DESTDIR)$(bindir)
	$(INSTALL) -m 755 -c ./the $(DESTDIR)$(bindir)/the
	$(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/man1
	$(INSTALL) -m 644 -c $(srcdir)/the.1        $(DESTDIR)$(mandir)/man1/the.1
	gzip -f $(DESTDIR)$(mandir)/man1/the.1
	$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/the
	$(INSTALL) -m 644 -c ./THE_Help.txt         $(DESTDIR)$(datadir)/the/THE_Help.txt
	$(INSTALL) -m 644 -c $(srcdir)/append.the   $(DESTDIR)$(datadir)/the/append.the
	$(INSTALL) -m 644 -c $(srcdir)/comm.the     $(DESTDIR)$(datadir)/the/comm.the
	$(INSTALL) -m 644 -c $(srcdir)/build.the    $(DESTDIR)$(datadir)/the/build.the
	$(INSTALL) -m 644 -c $(srcdir)/uncomm.the   $(DESTDIR)$(datadir)/the/uncomm.the
	$(INSTALL) -m 644 -c $(srcdir)/total.the    $(DESTDIR)$(datadir)/the/total.the
	$(INSTALL) -m 644 -c $(srcdir)/match.the    $(DESTDIR)$(datadir)/the/match.the
	$(INSTALL) -m 644 -c $(srcdir)/rm.the       $(DESTDIR)$(datadir)/the/rm.the
	$(INSTALL) -m 644 -c $(srcdir)/nl.the       $(DESTDIR)$(datadir)/the/nl.the
	$(INSTALL) -m 644 -c $(srcdir)/words.the    $(DESTDIR)$(datadir)/the/words.the
	$(INSTALL) -m 644 -c $(srcdir)/l.the        $(DESTDIR)$(datadir)/the/l.the
	$(INSTALL) -m 644 -c $(srcdir)/compile.the  $(DESTDIR)$(datadir)/the/compile.the
	$(INSTALL) -m 644 -c $(srcdir)/spell.the    $(DESTDIR)$(datadir)/the/spell.the
	$(INSTALL) -m 644 -c $(srcdir)/demo.the     $(DESTDIR)$(datadir)/the/demo.the
	$(INSTALL) -m 644 -c $(srcdir)/cua.the      $(DESTDIR)$(datadir)/the/cua.the
	$(INSTALL) -m 644 -c $(srcdir)/config.the   $(DESTDIR)$(datadir)/the/config.the
	$(INSTALL) -m 644 -c $(srcdir)/tags.the     $(DESTDIR)$(datadir)/the/tags.the
	$(INSTALL) -m 644 -c $(srcdir)/codecomp.the $(DESTDIR)$(datadir)/the/codecomp.the
	$(INSTALL) -m 644 -c $(srcdir)/complete.the $(DESTDIR)$(datadir)/the/complete.the
	$(INSTALL) -m 644 -c $(srcdir)/syntax.the   $(DESTDIR)$(datadir)/the/syntax.the
	$(INSTALL) -m 644 -c $(srcdir)/diff.the     $(DESTDIR)$(datadir)/the/diff.the
	for a in $(srcdir)/*.tld; do \
		bn=`basename $$a`; \
		$(INSTALL) -m 644 -c $$a $(DESTDIR)$(datadir)/the/$$bn; \
	done;
	for a in $(srcdir)/syntax/*.syntax; do \
		bn=`basename $$a`; \
		$(INSTALL) -m 644 -c $$a $(DESTDIR)$(datadir)/the/$$bn; \
	done;

uninstalldoc:

uninstallcommon:
	-rm -f $(DESTDIR)$(bindir)/the
	-rm -f $(DESTDIR)$(mandir)/man1/the.1.gz
	-rm -f $(DESTDIR)$(datadir)/the/THE_Help.txt
	-rm -f $(DESTDIR)$(datadir)/the/append.the
	-rm -f $(DESTDIR)$(datadir)/the/comm.the
	-rm -f $(DESTDIR)$(datadir)/the/build.the
	-rm -f $(DESTDIR)$(datadir)/the/uncomm.the
	-rm -f $(DESTDIR)$(datadir)/the/total.the
	-rm -f $(DESTDIR)$(datadir)/the/match.the
	-rm -f $(DESTDIR)$(datadir)/the/rm.the
	-rm -f $(DESTDIR)$(datadir)/the/nl.the
	-rm -f $(DESTDIR)$(datadir)/the/words.the
	-rm -f $(DESTDIR)$(datadir)/the/l.the
	-rm -f $(DESTDIR)$(datadir)/the/compile.the
	-rm -f $(DESTDIR)$(datadir)/the/spell.the
	-rm -f $(DESTDIR)$(datadir)/the/demo.the
	-rm -f $(DESTDIR)$(datadir)/the/cua.the
	-rm -f $(DESTDIR)$(datadir)/the/config.the
	-rm -f $(DESTDIR)$(datadir)/the/tags.the
	-rm -f $(DESTDIR)$(datadir)/the/codecomp.the
	-rm -f $(DESTDIR)$(datadir)/the/syntax.the
	-rm -f $(DESTDIR)$(datadir)/the/diff.the
	for a in $(srcdir)/*.tld; do \
		bn=`basename $$a`; \
		rm -f $(DESTDIR)$(datadir)/the/$$bn; \
	done;
	for a in $(srcdir)/syntax/*.syntax; do \
		bn=`basename $$a`; \
		rm -f $(DESTDIR)$(datadir)/the/$$bn; \
	done;
	-rmdir $(DESTDIR)$(datadir)/the

binary: $(BASE_BINARY)

binarybase: $(THEBIN) the the.man THE_Help.txt
	-rm -fr ./tmpdir
	$(INSTALL) -m 755 -d ./tmpdir/bin
	$(INSTALL) -m 755 -d ./tmpdir/man/man1
	$(INSTALL) -m 755 -d ./tmpdir/share/the
	$(INSTALL) -m 755 -c ./$(THEBIN) ./tmpdir/bin/$(THEBIN)
	$(INSTALL) -m 755 -c ./the ./tmpdir/bin/the
	$(INSTALL) -m 644 -c $(srcdir)/the.1 ./tmpdir/man/man1/the.1
	$(INSTALL) -m 644 -c ./THE_Help.txt ./tmpdir/share/the/THE_Help.txt
	$(INSTALL) -m 644 -c $(srcdir)/append.the   ./tmpdir/share/the/append.the
	$(INSTALL) -m 644 -c $(srcdir)/comm.the     ./tmpdir/share/the/comm.the
	$(INSTALL) -m 644 -c $(srcdir)/build.the    ./tmpdir/share/the/build.the
	$(INSTALL) -m 644 -c $(srcdir)/uncomm.the   ./tmpdir/share/the/uncomm.the
	$(INSTALL) -m 644 -c $(srcdir)/total.the    ./tmpdir/share/the/total.the
	$(INSTALL) -m 644 -c $(srcdir)/match.the    ./tmpdir/share/the/match.the
	$(INSTALL) -m 644 -c $(srcdir)/rm.the       ./tmpdir/share/the/rm.the
	$(INSTALL) -m 644 -c $(srcdir)/nl.the       ./tmpdir/share/the/nl.the
	$(INSTALL) -m 644 -c $(srcdir)/words.the    ./tmpdir/share/the/words.the
	$(INSTALL) -m 644 -c $(srcdir)/l.the        ./tmpdir/share/the/l.the
	$(INSTALL) -m 644 -c $(srcdir)/compile.the  ./tmpdir/share/the/compile.the
	$(INSTALL) -m 644 -c $(srcdir)/spell.the    ./tmpdir/share/the/spell.the
	$(INSTALL) -m 644 -c $(srcdir)/demo.the     ./tmpdir/share/the/demo.the
	$(INSTALL) -m 644 -c $(srcdir)/cua.the      ./tmpdir/share/the/cua.the
	$(INSTALL) -m 644 -c $(srcdir)/config.the   ./tmpdir/share/the/config.the
	$(INSTALL) -m 644 -c $(srcdir)/tags.the     ./tmpdir/share/the/tags.the
	$(INSTALL) -m 644 -c $(srcdir)/codecomp.the ./tmpdir/share/the/codecomp.the
	$(INSTALL) -m 644 -c $(srcdir)/complete.the ./tmpdir/share/the/complete.the
	$(INSTALL) -m 644 -c $(srcdir)/syntax.the   ./tmpdir/share/the/syntax.the
	$(INSTALL) -m 644 -c $(srcdir)/diff.the     ./tmpdir/share/the/diff.the
	for a in $(srcdir)/*.tld; do \
		bn=`basename $$a`; \
		$(INSTALL) -m 644 -c $$a ./tmpdir/share/the/$$bn; \
	done;
	for a in $(srcdir)/syntax/*.syntax; do \
		bn=`basename $$a`; \
		$(INSTALL) -m 644 -c $$a ./tmpdir/share/the/$$bn; \
	done;
	(cd ./tmpdir; \
	tar cvf - * | gzip > ../the-$(THETYPE)-@REXX_BUILD@-$(VERSION)-$(MACH_ARCH)-$(MYDISTRO).tgz )

cygwinbinary: the.exe the.man THE_Help.txt
	-rm -fr ./tmpdir
	$(INSTALL) -m 755 -d ./tmpdir/bin
	$(INSTALL) -m 755 -d ./tmpdir/man/man1
	$(INSTALL) -m 755 -d ./tmpdir/share/the
	$(INSTALL) -m 755 -c ./the.exe ./tmpdir/bin/the.exe
	$(INSTALL) -m 644 -c $(srcdir)/the.1 ./tmpdir/man/man1/the.1
	$(INSTALL) -m 644 -c ./THE_Help.txt ./tmpdir/share/the/THE_Help.txt
	$(INSTALL) -m 644 -c $(srcdir)/append.the   ./tmpdir/share/the/append.the
	$(INSTALL) -m 644 -c $(srcdir)/comm.the     ./tmpdir/share/the/comm.the
	$(INSTALL) -m 644 -c $(srcdir)/build.the    ./tmpdir/share/the/build.the
	$(INSTALL) -m 644 -c $(srcdir)/uncomm.the   ./tmpdir/share/the/uncomm.the
	$(INSTALL) -m 644 -c $(srcdir)/total.the    ./tmpdir/share/the/total.the
	$(INSTALL) -m 644 -c $(srcdir)/match.the    ./tmpdir/share/the/match.the
	$(INSTALL) -m 644 -c $(srcdir)/rm.the       ./tmpdir/share/the/rm.the
	$(INSTALL) -m 644 -c $(srcdir)/nl.the       ./tmpdir/share/the/nl.the
	$(INSTALL) -m 644 -c $(srcdir)/words.the    ./tmpdir/share/the/words.the
	$(INSTALL) -m 644 -c $(srcdir)/l.the        ./tmpdir/share/the/l.the
	$(INSTALL) -m 644 -c $(srcdir)/compile.the  ./tmpdir/share/the/compile.the
	$(INSTALL) -m 644 -c $(srcdir)/spell.the    ./tmpdir/share/the/spell.the
	$(INSTALL) -m 644 -c $(srcdir)/demo.the     ./tmpdir/share/the/demo.the
	$(INSTALL) -m 644 -c $(srcdir)/cua.the      ./tmpdir/share/the/cua.the
	$(INSTALL) -m 644 -c $(srcdir)/config.the   ./tmpdir/share/the/config.the
	$(INSTALL) -m 644 -c $(srcdir)/tags.the     ./tmpdir/share/the/tags.the
	$(INSTALL) -m 644 -c $(srcdir)/codecomp.the ./tmpdir/share/the/codecomp.the
	$(INSTALL) -m 644 -c $(srcdir)/complete.the ./tmpdir/share/the/complete.the
	$(INSTALL) -m 644 -c $(srcdir)/syntax.the   ./tmpdir/share/the/syntax.the
	$(INSTALL) -m 644 -c $(srcdir)/diff.the     ./tmpdir/share/the/diff.the
	for a in $(srcdir)/*.tld; do \
		bn=`basename $$a`; \
		$(INSTALL) -m 644 -c $$a ./tmpdir/share/the/$$bn; \
	done;
	for a in $(srcdir)/syntax/*.syntax; do \
		bn=`basename $$a`; \
		$(INSTALL) -m 644 -c $$a ./tmpdir/share/the/$$bn; \
	done;
	(cd ./tmpdir; \
	tar cvf - * | gzip > ../the-$(THETYPE)-$(VERSION)-$(target).tgz )

haikuinstall: all
	$(INSTALL) -m 755 -d $(DESTDIR)/bin
	$(INSTALL) -m 755 -d $(DESTDIR)/data/licenses
	$(INSTALL) -m 755 -d $(DESTDIR)/documentation/man/man1
	$(INSTALL) -m 755 -d $(DESTDIR)/data/@THE_PACKAGE_NAME@
	$(INSTALL) -m 755 -c ./the $(DESTDIR)/bin/the
	$(INSTALL) -m 744 -c $(srcdir)/the.1 $(DESTDIR)/documentation/man/man1/the.1
	$(INSTALL) -m 666 -c $(srcdir)/COPYING $(DESTDIR)/data/licenses/COPYING
	-mv $(DESTDIR)/data/licenses/COPYING "$(DESTDIR)/data/licenses/GNU GPL v2"
	$(INSTALL) -m 644 -c $(srcdir)/append.the   $(DESTDIR)/data/@THE_PACKAGE_NAME@/append.the
	$(INSTALL) -m 644 -c $(srcdir)/comm.the     $(DESTDIR)/data/@THE_PACKAGE_NAME@/comm.the
	$(INSTALL) -m 644 -c $(srcdir)/build.the    $(DESTDIR)/data/@THE_PACKAGE_NAME@/build.the
	$(INSTALL) -m 644 -c $(srcdir)/uncomm.the   $(DESTDIR)/data/@THE_PACKAGE_NAME@/uncomm.the
	$(INSTALL) -m 644 -c $(srcdir)/total.the    $(DESTDIR)/data/@THE_PACKAGE_NAME@/total.the
	$(INSTALL) -m 644 -c $(srcdir)/match.the    $(DESTDIR)/data/@THE_PACKAGE_NAME@/match.the
	$(INSTALL) -m 644 -c $(srcdir)/rm.the       $(DESTDIR)/data/@THE_PACKAGE_NAME@/rm.the
	$(INSTALL) -m 644 -c $(srcdir)/nl.the       $(DESTDIR)/data/@THE_PACKAGE_NAME@/nl.the
	$(INSTALL) -m 644 -c $(srcdir)/words.the    $(DESTDIR)/data/@THE_PACKAGE_NAME@/words.the
	$(INSTALL) -m 644 -c $(srcdir)/l.the        $(DESTDIR)/data/@THE_PACKAGE_NAME@/l.the
	$(INSTALL) -m 644 -c $(srcdir)/compile.the  $(DESTDIR)/data/@THE_PACKAGE_NAME@/compile.the
	$(INSTALL) -m 644 -c $(srcdir)/spell.the    $(DESTDIR)/data/@THE_PACKAGE_NAME@/spell.the
	$(INSTALL) -m 644 -c $(srcdir)/demo.the     $(DESTDIR)/data/@THE_PACKAGE_NAME@/demo.the
	$(INSTALL) -m 644 -c $(srcdir)/cua.the      $(DESTDIR)/data/@THE_PACKAGE_NAME@/cua.the
	$(INSTALL) -m 644 -c $(srcdir)/config.the   $(DESTDIR)/data/@THE_PACKAGE_NAME@/config.the
	$(INSTALL) -m 644 -c $(srcdir)/tags.the     $(DESTDIR)/data/@THE_PACKAGE_NAME@/tags.the
	$(INSTALL) -m 644 -c $(srcdir)/codecomp.the $(DESTDIR)/data/@THE_PACKAGE_NAME@/codecomp.the
	$(INSTALL) -m 644 -c $(srcdir)/complete.the $(DESTDIR)/data/@THE_PACKAGE_NAME@/complete.the
	$(INSTALL) -m 644 -c $(srcdir)/syntax.the   $(DESTDIR)/data/@THE_PACKAGE_NAME@/syntax.the
	$(INSTALL) -m 644 -c $(srcdir)/diff.the     $(DESTDIR)/data/@THE_PACKAGE_NAME@/diff.the
	for a in $(srcdir)/*.tld; do \
		bn=`basename $$a`; \
		$(INSTALL) -m 644 -c $$a $(DESTDIR)/data/@THE_PACKAGE_NAME@/$$bn; \
	done;
	for a in $(srcdir)/syntax/*.syntax; do \
		bn=`basename $$a`; \
		$(INSTALL) -m 644 -c $$a $(DESTDIR)/data/@THE_PACKAGE_NAME@/$$bn; \
	done;
	$(INSTALL) -m 644 -c ./haiku/PackageInfo $(DESTDIR)/.PackageInfo

haikuinstall-variant: all
	$(INSTALL) -m 755 -d $(DESTDIR)/data/licenses
	$(INSTALL) -m 755 -d $(DESTDIR)/bin
	$(INSTALL) -m 666 -c $(srcdir)/COPYING $(DESTDIR)/data/licenses/COPYING
	-mv $(DESTDIR)/data/licenses/COPYING "$(DESTDIR)/data/licenses/GNU GPL v2"
	$(INSTALL) -m 755 -c ./@THEBIN@ $(DESTDIR)/bin/@THEBIN@
	$(INSTALL) -m 644 -c ./haiku/PackageInfo-variant $(DESTDIR)/.PackageInfo

haikuinstall-doc: all
	$(INSTALL) -m 755 -d $(DESTDIR)/documentation/packages/$(THE_DIR)
	-$(INSTALL) -c -m 644 $(srcdir)/images/the64.png $(DESTDIR)/documentation/packages/$(THE_DIR)/the64.png
	for a in doc/html/*.html; do \
		bn=`basename $$a`; \
		$(INSTALL) -m 644 -c $$a $(DESTDIR)/documentation/packages/$(THE_DIR)/$$bn; \
	done;
	$(INSTALL) -m 644 -c ./haiku/PackageInfo-doc $(DESTDIR)/.PackageInfo

clean:
	-rm -f *.o trace $(THEBIN) the manext *.man *$(HTML_EXT) *.new config.log config.cache config.status

distclean: clean
	-rm -f Makefile

docclean:
	-rm -fr *.man *$(HTML_EXT) *.png *.new misc comm commset commsos images THE_Help* doc

mostlyclean: clean

realclean: distclean

#------------------------------------------------------------------------

XTRA_OBJS = @MH_XTRA_OBJS@ @ALLOCA@

OBJS =      \
	box.o      \
	colour.o   \
	column.o   \
	comm1.o    \
	comm2.o    \
	comm3.o    \
	comm4.o    \
	comm5.o    \
	commset1.o \
	commset2.o \
	commsos.o  \
	commutil.o \
	cursor.o   \
	default.o  \
	directry.o \
	edit.o     \
	error.o    \
	execute.o  \
	file.o     \
	thematch.o \
	getch.o    \
	linked.o   \
	mouse.o    \
	memory.o   \
	nonansi.o  \
	parser.o   \
	prefix.o   \
	print.o    \
	query.o    \
	query1.o   \
	query2.o   \
	regex.o    \
	reserved.o \
	rexx.o     \
	scroll.o   \
	show.o     \
	single.o   \
	sort.o     \
	target.o   \
	the.o      \
	mygetopt.o \
	util.o

the: execthe.o mygetopt.o
	$(LINK) execthe.o mygetopt.o -o the $(THELDFLAGS)

the-x11: $(OBJS) $(XTRA_OBJS)
	$(LINK) $(OBJS) $(XTRA_OBJS) -o the-x11 $(LDFLAGS)

the-x11w: $(OBJS) $(XTRA_OBJS)
	$(LINK) $(OBJS) $(XTRA_OBJS) -o the-x11w $(LDFLAGS)

the-con: $(OBJS) $(XTRA_OBJS)
	$(LINK) $(OBJS) $(XTRA_OBJS) -o the-con $(LDFLAGS)

the-conw: $(OBJS) $(XTRA_OBJS)
	$(LINK) $(OBJS) $(XTRA_OBJS) -o the-conw $(LDFLAGS)

the-sdl1: $(OBJS) $(XTRA_OBJS)
	$(LINK) $(OBJS) $(XTRA_OBJS) -o the-sdl1 $(LDFLAGS)

the-sdl2: $(OBJS) $(XTRA_OBJS)
	$(LINK) $(OBJS) $(XTRA_OBJS) -o the-sdl2 $(LDFLAGS)

the-sdl1w: $(OBJS) $(XTRA_OBJS)
	$(LINK) $(OBJS) $(XTRA_OBJS) -o the-sdl1w $(LDFLAGS)

the-sdl2w: $(OBJS) $(XTRA_OBJS)
	$(LINK) $(OBJS) $(XTRA_OBJS) -o the-sdl2w $(LDFLAGS)

box.o: $(srcdir)/box.c $(H1)
	$(CC) $(CCFLAGS) -o box.o $(srcdir)/box.c

colour.o: $(srcdir)/colour.c $(H1)
	$(CC) $(CCFLAGS) -o colour.o $(srcdir)/colour.c

column.o: $(srcdir)/column.c $(H1)
	$(CC) $(CCFLAGS) -o column.o $(srcdir)/column.c

comm1.o: $(srcdir)/comm1.c $(H1)
	$(CC) $(CCFLAGS) -o comm1.o $(srcdir)/comm1.c

comm2.o: $(srcdir)/comm2.c $(H1)
	$(CC) $(CCFLAGS) -o comm2.o $(srcdir)/comm2.c

comm3.o: $(srcdir)/comm3.c $(H1)
	$(CC) $(CCFLAGS) -o comm3.o $(srcdir)/comm3.c

comm4.o: $(srcdir)/comm4.c $(H1)
	$(CC) $(CCFLAGS) -o comm4.o $(srcdir)/comm4.c

comm5.o: $(srcdir)/comm5.c $(H1)
	$(CC) $(CCFLAGS) -o comm5.o $(srcdir)/comm5.c

commset1.o: $(srcdir)/commset1.c $(H1)
	$(CC) $(CCFLAGS) -o commset1.o $(srcdir)/commset1.c

commset2.o: $(srcdir)/commset2.c $(H1)
	$(CC) $(CCFLAGS) -o commset2.o $(srcdir)/commset2.c

commsos.o: $(srcdir)/commsos.c $(H1)
	$(CC) $(CCFLAGS) -o commsos.o $(srcdir)/commsos.c

commutil.o: $(srcdir)/commutil.c $(H2)
	$(CC) $(CCFLAGS) -o commutil.o $(srcdir)/commutil.c

cursor.o: $(srcdir)/cursor.c $(H1)
	$(CC) $(CCFLAGS) -o cursor.o $(srcdir)/cursor.c

default.o: $(srcdir)/default.c $(H1)
	$(CC) $(CCFLAGS) -o default.o $(srcdir)/default.c

directry.o: $(srcdir)/directry.c $(H6)
	$(CC) $(CCFLAGS) -o directry.o $(srcdir)/directry.c

edit.o: $(srcdir)/edit.c $(H1)
	$(CC) $(CCFLAGS) -o edit.o $(srcdir)/edit.c

error.o: $(srcdir)/error.c $(H1)
	$(CC) $(CCFLAGS) -o error.o $(srcdir)/error.c

execute.o: $(srcdir)/execute.c $(H1)
	$(CC) $(CCFLAGS) -o execute.o $(srcdir)/execute.c

file.o: $(srcdir)/file.c $(H6)
	$(CC) $(CCFLAGS) -o file.o $(srcdir)/file.c

thematch.o: $(srcdir)/thematch.c $(H5)
	$(CC) $(CCFLAGS) -o thematch.o $(srcdir)/thematch.c

getch.o: $(srcdir)/getch.c $(H3)
	$(CC) $(CCFLAGS) -o getch.o $(srcdir)/getch.c

mygetopt.o: $(srcdir)/mygetopt.c $(H1)
	$(CC) $(CCFLAGS) -o mygetopt.o $(srcdir)/mygetopt.c

linked.o: $(srcdir)/linked.c $(H1)
	$(CC) $(CCFLAGS) -o linked.o $(srcdir)/linked.c

mouse.o: $(srcdir)/mouse.c $(H1)
	$(CC) $(CCFLAGS) -o mouse.o $(srcdir)/mouse.c

memory.o: $(srcdir)/memory.c $(H1)
	$(CC) $(CCFLAGS) -o memory.o $(srcdir)/memory.c

nonansi.o: $(srcdir)/nonansi.c $(H1)
	$(CC) $(CCFLAGS) -o nonansi.o $(srcdir)/nonansi.c

parser.o: $(srcdir)/parser.c $(H1)
	$(CC) $(CCFLAGS) -o parser.o $(srcdir)/parser.c

os2eas.o: $(srcdir)/os2eas.c $(H1)
	$(CC) $(CCFLAGS) -o os2eas.o $(srcdir)/os2eas.c

prefix.o: $(srcdir)/prefix.c $(H1)
	$(CC) $(CCFLAGS) -o prefix.o $(srcdir)/prefix.c

print.o: $(srcdir)/print.c $(H1)
	$(CC) $(CCFLAGS) -o print.o $(srcdir)/print.c

query.o: $(srcdir)/query.c $(H4)
	$(CC) $(CCFLAGS) -o query.o $(srcdir)/query.c

query1.o: $(srcdir)/query1.c $(H4)
	$(CC) $(CCFLAGS) -o query1.o $(srcdir)/query1.c

query2.o: $(srcdir)/query2.c $(H4)
	$(CC) $(CCFLAGS) -o query2.o $(srcdir)/query2.c

regex.o: $(srcdir)/regex.c $(H0)
	$(CC) $(CCFLAGS) -o regex.o $(srcdir)/regex.c

reserved.o: $(srcdir)/reserved.c $(H1)
	$(CC) $(CCFLAGS) -o reserved.o $(srcdir)/reserved.c

rexx.o: $(srcdir)/rexx.c $(H7)
	$(CC) $(CCFLAGS) -o rexx.o $(srcdir)/rexx.c

scroll.o: $(srcdir)/scroll.c $(H1)
	$(CC) $(CCFLAGS) -o scroll.o $(srcdir)/scroll.c

show.o: $(srcdir)/show.c $(H1)
	$(CC) $(CCFLAGS) -o show.o $(srcdir)/show.c

single.o: $(srcdir)/single.c $(H1)
	$(CC) $(CCFLAGS) -o single.o $(srcdir)/single.c

sort.o: $(srcdir)/sort.c $(H1)
	$(CC) $(CCFLAGS) -o sort.o $(srcdir)/sort.c

target.o: $(srcdir)/target.c $(H1)
	$(CC) $(CCFLAGS) -o target.o $(srcdir)/target.c

the.o: $(srcdir)/the.c $(H1)
	$(CC) $(CCFLAGS) -DTHE_VERSION=\"$(VERSION)\" -DTHE_VERSION_DATE=\"$(VER_DATE)\" -o the.o $(srcdir)/the.c

trace.o: $(srcdir)/trace.c $(H1)
	$(CC) $(CCFLAGS) -o trace.o $(srcdir)/trace.c

util.o: $(srcdir)/util.c $(H1)
	$(CC) $(CCFLAGS) -o util.o $(srcdir)/util.c

alloca.o: $(srcdir)/alloca.c
	$(CC) $(CCFLAGS) -o alloca.o $(srcdir)/alloca.c

utf8.o: $(contribdir)/utf8.c $(H1)
	$(CC) $(CCFLAGS) -o utf8.o $(contribdir)/utf8.c

execthe.o: $(srcdir)/execthe.c $(H1)
	$(CC) $(CCFLAGS) -DTHE_VERSION=\"$(VERSION)\" -DTHE_VERSION_DATE=\"$(VER_DATE)\" -o execthe.o $(srcdir)/execthe.c


manext: manext.o
	$(LINK) manext.o -o manext

manext.o: $(srcdir)/manext.c $(srcdir)/the.h
	$(CC) $(CCFLAGS) -I$(srcdir) -o manext.o $(srcdir)/manext.c


packages_dir:
	-mkdir -p $(packagesdir)

zip:
	(cd $(srcdir); zip packages/thesrc$(VERSION_NODOT) $(ZIP_ARCHIVE_FILES) )

dist: packages_dir
	(cd $(srcdir);tar --exclude-vcs -cvf - --transform 's,^,$(THE_DIR)/,' $(ARCHIVE_FILES) | gzip > $(packagesdir)/$(THE_DIR).tar.gz )

bzip: packages_dir
	(cd $(srcdir);tar --exclude-vcs -cvf - --transform 's,^,$(THE_DIR)/,' $(ARCHIVE_FILES) | bzip2 > $(packagesdir)/$(THE_DIR).tar.bz2 )

tar:  packages_dir
	(cd $(srcdir);tar --exclude-vcs -cvf - --transform 's,^,$(THE_DIR)/,' $(ARCHIVE_FILES) | compress > $(packagesdir)/$(THE_DIR).tar.Z )

rpm: dist $(rpmtopdir)
	cp $(srcdir)/the64.xpm $(rpmtopdir)/SOURCES
	cp $(packagesdir)/$(THE_DIR).tar.gz $(rpmtopdir)/SOURCES
	-rm $(rpmtopdir)/RPMS/*/the-$(THETYPE)-@REXX_BUILD@-$(VERSION_UNQUOTED)-[0-9]*.rpm
	-rm $(rpmtopdir)/RPMS/*/the-common-$(VERSION_UNQUOTED)-[0-9]*.rpm
	-rm $(rpmtopdir)/RPMS/*/the-doc-$(VERSION_UNQUOTED)-[0-9]*.rpm
	rpmbuild -ba --clean --define "myversion $(VERSION_UNQUOTED)" --define "myrelease $(PACKAGE_RELEASE)" --define "myrexx @REXX_BUILD@" --define "mycurses @CURSES_BUILD@" --define "_topdir @rpmtopdir@" $(srcdir)/THE.spec
	rpmbuild -bs --clean --define "myversion $(VERSION_UNQUOTED)" --define "myrelease $(PACKAGE_RELEASE)" --define "myrexx none" --define "mycurses none" --define "_topdir @rpmtopdir@" $(srcdir)/THE.spec
	mv $(rpmtopdir)/RPMS/*/the-$(THETYPE)-@REXX_BUILD@-$(VERSION_UNQUOTED)-[0-9]*.rpm `dirname $(rpmtopdir)/RPMS/*/the-$(THETYPE)-@REXX_BUILD@-$(VERSION_UNQUOTED)-[0-9]*.rpm`/`basename $(rpmtopdir)/RPMS/*/the-$(THETYPE)-@REXX_BUILD@-$(VERSION_UNQUOTED)-[0-9]*.rpm .rpm`-$(MYDISTRO).rpm
	mv $(rpmtopdir)/RPMS/*/the-common-$(VERSION_UNQUOTED)-[0-9]*.rpm `dirname $(rpmtopdir)/RPMS/*/the-common-$(VERSION_UNQUOTED)-[0-9]*.rpm`/`basename $(rpmtopdir)/RPMS/*/the-common-$(VERSION_UNQUOTED)-[0-9]*.rpm .rpm`-$(MYDISTRO).rpm
	mv $(rpmtopdir)/RPMS/*/the-doc-$(VERSION_UNQUOTED)-[0-9]*.rpm `dirname $(rpmtopdir)/RPMS/*/the-doc-$(VERSION_UNQUOTED)-[0-9]*.rpm`/`basename $(rpmtopdir)/RPMS/*/the-doc-$(VERSION_UNQUOTED)-[0-9]*.rpm .rpm`-$(MYDISTRO).rpm
	ls -l $(rpmtopdir)/RPMS/*/the*rpm

srcrpm: dist $(rpmtopdir)
	cp $(srcdir)/../$(THE_DIR).tar.gz $(rpmtopdir)/SOURCES
	rpmbuild -ba --define "myversion $(VERSION_UNQUOTED)" --define "myrelease $(PACKAGE_RELEASE)" $(srcdir)/the-doc.spec

$(rpmtopdir):
	-mkdir -p $(rpmtopdir)/SOURCES
	-mkdir -p $(rpmtopdir)/SRPMS
	-mkdir -p $(rpmtopdir)/RPMS
	-mkdir -p $(rpmtopdir)/BUILD
	-mkdir -p $(rpmtopdir)/SPECS

$(debtopdir):
	-mkdir -p $(debtopdir)

deb: dist $(debtopdir)
	-rm -fr tmp
	-mkdir tmp
	(cd tmp; \
	tar zxvf $(packagesdir)/$(THE_DIR).tar.gz; \
	cd $(THE_DIR); \
	rexx ./fixdebian.rexx debian/rules.in debian/rules $(REXX_BUILD) $(CURSES_BUILD)  $(CURSES_INC_DIR_BUILD) $(CURSES_LIB_DIR_BUILD); \
	rexx ./fixdebian.rexx debian/control.in debian/control $(REXX_BUILD) $(CURSES_BUILD); \
	dpkg-buildpackage -rfakeroot; \
	cd ..; \
	mv the-$(THETYPE)-@REXX_BUILD@_$(VERSION_BASE_UNQUOTED)-[0-9]*.deb $(debtopdir)/`basename the-$(THETYPE)-@REXX_BUILD@_$(VERSION_BASE_UNQUOTED)-[0-9]*.deb .deb`-$(MYDISTRO).deb; \
	mv the-common_$(VERSION_BASE_UNQUOTED)-[0-9]*.deb $(debtopdir)/`basename the-common_$(VERSION_BASE_UNQUOTED)-[0-9]*.deb .deb`-$(MYDISTRO).deb; \
	mv the-doc_$(VERSION_BASE_UNQUOTED)-[0-9]*.deb $(debtopdir)/`basename the-doc_$(VERSION_BASE_UNQUOTED)-[0-9]*.deb .deb`-$(MYDISTRO).deb; )
	ls -l $(debtopdir)/*.deb

$(apktopdir):
	-mkdir -p $(apktopdir)

apk: dist $(apktopdir)
	cp $(packagesdir)/$(THE_DIR).tar.gz .
# we need to copy these files from the alpine directory even though they will be
# overridden by the scripts in APKBUILD because abuild expects them to be in the
# source directory as part of the pre-build sanity check
#	cp $(srcdir)/alpine/$(PACKAGE).post-install .
#	cp $(srcdir)/alpine/$(PACKAGE).pre-deinstall .
	abuild checksum
	abuild -P $(apktopdir)

hpkg:
# need to rename the config.h in the current directory as it seems to be used instead
# of the one generated by the following configure
	-mv config.h config.h.save
	-rm -fr $(packagesdir)/HPKG/build
	mkdir -p $(packagesdir)/HPKG/build/@THE_PACKAGE_NAME@_common
	mkdir -p $(packagesdir)/HPKG/build/@THE_PACKAGE_NAME@_@THECURSESTYPE@_@REXX_BUILD@
	mkdir -p $(packagesdir)/HPKG/build/@THE_PACKAGE_NAME@_doc
	(cd $(packagesdir)/HPKG/build;$(abs_srcdir)/configure --prefix=/boot/system --datarootdir=/boot/system/data --with-rexx=@REXX_BUILD@ --with-curses=@CURSES_BUILD@ ; \
	make DESTDIR=$(packagesdir)/HPKG/build/@THE_PACKAGE_NAME@_common haikuinstall; \
	make DESTDIR=$(packagesdir)/HPKG/build/@THE_PACKAGE_NAME@_@THECURSESTYPE@_@REXX_BUILD@ haikuinstall-variant; \
	make DESTDIR=$(packagesdir)/HPKG/build/@THE_PACKAGE_NAME@_doc haikuinstall-doc; )
	(cd $(packagesdir)/HPKG/build/@THE_PACKAGE_NAME@_common;package create ../../@THE_PACKAGE_NAME@-@VERSION_UNQUOTED@-1-@MACH_ARCH@.hpkg;)
	(cd $(packagesdir)/HPKG/build/@THE_PACKAGE_NAME@_doc;package create ../../@THE_PACKAGE_NAME@_doc-@VERSION_UNQUOTED@-1.hpkg;)
	(cd $(packagesdir)/HPKG/build/@THE_PACKAGE_NAME@_@THECURSESTYPE@_@REXX_BUILD@;package create ../../@THE_PACKAGE_NAME@_@THECURSESTYPE@_@REXX_BUILD@-@VERSION_UNQUOTED@-1-@MACH_ARCH@.hpkg;)
	-mv config.h.save config.h

check:
# dummy target for Alpine Linux build package; abuild -r
