# Makefile for login program and other related utils.
# By poe@daimi.aau.dk
# All this code is freely distributable.

CC     = cc

# Add -DSHADOW_PWD to CFLAGS too compile with support for shadow passwords
# Add -DSET_TZ to make simpleinit set the timezone from /etc/TZ
CFLAGS = -O3 -I.
LDFLAGS= -s

# Set LIBS = -lshadow if you want to support shadow passwords
LIBS   =

loginobj = login.o getpass.o
whoobj = who.o
gettyobj = agetty.o
initobj = simpleinit.o
writeobj = write.o

.SUFFIXES: .c .o
.c.o:
	${CC} ${CFLAGS} -c $*.c

all:	login who getty hostname init write domainname

install: all
	-mv /etc/init /etc/init.old
	cp init /etc 
	-mv /etc/getty /etc/getty.old
	cp getty /etc
	chown bin.bin /etc/init /etc/getty
	chmod 544 /etc/init /etc/getty
	cp login /bin
	chown root.bin /bin/login
	chmod a=rx,u+s /bin/login
	cp who hostname domainname write users mesg /usr/bin
	-ln -s /usr/bin/write /usr/bin/wall
	# -ln -s /dev/tty0 /dev/console
	touch /etc/utmp /etc/wtmp /etc/lastlog
	chown root.adm /etc/utmp /etc/wtmp /etc/lastlog
	chmod u=rw,og=r /etc/utmp /etc/wtmp /etc/lastlog

Install: install
	cp inittab securetty issue motd /etc

install-man:
	cp *.1 /usr/man/man1
	cp *.8 /usr/man/man8
	@echo Now you must run catman to format the manual pages

init:	${initobj}
	${CC} $(LDFLAGS) -static -o init ${initobj} $(LIBS)

getty:	${gettyobj}
	${CC} $(LDFLAGS) -static -o getty ${gettyobj}

login:	$(loginobj)
	$(CC) $(LDFLAGS) -static -o login $(loginobj) $(LIBS)

who:	$(whoobj)
	$(CC) $(LDFLAGS) -o who $(whoobj)

hostname:	hostname.o
	$(CC) $(LDFLAGS) -o hostname hostname.o

write:	$(writeobj)
	$(CC) $(LDFLAGS) -o write $(writeobj) $(LIBS)

clean:
	rm -f *.o

real-clean:
	rm -f *.o login who getty hostname domainname init write
