# Makefile for the "KBI" Application.
# Chapters 11, 12, and 13.

CC = gcc -Wall 
MYSQL-INCLUDES = -I/usr/include/mysql
MYSQL-LIBS = -L/usr/include/mysql -L/usr/lib/mysql -lmysqlclient -lz
GTK-CONFIG = `gtk-config --cflags --libs`
GTK-INCLUDES = `gtk-config --cflags`
GTK-LINKS = `gtk-config --libs`

kbi : main.o interface.o support.o callbacks.o kbi_utils.o
	$(CC) -o kbi *.o $(GTK-CONFIG) $(MYSQL-INCLUDES) $(MYSQL-LIBS)
	cp -f kbi /usr/local/bin/kbi

main.o : main.c
	$(CC) -c main.c $(GTK-INCLUDES)

interface.o : interface.c
	$(CC) -c interface.c $(GTK-INCLUDES)

support.o : support.c
	$(CC) -c support.c $(GTK-INCLUDES)

callbacks.o : callbacks.c
	$(CC) -c callbacks.c $(GTK-INCLUDES)

kbi_utils.o : kbi_utils.c
	$(CC) -c kbi_utils.c $(GTK-INCLUDES) $(MYSQL-INCLUDES)

# Note that you can force a full rebuild by calling 
# "make clean" before calling "make" or "make install".  By removing
# all the intermediate object files, you force a full
# rebuild of the kbi executable.  When make goes to compare
# the time of the kbi exe to that of the *.o files and finds
# no *.o files, it re-runs all the rules to make the object
# files.  Then, of course, the *.o files are newer than the
# last kbi executable, so the exe is rebuilt.

clean::
	rm -f *.o 


EXE_LOCATION = /usr/local/bin/
MENU_LOCATION = "/usr/share/gnome/apps/In House Applications/"

# In the commands below...
#     The -f after cp tells cp to overwrite an existing file of
#            the same name in the target location, if the file 
#            already exists.

install : kbi
	cp -f "Key Business Indicators.desktop" $(MENU_LOCATION)
	cp -f kbi $(EXE_LOCATION)kbi
	chmod 755 $(EXE_LOCATION)kbi
	echo Key Business Indicators Application Installed.

