#
# Makefile	Makefile for the systemV init suite.
#		Targets:   all      compiles everything
#		           install  installs the binaries (not the scripts)
#		           tar      creates tar.gz file
#                          clean    cleans up
#
# Version:	@(#)Makefile  2.57a  10-Jul-1994  MvS
#

NAME  = sysvinit-2.57a
DIR   = init-2.57a

CC	= cc
CFLAGS	= -N -Wall -O6
LDFLAGS	= -s

PROGS	= init halt last mesg shutdown wall utmpdump powerd killall5 runlevel

# Test for OWLD/Linux
ifndef BIN_OWNER
BIN_OWNER	= bin
BIN_GROUP	= bin
endif
BIN_COMBO	= $(BIN_OWNER).$(BIN_GROUP)
INSTALL		= install -o $(BIN_OWNER) -g $(BIN_GROUP)


all:		$(PROGS)

init:		init.c

shutdown.o:	shutdown.c

halt:		halt.c
		$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<

last:		last.c

mesg:		mesg.c

utmpdump:	utmpdump.c

powerd:		powerd.c

wall:		dowall.o wall.o
		$(CC) $(CFLAGS) $(LDFLAGS) -o $@ dowall.o wall.o

shutdown:	dowall.o shutdown.o
		$(CC) $(CFLAGS) $(LDFLAGS) -o $@ dowall.o shutdown.o

dowall.o:	dowall.c

wall.o:		wall.c

runlevel:	runlevel.c

killall5:	killall5.c

cleanobjs:
		rm -f *.o *.bak

clean:		cleanobjs
		@echo Type \"make clobber\" to really clean up.

clobber:	cleanobjs
		rm -f $(PROGS)

tar:
		@echo Creating tar archive...
		@cd ..; tar cvfz $(NAME).tar.gz $(DIR)
		@echo Tar archive created

install:
		$(INSTALL) -m 555 halt init killall5 \
			powerd runlevel shutdown powerd runlevel $(ROOT)/sbin
		$(INSTALL) -m 555 last mesg utmpdump wall $(ROOT)/usr/bin
		cd $(ROOT)/usr/bin; ln -sf last lastb; chown $(BIN_COMBO) lastb
		$(INSTALL) -m 755 etc/initscript.sample $(ROOT)/etc
		cd $(ROOT)/sbin; ln -sf halt reboot; chown $(BIN_COMBO) reboot
		cd $(ROOT)/sbin; ln -sf killall5 pidof; chown $(BIN_COMBO) pidof
		cd $(ROOT)/sbin; ln -sf init telinit; chown $(BIN_COMBO) telinit
		$(INSTALL) -m 644 *.8 $(ROOT)/usr/man/man8
		$(INSTALL) -m 644 *.5 $(ROOT)/usr/man/man5
		$(INSTALL) -m 644 *.1 $(ROOT)/usr/man/man1
		@if [ ! -c /dev/systty ]; then \
		 echo "Creating /dev/systty"; rm -f /dev/systty; \
		 mknod -m 622 /dev/systty c 4 0; fi
