# Makefile for Micro Quixote.
# Copyright (C) 1993,1994 ICOT
# Written by gniibe
# $Id: Makefile,v 1.4 1994/11/14 08:39:21 m-gniibe Exp $

CC = gcc
CFLAGS = -g -Wall -DDEBUG
RANLIB = ranlib

# CC = cc
# CFLAGS = -O

INSTALL= install
BISON  = bison
BFLAGS = --defines --output-file=parse_t.c

OBJS = mq.o 

# dot.o error.o exec.o internal.o subsump.o attr.o \
#        lex.o parse_t.o print.o tree.o unify.o cs.o lookup.o \
#        option.o subrel.o atom.o rule.o commands.o emit.o \
#        cs-dot.o cs-sub.o cs-ext.o ext.o version.o

LIB_OBJS = api.o dot.o error.o exec.o internal.o subsump.o attr.o \
       lex.o parse_t.o print.o tree.o unify.o cs.o lookup.o \
       option.o subrel.o atom.o rule.o commands.o emit.o \
       cs-dot.o cs-sub.o cs-ext.o ext.o version.o

OBSTACK_OBJ = obstack.o

#####
prefix = /usr/local
bindir = ${prefix}/bin
libdir = ${prefix}/lib
libsubdir = ${libdir}/mq
manext = .1
mandir = ${prefix}/man/man1
tmpdir = /tmp

##############
all: mq

lib: libmq.a

api_example: api_example.o obstack.o libmq.a
	${CC} -o api_example -g api_example.o obstack.o libmq.a

libmq.a: ${LIB_OBJS}
	${AR} rcv $@ $?
	${RANLIB} $@

install: all
	${INSTALL} mq ${bindir}

tags:
	etags *.c *.h *.y

clean:
	rm -f mq.o ${LIB_OBJS} ${OBSTACK_OBJ} \
		core parse_t.output *.o

veryclean:
	rm -f mq.o ${LIB_OBJS} ${OBSTACK_OBJ} \
		core parse_t.output mq libmq.a api_example *.o *~

rcslabel:
	(VERSION=`cat \{version\}`; \
	 rcs -nv$$VERSION: RCS/*; \
	 cd ../GNU; rcs -nv$$VERSION: quixote.el)

#version.c: {version} version.c.template
#	(DATE=`date "+19%y/%m/%d"`; \
#	 VERSION=`cat \{version\}`; \
#	 cat version.c.template  | \
#	 sed -e "s/_VERSION_/$$VERSION/" -e "s@_DATE_@$$DATE@" > version.c)

dist:
	(VERSION=`cat \{version\}`; cd ..;\
	 tar cf tmp/t.tar BUGS COPYRIGHT COPYRIGHT.j GNU INSTALL README src; \
	 cd tmp; \
	 mkdir mq-$$VERSION; \
	 (cd mq-$$VERSION; tar xf ../t.tar; \
	  mv src/Makefile src/Makefile-dist; \
	  rm -rf src/ChangeLog.old */*~ src/NEWS src/TAGS src/\{version\} src/*.template src/RCS GNU/RCS); \
	 tar cvf mq-$$VERSION.tar mq-$$VERSION; \
	 gzip mq-$$VERSION.tar; \
	 rm t.tar; mv mq-$$VERSION.tar.gz ..; \
	 rm -rf mq-$$VERSION)

##############
mq: mq.o libmq.a ${OBSTACK_OBJ}
	${CC} -o mq ${CFLAGS} mq.o ${OBSTACK_OBJ} libmq.a

parse_t.c: parse.y
	${BISON} ${BFLAGS} parse.y

parse_t.h: parse.y
	${BISON} ${BFLAGS} parse.y

parse_t.o: parse_t.c mq.h internal.h tree.h extern.h emit.h
obstack.o: obstack.c obstack.h


#################

lex.o: lex.c parse_t.h mq.h internal.h tree.h extern.h
dot.o: dot.c mq.h internal.h extern.h
error.o: error.c mq.h internal.h extern.h
exec.o: exec.c mq.h internal.h extern.h
internal.o: internal.c internal.h mq.h extern.h
subsump.o: subsump.c mq.h internal.h extern.h
mq.o: mq.c mq.h internal.h extern.h
tree.o: tree.c tree.h mq.h internal.h extern.h
unify.o: unify.c mq.h internal.h extern.h
cs.o: cs.c mq.h internal.h extern.h
cs-dot.o: cs-dot.c mq.h internal.h extern.h
cs-sub.o: cs-sub.c mq.h internal.h extern.h
cs-ext.o: cs-ext.c mq.h internal.h extern.h
lookup.o: lookup.c mq.h internal.h extern.h
option.o: option.c mq.h internal.h extern.h
subrel.o: subrel.c mq.h internal.h extern.h
atom.o: atom.c mq.h internal.h extern.h
rule.o: rule.c mq.h internal.h extern.h
emit.o: emit.c mq.h internal.h extern.h
commands.o: commands.c mq.h internal.h extern.h
attr.o: attr.c mq.h internal.h extern.h
print.o: print.c mq.h internal.h extern.h
version.o: version.c
ext.o: ext.c mq.h internal.h extern.h
