Skip to content

Instantly share code, notes, and snippets.

@sim590
Created May 23, 2018 00:48
Show Gist options
  • Save sim590/4bfcd42b35c660d5794ccf4a8e672017 to your computer and use it in GitHub Desktop.
Save sim590/4bfcd42b35c660d5794ccf4a8e672017 to your computer and use it in GitHub Desktop.
texinputs := sty
compiler := env TEXINPUTS=".:$(addsuffix :,$(texinputs))" lualatex
bibcompiler := biber
out_exts := out log aux toc snm nav pdf dvi vrb bbl blg bcf run.xml
main_tex_file := #TODO
tex_files := $(basename $(wildcard *.tex) $(wildcard dessins/*.tex))
final_pdf_file_title := #TODO
git_rev := $(shell git rev-parse --short HEAD)
dist_name := $(final_pdf_file_title)-$(shell date +%Y%m%d)$(if $(git_rev),-$(git_rev),)
dist_files := $(addsuffix .tex,$(tex_files)) $(main_tex_file).bib $(dist_name).pdf Makefile
.PHONY: clean $(wildcard $(dist_name).*) $(main_tex_file)
########################
# Règles principales #
########################
all: $(if $(main_tex_file),$(main_tex_file).pdf,)
####################################################
# Génération des documents PDF sous format final #
####################################################
dist-pdf: $(dist_name).pdf
$(dist_name).pdf: $(main_tex_file).pdf
cp $< $@
# fichiers LaTeX
$(main_tex_file).pdf: $(main_tex_file).tex $(main_tex_file).bbl $(addsuffix .tex,$(tex_files))
cd $(dir $<) && $(compiler) $(notdir $<)
####################
# Bibliographies #
####################
$(main_tex_file).bbl: $(main_tex_file).bib
cd $(dir $<) && \
$(compiler) $(notdir $(basename $<)).tex && \
$(bibcompiler) $(notdir $(basename $<)) && \
$(compiler) $(notdir $(basename $<)).tex && \
$(compiler) $(notdir $(basename $<)).tex
clean: clean-devoir
clean-devoir: $(main_tex_file)
rm -f $(foreach ext,$(out_exts),$(addsuffix .$(ext),$^))
###########################
# Génération d'archives #
###########################
dist: dist-tar-gz
dist-sign: sign dist
sign: $(dist_name).pdf dist-dir
gpg --sign $(dist_dir)/$(dist_name)/$(dist_name).pdf
cp -t . $(dist_dir)/$(dist_name)/$(dist_name).pdf.gpg
dist-dir: $(dist_files)
$(if $(dist_dir),,$(eval dist_dir := $(shell mktemp -d "/tmp/tmp.XXXXXXXXX")))
$(foreach dfile,$(dist_files),$(shell mkdir -p $(dist_dir)/$(dist_name)/$(dir $(dfile))))
$(foreach file,$(dist_files),\
$(shell install -m 644 $(file) $(dist_dir)/$(dist_name)/$(file)))
dist-tar-gz: dist-dir $(dist_name).tar.gz
rm -rf $(dist_dir)
$(dist_name).tar.gz: $(dist_name).pdf
(cd $(dist_dir) && tar -cvzf $@ $(dist_name))
mv $(dist_dir)/$@ .
dist-zip: dist-dir $(dist_name).zip
rm -rf $(dist_dir)
$(dist_name).zip: $(dist_name).pdf
(cd $(dist_dir) && zip -qvr $@ $(dist_name))
mv $(dist_dir)/$@ .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment