Conditionally adding sources in automake-files

Conditionally adding sources in automake-files

Post by Georg Ach » Mon, 10 Sep 2001 22:59:43



Hi,
I'm currently struggling with an automakefile-problem. Depending on a flag set
during configure, I want to use different additional sources for compilation.
Currently I use this in makefile.am:

if FLAG1
        program_SOURCES= a.c b.c c.c
else
        program_SOURCES= a.c b.c d.c
endif

But I have a lot of flags, thus I have to code every possible combination of
sources, which is not fun... I tried to use previously defined variables
etc. in the program_SOURCES statement, but they are not substituted by
automake. How can I solve that?

Thanks...
--

         http://www.in.tum.de/~acher/
          "Oh no, not again !" The bowl of petunias          

 
 
 

Conditionally adding sources in automake-files

Post by Wolfram Gloge » Tue, 11 Sep 2001 21:53:53



> I'm currently struggling with an automakefile-problem. Depending on a flag set
> during configure, I want to use different additional sources for compilation.
> Currently I use this in makefile.am:

> if FLAG1
>         program_SOURCES= a.c b.c c.c
> else
>         program_SOURCES= a.c b.c d.c
> endif

> But I have a lot of flags, thus I have to code every possible combination of
> sources, which is not fun... I tried to use previously defined variables
> etc. in the program_SOURCES statement, but they are not substituted by
> automake. How can I solve that?

Why not let make itself do the work, which does substitute previously
defined vars?  I.e. for the above

if FLAG1
        FLAG1_SOURCES = c.c
else
        FLAG1_SOURCES = d.c
endif
program_SOURCES = a.c b.c $(FLAG1_SOURCES)

Regards,
Wolfram.

 
 
 

Conditionally adding sources in automake-files

Post by Georg Ach » Tue, 11 Sep 2001 22:24:02




|> Why not let make itself do the work, which does substitute previously
|> defined vars?  I.e. for the above
|>
|> if FLAG1
|>   FLAG1_SOURCES = c.c
|> else
|>   FLAG1_SOURCES = d.c
|> endif
|> program_SOURCES = a.c b.c $(FLAG1_SOURCES)

The problem lies in automake (or elsewhere). The .c-filenames in program_SOURCES
are rewritten to .o-depencies, but that action seems to ignore any conditionally
defined variables in the file list. Variables without conditions work...  Then
the resulting object list (*_OBJECTS) in the makefile simply misses the files in
the variables. Of course I can put common files in variables and conditionnaly
set the _SOURCES, but that still requires all combinations...

--

         http://www.in.tum.de/~acher/
          "Oh no, not again !" The bowl of petunias          

 
 
 

Conditionally adding sources in automake-files

Post by Tom Trome » Thu, 13 Sep 2001 06:18:16


Georg> I'm currently struggling with an
Georg> automakefile-problem. Depending on a flag set during configure,
Georg> I want to use different additional sources for compilation.

What version of automake are you using?

Georg> if FLAG1
Georg>         program_SOURCES= a.c b.c c.c
Georg> else
Georg>         program_SOURCES= a.c b.c d.c
Georg> endif

Georg> But I have a lot of flags, thus I have to code every possible
Georg> combination of sources, which is not fun...

There are a few ways around this.  Unfortunately in automake 1.4 they
aren't very obvious.  I believe things are better in 1.5.  That is why
the version number is important.

One way is to introduce a new variable for each flag:

    if FLAG1
    flag1s = a.c
    endif

    program_SOURCES = $(flag1s) $(flag2s) ...

Another way is to do the work in configure.  This requires a bit more
strangeness in your Makefile.am.

Tom

 
 
 

Conditionally adding sources in automake-files

Post by Georg Ach » Thu, 13 Sep 2001 07:27:36




<automake-problem>
|> What version of automake are you using?

1.4 (seems to be standard...)

|> One way is to introduce a new variable for each flag:
|>
|>     if FLAG1
|>     flag1s = a.c
|>     endif
|>
|>     program_SOURCES = $(flag1s) $(flag2s) ...

That's the thing I've tried first, but as said in another post, the if'ed
variables are not substituted as objects in the resulting makefile... Smells
like a bug...

|> Another way is to do the work in configure.  This requires a bit more
|> strangeness in your Makefile.am.

I will investigate this (and try v1.5)
--

         http://www.in.tum.de/~acher/
          "Oh no, not again !" The bowl of petunias          

 
 
 

Conditionally adding sources in automake-files

