# makefile. - make the GNUish MS-DOS library
# Copyright (C) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
#
# The GNUish MS-DOS library 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 1, or (at your
# option) any later version.
#
# The GNUish MS-DOS library 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 the GNUish MS-DOS library; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#
# $Header: e:/gnu/lib/RCS/makefile 1.0.0.3 90/09/19 23:21:14 tho Exp $
#

# The name of the library and the memory model we want to create:
# Hint: use `make MODEL="s l"' to make only some memory models

LIBNAME	= gnulib_
MODELS	= s m c l

# Where to put the library and header files.

INSTALL	= cp -v
LIBDIR	= d:/usr/lib
INCDIR	= d:/usr/include

# The floppy drive and the zip archive for backups

DISK	= b:
ZIPFILE = gnulib.zip

LIBS	= $(addprefix $(LIBNAME), $(addsuffix .lib, $(MODELS))) _cwild.c

DEFINES	= -DUSG -DSTDC_HEADERS

CFLAGS	= -Ox -W4 -Za -I. $(DEFINES)
ARFLAGS = /noi -+

# Files

OBJS	= error.obj getopt.obj getopt1.obj glob.obj regex.obj \
	  xmalloc.obj xrealloc.obj ndir.obj pwd.obj
INCS	= getopt.h regex.h \
	  gnulib.h ndir.h pwd.h
SRCS	= error.c getopt.c getopt1.c glob.c regex.c \
	  xmalloc.c xrealloc.c _cwild.c ndir.c pwd.c
GNUFILES= getopt.h getopt.c getopt1.c error.c glob.c regex.h regex.c

GNUVER	= 1.1

RCSFILES = $(addprefix RCS/, $(SRCS) $(INCS) makefile)
MISC	 = readme copying changelo


# Main goal

.PHONY: all
all: $(LIBS)


# How to make the libraries:

%.lib:
	$(AR) $@ $(ARFLAGS) $(subst /,\\,$?), $(@:.lib=.lst),,

$(LIBNAME)s.lib: $(addprefix small/, $(OBJS))
$(LIBNAME)m.lib: $(addprefix medium/, $(OBJS))
$(LIBNAME)c.lib: $(addprefix compact/, $(OBJS))
$(LIBNAME)l.lib: $(addprefix large/, $(OBJS))


# Generate the object files for the different memory models in their
# subdirectories ...

small/%.obj: %.c small
	$(CC) -AS $(CFLAGS) $(CPPFLAGS) -c -Fo$@ $<

medium/%.obj: %.c medium
	$(CC) -AM $(CFLAGS) $(CPPFLAGS) -c -Fo$@ $<

compact/%.obj: %.c compact
	$(CC) -AC $(CFLAGS) $(CPPFLAGS) -c -Fo$@ $<

large/%.obj: %.c large
	$(CC) -AL $(CFLAGS) $(CPPFLAGS) -c -Fo$@ $<

small medium compact large:
	mkdir $@


# Dependencies:

$(addsuffix /regex.obj,		small medium compact large): regex.h
$(addsuffix /getopt1.obj,	small medium compact large): getopt.h
$(addsuffix /glob.obj,		small medium compact large): ndir.h gnulib.h
$(addsuffix /error.obj,		small medium compact large): gnulib.h
$(addsuffix /ndir.obj,		small medium compact large): ndir.h
$(addsuffix /pwd.obj,		small medium compact large): pwd.h
$(addsuffix /xmalloc.obj,	small medium compact large): gnulib.h
$(addsuffix /xrealloc.obj,	small medium compact large): gnulib.h


# Utilities:

tags: $(SOURCES) $(SPLIT_FILES)
	etags *.c $(SPLIT_FILES)

.PHONY: install
install: all _cwild.c
	$(INSTALL) $(LIBS) $(LIBDIR)
	$(INSTALL) $(INCS) $(INCDIR)

.PHONY: clean veryclean
clean:
	rm -fr small medium compact large DOS GNU
	rm -f *.bak *.tar *.z

veryclean: clean
	rm -f *.uue *.lib *.lst patches
	rcsclean *.c *.h makefile

.PHONY: zip disk
zip: $(ZIPFILE)
disk: $(DISK)/$(ZIPFILE)

$(ZIPFILE): $(RCSFILES) $(MISC)
	pkzip -P -r- $@ $?

$(DISK)/$(ZIPFILE): $(ZIPFILE)
	cp $< $@
	pkunzip -t $@ | grep -vw OK


.PHONY: dist
dist: gnulib-1.uue gnulib-2.uue

%.uue: %.tar
	compress < $< | uuencode $<.Z > $@

%.tar:
	tar -cf $@ $^

gnulib-1.tar: readme copying makefile \
	      $(filter-out regex.%, $(INCS) $(SRCS)) patches
gnulib-2.tar: readme copying $(filter regex.%, $(INCS) $(SRCS))

patches: $(addprefix DOS/, $(GNUFILES)) $(addprefix GNU/, $(GNUFILES))
	diff -c DOS GNU > $@

GNU/%: % gnu
	$(CO) -rGNU RCS/$< $@

DOS/%: % dos
	$(CO) RCS/$< $@

gnu dos:
	mkdir $@

.PHONY: test-dist
test-dist: gnulib-1.uue $(addprefix GNU/, $(GNUFILES)) \
		$(addprefix DOS/, $(GNUFILES))
	sed /\.tar\.Z/s//.Z/ gnulib-1.uue | uudecode
	compress -d < $ gnulib-1.Z | tar -xOf -  patches | patch -s -d DOS
	rm -f DOS/*~
	diff DOS GNU

#
# Local Variables:
# mode:Text
# ChangeLog:ChangeLog
# compile-command:make
# End:

