summaryrefslogtreecommitdiffstats
path: root/Makefile.common
blob: e430b921f39b27c4a74378138114854aa29fc23b (plain)
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
#########################################################################
# Makefile.common
#
# This file, to be included from every document's local Makefile, provides
# the basic targets used by the Fedora Docs Project.  To see a list,
# type "make help".
#########################################################################

#########################################################################
# PDF generation is still fragile and probably won't work on your document.
# Yet.
#########################################################################

#########################################################################
# STYLE GUIDE (Or, How To Keep Tommy From Raising A Single Eyebrow At You)
# 1) Lines are 80 characters, max.
# 2) Tabs are 8 characters, exactly.
# 3) All targets must use the "::" form to allow multiple instances of
#    the target.
# 4) Keep a modular Makefile.  For example, do NOT group all the "clean:"
#    rules into one place.  Using the "::" form lets us keep all the 
#    targets and rules for one object (file, template, whatever) close
#    together.  This makes maintenance much, much easier.
#########################################################################
# One key to writing good rules (the commands run to build a target) is
# to write the shell commands so they could be cut'n pasted into a real
# shell window.  To do this, we have to find a common pidgen syntax that
# works for both make(1) and the Bourne-type shells.
#
# Compared to even the most basic shell, the make(1) parser is very 
# limited.  This is most visible when referencing shell variables or
# make(1) macros.  While a shell only needs delimiters to disambiguate
# $FOObar from ${FOO}bar, make(1) needs the delimiters for any macro
# name longer than one character.  Combining the two rules, we get:
#
# 1) In a shell script, use the form ${FOO} to reference *EVERY* variable
#    instead of using $(FOO); most shells interpret the parens as a 
#    directive to run the contents in a subshell.  All shells correctly
#    handle the ${} braces form.
# 2) In a make(1) rule, use the form ${FOO} instead of $(FOO) when
#    referencing macros.
# 3) Reserve the form $(FOO), with parens, for enclosing real shell
#    commands such as $(shell /bin/pwd)
#########################################################################

#########################################################################
# Note: all targets within this Makefile.common must be defined as 
# double-colon (::) targets so that additional steps can be added by
# providing additional rules, also marked with double-colons, in the
# document Makefile.
#########################################################################

#########################################################################
# N.B., if you want to use built-in variables such as "$@" in a template
# be sure to quote them as "$$@" since the template is evaluated once as
# it is expanded
#########################################################################

#########################################################################
# WARNING.  This feature is deprecated and will shortly disappear.
#########################################################################
# Allow client document to provide "Make.paths" file to locate our files
# This is a "silent include", so if it's missing there is no problem.
# This file, if present, must be in the DOCUMENT directory, not here in
# docs-common.  Even if this file is present, defining FTPDIR via the
# command line will take precedence.
sinclude Make.paths
#########################################################################

#########################################################################
# Strange though it may seem, some shells do not provide a ${PWD} 
# environment variable for us.
PWD	:=$(shell /bin/pwd)
#########################################################################

#########################################################################
# Supply default values for the boilerplate files _unless_ the user has
# provided their own values.
define find-common-dir
for d in $(PWD)/docs-common $(PWD)/../docs-common $(PWD)/../../docs-common \
	/usr/share/fedora/doc/docs-common ; do \
if [ -f $$d/Makefile.common ] ; then (cd "$$d" && /bin/pwd); break; fi; done
endef
FDPCOMMONDIR	 := $(shell $(find-common-dir))
# FDPDIR may no longer be required.
FDPDIR		 ?= ${FDPCOMMONDIR}/..
FDPBIN		 ?= ${FDPCOMMONDIR}/bin
XSLPDF		 ?= ${FDPCOMMONDIR}/xsl/main-pdf.xsl
XSLHTML		 ?= ${FDPCOMMONDIR}/xsl/main-html.xsl
XSLHTMLNOCHUNKS	 ?= ${FDPCOMMONDIR}/xsl/main-html-nochunks.xsl
HTMLCSS		 ?= ${FDPCOMMONDIR}/css/fedora-draft.css
DRAFT		 ?= yes
PRI_LANG	 ?= en
POTBASE		 ?= ${DOCBASE}
RPMINFO		 ?= rpm-info.xml
RPMPREP		 ?= yes
RPMPOST		 ?= yes
XMLTOTXTPOSTOPT	 ?= -p '-I iso-8859-15 -O UTF-8'
XMLLINTOPT	 ?= --xinclude --postvalid --noent
LEGALNOTICEBASE	 ?= legalnotice-opl
#########################################################################

#########################################################################
# Use macros to locate our commonly-used programs
XMLTO		?= xmlto
XSLTPROC	?= xsltproc
XSLTPROCOPTS	?= --path ${FDPCOMMONDIR}/common/entities:${FDPCOMMONDIR}/packaging
XMLFORMAT	?= xmlformat
XMLFOPTS	?= -f $(FDPCOMMONDIR)/bin/xmlformat-fdp.conf
XMLLINT		?= xmllint
XML2PO		?= xml2po
# NEVER CHANGE ${XML2POFLAGS} TO "-k", EVER. THAT WOULD BE STUPID.
XML2POFLAGS	?= -e
MSGMERGE	?= msgmerge
MSGFMT		?= msgfmt
LN		?= ln
MEINPROC	?= meinproc
#########################################################################

