4 #===============================================================================
5 # Define global imports
6 #===============================================================================
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
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
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.'''
65 if type(config
) is not GLConfig
:
66 raise(TypeError('config must be a GLConfig, not %s' %
67 type(config
).__name
__))
71 '''x.__repr__() <==> repr(x)'''
72 result
= '<pygnulib.GLEmiter %s>' % hex(id(self
))
75 def copyright_notice(self
):
76 '''GLEmiter.copyright_notice() -> string
78 Emit a header for a generated file.'''
80 emit
+= "# %s" % self
.info
.copyright()
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 <http://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.'''
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.
156 else: # if not str(module) in ['gnumakefile', 'maintainer-makefile']
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
)
168 args
= ['sed', '-e', transformer
]
169 path
= fileassistant
.tmpfilename('snippet')
170 with codecs
.open(path
, 'wb', 'UTF-8') as file:
172 stdin
= codecs
.open(path
, 'rb', 'UTF-8')
173 snippet
= sp
.check_output(args
, stdin
=stdin
, shell
=False)
174 snippet
= snippet
.decode("UTF-8")
177 snippet
= snippet
.replace('$gl_cond_libtool', 'false')
178 snippet
= snippet
.replace('gl_libdeps', 'gltests_libdeps')
179 snippet
= snippet
.replace('gl_ltlibdeps', 'gltests_ltlibdeps')
181 snippet
= snippet
.replace('AM_GNU_GETTEXT([external])', 'dnl you must \
182 add AM_GNU_GETTEXT([external]) or similar to configure.ac.')
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
)
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])'
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'])
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.
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.'''
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']
266 # Ignore the conditions, and enable all modules unconditionally.
267 for module
in modules
:
271 solution
= module
.isNonTests()
273 solution
= module
.isTests()
275 emit
+= self
.autoconfSnippet(module
, fileassistant
, toplevel
,
276 disable_libtool
, disable_gettext
, replace_auxdir
, ' ')
278 # Emit the autoconf code for the unconditional modules.
279 for module
in modules
:
283 solution
= module
.isNonTests()
285 solution
= module
.isTests()
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
:
295 solution
= module
.isNonTests()
297 solution
= module
.isTests()
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
305 for module
in modules
:
309 solution
= module
.isNonTests()
311 solution
= module
.isTests()
313 if moduletable
.isConditional(module
):
314 shellfunc
= module
.getShellFunc()
315 shellvar
= module
.getShellVar()
316 emit
+= ' %s ()\n' % shellfunc
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.
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(
332 if condition
!= None:
333 emit
+= ' if %s; then\n' % condition
334 emit
+= ' %s\n' % shellfunc
336 else: # if condition == None
337 emit
+= ' %s\n' % shellfunc
338 # if not moduletable.isConditional(depmodule)
340 # The autoconf code for $dep has already been emitted above and
341 # therefore is already executed when this code is run.
343 # Define the Automake conditionals.
344 emit
+= ' m4_pattern_allow([^%s_GNULIB_ENABLED_])\n' % macro_prefix
345 for module
in modules
:
349 solution
= module
.isNonTests()
351 solution
= module
.isTests()
353 condname
= module
.getConditionalName()
354 shellvar
= module
.getShellVar()
355 emit
+= ' AM_CONDITIONAL([%s], [$%s])\n' % (
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'])
364 def po_Makevars(self
):
365 '''GLEmiter.po_Makevars() -> string
367 Emit the contents of po/ makefile parameterization.
368 GLConfig: pobase, podomain.'''
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
):
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
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, \
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
408 # - Strings which make invalid assumptions about notation of date, time or
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.'''
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
)
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.'''
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
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
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
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.'''
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.
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
522 m4_if(m4_sysval, [0], [],
523 [AC_FATAL([expected source file, required through AC_LIBSOURCES, not \
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([
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"
543 AC_SUBST([%V1%_LIBOBJS], [$%V1%_libobjs])
544 AC_SUBST([%V1%_LTLIBOBJS], [$%V1%_ltlibobjs])
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.'''
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
__))
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, [ ])
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
__))
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.
666 else: # if not makefile
672 else: # if not libtool
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()
688 if len(actioncmd
) <= 3000:
689 emit
+= "# Reproduce by: %s\n" % actioncmd
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')
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')
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
)),
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
)
740 if moduletable
.isConditional(module
):
741 name
= module
.getConditionalName()
742 allsnippets
+= 'if %s\n' % name
743 allsnippets
+= amsnippet1
745 allsnippets
+= 'endif\n'
746 allsnippets
+= amsnippet2
747 allsnippets
+= '## end gnulib module %s\n\n' % str(
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 \
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).
761 subdir_options
= string(' subdir-objects')
762 emit
+= 'AUTOMAKE_OPTIONS = 1.9.6 gnits%s\n' % subdir_options
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 # * http://debbugs.gnu.org/10997
773 # * http://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
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.
790 makefile_am_edits
= makefiletable
.count()
791 while current_edit
!= makefile_am_edits
:
792 dictionary
= makefiletable
[current_edit
]
793 if dictionary
['var']:
795 paths
+= [joinpath(dictionary
['dir'], 'Makefile.am')]
796 paths
+= [os
.path
.normpath('./%s/Makefile.am' %
798 paths
= sorted(set(paths
))
799 if destfile
in paths
:
800 emit
+= '%s += %s\n' % (dictionary
['var'],
804 # Define two parts of cppflags variable.
806 cppflags_part1
= string()
807 cppflags_part2
= string()
809 cppflags_part1
= ' -D%s=1' % witness_c_macro
811 cppflags_part2
= ' -DGNULIB_STRICT_CHECKING=1'
812 cppflags
= '%s%s' % (cppflags_part1
, cppflags_part2
)
814 emit
+= 'AM_CPPFLAGS =%s\n' % cppflags
815 emit
+= 'AM_CFLAGS =\n'
818 emit
+= 'AM_CPPFLAGS +=%s\n' % cppflags
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.
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:
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
)
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
)
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.
857 links
= [module
.getLink()
858 for module
in modules
if not module
.isTests()]
860 link
= constants
.nlremove(link
)
861 position
= link
.find(' when linking with libtool')
863 link
= link
[:position
]
865 listing
= sorted(set([link
for link
in listing
if link
!= '']))
867 emit
+= '%s_%s_LDFLAGS += %s\n' % (libname
, libext
, link
)
870 emit
+= 'AM_CPPFLAGS += -DDEFAULT_TEXT_DOMAIN="%s-gnulib"\n' % podomain
872 allsnippets
= allsnippets
.replace('$(top_srcdir)/build-aux/',
873 '$(top_srcdir)/%s/' % auxdir
)
876 emit
+= 'mostlyclean-local: mostlyclean-generic\n'
877 emit
+= '\t@for dir in \'\' $(MOSTLYCLEANDIRS); do \\\n'
878 emit
+= '\t if test -n "$$dir" && test -d $$dir; then \\\n'
879 emit
+= '\t echo "rmdir $$dir"; rmdir $$dir; \\\n'
880 emit
+= '\t fi; \\\n'
881 emit
+= '\tdone; \\\n'
883 emit
= constants
.nlconvert(emit
)
884 if type(emit
) is bytes
:
885 emit
= emit
.decode(ENCS
['default'])
886 result
= tuple([emit
, uses_subdirs
])
889 def tests_Makefile_am(self
, destfile
, modules
, makefiletable
,
890 witness_macro
, for_test
):
891 '''GLEmiter.tests_Makefile_am(destfile, modules, makefiletable,
892 witness_c_macro, for_test) -> tuple of string and bool
894 Emit the contents of the tests Makefile. Returns string and a bool variable
895 which shows if subdirectories are used.
896 GLConfig: localdir, modules, libname, auxdir, makefile, libtool,
897 sourcebase, m4base, testsbase, macro_prefix, witness_c_macro,
898 single_configure, libtests.
900 destfile is a filename relative to destdir of Makefile being generated.
901 witness_macro is a string which represents witness_c_macro with the suffix.
902 modules is a list of GLModule instances.
903 moduletable is a GLModuleTable instance.
904 makefiletable is a GLMakefileTable instance.
905 actioncmd is a string variable, which represents the actioncmd; it can be
906 an empty string e.g. when user wants to generate files for GLTestDir.
907 for_test is a bool variable; it must be set to True if creating a package
908 for testing, False otherwise.'''
909 if type(destfile
) is bytes
or type(destfile
) is string
:
910 if type(destfile
) is bytes
:
911 destfile
= destfile
.decode(ENCS
['default'])
912 else: # if destfile has not bytes or string type
913 raise(TypeError('destfile must be a string, not %s' %
914 type(destfile
).__name
__))
915 for module
in modules
:
916 if type(module
) is not GLModule
:
917 raise(TypeError('each module must be a GLModule instance'))
918 if type(makefiletable
) is not GLMakefileTable
:
919 raise(TypeError('makefiletable must be a GLMakefileTable, not %s' %
920 type(makefiletable
).__name
__))
921 if type(witness_macro
) is bytes
or type(witness_macro
) is string
:
922 if type(witness_macro
) is bytes
:
923 witness_macro
= witness_macro
.decode(ENCS
['default'])
924 else: # if witness_macro has not bytes or string type
925 raise(TypeError('witness_macro must be a string, not %s' %
926 type(witness_macro
).__name
__))
927 if type(for_test
) is not bool:
928 raise(TypeError('for_test must be a bool, not %s' %
929 type(for_test
).__name
__))
931 localdir
= self
.config
['localdir']
932 auxdir
= self
.config
['auxdir']
933 sourcebase
= self
.config
['sourcebase']
934 modcache
= self
.config
['modcache']
935 libname
= self
.config
['libname']
936 m4base
= self
.config
['m4base']
937 pobase
= self
.config
['pobase']
938 testsbase
= self
.config
['testsbase']
939 makefile
= self
.config
['makefile']
940 libtool
= self
.config
['libtool']
941 macro_prefix
= self
.config
['macro_prefix']
942 podomain
= self
.config
['podomain']
943 conddeps
= self
.config
['conddeps']
944 witness_c_macro
= self
.config
['witness_c_macro']
945 include_guard_prefix
= self
.config
['include_guard_prefix']
946 ac_version
= self
.config
['ac_version']
947 libtests
= self
.config
['libtests']
948 single_configure
= self
.config
['single_configure']
954 else: # if not libtool
959 # When creating a package for testing: Attempt to provoke failures,
960 # especially link errors, already during "make" rather than during
961 # "make check", because "make check" is not possible in a cross-compiling
962 # situation. Turn check_PROGRAMS into noinst_PROGRAMS.
963 check_PROGRAMS
= True
964 else: # if not for_test
965 check_PROGRAMS
= False
967 # Calculate testsbase_inverse
969 testsbase_inverse
= string()
970 while counter
< len(testsbase
.split('/')):
971 testsbase_inverse
+= '../'
973 testsbase_inverse
= os
.path
.normpath(testsbase_inverse
)
975 # Begin the generation.
976 emit
+= "## DO NOT EDIT! GENERATED AUTOMATICALLY!\n"
977 emit
+= "## Process this file with automake to produce Makefile.in.\n"
978 emit
+= '%s\n' % self
.copyright_notice()
981 main_snippets
= string()
982 longrun_snippets
= string()
983 for module
in modules
:
984 if for_test
and not single_configure
:
985 flag
= module
.isTests()
986 else: # if for_test and not single_configure
989 snippet
= module
.getAutomakeSnippet()
990 snippet
= snippet
.replace('lib_LIBRARIES', 'lib%_LIBRARIES')
991 snippet
= snippet
.replace(
992 'lib_LTLIBRARIES', 'lib%_LTLIBRARIES')
995 'lib_LDFLAGS[\t ]*\\+=(.*?)$', re
.S | re
.M
)
996 snippet
= pattern
.sub('', snippet
)
997 pattern
= compiler('lib_([A-Z][A-Z](?:.*?))', re
.S | re
.M
)
998 snippet
= pattern
.sub('libtests_a_\\1', snippet
)
999 snippet
= snippet
.replace('lib%_LIBRARIES', 'lib_LIBRARIES')
1000 snippet
= snippet
.replace(
1001 'lib%_LTLIBRARIES', 'lib_LTLIBRARIES')
1003 snippet
= snippet
.replace(
1004 'check_PROGRAMS', 'noinst_PROGRAMS')
1005 snippet
= snippet
.replace('${gl_include_guard_prefix}',
1006 include_guard_prefix
)
1007 # Check if module is 'alloca'.
1008 if libtests
and str(module
) == 'alloca':
1009 snippet
+= 'libtests_a_LIBADD += @%sALLOCA@\n' % perhapsLT
1010 snippet
+= 'libtests_a_DEPENDENCIES += @%sALLOCA@\n' % perhapsLT
1012 # Skip the contents if it's entirely empty.
1014 # Check status of the module.
1015 status
= module
.getStatus()
1018 if word
== 'longrunning-test':
1022 snippet
= snippet
.replace(
1023 '\n\nEXTRA_DIST', '\nEXTRA_DIST')
1024 main_snippets
+= '## begin gnulib module %s\n' % str(
1026 main_snippets
+= snippet
1027 main_snippets
+= '## end gnulib module %s\n\n' % str(
1029 else: # if islongrunning
1030 snippet
= snippet
.replace(
1031 '\n\nEXTRA_DIST', '\nEXTRA_DIST')
1032 longrun_snippets
+= '## begin gnulib module %s\n' % str(
1034 longrun_snippets
+= snippet
1035 longrun_snippets
+= '## end gnulib module %s\n' % str(
1038 # Test whether there are some source files in subdirectories.
1039 for file in module
.getFiles():
1040 if file.startswith('lib/') and file.endswith('.c') and \
1041 file.count('/') > 1:
1045 # Generate dependencies here, since it eases the debugging of test failures.
1046 # If there are source files in subdirectories, prevent collision of the
1047 # object files (example: hash.c and libxml/hash.c).
1048 subdir_options
= string()
1050 subdir_options
= string(' subdir-objects')
1051 emit
+= 'AUTOMAKE_OPTIONS = 1.9.6 foreign%s\n\n' % subdir_options
1052 if for_test
and not single_configure
:
1053 emit
+= 'ACLOCAL_AMFLAGS = -I %s/%s\n\n' % (
1054 testsbase_inverse
, m4base
)
1056 # Nothing is being added to SUBDIRS; nevertheless the existence of this
1057 # variable is needed to avoid an error from automake:
1058 # "AM_GNU_GETTEXT used but SUBDIRS not defined"
1059 emit
+= 'SUBDIRS = .\n'
1061 emit
+= 'XFAIL_TESTS =\n'
1062 emit
+= 'TESTS_ENVIRONMENT =\n'
1063 emit
+= 'noinst_PROGRAMS =\n'
1065 emit
+= 'check_PROGRAMS =\n'
1066 emit
+= 'noinst_HEADERS =\n'
1067 emit
+= 'noinst_LIBRARIES =\n'
1070 emit
+= 'noinst_LIBRARIES += libtests.a\n'
1071 else: # if not for_test
1072 emit
+= 'check_LIBRARIES = libtests.a\n'
1074 # Automake versions < 1.11.4 create an empty pkgdatadir at
1075 # installation time if you specify pkgdata_DATA to empty.
1076 # See automake bugs #10997 and #11030:
1077 # * http://debbugs.gnu.org/10997
1078 # * http://debbugs.gnu.org/11030
1079 # So we need this workaround.
1080 pattern
= compiler('^pkgdata_DATA *\\+=', re
.S | re
.M
)
1081 if bool(pattern
.findall(main_snippets
)) or \
1082 bool(pattern
.findall(longrun_snippets
)):
1083 emit
+= 'pkgdata_DATA =\n'
1085 emit
+= 'EXTRA_DIST =\n'
1086 emit
+= 'BUILT_SOURCES =\n'
1087 emit
+= 'SUFFIXES =\n'
1088 emit
+= 'MOSTLYCLEANFILES = core *.stackdump\n'
1089 emit
+= 'MOSTLYCLEANDIRS =\n'
1090 emit
+= 'CLEANFILES =\n'
1091 emit
+= 'DISTCLEANFILES =\n'
1092 emit
+= 'MAINTAINERCLEANFILES =\n'
1094 # Execute edits that apply to the Makefile.am being generated.
1095 # Execute edits that apply to the Makefile.am being generated.
1096 current_edit
= int()
1097 makefile_am_edits
= makefiletable
.count()
1098 while current_edit
!= makefile_am_edits
:
1099 dictionary
= makefiletable
[current_edit
]
1100 if dictionary
['var']:
1102 paths
+= [joinpath(dictionary
['dir'], 'Makefile.am')]
1103 paths
+= [os
.path
.normpath('./%s/Makefile.am' %
1105 paths
= sorted(set(paths
))
1106 if destfile
in paths
:
1107 emit
+= '%s += %s\n' % (dictionary
['var'],
1111 emit
+= '\nAM_CPPFLAGS = \\\n'
1113 emit
+= ' -DGNULIB_STRICT_CHECKING=1 \\\n'
1115 emit
+= ' -D%s=1 \\\n' % witness_c_macro
1117 emit
+= ' -D@%s@=1 \\\n' % witness_macro
1118 emit
+= ' -I. -I$(srcdir) \\\n'
1119 emit
+= ' -I%s -I$(srcdir)/%s \\\n' % \
1120 (testsbase_inverse
, testsbase_inverse
)
1121 emit
+= ' -I%s/%s -I$(srcdir)/%s/%s\n' % \
1122 (testsbase_inverse
, sourcebase
, testsbase_inverse
, sourcebase
)
1125 local_ldadd_before
= string()
1126 local_ldadd_after
= string()
1128 # All test programs need to be linked with libtests.a.
1129 # It needs to be passed to the linker before ${libname}.${libext}, since
1130 # the tests-related modules depend on the main modules.
1131 # It also needs to be passed to the linker after ${libname}.${libext}
1132 # because the latter might contain incomplete modules (such as the
1133 # 'error' module whose dependency to 'progname' is voluntarily omitted).
1134 # The LIBTESTS_LIBDEPS can be passed to the linker once or twice, it does
1136 local_ldadd_before
= ' libtests.a'
1137 local_ldadd_after
= ' libtests.a $(LIBTESTS_LIBDEPS)'
1138 emit
+= 'LDADD =%s %s/%s/%s.%s%s\n\n' % \
1139 (local_ldadd_before
, testsbase_inverse
, sourcebase
, libname
, libext
,
1142 emit
+= 'libtests_a_SOURCES =\n'
1143 # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
1144 # automake during its analysis looks for $(LIBOBJS), not for @LIBOBJS@.
1145 emit
+= 'libtests_a_LIBADD = $(%stests_LIBOBJS)\n' % macro_prefix
1146 emit
+= 'libtests_a_DEPENDENCIES = $(%stests_LIBOBJS)\n' % macro_prefix
1147 emit
+= 'EXTRA_libtests_a_SOURCES =\n'
1148 # The circular dependency in LDADD requires this.
1149 emit
+= 'AM_LIBTOOLFLAGS = --preserve-dup-deps\n\n'
1150 # Many test scripts use ${EXEEXT} or ${srcdir}.
1151 # EXEEXT is defined by AC_PROG_CC through autoconf.
1152 # srcdir is defined by autoconf and automake.
1153 emit
+= "TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='$(srcdir)'\n\n"
1154 main_snippets
= main_snippets
.replace('$(top_srcdir)/build-aux/',
1155 '$(top_srcdir)/%s/' % auxdir
)
1156 longrun_snippets
= longrun_snippets
.replace('$(top_srcdir)/build-aux/',
1157 '$(top_srcdir)/%s/' % auxdir
)
1158 emit
+= main_snippets
+ longrun_snippets
1159 emit
+= '# Clean up after Solaris cc.\n'
1160 emit
+= 'clean-local:\n'
1161 emit
+= '\trm -rf SunWS_cache\n\n'
1162 emit
+= 'mostlyclean-local: mostlyclean-generic\n'
1163 emit
+= '\t@for dir in \'\' $(MOSTLYCLEANDIRS); do \\\n'
1164 emit
+= '\t if test -n "$$dir" && test -d $$dir; then \\\n'
1165 emit
+= '\t echo "rmdir $$dir"; rmdir $$dir; \\\n'
1166 emit
+= '\t fi; \\\n'
1167 emit
+= '\tdone; \\\n'
1169 emit
= constants
.nlconvert(emit
)
1170 if type(emit
) is bytes
:
1171 emit
= emit
.decode(ENCS
['default'])
1172 result
= tuple([emit
, uses_subdirs
])