mirror of
https://github.com/NixOS/nix.git
synced 2025-11-14 22:42:41 +01:00
* Some trivial Nix Make examples.
This commit is contained in:
parent
a2e33d200e
commit
15646244ba
5 changed files with 45 additions and 0 deletions
8
examples/trivial/default.nix
Normal file
8
examples/trivial/default.nix
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
let {
|
||||||
|
|
||||||
|
inherit (import ../../lib) compileC link;
|
||||||
|
|
||||||
|
hello = link {objects = compileC {main = ./hello.c;};};
|
||||||
|
|
||||||
|
body = [hello];
|
||||||
|
}
|
||||||
7
examples/trivial/hello.c
Normal file
7
examples/trivial/hello.c
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main(int argc, char * * argv)
|
||||||
|
{
|
||||||
|
printf("Hello World\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
3
lib/compile-c.sh
Normal file
3
lib/compile-c.sh
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
. $stdenv/setup
|
||||||
|
mkdir $out
|
||||||
|
gcc -Wall -c $main -o $out/$(basename $main).o
|
||||||
17
lib/default.nix
Normal file
17
lib/default.nix
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
rec {
|
||||||
|
|
||||||
|
inherit (import /home/eelco/nixpkgs/pkgs/system/i686-linux.nix) stdenv;
|
||||||
|
|
||||||
|
compileC = {main}: stdenv.mkDerivation {
|
||||||
|
name = "compile-c";
|
||||||
|
builder = ./compile-c.sh;
|
||||||
|
inherit main;
|
||||||
|
};
|
||||||
|
|
||||||
|
link = {objects}: stdenv.mkDerivation {
|
||||||
|
name = "link";
|
||||||
|
builder = ./link.sh;
|
||||||
|
inherit objects;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
10
lib/link.sh
Normal file
10
lib/link.sh
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
. $stdenv/setup
|
||||||
|
|
||||||
|
objs=
|
||||||
|
for i in "$objects"; do
|
||||||
|
obj=$i/*.o
|
||||||
|
objs="$objs $obj"
|
||||||
|
done
|
||||||
|
|
||||||
|
mkdir $out
|
||||||
|
gcc -o $out/program $objs
|
||||||
Loading…
Add table
Add a link
Reference in a new issue