# Makefile for MBSE BBS under Linux
# Copyright (c) 1998, 2001 by M. Broek.
# $Id$

include ../Makefile.global

SRCS		= commonio.c putpwent.c salt.c sgetpwent.c xmalloc.c myname.c encrypt.c \
		  pwio.c shadowio.c mbpasswd.c mbuseradd.c rad64.c getdef.c pw_util.c \
		  mblogin.c env.c chowntty.c shell.c basename.c pwdcheck.c pwauth.c \
		  loginprompt.c utmp.c limits.c setupenv.c sub.c log.c setugid.c
HDRS		= commonio.h putpwent.h salt.h sgetpwent.h xmalloc.h myname.h encrypt.h \
		  pwio.h shadowio.h mbpasswd.h mbuseradd.h rad64.h getdef.h pw_util.h \
		  mblogin.h env.h chowntty.h shell.h basename.h pwdcheck.h pwauth.h \
		  loginprompt.h utmp.h limits.h setupenv.h sub.h log.h setugid.h
MBUSERADD_OBJS	= mbuseradd.o xmalloc.o
MBPASSWD_OBJS	= mbpasswd.o commonio.o pwio.o shadowio.o sgetpwent.o \
		  xmalloc.o myname.o rad64.o salt.o getdef.o encrypt.o putpwent.o pw_util.o
MBLOGIN_OBJS	= getdef.o env.o chowntty.o shell.o basename.o pwdcheck.o pwauth.o encrypt.o \
		  loginprompt.o utmp.o limits.o setupenv.o sub.o xmalloc.o log.o setugid.o \
		  mblogin.o
OTHER		= Makefile login.defs.in
TARGET		= mbuseradd mbpasswd mblogin

#############################################################################################################

.c.o:
		${CC} ${CFLAGS} ${INCLUDES} ${DEFINES} -c $<

all:		${TARGET}

clean: 
		rm -f ${TARGET} *.o *.h~ *.c~ core filelist Makefile.bak

mbuseradd:	${MBUSERADD_OBJS}
		${CC} -o mbuseradd ${MBUSERADD_OBJS} ${LDFLAGS} ${LIBS}

mbpasswd:	${MBPASSWD_OBJS}
		${CC} -o mbpasswd ${MBPASSWD_OBJS} ${LDFLAGS} ${LIBS}

mblogin:	${MBLOGIN_OBJS}
		${CC} -o mblogin ${MBLOGIN_OBJS} ${LDFLAGS} ${LIBS}

install:	all
		@if [ "`id -un`" != "root" ] ; then \
			echo; echo " Must be root to install!"; echo; exit 3; \
		fi
		${INSTALL} -c -s -o ${ROWNER} -g ${RGROUP} -m 6711 mbuseradd  ${BINDIR}
		${INSTALL} -c -s -o ${ROWNER} -g ${RGROUP} -m 6711 mbpasswd   ${BINDIR}
		${INSTALL} -c -s -o ${ROWNER} -g ${RGROUP} -m 0755 mblogin    ${BINDIR}
		@if [ ! -f ${ETCDIR}/login.defs ] ; then \
			${INSTALL} -c    -o ${OWNER} -g ${GROUP}  -m 0644 login.defs ${ETCDIR} ; \
			echo "${INSTALL} -c    -o ${OWNER} -g ${GROUP}  -m 0644 login.defs ${ETCDIR}" ; \
		else \
			${INSTALL} -c    -o ${OWNER} -g ${GROUP}  -m 0644 login.defs ${ETCDIR}/login.defs.new ; \
			echo "${INSTALL} -c    -o ${OWNER} -g ${GROUP}  -m 0644 login.defs ${ETCDIR}/login.defs.new" ; \
		fi

filelist:	Makefile
		BASE=`pwd`; \
		BASE=`basename $${BASE}`; \
		(for f in ${SRCS} ${HDRS} ${OTHER} ; do echo ${PACKAGE}-${VERSION}/$${BASE}/$$f; done) >filelist

depend:
		@rm -f Makefile.bak; \
		mv Makefile Makefile.bak; \
		sed -e '/^# DO NOT DELETE/,$$d' Makefile.bak >Makefile; \
		${ECHO} '# DO NOT DELETE THIS LINE - MAKE DEPEND RELIES ON IT' \
		>>Makefile; \
		${ECHO} '# Dependencies generated by make depend' >>Makefile; \
		for f in ${SRCS}; \
		do \
		${ECHO} "Dependencies for $$f:\c"; \
		${ECHO} "`basename $$f .c`.o:\c" >>Makefile; \
		for h in `sed -n -e \
			's/^#[ 	]*include[ 	]*"\([^"]*\)".*/\1/p' $$f`; \
		do \
			${ECHO} " $$h\c"; \
			${ECHO} " $$h\c" >>Makefile; \
		done; \
		${ECHO} " done."; \
		${ECHO} "" >>Makefile; \
		done; \
		${ECHO} '# End of generated dependencies' >>Makefile

# DO NOT DELETE THIS LINE - MAKE DEPEND RELIES ON IT
# Dependencies generated by make depend
commonio.o: ../config.h commonio.h
putpwent.o: ../config.h putpwent.h
salt.o: ../config.h rad64.h getdef.h
sgetpwent.o: ../config.h sgetpwent.h
xmalloc.o: ../config.h xmalloc.h
myname.o: ../config.h
encrypt.o: ../config.h encrypt.h
pwio.o: ../config.h sgetpwent.h commonio.h putpwent.h pwio.h
shadowio.o: ../config.h commonio.h shadowio.h
mbpasswd.o: ../config.h encrypt.h rad64.h myname.h xmalloc.h pwio.h shadowio.h pw_util.h getdef.h mbpasswd.h
mbuseradd.o: ../config.h xmalloc.h mbuseradd.h
rad64.o: ../config.h rad64.h
getdef.o: ../config.h getdef.h
pw_util.o: ../config.h pw_util.h
mblogin.o: ../config.h mblogin.h ../lib/users.h getdef.h env.h chowntty.h basename.h shell.h pwdcheck.h pwauth.h loginprompt.h utmp.h limits.h setupenv.h sub.h log.h setugid.h
env.o: ../config.h mblogin.h xmalloc.h
chowntty.o: ../config.h mblogin.h getdef.h chowntty.h
shell.o: ../config.h mblogin.h basename.h shell.h
basename.o: ../config.h mblogin.h basename.h
pwdcheck.o: ../config.h mblogin.h pwauth.h pwdcheck.h
pwauth.o: ../config.h mblogin.h pwauth.h getdef.h encrypt.h
loginprompt.o: ../config.h mblogin.h getdef.h xmalloc.h env.h loginprompt.h
utmp.o: ../config.h mblogin.h utmp.h
limits.o: ../config.h mblogin.h limits.h
setupenv.o: ../config.h mblogin.h getdef.h xmalloc.h env.h setupenv.h
sub.o: ../config.h mblogin.h sub.h
log.o: ../config.h mblogin.h log.h
setugid.o: ../config.h mblogin.h getdef.h setugid.h
# End of generated dependencies
