default: debug
o = .o
.SUFFIXES: .c $o
REGEX = regex$o
env = djgpp
# Makefile for GNU DIFF
# Copyright (C) 1988,1989,1991,1992,1993,1994 Free Software Foundation, Inc.
#
# This file is part of GNU DIFF.
#
# GNU DIFF 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.
#
# GNU DIFF 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 GNU DIFF; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

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

PACKAGE = diffutils
VERSION = 2.7.1

srcdir = .
VPATH = .

CC = gcc
INSTALL = xcopy
INSTALL_PROGRAM = xcopy
INSTALL_DATA = xcopy
MAKEINFO = makeinfo
TEXI2DVI = texi2dvi

CPPFLAGS =
DEFS = -DHAVE_CONFIG_H
CFLAGS = -Wall -O2
LDFLAGS = -s
LIBS =
LIBOBJS = pc$o

# Some System V machines do not come with libPW.
# If this is true for you, use the GNU alloca.o here.
ALLOCA =

prefix = c:\$(env)\docs
exec_prefix = c:\$(env)
edit_program_name = sed ''

bindir = $(exec_prefix)\bin

infodir = $(prefix)\info

DEFAULT_EDITOR_PROGRAM = edit
DIFF_PROGRAM = diff
NULL_DEVICE = nul
PR_PROGRAM = pr

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

# SHELL = /bin/sh
SUBSHELL = command >nul /c

# The source files for all of the programs.
diffutils_srcs = \
	analyze.c cmp.c cmpbuf.c cmpbuf.h context.c \
	diff.c diff.h diff3.c dir.c ed.c ifdef.c io.c \
	memchr.c normal.c quote.c sdiff.c side.c system.h \
	util.c waitpid.c
srcs = $(diffutils_srcs) \
	alloca.c error.c fnmatch.c fnmatch.h \
	getopt.c getopt.h getopt1.c regex.c regex.h xmalloc.c
distfiles = $(srcs) README INSTALL NEWS diagmeet.note Makefile.in \
	stamp-h.in config.hin configure configure.in COPYING ChangeLog \
	diff.texi diff.inf texinfo.tex \
	install-sh mkinstalldirs getmsgids messages.po version.c version.texi \
	pc/COPYING pc/INSTALL pc/config.h pc/makefile pc/makefile.sed pc/pc.c \
	pc/djgpp/config.h pc/djgpp/makefile.sed \
	pc/emx/config.h pc/emx/diff.def pc/emx/gnuregex.def pc/emx/makefile.sed

PROGRAMS = cmp diff diff3 sdiff

all: $(PROGRAMS) info

version.c:
	(echo '#include <config.h>' && \
	 echo 'char const version_string[] = "GNU $(PACKAGE) $(VERSION)"') >$@

version.texi: diff.texi
	(echo '@set VERSION $(VERSION)' && \
	 set `sed -n '/^.*\%%Id: diff.texi,v \([^ ]*\) \([^ ]*\).*/{ s//\1 \2/ s|/|-|g p q }' diff.texi` && \
	 echo "@set EDITION %%1" && \
	 echo "@set UPDATED %%2") >$@

COMPILE = $(CC) -c $(CPPFLAGS) $(DEFS) -I. -I$(srcdir) $(CFLAGS)

.c$o:
	$(COMPILE) $<

common_o = error$o getopt$o getopt1$o version$o xmalloc$o

diff_o = diff$o analyze$o cmpbuf$o dir$o io$o util$o \
	context$o ed$o ifdef$o normal$o side$o \
	fnmatch$o $(REGEX) $(common_o) $(ALLOCA) $(LIBOBJS)
diff: $(diff_o)
	$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(diff_o) $(LIBS)

diff3_o = diff3$o $(common_o) $(LIBOBJS)
diff3: $(diff3_o)
	$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(diff3_o) $(LIBS)

sdiff_o = sdiff$o $(common_o) $(LIBOBJS)
sdiff: $(sdiff_o)
	$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(sdiff_o) $(LIBS)

cmp_o = cmp$o cmpbuf$o $(common_o) $(LIBOBJS)
cmp: $(cmp_o)
	$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(cmp_o) $(LIBS)

info: diff.inf
diff.inf: diff.texi version.texi
	$(MAKEINFO) --no-split $(srcdir)/diff.texi --output=$@

dvi: diff.dvi
diff.dvi: diff.texi
	$(TEXI2DVI) $(srcdir)/diff.texi

$(diff_o): diff.h system.h
cmp$o diff3$o sdiff$o: system.h
context$o diff$o regex$o: regex.h
cmp$o diff$o diff3$o sdiff$o getopt$o getopt1$o: getopt.h
diff$o fnmatch$o: fnmatch.h
analyze$o cmpbuf$o cmp$o: cmpbuf.h

cmp$o: cmp.c
	$(COMPILE) -DNULL_DEVICE=\"$(NULL_DEVICE)\" $(srcdir)/cmp.c

diff3$o: diff3.c
	$(COMPILE) -DDIFF_PROGRAM=\"$(DIFF_PROGRAM)\" $(srcdir)/diff3.c

sdiff$o: sdiff.c
	$(COMPILE) -DDEFAULT_EDITOR_PROGRAM=\"$(DEFAULT_EDITOR_PROGRAM)\" \
		-DDIFF_PROGRAM=\"$(DIFF_PROGRAM)\" $(srcdir)/sdiff.c

util$o: util.c
	$(COMPILE) -DPR_PROGRAM=\"$(PR_PROGRAM)\" $(srcdir)/util.c

