#!/bin/make -f

# Copyright (c) 1986, Greg McGary
# @(#)makefile	1.3 86/11/06

# --------------------------------------------------------------------
# System Dependent Configuration:
#   Choose a pre-packaged set of options below, or roll your own.
#   The relevant options are as follows:
#
# * To use under unix, you MUST define '-DUNIX' in DEFS.
#
# * If you have the `PW' library which includes the regular-expression
#   funcions regcmp(3) and regex(3), then use `-DREGEX' in DEFS, and
#   `-lPW' in LIBS.  If you have the regular-expression functions
#   re_comp(3) and re_exec(3), use `-DRE_EXEC' in DEFS.  If you don't
#   have any regular-expression functions, don't add either to DEFS.
#
# * If you do not have the 4.2 directory access libraries, add `-lndir'
#   to LIBS, and define `-DNDIR' in DEFS. 
#
# * If your string libraries have index(3) and rindex(3) instead of
#   strchr(3) and strrchr(3), use `-DRINDEX' in DEFS.
#
# * If your compiler chokes on pointers to functions returning void,
#   use `-Dvoid=int' in DEFS.
#
# * If you have setlinebuf(3) in your stdio to set line-buffering on
#   a stream, use `-DERRLINEBUF' in DEFS.
#
# * If you have a System-III/V terminal driver, define `TERMIO' in DEFS.
#
# * If you have ranlib(1), define `RANLIB' as such.  If you don't have
#   it, set `RANLIB' to something harmless like `@:', or `echo'
# --------------------------------------------------------------------

# DEFS	=	-DUNIX -DREGEX -DNDIR -DTERMIO          # typical System-V defs
# DEFS	=	-DUNIX -Dvoid=int -DRINDEX -DRE_EXEC -DNDIR   # typical V7 defs
DEFS	=	-DUNIX -Dvoid=int -DRINDEX -DRE_EXEC -DERRLINEBUF    # BSD defs

# LIBS	=	-lndir -lPW	# typical System-V libs
# LIBS	=	-lndir	# typical V7 libs
LIBS	=	# typical BSD libs (none)

#RANLIB	=	@:	# system doesn't have ranlib (Sys-V)
RANLIB	=	ranlib	# system has ranlib (typically V7 & BSD)

# --------------------------------------------------------------------
# Compilation / Loading options:
#   Choose options to generate a system as an installed product,
#   for debugging, or for performance profiling.
# --------------------------------------------------------------------

# CCFLG	=	-g -DDEBUG 	# debugging
# CCFLG	=	-p	# profiling
CCFLG	=	-O	# production

# LDFLG	=	-g	# debugging
# LDFLG	=	-p	# profiling
LDFLG	=	# production

# --------------------------------------------------------------------

SHELL =		/bin/sh
TARGETS =	libid.a $(PROGS)
PROGS =		mkid lid idx fid $(LIDLINKS)
DESTINATION_DIR = /usr/local

LIDLINKS = 	gid aid eid
CFLAGS =	$(CCFLG) -I. $(DEFS)
LDFLAGS =	$(LDFLG) libid.a $(LIBS)

OFILES =	init.o getscan.o scan-c.o scan-asm.o bsearch.o hash.o \
		bitops.o basename.o gets0.o getsFF.o paths.o opensrc.o \
		stoi.o uerror.o document.o bitcount.o wmatch.o bitsvec.o \
		tty.o bzero.o

# --------------------------------------------------------------------

all:		$(TARGETS)

libid.a:	$(OFILES)
		ar rv $@ $?
		$(RANLIB) $@

mkid:		mkid.o libid.a
		$(CC) -o $@ $@.o $(LDFLAGS)

fid:		fid.o libid.a
		$(CC) -o $@ $@.o $(LDFLAGS)

lid:		lid.o libid.a
		$(CC) -o $@ $@.o $(LDFLAGS)

idx:		idx.o libid.a
		$(CC) -o $@ $@.o $(LDFLAGS)

$(LIDLINKS): lid
		-/bin/rm -f $@
		ln lid $@

install:	$(PROGS)
		mv $(PROGS) $(DESTINATION_DIR)

clean:
		rm -f $(TARGETS) *.o

id.tar:
		cd ..; tar cvbf 20 id/id.tar id/*.[ch1-8] id/makefile id/TODO id/TUTORIAL

id.tar.Z:	id.tar
		compress -b 14 <id.tar >id.tar.Z

id.shar:	id.shar-1 id.shar-2 id.shar-3

id.shar-1:
		shar $(SHARFLAGS) TUTORIAL TODO makefile *.h *.[1-8] >$@

id.shar-2:
		shar $(SHARFLAGS) [a-l]*.c >$@

id.shar-3:
		shar $(SHARFLAGS) [m-z]*.c >$@
