# Testsuite makefile for GNU sed

srcdir=.
SED=LANG=LC_CTYPE=C LC_MESSAGES=C LANG=C ../sed/sed
#TIME=time
CMP=cmp
RM=rm -f

enable sep inclib 8bit 8to7 newjis xabcx dollar noeol \
numsub head madding mac-mf empty xbxcx recall xemacs \
fasts uniq manis linecnt khadafy allsub flipcase::
	$(TIME) $(SED) -f $(srcdir)/$@.sed \
		< $(srcdir)/$@.inp > $@.out 
	$(CMP) $(srcdir)/$@.good $@.out 
	@$(RM) $@.out 

# This checks for a bug in 3.02 and 3.02.80
stdin::
	$(TIME) ($(SED) d; $(SED) G) < $(srcdir)/numsub.inp > $@.1out 
	$(TIME) cat $(srcdir)/numsub.inp | ($(SED) d; $(SED) G) > $@.2out 
	$(CMP) $@.1out $@.2out 
	@$(RM) $@.1out $@.2out 

cv-vars middle dc distrib factor::
	$(TIME) $(SED) -n -f $(srcdir)/$@.sed < $(srcdir)/$@.inp > $@.out 
	$(CMP) $(srcdir)/$@.good $@.out 
	@$(RM) $@.out 

subwrite::
	$(TIME) $(SED) -f $(srcdir)/$@.sed < $(srcdir)/$@.inp > $@.1out 
	$(CMP) $(srcdir)/subwrt1.good $@.1out 
	$(CMP) $(srcdir)/subwrt2.good $@.wout
	@$(RM) $@.1out $@.wout

spencer::
	sh $(srcdir)/$@.sh $(SED) < $(srcdir)/$@.inp \
		| $(TIME) sh | grep failed; \
	test $$? = 1

writeout::
	$(TIME) $(SED) -f $(srcdir)/$@.sed < $(srcdir)/$@.inp >$@.1out 
	$(CMP) $(srcdir)/wrtout1.good $@.1out 
	$(CMP) $(srcdir)/wrtout2.good $@.wout
	@$(RM) $@.1out $@.wout

readin.in2: $(srcdir)/readin.in2
	cat $< > $@

readin:: readin.in2
	$(TIME) $(SED) -f $(srcdir)/$@.sed < $(srcdir)/$@.inp >$@.out 
	$(CMP) $(srcdir)/$@.good $@.out 
	@$(RM) $@.out 

eval.in2: $(srcdir)/eval.inp
	cat $< > $@

eval:: eval.in2
	$(TIME) $(SED) -f $(srcdir)/$@.sed < $(srcdir)/$@.inp > $@.out 
	$(CMP) $(srcdir)/$@.good $@.out 
	@$(RM) $@.out 

binary binary2 binary3::
	$(TIME) $(SED) -n -f $(srcdir)/$@.sed < $(srcdir)/binary.inp >$@.out 
	$(CMP) $(srcdir)/binary.good $@.out 
	@$(RM) $@.out 

#
# cmdlines targets
#

help::
	$(SED) --help | $(SED) '1s/ [^ ]* / sed /' > $@.1out 
	$(SED) -h | $(SED) '1s/ [^ ]* / sed /' > $@.2out 
	$(SED) 2>&1 | $(SED) '1s/ [^ ]* / sed /' > $@.3out || :
	$(CMP) $@.1out $@.2out 
	$(CMP) $@.2out $@.3out 
	@$(RM) $@.1out $@.2out $@.3out 

version::
	sed 's^@'VERSION'@^$(VERSION)^' $(srcdir)/version.gin > $@.out 
	$(SED) --version  > $@.1out 2>&1
	$(SED) -V > $@.2out 2>&1
	$(CMP) $@.out $@.1out 
	$(CMP) $@.out $@.2out 
	@$(RM) $@.out $@.1out $@.2out 

file::
	$(TIME) $(SED) --file=$(srcdir)/newjis.sed \
		< $(srcdir)/newjis.inp > $@.out 
	$(CMP) $(srcdir)/newjis.good $@.out 
	@$(RM) $@.out 

quiet::
	$(TIME) $(SED) --quiet -f $(srcdir)/cv-vars.sed \
		< $(srcdir)/cv-vars.inp > $@.out 
	$(CMP) $(srcdir)/cv-vars.good $@.out 
	@$(RM) $@.out 

# The following target is not used in GNU sed builds (only super-sed)

pcretest::
	$(TIME) ./pcretest $(srcdir)/pcre1.inp pcre1.out
	$(CMP) $(srcdir)/pcre1.good pcre1.out
	#$(TIME) ./pcretest -p $(srcdir)/pcre1.inp pcre1p.out
	#$(CMP) $(srcdir)/pcre1p.good pcre1p.out
	$(TIME) ./pcretest -P $(srcdir)/pcre2.inp pcre2.out
	$(CMP) $(srcdir)/pcre2.good pcre2.out
	$(TIME) ./pcretest -P -p $(srcdir)/pcre2.inp pcre2p.out
	$(CMP) $(srcdir)/pcre2p.good pcre2p.out
	$(TIME) ./pcretest $(srcdir)/pcre3.inp pcre3.out
	$(CMP) $(srcdir)/pcre3.good pcre3.out
	$(TIME) ./pcretest -p $(srcdir)/pcre3.inp pcre3p.out
	$(CMP) $(srcdir)/pcre3p.good pcre3p.out
	@$(RM) pcre*.out
