#
# Copyright (c) 1988 Regents of the University of California.
# All rights reserved.
#
# Redistribution and use in source and binary forms are permitted
# provided that the above copyright notice and this paragraph are
# duplicated in all such forms and that any documentation, advertising
# materials, and other materials related to such redistribution and
# use acknowledge that the software was developed by the University
# of California, Berkeley.  The name of the University may not be
# used to endorse or promote products derived from this software
# without specific prior written permission.  THIS SOFTWARE IS PROVIDED
# ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
# WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND
# FITNESS FOR A PARTICULAR PURPOSE.
#
# @(#)Makefile	5.2 (Berkeley) 6/26/89
#

#
#  System dependent defines:
#	USE_GETWD	BSD-style   getwd()
#	USE_GETCWD	SysV-style  getcwd()	(default)
#	USE_UTIMES	BSD-style   utimes()
#	USE_UTIME	SysV-style  utime()	(default)
#	USE_MKDEV	Use SysV-style macroes
#	NO_GETPW	Do not use getpwuid(), getgruid() routines!
#

#INSTALL=install		# BSD-install behaviour expected.
#INSTOWNER=-o root
#INSTALL=install -S
INSTALL=/p/gnu/bin/install
INSTOWNER=-u root


CDEFS=-DUSE_GETCWD -DUSE_MKDEV -DNO_GETPW -DDO_FCNTL_LOCK	# Solaris 2.3
#CDEFS=-DUSE_GETWD -DNO_GETPW -DUSE_UTIMES	# SunOS 4.1.3
#CDEFS=-DUSE_GETCWD -DNO_GETPW -DUSE_UTIME	# OSF/1 v 3.x
CFLAGS=	-DWITHIN_FTPDLS $(CDEFS) #-Wall
CC=gcc -g -O -Wall
STATIC=-static
#CC=cc -O -migrate	# OSF/1 Alpha
#STATIC=-non_shared	# OSF/1

LIBC=	/lib/libc.a
SRCS=	cmp.c ls.c print.c util.c readdir.c namemap.c
OBJS=	cmp.o ls.o print.o util.o readdir.o namemap.o
MAN=	ls.0

all: ls ls-regen ls-namemap

ls: ${OBJS}
	${CC} $(STATIC) -o $@ ${CFLAGS} ${OBJS}

ls-regen: ls-regen.o
	${CC} -o $@ ${CFLAGS} ls-regen.o

ls-regen.o: ls-regen.c

ls-namemap: ls-namemap.o
	${CC} -o $@ ${CFLAGS} ls-namemap.o

ls-namemap.o: ls-namemap.c namemap.h
print.o: ls.h namemap.h
namemap.o: namemap.c namemap.h ls.h
ls.o: ls.c ls.h readdir.h
readdir.o: readdir.c readdir.h

clean:
	rm -f *.o core ls ls-regen ls-namemap *~ \#*\#

cleandir: clean
	rm -f ${MAN} tags .depend

depend: ${SRCS}
	mkdep -p ${CFLAGS} ${SRCS}

#install: ${MAN}
#	$(INSTALL) -s -o bin -g bin -m 755 ls ${DESTDIR}/bin
#	$(INSTALL) -c -o bin -g bin -m 444 ${MAN} ${DESTDIR}/usr/man/cat1

lint: ${SRCS}
	lint ${CFLAGS} ${SRCS}

tags: ${SRCS}
	ctags ${SRCS}

install: install-tag-regen install-tag-namemap install-tag-ls

install-tag-regen: ls-regen
	cp ls-regen /l/bin/ls-regen
	-strip /l/bin/ls-regen
	chown root /l/bin/ls-regen
	chmod 4755 /l/bin/ls-regen
	touch install-tag-regen

install-tag-namemap: ls-namemap
	$(INSTALL) -m 755 ls-namemap /l/bin/ls-namemap
	touch install-tag-namemap

install-tag-ls: ls
	cp ls /ftp/bin/ls.x
	chmod 755 /ftp/bin/ls.x
	mv /ftp/bin/ls.x /ftp/bin/ls.ftpd
	touch install-tag-ls

dist:	clean
	@echo "#  For NIC.FUNET.FI environment"
	cd ..; tar -cf - ls | gzip > /pub/local/src/ftpd-ls.tar.gz
