CFLAGS=-DPREFIX=\"`pwd`\" -DDEBUG=1

RANLIB=ranlib

PROGS=init shutdown wall mesg need showreg halt runlevel
LINKS=telinit check reboot
LIB=libinit.a
LOBJ=libwall.o librunlevel.o why_why_why.o wtmp.o libopen.o
MANPAGES=halt.8 reboot.8 init.8 shutdown.8 telinit.8 inittab.5

all: $(PROGS) $(LINKS)

halt: halt.o $(LIB)
need: need.o $(LIB)
showreg: showreg.o $(LIB)
shutdown: shutdown.o $(LIB)
wall: wall.o $(LIB)
runlevel: runlevel.o $(LIB)

$(LIB): $(LOBJ)
	$(AR) rv $(LIB) $(LOBJ)
	$(RANLIB) $(LIB)

check:	
	ln -s init check
telinit:
	ln -s init telinit
reboot:
	ln -s halt reboot

init: init.o $(LIB)
	$(CC) -o init init.o $(LIB)

clean:
	rm -f $(PROGS) $(LINKS) $(LIB) *.o

install: $(PROGS)
	install -d -o bin -g bin $(TOPDIR)/sbin
	install -d -o bin -g bin $(TOPDIR)/etc/rc.d/functions
	install -d -o bin -g bin $(TOPDIR)/usr/bin
	install -c -m 511 -s -o bin -g bin init runlevel halt shutdown \
		$(TOPDIR)/sbin
	ln -sf init $(TOPDIR)/sbin/telinit
	ln -sf halt $(TOPDIR)/sbin/reboot
	install -c -m 511 -s -o bin -g bin need showreg \
		$(TOPDIR)/etc/rc.d/functions
	install -c -m 511 -s -o bin -g bin wall $(TOPDIR)/usr/bin
	./install_manpages $(TOPDIR)/usr/man $(MANPAGES)

%.o: %.c init.h
