# Makefile for GNU e?grep
# Copyright (C) 1992 Free Software Foundation, Inc.

# 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, 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., 675 Mass Ave, Cambridge, MA 02139, USA.

SHELL = /bin/sh

#### Start of system configuration section. ####

INSTALL = copy clone
INSTALL_PROGRAM = copy clone
INSTALL_DATA = copy clone

# Things you might add to DEFS:
# -DSTDC_HEADERS	If you have ANSI C headers and libraries.
# -DHAVE_UNISTD_H	If you have unistd.h.
# -DUSG			If you have System V/ANSI C string
#			and memory functions and headers.
# -D__CHAR_UNSIGNED__	If type `char' is unsigned.
#			gcc defines this automatically.

DEFS = -isrc:unix/include/ -dSTDC_HEADERS -dHAVE_UNISTD_H

CDEBUG = -O
CFLAGS = $(CDEBUG) $(DEFS) -j100 -j104

prefix = unix:
exec_prefix = $(prefix)

# Prefix for installed program, normally empty or `g'.
binprefix = 
# Prefix for installed man page, normally empty or `g'.
manprefix = 

# Where to install executables.
bindir = $(exec_prefix)bin

#### End of system configuration section. ####

MISC = README INSTALL grep.man COPYING Makefile.in configure configure.in \
 README.cray README.sunos4
SRCS = grep.c dfa.c regex.c getopt.c alloca.c
HDRS = dfa.h getopt.h regex.h
DISTFILES = $(MISC) $(SRCS) $(HDRS)
TESTFILES = khadafy.lines khadafy.regexp regress.sh scriptgen.awk spencer.tests

OBJS = dfa.o regex.o getopt.o
GOBJ = ggrep.o
EOBJ = egrep.o

all: grep egrep

install: all
	$(INSTALL_PROGRAM) grep $(bindir)/$(binprefix)grep
	$(INSTALL_PROGRAM) egrep $(bindir)/$(binprefix)egrep

check:
	builddir=`pwd`; cd $(srcdir)/tests; sh regress.sh $$builddir
	touch check.done

check.done: grep egrep
	builddir=`pwd`; cd $(srcdir)/tests; sh regress.sh $$builddir
	touch check.done

grep: $(OBJS) $(GOBJ)
	blink from lib:c.o $(OBJS) $(GOBJ) \
	lib src:unix/src/unix.lib lib:lc.lib lib:amiga.lib \
	to grep sc sd batch

egrep: $(OBJS) $(EOBJ)
	blink from lib:c.o $(OBJS) $(EOBJ) \
	lib src:unix/src/unix.lib lib:lc.lib lib:amiga.lib \
	to egrep sc sd batch

ggrep.o: grep.c
	lc $(CFLAGS) grep.c
	copy grep.o ggrep.o

egrep.o: grep.c
	lc $(CFLAGS) -DEGREP grep.c
	copy grep.o egrep.o

TAGS: $(SRCS)
	etags $(SRCS)

clean:
	rm -f grep egrep check.done *.o core tests/core tests/tmp.script \
	tests/khadafy.out

mostlyclean: clean

distclean: clean
	rm -f Makefile config.status

realclean: distclean
	rm -f TAGS

dfa.o: dfa.c dfa.h
getopt.o: getopt.c getopt.h
grep.o: grep.c getopt.h regex.h dfa.h
regex.o: regex.c regex.h
