* 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
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;
compileC = {main, localIncludes ? []}: stdenv.mkDerivation {
compileC = {main, localIncludes ? [], cFlags ? ""}: stdenv.mkDerivation {
name = "compile-c";
builder = ./compile-c.sh;
localIncludes =
if localIncludes == "auto" then
import (findIncludes {main = toString main; hack = curTime;})
import (findIncludes {
main = toString main;
hack = curTime;
inherit cFlags;
})
else
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";
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";
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
mainDir=$(dirname $main)
(cd $mainDir && gcc -MM $(basename $main) -MF $makefile) || false
(cd $mainDir && gcc $cFlags -MM $(basename $main) -MF $makefile) || false
echo "[" >$out

View File

@ -1,12 +1,19 @@
. $stdenv/setup
objs=
for i in "$objects"; do
for i in $objects; do
obj=$(echo $i/*.o)
objs="$objs $obj"
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'..."
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