# Author: Jose A Ortega Ruiz # Start date: Mon Jan 06, 2003 00:47 # # Copyright (C) 2003, 2009, 2020 by Jose Antonio Ortega Ruiz # # This program 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. # # This program 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 this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # NOTANGLE ?= notangle NOWEAVE ?= noweave NOROOTS ?= noroots CPIF ?= cpif NODEFS ?= nodefs NOINDEX ?= noindex NW_LINEFORMAT ?= -L"\# %L \"%F\" %N" NW_MAIN ?= main NW_DOCUMENT_CLASS ?= report NW_CONTENTS ?= contents.tex NW_CODESIZE ?= smallcode NW_HYPER ?= yes NW_HYPER_OPTIONS ?= "colorlinks=true,linkcolor=blue" f_tabbed = $(if $(subst Makefile,,$(1)),,-t8) f_notangle = $(NOTANGLE) $(NW_LINEFORMAT) $(call f_tabbed,$(2)) -R$(2) $(1) \ | $(CPIF) $(2); f_latex = $(1) '\scrollmode \input '"$(2)";\ while grep -s 'Rerun to get cross-references right' $(2).log;\ do $(1) '\scrollmode \input '"$(2)"; done f_roots = $(shell $(NOROOTS) $(1) | sed -r 's/^(<<)(.*)>>$$/\2/') f_extract_inputs = $(strip $(shell \ cat $(1) | grep '^\\input' | \ sed -r 's/\\\input\{(.*)\}.*/\1/')) f_read_nw_files = $(foreach f, $(call f_extract_inputs, $(1)), $(dir $(1))$(f)) nw_contents_files = $(foreach d, $(NW_SUBDIRS), $d/$(NW_CONTENTS)) nw_files = $(foreach f, $(nw_contents_files), $(call f_read_nw_files, $(f))) NW_FILES = $(strip $(nw_files)) nw_sources = $(NW_FILES:%=%.nw) local_nw_files = $(call f_extract_inputs, $(NW_CONTENTS)) local_nw_sources = $(local_nw_files:%=%.nw) code_targets = $(local_nw_sources:%.nw=.%.tangle) main_tex = $(NW_MAIN).tex main_html = $(NW_MAIN).html main_dvi = $(NW_MAIN).dvi main_pdf = $(NW_MAIN).pdf main_defs = $(NW_MAIN).defs tex_files = $(NW_FILES:%=%.tex) defs_files = $(NW_FILES:%=%.defs) code_files = $(foreach f, $(NW_FILES), $(call f_roots, $(f).nw)) code_dirs = $(sort $(filter-out ./, \ $(foreach src, $(code_files), $(dir $(src))))) %.tex : %.nw ; $(NOWEAVE) -n -indexfrom $(main_defs) $< > $@ %.defs : %.nw ; $(NODEFS) $< > $@ $(main_tex): $(nw_contents_files) $(main_defs) $(tex_files) \ $(NW_PRE_TEX) $(NW_POST_TEX) @echo "\documentclass[a4paper]{$(NW_DOCUMENT_CLASS)}" > $(main_tex) @echo "\usepackage{noweb}" >> $(main_tex) @echo "\noweboptions{longchunks}" >> $(main_tex) @echo "\noweboptions{externalindex}" >> $(main_tex) @echo "\noweboptions{$(NW_CODESIZE)}" >> $(main_tex) @if [ ! -z $(NW_LANGUAGES) ]; \ then echo "\usepackage[$(NW_LANGUAGES)]{babel}" >> $(main_tex); fi @echo "\usepackage[utf8]{inputenc}" >> $(main_tex) @for f in $(NW_PACKAGES); do echo "\usepackage{$$f}" >> $(main_tex); \ done @for f in $(NW_PACKAGES_OPT); do echo "\usepackage$$f" >> $(main_tex); \ done @if [ "x$(HW_HYPER)" != "xno" ]; \ then echo "\usepackage[$(NW_HYPER_OPTIONS)]{hyperref}" >> $(main_tex); fi @echo "\begin{document}" >> $(main_tex) @for f in $(NW_PRE_TEX); do echo "\input{$$f}" >> $(main_tex); done @for f in $(nw_contents_files); do \ foo=`dirname $$f`; \ cat $$f | grep -v "^%" | \ sed -r "s/\\\input\{(.+)\}/\\\input\{$$foo\/\1\}/" \ >> $(main_tex); done @for f in $(NW_POST_TEX); do echo "\input{$$f}" >> $(main_tex); done @echo "\\end{document}" >> $(main_tex) $(code_dirs): $(nw_sources) mkdir -p $@ $(code_targets): .%.tangle: %.nw $(foreach root, $(call f_roots,$<), $(call f_notangle,$<,$(root))) touch $@ $(main_defs): $(defs_files) sort -u $(defs_files) | $(CPIF) $(main_defs) $(main_dvi): $(main_defs) $(tex_files) $(main_tex) $(nw_sources) latex $(NW_MAIN) $(NOINDEX) $(NW_MAIN) $(call f_latex, latex, $(NW_MAIN)) $(main_pdf): $(main_defs) $(tex_files) $(main_tex) $(nw_sources) pdflatex $(NW_MAIN) $(NOINDEX) $(NW_MAIN) $(call f_latex, pdflatex, $(NW_MAIN)) $(main_html): $(nw_sources) cat $(nw_sources) > $(NW_MAIN).nw $(NOWEAVE) -filter l2h -index -html $(NW_MAIN).nw | htmltoc \ > $(main_html) rm -f $(NW_MAIN).nw tangle: t_subdirs = $(filter-out ., $(NW_SUBDIRS)) tangle: $(code_dirs) $(code_targets) for d in $(t_subdirs); do cd $$d && $(MAKE) tangle; done weave: $(main_defs) $(tex_files) $(main_tex) debug: @echo "sources: $(nw_sources)" @echo "contents files: $(nw_contents_files)" @echo "noweb files: $(NW_FILES)" @echo "code targets: $(code_targets)" @echo "tex files: $(tex_files)" dvi: $(main_dvi) pdf: $(main_pdf) html: $(main_html) NW_TRASH_FILES = $(code_targets) $(code_files) $(tex_files) $(defs_files) \ $(main_html) $(main_defs) $(main_tex) $(main_pdf) \ $(NW_MAIN).out $(NW_MAIN).nwi *.toc *.log *.aux *.dvi clean: rm -rf $(NW_TRASH_FILES) .PHONY: clean dvi html weave tangle