#
# this makefile for cdtools, copyright 1994 thomas insel
# as updated to include ctctrl, 1997, Wade Hampton
#
# $Log: Makefile,v $
# Revision 1.6  1998/01/06 21:02:03  wadeh
# Revision 2.1.4
#
# Revision 1.5  1998/01/06 21:00:33  wadeh
# Added DoCr, changes to fix cdeject crash.
#
# Revision 1.4  1997/12/30 23:03:56  wadeh
# Added cdloop
#
# Revision 1.3  1997/12/30 23:01:49  wadeh
# Makefile for version beta 3.
#
# Revision 1.2  1997/12/24 15:39:10  wadeh
# Minor bug fixes:
# 1) Fixed cdctrl eject command causing a signal 11.
# 2) Fixed Makefile debug option to not strip symbols, can now debug.
# 3) Added command.h and more prototypes, more documentation.
# 4) Fixed read_hw to always return buffer, even on error.
#
#

# Where do we install the binaries and unformatted manual pages?
# -- These are for installation in the local tree:
BINDIR = /usr/local/bin
MANDIR = /usr/local/man

# -- These are for installation in the system tree (e.g., with distributions).
#BINDIR = /usr/bin
#MANDIR = /usr/man

# The name and release of the package
THISVER=cdtool-2.1.5
THISREL=1
SOURCES=/usr/src/wh/SOURCES

# SRCS are RCS'd files
SRCS = cdctrl.c main.c commands.c hardware.c database.c info.c shuffle.c \
cdown.c cdtool.1 cdctrl.1 cdown.1

# OTHERS are other files that are required in a distribution package
OTHERS = Makefile cdadd.sh README INSTALL COPYING cdctrl.h info.h config.h \
	database.h hardware.h main.h commands.h shuffle.h cdloop cdadd \
	*lsm *.spec

# OBJS are used to build cdtool
OBJS  = main.o   commands.o hardware.o database.o info.o shuffle.o
OBJS1 = cdctrl.o commands.o hardware.o database.o info.o shuffle.o

# LINKS are different names that cdtool can be called by
# Uncomment out the first one to get "cdplay".
# Uncomment out the second one to get "cdstart"
# Note, the cdp package includes a program, /usr/bin/cdplay which
# would interfere with the usage here.
#
#LINKS = cdplay cdpause cdstop cdeject cdir cdinfo cdreset
LINKS = cdstart cdpause cdstop cdeject cdir cdinfo cdreset cdshuffle

# We seem to need GCC
CC = gcc $(DEBUG_FLAGS)

all::
	make clean
	make noobjs
	make cdown
	make cdadd
	make cdctrl DEBUG_FLAGS="-O -s -DCDCTRL"
	make noobjs
	make cdtool DEBUG_FLAGS="-O -s"
	make links

debug::
	make clean
	make noobjs
	make cdown  DEBUG_FLAGS="-g -Wall"
	make cdadd
	make cdctrl DEBUG_FLAGS="-g -Wall -DDEBUG -DCDCTRL"
	make noobjs
	make cdtool DEBUG_FLAGS="-g -Wall -DDEBUG"
	make links

debugscsi::
	make clean
	make noobjs
	make cdown  DEBUG_FLAGS="-g -Wall"
	make cdadd
	make cdctrl DEBUG_FLAGS="-g -Wall -DDEBUG -DSCSI -DCDCTRL"
	make noobjs
	make cdtool DEBUG_FLAGS="-g -Wall -DDEBUG -DSCSI"
	make links

scsi::
	make clean
	make noobjs
	make cdown
	make cdadd
	make cdctrl DEBUG_FLAGS="-O -s -DSCSI -DCDCTRL"
	make noobjs
	make cdtool DEBUG_FLAGS="-O -s -DSCSI"
	make links

dist: $(SRCS) $(OTHERS)
	(cd ..;tar zcvf $(THISVER).tar.gz \
	`for i in $(SRCS) $(OTHERS);do echo $(THISVER)/$$i ;done`)

rpm: $(SRCS) $(OTHERS)
	make dist
	(cd ..;cp $(THISVER).tar.gz $(SOURCES) )
	rpm -ba $(THISVER)-$(THISREL).spec

cdown:  cdown.c
	$(CC) -o cdown $(DEBUG_FLAGS) cdown.c

cdtool: $(OBJS)
	$(CC) -o cdtool $(OBJS)

cdctrl: $(OBJS1)
	$(CC) -o cdctrl $(OBJS1)

cdadd: cdadd.sh
	sed s,@BINDIR@,$(BINDIR),g < $< > $@
	chmod a+x $@
	
links:
	@for i in $(LINKS); do \
	    if test -L $$i; then true; else rm -f $$i; ln -s cdtool $$i; fi; \
	done

install: cdtool cdtool.1 cdadd
	install -d $(BINDIR) -o root -m 0755
	install cdctrl $(BINDIR) -s -o root
	install cdloop $(BINDIR)    -o root
	install cdtool $(BINDIR) -s -o root
	install cdadd  $(BINDIR)    -o root
	install cdown  $(BINDIR)    -o root
	install -d $(MANDIR)/man1 -o root -m 0755
	install cdown.1  $(MANDIR)/man1
	install cdtool.1 $(MANDIR)/man1
	install cdctrl.1 $(MANDIR)/man1
	for i in $(LINKS); do \
		if test -h $(BINDIR)/$$i; then true; else \
			rm -f $(BINDIR)/$$i; ln -s ./cdtool $(BINDIR)/$$i; \
		fi; \
		if test -h $(MANDIR)/man1/$$i.1; then true; else \
			rm -f $(MANDIR)/man1/$$i.1; \
			ln $(MANDIR)/man1/cdtool.1 $(MANDIR)/man1/$$i.1; \
		fi; \
	done

uninstall: dummy
	rm -f $(BINDIR)/cdadd
	rm -f $(BINDIR)/cdloop 
	rm -f $(MANDIR)/man1/cdown.1  $(BINDIR)/cdown 
	rm -f $(MANDIR)/man1/cdctrl.1 $(BINDIR)/cdctrl 
	rm -f $(MANDIR)/man1/cdtool.1 $(BINDIR)/cdtool $(BINDIR)/cdadd
	for i in $(LINKS); do \
		rm -f $(BINDIR)/$$i $(MANDIR)/man1/$$i.1; \
	    done
	rm -f $(BINDIR)/cdtool

dummy:

clean:
	rm -rf *.o *~ $(LINKS) cdtool cdadd cdctrl cdown

noobjs:
	rm -rf *.o 	

always:

# dependencies 
cdctrl.o: cdctrl.h config.h commands.h info.h
main.o: config.h main.h commands.h
database.o: database.h 
hardware.o: database.h hardware.h 
info.o: database.h hardware.h main.h commands.h

