SUBDIR=rpc common net svc runixd clnt test preload
export CC=gcc
#CFLAGS=-DDEBUG -g -I.. -I../common -L..
CFLAGS=-O3 -I.. -I../common
PIC=-fPIC


# The following should be valid for subdirs, not for root level
export LIBRUNIX=../librunix.a
export LIBRUNIX_SVC=../librunix_svc.a
export LIBRUNIX_CLNT=../librunix_clnt.a
export GDEPEND=../tools/gdepend
export LIBRUNIX_SO=../librunix.so.1.0.0
export R4LIBS

RANLIB=ranlib

all: libs runixd $(LIBRUNIX_SO)

svr4:	ALWAYS
	$(MAKE) all RANLIB=true R4LIBS="-L/usr/ucblib -lrpcsoc -lnsl -lsocket -lc -lucb"
	

runixd: ALWAYS
	cd runixd; $(MAKE) CFLAGS="$(CFLAGS)" runixd

tstconn: ALWAYS
	cd test; $(MAKE) CFLAGS="$(CFLAGS)" tstconn

libs: ALWAYS
	touch maketime
	for dir in $(SUBDIR); do \
	  cd $$dir ; \
	  if ! $(MAKE) CFLAGS="$(PIC) $(CFLAGS)" \
		$(LIBRUNIX) $(LIBRUNIX_SVC) $(LIBRUNIX_CLNT); then exit 1; fi; \
	  cd .. ; \
    done
	zsh -c 'for i in *.a; do [ maketime -nt $$i ] || $(RANLIB) $$i || true; done'

$(LIBRUNIX_SO): ALWAYS
	cd preload; $(MAKE) CFLAGS="$(PIC) $(CFLAGS)" $(LIBRUNIX_SO)

depend:
	for dir in $(SUBDIR); do \
	  cd $$dir ; \
	  if ! $(MAKE) CFLAGS="$(CFLAGS)" depend; then exit 1; fi; \
	  cd ..; \
	done

clean:
	rm -f *.a 2>/dev/null
	find . \( -name "*.o" -o -name core -o -name typescript \) -print \
			| xargs rm -f \;
	for dir in $(SUBDIR); do \
	  cd $$dir ; \
          $(MAKE) clean || true; \
          cd ..; \
	done

swipe:
	find . \( -name '*~' -o -name '#*#' \) -print | xargs rm -f

ALWAYS:
