Simplify autodependency examples.
Turns out we don't need sed to process the output of gcc -MD. We can just
do this:
read DEPS <filename.deps
The 'read' command in sh actually handles backslashes correctly, so we don't
have to sed them out after all. And then a simple ${DEPS#*:} removes the
"target:" prefix from the dependency line, and we're done!
This commit is contained in:
parent
ea7057d9b6
commit
a2bce72255
3 changed files with 12 additions and 13 deletions
|
|
@ -48,11 +48,11 @@ of .h files it depends on. You can pass this information
|
||||||
along to redo-ifchange, so if any of those headers are
|
along to redo-ifchange, so if any of those headers are
|
||||||
changed or deleted, your .c file will be rebuilt:
|
changed or deleted, your .c file will be rebuilt:
|
||||||
|
|
||||||
redo-ifchange $1$2
|
redo-ifchange $1.c
|
||||||
gcc -o $3 -c $1$2 \
|
gcc -o $3 -c $1.c \
|
||||||
-MMD -MF $1.deps -MT DELETE_ME
|
-MMD -MF $1.deps
|
||||||
redo-ifchange $(sed -e 's,^DELETE_ME:,,' \
|
read DEPS <$1.deps
|
||||||
-e 's,\\,,' $1.deps)
|
redo-ifchange ${DEPS#*:}
|
||||||
|
|
||||||
This is much less confusing than the equivalent
|
This is much less confusing than the equivalent
|
||||||
autodependency mechanism in `make`(1), because make
|
autodependency mechanism in `make`(1), because make
|
||||||
|
|
|
||||||
|
|
@ -75,10 +75,9 @@ The easiest way to show it is with an example.
|
||||||
Create a file called default.o.do:
|
Create a file called default.o.do:
|
||||||
|
|
||||||
redo-ifchange $1.c
|
redo-ifchange $1.c
|
||||||
gcc -MD -MF $3.deps.tmp -c -o $3 $1.c
|
gcc -MD -MF $1.d -c -o $3 $1.c
|
||||||
DEPS=$(sed -e "s/^$3://" -e 's/\\//g' <$3.deps.tmp)
|
read DEPS <$1.d
|
||||||
rm -f $3.deps.tmp
|
redo-ifchange ${DEPS#*:}
|
||||||
redo-ifchange $DEPS
|
|
||||||
|
|
||||||
Create a file called myprog.do:
|
Create a file called myprog.do:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@ redo-ifchange config.sh
|
||||||
exec >$3
|
exec >$3
|
||||||
cat <<-EOF
|
cat <<-EOF
|
||||||
redo-ifchange \$1.c
|
redo-ifchange \$1.c
|
||||||
gcc $CFLAGS -MD -MF \$3.deps.tmp -o \$3 -c \$1.c
|
gcc $CFLAGS -MD -MF \$3.deps -o \$3 -c \$1.c
|
||||||
DEPS=\$(sed -e "s/^\$3://" -e 's/\\\\//g' <\$3.deps.tmp)
|
read DEPS <\$3.deps
|
||||||
rm -f \$3.deps.tmp
|
rm -f \$3.deps
|
||||||
redo-ifchange \$DEPS
|
redo-ifchange \${DEPS#*:}
|
||||||
EOF
|
EOF
|
||||||
chmod +x $3
|
chmod +x $3
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue