#! /bin/make -f
#
#	a very simple Makefile for libdlst
#

#ident	"@(#)dlst:Makefile	1.6	92/10/12 16:34:09 (woods)"

SHELL = /bin/sh

LOCAL = /local

BINDIR = $(LOCAL)/bin
LIBDIR = $(LOCAL)/lib
INCDIR = $(LOCAL)/include
MANEXT = 3
MANDIR = $(LOCAL)/man/man$(MANEXT)

# Select the right definition for your system, unless you are compiling on
# one of the following:  SunOS, ULTRIX, AIX, XENIX.
# 
#	v7:	SYSTYPE= -DV7		/* UNTESTED "The Real Thing!"(tm) ;-) */
#   any BSD:	SYSTYPE= -DBSD
#	SysIII: SYSTYPE= -DSYSIII	/* UNTESTED */
#	SysV:	SYSTYPE= -DSYSV	 	/* generic AT&T or USG unix */
#	SysVr1:	SYSTYPE= -DSYSVR1	/* UNTESTED i.e. the original SysV */
#	SysVr2:	SYSTYPE= -DSYSVR2	/* yes, 3b1'ers, this is you too! */
#	SysVr3: SYSTYPE= -DSYSVR3
#	SysVr4: SYSTYPE= -DSYSVR4
#   any P1003.1:SYSTYPE= -D_POSIX_SOURCE
#
CC		= /usr/5bin/cc
LINT		= /usr/5bin/lint
SYSTYPE		= -DSYSVR3

# NOTE:  you'll have to define DUMB_VOID if your compiler doesn't fully
# understand the 'void' keyword.  (The most common error indicating this
# symptom is "operands of ':' have incompatible types" for invocations of the
# lst_top()/lst_bottom() macros.)  If it doesn't understand 'void' at all,
# then you should also define REDEF_VOID.
#
#DEFS = $(SYSTYPE) -DDUMB_VOID
#DEFS = $(SYSTYPE) -DDUMB_VOID -DREDEF_VOID
#
DEFS = $(SYSTYPE)

# Use 'make DEBUG=-DDEBUG' to compile in debugging code
# Use 'make DEBUG=-DNDEBUG' to turn off assert()s
#
DEBUG = 

# Use 'make OPTIM= SDB=-g' to build for a debugger
#
OPTIM = -O
SDB = 

CFLAGS = $(OPTIM) $(SDB) -I$(INCDIR) $(DEFS) $(DEBUG)
LDFLAGS = -L$(LIBDIR)

# Another sample:
#
#CFLAGS = $(OPTIM) $(SDB) -I$(LOCAL)/include $(DEBUG) $(DEFS) -pipe -ansi \
#	-Wall -Wshadow -Wpointer-arith -Wcast-qual -Wwrite-strings \
#	-Dscanf=DONT_USE_SCANF -Dgets=DONT_USE_GETS
#CC = gcc

LINTARGS = -ax -p
LINTARGS = -ax

LIB = dlst
LIBRARY = lib$(LIB).a
LINTLIB = llib-l$(LIB).ln
MANPAGES = $(LIB).nro

OBJECTS = list.o alist.o llist.o
SOURCES = list.c alist.c llist.c
INCLUDES = $(LIB).h
OTHER = README Makefile-dist
DOCS = $(LIB).3

# for making distributions only!
#
EXTERN_HDRS = ../../head/sccsid.h ../../head/sysdefs.h ../../head/libc.h

default: $(LIBRARY)

all: $(LIBRARY) $(LINTLIB)

lib$(LIB).a: $(OBJECTS)
	ar ru $(LIBRARY) $(OBJECTS)
	-ranlib $(LIBRARY)

list.o: $(INCLUDES)
alist.o: $(INCLUDES)
llist.o: $(INCLUDES)

install:	$(LIBRARY) $(LINTLIB) $(INCLUDES) $(DOCS)
	cp $(LIBRARY) $(LIBDIR)
	cp llib-l$(LIB).ln $(LIBDIR)
	cp $(INCLUDES) $(INCDIR)
	cp $(DOCS) $(MANDIR)

lintlibrary $(LINTLIB):	$(SOURCES) $(INCLUDES)
	$(LINT) $(LINTARGS) -o $(LIB) $(DEFS) -I$(INCDIR) $(SOURCES)

lint:
	$(LINT) $(LINTARGS) $(DEFS) -I$(INCDIR) $(SOURCES)

clean:
	rm -f $(OBJECTS) core

clobber: clean
	rm -f $(LIBRARY) $(LINTLIB)

shar: $(LIB).shar

# using 'make dist' prevents ever patching Makefile-dist...
#
dist: $(LIB).shar Makefile-dist

fulldist: fullshar Makefile-dist

cleandist:
	rm -f $(LIB).shar

Makefile-dist:	Makefile
	@echo "Are you sure? [<DEL> to abort] \c"; read junk
	rm -f Makefile-dist
	cp Makefile Makefile-dist

$(LIB).shar: $(OTHER) $(DOCS) $(INCLUDES) $(SOURCES)
	shar -b -t 'Please read the file README first' \
		$(OTHER) $(DOCS) $(INCLUDES) $(SOURCES) > $(LIB).shar

fullshar: $(OTHER) $(DOCS) $(INCLUDES) $(SOURCES) externhdr.shar
	shar -b -t 'Please read the file README first' \
		$(OTHER) $(DOCS) $(INCLUDES) $(SOURCES) externhdr.shar > $(LIB).shar

externhdr.shar: $(EXTERN_HDRS) Makefile
	shar -b -t 'Please install in local include directory' \	
		$(EXTERN_HDRS) > externhdr.shar