#########################################################################
FDP_ENTITIES	?= fdp-entities.ent
#########################################################################

#########################################################################
# Rules to produce .po files from .xml files.  Get the tools to do this
# from the gnome-doc-utils RPM.
.SUFFIXES: .po .pot .fo .ent .xml
%.po:	%.xml
	${XML2PO} ${XML2POFLAGS} $< >$@

%.ent:	%.xml
	${XSLTPROC} ${XSLTPROCOPTS} -o $@.tmp \
		--stringparam FDPCOMMONDIR "${FDPCOMMONDIR}/common" \
		${FDPCOMMONDIR}/common/entities/entities.xsl $< && \
		move-if-change $@.tmp $@
#########################################################################

#########################################################################
# Use our very own "docs-common/bin/fdpsh" as the command interpreter
# This automatically has ${FDPBIN} as first in the ${PATH}
SHELL	=${FDPBIN}/fdpsh
#########################################################################

#########################################################################
ifndef RPMFLAGS
RPMFLAGS?=--define "docbase $(DOCBASE)" 				\
	 --define "_topdir $(PWD)/rpm" 					\
	 --define "_srpmdir ${PWD}"					\
	 --define "_rpmdir ${PWD}"					\
	 --define "_sourcedir ${PWD}"					\
         --define "fdpdir /usr/share/fedora/doc"
endif

# Do not use specspo by default in case we want to use summary or desc
RPMI18N		?= --i18ndomains %{nil}
RPMFLAGS	:= ${RPMFLAGS} ${RPMI18N}

ifneq	"${RPMDEBUG}" ""
RPMDFLAG	= -vv
endif
#########################################################################

#########################################################################
# If ${OTHERS} does not exist, look for a po/LINGUAS file with a list
# of locales.  Using a po/LINGUAS file allows translators with access
# to only the po/ folders to add their locales to the list without
# seeking help from an XML editorial person.
# The sed script ensures that comments are excised properly.
OTHERS	?=$(shell test -f po/LINGUAS && /bin/sed 's/\#.*//' po/LINGUAS)
#########################################################################

#########################################################################
# Set a provisional ${LANG} value.  We'll dynamically change this as 
# needed.  The "${PRI_LANG}" value is used because that is the original 
# language the doc.
LANG	=${PRI_LANG}
LANGUAGES=${PRI_LANG} ${OTHERS}
#
#########################################################################

#########################################################################
define	DOCENT_template
DOC_ENTITIES_XML-${1}=${1}/${DOC_ENTITIES}.xml
DOC_ENTITIES_ENT-${1}=${1}/${DOC_ENTITIES}.ent
endef

ifneq	"${DOC_ENTITIES}" ""
$(foreach L,${LANGUAGES},$(eval $(call DOCENT_template,${L})))
endif
#########################################################################

#########################################################################
# Explode the template from the doc-specific Makefile to get the
# XML files the author knows about.
$(foreach L,${LANGUAGES},$(eval $(call XMLFILES_template,${L})))
# Make sure rpm-info is part of the document PO template
$(foreach L,${LANGUAGES},$(eval XMLFILES-${L}+=${L}/${RPMINFO}))
# Append per-document dependencies
$(foreach L, ${LANGUAGES}, $(eval XMLDEPFILES-${L}+=${DOC_ENTITIES_ENT-${L}}))
$(foreach L, ${LANGUAGES}, $(eval XMLDEPFILES-${L}+=${L}/fdp-info.xml))
$(foreach L, ${LANGUAGES}, $(eval XMLDEPFILES-${L}+=${L}/${FDP_ENTITIES}))
#
#########################################################################

#########################################################################
TFMT="%-31s -- %s\n"
TPOFMT="%-30s* -- %s\n"
#########################################################################

#########################################################################
# PUT NO TARGETS BEFORE THIS ONE, not even in your base Makefile
# In a properly-constructed Makefile, this will be the default target

TARGETS=all clean distclean fdp-info html html-nochunks pdf po showvars \
        tarball rpm rpm-common noarch srpm package-prep package-post	\
	src-tarball txt text targets help tag

# FIXME: add the .PHONY attribute where the actual target is defined

.PHONY:	${TARGETS}
.PHONY:	$(foreach LANG,${LANGUAGES},html-${LANG})
.PHONY:	$(foreach LANG,${LANGUAGES},html-nochunks-${LANG})
.PHONY:	$(foreach LANG,${LANGUAGES},pdf-${LANG})

all::	html html-nochunks tarball # pdf

help::
	@echo -e 'The following targets are available for use with the make(1)'
	@echo -e 'command. Targets with a * marker can be built for a specific'
	@echo -e 'locale only. To do this, append a locale suffix to the'
	@echo -e 'target name, as in "make html-ja".'
	@echo -e 'Valid locales are: ${OTHERS}'
	@printf ${TPOFMT} 'all'	'Builds html, html-nochunks, and tarball'
	@printf ${TFMT} 'help' 'Brief list of targets'
	@printf ${TFMT} 'help-verbose' 'Full list, try "make help-verbose|sort"'


help-verbose:: help

${TARGETS}::

#########################################################################
# Ensure all 'clean' targets are invoked before 'distclean' targets
distclean:: clean
#
#########################################################################

