cee31991b0dcd2addc104f42f4bda2542fae2af0
[platform/upstream/automake.git] / m4 / depend.m4
1 ##                                                          -*- Autoconf -*-
2 # Copyright (C) 1999-2012 Free Software Foundation, Inc.
3 #
4 # This file is free software; the Free Software Foundation
5 # gives unlimited permission to copy and/or distribute it,
6 # with or without modifications, as long as this notice is preserved.
7
8 # serial 17
9
10 # There are a few dirty hacks below to avoid letting 'AC_PROG_CC' be
11 # written in clear, in which case automake, when reading aclocal.m4,
12 # will think it sees a *use*, and therefore will trigger all it's
13 # C support machinery.  Also note that it means that autoscan, seeing
14 # CC etc. in the Makefile, will ask for an AC_PROG_CC use...
15
16
17 # _AM_DEPENDENCIES(NAME)
18 # ----------------------
19 # See how the compiler implements dependency checking.
20 # NAME is "CC", "CXX", "OBJC", "OBJCXX", "UPC", or "GJC".
21 # We try a few techniques and use that to set a single cache variable.
22 #
23 # We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was
24 # modified to invoke _AM_DEPENDENCIES(CC); we would have a circular
25 # dependency, and given that the user is not expected to run this macro,
26 # just rely on AC_PROG_CC.
27 AC_DEFUN([_AM_DEPENDENCIES],
28 [AC_REQUIRE([AM_SET_DEPDIR])dnl
29 AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl
30 AC_REQUIRE([AM_MAKE_INCLUDE])dnl
31 AC_REQUIRE([AM_DEP_TRACK])dnl
32
33 m4_if([$1], [CC],   [depcc="$CC"   am_compiler_list=],
34       [$1], [CXX],  [depcc="$CXX"  am_compiler_list=],
35       [$1], [OBJC], [depcc="$OBJC" am_compiler_list='gcc3 gcc'],
36       [$1], [OBJCXX], [depcc="$OBJCXX" am_compiler_list='gcc3 gcc'],
37       [$1], [UPC],  [depcc="$UPC"  am_compiler_list=],
38       [$1], [GCJ],  [depcc="$GCJ"  am_compiler_list='gcc3 gcc'],
39                     [depcc="$$1"   am_compiler_list=])
40
41 AC_CACHE_CHECK([dependency style of $depcc],
42                [am_cv_$1_dependencies_compiler_type],
43 [if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then
44   # We make a subdir and do the tests there.  Otherwise we can end up
45   # making bogus files that we don't know about and never remove.  For
46   # instance it was reported that on HP-UX the gcc test will end up
47   # making a dummy file named 'D' -- because '-MD' means "put the output
48   # in D".
49   rm -rf conftest.dir
50   mkdir conftest.dir
51   # Copy depcomp to subdir because otherwise we won't find it if we're
52   # using a relative directory.
53   cp "$am_depcomp" conftest.dir
54   cd conftest.dir
55   # We will build objects and dependencies in a subdirectory because
56   # it helps to detect inapplicable dependency modes.  For instance
57   # both Tru64's cc and ICC support -MD to output dependencies as a
58   # side effect of compilation, but ICC will put the dependencies in
59   # the current directory while Tru64 will put them in the object
60   # directory.
61   mkdir sub
62
63   am_cv_$1_dependencies_compiler_type=none
64   if test "$am_compiler_list" = ""; then
65      am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp`
66   fi
67   am__universal=false
68   m4_case([$1], [CC],
69     [case " $depcc " in #(
70      *\ -arch\ *\ -arch\ *) am__universal=true ;;
71      esac],
72     [CXX],
73     [case " $depcc " in #(
74      *\ -arch\ *\ -arch\ *) am__universal=true ;;
75      esac])
76
77   for depmode in $am_compiler_list; do
78     # Setup a source with many dependencies, because some compilers
79     # like to wrap large dependency lists on column 80 (with \), and
80     # we should not choose a depcomp mode which is confused by this.
81     #
82     # We need to recreate these files for each test, as the compiler may
83     # overwrite some of them when testing with obscure command lines.
84     # This happens at least with the AIX C compiler.
85     : > sub/conftest.c
86     for i in 1 2 3 4 5 6; do
87       echo '#include "conftst'$i'.h"' >> sub/conftest.c
88       # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with
89       # Solaris 10 /bin/sh.
90       echo '/* dummy */' > sub/conftst$i.h
91     done
92     echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
93
94     # We check with '-c' and '-o' for the sake of the "dashmstdout"
95     # mode.  It turns out that the SunPro C++ compiler does not properly
96     # handle '-M -o', and we need to detect this.  Also, some Intel
97     # versions had trouble with output in subdirs.
98     am__obj=sub/conftest.${OBJEXT-o}
99     am__minus_obj="-o $am__obj"
100     case $depmode in
101     gcc)
102       # This depmode causes a compiler race in universal mode.
103       test "$am__universal" = false || continue
104       ;;
105     nosideeffect)
106       # After this tag, mechanisms are not by side-effect, so they'll
107       # only be used when explicitly requested.
108       if test "x$enable_dependency_tracking" = xyes; then
109         continue
110       else
111         break
112       fi
113       ;;
114     msvc7 | msvc7msys | msvisualcpp | msvcmsys)
115       # This compiler won't grok '-c -o', but also, the minuso test has
116       # not run yet.  These depmodes are late enough in the game, and
117       # so weak that their functioning should not be impacted.
118       am__obj=conftest.${OBJEXT-o}
119       am__minus_obj=
120       ;;
121     none) break ;;
122     esac
123     if depmode=$depmode \
124        source=sub/conftest.c object=$am__obj \
125        depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \
126        $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \
127          >/dev/null 2>conftest.err &&
128        grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 &&
129        grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 &&
130        grep $am__obj sub/conftest.Po > /dev/null 2>&1 &&
131        ${MAKE-make} -s -f confmf > /dev/null 2>&1; then
132       # icc doesn't choke on unknown options, it will just issue warnings
133       # or remarks (even with -Werror).  So we grep stderr for any message
134       # that says an option was ignored or not supported.
135       # When given -MP, icc 7.0 and 7.1 complain thusly:
136       #   icc: Command line warning: ignoring option '-M'; no argument required
137       # The diagnosis changed in icc 8.0:
138       #   icc: Command line remark: option '-MP' not supported
139       if (grep 'ignoring option' conftest.err ||
140           grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else
141         am_cv_$1_dependencies_compiler_type=$depmode
142         break
143       fi
144     fi
145   done
146
147   cd ..
148   rm -rf conftest.dir
149 else
150   am_cv_$1_dependencies_compiler_type=none
151 fi
152 ])
153 AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type])
154 AM_CONDITIONAL([am__fastdep$1], [
155   test "x$enable_dependency_tracking" != xno \
156   && test "$am_cv_$1_dependencies_compiler_type" = gcc3])
157 ])
158
159
160 # AM_SET_DEPDIR
161 # -------------
162 # Choose a directory name for dependency files.
163 # This macro is AC_REQUIREd in _AM_DEPENDENCIES.
164 AC_DEFUN([AM_SET_DEPDIR],
165 [AC_REQUIRE([AM_SET_LEADING_DOT])dnl
166 AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl
167 ])
168
169
170 # AM_DEP_TRACK
171 # ------------
172 AC_DEFUN([AM_DEP_TRACK],
173 [AC_ARG_ENABLE([dependency-tracking], [dnl
174 AS_HELP_STRING(
175   [--enable-dependency-tracking],
176   [do not reject slow dependency extractors])
177 AS_HELP_STRING(
178   [--disable-dependency-tracking],
179   [speeds up one-time build])])
180 if test "x$enable_dependency_tracking" != xno; then
181   am_depcomp="$ac_aux_dir/depcomp"
182   AMDEPBACKSLASH='\'
183   am__nodep='_no'
184 fi
185 AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno])
186 AC_SUBST([AMDEPBACKSLASH])dnl
187 _AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl
188 AC_SUBST([am__nodep])dnl
189 _AM_SUBST_NOTMAKE([am__nodep])dnl
190 ])