]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Support dependency generation with some non-GCC compilers.
authorGuy Harris <[email protected]>
Wed, 8 May 2013 07:08:12 +0000 (00:08 -0700)
committerGuy Harris <[email protected]>
Wed, 8 May 2013 07:08:12 +0000 (00:08 -0700)
Also, if we don't support it with a given compiler, have "make depend"
not run mkdep, as it won't do anything useful.

Makefile.in
aclocal.m4
configure
mkdep

index ee27e105fa5e3fbbca0daf1f8fac46a9b1a764d3..230aa35c930f2cd32a5d1e1e898f3ae5cb862a88 100644 (file)
@@ -41,6 +41,7 @@ VPATH = @srcdir@
 #
 
 CC = @CC@
+MKDEP = @MKDEP@
 PROG = tcpdump
 CCOPT = @V_CCOPT@
 INCLS = -I. @V_INCLS@
@@ -61,6 +62,8 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@
 INSTALL_DATA = @INSTALL_DATA@
 RANLIB = @RANLIB@
 
+DEPENDENCY_CFLAG = @DEPENDENCY_CFLAG@
+
 # Explicitly define compilation rule since SunOS 4's make doesn't like gcc.
 # Also, gcc does not remove the .o before forking 'as', which can be a
 # problem if you don't own the file but can write to the directory.
@@ -369,4 +372,4 @@ testlist:
        echo $(TEST_DIST)
 
 depend: $(GENSRC)
-       ${srcdir}/mkdep -c $(CC) $(DEFS) $(INCLS) $(SRC)
+       $(MKDEP) -c $(CC) -m $(DEPENDENCY_CFLAG) $(DEFS) $(INCLS) $(SRC)
index b8128396fb973dfe0172267b236222a7ebbbccb4..131283be6c220857704d00a4ef4162885a0b7881 100644 (file)
@@ -264,6 +264,119 @@ AC_DEFUN(AC_LBL_CHECK_COMPILER_OPT,
            ])
     ])
 
+dnl
+dnl Check whether the compiler supports an option to generate
+dnl Makefile-style dependency lines
+dnl
+dnl GCC uses -M for this.  Non-GCC compilers that support this
+dnl use a variety of flags, including but not limited to -M.
+dnl
+dnl We test whether the flag in question is supported, as older
+dnl versions of compilers might not support it.
+dnl
+dnl We don't try all the possible flags, just in case some flag means
+dnl "generate dependencies" on one compiler but means something else
+dnl on another compiler.
+dnl
+dnl Most compilers that support this send the output to the standard
+dnl output by default.  IBM's XLC, however, supports -M but sends
+dnl the output to {sourcefile-basename}.u, and AIX has no /dev/stdout
+dnl to work around that, so we don't bother with XLC.
+dnl
+AC_DEFUN(AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT,
+    [
+       AC_MSG_CHECKING([whether the compiler supports generating dependencies])
+       if test "$GCC" = yes ; then
+               #
+               # GCC, or a compiler deemed to be GCC by AC_PROG_CC (even
+               # though it's not); we assume that, in this case, the flag
+               # would be -M.
+               #
+               ac_lbl_dependency_flag="-M"
+       else
+               #
+               # Not GCC or a compiler deemed to be GCC; what platform is
+               # this?  (We're assuming that if the compiler isn't GCC
+               # it's the compiler from the vendor of the OS; that won't
+               # necessarily be true for x86 platforms, where it might be
+               # the Intel C compiler.)
+               #
+               case "$host_os" in
+
+               irix*|osf*|darwin*)
+                       #
+                       # MIPS C for IRIX, DEC C, and clang all use -M.
+                       #
+                       ac_lbl_dependency_flag="-M"
+                       ;;
+
+               solaris*)
+                       #
+                       # Sun C uses -xM.
+                       #
+                       ac_lbl_dependency_flag="-xM"
+                       ;;
+
+               hpux*)
+                       #
+                       # HP's older C compilers don't support this.
+                       # HP's newer C compilers support this with
+                       # either +M or +Make; the older compilers
+                       # interpret +M as something completely
+                       # different, so we use +Make so we don't
+                       # think it works with the older compilers.
+                       #
+                       ac_lbl_dependency_flag="+Make"
+                       ;;
+
+               *)
+                       #
+                       # Not one of the above; assume no support for
+                       # generating dependencies.
+                       #
+                       ac_lbl_dependency_flag=""
+                       ;;
+               esac
+       fi
+
+       #
+       # Is ac_lbl_dependency_flag defined and, if so, does the compiler
+       # complain about it?
+       #
+       # Note: clang doesn't seem to exit with an error status when handed
+       # an unknown non-warning error, even if you pass it
+       # -Werror=unknown-warning-option.  However, it always supports
+       # -M, so the fact that this test always succeeds with clang
+       # isn't an issue.
+       #
+       if test ! -z "$ac_lbl_dependency_flag"; then
+               AC_LANG_CONFTEST(
+                   [AC_LANG_SOURCE([[int main(void) { return 0; }]])])
+               echo "$CC" $ac_lbl_dependency_flag conftest.c >&5
+               if "$CC" $ac_lbl_dependency_flag conftest.c >/dev/null 2>&1; then
+                       AC_MSG_RESULT([yes, with $ac_lbl_dependency_flag])
+                       DEPENDENCY_CFLAG="$ac_lbl_dependency_flag"
+                       MKDEP='${srcdir}/mkdep'
+               else
+                       AC_MSG_RESULT([no])
+                       #
+                       # We can't run mkdep, so have "make depend" do
+                       # nothing.
+                       #
+                       MKDEP=:
+               fi
+               rm -rf conftest*
+       else
+               AC_MSG_RESULT([no])
+               #
+               # We can't run mkdep, so have "make depend" do
+               # nothing.
+               #
+               MKDEP=:
+       fi
+       AC_SUBST(DEPENDENCY_CFLAG MKDEP)
+    ])
+
 #
 # Try compiling a sample of the type of code that appears in
 # gencode.c with "inline", "__inline__", and "__inline".