showvars::
	@echo "XMLFILES=\"${XMLFILES-${PRI_LANG}}\""
	@echo "XMLDEPFILES=\"${XMLDEPFILES-${PRI_LANG}}\""
	@echo "FDPCOMMONDIR=\"${FDPCOMMONDIR}\""

help::
	@printf ${TFMT} 'showvars' 'Displays convenient make(1) variables'

#########################################################################
# Obtain the document version and release info for building RPM's
SPECFILE := $(firstword $(wildcard *.spec))

ifneq "${SPECFILE}" ""
# the name of the package
ifeq "${NAME}" ""
NAME := $(shell rpm ${RPMFLAGS} ${DISTRPMFLAGS} -q --qf "%{NAME}\n"	\
	--specfile ${SPECFILE} | head -1)
endif
# the version of the package
ifeq "${VERSION}" ""
VERSION := $(shell rpm ${RPMFLAGS} ${DISTRPMFLAGS} -q --qf "%{VERSION}\n" \
	--specfile ${SPECFILE} | head -1)
endif
# the release of the package
ifeq "${RELEASE}" ""
RELEASE := $(shell rpm ${RPMFLAGS} ${DISTRPMFLAGS} -q --qf "%{RELEASE}\n" \
	--specfile ${SPECFILE} | head -1)
endif

