#################
# Main makefile #
#################
export CONF_CC = g++
export CONF_CFLAGS = -fomit-frame-pointer -O2
export CONF_DEBUG =
export CONF_LDFLAGS =
export CONF_LIBNAME = tv
export CONF_LIBS = -lcurses -lgpm ../lib/libtv.a
export CONF_SUBDIRS = lib demo examples
export CONF_VERSION = 0.2
export CONF_DISTDIR = $(CONF_LIBNAME)-$(CONF_VERSION)

###################
# Other variables #
###################
RCS = README $(CONF_LIBNAME)-$(CONF_VERSION).lsm
DISTFILES = COPYING Makefile $(RCS)

###########
# Targets #
###########
all install uninstall:
	@echo Making $@ in lib
	@cd lib && $(MAKE) $@

tvdemo:
	@echo Making all in demo
	@cd demo && $(MAKE)

tvexamples:
	@echo Making all in examples
	@cd examples && $(MAKE)

world: all tvdemo tvexamples

.PHONY:	ciall coall clean dist

###################
# Store revisions #
###################
ciall:
	ci Makefile $(RCS)

#####################
# Recover revisions #
#####################
coall:
	co $(RCS)

########################
# Remove garbage files #
########################
clean:
	rm -f *.bak *~
	@for subdir in $(CONF_SUBDIRS); do \
		echo Making $@ in $$subdir; \
		(cd $$subdir && $(MAKE) $@) || exit 1; \
	done

############################
# Package-making procedure #
############################
dist: $(DISTFILES)
	@echo Making $(CONF_DISTDIR).tar.gz
	@rm -rf $(CONF_DISTDIR)
	@mkdir $(CONF_DISTDIR)
	@for file in $(DISTFILES); do \
		ln $$file $(CONF_DISTDIR) || { \
			echo Copying $$file instead; \
			cp -p $$file $(CONF_DISTDIR); \
		}; \
	done
	@for subdir in $(CONF_SUBDIRS); do \
		mkdir $(CONF_DISTDIR)/$$subdir || exit 1; \
		(cd $$subdir && $(MAKE) $@) || exit 1; \
	done
	tar -chvf - $(CONF_DISTDIR) | gzip -9 >$(CONF_DISTDIR).tar.gz
	@rm -rf $(CONF_DISTDIR)

# Makefile ends here
