include Makefile.common


SUBDIRS = src plugins ngcontrol fixes doc

all: 
	for dir in $(SUBDIRS); do make -C $$dir all || exit $?; done
.DEFAULT:
	for dir in $(SUBDIRS); do make -C $$dir $@ || exit $?; done

kill:
	killall -9 initng; killall valgrind; killall ngdc; true

install: all
	@echo "Warning: The init scripts in this package are only tested "
	@echo "and written for Gentoo, and may not work with your distro."
	install -d $(DESTDIR)/sbin
	install -d $(DESTDIR)/etc/initng
	install -d $(DESTDIR)/lib/initng
	
	for dir in $(SUBDIRS); do make -C $$dir install || exit $?; done
	
	
	
	cp -r -u -b -v --preserve=timestamps scripts ${DESTDIR}/lib/initng
	cp -r -u -b -v --preserve=timestamps initfiles/* $(DESTDIR)/etc/initng
	@echo
	@echo "Initng is installed. Add "init=/sbin/initng" in your bootloader configuration"
	@echo "eg. at the end of the kernel line in /boot/grub/grub.conf"
	@echo "Have a lot of fun!"
	@echo
	./gen_system_runlevel.sh $(DESTDIR)

install-doc:
	cp -r doc /etc/initng
	
reboothalt: install
	if [ ! -e "/sbin/reboot" ]; cp `pwd`/ngcontrol/reboot ${DESTDIR}/sbin then ;fi
	if [ ! -e "/sbin/halt" ]; cp `pwd`/ngcontrol/halt ${DESTDIR}/sbin then ;fi

link-install: all uninstall
	@echo
	@echo
	@echo "This will install links to this directory to the places where they"
	@echo "belong in the distribution."
	install -d $(DESTDIR)/sbin
	install -d $(DESTDIR)/etc/initng
	install -d $(DESTDIR)/lib/initng
	
	for dir in $(SUBDIRS); do make -C $$dir link-install || exit $?; done
	
	rm -r /etc/initng/system /etc/initng/daemon /etc/initng/net &> /dev/null ; /bin/true
	ln -s -f `pwd`/initfiles/system $(DESTDIR)/etc/initng/system
	ln -s -f `pwd`/initfiles/daemon $(DESTDIR)/etc/initng/daemon
	ln -s -f `pwd`/initfiles/net $(DESTDIR)/etc/initng/net
	cp -u `pwd`/initfiles/*.i $(DESTDIR)/etc/initng
	#cp -u `pwd`/initfiles/*.runlevel $(DESTDIR)/etc/initng
	ln -s -f `pwd`/scripts ${DESTDIR}/lib/initng/scripts
	@echo
	@echo "Initng is installed. Add "init=/sbin/initng" in your bootloader configuration"
	@echo "eg. at the end of the kernel line in /boot/grub/grub.conf"
	@echo "Have a lot of fun!"
	@echo
	./gen_system_runlevel.sh $(DESTDIR)

uninstall:
	
	for dir in $(SUBDIRS); do make -C $$dir uninstall || exit $?; done
	
	#rm -r $(DESTDIR)/etc/initng &> /dev/null ; /bin/true
	
