# @(#) $Revision: 72.4 $
#
# makefile -- makefile for /etc/init
#
# To make a "user process" version of init, set
#  DFLAGS=-DUDEBUG -DDEBUG1 -DDEBUG -DACCTDEBUG -DERRDEBUG
#
# MEMORY_CHECKS cause extra code to be included that checks if
#               init is allocating and freeing resources correctly.
#               If an error is detected, the file "init.memory" will
#               be created with diagnostics.
#               Defining DEBUG1 will increase the frequency of the
#               memory checks.
#
# DFLAGS  =
# DFLAGS  = -DMEMORY_CHECKS
# DFLAGS  = -g -DUDEBUG -DDEBUG1 -DDEBUG -DACCTDEBUG -DERRDEBUG -DMEMORY_CHECKS

DFLAGS  =
OBJECTS = \
	account.o	\
	init.o		\
	inittab.o	\
	proctable.o	\
	utility.o	\
	hpux_rel.o
SOURCES = \
	account.c	\
	init.c		\
	inittab.c	\
	proctable.c	\
	utility.c	\
	hpux_rel.c
FLAGS   = $(DFLAGS)

default: init

metrics: init.M

init: $(OBJECTS)
	libs="";						\
	if ifdef DISKLESS || ifdef DUX; then			\
	    libs="$$libs -lDUX";				\
	fi;							\
	if ifdef SecureWare || ifdef B1 || ifdef TRUSTED; then	\
	    libs="$$libs -lscmd -lsec -lcurses";		\
	fi;							\
	if ifdef COMSEC; then					\
	    libs="$$libs  -lscmd -lsec";				\
	fi;							\
	$(CC) -o $@ $(CFLAGS) $(OBJECTS) $$libs $(LDFLAGS)

init.M: $(SOURCES)
	$(METRICS) -o $@ $(CFLAGS) $(SOURCES)

clean:
	rm -f *.o _tmp.s

clobber: clean
	rm -f init init.M

.c.o:
	$(CC) -c $(CFLAGS) $(FLAGS) $*.c

#
# Assemble a ".s" file with cpp directives in a machine independent
# manner
#
.s.o:
	$(CC) -E $(CFLAGS) $(FLAGS) $*.s >_tmp.s
	$(CC) -c $(CFLAGS) $(FLAGS) _tmp.s
	mv _tmp.o $*.o
	rm -f _tmp.s

hpux_rel.o: hpux_rel.c
	set -- $(DFLAGS);					     \
	extra="";						     \
	for i in $$*; do					     \
	    case $$i in						     \
	    -DMEMORY_CHECKS|-DUDEBUG|-g)			     \
		if [ -z "$$extra" ]; then			     \
		    extra="$$i";				     \
		else						     \
		    extra="$$extra $$i";			     \
		fi;						     \
		;;						     \
	    *)							     \
		;;						     \
	    esac;						     \
	done;							     \
	if [ -n "$$extra" ]; then				     \
	    sed -e 's/ \$$"/ ('"$$extra"') $$"/' <hpux_rel.c >tmp.c; \
	    $(CC) -c $(CFLAGS) $(FLAGS) tmp.c -o hpux_rel.o;	     \
	    rm -f tmp.c;					     \
	else							     \
	    $(CC) -c $(CFLAGS) $(FLAGS) hpux_rel.c;		     \
	fi

init.c:      init.h proctable.h
proctable.c: init.h proctable.h
utility.c:   init.h
inittab.c:   init.h
