# Makefile for TCD, v2.0
# Tim Gerla <timg@means.net>

# Please edit this to suit your needs. 
#
DESTDIR		=/usr/local

# If you have trouble linking the program, 
# you may have to change CURSESLIB to -lcurses
#
CURSESLIB	=-I/usr/include/ncurses -lncurses
XLIBDIR		=-L/usr/X11R6/lib/
CC		=gcc
CCFLAGS		=-O3 -Wall -s -DHOSTNAME=\"`hostname`\" -DUSERNAME=\"`whoami`\"
XLIBS		= -lXext -lX11
GTKLIBS		= -lgtk -lgdk -lglib

# You shouldn't have to change anything below.

all : 
	@echo "Please run 'make <target>' where <target> is one of the following:"
	@echo
	@echo "Supported targets:"
	@echo "normal		- (Suggested) Makes console and Gtk version of tcd."
	@echo "tcd		- Makes the console version of tcd. Executable is 'tcd'"
	@echo "gtcd		- Makes the Gtk version of tcd. executable is 'gtcd'"
	@echo "                  (You must have Gtk 0.99.3 or greater on your system.)"
	@echo "install		- Installs everything"
	@echo "install-tcd	- Installs only tcd"
	@echo "install-gtcd	- Installs only gtcd"
	@echo "uninstall	- Uninstalls everything"
	@echo "uninstall-tcd	- Uninstalls only tcd"
	@echo "unnstall-gtcd	- Uninstalls only gtcd"
	@echo "clean		- Removes all .o, ~, and core files from compile directory."
	@echo

normal: tcd gtcd

dist: reallyclean normal clean
	strip tcd gtcd	

.c.o:
	$(CC) $(CCFLAGS) -c $*.c -o $*.o

tcd : src/tcd.o src/tracked.o src/libcdrom.a 
	$(CC) -s -o $@ $^ $(CURSESLIB) -lm

tcd-static : src/tcd.o src/tracked.o src/libcdrom.a 
	$(CC) -static -s -o $@ $^ $(CURSESLIB) -lm

gtcd : src/gtcd.o src/libcdrom.a src/gtracked.o src/gabout.o src/gcddb.o
	$(CC) -s -o $@ $^ $(XLIBDIR) $(XLIBS) $(GTKLIBS) -lm

gtcd-static : src/gtcd.o src/libcdrom.a src/gtracked.o src/gabout.o src/gcddb.o
	$(CC) -s -o $@ $^ -static $(GTKLIBS) $(XLIBDIR) $(XLIBS) -lm

src/libcdrom.a : src/cdrom.o src/cddb.o src/socket.o
	ar r $@ $^

src/tcd.o    	: src/tcd.h src/cdrom.h config.h src/tracked.h
src/gtcd.o	: src/cdrom.h config.h src/gtracked.h icons/* src/gabout.h src/gcddb.h
src/tracked.o	: src/tracked.h src/cdrom.h config.h
src/cddb.o	: src/cddb.h src/cdrom.h src/socket.h config.h
src/socket.o 	: src/socket.h config.h
src/cdrom.o	: src/cdrom.h src/cddb.h config.h
src/gtracked.o	: config.h src/gtracked.h src/cdrom.h
src/gabout.o	: config.h src/gabout.h
src/gcddb.o	: config.h src/gcddb.h src/cddb.h src/cdrom.h src/socket.h

clean:
	-rm -f *~ core *.o IrcLog DEADJOE libcdrom.a
	-rm -f src/*~ src/core src/*.o src/IrcLog src/DEADJOE src/libcdrom.a

reallyclean: clean
	-rm -f gtcd tcd tcd-static gtcd-static

install-tcd:
	-install -s -m 0755 tcd $(DESTDIR)/bin/tcd

install-gtcd:
	-install -s -m 0755 gtcd $(DESTDIR)/bin/gtcd
		
install: install-tcd install-gtcd

uninstall: uninstall-tcd uninstall-gtcd

uninstall-tcd:
	-rm -f $(DESTDIR)/bin/tcd

uninstall-gtcd:
	-rm -f $(DESTDIR)/bin/gtcd
