unicodeio: Fix wrong result on FreeBSD.
[gnulib.git] / pygnulib / GLEmiter.py
blob107f88cf21615803383db105c10529a9a3cdc14b
1 #!/usr/bin/python
2 # encoding: UTF-8
4 #===============================================================================
5 # Define global imports
6 #===============================================================================
7 import os
8 import re
9 import sys
10 import codecs
11 import shutil
12 import subprocess as sp
13 from . import constants
14 from .GLInfo import GLInfo
15 from .GLError import GLError
16 from .GLConfig import GLConfig
17 from .GLModuleSystem import GLModule
18 from .GLModuleSystem import GLModuleTable
19 from .GLMakefileTable import GLMakefileTable
20 from .GLFileSystem import GLFileAssistant
21 from pprint import pprint
24 #===============================================================================
25 # Define module information
26 #===============================================================================
27 __author__ = constants.__author__
28 __license__ = constants.__license__
29 __copyright__ = constants.__copyright__
32 #===============================================================================
33 # Define global constants
34 #===============================================================================
35 PYTHON3 = constants.PYTHON3
36 NoneType = type(None)
37 APP = constants.APP
38 DIRS = constants.DIRS
39 ENCS = constants.ENCS
40 UTILS = constants.UTILS
41 MODES = constants.MODES
42 TESTS = constants.TESTS
43 compiler = constants.compiler
44 joinpath = constants.joinpath
45 cleaner = constants.cleaner
46 string = constants.string
47 isabs = os.path.isabs
48 isdir = os.path.isdir
49 isfile = os.path.isfile
50 normpath = os.path.normpath
51 relpath = os.path.relpath
54 #===============================================================================
55 # Define GLEmiter class
56 #===============================================================================
57 class GLEmiter(object):
58 '''This class is used to emit the contents of necessary files.'''
60 def __init__(self, config):
61 '''GLEmiter.__init__(config) -> GLEmiter
63 Create GLEmiter instance.'''
64 self.info = GLInfo()
65 if type(config) is not GLConfig:
66 raise(TypeError('config must be a GLConfig, not %s' %
67 type(config).__name__))
68 self.config = config
70 def __repr__(self):
71 '''x.__repr__() <==> repr(x)'''
72 result = '<pygnulib.GLEmiter %s>' % hex(id(self))
73 return(result)
75 def copyright_notice(self):
76 '''GLEmiter.copyright_notice() -> string
78 Emit a header for a generated file.'''
79 emit = string()
80 emit += "# %s" % self.info.copyright()
81 emit += """
83 # This file is free software; you can redistribute it and/or modify
84 # it under the terms of the GNU General Public License as published by
85 # the Free Software Foundation; either version 3 of the License, or
86 # (at your option) any later version.
88 # This file is distributed in the hope that it will be useful,
89 # but WITHOUT ANY WARRANTY; without even the implied warranty of
90 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
91 # GNU General Public License for more details.
93 # You should have received a copy of the GNU General Public License
94 # along with this file. If not, see <https://www.gnu.org/licenses/>.
96 # As a special exception to the GNU General Public License,
97 # this file may be distributed as part of a program that
98 # contains a configuration script generated by Autoconf, under
99 # the same distribution terms as the rest of that program.
101 # Generated by gnulib-tool.\n"""
102 if type(emit) is bytes:
103 emit = emit.decode(ENCS['default'])
104 return(constants.nlconvert(emit))
106 def autoconfSnippet(self, module, fileassistant, toplevel,
107 disable_libtool, disable_gettext, replace_auxdir, indentation):
108 '''GLEmiter.autoconfSnippet(module, toplevel,
109 disable_libtool, disable_gettext, replace_auxdir,
110 indentation) -> string
112 Emit the autoconf snippet of a module.
113 GLConfig: include_guard_prefix.
115 module is a GLModule instance, which is processed.
116 fileassistant is a GLFileAssistant instance, which is used to get temporary
117 directories and sed transformer.
118 toplevel is a bool variable, False means a subordinate use of pygnulib.
119 disable_libtool is a bool variable; it tells whether to disable libtool
120 handling even if it has been specified through the GLConfig class.
121 disable_gettext is a bool variable; it tells whether to disable
122 AM_GNU_GETTEXT invocations.
123 replace_auxdir is a bool variable; it tells whether to replace
124 'build-aux' directory in AC_CONFIG_FILES.
125 indentation is a string which contain spaces to prepend on each line.'''
126 emit = string()
127 if type(module) is not GLModule:
128 raise(TypeError('module must be a GLModule, not %s' %
129 type(module).__name__))
130 if type(fileassistant) is not GLFileAssistant:
131 raise(TypeError('fileassistant must be a GLFileAssistant, not %s' %
132 type(fileassistant).__name__))
133 if type(toplevel) is not bool:
134 raise(TypeError('toplevel must be a bool, not %s' %
135 type(toplevel).__name__))
136 if type(disable_libtool) is not bool:
137 raise(TypeError('disable_libtool must be a bool, not %s' %
138 type(disable_libtool).__name__))
139 if type(disable_gettext) is not bool:
140 raise(TypeError('disable_gettext must be a bool, not %s' %
141 type(disable_gettext).__name__))
142 if type(indentation) is bytes or type(indentation) is string:
143 if type(indentation) is bytes:
144 indentation = indentation.decode(ENCS['default'])
145 else: # if indentation has not bytes or string type
146 raise(TypeError('indentation must be a string, not %s' %
147 type(indentation).__name__))
148 if not indentation.isspace():
149 raise(ValueError('indentation must contain only whitespaces'))
150 auxdir = self.config['auxdir']
151 libtool = self.config['libtool']
152 include_guard_prefix = self.config['include_guard_prefix']
153 if str(module) in ['gnumakefile', 'maintainer-makefile']:
154 # These modules are meant to be used only in the top-level directory.
155 flag = toplevel
156 else: # if not str(module) in ['gnumakefile', 'maintainer-makefile']
157 flag = True
158 if flag:
159 snippet = module.getAutoconfSnippet()
160 snippet = snippet.replace('${gl_include_guard_prefix}',
161 include_guard_prefix)
162 lines = [line for line in snippet.split('\n') if line.strip()]
163 snippet = '%s\n' % '\n'.join(lines)
164 transformer = fileassistant.transformers.get('aux', '')
165 pattern = compiler('(^.*?$)', re.S | re.M)
166 snippet = pattern.sub('%s\\1' % indentation, snippet)
167 if transformer:
168 args = ['sed', '-e', transformer]
169 path = fileassistant.tmpfilename('snippet')
170 with codecs.open(path, 'wb', 'UTF-8') as file:
171 file.write(snippet)
172 stdin = codecs.open(path, 'rb', 'UTF-8')
173 snippet = sp.check_output(args, stdin=stdin, shell=False)
174 snippet = snippet.decode("UTF-8")
175 os.remove(path)
176 if disable_libtool:
177 snippet = snippet.replace('$gl_cond_libtool', 'false')
178 snippet = snippet.replace('gl_libdeps', 'gltests_libdeps')
179 snippet = snippet.replace('gl_ltlibdeps', 'gltests_ltlibdeps')
180 if disable_gettext:
181 snippet = snippet.replace('AM_GNU_GETTEXT([external])', 'dnl you must \
182 add AM_GNU_GETTEXT([external]) or similar to configure.ac.')
183 else:
184 # Don't indent AM_GNU_GETTEXT_VERSION line, as that confuses
185 # autopoint through at least GNU gettext version 0.18.2.
186 snippet = compiler('^ *AM_GNU_GETTEXT_VERSION').sub('AM_GNU_GETTEXT_VERSION', snippet)
187 emit += snippet
188 if str(module) == 'alloca' and libtool and not disable_libtool:
189 emit += 'changequote(,)dnl\n'
190 emit += "LTALLOCA=`echo \"$ALLOCA\" | sed -e 's/\\.[^.]* /.lo \
191 /g;s/\\.[^.]*$/.lo/'`\n"
192 emit += 'changequote([, ])dnl\n'
193 emit += 'AC_SUBST([LTALLOCA])'
194 if replace_auxdir:
195 regex = 'AC_CONFIG_FILES\\(\\[(.*?)\\:build-aux/(.*?)\\]\\)'
196 repl = 'AC_CONFIG_FILES([\\1:%s/\\2])' % auxdir
197 pattern = compiler(regex, re.S | re.M)
198 emit = pattern.sub(repl, emit)
199 lines = [line for line in emit.split('\n') if line.strip()]
200 emit = '%s\n' % '\n'.join(lines)
201 emit = constants.nlconvert(emit)
202 if type(emit) is bytes:
203 emit = emit.decode(ENCS['default'])
204 return(emit)
206 def autoconfSnippets(self, modules, moduletable, fileassistant,
207 verifier, toplevel, disable_libtool, disable_gettext, replace_auxdir):
208 '''GLEmiter.autoconfSnippets(modules, fileassistant,
209 verifier, toplevel, disable_libtool, disable_gettext,
210 replace_auxdir) -> string
212 Collect and emit the autoconf snippets of a set of modules.
213 GLConfig: conddeps.
215 basemodules argument represents list of modules; every module in this list
216 must be a GLModule instance; this list of modules is used to sort all
217 modules after they were processed.
218 modules argument represents list of modules; every module in this list must
219 be a GLModule instance.
220 moduletable is a GLModuleTable instance, which contains necessary
221 information about dependencies of the modules.
222 fileassistant is a GLFileAssistant instance, which is used to get temporary
223 directories and sed transformers.
224 verifier is an integer, which can be 0, 1 or 2.
225 if verifier == 0, then process every module;
226 if verifier == 1, then process only non-tests modules;
227 if verifier == 2, then process only tests modules.
228 toplevel is a bool variable, False means a subordinate use of pygnulib.
229 disable_libtool is a bool variable; it tells whether to disable libtool
230 handling even if it has been specified through the GLConfig class.
231 disable_gettext is a bool variable; it tells whether to disable
232 AM_GNU_GETTEXT invocations.
233 replace_auxdir is a bool variable; it tells whether to replace
234 'build-aux' directory in AC_CONFIG_FILES.'''
235 emit = string()
236 for module in modules:
237 if type(module) is not GLModule:
238 raise(TypeError('each module must be a GLModule instance'))
239 if type(moduletable) is not GLModuleTable:
240 raise(TypeError('moduletable must be a GLFileAssistant, not %s' %
241 type(moduletable).__name__))
242 if type(fileassistant) is not GLFileAssistant:
243 raise(TypeError('fileassistant must be a GLFileAssistant, not %s' %
244 type(fileassistant).__name__))
245 if type(verifier) is not int:
246 raise(TypeError('verifier must be an int, not %s' %
247 type(verifier).__name__))
248 if not (0 <= verifier <= 2):
249 raise(ValueError('verifier must be 0, 1 or 2, not %d' % verifier))
250 if type(toplevel) is not bool:
251 raise(TypeError('toplevel must be a bool, not %s' %
252 type(toplevel).__name__))
253 if type(disable_libtool) is not bool:
254 raise(TypeError('disable_libtool must be a bool, not %s' %
255 type(disable_libtool).__name__))
256 if type(disable_gettext) is not bool:
257 raise(TypeError('disable_gettext must be a bool, not %s' %
258 type(disable_gettext).__name__))
259 if type(replace_auxdir) is not bool:
260 raise(TypeError('replace_auxdir must be a bool, not %s' %
261 type(replace_auxdir).__name__))
262 auxdir = self.config['auxdir']
263 conddeps = self.config['conddeps']
264 macro_prefix = self.config['macro_prefix']
265 if not conddeps:
266 # Ignore the conditions, and enable all modules unconditionally.
267 for module in modules:
268 if verifier == 0:
269 solution = True
270 elif verifier == 1:
271 solution = module.isNonTests()
272 elif verifier == 2:
273 solution = module.isTests()
274 if solution:
275 emit += self.autoconfSnippet(module, fileassistant, toplevel,
276 disable_libtool, disable_gettext, replace_auxdir, ' ')
277 else: # if conddeps
278 # Emit the autoconf code for the unconditional modules.
279 for module in modules:
280 if verifier == 0:
281 solution = True
282 elif verifier == 1:
283 solution = module.isNonTests()
284 elif verifier == 2:
285 solution = module.isTests()
286 if solution:
287 if not moduletable.isConditional(module):
288 emit += self.autoconfSnippet(module, fileassistant, toplevel,
289 disable_libtool, disable_gettext, replace_auxdir, ' ')
290 # Initialize the shell variables indicating that the modules are enabled.
291 for module in modules:
292 if verifier == 0:
293 solution = True
294 elif verifier == 1:
295 solution = module.isNonTests()
296 elif verifier == 2:
297 solution = module.isTests()
298 if solution:
299 if moduletable.isConditional(module):
300 shellvar = module.getShellVar()
301 emit += ' %s=false\n' % module.getShellVar()
302 # Emit the autoconf code for the conditional modules, each in a separate
303 # function. This makes it possible to support cycles among conditional
304 # modules.
305 for module in modules:
306 if verifier == 0:
307 solution = True
308 elif verifier == 1:
309 solution = module.isNonTests()
310 elif verifier == 2:
311 solution = module.isTests()
312 if solution:
313 if moduletable.isConditional(module):
314 shellfunc = module.getShellFunc()
315 shellvar = module.getShellVar()
316 emit += ' %s ()\n' % shellfunc
317 emit += ' {\n'
318 emit += ' if ! $%s; then\n' % shellvar
319 emit += self.autoconfSnippet(module, fileassistant, toplevel,
320 disable_libtool, disable_gettext, replace_auxdir, ' ')
321 emit += ' %s=true\n' % shellvar
322 dependencies = module.getDependencies()
323 depmodules = [pair[0] for pair in dependencies]
324 # Intersect dependencies with the modules list.
325 depmodules = [
326 dep for dep in depmodules if dep in modules]
327 for depmodule in depmodules:
328 if moduletable.isConditional(depmodule):
329 shellfunc = depmodule.getShellFunc()
330 condition = moduletable.getCondition(
331 module, depmodule)
332 if condition != None:
333 emit += ' if %s; then\n' % condition
334 emit += ' %s\n' % shellfunc
335 emit += ' fi\n'
336 else: # if condition == None
337 emit += ' %s\n' % shellfunc
338 # if not moduletable.isConditional(depmodule)
339 else:
340 # The autoconf code for $dep has already been emitted above and
341 # therefore is already executed when this code is run.
342 pass
343 # Define the Automake conditionals.
344 emit += ' m4_pattern_allow([^%s_GNULIB_ENABLED_])\n' % macro_prefix
345 for module in modules:
346 if verifier == 0:
347 solution = True
348 elif verifier == 1:
349 solution = module.isNonTests()
350 elif verifier == 2:
351 solution = module.isTests()
352 if solution:
353 condname = module.getConditionalName()
354 shellvar = module.getShellVar()
355 emit += ' AM_CONDITIONAL([%s], [$%s])\n' % (
356 condname, shellvar)
357 lines = [line for line in emit.split('\n') if line.strip()]
358 emit = '%s\n' % '\n'.join(lines)
359 emit = constants.nlconvert(emit)
360 if type(emit) is bytes:
361 emit = emit.decode(ENCS['default'])
362 return(emit)
364 def po_Makevars(self):
365 '''GLEmiter.po_Makevars() -> string
367 Emit the contents of po/ makefile parameterization.
368 GLConfig: pobase, podomain.'''
369 emit = string()
370 pobase = self.config['pobase']
371 podomain = self.config['podomain']
372 top_subdir = string()
373 source = '%s/' % os.path.normpath(pobase)
374 if os.path.sep in source:
375 for directory in source.split(os.path.sep):
376 if directory != '':
377 top_subdir += '../'
378 top_subdir = os.path.normpath(top_subdir)
379 emit += "## DO NOT EDIT! GENERATED AUTOMATICALLY!\n"
380 emit += "%s\n" % self.copyright_notice()
381 emit += "# Usually the message domain is the same as the package name.\n"
382 emit += "# But here it has a '-gnulib' suffix.\n"
383 emit += "DOMAIN = %s-gnulib\n\n" % podomain
384 emit += "# These two variables depend on the location of this directory.\n"
385 emit += "subdir = %s\n" % pobase
386 emit += "top_subdir = %s\n" % top_subdir
387 emit += """
388 # These options get passed to xgettext.
389 XGETTEXT_OPTIONS = \\
390 --keyword=_ --flag=_:1:pass-c-format \\
391 --keyword=N_ --flag=N_:1:pass-c-format \\
392 --keyword='proper_name:1,"This is a proper name. See the gettext manual, \
393 section Names."' \\
394 --keyword='proper_name_utf8:1,"This is a proper name. See the gettext \
395 manual, section Names."' \\
396 --flag=error:3:c-format --flag=error_at_line:5:c-format
398 # This is the copyright holder that gets inserted into the header of the
399 # $(DOMAIN).pot file. gnulib is copyrighted by the FSF.
400 COPYRIGHT_HOLDER = Free Software Foundation, Inc.
402 # This is the email address or URL to which the translators shall report
403 # bugs in the untranslated strings:
404 # - Strings which are not entire sentences, see the maintainer guidelines
405 # in the GNU gettext documentation, section 'Preparing Strings'.
406 # - Strings which use unclear terms or require additional context to be
407 # understood.
408 # - Strings which make invalid assumptions about notation of date, time or
409 # money.
410 # - Pluralisation problems.
411 # - Incorrect English spelling.
412 # - Incorrect formatting.
413 # It can be your email address, or a mailing list address where translators
414 # can write to without being subscribed, or the URL of a web page through
415 # which the translators can contact you.
416 MSGID_BUGS_ADDRESS = bug-gnulib@gnu.org
418 # This is the list of locale categories, beyond LC_MESSAGES, for which the
419 # message catalogs shall be used. It is usually empty.
420 EXTRA_LOCALE_CATEGORIES =
422 # This tells whether the $(DOMAIN).pot file contains messages with an 'msgctxt'
423 # context. Possible values are "yes" and "no". Set this to yes if the
424 # package uses functions taking also a message context, like pgettext(), or
425 # if in $(XGETTEXT_OPTIONS) you define keywords with a context argument.
426 USE_MSGCTXT = no\n"""
427 if type(emit) is bytes:
428 emit = emit.decode(ENCS['default'])
429 return(constants.nlconvert(emit))
431 def po_POTFILES_in(self, files):
432 '''GLEmiter.po_POTFILES_in(files) -> string
434 Emit the file list to be passed to xgettext.
435 GLConfig: sourcebase.'''
436 emit = string()
437 sourcebase = self.config['sourcebase']
438 sourcebase = '%s%s' % (self.sourcebase, os.path.sep)
439 if type(sourcebase) is bytes:
440 sourcebase = sourcebase.decode(ENCS['default'])
441 files = [substart('lib/', sourcebase, file) for file in files]
442 files = [file for file in files if file.startswith(sourcebase)]
443 emit += "## DO NOT EDIT! GENERATED AUTOMATICALLY!\n"
444 emit += "%s\n" % self.copyright_notice()
445 emit += "# List of files which contain translatable strings.\n"
446 emit += '\n'.join(files)
447 emit += '\n'
448 if type(emit) is bytes:
449 emit = emit.decode(ENCS['default'])
450 return(constants.nlconvert(emit))
452 def initmacro_start(self, macro_prefix_arg):
453 '''GLEmiter.initmacro_start(macro_prefix_arg) -> string
455 Emit the first few statements of the gl_INIT macro.'''
456 emit = string()
457 if type(macro_prefix_arg) is bytes or type(macro_prefix_arg) is string:
458 if type(macro_prefix_arg) is bytes:
459 macro_prefix_arg = macro_prefix_arg.decode(ENCS['default'])
460 else: # if macro_prefix_arg has not bytes or string type
461 raise(TypeError('macro_prefix_arg must be a string, not %s' %
462 type(macro_prefix_arg).__name__))
463 # Overriding AC_LIBOBJ and AC_REPLACE_FUNCS has the effect of storing
464 # platform-dependent object files in ${macro_prefix_arg}_LIBOBJS instead
465 # of LIBOBJS. The purpose is to allow several gnulib instantiations under
466 # a single configure.ac file. (AC_CONFIG_LIBOBJ_DIR does not allow this
467 # flexibility).
468 # Furthermore it avoids an automake error like this when a Makefile.am
469 # that uses pieces of gnulib also uses $(LIBOBJ):
470 # automatically discovered file `error.c' should not be explicitly
471 # mentioned.
472 emit += " m4_pushdef([AC_LIBOBJ],"
473 emit += " m4_defn([%V1%_LIBOBJ]))\n"
474 emit += " m4_pushdef([AC_REPLACE_FUNCS],"
475 emit += " m4_defn([%V1%_REPLACE_FUNCS]))\n"
476 # Overriding AC_LIBSOURCES has the same purpose of avoiding the automake
477 # error when a Makefile.am that uses pieces of gnulib also uses $(LIBOBJ):
478 # automatically discovered file `error.c' should not be explicitly
479 # mentioned
480 # We let automake know about the files to be distributed through the
481 # EXTRA_lib_SOURCES variable.
482 emit += " m4_pushdef([AC_LIBSOURCES],"
483 emit += " m4_defn([%V1%_LIBSOURCES]))\n"
484 # Create data variables for checking the presence of files that are
485 # mentioned as AC_LIBSOURCES arguments. These are m4 variables, not shell
486 # variables, because we want the check to happen when the configure file is
487 # created, not when it is run. ${macro_prefix_arg}_LIBSOURCES_LIST is the
488 # list of files to check for. ${macro_prefix_arg}_LIBSOURCES_DIR is the
489 # subdirectory in which to expect them.
490 emit += " m4_pushdef([%V1%_LIBSOURCES_LIST], [])\n"
491 emit += " m4_pushdef([%V1%_LIBSOURCES_DIR], [])\n"
492 emit += " gl_COMMON\n"
493 emit = emit.replace('%V1%', macro_prefix_arg)
494 if type(emit) is bytes:
495 emit = emit.decode(ENCS['default'])
496 return(constants.nlconvert(emit))
498 def initmacro_end(self, macro_prefix_arg):
499 '''GLEmiter.initmacro_end(macro_prefix_arg) -> string
501 Emit the last few statements of the gl_INIT macro.'''
502 emit = string()
503 if type(macro_prefix_arg) is bytes or type(macro_prefix_arg) is string:
504 if type(macro_prefix_arg) is bytes:
505 macro_prefix_arg = macro_prefix_arg.decode(ENCS['default'])
506 else: # if macro_prefix_arg has not bytes or string type
507 raise(TypeError('macro_prefix_arg must be a string, not %s' %
508 type(macro_prefix_arg).__name__))
509 # Check the presence of files that are mentioned as AC_LIBSOURCES
510 # arguments. The check is performed only when autoconf is run from the
511 # directory where the configure.ac resides; if it is run from a different
512 # directory, the check is skipped.
513 emit += """\
514 m4_ifval(%V1%_LIBSOURCES_LIST, [
515 m4_syscmd([test ! -d ]m4_defn([%V1%_LIBSOURCES_DIR])[ ||
516 for gl_file in ]%V1%_LIBSOURCES_LIST[ ; do
517 if test ! -r ]m4_defn([%V1%_LIBSOURCES_DIR])[/$gl_file ; then
518 echo "missing file ]m4_defn([%V1%_LIBSOURCES_DIR])[/$gl_file" >&2
519 exit 1
521 done])dnl
522 m4_if(m4_sysval, [0], [],
523 [AC_FATAL([expected source file, required through AC_LIBSOURCES, not \
524 found])])
526 m4_popdef([%V1%_LIBSOURCES_DIR])
527 m4_popdef([%V1%_LIBSOURCES_LIST])
528 m4_popdef([AC_LIBSOURCES])
529 m4_popdef([AC_REPLACE_FUNCS])
530 m4_popdef([AC_LIBOBJ])
531 AC_CONFIG_COMMANDS_PRE([
532 %V1%_libobjs=
533 %V1%_ltlibobjs=
534 if test -n "$%V1%_LIBOBJS"; then
535 # Remove the extension.
536 sed_drop_objext='s/\.o$//;s/\.obj$//'
537 for i in `for i in $%V1%_LIBOBJS; do echo "$i"; done | sed -e \
538 "$sed_drop_objext" | sort | uniq`; do
539 %V1%_libobjs="$%V1%_libobjs $i.$ac_objext"
540 %V1%_ltlibobjs="$%V1%_ltlibobjs $i.lo"
541 done
543 AC_SUBST([%V1%_LIBOBJS], [$%V1%_libobjs])
544 AC_SUBST([%V1%_LTLIBOBJS], [$%V1%_ltlibobjs])
545 ])\n"""
546 emit = emit.replace('%V1%', macro_prefix_arg)
547 if type(emit) is bytes:
548 emit = emit.decode(ENCS['default'])
549 return(constants.nlconvert(emit))
551 def initmacro_done(self, macro_prefix_arg, sourcebase_arg):
552 '''GLEmiter.initmacro_done(macro_prefix_arg, sourcebase_arg) -> string
554 Emit a few statements after the gl_INIT macro.
555 GLConfig: sourcebase.'''
556 emit = string()
557 if type(macro_prefix_arg) is bytes or type(macro_prefix_arg) is string:
558 if type(macro_prefix_arg) is bytes:
559 macro_prefix_arg = macro_prefix_arg.decode(ENCS['default'])
560 else: # if macro_prefix_arg has not bytes or string type
561 raise(TypeError('macro_prefix_arg must be a string, not %s' %
562 type(macro_prefix_arg).__name__))
563 if type(sourcebase_arg) is bytes or type(sourcebase_arg) is string:
564 if type(sourcebase_arg) is bytes:
565 sourcebase_arg = sourcebase_arg.decode(ENCS['default'])
566 else: # if sourcebase_arg has not bytes or string type
567 raise(TypeError('sourcebase_arg must be a string, not %s' %
568 type(sourcebase_arg).__name__))
569 emit += """\
571 # Like AC_LIBOBJ, except that the module name goes
572 # into %V1%_LIBOBJS instead of into LIBOBJS.
573 AC_DEFUN([%V1%_LIBOBJ], [
574 AS_LITERAL_IF([$1], [%V1%_LIBSOURCES([$1.c])])dnl
575 %V1%_LIBOBJS="$%V1%_LIBOBJS $1.$ac_objext"
578 # Like AC_REPLACE_FUNCS, except that the module name goes
579 # into %V1%_LIBOBJS instead of into LIBOBJS.
580 AC_DEFUN([%V1%_REPLACE_FUNCS], [
581 m4_foreach_w([gl_NAME], [$1], [AC_LIBSOURCES(gl_NAME[.c])])dnl
582 AC_CHECK_FUNCS([$1], , [%V1%_LIBOBJ($ac_func)])
585 # Like AC_LIBSOURCES, except the directory where the source file is
586 # expected is derived from the gnulib-tool parameterization,
587 # and alloca is special cased (for the alloca-opt module).
588 # We could also entirely rely on EXTRA_lib..._SOURCES.
589 AC_DEFUN([%V1%_LIBSOURCES], [
590 m4_foreach([_gl_NAME], [$1], [
591 m4_if(_gl_NAME, [alloca.c], [], [
592 m4_define([%V1%_LIBSOURCES_DIR], [%V2%])
593 m4_append([%V1%_LIBSOURCES_LIST], _gl_NAME, [ ])
596 ])\n"""
597 emit = emit.replace('%V1%', macro_prefix_arg)
598 emit = emit.replace('%V2%', sourcebase_arg)
599 if type(emit) is bytes:
600 emit = emit.decode(ENCS['default'])
601 return(constants.nlconvert(emit))
603 def lib_Makefile_am(self, destfile, modules,
604 moduletable, makefiletable, actioncmd, for_test):
605 '''GLEmiter.lib_Makefile_am(destfile, modules, moduletable, makefiletable,
606 actioncmd, for_test) -> tuple of string and bool
608 Emit the contents of the library Makefile. Returns string and a bool
609 variable which shows if subdirectories are used.
610 GLConfig: localdir, sourcebase, libname, pobase, auxdir, makefile, libtool,
611 macro_prefix, podomain, conddeps, witness_c_macro.
613 destfile is a filename relative to destdir of Makefile being generated.
614 modules is a list of GLModule instances.
615 moduletable is a GLModuleTable instance.
616 makefiletable is a GLMakefileTable instance.
617 actioncmd is a string variable, which represents the actioncmd; it can be
618 an empty string e.g. when user wants to generate files for GLTestDir.
619 for_test is a bool variable; it must be set to True if creating a package
620 for testing, False otherwise.'''
621 if type(destfile) is bytes or type(destfile) is string:
622 if type(destfile) is bytes:
623 destfile = destfile.decode(ENCS['default'])
624 else: # if destfile has not bytes or string type
625 raise(TypeError('destfile must be a string, not %s' %
626 type(destfile).__name__))
627 for module in modules:
628 if type(module) is not GLModule:
629 raise(TypeError('each module must be a GLModule instance'))
630 if type(moduletable) is not GLModuleTable:
631 raise(TypeError('moduletable must be a GLModuleTable, not %s' %
632 type(moduletable).__name__))
633 if type(makefiletable) is not GLMakefileTable:
634 raise(TypeError('makefiletable must be a GLMakefileTable, not %s' %
635 type(makefiletable).__name__))
636 if type(actioncmd) is bytes or type(actioncmd) is string:
637 if type(actioncmd) is bytes:
638 actioncmd = actioncmd.decode(ENCS['default'])
639 else: # if actioncmd has not bytes or string type
640 raise(TypeError('actioncmd must be a string, not %s' %
641 type(actioncmd).__name__))
642 if type(for_test) is not bool:
643 raise(TypeError('for_test must be a bool, not %s' %
644 type(for_test).__name__))
645 emit = string()
646 localdir = self.config['localdir']
647 sourcebase = self.config['sourcebase']
648 modcache = self.config['modcache']
649 libname = self.config['libname']
650 pobase = self.config['pobase']
651 auxdir = self.config['auxdir']
652 makefile = self.config['makefile']
653 libtool = self.config['libtool']
654 macro_prefix = self.config['macro_prefix']
655 podomain = self.config['podomain']
656 conddeps = self.config['conddeps']
657 witness_c_macro = self.config['witness_c_macro']
658 include_guard_prefix = self.config['include_guard_prefix']
659 ac_version = self.config['ac_version']
660 destfile = os.path.normpath(destfile)
662 # When creating an includable Makefile.am snippet, augment variables with
663 # += instead of assigning them.
664 if makefile:
665 assign = '+='
666 else: # if not makefile
667 assign = '='
668 if libtool:
669 libext = 'la'
670 perhapsLT = 'LT'
671 LD_flags = False
672 else: # if not libtool
673 libext = 'a'
674 perhapsLT = ''
675 LD_flags = True
676 if for_test:
677 # When creating a package for testing: Attempt to provoke failures,
678 # especially link errors, already during "make" rather than during
679 # "make check", because "make check" is not possible in a cross-compiling
680 # situation. Turn check_PROGRAMS into noinst_PROGRAMS.
681 check_PROGRAMS = True
682 else: # if not for_test
683 check_PROGRAMS = False
684 emit += "## DO NOT EDIT! GENERATED AUTOMATICALLY!\n"
685 emit += "## Process this file with automake to produce Makefile.in.\n"
686 emit += self.copyright_notice()
687 if actioncmd:
688 if len(actioncmd) <= 3000:
689 emit += "# Reproduce by: %s\n" % actioncmd
690 emit += '\n'
691 uses_subdirs = False
693 # Modify allsnippets variable.
694 allsnippets = string()
695 for module in modules:
696 if not module.isTests():
697 # Get conditional snippet, edit it and save to amsnippet1.
698 amsnippet1 = module.getAutomakeSnippet_Conditional()
699 amsnippet1 = amsnippet1.replace(
700 'lib_LIBRARIES', 'lib%_LIBRARIES')
701 amsnippet1 = amsnippet1.replace(
702 'lib_LTLIBRARIES', 'lib%_LTLIBRARIES')
703 if LD_flags:
704 pattern = compiler(
705 'lib_LDFLAGS[\t ]*\\+=(.*?)$', re.S | re.M)
706 amsnippet1 = pattern.sub('', amsnippet1)
707 pattern = compiler('lib_([A-Z][A-Z](?:.*?))', re.S | re.M)
708 amsnippet1 = pattern.sub('%s_%s_\\1' %
709 (libname, libext), amsnippet1)
710 amsnippet1 = amsnippet1.replace(
711 'lib%_LIBRARIES', 'lib_LIBRARIES')
712 amsnippet1 = amsnippet1.replace(
713 'lib%_LTLIBRARIES', 'lib_LTLIBRARIES')
714 if check_PROGRAMS:
715 amsnippet1 = amsnippet1.replace(
716 'check_PROGRAMS', 'noinst_PROGRAMS')
717 amsnippet1 = amsnippet1.replace('${gl_include_guard_prefix}',
718 include_guard_prefix)
719 if str(module) == 'alloca':
720 amsnippet1 += '%s_%s_LIBADD += @%sALLOCA@\n' % \
721 (libname, libext, perhapsLT)
722 amsnippet1 += '%s_%s_DEPENDENCIES += @%sALLOCA@\n' % \
723 (libname, libext, perhapsLT)
724 amsnippet1 = constants.combine_lines_matching(
725 compiler('%s_%s_SOURCES' % (libname, libext)),
726 amsnippet1)
728 # Get unconditional snippet, edit it and save to amsnippet2.
729 amsnippet2 = module.getAutomakeSnippet_Unconditional()
730 pattern = compiler('lib_([A-Z][A-Z](?:.*?))', re.S | re.M)
731 amsnippet2 = pattern.sub('%s_%s_\\1' %
732 (libname, libext), amsnippet2)
733 if type(amsnippet1) is bytes:
734 amsnippet1 = amsnippet1.decode(ENCS['default'])
735 if type(amsnippet2) is bytes:
736 amsnippet2 = amsnippet1.decode(ENCS['default'])
737 if not (amsnippet1 + amsnippet2).isspace():
738 allsnippets += '## begin gnulib module %s\n' % str(module)
739 if conddeps:
740 if moduletable.isConditional(module):
741 name = module.getConditionalName()
742 allsnippets += 'if %s\n' % name
743 allsnippets += amsnippet1
744 if conddeps:
745 allsnippets += 'endif\n'
746 allsnippets += amsnippet2
747 allsnippets += '## end gnulib module %s\n\n' % str(
748 module)
750 # Test whether there are some source files in subdirectories.
751 for file in module.getFiles():
752 if file.startswith('lib/') and file.endswith('.c') and \
753 file.count('/') > 1:
754 uses_subdirs = True
755 break
756 if not makefile:
757 subdir_options = string()
758 # If there are source files in subdirectories, prevent collision of the
759 # object files (example: hash.c and libxml/hash.c).
760 if uses_subdirs:
761 subdir_options = string(' subdir-objects')
762 emit += 'AUTOMAKE_OPTIONS = 1.9.6 gnits%s\n' % subdir_options
763 emit += '\n'
764 if not makefile:
765 emit += 'SUBDIRS =\n'
766 emit += 'noinst_HEADERS =\n'
767 emit += 'noinst_LIBRARIES =\n'
768 emit += 'noinst_LTLIBRARIES =\n'
769 # Automake versions < 1.11.4 create an empty pkgdatadir at
770 # installation time if you specify pkgdata_DATA to empty.
771 # See automake bugs #10997 and #11030:
772 # * https://debbugs.gnu.org/10997
773 # * https://debbugs.gnu.org/11030
774 # So we need this workaround.
775 pattern = compiler('^pkgdata_DATA *\\+=', re.S | re.M)
776 if pattern.findall(allsnippets):
777 emit += 'pkgdata_DATA =\n'
778 emit += 'EXTRA_DIST =\n'
779 emit += 'BUILT_SOURCES =\n'
780 emit += 'SUFFIXES =\n'
781 emit += 'MOSTLYCLEANFILES %s core *.stackdump\n' % assign
782 if not makefile:
783 emit += 'MOSTLYCLEANDIRS =\n'
784 emit += 'CLEANFILES =\n'
785 emit += 'DISTCLEANFILES =\n'
786 emit += 'MAINTAINERCLEANFILES =\n'
788 # Execute edits that apply to the Makefile.am being generated.
789 current_edit = int()
790 makefile_am_edits = makefiletable.count()
791 while current_edit != makefile_am_edits:
792 dictionary = makefiletable[current_edit]
793 if dictionary['var']:
794 paths = list()
795 paths += [joinpath(dictionary['dir'], 'Makefile.am')]
796 paths += [os.path.normpath('./%s/Makefile.am' %
797 dictionary['dir'])]
798 paths = sorted(set(paths))
799 if destfile in paths:
800 emit += '%s += %s\n' % (dictionary['var'],
801 dictionary['val'])
802 current_edit += 1
804 # Define two parts of cppflags variable.
805 emit += '\n'
806 cppflags_part1 = string()
807 cppflags_part2 = string()
808 if witness_c_macro:
809 cppflags_part1 = ' -D%s=1' % witness_c_macro
810 if for_test:
811 cppflags_part2 = ' -DGNULIB_STRICT_CHECKING=1'
812 cppflags = '%s%s' % (cppflags_part1, cppflags_part2)
813 if not makefile:
814 emit += 'AM_CPPFLAGS =%s\n' % cppflags
815 emit += 'AM_CFLAGS =\n'
816 else: # if makefile
817 if cppflags:
818 emit += 'AM_CPPFLAGS +=%s\n' % cppflags
819 emit += '\n'
821 # One of the snippets or the user's Makefile.am already specifies an
822 # installation location for the library. Don't confuse automake by saying
823 # it should not be installed.
824 # First test if allsnippets already specify an installation location.
825 insnippets = False
826 inmakefile = False
827 regex = '^[a-zA-Z0-9_]*_%sLIBRARIES *\\+{0,1}= *%s.%s' % \
828 (perhapsLT, libname, libext)
829 pattern = compiler(regex, re.S | re.M)
830 insnippets = bool(pattern.findall(allsnippets))
831 # Then test if $sourcebase/Makefile.am (if it exists) specifies it.
832 path = joinpath(sourcebase, 'Makefile.am')
833 if makefile and isfile(path):
834 with codecs.open(path, 'rb', 'UTF-8') as file:
835 data = file.read()
836 inmakefile = bool(pattern.findall(data))
837 if not any([insnippets, inmakefile]):
838 # By default, the generated library should not be installed.
839 emit += 'noinst_%sLIBRARIES += %s.%s\n' % (
840 perhapsLT, libname, libext)
842 emit += '\n'
843 emit += '%s_%s_SOURCES =\n' % (libname, libext)
844 # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
845 # automake during its analysis looks for $(LIBOBJS), not for @LIBOBJS@.
846 emit += '%s_%s_LIBADD = $(%s_%sLIBOBJS)\n' % \
847 (libname, libext, macro_prefix, perhapsLT)
848 emit += '%s_%s_DEPENDENCIES = $(%s_%sLIBOBJS)\n' % \
849 (libname, libext, macro_prefix, perhapsLT)
850 emit += 'EXTRA_%s_%s_SOURCES =\n' % (libname, libext)
851 if libtool:
852 emit += '%s_%s_LDFLAGS = $(AM_LDFLAGS)\n' % (libname, libext)
853 emit += '%s_%s_LDFLAGS += -no-undefined\n' % (libname, libext)
854 # Synthesize an ${libname}_${libext}_LDFLAGS augmentation by combining
855 # the link dependencies of all modules.
856 links = [module.getLink()
857 for module in modules if not module.isTests()]
858 ulinks = list()
859 for link in links:
860 for lib in link:
861 lib = constants.nlremove(lib)
862 position = lib.find(' when linking with libtool')
863 if position != -1:
864 lib = lib[:position]
865 ulinks += [lib]
866 ulinks = sorted(set(ulinks))
867 for link in ulinks:
868 emit += '%s_%s_LDFLAGS += %s\n' % (libname, libext, link)
869 emit += '\n'
870 if pobase:
871 emit += 'AM_CPPFLAGS += -DDEFAULT_TEXT_DOMAIN="%s-gnulib"\n' % podomain
872 emit += '\n'
873 allsnippets = allsnippets.replace('$(top_srcdir)/build-aux/',
874 '$(top_srcdir)/%s/' % auxdir)
875 emit += allsnippets
876 emit += '\n'
877 emit += 'mostlyclean-local: mostlyclean-generic\n'
878 emit += '\t@for dir in \'\' $(MOSTLYCLEANDIRS); do \\\n'
879 emit += '\t if test -n "$$dir" && test -d $$dir; then \\\n'
880 emit += '\t echo "rmdir $$dir"; rmdir $$dir; \\\n'
881 emit += '\t fi; \\\n'
882 emit += '\tdone; \\\n'
883 emit += '\t:\n'
884 emit = constants.nlconvert(emit)
885 if type(emit) is bytes:
886 emit = emit.decode(ENCS['default'])
887 result = tuple([emit, uses_subdirs])
888 return(result)
890 def tests_Makefile_am(self, destfile, modules, makefiletable,
891 witness_macro, for_test):
892 '''GLEmiter.tests_Makefile_am(destfile, modules, makefiletable,
893 witness_c_macro, for_test) -> tuple of string and bool
895 Emit the contents of the tests Makefile. Returns string and a bool variable
896 which shows if subdirectories are used.
897 GLConfig: localdir, modules, libname, auxdir, makefile, libtool,
898 sourcebase, m4base, testsbase, macro_prefix, witness_c_macro,
899 single_configure, libtests.
901 destfile is a filename relative to destdir of Makefile being generated.
902 witness_macro is a string which represents witness_c_macro with the suffix.
903 modules is a list of GLModule instances.
904 moduletable is a GLModuleTable instance.
905 makefiletable is a GLMakefileTable instance.
906 actioncmd is a string variable, which represents the actioncmd; it can be
907 an empty string e.g. when user wants to generate files for GLTestDir.
908 for_test is a bool variable; it must be set to True if creating a package
909 for testing, False otherwise.'''
910 if type(destfile) is bytes or type(destfile) is string:
911 if type(destfile) is bytes:
912 destfile = destfile.decode(ENCS['default'])
913 else: # if destfile has not bytes or string type
914 raise(TypeError('destfile must be a string, not %s' %
915 type(destfile).__name__))
916 for module in modules:
917 if type(module) is not GLModule:
918 raise(TypeError('each module must be a GLModule instance'))
919 if type(makefiletable) is not GLMakefileTable:
920 raise(TypeError('makefiletable must be a GLMakefileTable, not %s' %
921 type(makefiletable).__name__))
922 if type(witness_macro) is bytes or type(witness_macro) is string:
923 if type(witness_macro) is bytes:
924 witness_macro = witness_macro.decode(ENCS['default'])
925 else: # if witness_macro has not bytes or string type
926 raise(TypeError('witness_macro must be a string, not %s' %
927 type(witness_macro).__name__))
928 if type(for_test) is not bool:
929 raise(TypeError('for_test must be a bool, not %s' %
930 type(for_test).__name__))
931 emit = string()
932 localdir = self.config['localdir']
933 auxdir = self.config['auxdir']
934 sourcebase = self.config['sourcebase']
935 modcache = self.config['modcache']
936 libname = self.config['libname']
937 m4base = self.config['m4base']
938 pobase = self.config['pobase']
939 testsbase = self.config['testsbase']
940 makefile = self.config['makefile']
941 libtool = self.config['libtool']
942 macro_prefix = self.config['macro_prefix']
943 podomain = self.config['podomain']
944 conddeps = self.config['conddeps']
945 witness_c_macro = self.config['witness_c_macro']
946 include_guard_prefix = self.config['include_guard_prefix']
947 ac_version = self.config['ac_version']
948 libtests = self.config['libtests']
949 single_configure = self.config['single_configure']
951 if libtool:
952 libext = 'la'
953 perhapsLT = 'LT'
954 LD_flags = False
955 else: # if not libtool
956 libext = 'a'
957 perhapsLT = ''
958 LD_flags = True
959 if for_test:
960 # When creating a package for testing: Attempt to provoke failures,
961 # especially link errors, already during "make" rather than during
962 # "make check", because "make check" is not possible in a cross-compiling
963 # situation. Turn check_PROGRAMS into noinst_PROGRAMS.
964 check_PROGRAMS = True
965 else: # if not for_test
966 check_PROGRAMS = False
968 # Calculate testsbase_inverse
969 counter = int()
970 testsbase_inverse = string()
971 while counter < len(testsbase.split('/')):
972 testsbase_inverse += '../'
973 counter += 1
974 testsbase_inverse = os.path.normpath(testsbase_inverse)
976 # Begin the generation.
977 emit += "## DO NOT EDIT! GENERATED AUTOMATICALLY!\n"
978 emit += "## Process this file with automake to produce Makefile.in.\n"
979 emit += '%s\n' % self.copyright_notice()
981 uses_subdirs = False
982 main_snippets = string()
983 longrun_snippets = string()
984 for module in modules:
985 if for_test and not single_configure:
986 flag = module.isTests()
987 else: # if for_test and not single_configure
988 flag = True
989 if flag:
990 snippet = module.getAutomakeSnippet()
991 snippet = snippet.replace('lib_LIBRARIES', 'lib%_LIBRARIES')
992 snippet = snippet.replace(
993 'lib_LTLIBRARIES', 'lib%_LTLIBRARIES')
994 if LD_flags:
995 pattern = compiler(
996 'lib_LDFLAGS[\t ]*\\+=(.*?)$', re.S | re.M)
997 snippet = pattern.sub('', snippet)
998 pattern = compiler('lib_([A-Z][A-Z](?:.*?))', re.S | re.M)
999 snippet = pattern.sub('libtests_a_\\1', snippet)
1000 snippet = snippet.replace('lib%_LIBRARIES', 'lib_LIBRARIES')
1001 snippet = snippet.replace(
1002 'lib%_LTLIBRARIES', 'lib_LTLIBRARIES')
1003 if check_PROGRAMS:
1004 snippet = snippet.replace(
1005 'check_PROGRAMS', 'noinst_PROGRAMS')
1006 snippet = snippet.replace('${gl_include_guard_prefix}',
1007 include_guard_prefix)
1008 # Check if module is 'alloca'.
1009 if libtests and str(module) == 'alloca':
1010 snippet += 'libtests_a_LIBADD += @%sALLOCA@\n' % perhapsLT
1011 snippet += 'libtests_a_DEPENDENCIES += @%sALLOCA@\n' % perhapsLT
1013 # Skip the contents if it's entirely empty.
1014 if snippet.strip():
1015 # Check status of the module.
1016 status = module.getStatus()
1017 islongrun = False
1018 for word in status:
1019 if word == 'longrunning-test':
1020 islongrun = True
1021 break
1022 if not islongrun:
1023 snippet = snippet.replace(
1024 '\n\nEXTRA_DIST', '\nEXTRA_DIST')
1025 main_snippets += '## begin gnulib module %s\n' % str(
1026 module)
1027 main_snippets += snippet
1028 main_snippets += '## end gnulib module %s\n\n' % str(
1029 module)
1030 else: # if islongrunning
1031 snippet = snippet.replace(
1032 '\n\nEXTRA_DIST', '\nEXTRA_DIST')
1033 longrun_snippets += '## begin gnulib module %s\n' % str(
1034 module)
1035 longrun_snippets += snippet
1036 longrun_snippets += '## end gnulib module %s\n' % str(
1037 module)
1039 # Test whether there are some source files in subdirectories.
1040 for file in module.getFiles():
1041 if file.startswith('lib/') and file.endswith('.c') and \
1042 file.count('/') > 1:
1043 uses_subdirs = True
1044 break
1046 # Generate dependencies here, since it eases the debugging of test failures.
1047 # If there are source files in subdirectories, prevent collision of the
1048 # object files (example: hash.c and libxml/hash.c).
1049 subdir_options = string()
1050 if uses_subdirs:
1051 subdir_options = string(' subdir-objects')
1052 emit += 'AUTOMAKE_OPTIONS = 1.9.6 foreign%s\n\n' % subdir_options
1053 if for_test and not single_configure:
1054 emit += 'ACLOCAL_AMFLAGS = -I %s/%s\n\n' % (
1055 testsbase_inverse, m4base)
1057 # Nothing is being added to SUBDIRS; nevertheless the existence of this
1058 # variable is needed to avoid an error from automake:
1059 # "AM_GNU_GETTEXT used but SUBDIRS not defined"
1060 emit += 'SUBDIRS = .\n'
1061 emit += 'TESTS =\n'
1062 emit += 'XFAIL_TESTS =\n'
1063 emit += 'TESTS_ENVIRONMENT =\n'
1064 emit += 'noinst_PROGRAMS =\n'
1065 if not for_test:
1066 emit += 'check_PROGRAMS =\n'
1067 emit += 'noinst_HEADERS =\n'
1068 emit += 'noinst_LIBRARIES =\n'
1069 if libtests:
1070 if for_test:
1071 emit += 'noinst_LIBRARIES += libtests.a\n'
1072 else: # if not for_test
1073 emit += 'check_LIBRARIES = libtests.a\n'
1075 # Automake versions < 1.11.4 create an empty pkgdatadir at
1076 # installation time if you specify pkgdata_DATA to empty.
1077 # See automake bugs #10997 and #11030:
1078 # * https://debbugs.gnu.org/10997
1079 # * https://debbugs.gnu.org/11030
1080 # So we need this workaround.
1081 pattern = compiler('^pkgdata_DATA *\\+=', re.S | re.M)
1082 if bool(pattern.findall(main_snippets)) or \
1083 bool(pattern.findall(longrun_snippets)):
1084 emit += 'pkgdata_DATA =\n'
1086 emit += 'EXTRA_DIST =\n'
1087 emit += 'BUILT_SOURCES =\n'
1088 emit += 'SUFFIXES =\n'
1089 emit += 'MOSTLYCLEANFILES = core *.stackdump\n'
1090 emit += 'MOSTLYCLEANDIRS =\n'
1091 emit += 'CLEANFILES =\n'
1092 emit += 'DISTCLEANFILES =\n'
1093 emit += 'MAINTAINERCLEANFILES =\n'
1095 # Execute edits that apply to the Makefile.am being generated.
1096 # Execute edits that apply to the Makefile.am being generated.
1097 current_edit = int()
1098 makefile_am_edits = makefiletable.count()
1099 while current_edit != makefile_am_edits:
1100 dictionary = makefiletable[current_edit]
1101 if dictionary['var']:
1102 paths = list()
1103 paths += [joinpath(dictionary['dir'], 'Makefile.am')]
1104 paths += [os.path.normpath('./%s/Makefile.am' %
1105 dictionary['dir'])]
1106 paths = sorted(set(paths))
1107 if destfile in paths:
1108 emit += '%s += %s\n' % (dictionary['var'],
1109 dictionary['val'])
1110 current_edit += 1
1112 emit += '\nAM_CPPFLAGS = \\\n'
1113 if for_test:
1114 emit += ' -DGNULIB_STRICT_CHECKING=1 \\\n'
1115 if witness_c_macro:
1116 emit += ' -D%s=1 \\\n' % witness_c_macro
1117 if witness_macro:
1118 emit += ' -D@%s@=1 \\\n' % witness_macro
1119 emit += ' -I. -I$(srcdir) \\\n'
1120 emit += ' -I%s -I$(srcdir)/%s \\\n' % \
1121 (testsbase_inverse, testsbase_inverse)
1122 emit += ' -I%s/%s -I$(srcdir)/%s/%s\n' % \
1123 (testsbase_inverse, sourcebase, testsbase_inverse, sourcebase)
1124 emit += '\n'
1126 if libtests:
1127 # All test programs need to be linked with libtests.a.
1128 # It needs to be passed to the linker before ${libname}.${libext},
1129 # since the tests-related modules depend on the main modules.
1130 # It also needs to be passed to the linker after ${libname}.${libext}
1131 # because the latter might contain incomplete modules (such as the
1132 # 'version-etc' module whose dependency to 'version-etc-fsf' is
1133 # voluntarily omitted).
1134 # The LIBTESTS_LIBDEPS can be passed to the linker once or twice, it
1135 # does not matter.
1136 emit += 'LDADD = libtests.a %s/%s/%s.%s libtests.a %s/%s/%s.%s libtests.a $(LIBTESTS_LIBDEPS)\n\n' % \
1137 (testsbase_inverse, sourcebase, libname, libext,
1138 testsbase_inverse, sourcebase, libname, libext)
1139 else:
1140 emit += 'LDADD = %s/%s/%s.%s\n\n' % \
1141 (testsbase_inverse, sourcebase, libname, libext)
1142 if libtests:
1143 emit += 'libtests_a_SOURCES =\n'
1144 # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
1145 # automake during its analysis looks for $(LIBOBJS), not for @LIBOBJS@.
1146 emit += 'libtests_a_LIBADD = $(%stests_LIBOBJS)\n' % macro_prefix
1147 emit += 'libtests_a_DEPENDENCIES = $(%stests_LIBOBJS)\n' % macro_prefix
1148 emit += 'EXTRA_libtests_a_SOURCES =\n'
1149 # The circular dependency in LDADD requires this.
1150 emit += 'AM_LIBTOOLFLAGS = --preserve-dup-deps\n\n'
1151 # Many test scripts use ${EXEEXT} or ${srcdir}.
1152 # EXEEXT is defined by AC_PROG_CC through autoconf.
1153 # srcdir is defined by autoconf and automake.
1154 emit += "TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='$(srcdir)'\n\n"
1155 main_snippets = main_snippets.replace('$(top_srcdir)/build-aux/',
1156 '$(top_srcdir)/%s/' % auxdir)
1157 longrun_snippets = longrun_snippets.replace('$(top_srcdir)/build-aux/',
1158 '$(top_srcdir)/%s/' % auxdir)
1159 emit += main_snippets + longrun_snippets
1160 emit += '# Clean up after Solaris cc.\n'
1161 emit += 'clean-local:\n'
1162 emit += '\trm -rf SunWS_cache\n\n'
1163 emit += 'mostlyclean-local: mostlyclean-generic\n'
1164 emit += '\t@for dir in \'\' $(MOSTLYCLEANDIRS); do \\\n'
1165 emit += '\t if test -n "$$dir" && test -d $$dir; then \\\n'
1166 emit += '\t echo "rmdir $$dir"; rmdir $$dir; \\\n'
1167 emit += '\t fi; \\\n'
1168 emit += '\tdone; \\\n'
1169 emit += '\t:\n'
1170 emit = constants.nlconvert(emit)
1171 if type(emit) is bytes:
1172 emit = emit.decode(ENCS['default'])
1173 result = tuple([emit, uses_subdirs])
1174 return(result)