######################################################################
# $Id: Makefile.in,v 1.53 2003/10/11 20:47:54 hartmann Exp $
######################################################################

TARGET = freesweep
VERSION = 0.92

SRCS = clear.c drawing.c error.c fgui.c files.c game.c gpl.c main.c pbests.c\
	play.c sl.c stats.c tick.c utils.c image.c
HEADS = sweep.h defaults.h acconfig.h
MISC = README Makefile sweeprc install-sh configure.in Makefile.in\
	config.guess configure config.sub sweep.h.in freesweep.6.in CHANGES\
	config.h.in
CLEANUP = a.out $(TARGET) core made $(OBJS) config.cache config.log\
	config.status

srcdir = .


prefix = /usr/local
exec_prefix = ${prefix}
#bindir = $(exec_prefix)/bin
bindir = ${exec_prefix}/bin

CC = gcc
CFLAGS = -Wall -DVERSION=\"$(VERSION)\" -g -O2
LIBS = -lm -lncurses 
LDFLAGS = 
OBJS = $(SRCS:.c=.o)

TARGET_DIR = $(TARGET)-$(VERSION)
FILES = $(SRCS) $(MISC) $(HEADS)

# for systems that have purify
PURE_ARGS = /s/purify/bin/purify -collector=/s/purify/bin/collect2

.SUFFIXES: .c .o
.PHONY: clean sterile lines distclean maintainer-clean mrproper
#######################################################################
%.o: %.c $(HEADS) Makefile
	@/bin/rm -f $*.o 
	$(CC) $(CFLAGS) -c $<

$(TARGET): $(OBJS) $(HEADS) $(MISC)
	@/bin/rm -f $(TARGET)
	$(PURIFY) $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LIBS) -o $(TARGET)

configure: configure.in
	autoconf

#config.h.in: acconfig.h
#	autoheader

clean:
	@-/bin/rm -rf $(CLEANUP)

pure:
	@make clean
	@make "PURIFY=$(PURE_ARGS)"

install: $(TARGET) $(TARGET).6
	touch sweeptimes
	./install-sh -c -m 2555 -o root -g games -s $(TARGET) $(bindir)/$(TARGET)
	./install-sh -c -m 0664 -o root -g games sweeptimes /sweeptimes
	./install-sh -c -m 0644 -o root -g games sweeprc /usr/local/share/sweeprc
	./install-sh -c -m 0444 -o root -g games $(TARGET).6 ${prefix}/man/man6/$(TARGET).6

distclean:
	@make sterile

maintainer-clean:
	@make sterile

mrproper:
	@make sterile

sterile:
	-make clean
	@-/bin/rm -f *.o core made $(TARGET) a.out sweep.h configure Makefile freesweep.6 debug.log

tar: $(SRCS) $(MISC)
	(cd ../ ; ln -s sweep $(TARGET_DIR))
	(cd ../ ; /bin/tar cvfh $(TARGET_DIR).tar $(FILES:%=$(TARGET_DIR)/%))
	(cd ../ ; rm $(TARGET_DIR))

tags: $(SRCS) $(HEADS) $(MISC)
	@ctags $(SRCS) $(HEADS)

lines: $(SRCS) $(HEADS)
	@echo 'Total lines of code:'
	@wc -l $(SRCS) $(HEADS) | sort -rn
