automake: Renamed Objects

1 
1 27.7 Why are object files sometimes renamed?
1 ============================================
1 
1 This happens when per-target compilation flags are used.  Object files
1 need to be renamed just in case they would clash with object files
1 compiled from the same sources, but with different flags.  Consider the
1 following example.
1 
1      bin_PROGRAMS = true false
1      true_SOURCES = generic.c
1      true_CPPFLAGS = -DEXIT_CODE=0
1      false_SOURCES = generic.c
1      false_CPPFLAGS = -DEXIT_CODE=1
1 
1 Obviously the two programs are built from the same source, but it would
1 be bad if they shared the same object, because ‘generic.o’ cannot be
1 built with both ‘-DEXIT_CODE=0’ _and_ ‘-DEXIT_CODE=1’.  Therefore
1 ‘automake’ outputs rules to build two different objects:
1 ‘true-generic.o’ and ‘false-generic.o’.
1 
1    ‘automake’ doesn’t actually look whether source files are shared to
1 decide if it must rename objects.  It will just rename all objects of a
1 target as soon as it sees per-target compilation flags used.
1 
1    It’s OK to share object files when per-target compilation flags are
1 not used.  For instance, ‘true’ and ‘false’ will both use ‘version.o’ in
1 the following example.
1 
1      AM_CPPFLAGS = -DVERSION=1.0
1      bin_PROGRAMS = true false
1      true_SOURCES = true.c version.c
1      false_SOURCES = false.c version.c
1 
1    Note that the renaming of objects is also affected by the
1 ‘_SHORTNAME’ variable (⇒Program and Library Variables).
1