OSDN Git Service

Improve support for out-of-tree catalogue generation.
[mingw/mingw-dist.git] / Makefile.comm.in
1 # @configure_input@
2 #
3 # $Id$
4 #
5 # Written by Keith Marshall <keithmarshall@users.sourceforge.net>
6 # Copyright (C) 2010, 2011, 2013, MinGW.org Project
7 #
8 #
9 # Makefile template for generating mingw-get distribution manifests.
10 #
11 #   Project: @PACKAGE_TARNAME@
12 #   Version: @PACKAGE_VERSION@
13 #
14 #
15 # This is free software.  Permission is granted to copy, modify and
16 # redistribute this software, under the provisions of the GNU General
17 # Public License, Version 3, (or, at your option, any later version),
18 # as published by the Free Software Foundation; see the file COPYING
19 # for licensing details.
20 #
21 # Note, in particular, that this software is provided "as is", in the
22 # hope that it may prove useful, but WITHOUT WARRANTY OF ANY KIND; not
23 # even an implied WARRANTY OF MERCHANTABILITY, nor of FITNESS FOR ANY
24 # PARTICULAR PURPOSE.  Under no circumstances will the author, or the
25 # MinGW Project, accept liability for any damages, however caused,
26 # arising from the use of this software.
27 #
28 VPATH = ${srcdir}:${top_srcdir}:${top_builddir}
29
30 # Define hooks for invoking system tools.
31 #
32 LN_S = @LN_S@
33
34 all: all-distfiles
35
36 # Capture repository infrastructure changes.  The following rules ensure
37 # that configure, config.status, and all working makefiles will be updated,
38 # when any of their respective sources are modified.
39 #
40 configure: configure.ac makeopts.m4
41         cd ${top_srcdir}; autoconf
42
43 config.status: configure
44         cd ${top_builddir}; ./config.status --recheck
45
46 Makefile: config.status Makefile.in Makefile.stub.in Makefile.comm.in
47         cd ${top_builddir}; ./config.status
48
49 # To accommodate a top-level make on just a single subdirectory, we list
50 # each of the managed subdirectories as an independent goal, invoking the
51 # "all" action for the target subdirectory.
52 #
53 @mingw_ac_subdirs@: all
54
55 # We use an automatically generated Makefile.sub to manage the list
56 # of distributable files, ensuring that we automatically capture all
57 # XML files in the source directory, and converting them to serialised
58 # LZMA compressed format for upload to the repository server.
59 #
60 Makefile.sub: ${srcdir}/*.xml
61         echo "auto-distfiles = \\" > $@
62         for file in $^; do echo "$$file.lzma \\" | sed 's,.*/,  ,' >> $@; done
63         echo '  $$(EXTRA_DISTFILES)' >> $@
64
65 sinclude Makefile.sub
66 all-distfiles: unpublished issue.sed $(DISTFILES) $(auto-distfiles)
67 @SET_MAKE@
68
69 # Distributed manifests are serialised by incorporating a date-stamped
70 # issue number, of the form YYYYMMDDNN; we track issue numbers using the
71 # issue.log file, (which we keep in CVS to ensure that all maintainers
72 # can share a common issue number registry).
73 #
74 issue_number = YYYYMMDDNN
75 issue_key = awk '$$3 == "$*.xml" { print $$1 }' issue.new
76 issue_log = ${srcdir}/issue.log
77
78 update_issue_number = \
79   test -n "$$issue" || issue=0; \
80   test $$issue -lt $${mark="`date -u +%Y%m%d`00"} && \
81     issue=$$mark || issue=`expr $$issue + 1`
82 generate_catalogue = -f ${top_builddir}/issue.sed -e $(store_issue_number)
83 store_issue_number = "s/@$(issue_number)@/$(issue)/"
84
85 # We use SHA1 hashes to determine when source files have been changed
86 # from the last published version, as recorded in `issue.log'; the hash
87 # is computed by openssl, after filtering the source through awk; (this
88 # ensures that the computed hash is not influenced by any unintentional
89 # pollution due to accidental insertion of CRLF line endings).
90 #
91 sha1hash = awk '{ sub( "\r$$", "" ); print }' $$catalogue | $(sha1sum)
92 sha1sum = openssl sha1 | awk '{print $$NF}'
93
94 # Formatting within issue.log is controlled by PAD and TAB settings.
95 #
96 TAB = [  ]
97 PAD = "  "
98
99 # The following generic rule processes an XML source template, inserting
100 # the appropriate issue number, and compressing to yield the required LZMA
101 # distribution manifest.  The generated issue number which gets applied is
102 # appropriately serialised relative to the original record for the  source
103 # XML file being processed, as noted in the local copy of issue.log, which
104 # is then updated to record the new issue number; to avoid any regression
105 # of issue numbers, all maintainers are advised to update issue.log from
106 # CVS immediately prior manifest generation, and to commit back as soon
107 # as possible thereafter; any ensuing conflict must be resolved before
108 # any updated manifest is uploaded to the repository server.
109 #
110 %.xml.lzma: %.xml
111         @echo
112         >> $(issue_log)
113         rm -f issue.new issue.tmp
114         test -f ${top_builddir}/issue.sed || $(MAKE) issue.sed
115         sed '/^$(TAB)*$$/d;/^$(TAB)*#/d' $(issue_log) > issue.new
116         @catalogue="$<" issue=`awk '$$3 == "$*.xml" { print $$2 }' issue.new`; \
117           if test x$${hash="`$(sha1hash)`"} != x"`$(issue_key)`"; then \
118             $(update_issue_number); \
119             $(RMAKE) refname=$*.xml issue=$$issue hash=$$hash issue.tmp; \
120             fi; \
121           $(RMAKE) catalogue=$@ source=$< issue=$$issue generate-catalogue
122         @if test -f issue.tmp; then \
123           $(RMAKE) refname=$@ select-for-publication; \
124           $(RMAKE) update-issue-log; \
125           fi
126         rm -f issue.new issue.tmp
127
128 .PHONY: FORCE
129 # An internal target, to specify a dependency which must always be updated.
130 FORCE:
131
132 # Create a local directory in which to collect files which we have generated,
133 # but we have not yet published; (we make this a prerequisite of all sources,
134 # to ensure that it is created when the source directory is scanned to create
135 # Makefile.sub, so that will always exist when any individual source file is
136 # processed, even on explicit file-by-file request).
137 #
138 ${srcdir}/*.xml: unpublished
139 unpublished:
140         test -d $@ || mkdir $@
141
142 # Package lists are dynamically updated, to record the latest issues of each
143 # referenced package catalogue; the "sed" script used to accomplish this must
144 # be generated, and driven from, within the top build directory.  Similarly,
145 # the procedure for publishing updated catalogues to the file release system
146 # must be directed to the top build directory, to process the entire tree.
147 #
148 published update-references issue.sed: FORCE
149         cd ${top_builddir}; $(MAKE) $@
150
151 # Requests to update references will be redirected back to each sub-directory
152 # in turn, to be processed by the following recursive make rule.
153 #
154 update-local-references: unpublished issue.sed
155         rm -rf tmp; mkdir tmp; rm -f issue.tmp
156         sed '/^$(TAB)*$$/d;/^$(TAB)*#/d' $(issue_log) > issue.new
157         @for catalogue in `grep -l 'catalogue=' ${srcdir}/*.xml`; \
158           do refname=`echo $$catalogue | sed 's,^${srcdir}/,,'` \
159              issue=`awk '$$3 == "'$$refname'" { print $$2 }' issue.new`; \
160              $(RMAKE) refname=$$refname issue=$$issue generate-reference; \
161              lzma -dc $$refname.lzma | cmp -s - tmp/$$refname || \
162                { $(update_issue_number); \
163                  $(RMAKE) dir=${top_builddir} issue.chk; \
164                  $(RMAKE) refname=$$refname issue=$$issue \
165                    hash=`$(sha1hash)` issue.tmp; \
166                  $(RMAKE) catalogue=$$refname.lzma source=$$catalogue \
167                    issue=$$issue generate-catalogue; \
168                  $(RMAKE) refname=$$refname.lzma select-for-publication; \
169                }; \
170           done
171         @test -f issue.tmp && $(RMAKE) update-issue-log || true
172         rm -f ${top_builddir}/issue.sed issue.new issue.tmp
173         rm -rf tmp
174
175 # The preceding rules for compiling catalogues for publication, and resolving
176 # "package-list" references, use several recursive make hooks to perform common
177 # sub-tasks.  GNU make tends to be very verbose about entering and leaving the
178 # directories in which these sub-tasks are performed, even when there is no
179 # change of directory involved; to make it quieter, we prefer this form of
180 # recursive invocation for local sub-tasks.
181 #
182 RMAKE = $(MAKE)@NO_PRINT_DIRECTORY@
183
184 # The following sub-task rule creates a tentative "publication-ready" version
185 # of each catalogue.
186 #
187 generate-catalogue: FORCE
188         sed $(generate_catalogue) $(source) \
189           | lzma -c > $(catalogue)
190
191 # The following sub-task rule creates a reference copy of each catalogue, for
192 # comparison with the tentative "publication-ready" version, when checking for
193 # changes introduced by resolution of "package-list" references.
194 #
195 generate-reference: FORCE
196         sed $(generate_catalogue) ${srcdir}/$(refname) \
197           > tmp/$(refname)
198
199 # When any generated catalogue has been found to differ from its previously
200 # published version, (if any), the following rule adds it to the schedule of
201 # catalogues which should be republished, (or published for the first time).
202 #
203 select-for-publication: FORCE
204         cd unpublished && $(LN_S) -f ../$(refname) .
205
206 # The remaining macros and rules define the sub-tasks for management of the
207 # temporary files used to control the iterative resolution of "package-list"
208 # references, and to capture modifications to be recorded in the issue log...
209 #
210 extract_log_file_header = '/^$(TAB)*$$/q;/^$(TAB)*[^\#]/q;p'
211 extract_log_file_footer = 's/^$(TAB)*$$/break/;1,/^$(TAB)*[^\#]/d;/^$(TAB)*\#/p'
212
213 issue.chk: FORCE
214         test -f issue.tmp && mv -f issue.tmp issue.new || true
215         test -f ${dir}/$@ && echo check > ${dir}/$@ || true
216
217 issue.new: FORCE
218 issue.tmp: issue.new
219         awk '$$3 != "$(refname)"' $^ > $@
220         echo $(PAD)$(hash) $(issue) $(refname) >> $@
221
222 # ...with this final rule completing the recording of the current state of
223 # publication, in the permanent issue log files.
224 #
225 update-issue-log: FORCE
226         sed -n $(extract_log_file_header) $(issue_log) > issue.new
227         LC_COLLATE=POSIX sort -k3 issue.tmp >> issue.new;
228         sed -n $(extract_log_file_footer) $(issue_log) >> issue.new;
229         rm -f $(issue_log) && mv issue.new $(issue_log)
230
231 # The following goals may be specified, when building as a sub-project
232 # of mingw-get-setup; make each a no-op here.
233 #
234 NO_OP_GOALS = build.tag dist clean distclean maintainer-clean
235 .PHONY: $(NO_OP_GOALS)
236 $(NO_OP_GOALS):
237
238 # $RCSfile$: end of file