1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-15 15:02:42 +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:
Eelco Dolstra 2004-07-06 16:05:28 +00:00
parent fa50c0849e
commit 7d386d5c29
7 changed files with 62 additions and 2 deletions

View file

@ -0,0 +1 @@
#define WHAT "World"

View 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];
}

View file

@ -0,0 +1,3 @@
#define HELLO "Hello"
#include "../../bar/hello.h"

View file

@ -0,0 +1,9 @@
#include <stdio.h>
#include "fnord/indirect.h"
int main(int argc, char * * argv)
{
printf(HELLO " " WHAT "\n");
return 0;
}

View file

@ -64,7 +64,9 @@ for ((n = 0; n < ${#localIncludes[*]}; n += 2)); do
done done
# Create a symlink to the main file. # Create a symlink to the main file.
if ! test "$(readlink $prefix$mainName)" = $main; then
ln -s $main $prefix$mainName ln -s $main $prefix$mainName
fi
mkdir $out mkdir $out
test "$prefix" && cd $prefix test "$prefix" && cd $prefix

View file

@ -8,6 +8,20 @@ rec {
inherit main localIncludes; 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 { link = {objects, programName ? "program"}: stdenv.mkDerivation {
name = "link"; name = "link";
builder = ./link.sh; builder = ./link.sh;

20
lib/find-includes.sh Normal file
View 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