TOP = ..
include $(TOP)/mk/boilerplate.mk

#
# No ways
#
WAYS=

boot :: all

# Note: might be overridden from the command-line
#  (see install rule below)
INSTALLING=0

SCRIPT_PROG=lit2stuff
SCRIPT_OBJS=lit2stuff.prl
INTERP=perl

ifeq "$(INSTALLING)" "1"
datadir:=$(datadir)/literate
LIB_ARCH_DIR:=$(datadir)/$(HOSTNAME)
LIB_DIR:=$(datadir)
else
LIB_ARCH_DIR:=$(FPTOOLS_TOP_ABS)/literate
LIB_DIR:=$(FPTOOLS_TOP_ABS)/literate
endif

SUBDIRS=lit-deatify texi2html info-utils

SCRIPT_SUBST_VARS=    \
 TMPDIR               \
 LIB_ARCH_DIR         \
 LIB_DIR              \
 TGRIND_HELPER

LINK_TARGETS =   \
   lit2pgm       \
   lit2texi      \
   lit2html      \
   lit2latex     \
   mkdependlit   \
   lit2changelog \
   lit2text

INSTALL_DATAS += $(wildcard lit-2*.prl) \
 lit-globals.prl \
 lit-link-globals.prl \
 lit-linker.prl \
 lit-reader.prl \
 lit-style.tex

# Where to put the link to the various guises of lit2stuff..
# (install rules overrides this)
LINK_DEST_DIR=.

$(LINK_TARGETS):
	( cd $(LINK_DEST_DIR) ; $(LN_S) $(LITERATE_PREFIX)lit2stuff $@ )

include $(TOP)/mk/target.mk

#
# Before installing the various literate scripts 
# reconfigure it such that the paths it refers to,
# point to the installed utils. 
#
# After install has completed, we move back the 
install ::
	@$(CP) $(SCRIPT_PROG) $(SCRIPT_PROG)-old
	@$(MAKE) $(MFLAGS) INSTALLING=1 LINK_DEST_DIR=$(datadir)
	@$(CP) $(SCRIPT_PROG)-old $(SCRIPT_PROG)

all :: $(LINK_TARGETS) lit-inputter

lit-inputter : lit-inputter.prl
	@$(RM) $@
	@echo Creating $@...
ifeq "$(INTERP)" "perl"
	@echo "#! $(PERL)" > $@
else
ifneq "$(INTERP)" ""
	@echo "#! "$(INTERP) > $@
else
	@touch $@
endif
endif
	@eval $(SCRIPT_SUBST) 
	@cat $< >> $@
	@chmod a+x $@
	@echo Done.

clean ::  
	for i in $(LINK_TARGETS) lit-inputter ; do \
	   rm -f $$i; \
	done;

#
# Making a source distribution tree proceeds by including
# all symbolic links in a build tree in the distribution.
# This clashes with the literate/ setup, where $(LINK_TARGETS)
# are symbolic links to the real worker lit2stuff, so to avoid
# including all of $(LINK_TARGETS) we remove them from the distrib
# tree during the second stage of `make dist':
#
dist :: 
	for i in $(LINK_TARGETS); do \
	   rm -f $(SRC_DIST_DIR)/$$i; \
	done; 

#InstallBinaryTarget(lit-deatify, $(INSTLIBDIR_LITERATE))
#InstallScriptTarget(lit-inputter, $(INSTLIBDIR_LITERATE))
