[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
FYI: per-target _CPPFLAGS (PR/337)
From: |
Alexandre Duret-Lutz |
Subject: |
FYI: per-target _CPPFLAGS (PR/337) |
Date: |
11 Jul 2002 21:21:15 +0200 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 |
I was trying to implement `-Wgnu' and warn about definitions of
CFLAGS, CPPFLAGS, etc., when it occured to me I needed a way to
decide whether CPPFLAGS was required by the languages currently
in use. Fixing PR/337 seems a good way to answer this, since
CPPFLAGS is now listed in $lang->flags when it is used.
Here is what I plan to commit once `make check' has finished.
2002-07-11 Alexandre Duret-Lutz <address@hidden>
Fix for PR automake/337:
* automake.in: Redefine the `flags' attribute of each language
as a list. List CPPFLAGS in `flags' when it is used.
(register_language): Set the default value of 'flags'.
(handle_single_transform_list): Adjust to treat `flags' as a list.
(handle_languages): Likewise. Don't bother defining the
configure variable for `c', this is always done since we trace
configure.ac.
* automake.texi (etags): Use per-executable _CPPFLAGS.
(Program and Library Variables): Mention maude_CPPFLAGS.
(Program variables): Likewise.
* tests/specflags8.test: Use _CPPFLAGS instead of _CFLAGS.
* tests/specflags9.test: New file.
* tests/Makefile.am (TESTS): Add specflag9.test.
Index: NEWS
===================================================================
RCS file: /cvs/automake/automake/NEWS,v
retrieving revision 1.184
diff -u -r1.184 NEWS
--- NEWS 9 Jul 2002 19:12:30 -0000 1.184
+++ NEWS 11 Jul 2002 19:18:59 -0000
@@ -1,4 +1,6 @@
New in 1.6a:
+* Support for per-program and per-library `_CPPFLAGS'.
+* New `ctags' target (builds CTAGS files).
* Support for -Wmumble and -Wno-mumble, where mumble is a warning category
(see `automake --help' or the manual for a list of them).
* Honor the WARNINGS environment variable.
Index: automake.in
===================================================================
RCS file: /cvs/automake/automake/automake.in,v
retrieving revision 1.1326
diff -u -r1.1326 automake.in
--- automake.in 10 Jul 2002 21:21:27 -0000 1.1326
+++ automake.in 11 Jul 2002 19:19:23 -0000
@@ -64,7 +64,9 @@
# the product given the input extensions.
# (defaults to a subroutine which returns ('.$(OBJEXT)', '.lo'))
'output_extensions' => "\$",
- 'flags' => "\$",
+ # A list of flag variables used in 'compile'.
+ # (defaults to [])
+ 'flags' => "@",
# The file to use when generating rules for this language.
# The default is 'depend2'.
@@ -876,7 +878,7 @@
'config_vars' => ['CC'],
'ansi' => 1,
'autodep' => '',
- 'flags' => 'CFLAGS',
+ 'flags' => ['CFLAGS', 'CPPFLAGS'],
'compiler' => 'COMPILE',
'compile' => '$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES)
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)',
'lder' => 'CCLD',
@@ -894,7 +896,7 @@
'linker' => 'CXXLINK',
'link' => '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS)
$(LDFLAGS) -o $@',
'autodep' => 'CXX',
- 'flags' => 'CXXFLAGS',
+ 'flags' => ['CXXFLAGS', 'CPPFLAGS'],
'compile' => '$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES)
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)',
'compiler' => 'CXXCOMPILE',
'compile_flag' => '-c',
@@ -911,7 +913,7 @@
'linker' => 'OBJCLINK',,
'link' => '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS)
$(AM_LDFLAGS) $(LDFLAGS) -o $@',
'autodep' => 'OBJC',
- 'flags' => 'OBJCFLAGS',
+ 'flags' => ['OBJCFLAGS', 'CPPFLAGS'],
'compile' => '$(OBJC) $(DEFS) $(DEFAULT_INCLUDES)
$(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)',
'compiler' => 'OBJCCOMPILE',
'compile_flag' => '-c',
@@ -935,7 +937,7 @@
register_language ('name' => 'yacc',
'Name' => 'Yacc',
'config_vars' => ['YACC'],
- 'flags' => 'YFLAGS',
+ 'flags' => ['YFLAGS'],
'compile' => '$(YACC) $(YFLAGS) $(AM_YFLAGS)',
'compiler' => 'YACCCOMPILE',
'extensions' => ['.y'],
@@ -948,7 +950,7 @@
'Name' => 'Yacc (C++)',
'config_vars' => ['YACC'],
'rule_file' => 'yacc',
- 'flags' => 'YFLAGS',
+ 'flags' => ['YFLAGS'],
'compiler' => 'YACCCOMPILE',
'compile' => '$(YACC) $(YFLAGS) $(AM_YFLAGS)',
'extensions' => ['.y++', '.yy', '.yxx', '.ypp'],
@@ -962,7 +964,7 @@
'Name' => 'Lex',
'config_vars' => ['LEX'],
'rule_file' => 'lex',
- 'flags' => 'LFLAGS',
+ 'flags' => ['LFLAGS'],
'compile' => '$(LEX) $(LFLAGS) $(AM_LFLAGS)',
'compiler' => 'LEXCOMPILE',
'extensions' => ['.l'],
@@ -974,7 +976,7 @@
'Name' => 'Lex (C++)',
'config_vars' => ['LEX'],
'rule_file' => 'lex',
- 'flags' => 'LFLAGS',
+ 'flags' => ['LFLAGS'],
'compile' => '$(LEX) $(LFLAGS) $(AM_LFLAGS)',
'compiler' => 'LEXCOMPILE',
'extensions' => ['.l++', '.ll', '.lxx', '.lpp'],
@@ -988,7 +990,7 @@
'Name' => 'Assembler',
'config_vars' => ['CCAS', 'CCASFLAGS'],
- 'flags' => 'CCASFLAGS',
+ 'flags' => ['CCASFLAGS'],
# Users can set AM_ASFLAGS to includes DEFS, INCLUDES,
# or anything else required. They can also set AS.
'compile' => '$(CCAS) $(AM_CCASFLAGS) $(CCASFLAGS)',
@@ -1004,7 +1006,7 @@
'Name' => 'Fortran 77',
'linker' => 'F77LINK',
'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS)
$(LDFLAGS) -o $@',
- 'flags' => 'FFLAGS',
+ 'flags' => ['FFLAGS'],
'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS)',
'compiler' => 'F77COMPILE',
'compile_flag' => '-c',
@@ -1036,7 +1038,7 @@
'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS)
$(LDFLAGS) -o $@',
'lder' => 'F77LD',
'ld' => '$(F77)',
- 'flags' => 'FFLAGS',
+ 'flags' => ['FFLAGS', 'CPPFLAGS'],
'compiler' => 'PPF77COMPILE',
'compile' => '$(F77) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES)
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)',
'compile_flag' => '-c',
@@ -1052,7 +1054,7 @@
'link' => '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS)
$(LDFLAGS) -o $@',
'lder' => 'F77LD',
'ld' => '$(F77)',
- 'flags' => 'RFLAGS',
+ 'flags' => ['RFLAGS', 'FFLAGS'],
# FIXME also FFLAGS.
'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS)
$(RFLAGS)',
'compiler' => 'RCOMPILE',
@@ -1068,7 +1070,7 @@
'linker' => 'GCJLINK',
'link' => '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS)
$(LDFLAGS) -o $@',
'autodep' => 'GCJ',
- 'flags' => 'GCJFLAGS',
+ 'flags' => ['GCJFLAGS'],
'compile' => '$(GCJ) $(AM_GCJFLAGS) $(GCJFLAGS)',
'compiler' => 'GCJCOMPILE',
'compile_flag' => '-c',
@@ -1974,7 +1976,7 @@
my $output_flag = $lang->output_flag || '';
$output_flag = '-o'
if (! $output_flag
- && $lang->flags eq 'CFLAGS'
+ && $lang->name eq 'c'
&& defined $options{'subdir-objects'});
# Compute a possible derived extension.
@@ -2024,14 +2026,21 @@
next if defined $seen_files{$obj};
$seen_files{$obj} = 1;
- my $flags = $lang->flags || '';
- my $val = "${derived}_${flags}";
-
prog_error ("found " . $lang->name .
" in handle_languages, but compiler not defined")
unless defined $lang->compile;
- (my $obj_compile = $lang->compile) =~ s/\(AM_$flags/\($val/;
+ my $obj_compile = $lang->compile;
+
+ # Rewrite each occurence of `AM_$flag' in the compile
+ # rule into `${derived}_$flag' if it exists.
+ for my $flag (@{$lang->flags})
+ {
+ my $val = "${derived}_$flag";
+ $obj_compile =~ s/\(AM_$flag\)/\($val\)/
+ if variable_defined ($val);
+ }
+
my $obj_ltcompile = '$(LIBTOOL) --mode=compile ' . $obj_compile;
# We _need_ `-o' for per object rules.
@@ -2106,11 +2115,8 @@
if ($needs_c)
{
- if (! defined $done{$languages{'c'}})
- {
- &define_configure_variable ($languages{'c'}->flags);
- &define_compiler_variable ($languages{'c'});
- }
+ &define_compiler_variable ($languages{'c'})
+ unless defined $done{$languages{'c'}};
define_linker_variable ($languages{'c'});
}
}
@@ -2254,8 +2260,18 @@
}
$object = $base . $this_obj_ext;
- if (defined $lang->flags
- && variable_defined ($derived . '_' . $lang->flags))
+ # Do we have per-executable flags for this executable?
+ my $have_per_exec_flags = 0;
+ foreach my $flag (@{$lang->flags})
+ {
+ if (variable_defined ("${derived}_$flag"))
+ {
+ $have_per_exec_flags = 1;
+ last;
+ }
+ }
+
+ if ($have_per_exec_flags)
{
# We have a per-executable flag in effect for this
# object. In this case we rewrite the object's
@@ -5508,6 +5524,8 @@
unless defined $option{'autodep'};
$option{'linker'} = ''
unless defined $option{'linker'};
+ $option{'flags'} = []
+ unless defined $option{'flags'};
$option{'output_extensions'} = sub { return ( '.$(OBJEXT)', '.lo' ) }
unless defined $option{'output_extensions'};
Index: automake.texi
===================================================================
RCS file: /cvs/automake/automake/automake.texi,v
retrieving revision 1.288
diff -u -r1.288 automake.texi
--- automake.texi 10 Jul 2002 21:21:27 -0000 1.288
+++ automake.texi 11 Jul 2002 19:19:40 -0000
@@ -868,10 +868,10 @@
bin_PROGRAMS = ctags etags
ctags_SOURCES = etags.c
-ctags_CFLAGS = -DCTAGS
+ctags_CPPFLAGS = -DCTAGS
etags_SOURCES = etags.c
-etags_CFLAGS = -DETAGS_REGEXPS
+etags_CPPFLAGS = -DETAGS_REGEXPS
@end example
In this case Automake will cause @file{etags.c} to be compiled twice,
@@ -2320,14 +2320,31 @@
maude_LINK = $(CCLD) -magic -o $@@
@end example
address@hidden maude_CFLAGS
address@hidden maude_CCASFLAGS
address@hidden maude_CFLAGS
address@hidden maude_CPPFLAGS
address@hidden maude_CXXFLAGS
address@hidden maude_FFLAGS
address@hidden maude_GCJFLAGS
address@hidden maude_LFLAGS
address@hidden maude_OBJCFLAGS
address@hidden maude_RFLAGS
address@hidden maude_YFLAGS
Automake allows you to set compilation flags on a per-program (or
per-library) basis. A single source file can be included in several
programs, and it will potentially be compiled with different flags for
each program. This works for any language directly supported by
-Automake. The flags are @samp{_CFLAGS}, @samp{_CXXFLAGS},
address@hidden, @samp{_LFLAGS}, @samp{_YFLAGS}, @samp{_CCASFLAGS},
address@hidden, @samp{_RFLAGS}, and @samp{_GCJFLAGS}.
+Automake. The flags are
address@hidden,
address@hidden,
address@hidden,
address@hidden,
address@hidden,
address@hidden,
address@hidden,
address@hidden,
address@hidden, and
address@hidden
When using a per-program compilation flag, Automake will choose a
different name for the intermediate object files. Ordinarily a file
@@ -2345,6 +2362,7 @@
maude_CFLAGS = @dots{} your flags @dots{} $(AM_CFLAGS)
@end example
+
@item maude_DEPENDENCIES
It is also occasionally useful to have a program depend on some other
target which is not actually part of that program. This can be done
@@ -2419,6 +2437,9 @@
pointing to the directory holding @file{config.h} (if you've used
@code{AC_CONFIG_HEADERS} or @code{AM_CONFIG_HEADER}). You can disable
the default @samp{-I} options using the @samp{nostdinc} option.
+
address@hidden is ignored in preference to a per-executable (or
+per-library) @code{_CPPFLAGS} variable if it is defined.
@item INCLUDES
This does the same job as @samp{AM_CPPFLAGS}. It is an older name for
Index: tests/Makefile.am
===================================================================
RCS file: /cvs/automake/automake/tests/Makefile.am,v
retrieving revision 1.415
diff -u -r1.415 Makefile.am
--- tests/Makefile.am 10 Jul 2002 20:30:24 -0000 1.415
+++ tests/Makefile.am 11 Jul 2002 19:19:41 -0000
@@ -320,6 +320,7 @@
specflags6.test \
specflags7.test \
specflags8.test \
+specflags9.test \
spell.test \
spell2.test \
spell3.test \
Index: tests/specflags8.test
===================================================================
RCS file: /cvs/automake/automake/tests/specflags8.test,v
retrieving revision 1.4
diff -u -r1.4 specflags8.test
--- tests/specflags8.test 19 Jun 2002 18:31:37 -0000 1.4
+++ tests/specflags8.test 11 Jul 2002 19:19:42 -0000
@@ -1,8 +1,8 @@
#! /bin/sh
# Like the ctags/etags example from the manual,
-# with one extra indirection in the sources.
-# PR 315.
+# with one extra indirection in the sources (PR/315), and
+# use of _CPPFLAGS (PR/337).
required=gcc
. $srcdir/defs || exit 1
@@ -22,9 +22,9 @@
ETAGSSOURCE = etags.c
bin_PROGRAMS = etags ctags
ctags_SOURCES = $(ETAGSSOURCE)
-ctags_CFLAGS = -DCTAGS
+ctags_CPPFLAGS = -DCTAGS
etags_SOURCES = $(ETAGSSOURCE)
-etags_CFLAGS = -DETAGS
+etags_CPPFLAGS = -DETAGS
END
cat > etags.c << 'END'
Index: tests/specflags9.test
===================================================================
RCS file: tests/specflags9.test
diff -N tests/specflags9.test
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/specflags9.test 11 Jul 2002 19:19:42 -0000
@@ -0,0 +1,32 @@
+#! /bin/sh
+
+# Another check for per-target flag substitutions.
+
+. $srcdir/defs || exit 1
+
+set -e
+
+cat >> configure.in << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = zzfoo zzbar
+zzfoo_SOURCES = sub/foo.c
+zzbar_SOURCES = bar.c
+zzbar_CPPFLAGS = -Dfoo
+END
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+
+$FGREP '$(AM_CFLAGS)' Makefile.in
+
+$FGREP '$(zzfoo_CFLAGS)' Makefile.in && exit 1
+$FGREP '$(zzfoo_CPPFLAGS)' Makefile.in && exit 1
+
+$FGREP '$(zzbar_CFLAGS)' Makefile.in && exit 1
+$FGREP '$(zzbar_CPPFLAGS)' Makefile.in
+
+:
--
Alexandre Duret-Lutz
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- FYI: per-target _CPPFLAGS (PR/337),
Alexandre Duret-Lutz <=