Skip to content

Commit

Permalink
Support dependency generation with some non-GCC compilers.
Browse files Browse the repository at this point in the history
Also, if we don't support it with a given compiler, have "make depend"
not run mkdep, as it won't do anything useful.
  • Loading branch information
guyharris committed May 8, 2013
1 parent 5e2bdef commit 98b7898
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ LD = /usr/bin/ld
CC = @CC@
AR = @AR@
LN_S = @LN_S@
MKDEP = @MKDEP@
CCOPT = @V_CCOPT@
INCLS = -I. @V_INCLS@
DEFS = @DEFS@ @V_DEFS@
Expand All @@ -58,6 +59,7 @@ CFLAGS = @CFLAGS@
LDFLAGS = @LDFLAGS@
DYEXT = @DYEXT@
V_RPATH_OPT = @V_RPATH_OPT@
DEPENDENCY_CFLAG = @DEPENDENCY_CFLAG@
PROG=libpcap

# Standard CFLAGS
Expand Down Expand Up @@ -725,7 +727,7 @@ releasetar:
rm -rf $$name

depend: $(GENSRC) $(GENHDR) bpf_filter.c
./mkdep -c $(CC) $(DEFS) $(INCLS) $(SRC)
$(MKDEP) -c $(CC) -m $(DEPENDENCY_CFLAG) $(DEFS) $(INCLS) $(SRC)

Makefile: Makefile.in config.status
./config.status
Expand Down
114 changes: 114 additions & 0 deletions aclocal.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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)
])

dnl
dnl Determine what options are needed to build a shared library
dnl
Expand Down Expand Up @@ -867,6 +980,7 @@ AC_DEFUN(AC_LBL_DEVEL,
AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-prototypes)
AC_LBL_CHECK_COMPILER_OPT($1, -Wstrict-prototypes)
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
Expand Down
111 changes: 108 additions & 3 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ V_YACC
RANLIB
AR
LN_S
DEPENDENCY_CFLAG MKDEP
V_CCOPT
V_DEFS
V_FINDALLDEVS
Expand Down Expand Up @@ -10726,6 +10727,108 @@ fi
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
Expand Down Expand Up @@ -13173,6 +13276,8 @@ V_YACC!$V_YACC$ac_delim
RANLIB!$RANLIB$ac_delim
AR!$AR$ac_delim
LN_S!$LN_S$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_FINDALLDEVS!$V_FINDALLDEVS$ac_delim
Expand Down Expand Up @@ -13201,8 +13306,6 @@ CAN_SRC!$CAN_SRC$ac_delim
PKGCONFIG!$PKGCONFIG$ac_delim
PCAP_SUPPORT_DBUS!$PCAP_SUPPORT_DBUS$ac_delim
DBUS_SRC!$DBUS_SRC$ac_delim
INSTALL_PROGRAM!$INSTALL_PROGRAM$ac_delim
INSTALL_SCRIPT!$INSTALL_SCRIPT$ac_delim
_ACEOF
if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then
Expand Down Expand Up @@ -13244,11 +13347,13 @@ _ACEOF
ac_delim='%!_!# '
for ac_last_try in false false false false false :; do
cat >conf$$subs.sed <<_ACEOF
INSTALL_PROGRAM!$INSTALL_PROGRAM$ac_delim
INSTALL_SCRIPT!$INSTALL_SCRIPT$ac_delim
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` = 2; then
if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 4; then
break
elif $ac_last_try; then
{ { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
Expand Down
10 changes: 8 additions & 2 deletions mkdep
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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" |
Expand Down

0 comments on commit 98b7898

Please sign in to comment.