# Amiga Library Services - CD Administration Makefile

CONTENTSFMT =	"==========\n\n%N    %V    %S\n\n%d\n\nAuthor: %a\nArchive: %P\n\n"
QUICKREFFMT =	"%-12.12B %8.8V %9s  %-S\n"
TBBSFMT = "%-12.12B %9s %8.8T %-12.12B '' %-S\r\n"

# The order of these is significant.
BUILT_FILES =	CONTENTS.PI CONTENTS.TXT QUICKREF.TXT CONTENTS.LHA FILES.BBS TBBS.DIR

# The default thing to make.

all:

# This target will rebuild all the machine generated files, after you
# have done a "make clobber".

rebuild:
	@for i in *; \
	do \
		if test -d $$i; then \
			echo "Building $(BUILT_FILES) in $$i"; \
			(cd $$i; $(MAKE) -f ../AMIGALIB.MK $(BUILT_FILES)); \
		fi; \
	done

# Build a default FILES.BBS file.  Note that the -D flag turns on
# specific MS-DOS options, such as using MS-DOS BBS compatible format
# for the FILES.BBS file, and naming it all uppercase.  First we
# delete any existing FILES.BBS file, since the default is to append
# to the file.  Note we have to sort the file after creating it.
# The dependency on CONTENTS.PI is just to ensure that one always
# exists before building FILES.BBS.

FILES.BBS:	CONTENTS.PI
	rm -f $@
	find . -name '*.PI' -print | pitool -b -D -
	sort -f <$@ >/tmp/$@
	cp /tmp/$@ $@

# Build a default TBBS.DIR file.  Note that the -D flag turns on
# specific MS-DOS options.  First we delete any existing TBBS.DIR file,
# since the default is to append to the file.  Note we have to sort the
# file after creating it.  The dependency on CONTENTS.PI is just to
# ensure that one always exists before building TBBS.DIR.

TBBS.DIR:	CONTENTS.PI
	rm -f $@
	find . -name '*.PI' -print | pitool -f TBBS.DIR -b -D -F $(TBBSFMT) -
	sort -f <$@ >/tmp/$@
	cp /tmp/$@ $@

# Generate a summary file called "CONTENTS.TXT".

CONTENTS.TXT:	CONTENTS.PI
	echo "This file is generated automatically from the product info files" >$@
	echo "included in this directory." >>$@
	echo "" >>$@
	find . -name '*.PI' -print \
	  | sort -f \
	  | sed "s:^./::" \
	  | sed "/D[0-9]*XX/d" \
	  | pitool -b -D -f - -F $(CONTENTSFMT) - >>$@

# Generate a quick reference file, which contains the name of the product,
# the version number, and the short description; one product per line.

QUICKREF.TXT:	CONTENTS.PI
	echo "This file is generated automatically from the product info files" >$@
	echo "included in this directory.  See the 'CONTENTS.TXT' file for" >>$@
	echo "additional information about each item." >>$@
	echo "" >>$@
	pitool -b -D -F $(QUICKREFFMT) -f - . \
	  | sort -f \
	  | uniq >>$@

# The dependency on CONTENTS.PI is just to ensure that there is always a
# CONTENTS.PI for each CONTENTS.LHA file that is built.

CONTENTS.LHA:	CONTENTS.PI CONTENTS.TXT QUICKREF.TXT
	lha -mraxeq a $@ CONTENTS.TXT QUICKREF.TXT

CONTENTS.PI:	../CONTENTS.PIT
	cp $? $@

# Clean out all the machine generated files in preparation for rebuilding them
# all.

clobber:
	@for i in *; \
	do \
		if test -d $$i; then \
			echo "Making 'clobber' in $$i"; \
			(cd $$i; $(MAKE) -f ../AMIGALIB.MK clobber-local);\
		fi; \
	done

clobber-local:
	rm -f $(BUILT_FILES)


