Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 311bf43732
Fetching contributors…

Cannot retrieve contributors at this time

287 lines (234 sloc) 10.228 kb
#/*--------------------------------------------------------------------------
#* Variables globales
#*---------------------------------------------------------------------------*/
MAIN_DIR := $(HOME)/inetdoc
CWD := $(shell pwd)
STYLESHEET := inetdoc
PAGEMENUITEM := $(subst $(MAIN_DIR),,$(CWD))
PAGEMENUCAT := $(firstword $(shell echo $(PAGEMENUITEM)| sed 's/\// /g'))
TIDY := /usr/bin/tidy -q -asxhtml -utf8
FOP := ~/SVN/fop/trunk/fop -l fr -c $(MAIN_DIR)/common/fop.xconf
XSLT_STYLESHEET := $(MAIN_DIR)/common/xhtml_chunk.xsl
#/*--------------------------------------------------------------------------
#* Traitement des répertoires et sous-répertoires
#*---------------------------------------------------------------------------*/
# PROCESS contient la directive 'subdirs' : parcours des sous-répertoires
subdirs: $(SUBDIRS)
@for dir in $(SUBDIRS); do \
( cd $$dir && $(MAKE) ); \
done
# Les directives clean et subdirs_clean effacent des fichiers intermédiares.
# L'effacement est conditionné par le contenu du fichier .gitignore présent
# dans chaque répertoire de travail
.PHONY: clean
clean: subdirs_clean
ifneq ($(CWD),$(MAIN_DIR))
@for file in `cat .gitignore | tr '\n' ' '`; do \
rm -rf $$file ;\
done
endif
.PHONY: subdirs_clean
subdirs_clean:
ifdef SUBDIRS
@for dir in $(SUBDIRS); do \
(cd $$dir && $(MAKE) clean); \
done
endif
dist_dirs: $(MAIN_DIR)/odp $(MAIN_DIR)/pdf $(MAIN_DIR)/xml
$(MAIN_DIR)/odp $(MAIN_DIR)/pdf $(MAIN_DIR)/xml:
mkdir $@
#/*--------------------------------------------------------------------------
#* Traitement des liens symboliques
#*---------------------------------------------------------------------------*/
# PROCESS contient la directive 'symlink' : création des liens
symlink:
@for link in $(SYMLINKS); do \
if [ -f $$link ] && [ ! -h `basename $$link` ]; then \
ln -sf $$link . ;\
fi ;\
done
#/*--------------------------------------------------------------------------
#* Gestion des feuilles de styles CSS
#*---------------------------------------------------------------------------*/
# La feuille de styles est éditée pour identifier la rubrique courante
$(STYLESHEET).css: $(MAIN_DIR)/styles/$(STYLESHEET).css
@sed 's/.banner_menu #active/.banner_menu #$(PAGEMENUCAT)/' $< > $@
#/*--------------------------------------------------------------------------
#* Traitement des fichiers sources DocBook XML
#*---------------------------------------------------------------------------*/
ifeq (xml, $(findstring xml,$(PROCESS)))
OUTPUT := transform_output
ifndef XML_FILES
XML_FILES := $(wildcard *.xml)
XML_FILES := $(filter-out $(notdir $(wildcard $(MAIN_DIR)/common/*.xml)), $(XML_FILES))
endif
BASENAME = $(basename $(firstword $(XML_FILES)))
SVG_FILES := $(wildcard images/*.svg)
PNG_FILES := $(subst svg,png,$(SVG_FILES))
xml2xhtml: \
dist_dirs \
index.html \
$(STYLESHEET).css \
$(OUTPUT)/abstract.xml
$(OUTPUT)/$(BASENAME).xml: $(XML_FILES)
@if [ ! -d $(OUTPUT) ]; then mkdir $(OUTPUT); fi
# Validation XML de $(firstword $(XML_FILES))
@xmllint --encode utf-8 --noent --xinclude --postvalid $< > $@ ;\
if [ $$? -ne 0 ]; then rm -f $@; exit 1; fi
svg2png: $(PNG_FILES)
%.png: %.svg
# Génération des images au format PNG à partir du format SVG
# pour la publication Web
rasterizer -bg 255.255.255.255 \
-w `egrep -1i "format=(\"|')PNG(\"|')" $(BASENAME).xml | egrep -1i $(basename $(notdir $@)) | egrep -o [0-9]*px | egrep -o [0-9]*` $<
index.html: $(OUTPUT)/$(BASENAME).xml
# Insertion du nom de fichier imprimable
# Copie du fichier source complet dans le répertoire de distribution
# Transformation XHTML du résultat de la validation XML
@( \
cd $(OUTPUT) && \
sed -i 's/__printbasename__/$(BASENAME)\.pdf/g' $(BASENAME).xml && \
cp -a $(BASENAME).xml $(MAIN_DIR)/xml/ && \
xsltproc --stringparam html.stylesheet $(STYLESHEET).css $(XSLT_STYLESHEET) $(BASENAME).xml \
)
# Formatage des pages XHTML
@for file in `ls $(OUTPUT)/*.html`; do \
sed -i '/<title>/d;s/style=\"clear:* both\"//' $$file ;\
( cd $(MAIN_DIR) && \
nb --title $(BASENAME) make-page $(CWD)/$$file $(CWD)/`echo $${file##*/}` ) ;\
done
# Extraction et transformation de la table des matières
@echo '<div id="links">' >$(OUTPUT)/toc.htm
@echo '<div class="sidetitle">Formats</div>' >>$(OUTPUT)/toc.htm
@echo '<div class="side">' >>$(OUTPUT)/toc.htm
@echo '<a href="/xml/$(BASENAME).xml" class="xml-small">Source DocBook XML</a>' >>$(OUTPUT)/toc.htm
@echo '<a href="/pdf/$(BASENAME).pdf" class="pdf-small">Fichier imprimable PDF</a>' >>$(OUTPUT)/toc.htm
@echo '<a href="https://github.com/platu/inetdoc/commits/master$(PAGEMENUITEM)/$(BASENAME).xml" class="git-small">Historique des versions</a>' >>$(OUTPUT)/toc.htm
@echo '</div>' >> $(OUTPUT)/toc.htm
@sed -n '/<div class=\"toc\">/,/<\/div>/p' $(OUTPUT)/$@ >> $(OUTPUT)/toc.htm
@sed -i -f $(MAIN_DIR)/common/docbook-xml-toc.sed $(OUTPUT)/toc.htm
@echo '</div>' >> $(OUTPUT)/toc.htm
# Insertion de la table des matières dans la partie liens de chaque page
@for file in `ls *.html`; do \
sed -n '1,/<div id=\"container\">/p' $$file >> $$file.tmp ;\
cat $(OUTPUT)/toc.htm >> $$file.tmp ;\
sed -n '/<div id=\"content\">/,$$p' $$file >> $$file.tmp ;\
mv $$file.tmp $$file ;\
done
$(OUTPUT)/abstract.xml: $(BASENAME).xml
@if [ ! -d $(OUTPUT) ]; then mkdir $(OUTPUT); fi
@if egrep -qi -e "<abstract" $<; then \
echo '# Extraction du résumé' ;\
sed -n '/<abstract.*>/,/<\/abstract>/p' $< > $@ ;\
sed -i 's/<abstract.*>//;s/<\/abstract>//' $@ ;\
fi
xml2pdf: \
dist_dirs \
$(MAIN_DIR)/pdf/$(BASENAME).pdf
$(MAIN_DIR)/pdf/$(BASENAME).pdf: $(OUTPUT)/$(BASENAME).xml
# Transformations FO et PDF du résultat de la validation XML
@( \
cd $(OUTPUT) && \
if [ -d ../images ] && [ ! -h images ]; then ln -s ../images; fi && \
xsltproc --output $(BASENAME).fo $(MAIN_DIR)/common/fopdf.xsl $(BASENAME).xml && \
$(FOP) -fo $(BASENAME).fo -pdf $@ \
)
endif
#/*--------------------------------------------------------------------------
#* Traitement des fichiers sources Libreoffice ODP
#*---------------------------------------------------------------------------*/
ifeq (odp, $(findstring odp,$(PROCESS)))
libreoffice := $(shell which libreoffice)
OUTPUT := transform_output
ifndef ODP_FILES
ODP_FILES := $(wildcard *.odp)
endif
ifndef geometry
geometry = 800x600
endif
ifndef thumb-geometry
thumb-geometry = 200x150
endif
BASENAME = $(basename $(firstword $(ODP_FILES)))
odp2xhtml: \
dist_dirs \
$(STYLESHEET).css \
$(MAIN_DIR)/odp/$(BASENAME).odp \
$(MAIN_DIR)/pdf/$(BASENAME).pdf \
$(OUTPUT)/$(BASENAME)-00.png \
$(BASENAME)-00.idx.png \
$(BASENAME)-00.png \
index.html
$(MAIN_DIR)/odp/$(BASENAME).odp: $(BASENAME).odp
cp $< $@
$(MAIN_DIR)/pdf/%.pdf: %.odp
@if [ -z $(libreoffice) ]; then echo 'libreoffice indisponible'; exit 1; fi
@if [ ! -f $(HOME)/bin/DocumentConverter.py ]; then echo 'script de conversion PDF indisponible'; exit 1; fi
# Génération du fichier imprimable PDF
@$(libreoffice) --headless --invisible --convert-to pdf -outdir $(MAIN_DIR)/pdf $?
$(OUTPUT)/$(BASENAME)-00.png: $(MAIN_DIR)/pdf/$(BASENAME).pdf
# Génération d'un fichier image par vue
@if [ ! -d $(OUTPUT) ]; then mkdir $(OUTPUT); fi
@convert -density 720 $? -resample 150 $(OUTPUT)/$(BASENAME)-%02d.png
$(BASENAME)-00.idx.png: $(MAIN_DIR)/pdf/$(BASENAME).pdf $(OUTPUT)/$(BASENAME)-00.png
# Génération d'une vignette par vue
@for file in `ls $(OUTPUT)/*.png`; do \
convert -quality 95 -thumbnail $(thumb-geometry) $$file `basename $$file .png`.idx.png ;\
done
$(BASENAME)-00.png: $(MAIN_DIR)/pdf/$(BASENAME).pdf $(OUTPUT)/$(BASENAME)-00.png
# Génération d'une image par vue
@for file in `ls $(OUTPUT)/*.png`; do \
convert -quality 95 -resize $(geometry) $$file `basename $$file .png`.png ;\
done
index.html: $(MAIN_DIR)/pdf/$(BASENAME).pdf $(BASENAME)-00.idx.png $(BASENAME)-00.png
@rm -rf *.html $(OUTPUT)/*.html
# Formatage XHTML de la page d'index
$(MAIN_DIR)/common/odp2index.sh $(BASENAME) $(OUTPUT)/$@.tmp
@( cd $(MAIN_DIR) && \
nb --title $(BASENAME) make-page $(CWD)/$(OUTPUT)/$@.tmp $(CWD)/$(OUTPUT)/$@ \
)
@rm $(OUTPUT)/$@.tmp
# Formatage XHTML des pages de vues
$(MAIN_DIR)/common/odp2slidepages.sh $(BASENAME) $(OUTPUT)
@for file in `ls $(OUTPUT)/$(BASENAME)*.html`; do \
mv $$file $$file.tmp ;\
( cd $(MAIN_DIR) && \
nb --title $(BASENAME) make-page $(CWD)/$$file.tmp $(CWD)/$$file \
) ;\
rm $$file.tmp ;\
done
# Insertion de la feuille de styles
# Insertion des liens de distribution
@for file in `ls $(OUTPUT)/*.html`; do \
if ! egrep -qi -e "$(STYLESHEET).css" $$file; then \
sed -i 's/<\/head>/<link rel=\"stylesheet\" href=\"$(STYLESHEET).css\" type=\"text\/css\" media=\"all\" \/>&/' $$file ;\
fi ;\
sed -n '1,/<div id=\"container\">/p' $$file > $$file.tmp ;\
echo '<div id="links">' >> $$file.tmp ;\
echo '<div class="sidetitle">Formats</div>' >> $$file.tmp ;\
echo '<div class="side">' >> $$file.tmp ;\
echo '<a href="/odp/$(BASENAME).odp" class="odp-small">Fichier OpenDocument</a><br />' >> $$file.tmp ;\
echo '<a href="/pdf/$(BASENAME).pdf" class="pdf-small">Fichier imprimable PDF</a><br />' >> $$file.tmp ;\
echo '</div> <!-- /side div -->' >> $$file.tmp ;\
echo '</div> <!-- /links div -->' >> $$file.tmp ;\
sed -n '/<div id=\"content\">/,$$p' $$file >> $$file.tmp ;\
mv $$file.tmp $$file ;\
done
cp $(OUTPUT)/*.html .
endif
#/*--------------------------------------------------------------------------
#* Traitement des fichiers sources DocBook XML de travaux pratiques
#*---------------------------------------------------------------------------*/
ifeq (qonly, $(findstring qonly,$(PROCESS)))
ifndef XML_FILES
XML_FILES := $(wildcard *.xml)
XML_FILES := $(filter-out $(notdir $(wildcard $(MAIN_DIR)/common/*.xml)), $(XML_FILES))
endif
BASENAME := $(basename $(firstword $(XML_FILES)))
QANAME := $(shell find "$(MAIN_DIR)" -path "$(MAIN_DIR)/xml" -prune -o -iname "$(BASENAME)a.xml" -type f -print)
qonly: $(BASENAME).xml
$(BASENAME).xml: $(QANAME)
# Extraction de l'énoncé sans les réponses
sed '/<answer.*>/, /<\/answer>/d' $< > $@
sed -i 's/$(BASENAME)a/$(BASENAME)/g' $@
endif
Jump to Line
Something went wrong with that request. Please try again.