# Makefile for cdtool
# 2004, Max Vozeler <max@hinterhof.net>

prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
mandir = @mandir@
includedir = @includedir@
libdir = @libdir@

PACKAGE = @PACKAGE_NAME@
VERSION = @PACKAGE_VERSION@

CC = @CC@
INSTALL = @INSTALL@
STRIP = @STRIP@
CFLAGS = @MYCFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@

DESTDIR =

PROGRAMS = cdown cdtool cdctrl cdtool2cddb
OBJECTS = commands.o hardware.o database.o info.o shuffle.o util.o

build: $(PROGRAMS)

debug: CFLAGS += -DDEBUG -O0
debug: STRIP =
debug: build

cdtool: $(OBJECTS) cdtool.o
	$(CC) -o $@ $(LDFLAGS) $(OBJECTS) cdtool.o $(LIBS)

cdctrl: $(OBJECTS) cdctrl.o
	$(CC) -o $@ $(LDFLAGS) $(OBJECTS) cdctrl.o $(LIBS)

cdown: $(OBJECTS) cdown.o
	$(CC) -o $@ $(LDFLAGS) $(OBJECTS) cdown.o $(LIBS)

cdtool2cddb: cdtool2cddb.o
	$(CC) -o $@ $(LDFLAGS) $(LIBS) $<

install: install-files install-links
install-files:
	mkdir -p $(DESTDIR)$(bindir)
	$(INSTALL) cdctrl $(DESTDIR)$(bindir) -o root
	$(INSTALL) cdloop $(DESTDIR)$(bindir) -o root
	$(INSTALL) cdadd $(DESTDIR)$(bindir) -o root
	$(INSTALL) cdown $(DESTDIR)$(bindir) -o root
	$(INSTALL) cdtool2cddb $(DESTDIR)$(bindir) -o root

	mkdir -p $(DESTDIR)$(mandir)/man1
	$(INSTALL) cdctrl.1 $(DESTDIR)$(mandir)/man1
	$(INSTALL) cdloop.1 $(DESTDIR)$(mandir)/man1
	$(INSTALL) cdadd.1 $(DESTDIR)$(mandir)/man1
	$(INSTALL) cdown.1 $(DESTDIR)$(mandir)/man1
	$(INSTALL) cdtool.1 $(DESTDIR)$(mandir)/man1
	$(INSTALL) cdtool2cddb.1 $(DESTDIR)$(mandir)/man1

	mkdir -p $(DESTDIR)$(libdir)/cdtool
	$(INSTALL) cdtool $(DESTDIR)$(libdir)/cdtool -o root
 
LINKTARGET = ../lib/cdtool/cdtool
LINKS = cdplay cdpause cdstop cdclose cdeject cdir cdinfo cdreset \
        cdvolume cdshuffle

install-links-local: LINKTARGET = cdtool
install-links-local: bindir = .
install-links-local: install-links

install-links:
	for command in $(LINKS); do \
	  if ! test -h $(DESTDIR)$(bindir)/$$command; then \
	    echo installing $$command; \
	    rm -f $(DESTDIR)$(bindir)/$$command; \
	    ln -s $(LINKTARGET) $(DESTDIR)$(bindir)/$$command; \
	  fi; \
	  if ! test -h $(DESTDIR)$(mandir)/man1/$$command.1; then \
	    echo installing $$command.1; \
	    rm -f $(DESTDIR)$(mandir)/man1/$$command.1; \
	    ln -s cdtool.1 $(DESTDIR)$(mandir)/man1/$$command.1; \
	  fi; \
	done

clean:
	rm -f *.o $(PROGRAMS)

distclean: clean
	-rm -f config.cache config.log config.status

