| 1 |
|
| 2 |
####[ Check Software ]################################################ |
| 3 |
|
| 4 |
ifeq ($(filter else-if,$(.FEATURES)),) |
| 5 |
$(error GNU Make 3.81 needed. Please, update your software.) |
| 6 |
exit 1 |
| 7 |
endif |
| 8 |
|
| 9 |
# Some people want to call our Makefile snippet with |
| 10 |
# make -f LaTeX.mk |
| 11 |
# This should not work as $(MAKE) is call recursively and will not read |
| 12 |
# LaTeX.mk again. We cannot just add LaTeX.mk to MAKEFILES as LaTeX.mk |
| 13 |
# should be read AFTER a standard Makefile (if any) that can define some |
| 14 |
# variables (LU_MASTERS, ...) that LaTeX.mk must see. |
| 15 |
# So I introduce an HACK here that try to workaround the situation. Keep in |
| 16 |
# mind that this hack is not perfect and does not handle all cases |
| 17 |
# (for example, "make -f my_latex_config.mk -f LaTeX.mk" will not recurse |
| 18 |
# correctly) |
| 19 |
ifeq ($(foreach m,$(MAKEFILES), $(m)) $(lastword $(MAKEFILE_LIST)),$(MAKEFILE_LIST)) |
| 20 |
# We are the first file read after the ones from MAKEFILES |
| 21 |
# So we assume we are read due to "-f LaTeX.mk" |
| 22 |
LU_LaTeX.mk_NAME := $(lastword $(MAKEFILE_LIST)) |
| 23 |
# Is this Makefile correctly read for recursive calls ? |
| 24 |
ifeq ($(findstring -f $(LU_LaTeX.mk_NAME),$(MAKE)),) |
| 25 |
$(info ********************************************************************************) |
| 26 |
$(info Warning: $(LU_LaTeX.mk_NAME) called directly. I suppose that you run:) |
| 27 |
$(info Warning: $(MAKE) -f $(LU_LaTeX.mk_NAME) $(MAKECMDGOALS)) |
| 28 |
$(info Warning: or something similar that does not allow recursive invocation of make) |
| 29 |
$(info Warning: ) |
| 30 |
$(info Warning: Trying to enable a workaround. This ACK will be disabled in a future) |
| 31 |
$(info Warning: release. Consider using another syntax, for example:) |
| 32 |
$(info Warning: $(MAKE) -f $(LU_LaTeX.mk_NAME) MAKE="$(MAKE) -f $(LU_LaTeX.mk_NAME)" $(MAKECMDGOALS)) |
| 33 |
$(info ********************************************************************************) |
| 34 |
MAKE+= -f $(LU_LaTeX.mk_NAME) |
| 35 |
endif |
| 36 |
endif |
| 37 |
|
| 38 |
####[ Configuration ]################################################ |
| 39 |
|
| 40 |
# list of messages categories to display |
| 41 |
LU_SHOW ?= warning #info debug debug-vars |
| 42 |
|
| 43 |
# Select GNU/BSD/MACOSX utils (cp, rm, mv, ...) |
| 44 |
LU_UTILS ?= $(shell ( /bin/cp --heelp > /dev/null 2>&1 && echo GNU ) || echo BSD ) |
| 45 |
export LU_UTILS |
| 46 |
|
| 47 |
####[ End of configuration ]################################################ |
| 48 |
# Modifying the remaining of this document may endanger you life!!! ;) |
| 49 |
|
| 50 |
#--------------------------------------------------------------------- |
| 51 |
# Controling verbosity |
| 52 |
ifdef VERB |
| 53 |
MAK_VERB := $(VERB) |
| 54 |
else |
| 55 |
#MAK_VERB := debug |
| 56 |
#MAK_VERB := verbose |
| 57 |
#MAK_VERB := normal |
| 58 |
MAK_VERB := quiet |
| 59 |
#MAK_VERB := silent |
| 60 |
endif |
| 61 |
|
| 62 |
#--------------------------------------------------------------------- |
| 63 |
# MAK_VERB -> verbosity |
| 64 |
ifeq ($(MAK_VERB),debug) |
| 65 |
COMMON_PREFIX = echo " ======> building " $@ "<======" ; \ |
| 66 |
printf "%s $(@F) due to:$(foreach file,$?,\n * $(file))\n" $1; set -x; |
| 67 |
# |
| 68 |
COMMON_HIDE := set -x; |
| 69 |
COMMON_CLEAN := set -x; |
| 70 |
SHOW_LATEX:=true |
| 71 |
else |
| 72 |
ifeq ($(MAK_VERB),verbose) |
| 73 |
COMMON_PREFIX = echo " ======> building " $@ "<======" ; \ |
| 74 |
printf "%s $(@F) due to:$(foreach file,$?,\n * $(file))\n" $1; |
| 75 |
# |
| 76 |
COMMON_HIDE :=# |
| 77 |
COMMON_CLEAN :=# |
| 78 |
SHOW_LATEX:=true |
| 79 |
else |
| 80 |
ifeq ($(MAK_VERB),normal) |
| 81 |
COMMON_PREFIX =# |
| 82 |
COMMON_HIDE := @ |
| 83 |
COMMON_CLEAN :=# |
| 84 |
SHOW_LATEX:=true |
| 85 |
else |
| 86 |
ifeq ($(MAK_VERB),quiet) |
| 87 |
COMMON_PREFIX = @ echo " ======> building " $@ "<======" ; |
| 88 |
# echo "due to $?" ; |
| 89 |
COMMON_HIDE := @ |
| 90 |
COMMON_CLEAN :=# |
| 91 |
SHOW_LATEX:= |
| 92 |
else # silent |
| 93 |
COMMON_PREFIX = @ |
| 94 |
COMMON_HIDE := @ |
| 95 |
COMMON_CLEAN := @ |
| 96 |
SHOW_LATEX:= |
| 97 |
endif |
| 98 |
endif |
| 99 |
endif |
| 100 |
endif |
| 101 |
|
| 102 |
#--------------------------------------------------------------------- |
| 103 |
# Old LaTeX have limitations |
| 104 |
_LU_PDFTEX_EXT ?= pdftex |
| 105 |
|
| 106 |
######################################################################### |
| 107 |
# Utilities |
| 108 |
LU_CP=$(LU_CP_$(LU_UTILS)) |
| 109 |
LU_MV=$(LU_MV_$(LU_UTILS)) |
| 110 |
LU_RM=$(LU_RM_$(LU_UTILS)) |
| 111 |
LU_CP_GNU ?= cp -a -- |
| 112 |
LU_MV_GNU ?= mv -- |
| 113 |
LU_RM_GNU ?= rm -f -- |
| 114 |
LU_CP_BSD ?= cp -p |
| 115 |
LU_MV_BSD ?= mv |
| 116 |
LU_RM_BSD ?= rm -f |
| 117 |
LU_CP_MACOSX ?= /bin/cp -p |
| 118 |
LU_MV_MACOSX ?= /bin/mv |
| 119 |
LU_RM_MACOSX ?= /bin/rm -f |
| 120 |
|
| 121 |
lu-show=\ |
| 122 |
$(if $(filter $(LU_SHOW),$(1)), \ |
| 123 |
$(if $(2), \ |
| 124 |
$(if $(filter-out $(2),$(MAKELEVEL)),,$(3)), \ |
| 125 |
$(3))) |
| 126 |
lu-show-infos=\ |
| 127 |
$(if $(filter $(LU_SHOW),$(1)), \ |
| 128 |
$(if $(2), \ |
| 129 |
$(if $(filter-out $(2),$(MAKELEVEL)),,$(warning $(3))), \ |
| 130 |
$(warning $(3)))) |
| 131 |
lu-show-rules=$(call lu-show-infos,info,0,$(1)) |
| 132 |
lu-show-flavors=$(call lu-show-infos,info,0,$(1)) |
| 133 |
lu-show-var=$(call lu-show-infos,debug-vars,, * Set $(1)=$($(1))) |
| 134 |
lu-show-read-var=$(eval $(call lu-show-infos,debug-vars,, Reading $(1) in $(2) ctx: $(3)))$(3) |
| 135 |
lu-show-readone-var=$(eval $(call lu-show-infos,debug-vars,, Reading $(1) for $(2) [one value]: $(3)))$(3) |
| 136 |
lu-show-set-var=$(call lu-show-infos,debug-vars,, * Setting $(1) for $(2) to value: $(3)) |
| 137 |
lu-show-add-var=$(call lu-show-infos,debug-vars,, * Adding to $(1) for $(2) values: $(value 3)) |
| 138 |
lu-show-add-var2=$(call lu-show-infos,warning,, * Adding to $(1) for $(2) values: $(value 3)) |
| 139 |
|
| 140 |
lu-save-file=$(call lu-show,debug,,echo "saving $1" ;) \ |
| 141 |
if [ -f "$1" ];then $(LU_CP) "$1" "$2" ;else $(LU_RM) "$2" ;fi |
| 142 |
lu-cmprestaure-file=\ |
| 143 |
if cmp -s "$1" "$2"; then \ |
| 144 |
$(LU_MV) "$2" "$1" ; \ |
| 145 |
$(call lu-show,debug,,echo "$1" not modified ;) \ |
| 146 |
else \ |
| 147 |
$(call lu-show,debug,,echo "$1" modified ;) \ |
| 148 |
if [ -f "$2" -o -f "$1" ]; then \ |
| 149 |
$(RM) -- "$2" ; \ |
| 150 |
$3 \ |
| 151 |
fi ; \ |
| 152 |
fi |
| 153 |
|
| 154 |
lu-clean=$(if $(strip $(1)),$(RM) $(1)) |
| 155 |
|
| 156 |
define lu-bug # description |
| 157 |
$$(warning Internal error: $(1)) |
| 158 |
$$(error You probably found a bug. Please, report it.) |
| 159 |
endef |
| 160 |
|
| 161 |
######################################################################### |
| 162 |
######################################################################### |
| 163 |
######################################################################### |
| 164 |
######################################################################### |
| 165 |
################## ######################### |
| 166 |
################## Variables ######################### |
| 167 |
################## ######################### |
| 168 |
######################################################################### |
| 169 |
######################################################################### |
| 170 |
######################################################################### |
| 171 |
######################################################################### |
| 172 |
######################################################################### |
| 173 |
# |
| 174 |
# _LU_FLAVORS_DEFINED : list of available flavors |
| 175 |
# _LU_FLAV_*_'flavname' : per flavor variables |
| 176 |
# where * can be : |
| 177 |
# PROGNAME : variable name for programme (and .._OPTIONS for options) |
| 178 |
# EXT : extension of created file |
| 179 |
# TARGETNAME : global target |
| 180 |
# DEPFLAVOR : flavor to depend upon |
| 181 |
# CLEANFIGEXT : extensions to clean for fig figures |
| 182 |
_LU_FLAVORS_DEFINED = $(_LU_FLAVORS_DEFINED_TEX) $(_LU_FLAVORS_DEFINED_DVI) |
| 183 |
|
| 184 |
# INDEXES_TYPES = GLOSS INDEX |
| 185 |
# INDEXES_INDEX = name1 ... |
| 186 |
# INDEXES_GLOSS = name2 ... |
| 187 |
# INDEX_name1_SRC |
| 188 |
# GLOSS_name2_SRC |
| 189 |
|
| 190 |
define _lu-getvalues# 1:VAR 2:CTX (no inheritage) |
| 191 |
$(if $(filter-out undefined,$(origin LU_$2$1)),$(LU_$2$1),$($2$1) $(_LU_$2$1_MK) $(TD_$2$1)) |
| 192 |
endef |
| 193 |
define lu-define-addvar # 1:suffix_fnname 2:CTX 3:disp-debug 4:nb_args 5:inherited_ctx 6:ctx-build-depend |
| 194 |
define lu-addtovar$1 # 1:VAR 2:... $4: value |
| 195 |
_LU_$2$$1_MK+=$$($4) |
| 196 |
$$(call lu-show-add-var,$$1,$3,$$(value $4)) |
| 197 |
endef |
| 198 |
define lu-def-addvar-inherited-ctx$1 # 1:VAR 2:... |
| 199 |
$6 |
| 200 |
_LU_$2$$1_INHERITED_CTX=$$(sort \ |
| 201 |
$$(foreach ctx,$5,$$(ctx) $$(if $$(filter-out undefined,$$(origin \ |
| 202 |
LU_$$(ctx)$$1)),,\ |
| 203 |
$$(_LU_$$(ctx)$$1_INHERITED_CTX)))) |
| 204 |
$$$$(call lu-show-var,_LU_$2$$1_INHERITED_CTX) |
| 205 |
endef |
| 206 |
define lu-getvalues$1# 1:VAR 2:... |
| 207 |
$$(if $$(filter-out undefined,$$(origin _LU_$2$$1_INHERITED_CTX)),,$$(eval \ |
| 208 |
$$(call lu-def-addvar-inherited-ctx$1,$$1,$$2,$$3,$$4,$$5,$$6)\ |
| 209 |
))$$(call lu-show-read-var,$$1,$3,$$(foreach ctx,\ |
| 210 |
$(if $2,$2,GLOBAL) $$(if $$(filter-out undefined,$$(origin LU_$2$$1)),,\ |
| 211 |
$$(_LU_$2$$1_INHERITED_CTX))\ |
| 212 |
,$$(call _lu-getvalues,$$1,$$(filter-out GLOBAL,$$(ctx))))) |
| 213 |
endef |
| 214 |
endef |
| 215 |
|
| 216 |
# Global variable |
| 217 |
# VAR (DEPENDS) |
| 218 |
$(eval $(call lu-define-addvar,-global,,global,2)) |
| 219 |
|
| 220 |
# Per flavor variable |
| 221 |
# FLAVOR_$2_VAR (FLAVOR_DVI_DEPENDS) |
| 222 |
# 2: flavor name |
| 223 |
# Inherit from VAR (DEPENDS) |
| 224 |
$(eval $(call lu-define-addvar,-flavor,FLAVOR_$$2_,flavor $$2,3,\ |
| 225 |
GLOBAL,\ |
| 226 |
$$(eval $$(call lu-def-addvar-inherited-ctx-global,$$1)) \ |
| 227 |
)) |
| 228 |
|
| 229 |
# Per master variable |
| 230 |
# $2_VAR (source_DEPENDS) |
| 231 |
# 2: master name |
| 232 |
# Inherit from VAR (DEPENDS) |
| 233 |
$(eval $(call lu-define-addvar,-master,$$2_,master $$2,3,\ |
| 234 |
GLOBAL,\ |
| 235 |
$$(eval $$(call lu-def-addvar-inherited-ctx-global,$$1)) \ |
| 236 |
)) |
| 237 |
|
| 238 |
# Per target variable |
| 239 |
# $2$(EXT of $3)_VAR (source.dvi_DEPENDS) |
| 240 |
# 2: master name |
| 241 |
# 3: flavor name |
| 242 |
# Inherit from $2_VAR FLAVOR_$3_VAR (source_DEPENDS FLAVOR_DVI_DEPENDS) |
| 243 |
$(eval $(call lu-define-addvar,,$$2$$(call lu-getvalue-flavor,EXT,$$3)_,target $$2$$(call lu-getvalue-flavor,EXT,$$3),4,\ |
| 244 |
$$2_ FLAVOR_$$3_,\ |
| 245 |
$$(eval $$(call lu-def-addvar-inherited-ctx-master,$$1,$$2)) \ |
| 246 |
$$(eval $$(call lu-def-addvar-inherited-ctx-flavor,$$1,$$3)) \ |
| 247 |
)) |
| 248 |
|
| 249 |
# Per index/glossary variable |
| 250 |
# $(2)_$(3)_VAR (INDEX_source_DEPENDS) |
| 251 |
# 2: type (INDEX, GLOSS, ...) |
| 252 |
# 3: index name |
| 253 |
# Inherit from VAR (DEPENDS) |
| 254 |
$(eval $(call lu-define-addvar,-global-index,$$2_$$3_,index $$3[$$2],4,\ |
| 255 |
GLOBAL,\ |
| 256 |
$$(eval $$(call lu-def-addvar-inherited-ctx-global,$$1)) \ |
| 257 |
)) |
| 258 |
|
| 259 |
# Per master and per index/glossary variable |
| 260 |
# $(2)_$(3)_$(4)_VAR (source_INDEX_source_DEPENDS) |
| 261 |
# 2: master name |
| 262 |
# 3: type (INDEX, GLOSS, ...) |
| 263 |
# 4: index name |
| 264 |
# Inherit from $2_VAR $3_$4_VAR (source_DEPENDS INDEX_source_DEPENDS) |
| 265 |
$(eval $(call lu-define-addvar,-master-index,$$2_$$3_$$4_,index $$2/$$4[$$3],5,\ |
| 266 |
$$2_ $$3_$$4_,\ |
| 267 |
$$(eval $$(call lu-def-addvar-inherited-ctx-master,$$1,$$2)) \ |
| 268 |
$$(eval $$(call lu-def-addvar-inherited-ctx-global-index,$$1,$$3,$$4)) \ |
| 269 |
)) |
| 270 |
|
| 271 |
# Per target and per index/glossary variable |
| 272 |
# $(2)$(EXT of $3)_$(4)_$(5)_VAR (source.dvi_INDEX_source_DEPENDS) |
| 273 |
# 2: master name |
| 274 |
# 3: flavor name |
| 275 |
# 4: type (INDEX, GLOSS, ...) |
| 276 |
# 5: index name |
| 277 |
# Inherit from $2$(EXT of $3)_VAR $(2)_$(3)_$(4)_VAR |
| 278 |
# (source.dvi_DEPENDS source_INDEX_source_DEPENDS) |
| 279 |
$(eval $(call lu-define-addvar,-index,$$2$$(call lu-getvalue-flavor,EXT,$$3)_$$4_$$5_,index $$2$$(call lu-getvalue-flavor,EXT,$$3)/$$5[$$4],6,\ |
| 280 |
$$2$$(call lu-getvalue-flavor,EXT,$$3)_ $$2_$$4_$$5_,\ |
| 281 |
$$(eval $$(call lu-def-addvar-inherited-ctx,$$1,$$2,$$3)) \ |
| 282 |
$$(eval $$(call lu-def-addvar-inherited-ctx-master-index,$$1,$$2,$$4,$$5)) \ |
| 283 |
)) |
| 284 |
|
| 285 |
define lu-setvar-global # 1:name 2:value |
| 286 |
_LU_$(1) ?= $(2) |
| 287 |
$$(eval $$(call lu-show-set-var,$(1),global,$(2))) |
| 288 |
endef |
| 289 |
|
| 290 |
define lu-setvar-flavor # 1:name 2:flavor 3:value |
| 291 |
_LU_FLAVOR_$(2)_$(1) ?= $(3) |
| 292 |
$$(eval $$(call lu-show-set-var,$(1),flavor $(2),$(3))) |
| 293 |
endef |
| 294 |
|
| 295 |
define lu-setvar-master # 1:name 2:master 3:value |
| 296 |
_LU_$(2)_$(1) ?= $(3) |
| 297 |
$$(eval $$(call lu-show-set-var,$(1),master $(2),$(3))) |
| 298 |
endef |
| 299 |
|
| 300 |
define lu-setvar # 1:name 2:master 3:flavor 4:value |
| 301 |
_LU_$(2)$$(call lu-getvalue-flavor,EXT,$(3))_$(1)=$(4) |
| 302 |
$$(eval $$(call lu-show-set-var,$(1),master/flavor $(2)/$(3),$(4))) |
| 303 |
endef |
| 304 |
|
| 305 |
define lu-getvalue # 1:name 2:master 3:flavor |
| 306 |
$(call lu-show-readone-var,$(1),master/flavor $(2)/$(3),$(or \ |
| 307 |
$(LU_$(2)$(call lu-getvalue-flavor,EXT,$(3))_$(1)), \ |
| 308 |
$(TD_$(2)$(call lu-getvalue-flavor,EXT,$(3))_$(1)), \ |
| 309 |
$(LU_$(2)_$(1)), \ |
| 310 |
$($(2)_$(1)), \ |
| 311 |
$(LU_FLAVOR_$(3)_$(1)), \ |
| 312 |
$(LU_$(1)), \ |
| 313 |
$($(1)), \ |
| 314 |
$(_LU_$(2)$(call lu-getvalue-flavor,EXT,$(3))_$(1)), \ |
| 315 |
$(_LU_$(2)_$(1)), \ |
| 316 |
$(_LU_FLAVOR_$(3)_$(1)), \ |
| 317 |
$(_LU_$(1))\ |
| 318 |
)) |
| 319 |
endef |
| 320 |
|
| 321 |
define lu-getvalue-flavor # 1:name 2:flavor |
| 322 |
$(call lu-show-readone-var,$(1),flavor $(2),$(or \ |
| 323 |
$(LU_FLAVOR_$(2)_$(1)), \ |
| 324 |
$(LU_$(1)), \ |
| 325 |
$($(1)), \ |
| 326 |
$(_LU_FLAVOR_$(2)_$(1)), \ |
| 327 |
$(_LU_$(1))\ |
| 328 |
)) |
| 329 |
endef |
| 330 |
|
| 331 |
define lu-getvalue-master # 1:name 2:master |
| 332 |
$(call lu-show-readone-var,$(1),master $(2),$(or \ |
| 333 |
$(LU_$(2)_$(1)), \ |
| 334 |
$($(2)_$(1)), \ |
| 335 |
$(LU_$(1)), \ |
| 336 |
$($(1)), \ |
| 337 |
$(_LU_$(2)_$(1)), \ |
| 338 |
$(_LU_$(1))\ |
| 339 |
)) |
| 340 |
endef |
| 341 |
|
| 342 |
define lu-getvalue-index # 1:name 2:master 3:flavor 4:type 5:indexname |
| 343 |
$(call lu-show-readone-var,$(1),master/flavor/index $(2)/$(3)/[$(4)]$(5),$(or \ |
| 344 |
$(LU_$(2)$(call lu-getvalue-flavor,EXT,$(3))_$(4)_$(5)_$(1)), \ |
| 345 |
$(LU_$(2)_$(4)_$(5)_$(1)), \ |
| 346 |
$(TD_$(2)$(call lu-getvalue-flavor,EXT,$(3))_$(4)_$(5)_$(1)), \ |
| 347 |
$($(2)_$(4)_$(5)_$(1)), \ |
| 348 |
$(LU_$(4)_$(5)_$(1)), \ |
| 349 |
$($(4)_$(5)_$(1)), \ |
| 350 |
$(LU_$(2)$(call lu-getvalue-flavor,EXT,$(3))_$(4)_$(1)), \ |
| 351 |
$(LU_$(2)_$(4)_$(1)), \ |
| 352 |
$($(2)_$(4)_$(1)), \ |
| 353 |
$(LU_$(4)_$(1)), \ |
| 354 |
$($(4)_$(1)), \ |
| 355 |
$(LU_$(2)_$(1)), \ |
| 356 |
$($(2)_$(1)), \ |
| 357 |
$(LU_FLAVOR_$(3)_$(1)), \ |
| 358 |
$(LU_$(1)), \ |
| 359 |
$($(1)), \ |
| 360 |
$(_LU_$(2)$(call lu-getvalue-flavor,EXT,$(3))_$(4)_$(5)_$(1)), \ |
| 361 |
$(_LU_$(2)_$(4)_$(5)_$(1)), \ |
| 362 |
$(_LU_$(4)_$(5)_$(1)), \ |
| 363 |
$(_LU_$(2)$(call lu-getvalue-flavor,EXT,$(3))_$(4)_$(1)), \ |
| 364 |
$(_LU_$(2)_$(4)_$(1)), \ |
| 365 |
$(_LU_FLAVOR_$(3)_$(4)_$(1)), \ |
| 366 |
$(_LU_$(4)_$(1)), \ |
| 367 |
$(_LU_$(2)$(call lu-getvalue-flavor,EXT,$(3))_$(1)), \ |
| 368 |
$(_LU_$(2)_$(1)), \ |
| 369 |
$(_LU_FLAVOR_$(3)_$(1)), \ |
| 370 |
$(_LU_$(1))\ |
| 371 |
)) |
| 372 |
endef |
| 373 |
|
| 374 |
define lu-call-prog # 1:varname 2:master 3:flavor [4:index] |
| 375 |
$(call lu-getvalue,$(1),$(2),$(3)) $(call lu-getvalues,$(1)_OPTIONS,$(2),$(3)) |
| 376 |
endef |
| 377 |
|
| 378 |
define lu-call-prog-index # 1:varname 2:master 3:flavor 4:type 5:indexname |
| 379 |
$(call lu-getvalue$(if $(4),-index),$(1),$(2),$(3),$(4),$(5)) \ |
| 380 |
$(call lu-getvalues$(if $(4),-index),$(1)_OPTIONS,$(2),$(3),$(4),$(5)) |
| 381 |
endef |
| 382 |
|
| 383 |
define lu-call-prog-flavor # 1:master 2:flavor |
| 384 |
$(call lu-call-prog,$(call lu-getvalue,VARPROG,$(1),$(2)),$(1),$(2)) |
| 385 |
endef |
| 386 |
|
| 387 |
######################################################################### |
| 388 |
######################################################################### |
| 389 |
######################################################################### |
| 390 |
######################################################################### |
| 391 |
################## ######################### |
| 392 |
################## Global variables ######################### |
| 393 |
################## ######################### |
| 394 |
######################################################################### |
| 395 |
######################################################################### |
| 396 |
######################################################################### |
| 397 |
######################################################################### |
| 398 |
######################################################################### |
| 399 |
|
| 400 |
# Globals variables |
| 401 |
$(eval $(call lu-setvar-global,LATEX,latex)) |
| 402 |
$(eval $(call lu-setvar-global,PDFLATEX,pdflatex)) |
| 403 |
$(eval $(call lu-setvar-global,LUALATEX,lualatex)) |
| 404 |
$(eval $(call lu-setvar-global,DVIPS,dvips)) |
| 405 |
$(eval $(call lu-setvar-global,DVIPDFM,dvipdfm)) |
| 406 |
$(eval $(call lu-setvar-global,BIBTEX,bibtex)) |
| 407 |
#$(eval $(call lu-setvar-global,MPOST,TEX="$(LATEX)" mpost)) |
| 408 |
$(eval $(call lu-setvar-global,FIG2DEV,fig2dev)) |
| 409 |
#$(eval $(call lu-setvar-global,SVG2DEV,svg2dev)) |
| 410 |
$(eval $(call lu-setvar-global,EPSTOPDF,epstopdf)) |
| 411 |
$(eval $(call lu-setvar-global,MAKEINDEX,makeindex)) |
| 412 |
|
| 413 |
# workaround the fact that $(shell ...) ignore locally exported variables |
| 414 |
# get only the variables with plain names |
| 415 |
_LU_MAKE_ENV := $(shell echo '$(.VARIABLES)' | awk -v RS=' ' '/^[a-zA-Z0-9]+$$/') |
| 416 |
_LU_SHELL_EXPORT := $(foreach v,$(_LU_MAKE_ENV),$(v)='$($(v))') |
| 417 |
_lu_run_kpsewhich=$(shell $(_LU_SHELL_EXPORT) kpsewhich -format $1 $2) |
| 418 |
|
| 419 |
# Look first into the TDS (texmfscripts), then in PATH for our program |
| 420 |
# At each location, we prefer with suffix than without |
| 421 |
define _lu_which # VARNAME progname |
| 422 |
ifeq ($(origin _LU_$(1)_DEFAULT), undefined) |
| 423 |
_LU_$(1)_DEFAULT := $$(firstword $$(wildcard \ |
| 424 |
$$(call _lu_run_kpsewhich,texmfscripts,$(2)) \ |
| 425 |
$$(call _lu_run_kpsewhich,texmfscripts,$$(basename $(2))) \ |
| 426 |
$$(foreach dir,$$(subst :, ,$$(PATH)), \ |
| 427 |
$$(dir)/$(2) $$(dir)/$$(basename $(2))) \ |
| 428 |
) $(2)) |
| 429 |
export _LU_$(1)_DEFAULT |
| 430 |
_LU_$(1)_DEFAULT_OLD := $$(firstword $$(wildcard \ |
| 431 |
$$(addprefix bin/,$(2) $$(basename $(2))) \ |
| 432 |
$$(addprefix ./,$(2) $$(basename $(2))))) |
| 433 |
$$(if $$(filter-out $$(_LU_$(1)_DEFAULT), $$(_LU_$(1)_DEFAULT_OLD)),\ |
| 434 |
$$(if $$(_lu_scripts_warnings),, \ |
| 435 |
$$(eval _lu_scripts_warnings:=done) \ |
| 436 |
$$(warning By default, this version of LaTeX-Make do not use \ |
| 437 |
scripts in $$(dir $$(_LU_$(1)_DEFAULT_OLD)) anymore.) \ |
| 438 |
$$(warning For example $$(_LU_$(1)_DEFAULT) is used instead of $$(_LU_$(1)_DEFAULT_OLD))\ |
| 439 |
$$(warning If you want to keep the old behavior, add into your \ |
| 440 |
Makefile something like:)\ |
| 441 |
$$(warning export TEXMFSCRIPTS:=$$(dir $$(_LU_$(1)_DEFAULT_OLD))$$$$(addprefix :,$$$$(TEXMFSCRIPTS))::))) |
| 442 |
#$$(warning _LU_$(1)_DEFAULT=$$(_LU_$(1)_DEFAULT)) |
| 443 |
endif |
| 444 |
$$(eval $$(call lu-setvar-global,$(1),$$(_LU_$(1)_DEFAULT))) |
| 445 |
endef |
| 446 |
|
| 447 |
$(eval $(call _lu_which,GENSUBFIG,gensubfig.py)) |
| 448 |
$(eval $(call _lu_which,FIGDEPTH,figdepth.py)) |
| 449 |
$(eval $(call _lu_which,GENSUBSVG,gensubfig.py)) |
| 450 |
$(eval $(call _lu_which,SVGDEPTH,svgdepth.py)) |
| 451 |
$(eval $(call _lu_which,SVG2DEV,svg2dev.py)) |
| 452 |
$(eval $(call _lu_which,LATEXFILTER,latexfilter.py)) |
| 453 |
|
| 454 |
# Rules to use to check if the build document (dvi or pdf) is up-to-date |
| 455 |
# This can be overruled per document manually and/or automatically |
| 456 |
#REBUILD_RULES ?= latex texdepends bibtopic bibtopic_undefined_references |
| 457 |
$(eval $(call lu-addtovar-global,REBUILD_RULES,latex texdepends)) |
| 458 |
|
| 459 |
# Default maximum recursion level |
| 460 |
$(eval $(call lu-setvar-global,MAX_REC,6)) |
| 461 |
|
| 462 |
######################################################################### |
| 463 |
######################################################################### |
| 464 |
######################################################################### |
| 465 |
######################################################################### |
| 466 |
################## ######################### |
| 467 |
################## Flavors ######################### |
| 468 |
################## ######################### |
| 469 |
######################################################################### |
| 470 |
######################################################################### |
| 471 |
######################################################################### |
| 472 |
######################################################################### |
| 473 |
######################################################################### |
| 474 |
|
| 475 |
define lu-create-texflavor # 1:name 2:tex_prog 3:file_ext |
| 476 |
# 4:master_cible 5:fig_extention_to_clean |
| 477 |
_LU_FLAVORS_DEFINED_TEX += $(1) |
| 478 |
$(eval $(call lu-setvar-flavor,VARPROG,$(1),$(2))) |
| 479 |
$(eval $(call lu-setvar-flavor,EXT,$(1),$(3))) |
| 480 |
$(eval $(call lu-setvar-flavor,TARGETNAME,$(1),$(4))) |
| 481 |
$(eval $(call lu-addtovar-flavor,CLEANFIGEXT,$(1),$(5))) |
| 482 |
$(eval $(call lu-addtovar-flavor,CLEANSVGEXT,$(1),$(5))) |
| 483 |
endef |
| 484 |
|
| 485 |
define lu-create-dviflavor # 1:name 2:dvi_prog 3:file_ext |
| 486 |
# 4:master_cible 5:tex_flavor_depend |
| 487 |
$$(eval $$(call lu-define-flavor,$(5))) |
| 488 |
_LU_FLAVORS_DEFINED_DVI += $(1) |
| 489 |
$(eval $(call lu-setvar-flavor,VARPROG,$(1),$(2))) |
| 490 |
$(eval $(call lu-setvar-flavor,EXT,$(1),$(3))) |
| 491 |
$(eval $(call lu-setvar-flavor,TARGETNAME,$(1),$(4))) |
| 492 |
$(eval $(call lu-setvar-flavor,DEPFLAVOR,$(1),$(5))) |
| 493 |
endef |
| 494 |
|
| 495 |
define lu-create-flavor # 1:name 2:type 3..7:options |
| 496 |
$$(if $$(filter $(1),$(_LU_FLAVORS_DEFINED)), \ |
| 497 |
$$(call lu-show-flavors,Flavor $(1) already defined), \ |
| 498 |
$$(call lu-show-flavors,Creating flavor $(1) ($(2))) \ |
| 499 |
$$(eval $$(call lu-create-$(2)flavor,$(1),$(3),$(4),$(5),$(6),$(7)))) |
| 500 |
endef |
| 501 |
|
| 502 |
define lu-define-flavor # 1:name |
| 503 |
$$(eval $$(call lu-define-flavor-$(1))) |
| 504 |
endef |
| 505 |
|
| 506 |
define lu-flavor-rules # 1:name |
| 507 |
$$(call lu-show-flavors,Defining rules for flavor $(1)) |
| 508 |
$$(if $$(call lu-getvalue-flavor,TARGETNAME,$(1)), \ |
| 509 |
$$(call lu-getvalue-flavor,TARGETNAME,$(1)): \ |
| 510 |
$$(call lu-getvalues-flavor,TARGETS,$(1))) |
| 511 |
$$(if $$(call lu-getvalue-flavor,TARGETNAME,$(1)), \ |
| 512 |
.PHONY: $$(call lu-getvalue-flavor,TARGETNAME,$(1))) |
| 513 |
endef |
| 514 |
|
| 515 |
define lu-define-flavor-DVI # |
| 516 |
$$(eval $$(call lu-create-flavor,DVI,tex,LATEX,.dvi,dvi,\ |
| 517 |
.pstex_t .pstex)) |
| 518 |
endef |
| 519 |
|
| 520 |
define lu-define-flavor-PDF # |
| 521 |
$$(eval $$(call lu-create-flavor,PDF,tex,PDFLATEX,.pdf,pdf,\ |
| 522 |
.pdftex_t .$$(_LU_PDFTEX_EXT))) |
| 523 |
endef |
| 524 |
|
| 525 |
define lu-define-flavor-LUALATEX # |
| 526 |
$$(eval $$(call lu-create-flavor,LUALATEX,tex,LUALATEX,.pdf,pdf,\ |
| 527 |
.pdftex_t .$$(_LU_PDFTEX_EXT))) |
| 528 |
endef |
| 529 |
|
| 530 |
define lu-define-flavor-PS # |
| 531 |
$$(eval $$(call lu-create-flavor,PS,dvi,DVIPS,.ps,ps,DVI)) |
| 532 |
endef |
| 533 |
|
| 534 |
define lu-define-flavor-DVIPDF # |
| 535 |
$$(eval $$(call lu-create-flavor,DVIPDF,dvi,DVIPDFM,.pdf,pdf,DVI)) |
| 536 |
endef |
| 537 |
|
| 538 |
$(eval $(call lu-addtovar-global,FLAVORS,PDF PS)) |
| 539 |
|
| 540 |
######################################################################### |
| 541 |
######################################################################### |
| 542 |
######################################################################### |
| 543 |
######################################################################### |
| 544 |
################## ######################### |
| 545 |
################## Masters ######################### |
| 546 |
################## ######################### |
| 547 |
######################################################################### |
| 548 |
######################################################################### |
| 549 |
######################################################################### |
| 550 |
######################################################################### |
| 551 |
######################################################################### |
| 552 |
|
| 553 |
define _lu-do-latex # 1:master 2:flavor 3:source.tex 4:ext(.dvi/.pdf) |
| 554 |
exec 3>&1; \ |
| 555 |
run() { \ |
| 556 |
printf "Running:" 1>&3 ; \ |
| 557 |
for arg; do \ |
| 558 |
printf "%s" " '$$arg'" 1>&3 ; \ |
| 559 |
done ; echo 1>&3 ; \ |
| 560 |
"$$@" ; \ |
| 561 |
}; \ |
| 562 |
doit() { \ |
| 563 |
$(RM) -v "$(1)$(4)_FAILED" \ |
| 564 |
"$(1)$(4)_NEED_REBUILD" \ |
| 565 |
"$(1)$(4).mk" ;\ |
| 566 |
( echo X | \ |
| 567 |
run $(call lu-call-prog-flavor,$(1),$(2)) \ |
| 568 |
--interaction errorstopmode \ |
| 569 |
--jobname "$(1)" \ |
| 570 |
'\RequirePackage[extension='"$(4)"']{texdepends}\input'"{$(3)}" || \ |
| 571 |
touch "$(1)$(4)_FAILED" ; \ |
| 572 |
if grep -sq '^! LaTeX Error:' "$(1).log" ; then \ |
| 573 |
touch "$(1)$(4)_FAILED" ; \ |
| 574 |
fi \ |
| 575 |
) | $(call lu-call-prog,LATEXFILTER,$(1),$(2)) ; \ |
| 576 |
NO_TEXDEPENDS_FILE=0 ;\ |
| 577 |
if [ ! -f "$(1)$(4).mk" ]; then \ |
| 578 |
NO_TEXDEPENDS_FILE=1 ;\ |
| 579 |
fi ;\ |
| 580 |
sed -e 's,\\openout[0-9]* = \([^`].*\),TD_$(1)$(4)_OUTPUTS += \1,p;s,\\openout[0-9]* = `\(.*\)'"'.,TD_$(1)$(4)_OUTPUTS += \1,p;d" \ |
| 581 |
"$(1).log" >> "$(1)$(4).mk" ;\ |
| 582 |
if [ -f "$(1)$(4)_FAILED" ]; then \ |
| 583 |
echo "*************************************" ;\ |
| 584 |
echo "Building $(1)$(4) fails" ;\ |
| 585 |
echo "*************************************" ;\ |
| 586 |
echo "Here are the last lines of the log file" ;\ |
| 587 |
echo "If this is not enought, try to" ;\ |
| 588 |
echo "call 'make' with 'VERB=verbose' option" ;\ |
| 589 |
echo "*************************************" ;\ |
| 590 |
echo "==> Last lines in $(1).log <==" ; \ |
| 591 |
sed -e '/^[?] X$$/,$$d' \ |
| 592 |
-e '/^Here is how much of TeX'"'"'s memory you used:$$/,$$d' \ |
| 593 |
< "$(1).log" | tail -n 20; \ |
| 594 |
return 1; \ |
| 595 |
fi; \ |
| 596 |
if [ "$$NO_TEXDEPENDS_FILE" = 1 ]; then \ |
| 597 |
echo "*************************************" ;\ |
| 598 |
echo "texdepends does not seems be loaded" ;\ |
| 599 |
echo "Either your (La)TeX installation is wrong or you found a bug." ;\ |
| 600 |
echo "If so, please, report it (with the result of shell command 'kpsepath tex')";\ |
| 601 |
echo "Aborting compilation" ;\ |
| 602 |
echo "*************************************" ;\ |
| 603 |
touch "$(1)$(4)_FAILED" ; \ |
| 604 |
return 1 ;\ |
| 605 |
fi ;\ |
| 606 |
}; doit |
| 607 |
endef |
| 608 |
|
| 609 |
.PHONY: clean-build-fig |
| 610 |
|
| 611 |
########################################################## |
| 612 |
define lu-master-texflavor-index-vars # MASTER FLAVOR TYPE INDEX ext(.dvi/.pdf) |
| 613 |
$$(call lu-show-rules,Setting flavor index vars for $(1)/$(2)/[$(3)]$(4)) |
| 614 |
$$(eval $$(call lu-addtovar,DEPENDS,$(1),$(2), \ |
| 615 |
$$(call lu-getvalue-index,TARGET,$(1),$(2),$(3),$(4)))) |
| 616 |
$$(eval $$(call lu-addtovar,WATCHFILES,$(1),$(2), \ |
| 617 |
$$(call lu-getvalue-index,SRC,$(1),$(2),$(3),$(4)))) |
| 618 |
endef #################################################### |
| 619 |
define lu-master-texflavor-index-rules # MASTER FLAVOR TYPE INDEX ext(.dvi/.pdf) |
| 620 |
$$(call lu-show-rules,Setting flavor index rules for $(1)/$(2)/[$(3)]$(4)) |
| 621 |
$$(if $$(_LU_DEF_IND_$$(call lu-getvalue-index,TARGET,$(1),$(2),$(3),$(4))), \ |
| 622 |
$$(call lu-show-rules,=> Skipping: already defined in flavor $$(_LU_DEF_IND_$$(call lu-getvalue-index,TARGET,$(1),$(2),$(3),$(4)))), \ |
| 623 |
$$(eval $$(call _lu-master-texflavor-index-rules\ |
| 624 |
,$(1),$(2),$(3),$(4),$(5),$$(call lu-getvalue-index,TARGET,$(1),$(2),$(3),$(4))))) |
| 625 |
endef |
| 626 |
define _lu-master-texflavor-index-rules # MASTER FLAVOR TYPE INDEX ext TARGET |
| 627 |
$(6): \ |
| 628 |
$$(call lu-getvalue-index,SRC,$(1),$(2),$(3),$(4)) \ |
| 629 |
$$(wildcard $$(call lu-getvalue-index,STYLE,$(1),$(2),$(3),$(4))) |
| 630 |
$$(COMMON_PREFIX)$$(call lu-call-prog-index,MAKEINDEX,$(1),$(2),$(3),$(4)) \ |
| 631 |
$$(addprefix -s ,$$(call lu-getvalue-index,STYLE,$(1),$(2),$(3),$(4))) \ |
| 632 |
-o $$@ $$< |
| 633 |
_LU_DEF_IND_$(6)=$(2) |
| 634 |
clean:: |
| 635 |
$$(call lu-clean,$$(call lu-getvalue-index,TARGET,$(1),$(2),$(3),$(4)) \ |
| 636 |
$$(addsuffix .ilg,$$(basename \ |
| 637 |
$$(call lu-getvalue-index,SRC,$(1),$(2),$(3),$(4))))) |
| 638 |
endef #################################################### |
| 639 |
define lu-master-texflavor-index # MASTER FLAVOR INDEX ext(.dvi/.pdf) |
| 640 |
$$(eval $$(call lu-master-texflavor-index-vars,$(1),$(2),$(3),$(4))) |
| 641 |
$$(eval $$(call lu-master-texflavor-index-rules,$(1),$(2),$(3),$(4))) |
| 642 |
endef |
| 643 |
########################################################## |
| 644 |
|
| 645 |
########################################################## |
| 646 |
define lu-master-texflavor-vars # MASTER FLAVOR ext(.dvi/.pdf) |
| 647 |
$$(call lu-show-rules,Setting flavor vars for $(1)/$(2)) |
| 648 |
-include $(1)$(3).mk |
| 649 |
$$(eval $$(call lu-addtovar,DEPENDS,$(1),$(2), \ |
| 650 |
$$(call lu-getvalues,FIGURES,$(1),$(2)) \ |
| 651 |
$$(call lu-getvalues,BIBFILES,$(1),$(2)) \ |
| 652 |
$$(wildcard $$(call lu-getvalues,INPUTS,$(1),$(2))) \ |
| 653 |
$$(wildcard $$(call lu-getvalues,BIBSTYLES,$(1),$(2))) \ |
| 654 |
$$(call lu-getvalues,BBLFILES,$(1),$(2))\ |
| 655 |
)) |
| 656 |
|
| 657 |
$$(eval $$(call lu-addtovar-flavor,TARGETS,$(2),$(1)$(3))) |
| 658 |
|
| 659 |
$$(eval $$(call lu-addtovar,GPATH,$(1),$(2), \ |
| 660 |
$$(subst },,$$(subst {,,$$(subst }{, ,\ |
| 661 |
$$(call lu-getvalue,GRAPHICSPATH,$(1),$(2))))))) |
| 662 |
|
| 663 |
$$(if $$(sort $$(call lu-getvalues,SUBFIGS,$(1),$(2))), \ |
| 664 |
$$(eval include $$(addsuffix .mk,$$(sort \ |
| 665 |
$$(call lu-getvalues,SUBFIGS,$(1),$(2)))))) |
| 666 |
|
| 667 |
$$(eval $$(call lu-addtovar,WATCHFILES,$(1),$(2), \ |
| 668 |
$$(filter %.aux, $$(call lu-getvalues,OUTPUTS,$(1),$(2))))) |
| 669 |
|
| 670 |
$$(foreach type,$$(call lu-getvalues,INDEXES,$(1),$(2)), \ |
| 671 |
$$(foreach index,$$(call lu-getvalues,INDEXES_$$(type),$(1),$(2)), \ |
| 672 |
$$(eval $$(call lu-master-texflavor-index-vars,$(1),$(2),$$(type),$$(index),$(3))))) |
| 673 |
endef #################################################### |
| 674 |
define lu-master-texflavor-rules # MASTER FLAVOR ext(.dvi/.pdf) |
| 675 |
$$(call lu-show-rules,Defining flavor rules for $(1)/$(2)) |
| 676 |
$$(call lu-getvalues,BBLFILES,$(1),$(2)): \ |
| 677 |
$$(sort $$(call lu-getvalues,BIBFILES,$(1),$(2)) \ |
| 678 |
$$(wildcard $$(call lu-getvalues,BIBSTYLES,$(1),$(2)))) |
| 679 |
$(1)$(3): %$(3): \ |
| 680 |
$$(filter-out $$(call lu-getvalues,DEPENDS_EXCLUDE,$(1),$(2)), \ |
| 681 |
$$(call lu-getvalues,DEPENDS,$(1),$(2)) \ |
| 682 |
$$(call lu-getvalues,REQUIRED,$(1),$(2))) \ |
| 683 |
$$(if $$(wildcard $(1)$(3)_FAILED),LU_FORCE,) \ |
| 684 |
$$(if $$(wildcard $(1)$(3)_NEED_REBUILD),LU_FORCE,) \ |
| 685 |
$$(if $$(wildcard $(1)$(3)_NEED_REBUILD_IN_PROGRESS),LU_FORCE,) |
| 686 |
$$(if $$(filter-out $$(LU_REC_LEVEL),$$(call lu-getvalue,MAX_REC,$(1),$(2))),, \ |
| 687 |
$$(warning *********************************) \ |
| 688 |
$$(warning *********************************) \ |
| 689 |
$$(warning *********************************) \ |
| 690 |
$$(warning Stopping generation of $$@) \ |
| 691 |
$$(warning I got max recursion level $$(call lu-getvalue,MAX_REC,$(1),$(2))) \ |
| 692 |
$$(warning Set LU_$(1)_$(2)_MAX_REC, LU_MAX_REC_$(1) or LU_MAX_REC if you need it) \ |
| 693 |
$$(warning *********************************) \ |
| 694 |
$$(warning *********************************) \ |
| 695 |
$$(warning *********************************) \ |
| 696 |
$$(error Aborting generation of $$@)) |
| 697 |
$$(MAKE) LU_REC_MASTER="$(1)" LU_REC_FLAVOR="$(2)" LU_REC_TARGET="$$@"\ |
| 698 |
LU_WATCH_FILES_SAVE |
| 699 |
$$(COMMON_PREFIX)$$(call _lu-do-latex\ |
| 700 |
,$(1),$(2),$$(call lu-getvalue-master,MAIN,$(1)),$(3)) |
| 701 |
$$(MAKE) LU_REC_MASTER="$(1)" LU_REC_FLAVOR="$(2)" LU_REC_TARGET="$$@"\ |
| 702 |
LU_WATCH_FILES_RESTORE |
| 703 |
$$(MAKE) LU_REC_MASTER="$(1)" LU_REC_FLAVOR="$(2)" LU_REC_TARGET="$$@"\ |
| 704 |
$(1)$(3)_NEED_REBUILD |
| 705 |
ifneq ($(LU_REC_TARGET),) |
| 706 |
$(1)$(3)_NEED_REBUILD_IN_PROGRESS: |
| 707 |
$$(COMMON_HIDE)touch $(1)$(3)_NEED_REBUILD_IN_PROGRESS |
| 708 |
$$(addprefix LU_rebuild_,$$(call lu-getvalues,REBUILD_RULES,$(1),$(2))): \ |
| 709 |
$(1)$(3)_NEED_REBUILD_IN_PROGRESS |
| 710 |
.PHONY: $(1)$(3)_NEED_REBUILD |
| 711 |
$(1)$(3)_NEED_REBUILD: \ |
| 712 |
$(1)$(3)_NEED_REBUILD_IN_PROGRESS \ |
| 713 |
$$(addprefix LU_rebuild_,$$(call lu-getvalues,REBUILD_RULES,$(1),$(2))) |
| 714 |
$$(COMMON_HIDE)$(RM) $(1)$(3)_NEED_REBUILD_IN_PROGRESS |
| 715 |
$$(COMMON_HIDE)if [ -f "$(1)$(3)_NEED_REBUILD" ];then\ |
| 716 |
echo "********************************************" ;\ |
| 717 |
echo "*********** New build needed ***************" ;\ |
| 718 |
echo "********************************************" ;\ |
| 719 |
cat "$(1)$(3)_NEED_REBUILD" ; \ |
| 720 |
echo "********************************************" ;\ |
| 721 |
fi |
| 722 |
$$(MAKE) LU_REC_LEVEL=$$(shell expr $$(LU_REC_LEVEL) + 1) \ |
| 723 |
$$(LU_REC_TARGET) |
| 724 |
endif |
| 725 |
clean-build-fig:: |
| 726 |
$$(call lu-clean,$$(foreach fig, \ |
| 727 |
$$(basename $$(wildcard $$(filter %.fig, \ |
| 728 |
$$(call lu-getvalues,FIGURES,$(1),$(2))))), \ |
| 729 |
$$(addprefix $$(fig),$$(call lu-getvalues-flavor,CLEANFIGEXT,$(2))))) |
| 730 |
$$(call lu-clean,$$(foreach svg, \ |
| 731 |
$$(basename $$(wildcard $$(filter %.svg, \ |
| 732 |
$$(call lu-getvalues,FIGURES,$(1),$(2))))), \ |
| 733 |
$$(addprefix $$(svg),$$(call lu-getvalues-flavor,CLEANSVGEXT,$(2))))) |
| 734 |
clean:: clean-build-fig |
| 735 |
$$(call lu-clean,$$(call lu-getvalues,OUTPUTS,$(1),$(2)) \ |
| 736 |
$$(call lu-getvalues,BBLFILES,$(1),$(2)) \ |
| 737 |
$$(addsuffix .mk,$$(call lu-getvalues,SUBFIGS,$(1),$(2))) \ |
| 738 |
$$(patsubst %.bbl,%.blg,$$(call lu-getvalues,BBLFILES,$(1),$(2)))) |
| 739 |
$$(call lu-clean,$$(wildcard $(1).log)) |
| 740 |
distclean:: |
| 741 |
$$(call lu-clean,$$(wildcard $(1)$(3) $(1)$(3)_FAILED \ |
| 742 |
$(1)$(3)_NEED_REBUILD $(1)$(3)_NEED_REBUILD_IN_PROGRESS)) |
| 743 |
$$(foreach type,$$(call lu-getvalues,INDEXES,$(1),$(2)), \ |
| 744 |
$$(foreach index,$$(call lu-getvalues,INDEXES_$$(type),$(1),$(2)), \ |
| 745 |
$$(eval $$(call lu-master-texflavor-index-rules,$(1),$(2),$$(type),$$(index),$(3))))) |
| 746 |
endef #################################################### |
| 747 |
define lu-master-texflavor # MASTER FLAVOR ext(.dvi/.pdf) |
| 748 |
$$(eval $$(call lu-master-texflavor-vars,$(1),$(2),$(3))) |
| 749 |
$$(eval $$(call lu-master-texflavor-rules,$(1),$(2),$(3))) |
| 750 |
endef |
| 751 |
########################################################## |
| 752 |
|
| 753 |
########################################################## |
| 754 |
define lu-master-dviflavor-vars # MASTER FLAVOR ext(.ps) |
| 755 |
$$(call lu-show-rules,Setting flavor vars for \ |
| 756 |
$(1)/$(2)/$$(call lu-getvalue-flavor,DEPFLAVOR,$(2))) |
| 757 |
# $$(eval $$(call lu-addvar,VARPROG,$(1),$(2))) |
| 758 |
# $$(eval $$(call lu-addvar,$$(call lu-getvalue,VARPROG,$(1),$(2)),$(1),$(2))) |
| 759 |
$$(eval $$(call lu-addtovar-flavor,TARGETS,$(2),$(1)$(3))) |
| 760 |
endef #################################################### |
| 761 |
define lu-master-dviflavor-rules # MASTER FLAVOR ext(.ps) |
| 762 |
$$(call lu-show-rules,Defining flavor rules for \ |
| 763 |
$(1)/$(2)/$$(call lu-getvalue-flavor,DEPFLAVOR,$(2))) |
| 764 |
$(1)$(3): %$(3): %$$(call lu-getvalue-flavor,EXT,$$(call lu-getvalue-flavor,DEPFLAVOR,$(2))) |
| 765 |
$$(call lu-call-prog-flavor,$(1),$(2)) -o $$@ $$< |
| 766 |
distclean:: |
| 767 |
$$(call lu-clean,$$(wildcard $(1)$(3))) |
| 768 |
endef #################################################### |
| 769 |
define lu-master-dviflavor # MASTER FLAVOR ext(.ps) |
| 770 |
$$(eval $$(call lu-master-dviflavor-vars,$(1),$(2),$(3))) |
| 771 |
$$(eval $$(call lu-master-dviflavor-rules,$(1),$(2),$(3))) |
| 772 |
endef |
| 773 |
########################################################## |
| 774 |
|
| 775 |
########################################################## |
| 776 |
define lu-master-vars # MASTER |
| 777 |
$$(call lu-show-rules,Setting vars for $(1)) |
| 778 |
$$(eval $$(call lu-setvar-master,MAIN,$(1),$(1).tex)) |
| 779 |
$$(eval $$(call lu-addtovar-master,DEPENDS,$(1),\ |
| 780 |
$$(call lu-getvalue-master,MAIN,$(1)))) |
| 781 |
_LU_$(1)_DVI_FLAVORS=$$(filter $$(_LU_FLAVORS_DEFINED_DVI),\ |
| 782 |
$$(sort $$(call lu-getvalues-master,FLAVORS,$(1)))) |
| 783 |
_LU_$(1)_TEX_FLAVORS=$$(filter $$(_LU_FLAVORS_DEFINED_TEX),\ |
| 784 |
$$(sort $$(call lu-getvalues-master,FLAVORS,$(1)) \ |
| 785 |
$$(LU_REC_FLAVOR) \ |
| 786 |
$$(foreach dvi,$$(call lu-getvalues-master,FLAVORS,$(1)), \ |
| 787 |
$$(call lu-getvalue-flavor,DEPFLAVOR,$$(dvi))))) |
| 788 |
$$(foreach flav,$$(_LU_$(1)_TEX_FLAVORS), $$(eval $$(call \ |
| 789 |
lu-master-texflavor-vars,$(1),$$(flav),$$(call lu-getvalue-flavor,EXT,$$(flav))))) |
| 790 |
$$(foreach flav,$$(_LU_$(1)_DVI_FLAVORS), $$(eval $$(call \ |
| 791 |
lu-master-dviflavor-vars,$(1),$$(flav),$$(call lu-getvalue-flavor,EXT,$$(flav))))) |
| 792 |
endef #################################################### |
| 793 |
define lu-master-rules # MASTER |
| 794 |
$$(call lu-show-rules,Defining rules for $(1)) |
| 795 |
$$(foreach flav,$$(_LU_$(1)_TEX_FLAVORS), $$(eval $$(call \ |
| 796 |
lu-master-texflavor-rules,$(1),$$(flav),$$(call lu-getvalue-flavor,EXT,$$(flav))))) |
| 797 |
$$(foreach flav,$$(_LU_$(1)_DVI_FLAVORS), $$(eval $$(call \ |
| 798 |
lu-master-dviflavor-rules,$(1),$$(flav),$$(call lu-getvalue-flavor,EXT,$$(flav))))) |
| 799 |
endef #################################################### |
| 800 |
define lu-master # MASTER |
| 801 |
$$(eval $$(call lu-master-vars,$(1))) |
| 802 |
$$(eval $$(call lu-master-rules,$(1))) |
| 803 |
endef |
| 804 |
########################################################## |
| 805 |
|
| 806 |
#$(warning $(call LU_RULES,example)) |
| 807 |
$(eval $(call lu-addtovar-global,MASTERS,\ |
| 808 |
$$(shell grep -l '\\documentclass' *.tex 2>/dev/null | sed -e 's/\.tex$$$$//'))) |
| 809 |
ifneq ($(LU_REC_TARGET),) |
| 810 |
_LU_DEF_MASTERS = $(LU_REC_MASTER) |
| 811 |
_LU_DEF_FLAVORS = $(LU_REC_FLAVOR) $(FLAV_DEPFLAVOR_$(LU_REC_FLAVOR)) |
| 812 |
else |
| 813 |
_LU_DEF_MASTERS = $(call lu-getvalues-global,MASTERS) |
| 814 |
_LU_DEF_FLAVORS = $(sort $(foreach master,$(_LU_DEF_MASTERS),\ |
| 815 |
$(call lu-getvalues-master,FLAVORS,$(master)))) |
| 816 |
endif |
| 817 |
|
| 818 |
$(foreach flav, $(_LU_DEF_FLAVORS), $(eval $(call lu-define-flavor,$(flav)))) |
| 819 |
$(foreach master, $(_LU_DEF_MASTERS), $(eval $(call lu-master-vars,$(master)))) |
| 820 |
$(foreach flav, $(_LU_FLAVORS_DEFINED), $(eval $(call lu-flavor-rules,$(flav)))) |
| 821 |
$(foreach master, $(_LU_DEF_MASTERS), $(eval $(call lu-master-rules,$(master)))) |
| 822 |
|
| 823 |
##################################################################"" |
| 824 |
# Gestion des subfigs |
| 825 |
|
| 826 |
%.subfig.mk: %.subfig %.fig |
| 827 |
$(COMMON_PREFIX)$(call lu-call-prog,GENSUBFIG) \ |
| 828 |
-p '$$(COMMON_PREFIX)$(call lu-call-prog,FIGDEPTH) < $$< > $$@' \ |
| 829 |
-s $*.subfig $*.fig < $^ > $@ |
| 830 |
|
| 831 |
%.subfig.mk: %.subfig %.svg |
| 832 |
$(COMMON_PREFIX)$(call lu-call-prog,GENSUBSVG) \ |
| 833 |
-p '$$(COMMON_PREFIX)$(call lu-call-prog,SVGDEPTH) < $$< > $$@' \ |
| 834 |
-s $*.subfig $*.svg < $^ > $@ |
| 835 |
|
| 836 |
clean:: |
| 837 |
$(call lu-clean,$(FIGS2CREATE_LIST)) |
| 838 |
$(call lu-clean,$(FIGS2CREATE_LIST:%.fig=%.pstex)) |
| 839 |
$(call lu-clean,$(FIGS2CREATE_LIST:%.fig=%.pstex_t)) |
| 840 |
$(call lu-clean,$(FIGS2CREATE_LIST:%.fig=%.$(_LU_PDFTEX_EXT))) |
| 841 |
$(call lu-clean,$(FIGS2CREATE_LIST:%.fig=%.pdftex_t)) |
| 842 |
$(call lu-clean,$(FIGS2CREATE_LIST:%.svg=%.pstex)) |
| 843 |
$(call lu-clean,$(FIGS2CREATE_LIST:%.svg=%.pstex_t)) |
| 844 |
$(call lu-clean,$(FIGS2CREATE_LIST:%.svg=%.$(_LU_PDFTEX_EXT))) |
| 845 |
$(call lu-clean,$(FIGS2CREATE_LIST:%.svg=%.pdftex_t)) |
| 846 |
|
| 847 |
.PHONY: LU_FORCE clean distclean |
| 848 |
LU_FORCE: |
| 849 |
@echo "Previous compilation failed. Rerun needed" |
| 850 |
|
| 851 |
#$(warning $(MAKEFILE)) |
| 852 |
|
| 853 |
distclean:: clean |
| 854 |
|
| 855 |
%.eps: %.fig |
| 856 |
$(COMMON_PREFIX)$(call lu-call-prog,FIG2DEV) -L eps $< $@ |
| 857 |
|
| 858 |
%.pdf: %.fig |
| 859 |
$(COMMON_PREFIX)$(call lu-call-prog,FIG2DEV) -L pdf $< $@ |
| 860 |
|
| 861 |
%.pstex: %.fig |
| 862 |
$(COMMON_PREFIX)$(call lu-call-prog,FIG2DEV) -L pstex $< $@ |
| 863 |
|
| 864 |
%.pstex: %.svg |
| 865 |
$(COMMON_PREFIX)$(call lu-call-prog,SVG2DEV) -L pstex $< $@ |
| 866 |
|
| 867 |
|
| 868 |
.PRECIOUS: %.pstex |
| 869 |
%.pstex_t: %.fig %.pstex |
| 870 |
$(COMMON_PREFIX)$(call lu-call-prog,FIG2DEV) -L pstex_t -p $*.pstex $< $@ |
| 871 |
|
| 872 |
%.pstex_t: %.svg %.pstex |
| 873 |
$(COMMON_PREFIX)$(call lu-call-prog,SVG2DEV) -L pstex_t -p $*.pstex $< $@ |
| 874 |
|
| 875 |
|
| 876 |
%.$(_LU_PDFTEX_EXT): %.fig |
| 877 |
$(COMMON_PREFIX)$(call lu-call-prog,FIG2DEV) -L pdftex $< $@ |
| 878 |
|
| 879 |
%.$(_LU_PDFTEX_EXT): %.svg |
| 880 |
$(COMMON_PREFIX)$(call lu-call-prog,SVG2DEV) -L pdftex $< $@ |
| 881 |
|
| 882 |
.PRECIOUS: %.$(_LU_PDFTEX_EXT) |
| 883 |
%.pdftex_t: %.fig %.$(_LU_PDFTEX_EXT) |
| 884 |
$(COMMON_PREFIX)$(call lu-call-prog,FIG2DEV) -L pdftex_t -p $*.$(_LU_PDFTEX_EXT) $< $@ |
| 885 |
|
| 886 |
%.pdftex_t: %.svg %.$(_LU_PDFTEX_EXT) |
| 887 |
$(COMMON_PREFIX)$(call lu-call-prog,SVG2DEV) -L pdftex_t -p $*.$(_LU_PDFTEX_EXT) $< $@ |
| 888 |
|
| 889 |
%.pdf: %.eps |
| 890 |
$(COMMON_PREFIX)$(call lu-call-prog,EPSTOPDF) --filter < $< > $@ |
| 891 |
|
| 892 |
######################################################################### |
| 893 |
# Les flavors |
| 894 |
LU_REC_LEVEL ?= 1 |
| 895 |
ifneq ($(LU_REC_TARGET),) |
| 896 |
export LU_REC_FLAVOR |
| 897 |
export LU_REC_MASTER |
| 898 |
export LU_REC_TARGET |
| 899 |
export LU_REC_LEVEL |
| 900 |
LU_REC_LOGFILE=$(LU_REC_MASTER).log |
| 901 |
LU_REC_GENFILE=$(LU_REC_MASTER)$(call lu-getvalue-flavor,EXT,$(LU_REC_FLAVOR)) |
| 902 |
|
| 903 |
lu-rebuild-head=$(info *** Checking rebuild with rule '$(subst LU_rebuild_,,$@)') |
| 904 |
lu-rebuild-needed=echo $(1) >> "$(LU_REC_GENFILE)_NEED_REBUILD" ; |
| 905 |
|
| 906 |
.PHONY: $(addprefix LU_rebuild_,latex texdepends bibtex) |
| 907 |
LU_rebuild_latex: |
| 908 |
$(call lu-rebuild-head) |
| 909 |
$(COMMON_HIDE)if grep -sq 'Rerun to get'\ |
| 910 |
"$(LU_REC_LOGFILE)" ; then \ |
| 911 |
$(call lu-rebuild-needed\ |
| 912 |
,"$@: new run needed (LaTeX message 'Rerun to get...')") \ |
| 913 |
fi |
| 914 |
|
| 915 |
LU_rebuild_texdepends: |
| 916 |
$(call lu-rebuild-head) |
| 917 |
$(COMMON_HIDE)if grep -sq '^Package texdepends Warning: .* Check dependencies again.$$'\ |
| 918 |
"$(LU_REC_LOGFILE)" ; then \ |
| 919 |
$(call lu-rebuild-needed,"$@: new depends required") \ |
| 920 |
fi |
| 921 |
|
| 922 |
LU_rebuild_bibtopic: |
| 923 |
$(call lu-rebuild-head) |
| 924 |
$(COMMON_HIDE)sed -e '/^Package bibtopic Warning: Please (re)run BibTeX on the file(s):$$/,/^(bibtopic) *and after that rerun LaTeX./{s/^(bibtopic) *\([^ ]*\)$$/\1/p};d' \ |
| 925 |
"$(LU_REC_LOGFILE)" | while read file ; do \ |
| 926 |
touch $$file.aux ; \ |
| 927 |
$(call lu-rebuild-needed,"bibtopic: $$file.bbl outdated") \ |
| 928 |
done |
| 929 |
|
| 930 |
LU_rebuild_bibtopic_undefined_references: |
| 931 |
$(call lu-rebuild-head) |
| 932 |
$(COMMON_HIDE)if grep -sq 'There were undefined references'\ |
| 933 |
"$(MASTER_$(LU_REC_MASTER)).log" ; then \ |
| 934 |
$(call lu-rebuild-needed,"$@: new run needed") \ |
| 935 |
fi |
| 936 |
|
| 937 |
.PHONY: LU_WATCH_FILES_SAVE LU_WATCH_FILES_RESTORE |
| 938 |
LU_WATCH_FILES_SAVE: |
| 939 |
$(COMMON_HIDE)$(foreach file, $(sort \ |
| 940 |
$(call lu-getvalues,WATCHFILES,$(LU_REC_MASTER),$(LU_REC_FLAVOR))), \ |
| 941 |
$(call lu-save-file,$(file),$(file).orig);) |
| 942 |
|
| 943 |
LU_WATCH_FILES_RESTORE: |
| 944 |
$(COMMON_HIDE)$(foreach file, $(sort \ |
| 945 |
$(call lu-getvalues,WATCHFILES,$(LU_REC_MASTER),$(LU_REC_FLAVOR))), \ |
| 946 |
$(call lu-cmprestaure-file,"$(file)","$(file).orig",\ |
| 947 |
echo "New $(file) file" >> $(LU_REC_GENFILE)_NEED_REBUILD;\ |
| 948 |
);) |
| 949 |
|
| 950 |
endif |
| 951 |
|
| 952 |
%.bbl: %.aux |
| 953 |
$(COMMON_PREFIX)$(call lu-call-prog,BIBTEX) $* |
| 954 |
|
| 955 |
_LaTeX_Make_GROUPS=texmfscripts tex |
| 956 |
_LaTeX_Make_texmfscripts = LaTeX.mk figdepth.py gensubfig.py svg2dev.py svgdepth.py latexfilter.py |
| 957 |
_LaTeX_Make_texmfscripts_DIR = scripts/latex-make |
| 958 |
_LaTeX_Make_tex = figlatex.sty pdfswitch.sty texdepends.sty texgraphicx.sty |
| 959 |
_LaTeX_Make_tex_DIR = tex/latex/latex-make |
| 960 |
|
| 961 |
.PHONY: LaTeX-Make-local-install LaTeX-Make-local-uninstall |
| 962 |
|
| 963 |
LaTeX-Make-local-uninstall:: |
| 964 |
$(if $(TEXMF_INSTALL_ROOT_DIR),,\ |
| 965 |
$(error TEXMF_INSTALL_ROOT_DIR must be set when calling LaTeX-Make-local-uninstall)) |
| 966 |
$(foreach g,$(_LaTeX_Make_GROUPS),\ |
| 967 |
$(foreach f,$(_LaTeX_Make_$(g)), \ |
| 968 |
$(LU_RM) $(TEXMF_INSTALL_ROOT_DIR)/$(_LaTeX_Make_$(g)_DIR)/$f && \ |
| 969 |
) (rmdir $(TEXMF_INSTALL_ROOT_DIR)/$(_LaTeX_Make_$(g)_DIR) || true) && \ |
| 970 |
) $(LU_RM) LaTeX.mk |
| 971 |
|
| 972 |
LU_INSTALL_PKSEWHICH?=env -u TEXMFHOME kpsewhich |
| 973 |
LaTeX-Make-local-install:: |
| 974 |
$(if $(TEXMF_INSTALL_ROOT_DIR),,\ |
| 975 |
$(error TEXMF_INSTALL_ROOT_DIR must be set when calling LaTeX-Make-local-install)) |
| 976 |
$(if $(filter texmf,$(notdir $(TEXMF_INSTALL_ROOT_DIR))),,\ |
| 977 |
$(if $(FORCE),,\ |
| 978 |
$(warning TEXMF_INSTALL_ROOT_DIR does not end with 'texmf')\ |
| 979 |
$(error Use FORCE=1 if you really want to use this value of TEXMF_INSTALL_ROOT_DIR))) |
| 980 |
$(foreach g,$(_LaTeX_Make_GROUPS),\ |
| 981 |
mkdir -p $(TEXMF_INSTALL_ROOT_DIR)/$(_LaTeX_Make_$(g)_DIR) && \ |
| 982 |
$(foreach f,$(_LaTeX_Make_$(g)), \ |
| 983 |
$(LU_CP) -v $$($(LU_INSTALL_PKSEWHICH) -format $g $f) $(TEXMF_INSTALL_ROOT_DIR)/$(_LaTeX_Make_$(g)_DIR) && \ |
| 984 |
)) echo "Installation into $(TEXMF_INSTALL_ROOT_DIR) done." |
| 985 |
@echo "==> You must ensure your TEXMFHOME contains this path <==" |
| 986 |
|