automake
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Portable $addprefix


From: Quinn Grier
Subject: Re: Portable $addprefix
Date: Fri, 1 Sep 2017 20:27:02 -0700
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0

On 2017-09-01 17:34, Kip Warner wrote:
> On Mon, 2017-08-28 at 11:03 -0700, Quinn Grier wrote:
>> A portable way to do this is to do the work in configure.ac and
>> transfer
>> it to the Makefile with AC_SUBST. For example, with an empty
>> Makefile.am
>> and the following configure.ac:
>>
>>       AC_INIT([Example], [1.0])
>>       AM_INIT_AUTOMAKE([foreign])
>>
>>       m4_define([m_files_only], [a.foo b.foo c.foo])
>>       files_only='m_files_only'
>>       files_with_path='m4_map_args_w(m_files_only, [dir/], [], [ ])'
>>       AC_SUBST([files_only])
>>       AC_SUBST([files_with_path])
>>
>>       AC_CONFIG_FILES([Makefile])
>>       AC_OUTPUT
>>
>> The desired macros will appear in the resulting Makefile:
>>
>>       files_only = a.foo b.foo c.foo
>>       files_with_path = dir/a.foo dir/b.foo dir/c.foo
> 
> Hey Quinn. This would have worked perfectly, except automake bails when
> I run autoreconf:
> 
>     autoreconf: running: automake --add-missing --copy --no-force
>     configure.ac:310: error: 'parser_clobbered_source_full_paths' includes 
> configure substitution     '@parser    _clobbered_source_full_paths@'
>     configure.ac:310: and is referred to from 
> 'nodist_narayan_designer_SOURCES';
>     configure.ac:310: configure substitutions are not allowed in _SOURCES 
> variables
>     autoreconf: automake failed with exit status: 1
> 
> This is likely because as the message says, I am attempting to use the
> substitution within a *_SOURCES variable.
> 
> Is this a dead end or is there a workaround? Assume a reference within
> a _SOURCES variable is probably necessary.
> 

You can fix this by generating the complete macro definitions before
Automake runs and including them in Makefile.am.

One way you can do this is with a shell script that you must run before
autoreconf. For example:

      files_only='a.foo b.foo c.foo'
      files_path='dir/'
      files_with_path=
      for f in $files_only; do
        files_with_path=$files_with_path\ $files_path$f
      done
      echo files_only = \
        $files_only >files_only.am || exit 1
      echo files_with_path = \
        $files_with_path >files_with_path.am || exit 1

And, inside Makefile.am, you add these lines:

      include files_only.am
      include files_with_path.am

This is a natural fit if you're already using an autogen.sh script, as
you can put this code in there. If you're not using one, then this would
essentially force you to start using one, as you need to remember to run
this code before autoreconf.

Another idea is to generate the .am files in configure.ac at M4 time,
which should cause autoreconf to generate them before it runs Automake.
In this case, an autogen.sh script is unnecessary.

Here is an example configure.ac that does this:

      AC_INIT([Example], [1.0])
      AM_INIT_AUTOMAKE([foreign])
      AC_PROG_CC

      m4_define([m_files_only], [[a.foo b.foo c.foo]])
      m4_define([m_files_path], [[[dir/]]])
      m4_define([m_files_with_path],
                m4_dquote(m4_map_args_w(m_files_only,
                                        m_files_path, [], [ ])))
      m4_syscmd([echo files_only = ]dnl
                m_files_only[ >files_only.am])
      m4_assert(m4_sysval[ == 0])
      m4_syscmd([echo files_with_path = ]dnl
                m_files_with_path[ >files_with_path.am])
      m4_assert(m4_sysval[ == 0])

      AC_CONFIG_FILES([Makefile])
      AC_OUTPUT

And here is the accompanying example Makefile.am:

      include files_only.am
      include files_with_path.am
      bin_PROGRAMS = foo
      foo_SOURCES = foo.c $(files_with_path)

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]