#  htsclient.ncurses - a ncurses-based client for the game Holsham Traders
#  Copyright (C) 1999 Uwe Hermann
#
#  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

SHELL=/bin/sh

PROGRAM = htsclient.ncurses
VERSION = 0.4.1

CC = gcc
LIBS = -lncurses
CFLAGS = -Wall -O2 -pedantic -ansi -W -Wtraditional -Wshadow -Wpointer-arith \
         -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion \
         -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes \
         -Wmissing-declarations -Wnested-externs -Winline

OBJECTS = cmdline.o $(PROGRAM).o log.o misc.o ncurses.o net.o sock.o
INSTALL = /usr/bin/install

prefix = /usr/local
bindir = $(prefix)/bin
mandir = $(prefix)/man


all: $(PROGRAM)


cmdline.o: cmdline.c cmdline.h sock.h log.h data.h
	$(CC) -c $(CFLAGS) $<

$(PROGRAM).o: $(PROGRAM).c $(PROGRAM).h cmdline.h net.h
	$(CC) -c $(CFLAGS) $<

log.o: log.c log.h
	$(CC) -c $(CFLAGS) $<

misc.o: misc.c misc.h
	$(CC) -c $(CFLAGS) $<

ncurses.o: ncurses.c ncurses.h
	$(CC) -c $(CFLAGS) $<

net.o: net.c net.h sock.h
	$(CC) -c $(CFLAGS) $<

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


$(PROGRAM): $(OBJECTS)
	$(CC) $(CFLAGS) $(OBJECTS) $(LIBS) -o $(PROGRAM)

install: 
	$(INSTALL) -o root -g root -m 755 -d $(bindir)
	$(INSTALL) -o root -g root -m 755 -d $(mandir)/man6
	$(INSTALL) -o root -g root -m 755 -c $(PROGRAM) $(bindir)
	$(INSTALL) -o root -g root -m 644 -c $(PROGRAM).6 $(mandir)/man6

uninstall:
	rm -f $(bindir)/$(PROGRAM)
	rm -f $(mandir)/man6/$(PROGRAM).6

clean: 
	rm -f *.o core *~

distclean:
	rm -f $(PROGRAM) *.o core *~ $(PROGRAM)-$(VERSION).tar.gz \
	$(PROGRAM)-$(VERSION).tar.bz2

archive_common:
	rm -f $(PROGRAM)-$(VERSION).tar.gz
	rm -f $(PROGRAM)-$(VERSION).tar.bz2
	mkdir $(PROGRAM)-$(VERSION)
	cp AUTHORS COPYING ChangeLog INSTALL MANIFEST Makefile NEWS README \
        README.programmers TODO cmdline.c cmdline.h config.h data.h \
	htsclient.ncurses-0.4.1.lsm htsclient.ncurses.6 htsclient.ncurses.c \
	htsclient.ncurses.h log.c log.h misc.c misc.h \
	ncurses.c ncurses.h net.c net.h sock.c sock.h $(PROGRAM)-$(VERSION)
	chmod 755 $(PROGRAM)-$(VERSION)
	chmod 644 $(PROGRAM)-$(VERSION)/*

archive:
	@make archive_common
	tar cfvz $(PROGRAM)-$(VERSION).tar.gz $(PROGRAM)-$(VERSION)
	rm -rf $(PROGRAM)-$(VERSION)

bz2archive:
	@make archive_common
	tar cfvI $(PROGRAM)-$(VERSION).tar.bz2 $(PROGRAM)-$(VERSION)
	rm -rf $(PROGRAM)-$(VERSION)

lint:
	lclint +posixlib *.[ch]

