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

* A function to build libraries.

* The linker can link against libraries.
* C flags can be passed to the C compiler.
This commit is contained in:
Eelco Dolstra 2004-07-06 17:25:10 +00:00
parent 5d48dd6912
commit 17e20716c0
5 changed files with 43 additions and 11 deletions

View file

@ -70,4 +70,4 @@ fi
mkdir $out mkdir $out
test "$prefix" && cd $prefix test "$prefix" && cd $prefix
gcc -Wall -c $mainName -o $out/$mainName.o gcc -Wall $cFlags -c $mainName -o $out/$mainName.o

View file

@ -2,15 +2,19 @@ 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, localIncludes ? []}: stdenv.mkDerivation { compileC = {main, localIncludes ? [], cFlags ? ""}: stdenv.mkDerivation {
name = "compile-c"; name = "compile-c";
builder = ./compile-c.sh; builder = ./compile-c.sh;
localIncludes = localIncludes =
if localIncludes == "auto" then if localIncludes == "auto" then
import (findIncludes {main = toString main; hack = curTime;}) import (findIncludes {
main = toString main;
hack = curTime;
inherit cFlags;
})
else else
localIncludes; localIncludes;
inherit main; inherit main cFlags;
}; };
/* /*
@ -21,16 +25,22 @@ rec {
}; };
*/ */
findIncludes = {main, hack}: stdenv.mkDerivation { findIncludes = {main, hack, cFlags ? ""}: stdenv.mkDerivation {
name = "find-includes"; name = "find-includes";
builder = ./find-includes.sh; builder = ./find-includes.sh;
inherit main hack; inherit main hack cFlags;
}; };
link = {objects, programName ? "program"}: stdenv.mkDerivation { link = {objects, programName ? "program", libraries ? []}: stdenv.mkDerivation {
name = "link"; name = "link";
builder = ./link.sh; builder = ./link.sh;
inherit objects programName; inherit objects programName libraries;
};
makeLibrary = {objects, libraryName ? []}: stdenv.mkDerivation {
name = "library";
builder = ./make-library.sh;
inherit objects libraryName;
}; };
} }

View file

@ -5,7 +5,7 @@ echo "finding includes of \`$(basename $main)'..."
makefile=$NIX_BUILD_TOP/makefile makefile=$NIX_BUILD_TOP/makefile
mainDir=$(dirname $main) mainDir=$(dirname $main)
(cd $mainDir && gcc -MM $(basename $main) -MF $makefile) || false (cd $mainDir && gcc $cFlags -MM $(basename $main) -MF $makefile) || false
echo "[" >$out echo "[" >$out

View file

@ -1,12 +1,19 @@
. $stdenv/setup . $stdenv/setup
objs= objs=
for i in "$objects"; do for i in $objects; do
obj=$(echo $i/*.o) obj=$(echo $i/*.o)
objs="$objs $obj" objs="$objs $obj"
done done
libs=
for i in $libraries; do
lib=$(echo $i/*.a)
name=$(echo $(basename $lib) | sed -e 's/^lib//' -e 's/.a$//')
libs="$libs -L$(dirname $lib) -l$name"
done
echo "linking object files into \`$programName'..." echo "linking object files into \`$programName'..."
mkdir $out mkdir $out
gcc -o $out/$programName $objs gcc -o $out/$programName $objs $libs

15
lib/make-library.sh Normal file
View file

@ -0,0 +1,15 @@
. $stdenv/setup
objs=
for i in $objects; do
obj=$(echo $i/*.o)
objs="$objs $obj"
done
echo "archiving object files into library \`$libraryName'..."
outPath=$out/lib${libraryName}.a
mkdir $out
ar crs $outPath $objs
ranlib $outPath