
# Configuration 
DIRS 	    	 = $(shell find . -type d | grep -v '.svn')
BUILDDIR    	 = build
BIN  	    	 = $(BUILDDIR)/xr
LIB  	    	 = $(BUILDDIR)/libxr.a
TMPXR       	 = /tmp/xr-$(shell whoami)
CONF_CC	    	 = $(shell etc/c-conf -c $(BUILDDIR)/config.cache c++-compiler)
CONF_OPTFLAGS	 = $(shell etc/c-conf -c $(BUILDDIR)/config.cache optflags)
CONF_LIB    	 = $(shell etc/c-conf -c $(BUILDDIR)/config.cache \
		     lib ucb nsl pthread socket m alf)
CONF_GETOPT 	 = $(shell etc/c-conf -c $(BUILDDIR)/config.cache \
		     ifheader getopt.h HAVE_GETOPT_H)
CONF_GETOPT_LONG = $(shell etc/c-conf -c $(BUILDDIR)/config.cache \
		     libfunction getopt_long HAVE_GETOPT_LONG)
CONF_INET_ATON   = $(shell etc/c-conf -c $(BUILDDIR)/config.cache \
		     libfunction inet_aton HAVE_INET_ATON)
CONF_STRNSTR	 = $(shell etc/c-conf -c $(BUILDDIR)/config.cache \
		     libfunction strnstr HAVE_STRNSTR)

foo:
	$(MAKE) subdirs
	$(MAKE) $(BIN)

install: $(BINDIR)/xr
$(BINDIR)/xr: $(BUILDDIR)/xr
	cp $(BUILDDIR)/xr $(TMPXR)
	strip $(TMPXR)
	install $(TMPXR) $(BINDIR)/xr
	rm -f $(TMPXR)

subdirs: $(BUILDDIR)/usage.h $(BUILDDIR)/status.xslt.h
	@echo 'About to build in class dirs: $(DIRS)'
	@for f in $(DIRS) ; do \
	   echo "Making: $$f"; \
	   BASE=$(BASE) CC=$(CONF_CC) BUILDDIR=$(BUILDDIR) VER='$(VER)' \
	     AUTHOR='$(AUTHOR)' MAINTAINER='$(MAINTAINER)' \
	     DISTSITE='$(DISTSITE)' MEMDEBUG=$(MEMDEBUG)\
	     CONF_CC='$(CONF_CC)' CONF_LIB='$(CONF_LIB)' \
	     CONF_GETOPT=$(CONF_GETOPT) CONF_GETOPT_LONG=$(CONF_GETOPT_LONG) \
	     CONF_INET_ATON=$(CONF_INET_ATON) CONF_OPTFLAGS='$(CONF_OPTFLAGS)' \
	     CONF_STRNSTR=$(CONF_STRNSTR) \
	     $(MAKE) -C $$f -f $(BASE)/xr/etc/Makefile.class \
	     || exit 1; \
	 done
	ar rs $(LIB) */*.o
	ranlib $(LIB)
$(BUILDDIR)/usage.h: etc/usage.txt
	etc/e-txt2c USAGE <etc/usage.txt >$(BUILDDIR)/usage.h
	touch config/parsecmdline.cc
$(BUILDDIR)/status.xslt.h: etc/status.xslt
	etc/e-txt2c XSLT  <etc/status.xslt >$(BUILDDIR)/status.xslt.h
	touch webinterface/answerxslt.cc

$(BIN): $(BUILDDIR)/libxr.a
	$(CONF_CC) $(PROF) $(CONF_OPTFLAGS) -g -o $(BIN) \
	  -L$(BUILDDIR) -lxr $(CONF_LIB)

clean:
	rm -f $(BIN) $(LIB) core obj/*.o etc/usage.h $(BUILDDIR)/config.cache
	find . -name \*.bak -exec rm {} \;

