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

# This Makefile is for DJGPP v2.0

# 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=.
VPATH=.

AWK=gawk
INSTALL=xcopy
INSTALL_PROGRAM=$(INSTALL)
INSTALL_DATA=$(INSTALL)

CC=gcc
LINT=lint

DEFS=-DGREP -DHAVE_CONFIG_H

# Extra libraries.
LIBS=
ALLOCA=

CFLAGS=-O3 -Wall -g
LDFLAGS=-s

prefix=c:/djgpp
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=lns.bat

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

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

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

all: grep check

# 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
	$(LN) grep egrep
	$(LN) grep fgrep
	for %%p in (grep.exe egrep.exe fgrep.exe) do $(INSTALL_PROGRAM) %%p $(bindir)\$(binprefix)
	copy $(srcdir)\grep.man $(srcdir)\grep.$(manext)
	$(INSTALL_DATA) $(srcdir)\grep.$(manext) $(mandir)

check: check.done

check.done: grep
	grep -E -f tests/khadafy.reg tests/khadafy.lin > khadafy.out
	cmp tests/khadafy.lin khadafy.out
	$(AWK) -F: -f tests/scriptge.dos tests/spencer.tes > script.bat
	script.bat
	touch check.done

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

clean:
	for %%f in (grep *.o *.exe check.don script.bat khadafy.out) do del %%f

mostlyclean: clean

distclean: clean
	if exist Makefile del Makefile
	if exist config.h del config.h

realclean: distclean
	del TAGS

grep.ii: grep.c
	$(CC) $(CFLAGS) $(DEFS) -I$(srcdir) -E -c $< -o grep.ii

Makefile: $(srcdir)/Makefile.dj
	copy Makefile.dj Makefile

# Some header file dependencies that really ought to be automatically deduced.
grep.o: dosbuf.c
dfa.o search.o: dfa.h
grep.o search.o: grep.h
kwset.o search.o: kwset.h
kwset.o obstack.o: obstack.h
regex.o search.o: regex.h
grep.o regex.o search.o getopt.o alloca.o: config.h