# CVS-safe version/release -- a package name like 4Suite screws things
# up, so we have to remove the leaving digits from the name
TAG_NAME    := $(shell echo ${NAME}    | sed -e s/\\\./_/g -e s/^[0-9]\\\+//g)
TAG_VERSION := $(shell echo ${VERSION} | sed s/\\\./_/g)
TAG_RELEASE := $(shell echo ${RELEASE} | sed s/\\\./_/g)

# tag to export, defaulting to current tag in the spec file
TAG ?= ${TAG_NAME}-${TAG_VERSION}-${TAG_RELEASE}

# The rest of this rule is set outside the ifneq
.PHONY: tag
tag:: ${SPECFILE}
	@:

else		# ifneq "${SPECFILE}" ""

# Only set tag here if not done already (i.e. SPECFILE doesn't exist)
# Use the FDPSH function to get a current version.  Keep in mind this
# will prevent repetitive tagging without the user making use of
# TAG_OPTS.  I'd say that encourages people to Do The Right Thing by
# changing version numbers where necessary. (PWF)
VERSION     ?= $(shell version doc)
TAG_NAME    ?= $(shell echo ${DOCBASE} | sed -e s/\\\./_/g -e s/^[0-9]\\\+//g)
TAG_VERSION ?= $(shell version doc | sed s/\\\./_/g)
TAG         ?= ${TAG_NAME}-${TAG_VERSION}
endif

# the last revision date of the package, according to rpm-info
REVDATE     ?= $(shell date doc)

tag::
	cvs tag ${TAG_OPTS} -c ${TAG}
	@echo "Tagged with: ${TAG}"
	@echo

showvars::
	@echo "NAME=${NAME}"
	@echo "VERSION=${VERSION}"
	@echo "TAG_NAME=${TAG_NAME}"
	@echo "TAG_VERSION=${TAG_VERSION}"
ifdef TAG_RELEASE	# Only used if we have a specfile!
	@echo "RELEASE=$(RELEASE)"
	@echo "TAG_RELEASE=${TAG_RELEASE}"
endif
	@echo "TAG=${TAG}"
	@echo "### (Tag vars do not necessarily reflect CVS status)"
	@echo "REVDATE=${REVDATE}"

help::
	@printf ${TFMT} 'tag' 'Tag this directory with the packaging NVR'

#########################################################################

#########################################################################
# Rules to generate the "${LANG}/${DOC_ENTITIES}.ent" file, if used
define DOC_ENTITIES_template

${1}/${DOC_ENTITIES}.xml:: ${1}/${FDP_ENTITIES} po/${1}.po ${PRI_LANG}/${DOC_ENTITIES}.xml
	${XML2PO} ${XML2POFLAGS} -p po/${1}.po 				\
		${PRI_LANG}/${DOC_ENTITIES}.xml >$$@

clean::
	${RM} ${1}/${DOC_ENTITIES}.xml

${1}/${DOC_ENTITIES}.ent::  ${1}/${DOC_ENTITIES}.xml

help-verbose::
	@printf ${TFMT} '${1}/${DOC_ENTITIES}.ent' 'Per-doc entities for locale "${1}"'
	@printf ${TFMT} '${1}/${DOC_ENTITIES}.xml' 'Translated per-doc entities for locale "${1}"'
endef

ifneq	"${DOC_ENTITIES}" ""
${PRI_LANG}/${DOC_ENTITIES}.ent::  ${PRI_LANG}/${DOC_ENTITIES}.xml
help-verbose::
	@printf ${TFMT} '${PRI_LANG}/${DOC_ENTITIES}.ent' 'Per-doc entities for locale "${PRI_LANG}"'
$(foreach L, ${OTHERS},$(eval $(call DOC_ENTITIES_template,${L})))

showvars::
	@echo "DOC_ENTITIES=${DOC_ENTITIES}"
endif
#
#########################################################################


#########################################################################
po/${POTBASE}.pot:: ${DOC_ENTITIES_XML-${PRI_LANG}} 			\
		${DOC_ENTITIES_ENT-${PRI_LANG}}				\
		${PRI_LANG}/${FDP_ENTITIES} ${XMLFILES-${PRI_LANG}}
	[ -d po/CVS ] || (echo ADD po/ TO CVS >&2; exit 1)
	${XML2PO} ${XML2POFLAGS} -o $@ ${XMLFILES-${PRI_LANG}} ${DOC_ENTITIES_XML-${PRI_LANG}}
help-verbose::
	@printf ${TFMT} 'po/${POTBASE}.pot' 'Writes one POT file for all XML'

showvars::
	@echo "POTBASE=${POTBASE}"

.PHONY:	pot
pot::	po/${POTBASE}.pot
help::
	@printf ${TPOFMT} 'po' 'Writes one ${PRI_LANG} PO file for all XML'
	@printf ${TFMT} 'pot' 'Writes one POT file for all XML'
#########################################################################

#########################################################################
define	PO_template

.PRECIOUS: po/${1}.po

po/${1}.po:: po/${POTBASE}.pot $${DOC_ENTITITES_ENT-${1}}
	[ -d po/CVS ] || (echo ADD po/ TO CVS >&2; exit 1)
	if [ ! -f $$@ ]; then						\
		cp po/${POTBASE}.pot $$@;				\
	else								\
		${MSGMERGE} -U -q $$@ po/${POTBASE}.pot;		\
		touch $$@;						\
	fi

.PHONY:	po-${1}
po-${1}:: po/${1}.po
postat-${1}::
	@echo "${1}: $(shell $(MSGFMT) --stat po/${1}.po 2>&1 | \
		sed 's@[^0-9]\+@/@g')"

help-verbose::
	@printf ${TFMT} 'po/${1}.po' 'Creates or updates locale ${1} .PO file'

endef

$(foreach L,${OTHERS},$(eval $(call PO_template,${L})))

.PHONY:	po

po::	$(foreach L,${OTHERS},po-${L})
postat::  $(foreach L,${OTHERS},postat-${L})

clean::
	${RM} .xml2po.mo
########################################################################

#########################################################################
# Define a template to generate the locale-specific XML files given the
# original ${PRI_LANG} file and an updated po/${LANG}.po file.
# We have to be funky and cd(1) into the ${LANG} directory so that
# the "lang=foo" attribute that ${XML2PO} generates will be correct. 
# Hiss! Boo!
define	XML_template
$(patsubst ${PRI_LANG}/%,${1}/%,${2}):: ${2} po/${1}.po
	mkdir -p ${1}
	cd po && ${XML2PO} ${XML2POFLAGS} -p ${1}.po ../${2} >../$$@

endef

$(foreach L,${OTHERS},							\
	$(foreach F,${XMLFILES-${PRI_LANG}},				\
		$(eval $(call XML_template,${L},${F}))))

clean::
	cd po && ${RM} .xml2po.mo
	${RM} messages.mo

define	XMLTARGET_template
.PHONY:	xml-${1}

xml-${1}::	${XMLDEPFILES-${1}} ${XMLFILES-${1}}

distclean::
	${RM} -r ${1}

help-verbose::
	@printf ${TFMT} 'xml-${1}' 'Produces translated XML for locale ${1}'

endef

.PHONY:	xml-${PRI_LANG}
xml-${PRI_LANG}:: ${XMLFILES-${PRI_LANG}}

$(foreach L,${OTHERS},$(eval $(call XMLTARGET_template,${L})))

.PHONY:	xml xml-all
xml xml-all:: $(foreach L,${LANGUAGES},xml-${L})

help::
	@printf ${TPOFMT} 'xml' 'Creates all XML locale files, no validation'

distclean::
	$(foreach L,${OTHERS},${RM} -r ${L})
#########################################################################

###########
#
# Get or build OMF.
# 
# If the per-doc Makefile provides a ${OMFINFILES} list, we use those.
# If it does not:
# 1.  look for ${PRI_LANG}/*.omf.in and use those; or, failing that,
# 2.  if ${BUILDOMF} is defined, make one using XSLT and rpm-info data.
#
# The template OMF files are expected to use @VARNAME@ notation to
# allow replacement of their content dynamically at build time.  They
# should retain this notation during PO/POT conversion so that
# translators never have to worry about that content.  Substitution
# only occurs during the packaging process.
#

# FIXME: There may not be a need to have the ${PRI_LANG} prefixing
# each entry in ${OMFINFILES}.  Might be a good idea to take that out.

# if OMFINFILES is empty, try and get the file list.
# If it's still empty, and BUILDOMF is set, use that to populate the list.
# Otherwise it stays empty.  After all, we may not want them at all.

ifeq "${OMFINFILES}" ""
OMFINFILES=$(foreach F,$(wildcard ${PRI_LANG}/*.omf.in),$(shell basename ${F}))
ifeq "${OMFINFILES}" ""
ifdef BUILDOMF
OMFINFILES=${PKGNAME}.omf.in
${PRI_LANG}/${PKGNAME}.omf.in:: ${PRI_LANG}/${RPMINFO}
	${XSLTPROC} --stringparam lang ${PRI_LANG}		\
		--stringparam docbase ${PKGNAME}		\
		${FDPCOMMONDIR}/packaging/omf-in.xsl 	\
		$< > $@
endif
endif
endif

showvars::
	@echo "OMFINFILES=\"${OMFINFILES}\""

define OMFVAR_template
$(foreach F,${OMFINFILES},$(eval OMFINFILES-${1}+=${1}/${F}))
$(foreach F,${OMFINFILES},$(eval OMFFILES-${1}+=$(patsubst %.in,${1}/%,${F})))
showvars-debug::
	@echo "OMFFILES-${1}=\"${OMFFILES-${1}}\""
endef

$(foreach L,${LANGUAGES},$(eval $(call OMFVAR_template,${L})))

define OMFIN_template
.PHONY: omf-in-${1}
omf-in-${1}:: ${OMFINFILES-${1}}
# Treat .omf.in files just like XML... since they are!
$(foreach F,${OMFINFILES},$(eval $(call XML_template,${1},${PRI_LANG}/${F})))

clean::
	${RM} ${OMFINFILES-${1}}

endef

$(foreach L,${OTHERS},$(eval $(call OMFIN_template,${L})))

.PHONY: omf-in
omf-in:: $(foreach L,${LANGUAGES},${OMFINFILES-${L}})

help::
	@printf ${TPOFMT} 'omf-in' 'Make all OMF input files'


# To make the real OMF, just do a quick bit of sed processing.
# The spacing in the second command is purposeful to ensure no extra
# space appears in the sed command.
#
# Note the difference between @LANG@ and @LANGC@: the former is always
# replaced by the locale name, whereas the latter is replaced by the
# locale name *unless* the locale is en_US, in which case it is replaced
# by "C", the fallback.
%.omf:	%.omf.in
	sed -e 's!@RELEASE@!${VERSION}!g' $< > $@
	sed -i 's!@DATE@!${REVDATE}!g' $@
	sed -i 's!@LANG@!$(patsubst %/$(shell basename $<),%,$<)!g' $@
	sed -i 's!@LANGC@!$(if $(findstring en_US,$(patsubst 		\
		%/$(shell basename $<),%,$<)),C,$(patsubst 		\
		%/$(shell basename $<),%,$<))!g' $@


define OMF_template
.PHONY: omf-${1}
omf-${1}:: ${OMFFILES-${1}}

clean::
	${RM} ${OMFFILES-${1}}

endef

$(foreach L,${LANGUAGES},$(eval $(call OMF_template,${L})))

.PHONY: omf
omf:: $(foreach L,${LANGUAGES},${OMFFILES-${L}})
help::
	@printf ${TPOFMT} 'omf' 'Make all OMF files for all locales'
# End of OMF ###############################

#########################################################################
# For each LANG in LANGUAGES, generate a target and rule similar to:
# mydoc-en/index.html:: mydoc-en.xml ${XMLEXTRAFILES}-en
#  LANG=en.UTF-8 ${XMLTO} html -x $(XSLHTML) -o mydoc-en mydoc-en.xml
#  mkdir -p mydoc-en/stylesheet-images
#  cp ${FDPCOMMONDIR}/stylesheet-images/*.png mydoc-en/stylesheet-images/
#  cp ${HTMLCSS} mydoc-en/fedora.css
#  cp ${HTMLCSSEXTRA} mydoc-en/watermark.png
#  cp ${FDPCOMMONDIR}/images/watermark.png mydoc-en/
#  ${FDPCOMMONDIR}/bin/copy-figs -f '*.png' figs mydoc-en/
# but we do avoid copying EPS files since they are nonsense to the HTML world.
#
define	HTML_template
.PHONY:	html-${1}
html-$(1):: ${DOCBASE}-$(1)/index.html
${DOCBASE}-$(1)/index.html::  ${XMLFILES-${1}} ${XMLDEPFILES-${1}}
	LANG=$(1).UTF-8 ${XMLTO} html -x $(XSLHTML) ${XMLTOOPTS} \
		-o $(DOCBASE)-$(1) $(1)/$(DOCBASE).xml
	mkdir -p $(DOCBASE)-$(1)/stylesheet-images/
	cp ${FDPCOMMONDIR}/stylesheet-images/*.png \
		$(DOCBASE)-$(1)/stylesheet-images
	cp ${HTMLCSS} $(DOCBASE)-$(1)/fedora.css
ifneq	"${DRAFT}" "no"
	cp ${FDPCOMMONDIR}/images/watermark-$(1).png \
		$(DOCBASE)-$(1)/watermark.png
endif
	[ ! -d figs ] || copy-figs -v -f '*.png' \
		-l $(1) figs $(DOCBASE)-$(1)

distclean::
	${RM} -r ${DOCBASE}-${1}

help-verbose::
	@printf ${TFMT} '${1}/index.html' 'Renders XML into locale ${1}'
endef

$(foreach L,${LANGUAGES},$(eval $(call HTML_template,${L})))

.PHONY:	html

html::	$(foreach L,${LANGUAGES},html-${L})

help::
	@printf ${TPOFMT} 'html' 'Renders XML into chunked HTML'
#
#########################################################################

#########################################################################
# For each language in ${LANGUAGES}, generate a single HTML file
define	HTMLNOCHUNK_template
.PHONY:	html-nochunks-${1}

html-nochunks-$(1):: ${DOCBASE}-$(1).html

${DOCBASE}-$(1).html:: ${XMLFILES-${1}} ${XMLDEPFILES-${1}}
	LANG=${1}.UTF-8 ${XMLTO} html-nochunks -x $(XSLHTMLNOCHUNKS) \
		${XMLTOOPTS} $(1)/$(DOCBASE).xml
	mv $(DOCBASE).html $(DOCBASE)-$(1).html
	mkdir -p stylesheet-images/
	cp ${FDPCOMMONDIR}/stylesheet-images/*.png stylesheet-images/
	cp ${HTMLCSS} fedora.css
ifneq	"${DRAFT}" "no"
	cp ${FDPCOMMONDIR}/images/watermark-$(1).png watermark.png
endif

distclean::
	${RM} ${DOCBASE}-${1}.html
	${RM} -r stylesheet-images
	${RM} fedora.css
	${RM} watermark.png

help-verbose::
	@printf ${TFMT} '${DOCBASE}-${1}.html' 'Renders XML into locale ${1} HTML'
endef

$(foreach L,${LANGUAGES},$(eval $(call HTMLNOCHUNK_template,${L})))

.PHONY:	html-nochunks

html-nochunks::	$(foreach L,${LANGUAGES},html-nochunks-$(L))

help::
	@printf ${TPOFMT} 'html-nochunks' 'Renders XML into locale ${1} HTML'
#
#########################################################################

#########################################################################
# For each language in ${LANGUAGES}, build a tarball of the HTML and
# image files.  Any ".eps" files are ignored.
#
define	HTMLTAR_template
.PHONY: tarball-${1}
tarball-${1}:: ${DOCBASE}-${1}.tar.gz

${DOCBASE}-$(1).tar.gz:: ${DOCBASE}-$(1)/index.html
	tar -zc --exclude '*.eps' -f ${DOCBASE}-$(1).tar.gz ${DOCBASE}-$(1)

distclean::
	${RM} ${DOCBASE}-${1}.tar.gz

help-verbose::
	@printf ${TFMT} '${DOCBASE}-${1}.tar.gz' 'Tar archive of HTML and images'
endef

$(foreach L,${LANGUAGES},$(eval $(call HTMLTAR_template,${L})))

.PHONY:	tarball

tarball::	$(foreach LANG,${LANGUAGES},$(DOCBASE)-$(LANG).tar.gz)

help::
	@printf ${TPOFMT} 'tarball' 'Tar archive of HTML and images'
#
#########################################################################

#########################################################################
# For each language in ${LANGUAGES}, generate an Adobe Portable Document
# Format (PDF) file.
define	FO_template
.PHONY:	fo-${1}
fo-${1}:: ${1}/${DOCBASE}.fo
${1}/${DOCBASE}.fo:: ${XMLFILES-${1}} ${XMLDEPFILES-${1}}
	LANG=${1}.UTF-8 xsltproc --xinclude 			\
	     --stringparam FDPCOMMONDIR ${FDPCOMMONDIR}		\
	     --stringparam IMGROOT ${PWD}			\
	     --stringparam RENDEREDBY fop-0.20.5		\
	     ${XSLPDF} ${1}/${DOCBASE}.xml | ${XMLLINT} --format -o $$@ -
clean::
	${RM} ${1}/${DOCBASE}.fo
help-verbose::
	@printf ${TFMT} '${1}/${DOCBASE}.fo' 'XSL-FO file for locale ${1}'
endef

$(foreach L,${LANGUAGES},$(eval $(call FO_template,${L})))

.PHONY:	fo fo-all
fo fo-all::	$(foreach L,${LANGUAGES},fo-${L})
help::
	@printf ${TPOFMT} 'fo' 'Generate .FO files for all languages'

define	PDF_template
.PHONY:	pdf-${1}
pdf-$(1):: ${DOCBASE}-$(1).pdf

${DOCBASE}-${1}.pdf:: ${1}/${DOCBASE}.fo
	LANG=${1}.UTF-8 ${XMLTO} ${XMLTOOPTS} -o ${1} pdf $$<
	mv -f ${1}/${DOCBASE}.pdf $$@

distclean::
	${RM} ${DOCBASE}-${1}.pdf

help-verbose::
	@printf ${TFMT} '${DOCBASE}-${1}.pdf' 'Renders XML-FO into PDF file for locale ${1}'

endef

$(foreach L,${LANGUAGES},$(eval $(call PDF_template,${L})))

.PHONY:	pdf

pdf::	$(foreach LANG,${LANGUAGES},pdf-$(LANG))

help::
	@printf ${TPOFMT} 'pdf' 'Renders XML-FO into PDF file'


define  TXT_template
.PHONY: txt-${1} text-${1}

txt-$(1) text-$(1):: ${DOCBASE}-$(1).txt

${DOCBASE}-$(1).txt:: ${XMLFILES-${1}} ${XMLDEPFILES-${1}}
# Not pretty, but it's what we've got.
	test -f /usr/bin/w3m || ( echo 'Missing w3m package.' && exit 1 )
	${XMLLINT} ${XMLLINTOPT} $(1)/$(DOCBASE).xml > $(1)/$(DOCBASE).lint.xml
	${XSLTPROC} $(FDPCOMMONDIR)/packaging/strip-for-txt.xsl \
		$(1)/$(DOCBASE).lint.xml > $(1)/$(DOCBASE).stripped.xml
	rm $(1)/$(DOCBASE).lint.xml
	LANG=$(1).UTF-8 ${XMLTO} ${XMLTOOPTS} ${XMLTOTXTPOSTOPT} txt \
		$(1)/$(DOCBASE).stripped.xml
	mv $(DOCBASE).stripped.txt $(DOCBASE)-$(1).txt
	rm $(1)/$(DOCBASE).stripped.xml

clean::
	${RM} ${1}/${DOCBASE}.stripped.xml

distclean::
	${RM} ${DOCBASE}-${1}.txt

help-verbose::
	@printf ${TFMT} '${DOCBASE}-${1}.txt' 'Renders XML into ASCII text for locale ${1}'

endef

$(foreach L,${LANGUAGES},$(eval $(call TXT_template,${L})))

.PHONY: txt text

txt text::	$(foreach LANG,${LANGUAGES},txt-$(LANG))

help::
	@printf ${TPOFMT} 'txt' 'Renders XML into ASCII text'
	@printf ${TPOFMT} 'text' 'Renders XML into ASCII text'
#
#########################################################################

#########################################################################
clean:: 
	${RM} *.tmp
#########################################################################

#########################################################################
#
showvars::
	@echo "DOCBASE=\"$(DOCBASE)\""
	@echo "PRI_LANG=\"$(PRI_LANG)\""
	@echo "OTHERS=\"$(OTHERS)\""
#
#########################################################################

#########################################################################
# Show differences between two file revisions. To use this tool:
# 	$ make OLD=old.xml NEW=new.xml diff
# The ${DIFFS} macro can select a different output format:
# 	$ make DIFFS=-C OLD=old.xml NEW=new.xml diff

OLD	=define-me-old.xml
NEW	=define-me-new.xml
DIFFS	=-u

diff::
	xmldiff ${DIFFS} ${OLD} ${NEW}

help::
	@printf ${TFMT} 'diff' 'Compares XML files'

#
#########################################################################

#########################################################################
# The "${LANG}/rpm-info.xml" file contains the revision information for
# the original DocBook source.  We use it to generate the "fdp-info.xml"
# file discussed in the next section.
#
define rpm-info_template
${1}/${RPMINFO}::  po/${1}.po ${PRI_LANG}/${RPMINFO}
	mkdir -p ${1}
	${XML2PO} ${XML2POFLAGS} -p po/${1}.po				\
		${PRI_LANG}/${RPMINFO} >$$@

clean::
	${RM} ${1}/${RPMINFO}

help-verbose::
	@printf ${TFMT} '${1}/${RPMINFO}' 'Make translated document revision info'
endef

# ${PRI_LANG}/${RPMINFO} must exist, only generate for OTHERS
$(foreach L,${OTHERS},$(eval $(call rpm-info_template,${L})))
#
#########################################################################


#########################################################################
# The "${LANG}/fdp-info.xml" file contains the <articleinfo> or 
# <bookinfo> stanza.  It is automatically generated from data in the
# "rpm-info.xml" file whenever that file changes.
#
define fdp-info_template
$(1)/fdp-info.xml::	${1}/$(RPMINFO)
	mkdir -p ${1}
	LANG=$(1).UTF-8 ${XSLTPROC} ${XSLTPROCOPTS} --stringparam lang $(1) \
		--stringparam fdpcommondir $(FDPCOMMONDIR)		\
		--stringparam doctype $(shell				\
			doctype ${PRI_LANG}/$(DOCBASE).xml)		\
		--stringparam legalbase ${LEGALNOTICEBASE}		\
		${FDPCOMMONDIR}/packaging/bookinfo.xsl 		\
		${1}/$(RPMINFO) 				| 	\
	$(XMLFORMAT) $(XMLFOPTS) >$$@

clean::
	${RM} ${1}/fdp-info.xml

help-verbose::
	@printf ${TFMT} '${1}/fdp-info.xml' 'Locale ${1} packaging information'

endef

$(foreach L,${LANGUAGES},$(eval $(call fdp-info_template,${L})))

.PHONY:	fdp-info

fdp-info::  $(foreach LANG,${LANGUAGES},$(LANG)/fdp-info.xml)

help::
	@printf ${TPOFMT} 'fdp-info' 'Outputs XML document info'

define khelp_template
.PHONY: khelp-$(1)

khelp-$(1):: ${XMLFILES-$(1)} ${XMLDEPFILES-$(1)}
	LANG=$(1).UTF-8 ${XMLLINT} --noent --xinclude $(1)/$(DOCBASE).xml \
		2>/dev/null >$(1)/$(DOCBASE).xml-parsed
	mkdir -p kde-$(1)
	${MEINPROC} --output kde-$(1)/index.docbook			\
		--cache kde-$(1)/index.cache.bz2			\
		$(1)/$(DOCBASE).xml-parsed
	${RM} -f $(1)/$(DOCBASE).xml-parsed

clean::
	${RM} -rf kde-$(1)

endef

$(foreach L,${LANGUAGES},$(eval $(call khelp_template,${L})))

.PHONY: khelp

khelp:: $(foreach LANG,${LANGUAGES},khelp-$(LANG))

help::
	@printf ${TPOFMT} 'khelp' 'Build all locale-specific khelpcenter files'
#
#########################################################################

#########################################################################
# Stuff after here is for RPM packaging
#########################################################################

#########################################################################
# Make a new changelog entry for an existing rpm-info.xml file.

# We cannot guarantee a correct relative location in <xsl:output>, so
# this target needs to be dropped.
#clog:: ${PRI_LANG}/$(RPMINFO)
#	insert-changelog $(RPMINFO).tmp && 	\
#		move-if-change $(RPMINFO).tmp ${PRI_LANG}/$(RPMINFO)
#
#help::
#	@printf ${TFMT} 'clog' 'Adds changelog entry to rpm-info.xml file'

#
#########################################################################
# Make a new colophon entry for an existing rpm-info.xml file.

# We cannot guarantee a correct relative location in <xsl:output>, so
# this target needs to be dropped.
# colophon:: ${PRI_LANG}/${RPMINFO}
#	insert-colophon ${RPMINFO}.tmp && 	\
#		move-if-change ${RPMINFO}.tmp ${PRI_LANG}/${RPMINFO}
#
#help::
#	@printf ${TFMT} 'colophon' 'Adds colophon entry to rpm-info.xml file'

#########################################################################
.PHONY:	distclean-${1} ${DOCBASE}-${1}-distclean

define	DISTCLEAN_template
distclean-${1} ${DOCBASE}-$(1)-distclean::
	${RM} *-$(1).omf
	${RM} *-$(1).desktop

endef

$(foreach L,${LANGUAGES},$(eval $(call DISTCLEAN_template,${L})))

distclean:: $(foreach L,${LANGUAGES},${DOCBASE}-${L}-distclean)
help::
	@printf ${TPOFMT} 'distclean' 'Removes product files and temporary files'
	@printf ${TFMT} 'clean' 'Removes temporary files'
#########################################################################

#########################################################################

clean::
	${RM} $(DOCBASE)-$(VERSION)*.src.tar.gz
	${RM} -r $(DOCBASE)-$(VERSION)/
	${RM} fedora-doc-$(DOCBASE)*.{omf,desktop,spec}
	${RM} *~

distclean::
	${RM} -r rpm
	${RM} fedora-doc-$(DOCBASE)*.rpm
	${RM} fedora-doc-$(DOCBASE)*.omf
	${RM} fedora-doc-$(DOCBASE)*.desktop
	${RM} fedora-doc-$(DOCBASE)*.spec
	${RM} $(DOCBASE)*.src.tar.gz


#
#########################################################################
# Build project-wide entities.  
#
define	FDP_ENTITIES_template
${1}/$${FDP_ENTITIES}::
	mkdir -p ${1}
	( cd ${FDPCOMMONDIR}/common/entities ; $$(MAKE) entities-${1}.ent ) 
	cp -u ${FDPCOMMONDIR}/common/entities/entities-${1}.ent $$@

clean::
	${RM} ${1}/$${FDP_ENTITIES}

help-verbose::
	@printf ${TFMT} '${1}/$${FDP_ENTITIES}' 'Link locale ${1} to FDP entities'
endef

$(foreach L,${LANGUAGES},$(eval $(call FDP_ENTITIES_template,${L})))
#########################################################################

#########################################################################
# 'LOCALE_template' issues rules and targets to symbolicly link the local
# file 'locale-entities.xml' to the per-locale entity files located in 
# the "docs-common/common/entities/" directory.
#
define	LOCALE_template
.PHONY:	set-locale-${1}

set-locale-${1}:: ${XMLDEPFILES-${1}}

clean::
	${RM} ${XMLDEPFILES-${1}}

help-verbose::
	@printf ${TFMT} 'set-locale-${1}' 'Link to locale ${1} FDP entities'
endef

$(foreach L,${PRI_LANG} ${OTHERS},$(eval $(call LOCALE_template,${L})))

#
#########################################################################

#########################################################################
# 'VALIDATE_template' emits rules and targets to validate the XML for the
# specified ${LANG}
define	VALIDATE_template

.PHONY:	validate-xml-${1}

validate-xml-${1}:: ${XMLFILES-${1}} ${XMLDEPFILES-${1}}
	${XMLLINT} --noout --xinclude --postvalid ${1}/${DOCBASE}.xml

endef

$(foreach L,${PRI_LANG} ${OTHERS},$(eval $(call VALIDATE_template,${L})))

.PHONY: validate-xml

validate-xml: $(foreach L,${PRI_LANG} ${OTHERS},validate-xml-${L})

help::
	@printf ${TPOFMT} 'validate-xml' 'Validate all XML'
#
#########################################################################


#########################################################################
# I'm going to bury this target deep at the bottom of the Makefile so 
# that maybe you won't see it ;-)  This is a *VERY DANGEROUS* target
# what will destroy *ALL* of your work, that of all the translators,
# and probably cause dental cavities as well.  You *DO NOT* want to
# use this target, ever.  The purpose of this target is to erase the
# oh-so-carefully hand-crafted .POT and .PO translation files in addition
# to all of the other generated product files.  THIS IS THE ONLY TARGET
# THAT WILL ERASE A .PO FILE!  Unless you are working on the I18N part
# of the FDP toolchain itself, you MUST NOT EVER use this target!  It
# voids all warranties!  It will never show up on a "make help" list!
mrproper: distclean
	${RM} po/*.*
# OK, you tried it anyway didn't you?  To recover you must:
# 1) NOT DO A CVS COMMIT; and
# 2) Immediately do a "cvs update po" to repair the damage; and
# 3) Send $25.00USD to the charity of your choice; or
# 4) Just pretend you didn't use this target in the first place.
#########################################################################

#########################################################################
# End of Makefile.common
#########################################################################
# Local variables:
# mode: makefile
# End: