# Makefile for gzip (GNU zip)    -*- Makefile -*-
# Copyright (C) 1992-1993 Jean-loup Gailly and the Free Software Foundation
# Modified for GNUish make/MS_SH200/DJGPP 1.09+ by Eric Backus
# Modified for GNU Make 3.75 or later and Bash 1.14.7 by Eli Zaretskii

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

# $Id: Makefile.djg,v 1.3 1993/06/22 15:43:24 jloup Exp $

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

srcdir = .
VPATH = $(srcdir)

CC = gcc

# Use ginstall, not install, so that some other install.exe, like
# from Windows or some game, won't get run by chance.
INSTALL = ginstall -c
INSTALL_PROGRAM = $(INSTALL)
INSTALL_DATA = $(INSTALL) -m 644

# tailor.h defines things for DJGPP so nothing is needed here
CPPFLAGS =
DEFS =
LIBS =

# additional sources for particular systems may be required.
OBJA = match$O tailor$O

SEDCMD = 1d

CFLAGS = -O2 -fomit-frame-pointer
LDFLAGS = -s

# To install znew, zmore, etc... as gznew, gzmore... use: G=g
G=

# To install zcat executable and man page as gzcat, use: ZCAT=gzcat
ZCAT=zcat

X=.exe
O=.o

prefix = ${DJDIR}
exec_prefix = $(prefix)

bindir = $(exec_prefix)/bin
# scriptdir is the directory in which shell scripts should be installed
scriptdir = $(bindir)
datadir = $(prefix)/lib
libdir = $(prefix)/lib
infodir = $(prefix)/info

# Extension (not including `.') for the installed manual page filenames.
manext = 1
# Where to install the manual pages.
mandir = $(prefix)/info

alldirs = $(bindir) $(scriptdir) $(datadir) $(libdir) $(infodir) $(mandir)

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

# /bin/sh or its workalike is required to run the install targets.
SHELL = /bin/sh

LOADLIBES = $(LIBS)

TAR = tar

SRCS = gzip.c zip.c deflate.c trees.c bits.c unzip.c inflate.c util.c crypt.c\
       lzw.c unlzw.c unpack.c unlzh.c getopt.c match.S

OBJS = gzip$O zip$O deflate$O trees$O bits$O unzip$O inflate$O util$O \
       crypt$O lzw$O unlzw$O unpack$O unlzh$O getopt$O $(OBJA)

HDRS = gzip.h lzw.h tailor.h revision.h crypt.h getopt.h

GENFILES =  README NEWS INSTALL Makefile.in configure.in configure COPYING \
  TODO THANKS ChangeLog $(SRCS) $(HDRS) zmore.in znew.in zdiff.in zgrep.in \
  zforce.in gzexe.in gzip.1 zdiff.1 zgrep.1 zmore.1 znew.1 gzexe.1 zforce.1 \
  gzip.doc algorithm.doc gzip.texi texinfo.tex gpl.texinfo gzip.info install-sh

sampleFILES =  sample/makecrc.c sample/zread.c sample/add.c sample/sub.c \
       sample/ztouch sample/zfile

msdosFILES = msdos/tailor.c msdos/match.asm msdos/gzip.prj msdos/doturboc.bat \
  msdos/Makefile.msc msdos/Makefile.bor msdos/Makefile.djg msdos/Makefile.dj2

os2FILES = os2/Makefile.os2 os2/gzip.def os2/gzip16.def

ntFILES = nt/Makefile.nt

vmsFILES = vms/Readme.vms vms/Makefile.vms vms/Makefile.gcc vms/makegzip.com \
   vms/Makefile.mms vms/vms.c vms/gzip.hlp

amigaFILES = amiga/Makefile.sasc amiga/Makefile.gcc amiga/tailor.c \
  amiga/utime.h amiga/match.a

atariFILES = atari/Makefile.st

primosFILES = primos/readme primos/primos.c primos/ci.opts \
   primos/build.cpl primos/include/errno.h primos/include/fcntl.h \
   primos/include/stdlib.h primos/include/sysStat.h primos/include/sysTypes.h

