summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2020-03-02 16:25:30 -0800
committerGuy Harris <guy@alum.mit.edu>2020-03-02 16:25:30 -0800
commit5ef129cf43654c0a59be1deed9d164ca9ec2aaf5 (patch)
tree217bfc599740e10493e63d5293494fd679d73c96
parent3e9b08cc73e8fdf9386af2732f8e0bd465d010ce (diff)
downloadlibpcap-5ef129cf43654c0a59be1deed9d164ca9ec2aaf5.tar.gz
Fix "make depend" for out-of-tree builds.
Have mkdep take a -s argument, giving the source directory, and have it prepend that directory to all source files before running them through the compiler's make-dependencies operation. (There's more to fix, namely handling generated source files.)
-rw-r--r--Makefile.in2
-rwxr-xr-xmkdep27
-rw-r--r--rpcapd/Makefile.in2
-rw-r--r--testprogs/Makefile.in2
4 files changed, 28 insertions, 5 deletions
diff --git a/Makefile.in b/Makefile.in
index 00bcf139..9826db20 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -798,6 +798,6 @@ rc1 rc2 rc3 rc4 rc5:
git checkout VERSION
depend: $(GENERATED_C_SRC) $(GENHDR)
- $(MKDEP) -c "$(CC)" -m "$(DEPENDENCY_CFLAG)" $(CFLAGS) $(DEFS) $(INCLS) $(SRC)
+ $(MKDEP) -c "$(CC)" -m "$(DEPENDENCY_CFLAG)" -s "$(srcdir)" $(CFLAGS) $(DEFS) $(INCLS) $(SRC)
cd rpcapd; $(MAKE) depend
cd testprogs; $(MAKE) depend
diff --git a/mkdep b/mkdep
index 1486b185..656ca099 100755
--- a/mkdep
+++ b/mkdep
@@ -16,7 +16,10 @@
MAKE=Makefile # default makefile name is "Makefile"
CC=cc # default C compiler is "cc"
DEPENDENCY_CFLAG=-M # default dependency-generation flag is -M
+SOURCE_DIRECTORY=. # default source directory is the current directory
+# No command-line flags seen yet.
+flags=""
while :
do case "$1" in
# -c allows you to specify the C compiler
@@ -39,13 +42,24 @@ while :
-p)
SED='s;\.o;;'
shift ;;
+
+ # -s allows you to specify the source directory
+ -s)
+ SOURCE_DIRECTORY=$2
+ shift; shift ;;
+
+ # other command-line flag
+ -*)
+ flags="$flags $1"
+ shift ;;
+
*)
break ;;
esac
done
if [ $# = 0 ] ; then
- echo 'usage: mkdep [-p] [-c cc] [-f makefile] [-m dependency-cflag] [flags] file ...'
+ echo 'usage: mkdep [-p] [-c cc] [-f makefile] [-m dependency-cflag] [-s source-directory] [flags] file ...'
exit 1
fi
@@ -76,8 +90,17 @@ _EOF_
# egrep '^#include[ ]*".*"' /dev/null $* |
# sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
+#
+# Construct a list of source files with paths relative to the source directory.
+#
+sources=""
+for srcfile in $*
+do
+ sources="$sources $SOURCE_DIRECTORY/$srcfile"
+done
+
# XXX this doesn't work with things like "-DDECLWAITSTATUS=union\ wait"
-$CC $DEPENDENCY_CFLAG $* |
+$CC $DEPENDENCY_CFLAG $flags $sources |
sed "
s; \./; ;g
$SED" |
diff --git a/rpcapd/Makefile.in b/rpcapd/Makefile.in
index e46a2b68..32906790 100644
--- a/rpcapd/Makefile.in
+++ b/rpcapd/Makefile.in
@@ -139,4 +139,4 @@ tags: $(TAGFILES)
ctags -wtd $(TAGFILES)
depend:
- $(MKDEP) -c "$(CC)" -m "$(DEPENDENCY_CFLAG)" $(CFLAGS) $(DEFS) $(INCLS) $(SRC)
+ $(MKDEP) -c "$(CC)" -m "$(DEPENDENCY_CFLAG)" -s "$(srcdir)" $(CFLAGS) $(DEFS) $(INCLS) $(SRC)
diff --git a/testprogs/Makefile.in b/testprogs/Makefile.in
index e099d465..3a81e760 100644
--- a/testprogs/Makefile.in
+++ b/testprogs/Makefile.in
@@ -142,4 +142,4 @@ tags: $(TAGFILES)
ctags -wtd $(TAGFILES)
depend:
- $(MKDEP) -c "$(CC)" -m "$(DEPENDENCY_CFLAG)" $(CFLAGS) $(DEFS) $(INCLS) $(SRC)
+ $(MKDEP) -c "$(CC)" -m "$(DEPENDENCY_CFLAG)" -s "$(srcdir)" $(CFLAGS) $(DEFS) $(INCLS) $(SRC)