#
# Makefile for XShogi, part of GNU shogi.
#
# Copyright (c) 1993 Matthias Mutz
# Copyright (c) 1998, 1999 Michael C. Vanier and the Free Software Foundation
#
# XShogi 1.1 is based on XBoard 2.0
# Copyright (c) 1992 Free Software Foundation
#
# This file is part of XShogi.
#
# XShogi 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 1, or (at your option)
# any later version.
#
# XShogi 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 XShogi; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#

#
# xshogi is the X Windows-based user interface for GNU Shogi.
#

SHELL           = /bin/sh
VERS            = 1.3
INSTALL         = /usr/bin/install -c
INSTALL_DATA    = ${INSTALL} -m 644
INSTALL_PROGRAM = ${INSTALL}
ROOT            = ..


#
# Installation directories.
#

prefix  = /usr/local
BINDIR  = $(prefix)/bin
MANDIR  = $(prefix)/man/man6


#
# Parser generator.
#

LEX    =   flex
YACC   =   bison -y


#
# C compiler and compiler options.
#

CC          = gcc
XINCLUDES   = 
CWARNINGS   = -Wall -Wno-implicit-int -Wstrict-prototypes -ansi -pedantic
CEXTRAFLAGS = -fsigned-char -funroll-loops $(HASH)
CFLAGS      = -g -O2 $(CEXTRAFLAGS) $(XINCLUDES) -I..
LIBS        =
XLIBS       =  -L/usr/X11/lib -R/usr/X11/lib -lXaw -lXmu -lXt -lXext -lX11
LDFLAGS     = $(XLIBS) $(LIBS)


OPT                   = 
FIRST_SHOGI_PROGRAM   = -DFIRST_SHOGI_PROGRAM=\"gnushogi\"
SECOND_SHOGI_PROGRAM  = -DSECOND_SHOGI_PROGRAM=\"gnushogi\"
FIRST_HOST            = -DFIRST_HOST=\"localhost\"
SECOND_HOST           = -DSECOND_HOST=\"localhost\"


#
# Targets.
#

all: xshogi

xshogi: 
	$(CC) -o xshogi xshogi.o parser.o $(CFLAGS) $(LDFLAGS) 

xshogi.o: 
	$(CC) -c xshogi.c $(CWARNINGS) $(CFLAGS) \
        $(OPT) $(FIRST_SHOGI_PROGRAM) $(SECOND_SHOGI_PROGRAM) \
        $(FIRST_HOST) $(SECOND_HOST) 


#
# Regenerate the parser.  NOTE: scanner.c is never compiled; it
# is #included into parser.y.
#

parser.o: 
	$(CC) -c parser.c $(CFLAGS)

parser.c: 
	$(YACC) parser.y
	mv y.tab.c parser.c

scanner.c: scanner.l
	$(LEX) scanner.l
	mv lex.yy.c scanner.c


#
# Sources.
#

SOURCES = xshogi.c 


#
# Installation.
#

install: xshogi
	strip xshogi
	$(INSTALL_PROGRAM) -d $(BINDIR)
	$(INSTALL_PROGRAM) -d $(MANDIR)
	$(INSTALL_PROGRAM) xshogi $(BINDIR)
	$(INSTALL_DATA)    $(ROOT)/doc/xshogi.6 $(MANDIR)


#
# Cleanup.
#

CLEANFILES = xshogi *.o parser.c y.tab.c scanner.c lex.yy.c

clean:
	for file in $(CLEANFILES); do \
    if [ -f $$file ]; then rm $$file; fi; \
	done


#
# Dependencies.
#

xshogi:     xshogi.o parser.o
xshogi.o:   xshogi.c sysdeps.h xshogi.h bitmaps.h ../version.h ../config.h
parser.o:   parser.c xshogi.h
parser.c:   parser.y scanner.c
scanner.c:  scanner.l

