Skip to content
This repository
tree: 311bf43732
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 287 lines (234 sloc) 10.228 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
#/*--------------------------------------------------------------------------
#* 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
Something went wrong with that request. Please try again.