#
# this makefile for cdtools, copyright 1994 thomas insel
#

# where do we install the binaries and unformatted manual pages?
BINDIR = /usr/local/bin
MANDIR = /usr/local/man

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

# OTHERS are other files that are required in a distribution package
OTHERS = Makefile cdadd.sh README COPYING config.h database.h hardware.h

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

# LINKS are different names that cdtool can be called by
LINKS = cdplay cdpause cdstop cdeject cdir

# We seem to need GCC
CC = gcc

all: cdtool links

dist: $(SRCS) $(OTHERS)
	rm -rf ../cdtool-xx
	mkdir ../cdtool-xx
	cp $(SRCS) $(OTHERS) ../cdtool-xx

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

links:
	for i in $(LINKS); do \
	    if test -h $$i; then true; else rm -f $$i; ln -s cdtool $$i; fi; \
	done

install: cdtool cdtool.1
	install -d $(BINDIR) -o root -m 0755
	install cdtool $(BINDIR) -s -o bin
	install cdadd.sh $(BINDIR)/cdadd -o bin
	install -d $(MANDIR)/man1 -o root -m 0755
	install cdtool.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 $(MANDIR)/man1/cdtool.1 $(BINDIR)/cdtool $(BINDIR)/cdadd
	for i in $(LINKS); do \
		rm -f $(BINDIR)/$$i $(MANDIR)/man1/$$i.1; \
    done

dummy:

clean:
	rm -rf *.o $(LINKS) cdtool

realclean: clean
	for i in $(SRCS); do \
	    if test -w $$i; then ci $$i; fi; \
	    if test -e $$i; then rm -f $$i; fi; \
	done

.DEFAULT:
	co $<

cdtool.1:
	co cdtool.1

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