# GTimer Makefile
#
# Copyright:
#	(C) 1998 Craig Knudsen, cknudsen@radix.net
#	See accompanying file "COPYING".
# 
#	This program is free software; you can redistribute it and/or
#	modify it under the terms of the GNU General Public License
#	as published by the Free Software Foundation; either version 2
#	of the License, or (at your option) any later version.
# 
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
# 
#	You should have received a copy of the GNU General Public License
#	along with this program; if not, write to the
#	Free Software Foundation, Inc., 59 Temple Place,
#	Suite 330, Boston, MA  02111-1307, USA
#

# Set the GTK version number
# minor and micro must be two digits (99 or 01, etc.)
# major should be blank for 0 (otherwise, it's treated as an octal)
GTK_MAJOR_VERSION	= 
GTK_MINOR_VERSION	= 99
GTK_MICRO_VERSION	= 09
GTK_VERSION	= $(GTK_MAJOR_VERSION)$(GTK_MINOR_VERSION)$(GTK_MICRO_VERSION)
CFLAGS	= -O2 -Wall -DGTKVERSION=$(GTK_VERSION)
LIBS	=
LDFLAGS = -L/usr/X11R6/lib -lgtk -lgdk -lglib -lXext -lX11 -lm
VERSION = unknown
DIR	= gtimer-$(VERSION)
DESTDIR = /usr/X11R6/bin

gtimer: main.o edit.o annotate.o report.o confirm.o config.o task.o
	$(CC) main.o edit.o report.o annotate.o confirm.o config.o task.o \
	$(LIBS) $(LDFLAGS) -o gtimer


# to build this, you need the memdebug library I wrote.
debug:
	make "CFLAGS=-g -Wall -DGTIMER_MEMDEBUG -DGTKVERSION=$(GTK_VERSION)" "LIBS=memdebug/libmd.a"

tasktest: tasktest.o task.o
	$(CC) tasktest.o task.o $(LIBS) -o tasktest

main.o: main.c task.h gtimer.h
	$(CC) $(CFLAGS) main.c -c -o main.o

report.o: report.c task.h gtimer.h
	$(CC) $(CFLAGS) report.c -c -o report.o

edit.o: edit.c task.h gtimer.h
	$(CC) $(CFLAGS) edit.c -c -o edit.o

annotate.o: annotate.c task.h gtimer.h
	$(CC) $(CFLAGS) annotate.c -c -o annotate.o

confirm.o: confirm.c task.h gtimer.h
	$(CC) $(CFLAGS) confirm.c -c -o confirm.o

config.o: config.c config.h
	$(CC) $(CFLAGS) config.c -c -o config.o

task.o: task.c task.h
	$(CC) $(CFLAGS) task.c -c -o task.o

tasktest.o: tasktest.c task.h
	$(CC) $(CFLAGS) tasktest.c -c -o tasktest.o


#
# The "dist" target is used for creating the .tar.gz and .tar.bz2
# distributions.
#
dist:
	make "VERSION=`./get_version.pl`" targz bzip

version:
	echo "Version is `./get_version.pl`"

gz targz: gtimer-$(VERSION).tar.gz

bzip bzip2: gtimer-$(VERSION).tar.bz2

gtimer-$(VERSION).tar.gz: gtimer
	echo "Building version $(VERSION) .tar.gz"; \
	if [ ! -d $(DIR) ]; then \
	  ln -s . $(DIR); \
	fi; \
	tar cvf - $(DIR)/README $(DIR)/COPYING \
	$(DIR)/gtimer.1 $(DIR)/Makefile \
	$(DIR)/confirm.c $(DIR)/edit.c $(DIR)/annotate.c $(DIR)/main.c \
	$(DIR)/report.c $(DIR)/task.c \
	$(DIR)/task.h $(DIR)/gtimer.h \
	$(DIR)/config.c $(DIR)/config.h \
	$(DIR)/icons/*xpm $(DIR)/icons/gtimer.gif | \
	gzip -c > gtimer-$(VERSION).tar.gz

gtimer-$(VERSION).tar.bz2:
	echo "Building version $(VERSION) .tar.bz2"; \
	if [ ! -d $(DIR) ]; then \
	  ln -s . $(DIR); \
	fi; \
	tar cvf - $(DIR)/README $(DIR)/COPYING \
	$(DIR)/gtimer.1 $(DIR)/Makefile \
	$(DIR)/confirm.c $(DIR)/edit.c $(DIR)/annotate.c $(DIR)/main.c \
	$(DIR)/report.c $(DIR)/task.c \
	$(DIR)/task.h $(DIR)/gtimer.h \
	$(DIR)/config.c $(DIR)/config.h \
	$(DIR)/icons/*xpm $(DIR)/icons/gtimer.gif | \
	bzip2 --repetitive-best > gtimer-$(VERSION).tar.bz2

# for building the man page
buildman:
	d=`grep GTIMER_VERSION_DATE gtimer.h | \
	  awk '-F"' '{ print $$2 }' | \
	  awk '{ printf "%s %s, %s\n", $$2, $$1, $$3 }'`; \
	make "VERSION=`./get_version.pl`" "DATE=$$d" gtimer.1

gtimer.1: gtimer.man gtimer.h
	sed 's;VERSION;$(VERSION);g' gtimer.man | \
	  sed 's;DATE;$(DATE);g' > gtimer.1

clean:
	rm -f *.o *~ gtimer core

distclean: clean

install:
	install -o root -m 0755 `pwd`/gtimer $(DESTDIR)

all: clean gtimer install

makefile:
	@sed -n '1,/^# DEPEND/ p' Makefile > Makefile.new; \
	make -s depend >> Makefile.new; \
	mv Makefile Makefile.old; \
	mv Makefile.new Makefile
	

depend:
	@for i in `ls -1 *.c`; do \
	  o=`echo $$i | sed "s;\.c;.o;"`; \
	  echo "$$o: " | tr -d '\012'; \
	  gcc -M $$i | sed -n '2,$$ p' | tr -d '\\' | tr '\012' ' ' | tr ' ' '\012' | grep -v '/usr/' | grep '[a-z]' | tr '\012' ' '; \
	  echo ""; \
	done

############################################################################
# DEPEND
annotate.o: task.h gtimer.h 
config.o: config.h 
confirm.o: task.h gtimer.h icons/error.xpm icons/confirm.xpm icons/about.xpm 
edit.o: task.h gtimer.h 
main.o: task.h gtimer.h config.h icons/splash.xpm icons/clock1.xpm icons/clock2.xpm icons/clock3.xpm icons/clock4.xpm icons/clock5.xpm icons/clock6.xpm icons/clock7.xpm icons/clock8.xpm icons/blank.xpm icons/start.xpm icons/stop.xpm icons/stop_all.xpm icons/annotate.xpm icons/new.xpm icons/edit.xpm 
report.o: task.h gtimer.h config.h 
report.v95.o: task.h gtimer.h 
task.o: task.h 
tasktest.o: task.h 
template.o: template.h 
xextras.o: 
