# Makefile for GNU 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. ####

srcdir=@srcdir@
VPATH=@srcdir@

AWK=@AWK@
INSTALL=@INSTALL@
INSTALL_PROGRAM=@INSTALL_PROGRAM@
INSTALL_DATA=@INSTALL_DATA@

CC=@CC@
LINT=lint

# Things you might add to DEFS:
# -DSTDC_HEADERS	If you have ANSI C headers and libraries.
# -DHAVE_UNISTD_H	If you have unistd.h.
# -DHAVE_STRING_H	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=-DGREP @DEFS@

# Extra libraries.
LIBS=@LIBS@
ALLOCA=@ALLOCA@
LIBIBERTY = `if [ -f ../libiberty/libiberty.a ] ; then echo ../libiberty/libiberty.a ; else echo -liberty ; fi`

CFLAGS=-g
LDFLAGS=$(CFLAGS)

prefix=/usr/local
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

# Where to install man pages.
mandir=$(prefix)/man/man1

# Extension for man pages.
manext=1

# How to make a hard link.
LN=ln

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

SRCS=grep.c regex.c dfa.c kwset.c search.c
OBJS=grep.o regex.o dfa.o kwset.o search.o

.SUFFIXES: .c .o

.c.o:
	$(CC) $(CFLAGS) $(DEFS) -I$(srcdir) -I$(srcdir)/../include -c $<

all: grep check.done
clean-info:
info:
install-info:
dvi:

# For Saber C.
grep.load: $(SRCS)
	#load $(CFLAGS) $(DEFS) -I$(srcdir) (SRCS)

# For Lint.
grep.lint: $(SRCS)
	$(LINT) $(CFLAGS) $(DEFS) -I$(srcdir) $(SRCS)

install: all
	$(INSTALL_PROGRAM) grep $(bindir)/$(binprefix)grep
	rm -f $(bindir)/$(binprefix)egrep
	$(LN) $(bindir)/$(binprefix)grep $(bindir)/$(binprefix)egrep
	rm -f $(bindir)/$(binprefix)fgrep
	$(LN) $(bindir)/$(binprefix)grep $(bindir)/$(binprefix)fgrep	
	$(INSTALL_DATA) $(srcdir)/grep.man $(mandir)/grep.$(manext)

installcheck:
check:
	AWK=$(AWK) sh $(srcdir)/tests/check.sh $(srcdir)/tests
	touch check.done

check.done: grep
	AWK=$(AWK) sh $(srcdir)/tests/check.sh $(srcdir)/tests
	touch check.done

grep: $(OBJS) $(LIBOBJS)
	$(CC) $(LDFLAGS) -o grep $(OBJS) $(LIBOBJS) $(LIBS) $(LIBIBERTY)

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

mostlyclean: clean

distclean: clean
	rm -f Makefile config.status

realclean: distclean
	rm -f TAGS

Makefile: $(srcdir)/Makefile.in config.status
	$(SHELL) config.status

dist:
	V=`sed -n '/version\\[/s/.*\\([0-9][0-9]*\\.[0-9]*\\).*/\\1/p' \
	grep.c`; \
	mkdir grep-$$V; mkdir grep-$$V/tests; \
	for f in `awk '{print $$1}' MANIFEST`; do ln $$f grep-$$V/$$f; done; \
	tar cvhf - grep-$$V | gzip > grep-$$V.tar.z; \
	rm -fr grep-$$V

# Some header file dependencies that really ought to be automatically deduced.
dfa.o search.o: dfa.h
grep.o search.o: grep.h
kwset.o search.o: kwset.h
regex.o search.o: regex.h