@@ -894,6 +1007,7 @@ AC_DEFUN(AC_LBL_DEVEL,
                    AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-arith)
                    AC_LBL_CHECK_COMPILER_OPT($1, -W)
            fi
+           AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT()
            if test "$GCC" = yes ; then
                    if test "${LBL_CFLAGS+set}" != set; then
                            if test "$ac_cv_prog_cc_g" = yes ; then
index 014eca66f78067afce5cedc4a249c3ea274f626b..68af1c33324a84b26d3ca376ba9956d76c9a5a59 100755 (executable)
--- a/configure
+++ b/configure
@@ -673,6 +673,7 @@ EGREP
 LIBOBJS
 PCAP_CONFIG
 RANLIB
+DEPENDENCY_CFLAG MKDEP
 V_CCOPT
 V_DEFS
 V_GROUP
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
            fi
+
+       { echo "$as_me:$LINENO: checking whether the compiler supports generating dependencies" >&5
+echo $ECHO_N "checking whether the compiler supports generating dependencies... $ECHO_C" >&6; }
+       if test "$GCC" = yes ; then
+               #
+               # GCC, or a compiler deemed to be GCC by AC_PROG_CC (even
+               # though it's not); we assume that, in this case, the flag
+               # would be -M.
+               #
+               ac_lbl_dependency_flag="-M"
+       else
+               #
+               # Not GCC or a compiler deemed to be GCC; what platform is
+               # this?  (We're assuming that if the compiler isn't GCC
+               # it's the compiler from the vendor of the OS; that won't
+               # necessarily be true for x86 platforms, where it might be
+               # the Intel C compiler.)
+               #
+               case "$host_os" in
+
+               irix*|osf*|darwin*)
+                       #
+                       # MIPS C for IRIX, DEC C, and clang all use -M.
+                       #
+                       ac_lbl_dependency_flag="-M"
+                       ;;
+
+               solaris*)
+                       #
+                       # Sun C uses -xM.
+                       #
+                       ac_lbl_dependency_flag="-xM"
+                       ;;
+
+               hpux*)
+                       #
+                       # HP's older C compilers don't support this.
+                       # HP's newer C compilers support this with
+                       # either +M or +Make; the older compilers
+                       # interpret +M as something completely
+                       # different, so we use +Make so we don't
+                       # think it works with the older compilers.
+                       #
+                       ac_lbl_dependency_flag="+Make"
+                       ;;
+
+               *)
+                       #
+                       # Not one of the above; assume no support for
+                       # generating dependencies.
+                       #
+                       ac_lbl_dependency_flag=""
+                       ;;
+               esac
+       fi
+
+       #
+       # Is ac_lbl_dependency_flag defined and, if so, does the compiler
+       # complain about it?
+       #
+       # Note: clang doesn't seem to exit with an error status when handed
+       # an unknown non-warning error, even if you pass it
+       # -Werror=unknown-warning-option.  However, it always supports
+       # -M, so the fact that this test always succeeds with clang
+       # isn't an issue.
+       #
+       if test ! -z "$ac_lbl_dependency_flag"; then
+               cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+int main(void) { return 0; }
+_ACEOF
+               echo "$CC" $ac_lbl_dependency_flag conftest.c >&5
+               if "$CC" $ac_lbl_dependency_flag conftest.c >/dev/null 2>&1; then
+                       { echo "$as_me:$LINENO: result: yes, with $ac_lbl_dependency_flag" >&5
+echo "${ECHO_T}yes, with $ac_lbl_dependency_flag" >&6; }
+                       DEPENDENCY_CFLAG="$ac_lbl_dependency_flag"
+                       MKDEP='${srcdir}/mkdep'
+               else
+                       { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+                       #
+                       # We can't run mkdep, so have "make depend" do
+                       # nothing.
+                       #
+                       MKDEP=:
+               fi
+               rm -rf conftest*
+       else
+               { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+               #
+               # We can't run mkdep, so have "make depend" do
+               # nothing.
+               #
+               MKDEP=:
+       fi
+
+
            if test "$GCC" = yes ; then
                    if test "${LBL_CFLAGS+set}" != set; then
                            if test "$ac_cv_prog_cc_g" = yes ; then
@@ -12989,6 +13092,8 @@ EGREP!$EGREP$ac_delim
 LIBOBJS!$LIBOBJS$ac_delim
 PCAP_CONFIG!$PCAP_CONFIG$ac_delim
 RANLIB!$RANLIB$ac_delim
+DEPENDENCY_CFLAG!$DEPENDENCY_CFLAG$ac_delim
+MKDEP!$MKDEP$ac_delim
 V_CCOPT!$V_CCOPT$ac_delim
 V_DEFS!$V_DEFS$ac_delim
 V_GROUP!$V_GROUP$ac_delim
@@ -13003,7 +13108,7 @@ INSTALL_DATA!$INSTALL_DATA$ac_delim
 LTLIBOBJS!$LTLIBOBJS$ac_delim
 _ACEOF
 
-  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 71; then
+  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 73; then
     break
   elif $ac_last_try; then
     { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
diff --git a/mkdep b/mkdep
index 2a9c221b1f1d79219c4df6ae939b00d19added05..3062e642eab8a017cb9f26efcf1ad910a4ee8e0c 100755 (executable)
--- a/mkdep
+++ b/mkdep
@@ -18,6 +18,7 @@ export PATH
 
 MAKE=Makefile                  # default makefile name is "Makefile"
 CC=cc                          # default C compiler is "cc"
+DEPENDENCY_CFLAG=-M            # default dependency-generation flag is -M
 
 while :
        do case "$1" in
@@ -31,6 +32,11 @@ while :
                        MAKE=$2
                        shift; shift ;;
 
+               # -m allows you to specify the dependency-generation flag
+               -m)
+                       DEPENDENCY_CFLAG=$2
+                       shift; shift ;;
+
                # the -p flag produces "program: program.c" style dependencies
                # so .o's don't get produced
                -p)
@@ -42,7 +48,7 @@ while :
 done
 
 if [ $# = 0 ] ; then
-       echo 'usage: mkdep [-p] [-c cc] [-f makefile] [flags] file ...'
+       echo 'usage: mkdep [-p] [-c cc] [-f makefile] [-m dependency-cflag] [flags] file ...'
        exit 1
 fi
 
@@ -74,7 +80,7 @@ _EOF_
 # sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
 
 # XXX this doesn't work with things like "-DDECLWAITSTATUS=union\ wait"
-$CC -M $* |
+$CC $DEPENDENCY_CFLAG $* |
 sed "
        s; \./; ;g
        $SED" |