# Makefile for GNU patch.
# Copyright 1993, 1997 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; see the file COPYING.
# If not, write to the Free Software Foundation,
# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

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

srcdir = @srcdir@
VPATH = @srcdir@

@SET_MAKE@

CC = @CC@
ed_PROGRAM = @ed_PROGRAM@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
transform = @program_transform_name@

CFLAGS = @CFLAGS@
CPPFLAGS = @CPPFLAGS@
DEFS = @DEFS@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
PACKAGE = @PACKAGE@
VERSION = @VERSION@

prefix = @prefix@
exec_prefix = @exec_prefix@

bindir = $(exec_prefix)/bin

# Where to put the manual pages.
man1dir = $(prefix)/man/man1
# Extension (including `.') for the manual page filenames.
man1ext = .1

# Hook for nonstandard builds.
CONFIG_STATUS = config.status

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

SHELL = /bin/sh

LIBSRCS = getopt.c getopt1.c memchr.c rename.c
SRCS = addext.c argmatch.c backupfile.c basename.c inp.c maketime.c \
	partime.c patch.c pch.c quotearg.c util.c version.c $(LIBSRCS)
OBJS = addext.o argmatch.o backupfile.o basename.o inp.o maketime.o \
	partime.o patch.o pch.o quotearg.o util.o version.o $(LIBOBJS)
HDRS = argmatch.h backupfile.h common.h getopt.h \
	inp.h maketime.h partime.h pch.h quotearg.h util.h version.h
MISC = COPYING ChangeLog INSTALL Makefile.in NEWS README \
	acconfig.h config.hin configure configure.in \
	install-sh mkinstalldirs patch.man
DISTFILES = $(MISC) $(SRCS) $(HDRS)
DISTFILES_PC = pc/chdirsaf.c
DISTFILES_PC_DJGPP = pc/djgpp/README pc/djgpp/config.sed \
	pc/djgpp/configure.bat pc/djgpp/configure.sed

patch_name = `echo patch | sed '$(transform)'`

all:: patch

info::
check::
installcheck::

COMPILE = $(CC) -c $(CPPFLAGS) $(DEFS) -Ded_PROGRAM=\"$(ed_PROGRAM)\" \
	-I. -I$(srcdir) $(CFLAGS)

.c.o:
	$(COMPILE) $<

patch: $(OBJS)
	$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(OBJS) $(LIBS)

install:: all installdirs
	$(INSTALL_PROGRAM) patch $(DESTDIR)$(bindir)/$(patch_name)
	-$(INSTALL_DATA) $(srcdir)/patch.man $(DESTDIR)$(man1dir)/$(patch_name)$(man1ext)

installdirs::
	$(SHELL) $(srcdir)/mkinstalldirs $(DESTDIR)$(bindir) $(DESTDIR)$(man1dir)

install-strip::
	$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install

uninstall::
	rm -f $(DESTDIR)$(bindir)/$(patch_name) $(DESTDIR)$(man1dir)/$(patch_name)$(man1ext)

Makefile: Makefile.in $(CONFIG_STATUS)
	$(SHELL) $(CONFIG_STATUS)
config.status: configure
	$(SHELL) $(CONFIG_STATUS) --recheck

patchlevel.h: Makefile
	echo '#define PATCH_VERSION "$(VERSION)"' >patchlevel.h

TAGS: $(HDRS) patchlevel.h $(SRCS)
	etags $(HDRS) patchlevel.h $(SRCS)

clean::
	rm -f patch core* *core *.o

mostlyclean:: clean

distclean:: clean
	rm -f Makefile config.cache config.log config.status config.h
	rm -f patchlevel.h

maintainer-clean::
	@echo "This command is intended for maintainers to use;"
	@echo "rebuilding the deleted files requires special tools."
	$(MAKE) distclean
	rm -f TAGS

PV = $(PACKAGE)-$(VERSION)

dist:: $(DISTFILES) $(DISTFILES_PC) $(DISTFILES_PC_DJGPP)
	rm -rf $(PV)
	mkdir $(PV) $(PV)/pc $(PV)/pc/djgpp
	cp -p $(DISTFILES) $(PV)
	cp -p $(DISTFILES_PC) $(PV)/pc
	cp -p $(DISTFILES_PC_DJGPP) $(PV)/pc/djgpp
	tar -chf - $(PV) | gzip -9 >$(PV).tar.gz
	rm -rf $(PV)

$(OBJS): config.h
addext.o: backupfile.h
argmatch.o: argmatch.h
backupfile.o: argmatch.h backupfile.h
basename.o: backupfile.h
getopt.o getopt1.o: getopt.h
maketime.o: maketime.h partime.h
inp.o: backupfile.h common.h inp.h pch.h util.h
partime.o: partime.h
patch.o: argmatch.h backupfile.h common.h getopt.h inp.h pch.h util.h version.h
pch.o: common.h inp.h pch.h util.h
quotearg.o: quotearg.h
util.o: backupfile.h common.h maketime.h partime.h quotearg.h util.h version.h
version.o: common.h patchlevel.h util.h version.h
