1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-14 22:42:41 +01:00

* Header files that are used by a compilation must be declared

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.
This commit is contained in:
Eelco Dolstra 2004-07-06 12:27:19 +00:00
parent 15646244ba
commit 08de98f8b6
7 changed files with 43 additions and 4 deletions

3
examples/default.nix Normal file
View file

@ -0,0 +1,3 @@
[ (import ./trivial)
(import ./simple-header)
]

View file

@ -0,0 +1,11 @@
let {
inherit (import ../../lib) compileC link;
hello = link {objects = compileC {
main = ./hello.c;
localIncludes = [ [./hello.h "hello.h"] ];
};};
body = [hello];
}

View file

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

View file

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

View file

@ -1,3 +1,18 @@
. $stdenv/setup . $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 mkdir $out
gcc -Wall -c $main -o $out/$(basename $main).o gcc -Wall -c $mainName -o $out/$mainName.o

View file

@ -2,10 +2,10 @@ rec {
inherit (import /home/eelco/nixpkgs/pkgs/system/i686-linux.nix) stdenv; inherit (import /home/eelco/nixpkgs/pkgs/system/i686-linux.nix) stdenv;
compileC = {main}: stdenv.mkDerivation { compileC = {main, localIncludes ? []}: stdenv.mkDerivation {
name = "compile-c"; name = "compile-c";
builder = ./compile-c.sh; builder = ./compile-c.sh;
inherit main; inherit main localIncludes;
}; };
link = {objects}: stdenv.mkDerivation { link = {objects}: stdenv.mkDerivation {