DISTFILES = $(GENFILES) $(sampleFILES) $(msdosFILES) $(os2FILES) $(ntFILES)\
   $(vmsFILES) $(amigaFILES) $(atariFILES) $(primosFILES)

SCRIPTS = $(G)zdiff $(G)zgrep $(G)zmore $(G)znew $(G)zforce gzexe

.c$O:
	$(CC) -c $(CPPFLAGS) $(DEFS) $(CFLAGS) $<

#.PHONY: default all force test check

default:  gzip$X
all:	gzip$X $(G)zdiff $(G)zgrep $(G)zmore $(G)znew $(G)zforce gzexe
force:

install: installdirs installbin installman

installbin: all
	$(INSTALL_PROGRAM) gzip$X $(bindir)/gzip$X
	for f in $(SCRIPTS); do \
	  $(INSTALL_PROGRAM) $${f} $(scriptdir)/$${f}; done
	rm -f $(scriptdir)/$(G)zcmp; \
	  ln $(scriptdir)/$(G)zdiff $(scriptdir)/$(G)zcmp
	for f in gunzip$X ungzip$X $(ZCAT)$X ; do \
	  rm -f $(bindir)/$${f}; done
	ln -s $(bindir)/gzip$X $(bindir)/gunzip$X
	ln -s $(bindir)/gzip$X $(bindir)/$(ZCAT)$X

installman: gzip.info
	for f in gzip gunzip $(ZCAT) $(SCRIPTS) $(G)zcmp; do \
	  rm -f $(mandir)/$${f}.$(manext); done
	-cd $(srcdir); for f in gzip gzexe; do \
	  $(INSTALL_DATA) $${f}.1 $(mandir)/$${f}.$(manext); done
	-cd $(srcdir); for f in zdiff zgrep zmore znew zforce; do \
	  $(INSTALL_DATA) $${f}.1 $(mandir)/$(G)$${f}.$(manext); done
	-cd $(mandir); \
	  ln gzip.$(manext)  $(ZCAT).$(manext);\
	  ln $(G)zdiff.$(manext) $(G)zcmp.$(manext);\
	  ln gzip.$(manext)  gunzip.$(manext)
	-cd $(srcdir); for f in gzip.i* ; do $(INSTALL_DATA) $${f} \
	  $(infodir)/$${f}; done

uninstall: force
	-cd $(bindir); rm -f gzip$X gunzip$X $(ZCAT)$X
	-cd $(scriptdir); rm -f $(SCRIPTS) $(G)zcmp
	-for f in gzip gunzip $(ZCAT) $(SCRIPTS) $(G)zcmp; do \
	  rm -f $(mandir)/$${f}.$(manext); done
	-cd $(infodir); rm -f gzip.i*

# install all files and replace compress (not recommended)
install_compress: install
	-test -f $(bindir)/compress.old || \
	  mv $(bindir)/compress$X $(bindir)/compress.old
	ln -s $(bindir)/gzip$X $(bindir)/compress$X
	rm -f $(bindir)/uncompress$X
	ln -s $(bindir)/gzip$X $(bindir)/uncompress$X

# Make sure all installation directories, e.g. $(bindir) actually exist by
# making them if necessary.  Use gmkdir, to make sure COMMAND.COM's internal
# command is never invoked.
installdirs:
	-for dir in $(alldirs) ; do \
	   if test ! -d $${dir}; then \
	     gmkdir -p $${dir}; fi; \
	done

test: check
check:	gzip$X
	./gzip -6 < $(srcdir)/texinfo.tex > _gztest.gz
	@LANG=""; export LANG; if test `wc -c < _gztest.gz` -eq 30890; then \
	   true; \
	else \
	   echo FAILED gzip test: incorrect size; \
	fi
	rm -f _gztest
	./gzip -d _gztest.gz
	@if cmp _gztest $(srcdir)/texinfo.tex; then \
	   echo gzip test OK; \
	else \
	   echo FAILED gzip test: incorrect decompress; \
	fi
	rm -f _gztest*


