mirror of
https://github.com/NixOS/nix.git
synced 2025-11-14 22:42:41 +01:00
* Linker accepts a name for the program.
* Better diagnostics.
This commit is contained in:
parent
0920fe3038
commit
321be4649d
4 changed files with 10 additions and 7 deletions
|
|
@ -2,7 +2,7 @@ let {
|
|||
|
||||
inherit (import ../../lib) compileC link;
|
||||
|
||||
hello = link {objects = compileC {
|
||||
hello = link {programName = "hello"; objects = compileC {
|
||||
main = ./foo/hello.c;
|
||||
localIncludes = [
|
||||
[./foo/fnord/indirect.h "fnord/indirect.h"]
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
mainName=$(basename $main | cut -c34-)
|
||||
|
||||
echo "compiling $mainName..."
|
||||
echo "compiling \`$mainName'..."
|
||||
|
||||
# Turn $localIncludes into an array.
|
||||
localIncludes=($localIncludes)
|
||||
|
|
@ -67,4 +67,5 @@ done
|
|||
ln -s $main $prefix$mainName
|
||||
|
||||
mkdir $out
|
||||
gcc -Wall -c $prefix$mainName -o $out/$mainName.o
|
||||
test "$prefix" && cd $prefix
|
||||
gcc -Wall -c $mainName -o $out/$mainName.o
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ rec {
|
|||
inherit main localIncludes;
|
||||
};
|
||||
|
||||
link = {objects}: stdenv.mkDerivation {
|
||||
link = {objects, programName ? "program"}: stdenv.mkDerivation {
|
||||
name = "link";
|
||||
builder = ./link.sh;
|
||||
inherit objects;
|
||||
inherit objects programName;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@
|
|||
|
||||
objs=
|
||||
for i in "$objects"; do
|
||||
obj=$i/*.o
|
||||
obj=$(echo $i/*.o)
|
||||
objs="$objs $obj"
|
||||
done
|
||||
|
||||
echo "linking object files into \`$programName'..."
|
||||
|
||||
mkdir $out
|
||||
gcc -o $out/program $objs
|
||||
gcc -o $out/$programName $objs
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue