# Copyright 2012-2022, Alexander Shibakov
# This file is part of SPLinT
#
# SPLinT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SPLinT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SPLinT.  If not, see <http://www.gnu.org/licenses/>.

# this Makefile uses a flat directory structure for demonstration
# purposes; the main directory (../..) contains a slightly more
# modular organization.

XXPRESSION_PREREQS = %.tex %.scn %.idx %.tok ${SPLINT_XTABLES} xymmap.sty xtoks.sty

include ../../makefile.inc
include ${SPLINT_ROOT}makefile.loc

# rules specific to this example

PARSER = xxpp
LEXER = xxpl

all:            xxpression.pdf ptab.tex ltab.tex

step1:          ${PARSER}.y ${LEXER}.l
step2:          ptabout ltabout
step3:          ltab.tex ptab.tex
step4:          xymbols.sns

ptabout:        ${SPLINT_ROOT}cweb/mkeparser.c ${PARSER}.c
               ${CC} -DPARSER_FILE=\"../examples/xxpression/$(lastword $^)\" -DYYPARSE_PARAMETERS= -o $@ $<

ptab.tex:       ptabout
               $< --optimize-actions $@

ltabout:        ${SPLINT_ROOT}cweb/mkscanner.c ${LEXER}.c
               ${CC} -DLEXER_FILE=\"../examples/xxpression/$(lastword $^)\" -o $@ $<

ltab.tex:       ltabout
               $< --optimize-actions $@

${LEXER}.c:     ${LEXER}.l
               ${FLEX} -o $@ $<

test.tex xymbols.tex \
${PARSER}.yy ${LEXER}.ll:       xxpression.x alphas.hx
                               @${CTANGLE} $<
                               ${UNLINE} test.txx test.tex
                               ${UNLINE} xymbols.txx xymbols.tex

xymbols.sns:                    xymbols.tex xxpression.tok ${SPLINT_XTABLES} ptab.tex
                               ${PDFTEX} $<

alphas.hx:
                               ${MISCCW} --alpha-list --alpha-length=1 $@

xxpression.tex:                 xxpression.x alphas.hx
                               ${CWEAVE} $<

xxpression.gdx:%.gdx:           ${XXPRESSION_PREREQS}
                               ${TEX} $*.tex

xxpression.pdf:%.pdf:           ${XXPRESSION_PREREQS} %.gdy
                               ${PDFTEX} $* && touch $*.gdy && touch $*.pdf
#               if [ -f $*.gdx ] ; then ${BINDX} $*.gdx $*.gdy; fi

xxpression.tok:                 xxpression.tex ${SPLINT_XPTABLES} ${SPLINT_XLTABLES} ${SPLINT_ROOT}cweb/bo.tok
                               ${PDFTEX} $< && touch xxpression.tok

${SPLINT_ROOT}cweb/%:
                               cd ${SPLINT_ROOT}cweb/ && ${MAKE} $(notdir $@)

test:   test.tex xymbols.sns xxpression.tok ptab.tex ltab.tex ${SPLINT_ROOT}cweb/fo.tok
       tex test.tex

docs:   xxpression.pdf

clean:  clean_core
       -rm -f ptabout ltabout *.txx

mostlyclean:                    clean_temp
                               -rm -f ptabout ltabout xxpression.c *.txx

distclean:                      clean
                               cd ${SPLINT_ROOT} && ${MAKE} clean

INTERMEDIATE:                   xxpression.gdx