################################################################################
#
#  Copyright (c) 1999 by Thierry Lelegard
#
#  This software is covered by the "GNU GENERAL PUBLIC LICENSE" (GPL),
#  version 2, June 1991. See the file named COPYING for details.
#
#  Project: VMSCD - OpenVMS CD-ROM Utility for Linux
#  File:    Makefile
#  Author:  Thierry Lelegard
#
#
#  Abstract
#  --------
#  This makefile rebuilds the VMSCD utilities.
#
#
#  Modification History
#  --------------------
#  18 Dec 1999 - Thierry Lelegard (lelegard@club-internet.fr)
#                Creation of the file.
#
#
################################################################################


CFLAGS  = -Wall -O2
NPD     = --no-print-directory
RPMROOT = tmp-build

default: execs docs
execs: vmscd
docs: vmscd.ps vmscd.pdf vmscd.html
debug:
	@${MAKE} ${MAKEFLAGS} ${NPD} CFLAGS="-Wall -g" execs docs
clean:
	-rm -rf *.o *.tmp ${RPMROOT} *~ #*# .#*
cleanall: clean
	-rm -f vmscd vmscd.ps vmscd.pdf vmscd.html vmscd-*.tar.gz vmscd-*.rpm

# The target "install" copies the required files on the operating system
# to install vmscd system-wide. The normal installation process is to
# create the RPM package (target "distrib") and install it.

install: vmscd
	install -m 0755 -d ${ROOT}/usr/bin
	install -m 0755 -s vmscd ${ROOT}/usr/bin/vmscd
	install -m 0755 -d ${ROOT}/usr/man/man1
	install -m 0644 vmscd.1 ${ROOT}/usr/man/man1/vmscd.1

# The target "distrib" creates the distribution kits.
# The version number of the vmscd utility is automatically udated in
# the RPM configuration file vmscd.spec.

distrib: vmscd
	rm -rf ${RPMROOT}
	mkdir ${RPMROOT} ${RPMROOT}/vmscd-`./vmscd -V`
	sed -e 's/\(^%define version \).*/\1'`./vmscd -V`/ <vmscd.spec \
	  >${RPMROOT}/vmscd-`./vmscd -V`.spec
	cp -p `ls | grep -v ${RPMROOT}` ${RPMROOT}/vmscd-`./vmscd -V`/
	(cd ${RPMROOT}/vmscd-`./vmscd -V` && make ${NPD} cleanall)
	rm -f vmscd-`./vmscd -V`.tar.gz
	(cd ${RPMROOT} && \
	  tar cfz ../vmscd-`../vmscd -V`.tar.gz vmscd-`../vmscd -V`)
	cp vmscd-`./vmscd -V`.tar.gz /usr/src/redhat/SOURCES
	rpm -ba ${RPMROOT}/vmscd-`./vmscd -V`.spec
	cp /usr/src/redhat/RPMS/i?86/vmscd-`./vmscd -V`-1.i?86.rpm .
	cp /usr/src/redhat/SRPMS/vmscd-`./vmscd -V`-1.src.rpm .

# The rest of the Makefile describes the dependencies and building
# of the vmscd executable and documentation files.

cache.o: ods2.h utils.h cache.h
copy.o: ods2.h utils.h cache.h volume.h copy.h
list.o: ods2.h utils.h cache.h volume.h copy.h list.h
utils.o: utils.h
vmscd.o: ods2.h utils.h cache.h volume.h list.h copy.h version.h
volume.o: ods2.h utils.h cache.h volume.h

vmscd: vmscd.o utils.o cache.o volume.o list.o copy.o
	${CC} ${CFLAGS} -o $@ $+ -lreadline
vmscd.ps: vmscd.1
	groff -man $+ >$@
vmscd.pdf: vmscd.ps
	ps2pdf $+ $@
vmscd.html: vmscd.1
	man2html $+ >$@