TAGS: $(SRCS) $(HDRS)
	cd $(srcdir); etags $(SRCS) msdos/tailor.c $(HDRS)

makefile: msdos/Makefile.dj2
	sed -e '' $< > $@

clean:
	rm -f *$O gzip$X gunzip$X ungzip$X $(ZCAT)$X add$X sub$X a.out core
	rm -f $(G)zcmp $(SCRIPTS) _gztest*
	rm -f *.aux *.cp *.cps *.dvi *.fn *.fns *.ky *.kys *.log
	rm -f *.pg *.pgs *.toc *.tp *.tps *.vr *.vrs

mostlyclean: clean

distclean: clean
	rm -f makefile config.cache config.status

realclean: distclean
	rm -f TAGS gzip.i* gzip.doc

dist: $(DISTFILES) makefile
	d=gzip`sed -e '/VERSION/!d' -e 's/[^0-9.]*\([0-9.]*\).*/\1/' \
	            -e 's/[.]//g -e q revision.h` ; \
	rm -f ../$$d; \
	cp -pr . ../$$d; \
	cd ..; \
	files=""; \
	for f in $(DISTFILES); do files="$$files $$d/$$f"; done; \
	$(TAR) chof - $$files | gzip -9 >$$d/$$d.tgz; \
	rm -f $$d

zipdist: $(DISTFILES) makefile
	zip -u9T gzip`sed -e '/VERSION/!d' -e 's/[^0-9.]*\([0-9.]*\).*/\1/' \
			  -e s/[.]//g -e q revision.h` $(DISTFILES)

# Actual build-related targets

gzip$X:	makefile $(OBJS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
	command.com /c 'for %f in (gunzip$X $(ZCAT)$X) do if exist %f del %f'
	stubify -g gunzip$X; stubedit gunzip$X runfile=gzip
	stubify -g $(ZCAT)$X; stubedit $(ZCAT)$X runfile=gzip

gzip$O zip$O deflate$O trees$O bits$O unzip$O inflate$O: gzip.h tailor.h
util$O lzw$O unlzw$O unpack$O unlzh$O crypt$O tailor$O: gzip.h tailor.h

gzip$O unlzw$O: revision.h lzw.h

bits$O unzip$O util$O zip$O: crypt.h

gzip$O getopt$O: getopt.h

match$O: match.S
	$(CC) -c $<

tailor$O: msdos/tailor.c
	$(CC) -c $(CPPFLAGS) -I$(srcdir) $(DEFS) $(CFLAGS) -o $@ $<

$(G)zdiff: zdiff.in
	sed -e "$(SEDCMD)" -e "s|BINDIR:|$(bindir);|" $(srcdir)/zdiff.in > $@

$(G)zgrep: zgrep.in
	sed -e "$(SEDCMD)" -e "s|BINDIR:|$(bindir);|" $(srcdir)/zgrep.in > $@

$(G)zmore: zmore.in
	sed -e "$(SEDCMD)" -e "s|BINDIR:|$(bindir);|" $(srcdir)/zmore.in > $@

$(G)znew: znew.in
	sed -e "$(SEDCMD)" -e "s|BINDIR:|$(bindir);|" $(srcdir)/znew.in > $@

$(G)zforce: zforce.in
	sed -e "$(SEDCMD)" -e "s|BINDIR:|$(bindir);|" $(srcdir)/zforce.in > $@

gzexe: gzexe.in
	sed -e "$(SEDCMD)" -e "s|BINDIR:|$(bindir);|" $(srcdir)/gzexe.in > $@

gzip.info: gzip.texi
	cd $(srcdir); makeinfo gzip.texi

gzip.dvi: gzip.texi
	cd $(srcdir); texi2dvi gzip.texi

gzip.doc: gzip.1
	groff -man $(srcdir)/gzip.1 > gzip.doc

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

# end of file