Post by Wolfram Gloge » Thu, 13 Sep 2001 19:02:46





> |> Why not let make itself do the work, which does substitute previously
> |> defined vars?  I.e. for the above
> |>
> |> if FLAG1
> |>      FLAG1_SOURCES = c.c
> |> else
> |>      FLAG1_SOURCES = d.c
> |> endif
> |> program_SOURCES = a.c b.c $(FLAG1_SOURCES)

> The problem lies in automake (or elsewhere). The .c-filenames in program_SOURCES
> are rewritten to .o-depencies,

How 'rewritten'?  I'm lost here, you should include whatever is
involved in that 'rewriting' in your example.

Quote:> the resulting object list (*_OBJECTS) in the makefile simply misses the files in
> the variables.

How is *_OBJECTS defined?  Maybe try:

program_OBJECTS = $(program_SOURCES:%.c=%.o)

Regards,
Wolfram.

 
 
 

Conditionally adding sources in automake-files

Post by Roger Leig » Thu, 13 Sep 2001 20:05:02





> |> Why not let make itself do the work, which does substitute previously
> |> defined vars?  I.e. for the above
> |>
> |> if FLAG1
> |>      FLAG1_SOURCES = c.c
> |> else
> |>      FLAG1_SOURCES = d.c
> |> endif
> |> program_SOURCES = a.c b.c $(FLAG1_SOURCES)

> The problem lies in automake (or elsewhere). The .c-filenames in
> program_SOURCES are rewritten to .o-depencies, but that action seems
> to ignore any conditionally defined variables in the file
> list. Variables without conditions work...  Then the resulting
> object list (*_OBJECTS) in the makefile simply misses the files in
> the variables. Of course I can put common files in variables and
> conditionnaly set the _SOURCES, but that still requires all
> combinations...

Conditionally compiling with automake is not perfect yet.  I would
suggest that you do this:


EXTRA_program_SOURCES = file3a.c file3b.c file3c.c

You have to AC_SUBST(EXTRA_PROGRAM_FILES) in configure.ac, and define
what extra source files need compiling in this variable.  This is not
too great, as it means that logic that should be in the Makefile goes
in configure.ac, making it overly complex.  Last time I tried, I
couldn't use make macros in automake declarations e.g.:

program_SOURCES = file1.c file2.c $(EXTRA_PROGRAM_FILES)

I found a horrible hack to get around this.

EXTRA_program_SOURCES = file3a.c file3b.c file3c.c

in configure.ac:
if ... ; then
  EXTRA_PROGRAM_FILES="\$(EXTRA_program_SOURCES)"
fi

However, this is dependent on the order of definitions in the
Makefile, and is again overly complex, but does move some logic out of
configure.ac.

Automake 1.5 is now out.  I have not tried it yet, but it is possible
these issues have been fixed.  They are only due to automake being too
picky when parsing Makefile.am, although I'm sure there were valid
reasons for making it so.

Regards,
Roger

--
Roger Leigh ** Registration Number: 151826, http://counter.li.org **
Need Epson Stylus Utilities? http://gimp-print.sourceforge.net/

 
 
 

1. automake: adding new file type

Hi all,

I have no idea how to add new dependency (file extention is .b, e.g.
file.b), which depends on C++ header file file.h, in Makefile.am?

For example, file.b depends on file.h and the suffix rule is as follows:

        >.h.b:

File extention ".b" should be new for Automake so that I added the
following at the top of Makefile.am:

        >SUFFIXES = .b

Any othe related is as follows:

        >bin_PROGRAMS        = x
        >x_SOURCES   = main.cpp file.h file.b

main.cpp includes file.h and file.h includes file.b.

Unfortunately, when I run "make", at the compiling main.cpp, it failes
because file.b doesn't exist.  file.b should be generated by bgen
as I tried to define at suffix rule.

Could anyone help me why?

Best Regards,
Wells

2. shapecfg.c - traffic shaper source code location

3. automake : how to tell make to recompile a source file

4. IP Masquerading and pop3/ftp bigger then 30k

5. hacking bash to source conditionally

6. Problem w/Buslogic and 4mm DAT?

7. Errors compiling Wingz 1.4 Add-ins (Linux 1.3.99, GCC 2.6)

8. X + xload = X Freeze Up ?!

9. Communicator dies on add-ins

10. Wingz add-ins - how to write

11. adding comments to source file during sccs get

12. automake/autoconf: linking object files built with different compilers

13. automake and shared files