mirror of
https://github.com/NixOS/nix.git
synced 2025-11-15 23:12:44 +01:00
* Automatically determine header file dependencies using the
`findIncludes' function. The current implementation is impure and therefore not correct: it gathers header file dependencies only once for a specific path (due to caching).
This commit is contained in:
parent
fa50c0849e
commit
7d386d5c29
7 changed files with 62 additions and 2 deletions
1
examples/not-so-simple-header-auto/bar/hello.h
Normal file
1
examples/not-so-simple-header-auto/bar/hello.h
Normal file
|
|
@ -0,0 +1 @@
|
|||
#define WHAT "World"
|
||||
11
examples/not-so-simple-header-auto/default.nix
Normal file
11
examples/not-so-simple-header-auto/default.nix
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
let {
|
||||
|
||||
inherit (import ../../lib) compileC findIncludes link;
|
||||
|
||||
hello = link {programName = "hello"; objects = compileC {
|
||||
main = ./foo/hello.c;
|
||||
localIncludes = import (findIncludes {main = toString ./foo/hello.c;});
|
||||
};};
|
||||
|
||||
body = [hello];
|
||||
}
|
||||
3
examples/not-so-simple-header-auto/foo/fnord/indirect.h
Normal file
3
examples/not-so-simple-header-auto/foo/fnord/indirect.h
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#define HELLO "Hello"
|
||||
|
||||
#include "../../bar/hello.h"
|
||||
9
examples/not-so-simple-header-auto/foo/hello.c
Normal file
9
examples/not-so-simple-header-auto/foo/hello.c
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "fnord/indirect.h"
|
||||
|
||||
int main(int argc, char * * argv)
|
||||
{
|
||||
printf(HELLO " " WHAT "\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -64,7 +64,9 @@ for ((n = 0; n < ${#localIncludes[*]}; n += 2)); do
|
|||
done
|
||||
|
||||
# Create a symlink to the main file.
|
||||
ln -s $main $prefix$mainName
|
||||
if ! test "$(readlink $prefix$mainName)" = $main; then
|
||||
ln -s $main $prefix$mainName
|
||||
fi
|
||||
|
||||
mkdir $out
|
||||
test "$prefix" && cd $prefix
|
||||
|
|
|
|||
|
|
@ -8,10 +8,24 @@ rec {
|
|||
inherit main localIncludes;
|
||||
};
|
||||
|
||||
/*
|
||||
runCommand = {command}: {
|
||||
name = "run-command";
|
||||
builder = ./run-command.sh;
|
||||
inherit command;
|
||||
};
|
||||
*/
|
||||
|
||||
findIncludes = {main}: stdenv.mkDerivation {
|
||||
name = "find-includes";
|
||||
builder = ./find-includes.sh;
|
||||
inherit main;
|
||||
};
|
||||
|
||||
link = {objects, programName ? "program"}: stdenv.mkDerivation {
|
||||
name = "link";
|
||||
builder = ./link.sh;
|
||||
inherit objects programName;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
20
lib/find-includes.sh
Normal file
20
lib/find-includes.sh
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
. $stdenv/setup
|
||||
|
||||
echo "finding includes of \`$(basename $main)'..."
|
||||
|
||||
makefile=$NIX_BUILD_TOP/makefile
|
||||
|
||||
mainDir=$(dirname $main)
|
||||
(cd $mainDir && gcc -MM $(basename $main) -MF $makefile) || false
|
||||
|
||||
echo "[" >$out
|
||||
|
||||
while read line; do
|
||||
line=$(echo "$line" | sed 's/.*://')
|
||||
for i in $line; do
|
||||
fullPath=$(readlink -f $mainDir/$i)
|
||||
echo " [ $fullPath \"$i\" ]" >>$out
|
||||
done
|
||||
done < $makefile
|
||||
|
||||
echo "]" >>$out
|
||||
Loading…
Add table
Add a link
Reference in a new issue