forked from edolstra/nix-make
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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. svn path=/nix/branches/nix-make/examples/; revision=1135
- Loading branch information
Showing
7 changed files
with
43 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[ (import ./trivial) | ||
(import ./simple-header) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
let { | ||
|
||
inherit (import ../../lib) compileC link; | ||
|
||
hello = link {objects = compileC { | ||
main = ./hello.c; | ||
localIncludes = [ [./hello.h "hello.h"] ]; | ||
};}; | ||
|
||
body = [hello]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <stdio.h> | ||
|
||
#include "hello.h" | ||
|
||
int main(int argc, char * * argv) | ||
{ | ||
printf("Hello " WHAT "\n"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#define WHAT "World" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ let { | |
hello = link {objects = compileC {main = ./hello.c;};}; | ||
|
||
body = [hello]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters