#
# Makefile	Makefile for the systemV init suite.
#		Targets:   all      compiles everything
#		           install  installs the binaries (not the scripts)
#                          clean    cleans up
#
# Version:	@(#)Makefile  2.66  29-Oct-1996  MvS
#

CC	= cc
CFLAGS	= -Wall -O2 -D_GNU_SOURCE
LDFLAGS	= -s
STATIC	=

# Use the first 2 lines to build all of the programs (some are non-debian).
# PROGS	= init halt shutdown powerd killall5 runlevel sulogin utmpdump \
#		last mesg wall start-stop-daemon
PROGS	= init halt shutdown powerd killall5 runlevel sulogin last mesg

BIN_OWNER	= root
BIN_GROUP	= root
BIN_COMBO	= $(BIN_OWNER).$(BIN_GROUP)
INSTALL		= install -o $(BIN_OWNER) -g $(BIN_GROUP)

ifneq ($(wildcard /usr/lib/libcrypt.a),)
LIBS		= -lcrypt
endif

all:		$(PROGS)

init:		init.c
		$(CC) $(CFLAGS) $(LDFLAGS) $(STATIC) -o $@ init.c

shutdown.o:	shutdown.c

halt:		halt.c

last:		last.c

mesg:		mesg.c

utmpdump:	utmpdump.c

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

sulogin:	sulogin.c
		$(CC) $(CFLAGS) $(LDFLAGS) $(STATIC) -o $@ sulogin.c $(LIBS)

start-stop-daemon:	start-stop-daemon.c
		$(CC) $(CFLAGS) $(LDFLAGS) $(STATIC) -o $@ start-stop-daemon.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)

install:
		$(INSTALL) -m 755 halt init killall5 sulogin \
			powerd runlevel shutdown $(ROOT)/sbin
		# These are not installed by default
		# $(INSTALL) -m 555 utmpdump wall $(ROOT)/usr/bin
		# $(INSTALL) -m 755 etc/initscript.sample $(ROOT)/etc
		$(INSTALL) -m 755 mesg last $(ROOT)/usr/bin
		cd $(ROOT)/usr/bin; ln -sf last lastb; chown $(BIN_COMBO) lastb
		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
		# Some manpages not installed by default.
		# $(INSTALL) -m 644 wall.1 $(ROOT)/usr/man/man1
		$(INSTALL) -m 644 last.1 lastb.1 mesg.1 $(ROOT)/usr/man/man1
		#
		# This part is skipped on debian systems, the
		# debian.preinst script takes care of it.
		@if [ ! -p /dev/initctl ]; then \
		 echo "Creating /dev/initctl"; \
		 rm -f /dev/initctl; \
		 mknod -m 600 /dev/initctl p; fi
