-
Add some more lines to foo.c (specifically the "quux" lines):
#include <stdio.h>
#include "bar.h"
#include "quux.h"
int main() {
printf("Hello from foo\\n");
printf("bar() says %d\\n", bar());
printf("quux() says %d\\n", quux());
return 0;
}
-
Add a new folder called ../quux. (In dep style, the folders of libraries and apps form a
shallow hierachy of siblings instead of a deep hierarchy of dependencies):
$ mkdir ../quux
$ cd ../quux
-
In there, add quux.h:
#ifndef QUUX_H
#define QUUX_H
int quux();
#endif
-
And add quux.c:
#include "quux.h"
int quux() {
return 123;
}
-
And add a DepFile for a shared library:
include /etc/depsyntax
cc -c -o quux.o quux.c
mkdir -p ../bin
cc -shared -o ../bin/libquux.so quux.o
-
cd back to ../foo:
$ cd ../foo
and edit the DepFile:
include ../quux/DepFile
cc -c -o foo.o -I . -I ../quux foo.c
cc -c -o bar.o bar.c
mkdir ../bin
cc -o ../bin/foo foo.o bar.o -L ../bin -Wl,-rpath,../bin -l quux
-
Run dep --mkdir --fixedorder:
Targetting ../bin/foo
(in ../quux) cc -c -o quux.o quux.c
(in ../quux) mkdir -p ../bin
(in ../quux) cc -shared -o ../bin/libquux.so quux.o
cc -c -o foo.o -I . -I ../quux foo.c
cc -o ../bin/foo foo.o bar.o -L ../bin -Wl,-rpath,../bin -l quux
The --mkdir option causes dep to automatically add existence dependencies between
files mkdir commands. Without the option, dep does not add such dependencies,
as there are a lot of them, and they are rarely needed.
An existence dependency is a dependency where a target is considered up to date
if its source exists. Timestamps and file sizes are not compared any further.
Make calls these order-only dependencies.
-
run ../bin/foo
Hello from foo
bar() says 17
quux() says 123
-
Edit ../quux/quux.c and change the return value of the function:
#include "quux.h"
int quux() {
return 4321;
}
-
And run dep again:
Targetting ../bin/foo
(in ../quux) cc -c -o quux.o quux.c
(in ../quux) cc -shared -o ../bin/libquux.so quux.o
-
It is worth noting here is that dep did not re-link the final executable ../bin/foo.
Most of the time, it doesn't have to: final linkage is actually done by the
loader. To be sure that the program still works, run ../bin/foo:
Hello from foo
bar() says 17
quux() says 4321
These are existence dependencies again. /etc/depsyntax has the line:
exists_file_ext .so .dll
This means that any source file with the extension .so or .dll gets an existence dependency
instead of of an ordinary source dependency.
-
On occasion, you might prefer (or need) to do a full relink
that does not skip any steps. Do do this, run dep --noskip:
Targetting ../bin/foo
cc -o ../bin/foo foo.o bar.o -L ../bin -Wl,-rpath,../bin -l quux