Skip to content

Commit

Permalink
* Header files that are used by a compilation must be declared
Browse files Browse the repository at this point in the history
  explicitly.  If you forget a dependency, it's simply not visible to
  the compiler, and so the compilation fails.  This is a big plus over
  conventional Make.

svn path=/nix/branches/nix-make/examples/; revision=1135
  • Loading branch information
edolstra committed Jul 6, 2004
1 parent 6e87e58 commit 37a7ce7
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 4 deletions.
3 changes: 3 additions & 0 deletions examples/default.nix
@@ -0,0 +1,3 @@
[ (import ./trivial)
(import ./simple-header)
]
11 changes: 11 additions & 0 deletions examples/simple-header/default.nix
@@ -0,0 +1,11 @@
let {

inherit (import ../../lib) compileC link;

hello = link {objects = compileC {
main = ./hello.c;
localIncludes = [ [./hello.h "hello.h"] ];
};};

body = [hello];
}
9 changes: 9 additions & 0 deletions examples/simple-header/hello.c
@@ -0,0 +1,9 @@
#include <stdio.h>

#include "hello.h"

int main(int argc, char * * argv)
{
printf("Hello " WHAT "\n");
return 0;
}
1 change: 1 addition & 0 deletions examples/simple-header/hello.h
@@ -0,0 +1 @@
#define WHAT "World"
2 changes: 1 addition & 1 deletion examples/trivial/default.nix
Expand Up @@ -5,4 +5,4 @@ let {
hello = link {objects = compileC {main = ./hello.c;};};

body = [hello];
}
}
17 changes: 16 additions & 1 deletion lib/compile-c.sh
@@ -1,3 +1,18 @@
. $stdenv/setup

mainName=$(basename $main | cut -c34-)
ln -s $main $mainName

echo "compiling $mainName..."

localIncludes=($localIncludes)
n=0
while test $n -lt ${#localIncludes[*]}; do
source=${localIncludes[n]}
target=${localIncludes[$((n+1))]}
ln -s $source $target
n=$((n + 2))
done

mkdir $out
gcc -Wall -c $main -o $out/$(basename $main).o
gcc -Wall -c $mainName -o $out/$mainName.o
4 changes: 2 additions & 2 deletions lib/default.nix
Expand Up @@ -2,10 +2,10 @@ rec {

inherit (import /home/eelco/nixpkgs/pkgs/system/i686-linux.nix) stdenv;

compileC = {main}: stdenv.mkDerivation {
compileC = {main, localIncludes ? []}: stdenv.mkDerivation {
name = "compile-c";
builder = ./compile-c.sh;
inherit main;
inherit main localIncludes;
};

link = {objects}: stdenv.mkDerivation {
Expand Down

0 comments on commit 37a7ce7

Please sign in to comment.