# srr/Makefile
#
# $Id: Makefile,v 1.12 2001/07/26 18:26:52 andrew Exp $
#

# Install prefix, usually / unless you're using stow
prefix		=/usr/local
modprefix 	=/lib/modules

INSTALL		= /usr/bin/install
DEPMOD		= /sbin/depmod
MKNOD		= /bin/mknod

# Set SRRDEBUG to n to exclude debugging information
SRRDEBUG=n

# Make flags can be specified on the command line
MAKE	=make $(MF) SRRDEBUG=$(SRRDEBUG)

# Extract version number from headers.
VER	= $(shell uname -r)

# Construct base name of archive.
ARCH	= srr-`cat Version`

SUBDIRS	= inc mod lib exe

ALL	= $(SUBDIRS) doc

DOCS = README README.html CHANGES CHANGES.html BUGS BUGS.html

.PHONY: all inc mod lib exe clean empty install release

all: $(ALL)

inc:
	$(MAKE) -C inc

mod:
	$(MAKE) -C mod

lib:
	$(MAKE) -C lib

exe:
	$(MAKE) -C exe

## documentation

.PHONY: doc

doc: $(DOCS)

README: README.pod
	./pod2text $< > $@

README.html: README.pod
	./pod2html --title="SRR -- QNX API Compatible Message Passing for Linux" $< > $@

CHANGES: CHANGES.pod
	./pod2text $< > $@

CHANGES.html: CHANGES.pod
	./pod2html --title="SRR -- Changelog" $< > $@

BUGS: BUGS.pod
	./pod2text $< > $@

BUGS.html: BUGS.pod
	./pod2html --title="SRR -- Bugs" $< > $@

## installation

install: i_prefix i_mod i_exe i_devel i_auto
	@echo "note: installed but not necessarily auto-loading, read INSTALL."

i_prefix:
	$(INSTALL) -d $(prefix)/

i_mod:
	$(INSTALL) -d $(modprefix)/$(VER)/misc
	$(INSTALL) mod/srripc.o $(modprefix)/$(VER)/misc
	$(DEPMOD) -a
	-rm -f /dev/srripc
	$(MKNOD) -m0666 /dev/srripc c 10 171

# not necessary, the module can be auto-loaded
i_init:
	ln -fs $(prefix)/bin/srrmodule /etc/rc.d/init.d
	cd /etc/rc.d/rc3.d; ln -fs ../init.d/srrmodule S99srrmodule

i_exe:
	$(INSTALL) -d $(prefix)/bin
	$(INSTALL) exe/srrmodule $(prefix)/bin
	$(INSTALL) exe/srrctl $(prefix)/bin

i_devel:
	$(INSTALL) -d $(prefix)/lib
	$(INSTALL) -d $(prefix)/include
	$(INSTALL) -d $(prefix)/include/sys
	$(INSTALL) lib/libsrr.a $(prefix)/lib
	$(INSTALL) inc/*.h $(prefix)/include
	cd inc/sys; \
	for f in *.h; do \
		cd $(prefix)/include/sys; \
		ln -fs ../srr.h $$f; \
	done

i_auto:
	@if [ -f /etc/conf.modules ] ; then \
		if ! egrep -q "^alias char-major-10-171" /etc/conf.modules ; then \
			echo "Add alias to /etc/conf.modules" ; \
			echo "alias char-major-10-171 srripc" >> /etc/conf.modules; \
		else \
			echo "srripc is already in /etc/conf.modules" ; \
		fi \
	elif [ -f /etc/modules.conf ] ; then \
		if ! egrep -q "^alias char-major-10-171" /etc/modules.conf ; then \
			echo "Add alias to /etc/modules.conf" ; \
			echo "alias char-major-10-171 srripc" >> /etc/modules.conf; \
		else \
			echo "srripc is already in /etc/modules.conf" ; \
		fi \
	fi
	@if [ ! -f /proc/modules ] ; then \
		echo You must compile your kernel with module auto-loading turned on ;\
		echo in order to auto-load this module.  See INSTALL. ;\
		echo If not, place the line \"modprobe srripc\" somewhere in your ;\
		echo startup sequence, or \"make i_init\" to install a SysV-style ;\
		echo startup script. ;\
	fi

release:
	-mkdir $(ARCH)
	tar -cf- -T Manifest | tar -C $(ARCH) -xf-
	tar -cvf $(ARCH).tar $(ARCH)
	gzip $(ARCH).tar
	mv $(ARCH).tar.gz $(ARCH).tgz
	rm -Rf $(ARCH)

## cleanup

clean:
	for f in $(SUBDIRS); do make -C $$f clean; done
	rm -f pod2html-dircache pod2html-itemcache

empty: clean
	for f in $(SUBDIRS); do make -C $$f empty; done
	rm -f $(DOCS)

-include .depend


# DO NOT DELETE