TAGS: $(srcs)
	etags $(srcs)

messages.po: getmsgids $(diffutils_srcs)
	./getmsgids $(diffutils_srcs) >$@

clean: pc-clean
	$(SUBSHELL) for %%f in (*.o $(PROGRAMS) core) do del %%f
	$(SUBSHELL) for %%f in (*.aux *.cp *.cps *.dvi *.fn *.fns *.ky *.kys *.log) do del %%f
	$(SUBSHELL) for %%f in (*.pg *.pgs *.toc *.tp *.tps *.vr *.vrs) do del %%f

mostlyclean: clean

distclean: clean
	$(SUBSHELL) for %%f in (Makefile config.cache config.h config.log config.status stamp-h) do del %%f

realclean: distclean
	$(SUBSHELL) for %%f in (TAGS *.inf messages.po version.*) do del %%f

install: all installdirs
	$(SUBSHELL) for %%p in ($(PROGRAMS)) do $(INSTALL_PROGRAM) %%p.exe $(bindir)
	$(SUBSHELL) $(INSTALL_DATA) diff.inf $(infodir)

installdirs:
	$(SUBSHELL) for %%d in ($(exec_prefix) $(prefix) $(bindir) $(infodir)) do md %%d

# We need more tests.
check: $(PROGRAMS)
	./cmp cmp cmp
	./diff diff diff
	./diff3 diff3 diff3 diff3
	./sdiff sdiff sdiff

uninstall:
	$(SUBSHELL) for %%p in ($(PROGRAMS)) do del $(bindir)\%%p.exe
	$(SUBSHELL) for %%f in ($(infodir)\diff.inf*) do del %%f

configure: configure.in
	cd $(srcdir) && autoconf

# autoheader might not change config.hin.
config.hin: stamp-h.in
stamp-h.in: configure.in
	cd $(srcdir) && autoheader
	date > $(srcdir)/stamp-h.in

config.status: configure
	./config.status --recheck

# config.status might not change config.h, but it changes stamp-h.
#config.h: stamp-h
stamp-h: config.hin config.status
	./config.status
D = $(PACKAGE)-$(VERSION)
D_dirs = $D $D\pc $D\pc\djgpp $D\pc\emx

$D.tar.gz: $(distfiles)
	rm -rf $D
	mkdir $(D_dirs)
	chmod a+rwx $(D_dirs)
	for file in $(distfiles) do \
	  ln %%file $D/%%file 2>/dev/null || cp -p %%file $D/%%file \
	tar -chf - $D | gzip >$@
	rm -rf $D

# Prevent GNU make v3 from overflowing arg limit on SysV.
.NOEXPORT:


# Additional rules for pc makefiles.

makefile : Makefile.in pc/makefile pc/makefile.sed pc/$(env)/makefile.sed
	sed -f pc/makefile.sed -f pc/$(env)/makefile.sed <Makefile.in >$@

COPY = copy
config.h: pc/$(env)/config.h
	$(COPY) pc\$(env)\config.h $@
# Use `\' in previous line: `copy' requires it.

$(diff_o) $(cmp_o) $(sdiff_o) $(diff3_o): config.h pc/config.h
$(PROGRAMS): $(LIBS)

pc$o: pc/pc.c
	$(COMPILE) pc/pc.c -o $@

debug dos-debug: config.h
	$(MAKE) all \
		'CFLAGS=-g -O -Wall' \
		LDFLAGS=
dos-release: config.h all

os2-debug : dos-debug
os2-release: config.h
	$(MAKE) all gnuregex.dll \
		'CFLAGS=-Zomf -Zmtd -O2 -Wall' \
		LDFLAGS=-s \
		o=.obj \
		REGEX=regex.lib
gnuregex.dll: regex$o pc/$(env)/gnuregex.def
	$(CC) $(CFLAGS) -Zdll regex$o -o $@ pc/$(env)/gnuregex.def
regex.lib : pc/$(env)/gnuregex.def
	emximp -o $@ pc/$(env)/gnuregex.def

pc-clean:
	$(SUBSHELL) for %%f in (*.o* *.bat *.dll *.lib *.exe fname) do del %%f

# dist.bat must use `\', since DOS tools require it.
dist:
	sed -e /version_string/!d -e "s/[^0-9]*\([0-9a-z.]*\).*/diff-\1/" -e "s/\([0-9]\)\./\1/g" -e q version.c > fname
	echo @echo off > dist.bat
	sed -e "s|.*|md ..\\\&|" fname >> dist.bat
	sed -e "s|.*|del ..\\\&\\\*.*|" fname >> dist.bat
	sed -e "s|.*|xcopy *.* ..\\\& /s/e|" fname >> dist.bat
	sed -e "s|.*|del ..\\\&\\\*.o*|" fname >> dist.bat
	sed -e "s|.*|del ..\\\&\\\diff*|" fname >> dist.bat
	sed -e "s|.*|del ..\\\&\\\sdiff|" fname >> dist.bat
	sed -e "s|.*|del ..\\\&\\\cmp|" fname >> dist.bat
	sed -e "s|.*|del ..\\\&\\\dist.bat|" fname >> dist.bat
	sed -e "s|.*|del ..\\\&\\\fname|" fname >> dist.bat
	sed -e "s|.*|del ..\\\&\\\~*.*|" fname >> dist.bat
	echo cd .. >> dist.bat
	sed -e "s|.*|pkzip -rPmex &.zip &\\\*.*|" fname >> dist.bat
	./dist.bat
