#
# Makefile for udl
# (c) 1993-1996 Soenke Behrens, Devin Reade
#
# $Id: Makefile.unx,v 1.9 1996/02/11 20:05:48 gdr Exp $
#

# $(CC) _must_ be an ANSI compiler. Use gcc if your cc is not.
CC	= cc
BINDIR	= /usr/local/bin
MANDIR	= /usr/local/man/man1
INSTALL	= /usr/bin/install

# These are arguments to $(INSTALL)
MODE644		= -m 644
MODE755		= -m 755
OWNER_GROUP	= -o bin -g sys

# You should not have to modify anything beyond this point
##########################################################

#
# OS-dependant macros.  See the README for an explanation of these.
#

DEFINES_AIX	= -DBROKEN_REALLOC -D_POSIX_C_SOURCE -D_POSIX_SOURCE

DEFINES_Linux	= -DREADDIR_RETURNS_DOT -D_POSIX_C_SOURCE -D_POSIX_SOURCE \
		  -DHAS_ATEXIT

DEFINES_Solaris	= -DREADDIR_RETURNS_DOT -D_POSIX_C_SOURCE -D_POSIX_SOURCE \
		  -DBROKEN_DIRENT_STRUCT
LDLIBS_Solaris	= -lucb

DEFINES_SunOS	= -DREADDIR_RETURNS_DOT -D_POSIX_C_SOURCE -D_POSIX_SOURCE \
		  -DBROKEN_REALLOC

CFLAGS  = $(DEFINES_$(OS)) -O
LDFLAGS = $(LDFLAGS_$(OS)) -s
LDLIBS	= $(LDLIBS_$(OS))

OBJS	= udl.o udluse.o common.o globals.o

build:
	@os_string=`uname -sr | tr ' ' '_'`; \
	case $$os_string in \
	SunOS_4*)	os=SunOS;; \
	SunOS_5*)	os=Solaris;; \
	AIX*)		os=AIX;; \
	Linux*)		os=Linux;; \
	*) 	echo "don't know about OS $$os_string"; \
		exit -1;; \
	esac; \
	$(MAKE) udl -f Makefile.unx OS=$$os

udl: $(OBJS)
	$(CC) $(LDFLAGS) -o udl $(OBJS) $(LDLIBS)

udl.o: udlunix.c common.h
	$(CC) -c $(CFLAGS) -o udl.o udlunix.c

newudl.1: udl.1
	@echo "creating newudl.1"; \
	echo '/^.TH/ c\' > sed.script; \
	echo '.TH UDL 1 "15 January 1996" "Version 1.1.5"\
"Commands and Applications"' >>sed.script; \
	sed -f sed.script <udl.1 >newudl.1; \
	rm -f sed.script

install: newudl.1 build
	$(INSTALL) $(MODE755) $(OWNER_GROUP) udl   $(BINDIR)
	$(INSTALL) $(MODE644) $(OWNER_GROUP) newudl.1 $(MANDIR)/udl.1
	rm -f newudl.1

clean:
	-rm -f *.o *~ core

clobber: clean
	-rm -rf udl newudl.1 help

dist: clobber
	@echo "creating archive"; \
	cwd=`pwd`; \
	parent=`dirname $$cwd`; \
	dir=`basename $$cwd`; \
	cd $$parent; \
	archive=$$dir.tar.Z; \
	if [ -f $$archive ]; then \
	    echo "please move $$parent/$$archive out of the way, first"; \
	    exit -1; \
	fi; \
	tar -cf - $$dir | compress > $$archive

udluse.o common.o globals.o:: common.h
