include ../config
ifeq ($(FULLUNIX)$(HAS_NROFF),ny)
all: datadir.txt bed.txt
else
all: datadir.txt bed.1.gz
endif
GLOBALCONFIG=$(shell echo '$(GLOBALCONFFILE)'| sed -e 's/\//\\\//g' )
PERSCONFIG=$(shell echo '$(PERSCONFFILE)'| sed -e 's/\//\\\//g' )
CONFDIRLINKER=$(shell echo '$(CONFDIRLINK)'| sed -e 's/\//\\\//g' )

bed.txt: bed.1 Makefile
	nroff -mandoc bed.1|sed 's/.//g' > bed.txt
datadir.txt: .datadir.txt ../.common.txt
	cat .datadir.txt > datadir.txt
	sed 's/CONFDIRLINK/$(CONFDIRLINKER)/g' < ../.common.txt >>datadir.txt
install:
	$(MKDIR)  $(ROOTDIR)$(MANDIR)
ifeq ($(FULLUNIX),y)
	$(CP) bed.1.gz $(ROOTDIR)$(MANDIR)/$(PROGRAM).1.gz
	$(CP) xbed.1.gz $(ROOTDIR)$(MANDIR)/$(XPROGRAM).1.gz
	-chmod 0644 $(ROOTDIR)$(MANDIR)/$(XPROGRAM).1.gz $(ROOTDIR)$(MANDIR)/$(PROGRAM).1.gz
	-man -F bed 2>/dev/null >&2
else
	(test -s bed.txt && $(CP) bed.txt $(ROOTDIR)$(MANDIR)/$(PROGRAM).txt)|| $(CP) bed.1.gz $(ROOTDIR)$(MANDIR)/$(PROGRAM).1.gz
endif

realclean:
	-rm bed.txt bed.1 bed.1.gz procedures bed.1.in prehtml bed.html menu.html


bed.1: bed.1.in Makefile
	sed -e '{s/PROGRAM/$(PROGRAM)/g;s/VERSION/$(VERSION)/g;s/CONFDIRLINK/$(CONFDIRLINKER)/g;s/GLOBALCONFIG/$(GLOBALCONFIG)/g;s/PERSCONFIG/$(PERSCONFIG)/g;s/prockey \(\<[^ 	]*\>\)/Alt-t,d,\1/g; }' < bed.1.in > bed.1
oldbed.html: bed.1 
	man2html -M /cgi-bin/man2html bed.1|sed -e '{s/Content-type: text\/html//g;s/^.*Return to Main Contents.*$$//g;s/^Section: User Commands.*$$//g;s/<BODY>/<body text="#000000" bgcolor="#FFFFFF" link="#0000EF" vlink="#55188A" alink="#FF0000">/g;}' > oldbed.html 
menu.html:bed.html menustart menuend mkindex
	bash mkindex
view: bed.1
	nroff -mandoc bed.1|less
bed.1.gz:bed.1
	-rm bed.1.gz
	gzip -c bed.1 > bed.1.gz
bed.1.in2: bed.1.in2a bed.1.in2b
	cat bed.1.in2a > bed.1.in2
	../src/bed -h|sed -n -f options.sed  >> bed.1.in2
	cat bed.1.in2b >> bed.1.in2
bed.1.in: bed.1.in1 ../description bed.1.in2 procedures bed.1.inend
	sed -f ../src/chhelp < bed.1.in1 > bed.1.in
	sed -e 's/^[	 ]*//g' < ../description >> bed.1.in
	sed -f ../src/chhelp < bed.1.in2 >> bed.1.in
	cat procedures >> bed.1.in
	sed -f ../src/chhelp < bed.1.inend >> bed.1.in
bed.html: prehtml	html1.sed ../src/chhelp html3.sed
	cat prehtml|sed -e '{s/PROGRAM/$(PROGRAM)/g;s/VERSION/$(VERSION)/g;s/CONFDIRLINK/$(CONFDIRLINKER)/g;s/GLOBALCONFIG/$(GLOBALCONFIG)/g;s/PERSCONFIG/$(PERSCONFIG)/g;}' |man2html -M /cgi-bin/man2html|sed -f html1.sed |sed -f ../src/chhelp|sed -f html3.sed > bed.html
prehtml: bed.1.in1 ../description bed.1.in2 procedures bed.1.inend prehtml.sed
	cat bed.1.in1 > prehtml
	sed -e 's/^[	 ]*//g' < ../description >> prehtml
	cat  bed.1.in2  >> prehtml
	cat ../src/prehelpdata ../plugins/examples/plughelp ../plugins/examples/plugman |sed -f prehtml.sed >> prehtml
	cat bed.1.inend >>prehtml

procedures: ../plugins/examples/plugman ../src/helpdata ../src/todoc.sed
	cat ../src/helpdata ../plugins/examples/plugman |sed -f ../src/todoc.sed  > procedures

../plugins/examples/plugman:
	$(MAKE) -C../plugins/examples/ plugman
../src/helpdata:
	$(MAKE) -C ../src helpdata

try:
	sed -n -e 's/hallo/this\n\
is\n\
een\n\
zin/gp'
