# This makefile automates generating Lovelace tutorial files
# from its source files (.les) files.

# NOTE: See the file "legal.htm" for more information about the
# legal status of Lovelace.

# It is unabashedly Unix-dependent, though translating it to some
# other system (like MS-DOS) shouldn't be too hard if desired.
# It's intended for my (David A. Wheeler's) personal use,
# but I'm including it in the distribution since it might be useful.

# Definitions of generic lesson-generating rules.

# The "-s" option in mklesson generates short filename extensions
# (.htm instead of .html):

MKLESSON=mklesson -s -a

.les.tim:
	$(MKLESSON) $<

SUFFIXES += .tim .les

.SUFFIXES : $(SUFFIXES)

# Makefile variable definitions for file generation.

OBJECT_FILES = lesson1.tim lesson2.tim lesson3.tim lesson4.tim \
               lesson5.tim lesson6.tim lesson7.tim lesson8.tim \
               lesson9.tim lesson10.tim lesson11.tim lesson12.tim \
               lesson13.tim lesson14.tim lesson15.tim lesson16.tim \
               lesson17.tim

# Lesson 18 is _NOT_ listed in OBJECT_FILES because it's generated
# while generating program "Small".
# Lesson 18 is considered part of program "Small" for legal purposes.
# As with the rest of "Small", lesson 18 is part of the Lovelace distribution,
# and lesson18.les is included.

MKLESSON_FILES = readme gpl lgpl userg.htm mklesson template default \
              formattm.htm formatmk.txt blank.les new_sect \
              previous.gif next.gif up.gif tinyhome.gif \
              skip1s1.htm txttemp makefile

# File name of the "last lesson" (i.e. the lesson/section that doesn't exist)
LAST_LESSON = s19s1.htm


# Rules for file generation; default is "all".

# Comments to myself:
# Before running this command "for real", regenerate all files for
# program Small, and from the Small directory "make install".
# This will place Small results into the Lovelace files.
# To everyone else this will make no difference, since Small is distributed
# as part of Lovelace.

# Note all the checking systems;
# weblint looks for HTML errors, hspell for spelling errors, and
# gcc calls GNAT to check for Ada syntax errors.
# Perhaps later I'll add "-gnatg" and explicitly use GNAT style.

all: $(OBJECT_FILES) comments.htm
	echo "Make sure you've install the program Small files."
	cp fini.htm $(LAST_LESSON)
	chmod ugo+r [a-z]*
	weblint -e bad-link,mailto-link,upper-case \
                -d heading-order,empty-container -x netscape *.htm
	nolink -i dwheeler.htm *.htm
	hspell -x comments.htm *.htm
	gcc -c -gnatc -gnatk8 *.adb *.ads
	# replace '<BODY>' '<BODY BGCOLOR="#FFFFFF">' *.htm
	-grep ' < ' *.les > ,goofs
	-grep ' > ' *.les >> ,goofs
	-grep ' & ' *.les >> ,goofs
	-grep ' <= ' *.les >> ,goofs
	-grep ' >= ' *.les >> ,goofs
	-grep ' => ' *.les >> ,goofs
	-echo "List of goofs follows:"
	-cat ,goofs

comments.htm: comments.hd COMMENTS comments.tl
	mkcomm

clean:
	echo > ,temp.BAK
	echo > ,temp.org
	rm *.BAK *.org

really_clean: clean
	-rm *.tim
	-rm s[1-9][-s][1-9f].htm
	-rm s[1-9][0-9][-s][1-9f].htm
	-rm s[1-9][-s][1-9f]r[1-9].htm
	-rm s[1-9][0-9][-s][1-9f]r[1-9].htm


# Eventually add a "make check" entry, to perform a
# weblint, spellcheck, and a clean-compilation check.

# There's an implied order here:
# 1. Edit version files (lversion.htm, lovelace.htm, and version).
# 2. "make ci_all" to check in all local files.
# 3. "make distribute" to create the .zip, .tar.gz, and the WWW version.
# The distribution files do not contain old versions of
# documents (i.e. my RCS and OLD directories are not sent on).


# Check in every file in the (local) RCS directory.

ci_all:
	echo "You should have already edited these files:"
	echo "Files: version, lovelace.htm, lversion.htm"
	echo "Checking in all RCS files."
	ci -l RCS/*
	echo "Version Number is:"
	cat < version
	echo "If all's okay, execute this and make distribute:"
	echo 'rcs -Nversion: RCS/*'
	echo "Where version is Lversion.number (without the period)"

# "ci_all" doesn't do the rcs command because it's easy to
# forget to upgrade all the version files.


distribute: clean
	lcount > stats.htm
	chmod ugo+r [a-z]*
	rm -f lovelace.zip lovelace.tar.gz
	zip -9 lovelace.zip [a-z]* *.class -x `cat exclude`
	tar cvfX - exclude [a-z]* *.class > lovelace.tar
	gzip --best lovelace.tar
	rm -f mklesson.tar.gz mklesson.zip
	zip -9 mklesson.zip $(MKLESSON_FILES) -x `cat exclude`
	tar cvf - $(MKLESSON_FILES) > mklesson.tar
	gzip mklesson.tar
	chmod ugo+r *.zip *.gz
	rm -fr CELLO
	mkdir CELLO
	cp -p JUST_CELLO/* CELLO
	cp -p [a-z]* *.class CELLO
	cd CELLO; zip -9 LV-CELLO.zip [a-z]* -x `cat exclude`
	mv CELLO/LV-CELLO.zip .
	rm -fr CELLO
	mv LV-CELLO.zip lovecell.zip
	tar cvf - WWW_install [a-z]* *.class > WWW_LOVELACE.tar
	mv lovecell.zip LV-CELLO.zip
	chmod a+r WWW_LOVELACE.tar
	compress WWW_LOVELACE.tar

