####
####	Makefile for Ted.
####
####	No explicit 'configure' is needed as it is done by the 'make' process
####	for the various targets.
####
####	I admit that this makefile is more like a shell script.
####
####	Sensible targets are:
####
####	compile:	Just build an executable in the 'Ted' directory
####	package:	Build a package. Must be run as root.
####	install:	Install the package. Must be run as root.
####	clean:		Cleanup rubbish from previous attempts.
####
####	compile.shared:	Compile, do not try to link statically.
####	package.shared:	Build a package, using the dynamically linked
####			executable
####	install.shared:	Install the package. Must be run as root.
####			Installs the package just made, does not force
####			the package to be dynamically linked. This target
####			exists only for convenience.
####


compile:	tedlibs		\
		Ted/Ted		\
		Ted/Ted.static
	:
	: Executable Ted/Ted ready
	: You can now run 'make package' AS ROOT

compile.shared:	tedlibs		\
		Ted/Ted
	:
	: Executable Ted/Ted ready
	: You can now run 'make package.shared' AS ROOT

####
####	Make library directory.
####

lib:
	mkdir lib

####
####	Build ted libraries
####
tedlibs: 	lib		\
		lib/bitmap.a	\
		lib/ind.a	\
		lib/reg.a	\
		lib/appUtil.a	\
		lib/appFrame.a

####
####	Compile the bitmap manipulation library
####

lib/bitmap.a: bitmap/makefile
	cd bitmap && make

bitmap/makefile: bitmap/makefile.in
	cd bitmap && ./configure

####
####	Compile the spell checker library
####

lib/ind.a: ind/makefile
	cd ind && make

ind/makefile: ind/makefile.in
	cd ind && ./configure

####
####	Compile the regular expression library
####

lib/reg.a: libreg/makefile
	cd libreg && make

libreg/makefile: libreg/makefile.in
	cd libreg && ./configure

####
####	Compile the application utility library
####

lib/appUtil.a: appUtil/makefile
	cd appUtil && make

appUtil/makefile: appUtil/makefile.in
	cd appUtil && ./configure

####
####	Compile the application framework library
####

lib/appFrame.a: appFrame/makefile
	cd appFrame && make

appFrame/makefile: appFrame/makefile.in
	cd appFrame && ./configure

####
####	Compile and link Ted
####

Ted/Ted.static: tedlibs Ted/makefile
	cd Ted && make Ted.static

Ted/Ted: tedlibs Ted/makefile
	cd Ted && make

Ted/makefile: Ted/makefile.in
	cd Ted && ./configure

####
####	Make a ready to install package
####	Must be run as root
####

package: tedPackage/makefile compile
	cd tedPackage && make
	:
	: Package ready.
	: To install Ted, you can now run 'make install' AS ROOT

package.shared: tedPackage/makefile compile.shared
	cd tedPackage && make package.shared
	:
	: Dynamically linked package ready.
	: To install Ted, you can now run 'make install' AS ROOT

tedPackage/makefile: tedPackage/makefile.in
	cd tedPackage && ./configure

####
####	Install Ted from the package just built
####

install: package
	sh ./tedPackage/installTed.sh

install.shared: package.shared
	sh ./tedPackage/installTed.sh

####
####	Cleanup
####

clean:
	rm -rf lib
	rm -f */config.h */config.cache */config.log */config.status
	rm -f */makefile
	rm -f */*.o
	rm -rf tedPackage/scratch
	rm -f tedPackage/*.gz
	rm -f tedPackage/*.lsm
	rm -f tedPackage/installTed.sh
	rm -f tedPackage/README
	rm -f tedPackage/package
	rm -f tedPackage/package.shared

