CHDIR = cd
RM    = rm
TOUCH = touch
PRCS  = prcs

all: library

library:
	@if [ -r .build_done ]; then \
	    (($(CHDIR) src && $(MAKE) library) || $(RM) .build_done); \
	else \
	    (($(CHDIR) src && $(MAKE) library) && $(TOUCH) .build_done); \
	fi

library-lean:
	@if [ -r .build_done ]; then \
	    (($(CHDIR) src && $(MAKE) library-lean) || $(RM) .build_done); \
	else \
	    (($(CHDIR) src && $(MAKE) library-lean) && $(TOUCH) .build_done); \
	fi

.build_done: library


check:
	($(CHDIR) src && $(MAKE) check)

subset:
	@if [ -z "$(DESTDIR)" ]; then \
		echo 'error: DESTDIR must be specified.' 1>&2; \
	else \
		./bin/make-subset --prefix=`pwd` \
				  --libraries="$(LIBRARIES)" \
				  --destdir="$(DESTDIR)"; \
	fi

clean:
	$(RM) -f .build_done
	($(CHDIR) src && $(MAKE) clean)

distclean: clean


#
# Version Control
#
diff:
	@($(PRCS) diff) || true

populate:
	@$(PRCS) populate

checkin:
	@$(PRCS) checkin && $(RM) -f .*.prcs_aux


.PHONY: all library library-lean check subset clean diff populate checkin
