mirror of
https://github.com/NixOS/nix.git
synced 2024-11-21 22:32:26 +00: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:
parent
5d48dd6912
commit
17e20716c0
@ -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
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
11
lib/link.sh
11
lib/link.sh
@ -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
15
lib/make-library.sh
Normal 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
|
Loading…
Reference in New Issue
Block a user